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

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

Merge "Remove PackageManagerInternal#pruneCachedApksInApex"

parents a78ea6e4 00053b24
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -502,12 +502,6 @@ public abstract class PackageManagerInternal {
     */
    public abstract void pruneInstantApps();

    /**
     * Prunes the cache of the APKs in the given APEXes.
     * @param apexPackageNames The list of APEX package names that may contain APK-in-APEX.
     */
    public abstract void pruneCachedApksInApex(@NonNull List<String> apexPackageNames);

    /**
     * @return The SetupWizard package name.
     */
+0 −21
Original line number Diff line number Diff line
@@ -201,7 +201,6 @@ import com.android.server.pm.dex.ArtManagerService;
import com.android.server.pm.dex.ArtUtils;
import com.android.server.pm.dex.DexManager;
import com.android.server.pm.dex.ViewCompiler;
import com.android.server.pm.parsing.PackageCacher;
import com.android.server.pm.parsing.PackageInfoUtils;
import com.android.server.pm.parsing.PackageParser2;
import com.android.server.pm.parsing.pkg.AndroidPackage;
@@ -6174,26 +6173,6 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            }
        }

        @Override
        public void pruneCachedApksInApex(@NonNull List<String> apexPackageNames) {
            if (mCacheDir == null) {
                return;
            }

            final PackageCacher cacher = new PackageCacher(mCacheDir);
            synchronized (mLock) {
                final Computer snapshot = snapshot();
                for (int i = 0, size = apexPackageNames.size(); i < size; i++) {
                    final List<String> apkNames =
                            mApexManager.getApksInApex(apexPackageNames.get(i));
                    for (int j = 0, apksInApex = apkNames.size(); j < apksInApex; j++) {
                        final AndroidPackage pkg = snapshot.getPackage(apkNames.get(j));
                        cacher.cleanCachedResult(new File(pkg.getPath()));
                    }
                }
            }
        }

        @Override
        public void setExternalSourcesPolicy(ExternalSourcesPolicy policy) {
            if (policy != null) {
+2 −7
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.content.Intent;
import android.content.pm.IPackageInstallObserver2;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.SigningDetails;
import android.content.pm.parsing.result.ParseResult;
import android.content.pm.parsing.result.ParseTypeImpl;
@@ -325,10 +324,7 @@ final class PackageSessionVerifier {
        // APEX checks. For single-package sessions, check if they contain an APEX. For
        // multi-package sessions, find all the child sessions that contain an APEX.
        if (hasApex) {
            final List<String> apexPackageNames = submitSessionToApexService(session, rollbackId);
            final PackageManagerInternal packageManagerInternal =
                    LocalServices.getService(PackageManagerInternal.class);
            packageManagerInternal.pruneCachedApksInApex(apexPackageNames);
            submitSessionToApexService(session, rollbackId);
        }
    }

@@ -372,7 +368,7 @@ final class PackageSessionVerifier {
        }
    }

    private List<String> submitSessionToApexService(StagingManager.StagedSession session,
    private void submitSessionToApexService(StagingManager.StagedSession session,
            int rollbackId) throws PackageManagerException {
        final IntArray childSessionIds = new IntArray();
        if (session.isMultiPackage()) {
@@ -412,7 +408,6 @@ final class PackageSessionVerifier {
        }
        Slog.d(TAG, "Session " + session.sessionId() + " has following APEX packages: "
                + apexPackageNames);
        return apexPackageNames;
    }

    private int retrieveRollbackIdForCommitSession(int sessionId) throws PackageManagerException {
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ java_test_host {
    data: [
        ":apex.apexd_test",
        ":com.android.apex.apkrollback.test_v1",
        ":com.android.apex.apkrollback.test_v2",
        ":StagedInstallTestApexV2",
        ":StagedInstallTestApexV2_WrongSha",
        ":TestAppAv1",
+23 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
import com.android.ddmlib.Log;
import com.android.tests.rollback.host.AbandonSessionsRule;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.PackageInfo;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
import com.android.tradefed.util.CommandResult;
@@ -203,6 +204,28 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        runPhase("testDuplicateApkInApexShouldFail_Verify");
    }

    /**
     * Tests the cache of apk-in-apex is pruned and rebuilt correctly.
     */
    @Test
    @LargeTest
    public void testApkInApexPruneCache() throws Exception {
        final String apkInApexPackageName = "com.android.cts.install.lib.testapp.A";

        pushTestApex(APK_IN_APEX_TESTAPEX_NAME + "_v1.apex");
        getDevice().reboot();
        PackageInfo pi = getDevice().getAppPackageInfo(apkInApexPackageName);
        assertThat(Integer.parseInt(pi.getVersionCode())).isEqualTo(1);
        assertThat(pi.getCodePath()).startsWith("/apex/" + APK_IN_APEX_TESTAPEX_NAME);

        installPackage(APK_IN_APEX_TESTAPEX_NAME + "_v2.apex", "--staged");
        getDevice().reboot();
        pi = getDevice().getAppPackageInfo(apkInApexPackageName);
        // The version code of apk-in-apex will be stale if the cache is not rebuilt
        assertThat(Integer.parseInt(pi.getVersionCode())).isEqualTo(2);
        assertThat(pi.getCodePath()).startsWith("/apex/" + APK_IN_APEX_TESTAPEX_NAME);
    }

    @Test
    public void testSystemServerRestartDoesNotAffectStagedSessions() throws Exception {
        runPhase("testSystemServerRestartDoesNotAffectStagedSessions_Commit");