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

Commit 44ad95be authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam
Browse files

Allow StagingManager to abort individual staged session

Now that apexd can stage multiple sessions, we need to be able to abort
specific staged session during pre-reboot verification. The only need to
abort activated session while resuming staged session during boot.

Bug: 141843321
Test: atest StagedInstallTest
Change-Id: I97d4216e1fe9ec6c98474ec12f4046b002d9edda
parent 2dfc86af
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -208,6 +208,13 @@ abstract class ApexManager {
     */
    abstract boolean abortActiveSession();

    /**
     * Abandons the staged session with the given sessionId.
     *
     * @return {@code true} upon success, {@code false} if any remote exception occurs
     */
    abstract boolean abortStagedSession(int sessionId) throws PackageManagerException;

    /**
     * Uninstalls given {@code apexPackage}.
     *
@@ -495,6 +502,21 @@ abstract class ApexManager {
            }
        }

        @Override
        boolean abortStagedSession(int sessionId) throws PackageManagerException {
            try {
                mApexService.abortStagedSession(sessionId);
                return true;
            } catch (RemoteException re) {
                Slog.e(TAG, "Unable to contact apexservice", re);
                return false;
            } catch (Exception e) {
                throw new PackageManagerException(
                        PackageInstaller.SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
                        "Failed to abort staged session : " + e.getMessage());
            }
        }

        @Override
        boolean uninstallApex(String apexPackagePath) {
            try {
@@ -682,6 +704,11 @@ abstract class ApexManager {
            throw new UnsupportedOperationException();
        }

        @Override
        boolean abortStagedSession(int sessionId) throws PackageManagerException {
            throw new UnsupportedOperationException();
        }

        @Override
        boolean uninstallApex(String apexPackagePath) {
            throw new UnsupportedOperationException();
+6 −3
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ public class StagingManager {
        }
        final long activeVersion = activePackage.applicationInfo.longVersionCode;
        if (activeVersion != session.params.requiredInstalledVersionCode) {
            if (!mApexManager.abortActiveSession()) {
            if (!mApexManager.abortStagedSession(session.sessionId)) {
                Slog.e(TAG, "Failed to abort apex session " + session.sessionId);
            }
            throw new PackageManagerException(
@@ -231,7 +231,7 @@ public class StagingManager {
        final boolean allowsDowngrade = PackageManagerServiceUtils.isDowngradePermitted(
                session.params.installFlags, activePackage.applicationInfo.flags);
        if (activeVersion > newVersionCode && !allowsDowngrade) {
            if (!mApexManager.abortActiveSession()) {
            if (!mApexManager.abortStagedSession(session.sessionId)) {
                Slog.e(TAG, "Failed to abort apex session " + session.sessionId);
            }
            throw new PackageManagerException(
@@ -658,7 +658,10 @@ public class StagingManager {
                                + " because it is not active or APEXD is not reachable");
                return;
            }
            mApexManager.abortActiveSession();
            try {
                mApexManager.abortStagedSession(session.sessionId);
            } catch (Exception ignore) {
            }
        }
    }