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

Commit ce23b4a5 authored by TYM Tsai's avatar TYM Tsai
Browse files

Fix system server crash caused by package installer

Package installer crashes when trying to install a staged session
but is already applied or fails. Even if session validation fails,
the service should not crash the system. Also refine the error
message in terms of which session is causing the issue and how we
got to that state.

Bug: 286306412
Test: Build successfully and boot to home
Change-Id: I0de3ef888fba0c81a0d404dfdce4389a5b7bfd24
parent c2312cee
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -705,12 +705,33 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        @Override
        public void verifySession() {
            assertCallerIsOwnerOrRootOrSystem();
            Preconditions.checkArgument(isCommitted());
            Preconditions.checkArgument(!isInTerminalState());
            if (isCommittedAndNotInTerminalState()) {
                verify();
            }
        }

        private boolean isCommittedAndNotInTerminalState() {
            String errorMsg = null;
            if (!isCommitted()) {
                errorMsg = TextUtils.formatSimple("The session %d should be committed", sessionId);
            } else if (isSessionApplied()) {
                errorMsg = TextUtils.formatSimple("The session %d has applied", sessionId);
            } else if (isSessionFailed()) {
                synchronized (PackageInstallerSession.this.mLock) {
                    errorMsg = TextUtils.formatSimple("The session %d has failed with error: %s",
                            sessionId, PackageInstallerSession.this.mSessionErrorMessage);
                }
            }
            if (errorMsg != null) {
                Slog.e(TAG, "verifySession error: " + errorMsg);
                setSessionFailed(INSTALL_FAILED_INTERNAL_ERROR, errorMsg);
                onSessionVerificationFailure(INSTALL_FAILED_INTERNAL_ERROR, errorMsg);
                return false;
            }
            return true;
        }
    }

    /**
     * Path to the validated base APK for this session, which may point at an
     * APK inside the session (when the session defines the base), or it may