Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6d7695c authored by Holly Jiuyu Sun's avatar Holly Jiuyu Sun
Browse files

Change the default behavior when MCC/MNC changes.

By default, we don't restart the activity when MCC/MNC changes
even when they are not set in configChanges. If they want to
restart, set mcc or mnc in the new attribute restartOnConfigChanges.

Bug: 34258948
Test: Test in unit test(testGetActivityConfigChanges() in
      PackageParserTest.java) and on real device with
      changing the SIM card.

Change-Id: Icd6899597c9b8f2e5706e74373a0280d19150092
parent 4842c4c8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1052,6 +1052,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
+1 −0
Original line number Diff line number Diff line
@@ -1161,6 +1161,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
+1 −0
Original line number Diff line number Diff line
@@ -1052,6 +1052,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
+21 −1
Original line number Diff line number Diff line
@@ -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);
+24 −2
Original line number Diff line number Diff line
@@ -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. -->
@@ -1917,6 +1938,7 @@
        <attr name="launchMode" />
        <attr name="screenOrientation" />
        <attr name="configChanges" />
        <attr name="restartOnConfigChanges" />
        <attr name="permission" />
        <attr name="multiprocess" />
        <attr name="process" />
Loading