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

Commit 62e67203 authored by Lee Shombert's avatar Lee Shombert
Browse files

Disable snapshots for mocked tests

Bug: 180107750

Disable snapshots inside the PackageManagerService test constructor.
Enable snapshots inside the PackageManagerService "operational"
constructor.  The global constant SNAPSHOT_ENABLE is still used.

When snapshots are disabled, do not register any observers.

Test: atest
 * FrameworksServicesTests:AppsFilterTest
 * FrameworksServicesTests:PackageInstallerSessionTest
 * FrameworksServicesTests:PackageManagerServiceTest
 * FrameworksServicesTests:PackageManagerSettingsTests
 * FrameworksServicesTests:ScanTests
 * FrameworksServicesTests:UserSystemPackageInstallerTest
 * PackageManagerServiceBootTest
 * UserLifecycleTests#startUser
 * UserLifecycleTests#stopUser
 * UserLifecycleTests#switchUser
 * android.appsecurity.cts.EphemeralTest
 * android.appsecurity.cts.InstantAppUserTest

Change-Id: I4eb66ffd4d59a7981868691c58b4b237cb6b206f
parent 0c89d4b8
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -4701,6 +4701,10 @@ public class PackageManagerService extends IPackageManager.Stub
    // and an image with the flag set false does not use snapshots.
    private static final boolean SNAPSHOT_ENABLED = true;
    // The per-instance snapshot disable/enable flag.  This is generally set to false in
    // test instances and set to SNAPSHOT_ENABLED in operational instances.
    private final boolean mSnapshotEnabled;
    /**
     * Return the live computer.
     */
@@ -4713,7 +4717,7 @@ public class PackageManagerService extends IPackageManager.Stub
     * The live computer will be returned if snapshots are disabled.
     */
    private Computer snapshotComputer() {
        if (!SNAPSHOT_ENABLED) {
        if (!mSnapshotEnabled) {
            return mLiveComputer;
        }
        if (Thread.holdsLock(mLock)) {
@@ -6048,15 +6052,12 @@ public class PackageManagerService extends IPackageManager.Stub
        mOverlayConfigSignaturePackage = testParams.overlayConfigSignaturePackage;
        mResolveComponentName = testParams.resolveComponentName;
        // Create the computer as soon as the state objects have been installed.  The
        // cached computer is the same as the live computer until the end of the
        // constructor, at which time the invalidation method updates it.  The cache is
        // corked initially to ensure a cached computer is not built until the end of the
        // constructor.
        sSnapshotCorked = true;
        // Disable snapshots in this instance of PackageManagerService, which is only used
        // for testing.  The instance still needs a live computer.  The snapshot computer
        // is set to null since it must never be used by this instance.
        mSnapshotEnabled = false;
        mLiveComputer = createLiveComputer();
        mSnapshotComputer = mLiveComputer;
        registerObserver();
        mSnapshotComputer = null;
        mPackages.putAll(testParams.packages);
        mEnableFreeCacheV2 = testParams.enableFreeCacheV2;
@@ -6069,7 +6070,6 @@ public class PackageManagerService extends IPackageManager.Stub
        mIncrementalVersion = testParams.incrementalVersion;
        invalidatePackageInfoCache();
        sSnapshotCorked = false;
    }
    public PackageManagerService(Injector injector, boolean onlyCore, boolean factoryTest,
@@ -6215,6 +6215,7 @@ public class PackageManagerService extends IPackageManager.Stub
        // constructor, at which time the invalidation method updates it.  The cache is
        // corked initially to ensure a cached computer is not built until the end of the
        // constructor.
        mSnapshotEnabled = SNAPSHOT_ENABLED;
        sSnapshotCorked = true;
        mLiveComputer = createLiveComputer();
        mSnapshotComputer = mLiveComputer;