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

Commit 9c6e07a7 authored by JW Wang's avatar JW Wang Committed by Android (Google) Code Review
Browse files

Merge changes from topic "bug195517333"

* changes:
  Support rollback for rebootless apex (2/n)
  Handle downgrade install for rebootless apexes correctly (1/n)
parents e0af999e 858845f7
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -1035,17 +1035,6 @@ public abstract class ApexManager {
            }
        }

        private void checkDowngrade(PackageInfo existingApexPkg, PackageInfo newApexPkg)
                throws PackageManagerException {
            final long currentVersionCode = existingApexPkg.applicationInfo.longVersionCode;
            final long newVersionCode = newApexPkg.applicationInfo.longVersionCode;
            if (currentVersionCode > newVersionCode) {
                throw new PackageManagerException(PackageManager.INSTALL_FAILED_VERSION_DOWNGRADE,
                          "Downgrade of APEX package " + newApexPkg.packageName
                                  + " is not allowed");
            }
        }

        @Override
        void installPackage(File apexFile, PackageParser2 packageParser)
                throws PackageManagerException {
@@ -1069,7 +1058,6 @@ public abstract class ApexManager {
                            "It is forbidden to install new APEX packages");
                }
                checkApexSignature(existingApexPkg, newApexPkg);
                checkDowngrade(existingApexPkg, newApexPkg);
                ApexInfo apexInfo = waitForApexService().installAndActivatePackage(
                        apexFile.getAbsolutePath());
                final ParsedPackage parsedPackage2 = packageParser.parsePackage(
+0 −5
Original line number Diff line number Diff line
@@ -688,11 +688,6 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
            if (params.isMultiPackage) {
                throw new IllegalArgumentException("A multi-session can't be set as APEX.");
            }
            if (!params.isStaged
                    && (params.installFlags & PackageManager.INSTALL_ENABLE_ROLLBACK) != 0) {
                throw new IllegalArgumentException(
                    "Non-staged APEX session doesn't support INSTALL_ENABLE_ROLLBACK");
            }
            if (isCalledBySystemOrShell(callingUid) || mBypassNextAllowedApexUpdateCheck) {
                params.installFlags |= PackageManager.INSTALL_DISABLE_ALLOWED_APEX_UPDATE_CHECK;
            } else {
+5 −0
Original line number Diff line number Diff line
@@ -843,6 +843,11 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub implements Rollba
        final String packageName = newPackage.getPackageName();
        final int rollbackDataPolicy = computeRollbackDataPolicy(
                session.rollbackDataPolicy, newPackage.getRollbackDataPolicy());
        if (!session.isStaged() && (installFlags & PackageManager.INSTALL_APEX) != 0
                && rollbackDataPolicy != PackageManager.ROLLBACK_DATA_POLICY_RETAIN) {
            Slog.e(TAG, "Only RETAIN is supported for rebootless APEX: " + packageName);
            return false;
        }
        Slog.i(TAG, "Enabling rollback for install of " + packageName
                + ", session:" + session.sessionId
                + ", rollbackDataPolicy=" + rollbackDataPolicy);
+0 −18
Original line number Diff line number Diff line
@@ -347,24 +347,6 @@ public class ApexManagerTest {
        assertThat(e).hasMessageThat().contains("It is forbidden to install new APEX packages");
    }

    @Test
    public void testInstallPackageDowngrade() throws Exception {
        File activeApex = extractResource("test.apex_rebootless_v2",
                "test.rebootless_apex_v2.apex");
        ApexInfo activeApexInfo = createApexInfo("test.apex_rebootless", 2, /* isActive= */ true,
                /* isFactory= */ false, activeApex);
        when(mApexService.getAllPackages()).thenReturn(new ApexInfo[]{activeApexInfo});
        mApexManager.scanApexPackagesTraced(mPackageParser2,
                ParallelPackageParser.makeExecutorService());

        File installedApex = extractResource("test.apex_rebootless_v1",
                "test.rebootless_apex_v1.apex");
        PackageManagerException e = expectThrows(PackageManagerException.class,
                () -> mApexManager.installPackage(installedApex, mPackageParser2));
        assertThat(e).hasMessageThat().contains(
                "Downgrade of APEX package test.apex.rebootless is not allowed");
    }

    @Test
    public void testInstallPackage_activeOnSystem() throws Exception {
        ApexInfo activeApexInfo = createApexInfo("test.apex_rebootless", 1, /* isActive= */ true,
+6 −2
Original line number Diff line number Diff line
@@ -31,7 +31,8 @@ android_test {
    test_config: "RollbackTest.xml",
    java_resources: [
        ":com.android.apex.apkrollback.test_v2",
        ":com.android.apex.apkrollback.test_v2Crashing"
        ":com.android.apex.apkrollback.test_v2Crashing",
        ":test.rebootless_apex_v2",
    ],
}

@@ -47,7 +48,10 @@ java_test_host {
    ],
    test_suites: ["general-tests"],
    test_config: "StagedRollbackTest.xml",
    data: [":com.android.apex.apkrollback.test_v1"],
    data: [
        ":com.android.apex.apkrollback.test_v1",
        ":test.rebootless_apex_v1",
    ],
}

java_test_host {
Loading