diff options
| author | 2017-01-20 22:58:21 +0000 | |
|---|---|---|
| committer | 2017-01-20 22:58:25 +0000 | |
| commit | 417d30d88b7fef58a9b8765d712885cef2d3eb88 (patch) | |
| tree | abc312dedc85a3160afd958c1efc0e9a71971a55 | |
| parent | 6ba5dccd50d098d8ae1c5fac8e83be7f61c70018 (diff) | |
| parent | b6d7695cf2e7cec5c7b24e1b09e1f7d8f1788cb7 (diff) | |
Merge "Change the default behavior when MCC/MNC changes."
| -rw-r--r-- | api/current.txt | 1 | ||||
| -rw-r--r-- | api/system-current.txt | 1 | ||||
| -rw-r--r-- | api/test-current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/content/pm/PackageParser.java | 22 | ||||
| -rw-r--r-- | core/res/res/values/attrs_manifest.xml | 26 | ||||
| -rw-r--r-- | core/res/res/values/public.xml | 1 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/content/pm/PackageParserTest.java | 42 |
7 files changed, 91 insertions, 3 deletions
diff --git a/api/current.txt b/api/current.txt index 1b9ba877c76a..634812cb9909 100644 --- a/api/current.txt +++ b/api/current.txt @@ -1054,6 +1054,7 @@ package android { 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 diff --git a/api/system-current.txt b/api/system-current.txt index c2cdbeb286c9..3871e3888b9a 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -1163,6 +1163,7 @@ package android { 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 diff --git a/api/test-current.txt b/api/test-current.txt index e7d98e1861ae..7800b80d4058 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -1054,6 +1054,7 @@ package android { 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 diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index 083e4cc6676b..2fdc527208c0 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -179,6 +179,13 @@ public class PackageParser { 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 { @@ -3855,7 +3862,9 @@ public class PackageParser { 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); @@ -4083,6 +4092,17 @@ public class PackageParser { } } + /** + * @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); diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml index d1a1d3e9352a..6a4711a81fb2 100644 --- a/core/res/res/values/attrs_manifest.xml +++ b/core/res/res/values/attrs_manifest.xml @@ -776,6 +776,21 @@ <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, @@ -793,10 +808,16 @@ 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. --> @@ -1920,6 +1941,7 @@ <attr name="launchMode" /> <attr name="screenOrientation" /> <attr name="configChanges" /> + <attr name="restartOnConfigChanges" /> <attr name="permission" /> <attr name="multiprocess" /> <attr name="process" /> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 664baa2eed97..ad9e4d984cc8 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -2785,6 +2785,7 @@ <public name="appCategory" /> <public name="autoSizeMaxTextSize" /> <public name="supportsDismissingWindow" /> + <public name="restartOnConfigChanges" /> </public-group> <public-group type="style" first-id="0x010302e0"> diff --git a/core/tests/coretests/src/android/content/pm/PackageParserTest.java b/core/tests/coretests/src/android/content/pm/PackageParserTest.java index 2a3c22c64ec2..ca4141afae2d 100644 --- a/core/tests/coretests/src/android/content/pm/PackageParserTest.java +++ b/core/tests/coretests/src/android/content/pm/PackageParserTest.java @@ -215,4 +215,46 @@ public class PackageParserTest { // 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. + } } |