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

Commit 777ee948 authored by Nikita Ioffe's avatar Nikita Ioffe Committed by Automerger Merge Worker
Browse files

Merge "Treat APEX installs as upgrades" into sc-dev am: bdf97e12

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15245531

Change-Id: I415022682ed3d58501a2b7d6c22cce957ddb2db2
parents e1c1fcec bdf97e12
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -957,7 +957,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                android.Manifest.permission.UPDATE_PACKAGES_WITHOUT_USER_ACTION, mInstallerUid)
                == PackageManager.PERMISSION_GRANTED);
        final int targetPackageUid = mPm.getPackageUid(packageName, 0, userId);
        final boolean isUpdate = targetPackageUid != -1;
        final boolean isUpdate = targetPackageUid != -1 || isApexSession();
        final InstallSourceInfo existingInstallSourceInfo = isUpdate
                ? mPm.getInstallSourceInfo(packageName)
                : null;
+3 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ android_test_helper_app {
    java_resources: [
        ":com.android.apex.apkrollback.test_v2",
        ":StagedInstallTestApexV2_WrongSha",
        ":test.rebootless_apex_v1",
        ":test.rebootless_apex_v2",
    ],
}

@@ -54,6 +56,7 @@ java_test_host {
        ":com.android.apex.cts.shim.v2_prebuilt",
        ":StagedInstallTestApexV2_WrongSha",
        ":TestAppAv1",
        ":test.rebootless_apex_v1",
    ],
    test_suites: ["general-tests"],
    test_config: "StagedInstallInternalTest.xml",
+34 −0
Original line number Diff line number Diff line
@@ -23,7 +23,10 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import android.Manifest;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;

import androidx.test.platform.app.InstrumentationRegistry;

@@ -192,6 +195,37 @@ public class StagedInstallInternalTest {
        assertSessionFailedWithMessage(sessionId, "has unexpected SHA512 hash");
    }

    @Test
    public void testRebootlessUpdates() throws Exception {
        InstallUtils.dropShellPermissionIdentity();
        InstallUtils.adoptShellPermissionIdentity(Manifest.permission.INSTALL_PACKAGE_UPDATES);

        final PackageManager pm =
                InstrumentationRegistry.getInstrumentation().getContext().getPackageManager();
        {
            PackageInfo apex = pm.getPackageInfo("test.apex.rebootless", PackageManager.MATCH_APEX);
            assertThat(apex.getLongVersionCode()).isEqualTo(1);
            assertThat(apex.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)
                    .isEqualTo(ApplicationInfo.FLAG_SYSTEM);
            assertThat(apex.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)
                    .isEqualTo(ApplicationInfo.FLAG_INSTALLED);
            assertThat(apex.applicationInfo.sourceDir).startsWith("/system/apex");
        }

        TestApp apex2 = new TestApp("TestRebootlessApexV1", "test.apex.rebootless", 2,
                /* isApex= */ true, "test.rebootless_apex_v2.apex");
        Install.single(apex2).commit();

        {
            PackageInfo apex = pm.getPackageInfo("test.apex.rebootless", PackageManager.MATCH_APEX);
            assertThat(apex.getLongVersionCode()).isEqualTo(2);
            assertThat(apex.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM).isEqualTo(0);
            assertThat(apex.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)
                    .isEqualTo(ApplicationInfo.FLAG_INSTALLED);
            assertThat(apex.applicationInfo.sourceDir).startsWith("/data/apex/active");
        }
    }

    private static void assertSessionFailedWithMessage(int sessionId, String msg) {
        assertSessionState(sessionId, (session) -> {
            assertThat(session.isStagedSessionFailed()).isTrue();
+11 −4
Original line number Diff line number Diff line
@@ -85,7 +85,9 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        }
        deleteFiles("/system/apex/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex",
                "/data/apex/active/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex",
                "/data/apex/active/" + SHIM_APEX_PACKAGE_NAME + "*.apex");
                "/data/apex/active/" + SHIM_APEX_PACKAGE_NAME + "*.apex",
                "/system/apex/test.rebootless_apex_v1.apex",
                "/data/apex/active/test.apex.rebootless*.apex");
    }

    @Before
@@ -124,9 +126,8 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        }
    }

    private void pushTestApex() throws Exception {
    private void pushTestApex(String fileName) throws Exception {
        CompatibilityBuildHelper buildHelper = new CompatibilityBuildHelper(getBuild());
        final String fileName = APK_IN_APEX_TESTAPEX_NAME + "_v1.apex";
        final File apex = buildHelper.getTestFile(fileName);
        if (!getDevice().isAdbRoot()) {
            getDevice().enableAdbRoot();
@@ -142,7 +143,7 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
    @Test
    @LargeTest
    public void testDuplicateApkInApexShouldFail() throws Exception {
        pushTestApex();
        pushTestApex(APK_IN_APEX_TESTAPEX_NAME + "_v1.apex");
        runPhase("testDuplicateApkInApexShouldFail_Commit");
        getDevice().reboot();
        runPhase("testDuplicateApkInApexShouldFail_Verify");
@@ -344,6 +345,12 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        runPhase("testApexActivationFailureIsCapturedInSession_Verify");
    }

    @Test
    public void testRebootlessUpdates() throws Exception {
        pushTestApex("test.rebootless_apex_v1.apex");
        runPhase("testRebootlessUpdates");
    }

    private List<String> getStagingDirectories() throws DeviceNotAvailableException {
        String baseDir = "/data/app-staging";
        try {