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

Commit 6acd2bda authored by JW Wang's avatar JW Wang
Browse files

Ensure no state changes after mDestroyed=true (4/n)

mDestroyed=true is a terminal state. No more state changes should happen
after reaching the final state.

Since abandon() can be called at any moment, checking mDestroyed and
setting mCommitted/mRelinquished must be done in the same synchronization
block to prevent state changes after mDestroyed=true.

Bug: 161765186
Test: atest StagedInstallTest AtomicInstallTest StagedInstallInternalTest
Change-Id: I301ab7d89332cfbf14bd69b7b2601fe26bd0eaf3
parent 061a28c7
Loading
Loading
Loading
Loading
+17 −15
Original line number Diff line number Diff line
@@ -1497,6 +1497,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            }

            synchronized (mLock) {
                if (mDestroyed) {
                    throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
                            "Session destroyed");
                }
                // Client staging is fully done at this point
                mClientProgress = 1f;
                computeProgressLocked(true);
@@ -1839,21 +1843,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            throws PackageManagerException {
        assertNotLocked("makeSessionActive");

        synchronized (mLock) {
            if (mRelinquished) {
                throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
                        "Session relinquished");
            }
            if (mDestroyed) {
                throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
                        "Session destroyed");
            }
            if (!mSealed) {
                throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
                        "Session not sealed");
            }
        }

        // TODO(b/159331446): Move this to makeSessionActiveForInstall and update javadoc
        if (!params.isMultiPackage && needToAskForPermissions()) {
            // User needs to confirm installation;
@@ -1883,6 +1872,19 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    @GuardedBy("mLock")
    private PackageManagerService.VerificationParams makeVerificationParamsLocked()
            throws PackageManagerException {
        if (mRelinquished) {
            throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
                    "Session relinquished");
        }
        if (mDestroyed) {
            throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
                    "Session destroyed");
        }
        if (!mSealed) {
            throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
                    "Session not sealed");
        }

        // TODO(b/136257624): Some logic in this if block probably belongs in
        //  makeInstallParams().
        if (!params.isMultiPackage && !isApexInstallation()) {