field public static final int resizeable = 16843405; // 0x101028d
field public static final int resizeableActivity = 16844022; // 0x10104f6
field public static final int resource = 16842789; // 0x1010025
+ field public static final int restartOnConfigChanges = 16844105; // 0x1010549
field public static final int restoreAnyVersion = 16843450; // 0x10102ba
field public static final deprecated int restoreNeedsApplication = 16843421; // 0x101029d
field public static final int restrictedAccountType = 16843733; // 0x10103d5
field public static final int resizeable = 16843405; // 0x101028d
field public static final int resizeableActivity = 16844022; // 0x10104f6
field public static final int resource = 16842789; // 0x1010025
+ field public static final int restartOnConfigChanges = 16844105; // 0x1010549
field public static final int restoreAnyVersion = 16843450; // 0x10102ba
field public static final deprecated int restoreNeedsApplication = 16843421; // 0x101029d
field public static final int restrictedAccountType = 16843733; // 0x10103d5
field public static final int resizeable = 16843405; // 0x101028d
field public static final int resizeableActivity = 16844022; // 0x10104f6
field public static final int resource = 16842789; // 0x1010025
+ field public static final int restartOnConfigChanges = 16844105; // 0x1010549
field public static final int restoreAnyVersion = 16843450; // 0x10102ba
field public static final deprecated int restoreNeedsApplication = 16843421; // 0x101029d
field public static final int restrictedAccountType = 16843733; // 0x10103d5
private static final String TAG_PACKAGE = "package";
private static final String TAG_RESTRICT_UPDATE = "restrict-update";
+ /**
+ * Bit mask of all the valid bits that can be set in restartOnConfigChanges.
+ * @hide
+ */
+ private static final int RESTART_ON_CONFIG_CHANGES_MASK =
+ ActivityInfo.CONFIG_MCC | ActivityInfo.CONFIG_MNC;
+
// These are the tags supported by child packages
private static final Set<String> CHILD_PACKAGE_TAGS = new ArraySet<>();
static {
a.info.maxRecents = sa.getInt(
R.styleable.AndroidManifestActivity_maxRecents,
ActivityManager.getDefaultAppRecentsLimitStatic());
- a.info.configChanges = sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0);
+ a.info.configChanges = getActivityConfigChanges(
+ sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0),
+ sa.getInt(R.styleable.AndroidManifestActivity_restartOnConfigChanges, 0));
a.info.softInputMode = sa.getInt(
R.styleable.AndroidManifestActivity_windowSoftInputMode, 0);
}
}
+ /**
+ * @param configChanges The bit mask of configChanges fetched from AndroidManifest.xml.
+ * @param restartOnConfigChanges The bit mask restartOnConfigChanges fetched from
+ * AndroidManifest.xml.
+ * @hide Exposed for unit testing only.
+ */
+ @TestApi
+ public static int getActivityConfigChanges(int configChanges, int restartOnConfigChanges) {
+ return configChanges | ((~restartOnConfigChanges) & RESTART_ON_CONFIG_CHANGES_MASK);
+ }
+
private void parseLayout(Resources res, AttributeSet attrs, Activity a) {
TypedArray sw = res.obtainAttributes(attrs,
com.android.internal.R.styleable.AndroidManifestLayout);
<enum name="locked" value="14" />
</attr>
+ <!-- Specify the configuration changes that trigger the system to restart the
+ current activity if any of these configuration changes happen in the system.
+ The valid configuration changes include mcc and mnc which are the same with
+ those in configChanges. By default from Android O, we don't restart the activity
+ even the app doesn't specify mcc or mnc in configChanges. If the app wants to
+ restart, specify them in restartOnConfigChanges. -->
+ <attr name="restartOnConfigChanges">
+ <!-- The IMSI MCC has changed, that is a SIM has been detected and
+ updated the Mobile Country Code. -->
+ <flag name="mcc" value="0x0001" />
+ <!-- The IMSI MNC has changed, that is a SIM has been detected and
+ updated the Mobile Network Code. -->
+ <flag name="mnc" value="0x0002" />
+ </attr>
+
<!-- Specify one or more configuration changes that the activity will
handle itself. If not specified, the activity will be restarted
if any of these configuration changes happen in the system. Otherwise,
include/utils/ResourceTypes.h. -->
<attr name="configChanges">
<!-- The IMSI MCC has changed, that is a SIM has been detected and
- updated the Mobile Country Code. -->
+ updated the Mobile Country Code. By default from Android O, we
+ don't restart the activity even the app doesn't specify mcc in
+ configChanges. If the app wants to restart, specify mcc in
+ restartOnConfigChanges. -->
<flag name="mcc" value="0x0001" />
<!-- The IMSI MNC has changed, that is a SIM has been detected and
- updated the Mobile Network Code. -->
+ updated the Mobile Network Code. By default from Android O, we
+ don't restart the activity even the app doesn't specify mnc in
+ configChanges. If the app wants to restart, specify mnc in
+ restartOnConfigChanges. -->
<flag name="mnc" value="0x0002" />
<!-- The locale has changed, that is the user has selected a new
language that text should be displayed in. -->
<attr name="launchMode" />
<attr name="screenOrientation" />
<attr name="configChanges" />
+ <attr name="restartOnConfigChanges" />
<attr name="permission" />
<attr name="multiprocess" />
<attr name="process" />
<public name="appCategory" />
<public name="autoSizeMaxTextSize" />
<public name="supportsDismissingWindow" />
+ <public name="restartOnConfigChanges" />
</public-group>
<public-group type="style" first-id="0x010302e0">
// DEV: Released API 20
verifyComputeTargetSdkVersion(NEWER_VERSION, NEWER_PRE_RELEASE, true, -1);
}
+
+ /**
+ * Unit test for PackageParser.getActivityConfigChanges().
+ * If the bit is 1 in the original configChanges, it is still 1 in the final configChanges.
+ * If the bit is 0 in the original configChanges and the bit is not set to 1 in
+ * restartOnConfigChanges, the bit is changed to 1 in the final configChanges by default.
+ */
+ @Test
+ public void testGetActivityConfigChanges() {
+ // Not set in either configChanges or restartOnConfigChanges.
+ int configChanges = 0x0000; // 00000000.
+ int restartOnConfigChanges = 0x0000; // 00000000.
+ int finalConfigChanges =
+ PackageParser.getActivityConfigChanges(configChanges, restartOnConfigChanges);
+ assertEquals(0x0003, finalConfigChanges); // Should be 00000011.
+
+ // Not set in configChanges, but set in restartOnConfigChanges.
+ configChanges = 0x0000; // 00000000.
+ restartOnConfigChanges = 0x0003; // 00000011.
+ finalConfigChanges =
+ PackageParser.getActivityConfigChanges(configChanges, restartOnConfigChanges);
+ assertEquals(0x0000, finalConfigChanges); // Should be 00000000.
+
+ // Set in configChanges.
+ configChanges = 0x0003; // 00000011.
+ restartOnConfigChanges = 0X0000; // 00000000.
+ finalConfigChanges =
+ PackageParser.getActivityConfigChanges(configChanges, restartOnConfigChanges);
+ assertEquals(0x0003, finalConfigChanges); // Should be 00000011.
+
+ restartOnConfigChanges = 0x0003; // 00000011.
+ finalConfigChanges =
+ PackageParser.getActivityConfigChanges(configChanges, restartOnConfigChanges);
+ assertEquals(0x0003, finalConfigChanges); // Should still be 00000011.
+
+ // Other bit set in configChanges.
+ configChanges = 0x0080; // 10000000, orientation.
+ restartOnConfigChanges = 0x0000; // 00000000.
+ finalConfigChanges =
+ PackageParser.getActivityConfigChanges(configChanges, restartOnConfigChanges);
+ assertEquals(0x0083, finalConfigChanges); // Should be 10000011.
+ }
}