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

Commit 68d6ab78 authored by JW Wang's avatar JW Wang
Browse files

Allow app to specify the rollback data policy in the manifest (1/n)

See b/148098864#comment1.

It makes more sense for an app to declare the data policy in their
manifest, rather than leaving this decision to the installer.

The attribute will be read by RollbackManager during install to decide
which data policy to adopt when committing a rollback.

Also migrate to ApkLiteParseUtils per
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/11069722/1/core/java/android/content/pm/PackageParser.java#1660.

Bug: 148098864
Test: m
Change-Id: Ie6635249ea0dfbd21b0e56080fb492b9949841ec
parent 9448362c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1165,6 +1165,7 @@ package android {
    field public static final int right = 16843183; // 0x10101af
    field public static final int ringtonePreferenceStyle = 16842899; // 0x1010093
    field public static final int ringtoneType = 16843257; // 0x10101f9
    field public static final int rollbackDataPolicy = 16844314; // 0x101061a
    field public static final int rotation = 16843558; // 0x1010326
    field public static final int rotationAnimation = 16844090; // 0x101053a
    field public static final int rotationX = 16843559; // 0x1010327
+9 −2
Original line number Diff line number Diff line
@@ -473,6 +473,7 @@ public class PackageParser {
        public final String targetPackageName;
        public final boolean overlayIsStatic;
        public final int overlayPriority;
        public final int rollbackDataPolicy;

        public ApkLite(String codePath, String packageName, String splitName,
                boolean isFeatureSplit,
@@ -483,7 +484,7 @@ public class PackageParser {
                boolean debuggable, boolean multiArch, boolean use32bitAbi,
                boolean useEmbeddedDex, boolean extractNativeLibs, boolean isolatedSplits,
                String targetPackageName, boolean overlayIsStatic, int overlayPriority,
                int minSdkVersion, int targetSdkVersion) {
                int minSdkVersion, int targetSdkVersion, int rollbackDataPolicy) {
            this.codePath = codePath;
            this.packageName = packageName;
            this.splitName = splitName;
@@ -509,6 +510,7 @@ public class PackageParser {
            this.overlayPriority = overlayPriority;
            this.minSdkVersion = minSdkVersion;
            this.targetSdkVersion = targetSdkVersion;
            this.rollbackDataPolicy = rollbackDataPolicy;
        }

        public long getLongVersionCode() {
@@ -1586,6 +1588,7 @@ public class PackageParser {
        String targetPackage = null;
        boolean overlayIsStatic = false;
        int overlayPriority = 0;
        int rollbackDataPolicy = 0;

        String requiredSystemPropertyName = null;
        String requiredSystemPropertyValue = null;
@@ -1652,6 +1655,9 @@ public class PackageParser {
                    if ("useEmbeddedDex".equals(attr)) {
                        useEmbeddedDex = attrs.getAttributeBooleanValue(i, false);
                    }
                    if (attr.equals("rollbackDataPolicy")) {
                        rollbackDataPolicy = attrs.getAttributeIntValue(i, 0);
                    }
                }
            } else if (PackageParser.TAG_OVERLAY.equals(parser.getName())) {
                for (int i = 0; i < attrs.getAttributeCount(); ++i) {
@@ -1709,7 +1715,8 @@ public class PackageParser {
                configForSplit, usesSplitName, isSplitRequired, versionCode, versionCodeMajor,
                revisionCode, installLocation, verifiers, signingDetails, coreApp, debuggable,
                multiArch, use32bitAbi, useEmbeddedDex, extractNativeLibs, isolatedSplits,
                targetPackage, overlayIsStatic, overlayPriority, minSdkVersion, targetSdkVersion);
                targetPackage, overlayIsStatic, overlayPriority, minSdkVersion, targetSdkVersion,
                rollbackDataPolicy);
    }

    /**
+5 −1
Original line number Diff line number Diff line
@@ -292,6 +292,7 @@ public class ApkLiteParseUtils {
        String targetPackage = null;
        boolean overlayIsStatic = false;
        int overlayPriority = 0;
        int rollbackDataPolicy = 0;

        String requiredSystemPropertyName = null;
        String requiredSystemPropertyValue = null;
@@ -369,6 +370,9 @@ public class ApkLiteParseUtils {
                        case "useEmbeddedDex":
                            useEmbeddedDex = attrs.getAttributeBooleanValue(i, false);
                            break;
                        case "rollbackDataPolicy":
                            rollbackDataPolicy = attrs.getAttributeIntValue(i, 0);
                            break;
                    }
                }
            } else if (PackageParser.TAG_OVERLAY.equals(parser.getName())) {
@@ -428,7 +432,7 @@ public class ApkLiteParseUtils {
                versionCodeMajor, revisionCode, installLocation, verifiers, signingDetails,
                coreApp, debuggable, multiArch, use32bitAbi, useEmbeddedDex, extractNativeLibs,
                isolatedSplits, targetPackage, overlayIsStatic, overlayPriority, minSdkVersion,
                targetSdkVersion);
                targetSdkVersion, rollbackDataPolicy);
    }

    public static VerifierInfo parseVerifier(AttributeSet attrs) {
+10 −0
Original line number Diff line number Diff line
@@ -1835,6 +1835,16 @@
            <enum name="discouraged" value="1" />
            <enum name="disallowed" value="2" />
        </attr>

        <!-- Declare the policy to deal with user data when rollback is committed. -->
        <attr name="rollbackDataPolicy">
            <!-- User data will be restored during rollback. -->
            <enum name="restore" value="0" />
            <!-- User data will be wiped out during rollback. -->
            <enum name="wipe" value="1" />
            <!-- User data will remain unchanged during rollback. -->
            <enum name="retain" value="2" />
        </attr>
    </declare-styleable>

    <!-- An attribution is a logical part of an app and is identified by a tag.
+1 −0
Original line number Diff line number Diff line
@@ -3022,6 +3022,7 @@
      <public name="gwpAsanMode" />
      <!-- @hide -->
      <public name="scrollCaptureHint" />
      <public name="rollbackDataPolicy" />
    </public-group>

    <public-group type="drawable" first-id="0x010800b5">
Loading