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

Commit 5df37ffe authored by JW Wang's avatar JW Wang Committed by Chun-Wei Wang
Browse files

Use PackageManager.INSTALL_XXX error codes (15/n)

2 sets of error codes are a source of confusion. This CL migrates
all uses of SessionInfo.SESSION_XXX error codes to
PackageManager.INSTALL_XXX ones which provide a richer set of
error codes.

Bug: 210359798
Test: atest StagingManagerTest \
            com.android.server.pm.test.PackageInstallerSessionTest \
	    CtsStagedInstallHostTestCases

Merged-In: I0a721a48293029983ffd80912adbb2229ab4ee5d
Change-Id: I0a721a48293029983ffd80912adbb2229ab4ee5d
(cherry picked from commit 1ed3bff6)
parent 038fd80c
Loading
Loading
Loading
Loading
+2 −11
Original line number Diff line number Diff line
@@ -2421,15 +2421,6 @@ public class PackageInstaller {
        /** {@hide} */
        private static final int[] NO_SESSIONS = {};

        /** @hide */
        @IntDef(prefix = { "SESSION_" }, value = {
                SESSION_NO_ERROR,
                SESSION_VERIFICATION_FAILED,
                SESSION_ACTIVATION_FAILED,
                SESSION_UNKNOWN_ERROR,
                SESSION_CONFLICT})
        @Retention(RetentionPolicy.SOURCE)
        public @interface SessionErrorCode {}
        /**
         * @deprecated use {@link #SESSION_NO_ERROR}.
         */
@@ -3113,7 +3104,7 @@ public class PackageInstaller {
         * If something went wrong with a staged session, clients can check this error code to
         * understand which kind of failure happened. Only meaningful if {@code isStaged} is true.
         */
        public @SessionErrorCode int getStagedSessionErrorCode() {
        public int getStagedSessionErrorCode() {
            checkSessionIsStaged();
            return mSessionErrorCode;
        }
@@ -3128,7 +3119,7 @@ public class PackageInstaller {
        }

        /** {@hide} */
        public void setSessionErrorCode(@SessionErrorCode int errorCode, String errorMessage) {
        public void setSessionErrorCode(int errorCode, String errorMessage) {
            mSessionErrorCode = errorCode;
            mSessionErrorMessage = errorMessage;
        }
+8 −0
Original line number Diff line number Diff line
@@ -2202,6 +2202,14 @@ public abstract class PackageManager {
     */
    public static final int INSTALL_FAILED_BAD_PERMISSION_GROUP = -127;

    /**
     * Installation failed return code: an error occurred during the activation phase of this
     * session.
     *
     * @hide
     */
    public static final int INSTALL_ACTIVATION_FAILED = -128;

    /** @hide */
    @IntDef(flag = true, prefix = { "DELETE_" }, value = {
            DELETE_KEEP_DATA,
+2 −3
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.apex.CompressedApexInfoList;
import android.apex.IApexService;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.SigningDetails;
import android.content.pm.parsing.result.ParseResult;
@@ -813,7 +812,7 @@ public abstract class ApexManager {
                throw new RuntimeException(re);
            } catch (Exception e) {
                throw new PackageManagerException(
                        PackageInstaller.SessionInfo.SESSION_VERIFICATION_FAILED,
                        PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
                        "apexd verification failed : " + e.getMessage());
            }
        }
@@ -840,7 +839,7 @@ public abstract class ApexManager {
                throw new RuntimeException(re);
            } catch (Exception e) {
                throw new PackageManagerException(
                        PackageInstaller.SessionInfo.SESSION_VERIFICATION_FAILED,
                        PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
                        "Failed to mark apexd session as ready : " + e.getMessage());
            }
        }
+2 −2
Original line number Diff line number Diff line
@@ -334,7 +334,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
                StagingManager.StagedSession stagedSession = session.mStagedSession;
                if (!stagedSession.isInTerminalState() && stagedSession.hasParentSessionId()
                        && getSession(stagedSession.getParentSessionId()) == null) {
                    stagedSession.setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED,
                    stagedSession.setSessionFailed(PackageManager.INSTALL_ACTIVATION_FAILED,
                            "An orphan staged session " + stagedSession.sessionId() + " is found, "
                                + "parent " + stagedSession.getParentSessionId() + " is missing");
                    continue;
@@ -852,7 +852,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
                mSilentUpdatePolicy, mInstallThread.getLooper(), mStagingManager, sessionId,
                userId, callingUid, installSource, params, createdMillis, 0L, stageDir, stageCid,
                null, null, false, false, false, false, null, SessionInfo.INVALID_ID,
                false, false, false, SessionInfo.SESSION_NO_ERROR, "");
                false, false, false, PackageManager.INSTALL_UNKNOWN, "");

        synchronized (mSessions) {
            mSessions.put(sessionId, session);
+5 −7
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@ import android.content.pm.InstallationFileParcel;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.PackageInstaller.SessionInfo.SessionErrorCode;
import android.content.pm.PackageInstaller.SessionParams;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
@@ -462,7 +461,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    @GuardedBy("mLock")
    private boolean mSessionFailed;
    @GuardedBy("mLock")
    private int mSessionErrorCode = SessionInfo.SESSION_NO_ERROR;
    private int mSessionErrorCode = PackageManager.INSTALL_UNKNOWN;
    @GuardedBy("mLock")
    private String mSessionErrorMessage;

@@ -2315,7 +2314,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                maybeFinishChildSessions(INSTALL_SUCCEEDED, "Session installed");
            } else {
                PackageManagerException e = (PackageManagerException) t.getCause();
                setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED,
                setSessionFailed(e.error,
                        PackageManager.installStatusToString(e.error, e.getMessage()));
                dispatchSessionFinished(e.error, e.getMessage(), null);
                maybeFinishChildSessions(e.error, e.getMessage());
@@ -4023,7 +4022,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            mSessionReady = true;
            mSessionApplied = false;
            mSessionFailed = false;
            mSessionErrorCode = SessionInfo.SESSION_NO_ERROR;
            mSessionErrorCode = PackageManager.INSTALL_UNKNOWN;
            mSessionErrorMessage = "";
        }
        mCallback.onSessionChanged(this);
@@ -4051,7 +4050,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            mSessionReady = false;
            mSessionApplied = true;
            mSessionFailed = false;
            mSessionErrorCode = SessionInfo.SESSION_NO_ERROR;
            mSessionErrorCode = INSTALL_SUCCEEDED;
            mSessionErrorMessage = "";
            Slog.d(TAG, "Marking session " + sessionId + " as applied");
        }
@@ -4081,7 +4080,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    }

    /** {@hide} */
    @SessionErrorCode
    int getSessionErrorCode() {
        synchronized (mLock) {
            return mSessionErrorCode;
@@ -4569,7 +4567,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        final boolean isFailed = in.getAttributeBoolean(null, ATTR_IS_FAILED, false);
        final boolean isApplied = in.getAttributeBoolean(null, ATTR_IS_APPLIED, false);
        final int sessionErrorCode = in.getAttributeInt(null, ATTR_SESSION_ERROR_CODE,
                SessionInfo.SESSION_NO_ERROR);
                PackageManager.INSTALL_UNKNOWN);
        final String sessionErrorMessage = readStringAttribute(in, ATTR_SESSION_ERROR_MESSAGE);

        if (!isStagedSessionStateValid(isReady, isApplied, isFailed)) {
Loading