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

Commit e2d52f57 authored by Nikita Ioffe's avatar Nikita Ioffe
Browse files

Abort apexd session only if staged session contains apex

* Always abort staged session. It's fine if aborting an apexd session
  fails. Apexd will wipe out metadata about previous sessions when
  committing a new one any way.
* Don't fail if there is no apexd session associated with this staged
  session. This can happen if abortCommittedSession was called twice.
  In this case second call will be a no-op. Which feels like a desired
  behaviour.

Test: adb install --staged foo.apk && adb shell pm install-abandon
Bug: 128108135
Fixes: 128108135
Change-Id: I016534d957ea559289a2e3d97e603a5e4d146e35
parent 061317ba
Loading
Loading
Loading
Loading
+12 −10
Original line number Original line Diff line number Diff line
@@ -498,19 +498,21 @@ public class StagingManager {
            Slog.w(TAG, "Cannot abort applied session!");
            Slog.w(TAG, "Cannot abort applied session!");
            return;
            return;
        }
        }
        if (isStagedSessionFinalized(session.sessionId)) {
        abortSession(session);
            Slog.w(TAG, "Cannot abort session because it is not active or APEXD is not reachable");

        boolean hasApex = sessionContainsApex(session);
        if (hasApex) {
            ApexSessionInfo apexSession = mApexManager.getStagedSessionInfo(session.sessionId);
            if (apexSession == null || isApexSessionFinalized(apexSession)) {
                Slog.w(TAG,
                        "Cannot abort session because it is not active or APEXD is not reachable");
                return;
                return;
            }
            }

            mApexManager.abortActiveSession();
            mApexManager.abortActiveSession();

        }
        abortSession(session);
    }
    }


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

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