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

Commit f012f582 authored by Jackal Guo's avatar Jackal Guo
Browse files

Fix the dervied fileds in ApplicationInfo are missing for APEXes

This is a quick fix for solving the problem of missing dervied fileds
in app info for APEXes.

Bug: 215198278
Test: atest StagedInstallInternalTest#testGetAppInfo_flagTestOnlyIsSet
Test: Verify if the FLAG_TEST_ONLY bit is set in the ApplicationInfo
      of test_com.android.server via pm dump command.
Change-Id: I065c3496ede3e7e3a01f8e0f1b6803b1e6341e89
parent 8d6f835e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -580,6 +580,8 @@ public abstract class ApexManager {
                ApexInfo ai = parsingApexInfo.get(parseResult.scanFile);

                if (throwable == null) {
                    // Calling hideAsFinal to assign derived fields for the app info flags.
                    parseResult.parsedPackage.hideAsFinal();
                    final PackageInfo packageInfo = PackageInfoWithoutStateUtils.generate(
                            parseResult.parsedPackage, ai, flags);
                    if (packageInfo == null) {
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ java_test_host {
        ":TestAppAv1",
        ":test.rebootless_apex_v1",
        ":test.rebootless_apex_v2",
        ":test_com.android.server",
    ],
    test_suites: ["general-tests"],
    test_config: "StagedInstallInternalTest.xml",
+13 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.content.pm.IStagedApexObserver;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.ApplicationInfoFlags;
import android.content.pm.StagedApexInfo;
import android.os.IBinder;
import android.os.ServiceManager;
@@ -80,6 +81,8 @@ public class StagedInstallInternalTest {
            TEST_APEX_PACKAGE_NAME, 1, /*isApex=*/true,
            "apex.apexd_test_classpath.apex");

    private static final String TEST_APEX_SYSTEM_SERVER_PACKAGE_NAME = "test_com.android.server";

    private File mTestStateFile = new File(
            InstrumentationRegistry.getInstrumentation().getContext().getFilesDir(),
            "stagedinstall_state");
@@ -483,6 +486,16 @@ public class StagedInstallInternalTest {
        InstallUtils.openPackageInstallerSession(sessionId).abandon();
    }

    @Test
    public void testGetAppInfo_flagTestOnlyIsSet() throws Exception {
        final PackageManager pm =
                InstrumentationRegistry.getInstrumentation().getContext().getPackageManager();
        final ApplicationInfo info = pm.getApplicationInfo(TEST_APEX_SYSTEM_SERVER_PACKAGE_NAME,
                ApplicationInfoFlags.of(PackageManager.MATCH_APEX));
        assertThat(info).isNotNull();
        assertThat((info.flags & ApplicationInfo.FLAG_TEST_ONLY) != 0).isTrue();
    }

    public static class MockStagedApexObserver extends IStagedApexObserver.Stub {
        @Override
        public void onApexStaged(ApexStagedEvent event) {
+13 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
    private static final String APK_A = "TestAppAv1.apk";
    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 TEST_VENDOR_APEX_ALLOW_LIST =
            "/vendor/etc/sysconfig/test-vendor-apex-allow-list.xml";
@@ -512,6 +513,18 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        runPhase("testGetStagedApexInfo");
    }

    @Test
    @LargeTest
    public void testGetAppInfo_flagTestOnlyIsSet() throws Exception {
        assumeTrue("Device does not support updating APEX",
                mHostUtils.isApexUpdateSupported());

        pushTestApex(FAKE_APEX_SYSTEM_SERVER_APEX);
        getDevice().reboot();

        runPhase("testGetAppInfo_flagTestOnlyIsSet");
    }

    @Test
    public void testStagedApexObserver() throws Exception {
        assumeTrue("Device does not support updating APEX",