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

Commit 9b12ca9a authored by Shafik Nassar's avatar Shafik Nassar Committed by Android (Google) Code Review
Browse files

Merge "StagingManager: Support abandoning staged sessions"

parents fc9fd20d 07205e38
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -213,6 +213,21 @@ class ApexManager {
        return !mActivePackagesCache.isEmpty();
    }

    /**
     * Abandons the (only) active session previously submitted.
     *
     * @return {@code true} upon success, {@code false} if any remote exception occurs
     */
    boolean abortActiveSession() {
        try {
            mApexService.abortActiveSession();
            return true;
        } catch (RemoteException re) {
            Slog.e(TAG, "Unable to contact apexservice", re);
            return false;
        }
    }

    /**
     * Dumps various state information to the provided {@link PrintWriter} object.
     *
+9 −0
Original line number Diff line number Diff line
@@ -1867,6 +1867,15 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        synchronized (mLock) {
            assertCallerIsOwnerOrRootLocked();

            if (mCommitted && params.isStaged) {
                synchronized (mLock) {
                    mDestroyed = true;
                }
                mStagingManager.abortCommittedSession(this);

                //TODO(b/123624108): delete staging dir
            }

            if (mRelinquished) {
                Slog.d(TAG, "Ignoring abandon after commit relinquished control");
                return;
+22 −1
Original line number Diff line number Diff line
@@ -445,11 +445,32 @@ public class StagingManager {

    void abortSession(@NonNull PackageInstallerSession session) {
        synchronized (mStagedSessions) {
            updateStoredSession(session);
            mStagedSessions.remove(session.sessionId);
        }
    }

    void abortCommittedSession(@NonNull PackageInstallerSession session) {
        if (session.isStagedSessionApplied()) {
            Slog.w(TAG, "Cannot abort applied session!");
            return;
        }
        if (isStagedSessionFinalized(session.sessionId)) {
            Slog.w(TAG, "Cannot abort session because it is not active or APEXD is not reachable");
            return;
        }

        mApexManager.abortActiveSession();

        abortSession(session);
    }

    private boolean isStagedSessionFinalized(int sessionId) {
        ApexSessionInfo session = mApexManager.getStagedSessionInfo(sessionId);

        /* checking if the session is in a final state, i.e., not active anymore */
        return session.isUnknown || session.isActivationFailed || session.isSuccess;
    }

    @GuardedBy("mStagedSessions")
    private boolean isMultiPackageSessionComplete(@NonNull PackageInstallerSession session) {
        // This method assumes that the argument is either a parent session of a multi-package