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

Commit 759b24a0 authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam
Browse files

Simplify handleStartCopy by extracting logic into separate methods

Also renamed mVerificationCompleted and others variables + simplified
logics surrounding their use.

Bug: 136257624
Test: atest GtsSecurityHostTestCases
Change-Id: Ic5ce2741de11afed7be749c49617a880ac8ffe21
parent cf70e8f1
Loading
Loading
Loading
Loading
+126 −120
Original line number Diff line number Diff line
@@ -14638,9 +14638,9 @@ public class PackageManagerService extends IPackageManager.Stub
        int installFlags;
        @NonNull final InstallSource installSource;
        final String volumeUuid;
        private boolean mVerificationCompleted;
        private boolean mIntegrityVerificationCompleted;
        private boolean mEnableRollbackCompleted;
        private boolean mWaitForVerificationToComplete;
        private boolean mWaitForIntegrityVerificationToComplete;
        private boolean mWaitForEnableRollbackToComplete;
        private InstallArgs mArgs;
        int mRet;
        final String packageAbiOverride;
@@ -14805,16 +14805,15 @@ public class PackageManagerService extends IPackageManager.Stub
            return pkgLite.recommendedInstallLocation;
        }
        /*
         * Invoke remote method to get package information and install
         * location values. Override install location based on default
         * policy if needed and then create install arguments based
         * on the install location.
        /**
         * Override install location based on default policy if needed.
         *
         * Only {@link #installFlags} and {@link #mRet} are mutated in this method.
         *
         * Only {@link PackageManager#INSTALL_INTERNAL} flag is mutated in
         * {@link #installFlags}
         */
        public void handleStartCopy() {
            PackageInfoLite pkgLite = PackageManagerServiceUtils.getMinimalPackageInfo(mContext,
                    origin.resolvedPath, installFlags, packageAbiOverride);
        private void overrideInstallLocation(PackageInfoLite pkgLite) {
            final boolean ephemeral = (installFlags & PackageManager.INSTALL_INSTANT_APP) != 0;
            if (DEBUG_INSTANT && ephemeral) {
                Slog.v(TAG, "pkgLite for install: " + pkgLite);
@@ -14898,17 +14897,35 @@ public class PackageManagerService extends IPackageManager.Stub
                    }
                }
            }
            mRet = ret;
        }
            mVerificationCompleted = true;
            mIntegrityVerificationCompleted = true;
            mEnableRollbackCompleted = true;
        /*
         * Invoke remote method to get package information and install
         * location values. Override install location based on default
         * policy if needed and then create install arguments based
         * on the install location.
         */
        public void handleStartCopy() {
            PackageInfoLite pkgLite = PackageManagerServiceUtils.getMinimalPackageInfo(mContext,
                    origin.resolvedPath, installFlags, packageAbiOverride);
            overrideInstallLocation(pkgLite);
            // Now that installFlags is finalized, we can create an immutable InstallArgs
            mArgs = createInstallArgs(this);
            // Perform package verification and enable rollback (unless we are simply moving the
            // package).
            if (ret == PackageManager.INSTALL_SUCCEEDED && !origin.existing) {
            if (mRet == PackageManager.INSTALL_SUCCEEDED && !origin.existing) {
                sendApkVerificationRequest(pkgLite);
                if ((installFlags & PackageManager.INSTALL_ENABLE_ROLLBACK) != 0) {
                    sendEnableRollbackRequest();
                }
            }
        }
        void sendApkVerificationRequest(PackageInfoLite pkgLite) {
            final int verificationId = mPendingVerificationToken++;
            PackageVerificationState verificationState =
@@ -14916,15 +14933,16 @@ public class PackageManagerService extends IPackageManager.Stub
            mPendingVerification.append(verificationId, verificationState);
            sendIntegrityVerificationRequest(verificationId, pkgLite, verificationState);
                ret = sendPackageVerificationRequest(
            mRet = sendPackageVerificationRequest(
                    verificationId, pkgLite, verificationState);
            // If both verifications are skipped, we should remove the state.
            if (verificationState.areAllVerificationsComplete()) {
                mPendingVerification.remove(verificationId);
            }
        }
                if ((installFlags & PackageManager.INSTALL_ENABLE_ROLLBACK) != 0) {
        void sendEnableRollbackRequest() {
            final int enableRollbackToken = mPendingEnableRollbackToken++;
            Trace.asyncTraceBegin(
                    TRACE_TAG_PACKAGE_MANAGER, "enable_rollback", enableRollbackToken);
@@ -14968,11 +14986,7 @@ public class PackageManagerService extends IPackageManager.Stub
                        }
                    }, null, 0, null, null);
                    mEnableRollbackCompleted = false;
                }
            }
            mRet = ret;
            mWaitForEnableRollbackToComplete = true;
        }
        /**
@@ -15036,7 +15050,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    TRACE_TAG_PACKAGE_MANAGER, "integrity_verification", verificationId);
            // stop the copy until verification succeeds.
            mIntegrityVerificationCompleted = false;
            mWaitForIntegrityVerificationToComplete = true;
        }
        /**
@@ -15173,7 +15187,7 @@ public class PackageManagerService extends IPackageManager.Stub
                     * We don't want the copy to proceed until verification
                     * succeeds.
                     */
                    mVerificationCompleted = false;
                    mWaitForVerificationToComplete = true;
                }
            } else {
                verificationState.setVerifierResponse(
@@ -15215,37 +15229,30 @@ public class PackageManagerService extends IPackageManager.Stub
        }
        void handleVerificationFinished() {
            if (!mVerificationCompleted) {
                mVerificationCompleted = true;
                if (mIntegrityVerificationCompleted) {
            mWaitForVerificationToComplete = false;
            handleReturnCode();
        }
                // integrity verification still pending.
            }
        }
        void handleIntegrityVerificationFinished() {
            if (!mIntegrityVerificationCompleted) {
                mIntegrityVerificationCompleted = true;
                if (mVerificationCompleted) {
            mWaitForIntegrityVerificationToComplete = false;
            handleReturnCode();
        }
                // verifier still pending
            }
        }
        void handleRollbackEnabled() {
            // TODO(ruhler) b/112431924: Consider halting the install if we
            // couldn't enable rollback.
            mEnableRollbackCompleted = true;
            mWaitForEnableRollbackToComplete = false;
            handleReturnCode();
        }
        @Override
        void handleReturnCode() {
            if (mVerificationCompleted
                    && mIntegrityVerificationCompleted && mEnableRollbackCompleted) {
            if (mWaitForVerificationToComplete || mWaitForIntegrityVerificationToComplete
                    || mWaitForEnableRollbackToComplete) {
                return;
            }
            if ((installFlags & PackageManager.INSTALL_DRY_RUN) != 0) {
                String packageName = "";
                ParseResult<PackageLite> result = ApkLiteParseUtils.parsePackageLite(
@@ -15277,7 +15284,6 @@ public class PackageManagerService extends IPackageManager.Stub
            processPendingInstall(mArgs, mRet);
        }
    }
    }
    private InstallArgs createInstallArgs(InstallParams params) {
        if (params.move != null) {