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

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

Mark apexd session as successful before marking staged session applied

Failing to mark session as successful won't block this staged session:
- it's mostly for bookkeeping purposes, in the future apexd might just
  delete information about the session after it is marked as successful;
- in case this call failed, when new session is staged apexd will delete
  all dangling sessions.

Bug: 124215327
Fixes: 124215327
Test: apex_e2e_tests
Change-Id: I7c9a068bc32352792610e7190e08a884bb5d09a5
parent e4f26ef2
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -166,6 +166,27 @@ class ApexManager {
        }
    }

    /**
     * Marks a staged session as successful.
     *
     * <p>Only activated session can be marked as successful.
     *
     * @param sessionId the identifier of the {@link PackageInstallerSession} being marked as
     *                  successful.
     */
    void markStagedSessionSuccessful(int sessionId) {
        try {
            mApexService.markStagedSessionSuccessful(sessionId);
        } catch (RemoteException re) {
            Slog.e(TAG, "Unable to contact apexservice", re);
            throw new RuntimeException(re);
        } catch (Exception e) {
            // It is fine to just log an exception in this case. APEXd will be able to recover in
            // case markStagedSessionSuccessful fails.
            Slog.e(TAG, "Failed to mark session " + sessionId + " as successful", e);
        }
    }

    /**
     * Dumps various state information to the provided {@link PrintWriter} object.
     *
@@ -196,7 +217,7 @@ class ApexManager {
            ipw.increaseIndent();
            final ApexSessionInfo[] sessions = mApexService.getSessions();
            for (ApexSessionInfo si : sessions) {
                ipw.println("Session ID: " + Integer.toString(si.sessionId));
                ipw.println("Session ID: " + si.sessionId);
                ipw.increaseIndent();
                if (si.isUnknown) {
                    ipw.println("State: UNKNOWN");
+7 −2
Original line number Diff line number Diff line
@@ -247,7 +247,8 @@ public class StagingManager {
    }

    private void resumeSession(@NonNull PackageInstallerSession session) {
        if (sessionContainsApex(session)) {
        boolean hasApex = sessionContainsApex(session);
        if (hasApex) {
            // Check with apexservice whether the apex packages have been activated.
            ApexSessionInfo apexSessionInfo = mApexManager.getStagedSessionInfo(session.sessionId);
            if (apexSessionInfo == null) {
@@ -271,7 +272,7 @@ public class StagingManager {
                mBgHandler.post(() -> preRebootVerification(session));
                return;
            }
            if (!apexSessionInfo.isActivated) {
            if (!apexSessionInfo.isActivated && !apexSessionInfo.isSuccess) {
                // In all the remaining cases apexd will try to apply the session again at next
                // boot. Nothing to do here for now.
                Slog.w(TAG, "Staged session " + session.sessionId + " scheduled to be applied "
@@ -287,7 +288,11 @@ public class StagingManager {
                        + "more information.");
            return;
        }

        session.setStagedSessionApplied();
        if (hasApex) {
            mApexManager.markStagedSessionSuccessful(session.sessionId);
        }
    }

    private String findFirstAPKInDir(File stageDir) {