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

Commit d50a2b4e authored by Chun-Wei Wang's avatar Chun-Wei Wang Committed by Android (Google) Code Review
Browse files

Merge "Fix scan flags"

parents ae0042d7 b59f12d7
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3476,7 +3476,8 @@ final class InstallPackageHelper {
            Throwable throwable = parseResult.throwable;
            ApexInfo ai = parsingApexInfo.get(parseResult.scanFile);
            int newParseFlags = parseFlags;
            int newScanFlags = scanFlags | SCAN_AS_APEX;
            int newScanFlags = scanFlags | SCAN_AS_APEX
                    | mPm.getSystemPackageScanFlags(parseResult.scanFile);
            if (!ai.isFactory) {
                newParseFlags &= ~ParsingPackageUtils.PARSE_IS_SYSTEM_DIR;
                newScanFlags |= SCAN_NEW_INSTALL;
+23 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import java.util.function.Consumer;
@RunWith(JUnit4.class)
public class StagedInstallInternalTest {
    private static final String APK_IN_APEX_TESTAPEX_NAME = "com.android.apex.apkrollback.test";
    private static final String REBOOTLESS_APEX_PACKAGE_NAME = "test.apex.rebootless";
    private static final TestApp TEST_APEX_WITH_APK_V2 = new TestApp("TestApexWithApkV2",
            APK_IN_APEX_TESTAPEX_NAME, 2, /*isApex*/true, APK_IN_APEX_TESTAPEX_NAME + "_v2.apex");
    private static final TestApp APEX_WRONG_SHA_V2 = new TestApp(
@@ -594,6 +595,28 @@ public class StagedInstallInternalTest {
        assertThat(InstallUtils.getInstalledVersion(packageName)).isEqualTo(1);
    }

    @Test
    public void testVendorApex_VerifyFactory() throws Exception {
        final PackageManager pm =
                InstrumentationRegistry.getInstrumentation().getContext().getPackageManager();
        PackageInfo pi = pm.getPackageInfo(REBOOTLESS_APEX_PACKAGE_NAME, PackageManager.MATCH_APEX);
        assertThat(pi.getLongVersionCode()).isEqualTo(1);
        assertThat(pi.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR)
                .isEqualTo(ApplicationInfo.PRIVATE_FLAG_VENDOR);
        assertThat(pi.applicationInfo.sourceDir).startsWith("/vendor/apex");
    }

    @Test
    public void testVendorApex_VerifyData() throws Exception {
        final PackageManager pm =
                InstrumentationRegistry.getInstrumentation().getContext().getPackageManager();
        PackageInfo pi = pm.getPackageInfo(REBOOTLESS_APEX_PACKAGE_NAME, PackageManager.MATCH_APEX);
        assertThat(pi.getLongVersionCode()).isEqualTo(2);
        assertThat(pi.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR)
                .isEqualTo(ApplicationInfo.PRIVATE_FLAG_VENDOR);
        assertThat(pi.applicationInfo.sourceDir).startsWith("/data/apex");
    }

    private IPackageManagerNative getPackageManagerNative() {
        IBinder binder = ServiceManager.waitForService("package_native");
        assertThat(binder).isNotNull();
+35 −1
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
    private static final String APK_IN_APEX_TESTAPEX_NAME = "com.android.apex.apkrollback.test";
    private static final String APEXD_TEST_APEX = "apex.apexd_test.apex";
    private static final String FAKE_APEX_SYSTEM_SERVER_APEX = "test_com.android.server.apex";
    private static final String REBOOTLESS_V1 = "test.rebootless_apex_v1.apex";
    private static final String REBOOTLESS_V2 = "test.rebootless_apex_v2.apex";

    private static final String TEST_VENDOR_APEX_ALLOW_LIST =
            "/vendor/etc/sysconfig/test-vendor-apex-allow-list.xml";
@@ -94,6 +96,7 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
                "/data/apex/active/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex",
                "/data/apex/active/" + SHIM_APEX_PACKAGE_NAME + "*.apex",
                "/system/apex/test.rebootless_apex_v*.apex",
                "/vendor/apex/test.rebootless_apex_v*.apex",
                "/data/apex/active/test.apex.rebootless*.apex",
                "/system/app/TestApp/TestAppAv1.apk",
                TEST_VENDOR_APEX_ALLOW_LIST);
@@ -137,13 +140,17 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
    }

    private void pushTestApex(String fileName) throws Exception {
        pushTestApex(fileName, "system");
    }

    private void pushTestApex(String fileName, String partition) throws Exception {
        CompatibilityBuildHelper buildHelper = new CompatibilityBuildHelper(getBuild());
        final File apex = buildHelper.getTestFile(fileName);
        if (!getDevice().isAdbRoot()) {
            getDevice().enableAdbRoot();
        }
        getDevice().remountSystemWritable();
        assertTrue(getDevice().pushFile(apex, "/system/apex/" + fileName));
        assertTrue(getDevice().pushFile(apex, "/" + partition + "/apex/" + fileName));
    }

    private void pushTestVendorApexAllowList(String installerPackageName) throws Exception {
@@ -497,6 +504,33 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        runPhase("testVendorApexCorrectInstaller_nonStaged");
    }

    /**
     * Tests correctness of {@link android.content.pm.ApplicationInfo} for APEXes on /vendor.
     */
    @Test
    @LargeTest
    public void testVendorApex_Staged() throws Exception {
        pushTestApex(REBOOTLESS_V1, "vendor");
        getDevice().reboot();
        runPhase("testVendorApex_VerifyFactory");
        installPackage(REBOOTLESS_V2, "--staged");
        getDevice().reboot();
        runPhase("testVendorApex_VerifyData");
    }

    /**
     * Tests correctness of {@link android.content.pm.ApplicationInfo} for APEXes on /vendor.
     */
    @Test
    @LargeTest
    public void testVendorApex_NonStaged() throws Exception {
        pushTestApex(REBOOTLESS_V1, "vendor");
        getDevice().reboot();
        runPhase("testVendorApex_VerifyFactory");
        installPackage(REBOOTLESS_V2, "--force-non-staged");
        runPhase("testVendorApex_VerifyData");
    }

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