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

Commit 66b3b89f authored by Chun-Wei Wang's avatar Chun-Wei Wang Committed by Android (Google) Code Review
Browse files

Merge "Move and rename some members (1/n)"

parents d25326ec 8c19110b
Loading
Loading
Loading
Loading
+26 −27
Original line number Diff line number Diff line
@@ -2374,7 +2374,7 @@ public class PackageInstaller {
                STAGED_SESSION_UNKNOWN,
                STAGED_SESSION_CONFLICT})
        @Retention(RetentionPolicy.SOURCE)
        public @interface StagedSessionErrorCode{}
        public @interface SessionErrorCode {}
        /**
         * Constant indicating that no error occurred during the preparation or the activation of
         * this staged session.
@@ -2486,13 +2486,13 @@ public class PackageInstaller {
        public int[] childSessionIds = NO_SESSIONS;

        /** {@hide} */
        public boolean isStagedSessionApplied;
        public boolean isSessionApplied;
        /** {@hide} */
        public boolean isStagedSessionReady;
        public boolean isSessionReady;
        /** {@hide} */
        public boolean isStagedSessionFailed;
        private int mStagedSessionErrorCode;
        private String mStagedSessionErrorMessage;
        public boolean isSessionFailed;
        private int mSessionErrorCode;
        private String mSessionErrorMessage;

        /** {@hide} */
        public boolean isCommitted;
@@ -2553,11 +2553,11 @@ public class PackageInstaller {
            if (childSessionIds == null) {
                childSessionIds = NO_SESSIONS;
            }
            isStagedSessionApplied = source.readBoolean();
            isStagedSessionReady = source.readBoolean();
            isStagedSessionFailed = source.readBoolean();
            mStagedSessionErrorCode = source.readInt();
            mStagedSessionErrorMessage = source.readString();
            isSessionApplied = source.readBoolean();
            isSessionReady = source.readBoolean();
            isSessionFailed = source.readBoolean();
            mSessionErrorCode = source.readInt();
            mSessionErrorMessage = source.readString();
            isCommitted = source.readBoolean();
            rollbackDataPolicy = source.readInt();
            createdMillis = source.readLong();
@@ -2951,7 +2951,7 @@ public class PackageInstaller {
         * since that is the one that should have been {@link Session#commit committed}.
         */
        public boolean isStagedSessionActive() {
            return isStaged && isCommitted && !isStagedSessionApplied && !isStagedSessionFailed
            return isStaged && isCommitted && !isSessionApplied && !isSessionFailed
                    && !hasParentSessionId();
        }

@@ -2992,7 +2992,7 @@ public class PackageInstaller {
         */
        public boolean isStagedSessionApplied() {
            checkSessionIsStaged();
            return isStagedSessionApplied;
            return isSessionApplied;
        }

        /**
@@ -3001,7 +3001,7 @@ public class PackageInstaller {
         */
        public boolean isStagedSessionReady() {
            checkSessionIsStaged();
            return isStagedSessionReady;
            return isSessionReady;
        }

        /**
@@ -3010,16 +3010,16 @@ public class PackageInstaller {
         */
        public boolean isStagedSessionFailed() {
            checkSessionIsStaged();
            return isStagedSessionFailed;
            return isSessionFailed;
        }

        /**
         * 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 @StagedSessionErrorCode int getStagedSessionErrorCode() {
        public @SessionErrorCode int getStagedSessionErrorCode() {
            checkSessionIsStaged();
            return mStagedSessionErrorCode;
            return mSessionErrorCode;
        }

        /**
@@ -3028,14 +3028,13 @@ public class PackageInstaller {
         */
        public @NonNull String getStagedSessionErrorMessage() {
            checkSessionIsStaged();
            return mStagedSessionErrorMessage;
            return mSessionErrorMessage;
        }

        /** {@hide} */
        public void setStagedSessionErrorCode(@StagedSessionErrorCode int errorCode,
                                              String errorMessage) {
            mStagedSessionErrorCode = errorCode;
            mStagedSessionErrorMessage = errorMessage;
        public void setSessionErrorCode(@SessionErrorCode int errorCode, String errorMessage) {
            mSessionErrorCode = errorCode;
            mSessionErrorMessage = errorMessage;
        }

        /**
@@ -3124,11 +3123,11 @@ public class PackageInstaller {
            dest.writeBoolean(forceQueryable);
            dest.writeInt(parentSessionId);
            dest.writeIntArray(childSessionIds);
            dest.writeBoolean(isStagedSessionApplied);
            dest.writeBoolean(isStagedSessionReady);
            dest.writeBoolean(isStagedSessionFailed);
            dest.writeInt(mStagedSessionErrorCode);
            dest.writeString(mStagedSessionErrorMessage);
            dest.writeBoolean(isSessionApplied);
            dest.writeBoolean(isSessionReady);
            dest.writeBoolean(isSessionFailed);
            dest.writeInt(mSessionErrorCode);
            dest.writeString(mSessionErrorMessage);
            dest.writeBoolean(isCommitted);
            dest.writeInt(rollbackDataPolicy);
            dest.writeLong(createdMillis);
+1 −1
Original line number Diff line number Diff line
@@ -1623,7 +1623,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
                    progress);
        }

        public void onStagedSessionChanged(PackageInstallerSession session) {
        public void onSessionChanged(PackageInstallerSession session) {
            session.markUpdated();
            mSettingsWriteRequest.schedule();
            if (mOkToSendBroadcasts && !session.isDestroyed()) {
+111 −118
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ 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.StagedSessionErrorCode;
import android.content.pm.PackageInstaller.SessionInfo.SessionErrorCode;
import android.content.pm.PackageInstaller.SessionParams;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
@@ -228,8 +228,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    private static final String ATTR_IS_READY = "isReady";
    private static final String ATTR_IS_FAILED = "isFailed";
    private static final String ATTR_IS_APPLIED = "isApplied";
    private static final String ATTR_STAGED_SESSION_ERROR_CODE = "errorCode";
    private static final String ATTR_STAGED_SESSION_ERROR_MESSAGE = "errorMessage";
    private static final String ATTR_SESSION_ERROR_CODE = "errorCode";
    private static final String ATTR_SESSION_ERROR_MESSAGE = "errorMessage";
    private static final String ATTR_MODE = "mode";
    private static final String ATTR_INSTALL_FLAGS = "installFlags";
    private static final String ATTR_INSTALL_LOCATION = "installLocation";
@@ -453,11 +453,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    @GuardedBy("mLock")
    private ArrayMap<String, PerFileChecksum> mChecksums = new ArrayMap<>();

    @Nullable
    final StagedSession mStagedSession;

    @VisibleForTesting
    public class StagedSession implements StagingManager.StagedSession {
    @GuardedBy("mLock")
    private boolean mSessionApplied;
    @GuardedBy("mLock")
@@ -469,6 +464,11 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    @GuardedBy("mLock")
    private String mSessionErrorMessage;

    @Nullable
    final StagedSession mStagedSession;

    @VisibleForTesting
    public class StagedSession implements StagingManager.StagedSession {
        /**
         * The callback to run when pre-reboot verification has ended. Used by {@link #abandon()}
         * to delay session clean-up until it is safe to do so.
@@ -477,15 +477,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        @Nullable
        private Runnable mPendingAbandonCallback;

        StagedSession(boolean isReady, boolean isApplied, boolean isFailed, int errorCode,
                String errorMessage) {
            mSessionReady = isReady;
            mSessionApplied = isApplied;
            mSessionFailed = isFailed;
            mSessionErrorCode = errorCode;
            mSessionErrorMessage = errorMessage != null ? errorMessage : "";
        }

        @Override
        public List<StagingManager.StagedSession> getChildSessions() {
            if (!params.isMultiPackage) {
@@ -533,52 +524,17 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {

        @Override
        public void setSessionReady() {
            synchronized (mLock) {
                // Do not allow destroyed/failed staged session to change state
                if (mDestroyed || mSessionFailed) return;
                mSessionReady = true;
                mSessionApplied = false;
                mSessionFailed = false;
                mSessionErrorCode = SessionInfo.STAGED_SESSION_NO_ERROR;
                mSessionErrorMessage = "";
            }
            mCallback.onStagedSessionChanged(PackageInstallerSession.this);
            PackageInstallerSession.this.setSessionReady();
        }

        @Override
        public void setSessionFailed(int errorCode, String errorMessage) {
            List<PackageInstallerSession> childSessions;
            synchronized (mLock) {
                // Do not allow destroyed/failed staged session to change state
                if (mDestroyed || mSessionFailed) return;
                mSessionReady = false;
                mSessionApplied = false;
                mSessionFailed = true;
                mSessionErrorCode = errorCode;
                mSessionErrorMessage = errorMessage;
                Slog.d(TAG, "Marking session " + sessionId + " as failed: " + errorMessage);
                childSessions = getChildSessionsLocked();
            }
            destroy();
            mCallback.onStagedSessionChanged(PackageInstallerSession.this);
            PackageInstallerSession.this.setSessionFailed(errorCode, errorMessage);
        }

        @Override
        public void setSessionApplied() {
            List<PackageInstallerSession> childSessions;
            synchronized (mLock) {
                // Do not allow destroyed/failed staged session to change state
                if (mDestroyed || mSessionFailed) return;
                mSessionReady = false;
                mSessionApplied = true;
                mSessionFailed = false;
                mSessionErrorCode = SessionInfo.STAGED_SESSION_NO_ERROR;
                mSessionErrorMessage = "";
                Slog.d(TAG, "Marking session " + sessionId + " as applied");
                childSessions = getChildSessionsLocked();
            }
            destroy();
            mCallback.onStagedSessionChanged(PackageInstallerSession.this);
            PackageInstallerSession.this.setSessionApplied();
        }

        @Override
@@ -655,35 +611,17 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {

        @Override
        public boolean isSessionReady() {
            synchronized (mLock) {
                return mSessionReady;
            }
            return PackageInstallerSession.this.isSessionReady();
        }

        @Override
        public boolean isSessionApplied() {
            synchronized (mLock) {
                return mSessionApplied;
            }
            return PackageInstallerSession.this.isSessionApplied();
        }

        @Override
        public boolean isSessionFailed() {
            synchronized (mLock) {
                return mSessionFailed;
            }
        }

        @StagedSessionErrorCode int getSessionErrorCode() {
            synchronized (mLock) {
                return mSessionErrorCode;
            }
        }

        String getSessionErrorMessage() {
            synchronized (mLock) {
                return mSessionErrorMessage;
            }
            return PackageInstallerSession.this.isSessionFailed();
        }

        @Override
@@ -713,7 +651,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                if (mStageDirInUse) {
                    // Pre-reboot verification is ongoing, not safe to clean up the session yet.
                    mPendingAbandonCallback = r;
                    mCallback.onStagedSessionChanged(PackageInstallerSession.this);
                    mCallback.onSessionChanged(PackageInstallerSession.this);
                    return;
                }
            }
@@ -1014,8 +952,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            ArrayMap<String, PerFileChecksum> checksums,
            boolean prepared, boolean committed, boolean destroyed, boolean sealed,
            @Nullable int[] childSessionIds, int parentSessionId, boolean isReady,
            boolean isFailed, boolean isApplied, int stagedSessionErrorCode,
            String stagedSessionErrorMessage) {
            boolean isFailed, boolean isApplied, int sessionErrorCode,
            String sessionErrorMessage) {
        mCallback = callback;
        mContext = context;
        mPm = pm;
@@ -1070,8 +1008,13 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        mPrepared = prepared;
        mCommitted.set(committed);
        mDestroyed = destroyed;
        mStagedSession = params.isStaged ? new StagedSession(isReady, isApplied, isFailed,
                stagedSessionErrorCode, stagedSessionErrorMessage) : null;
        mSessionReady = isReady;
        mSessionApplied = isApplied;
        mSessionFailed = isFailed;
        mSessionErrorCode = sessionErrorCode;
        mSessionErrorMessage =
                sessionErrorMessage != null ? sessionErrorMessage : "";
        mStagedSession = params.isStaged ? new StagedSession() : null;

        if (isDataLoaderInstallation()) {
            if (isApexSession()) {
@@ -1172,11 +1115,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            info.rollbackDataPolicy = params.rollbackDataPolicy;
            info.parentSessionId = mParentSessionId;
            info.childSessionIds = getChildSessionIdsLocked();
            info.isStagedSessionApplied = isStagedSessionApplied();
            info.isStagedSessionReady = isStagedSessionReady();
            info.isStagedSessionFailed = isStagedSessionFailed();
            info.setStagedSessionErrorCode(getStagedSessionErrorCode(),
                    getStagedSessionErrorMessage());
            info.isSessionApplied = mSessionApplied;
            info.isSessionReady = mSessionReady;
            info.isSessionFailed = mSessionFailed;
            info.setSessionErrorCode(mSessionErrorCode, mSessionErrorMessage);
            info.createdMillis = createdMillis;
            info.updatedMillis = updatedMillis;
            info.requireUserAction = params.requireUserAction;
@@ -4219,30 +4161,83 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        }
    }

    private void setSessionReady() {
        synchronized (mLock) {
            // Do not allow destroyed/failed session to change state
            if (mDestroyed || mSessionFailed) return;
            mSessionReady = true;
            mSessionApplied = false;
            mSessionFailed = false;
            mSessionErrorCode = SessionInfo.STAGED_SESSION_NO_ERROR;
            mSessionErrorMessage = "";
        }
        mCallback.onSessionChanged(this);
    }

    private void setSessionFailed(int errorCode, String errorMessage) {
        synchronized (mLock) {
            // Do not allow destroyed/failed session to change state
            if (mDestroyed || mSessionFailed) return;
            mSessionReady = false;
            mSessionApplied = false;
            mSessionFailed = true;
            mSessionErrorCode = errorCode;
            mSessionErrorMessage = errorMessage;
            Slog.d(TAG, "Marking session " + sessionId + " as failed: " + errorMessage);
        }
        destroy();
        mCallback.onSessionChanged(this);
    }

    private void setSessionApplied() {
        synchronized (mLock) {
            // Do not allow destroyed/failed session to change state
            if (mDestroyed || mSessionFailed) return;
            mSessionReady = false;
            mSessionApplied = true;
            mSessionFailed = false;
            mSessionErrorCode = SessionInfo.STAGED_SESSION_NO_ERROR;
            mSessionErrorMessage = "";
            Slog.d(TAG, "Marking session " + sessionId + " as applied");
        }
        destroy();
        mCallback.onSessionChanged(this);
    }

    /** {@hide} */
    boolean isStagedSessionReady() {
        return params.isStaged && mStagedSession.isSessionReady();
    boolean isSessionReady() {
        synchronized (mLock) {
            return mSessionReady;
        }
    }

    /** {@hide} */
    boolean isStagedSessionApplied() {
        return params.isStaged && mStagedSession.isSessionApplied();
    boolean isSessionApplied() {
        synchronized (mLock) {
            return mSessionApplied;
        }
    }

    /** {@hide} */
    boolean isStagedSessionFailed() {
        return params.isStaged && mStagedSession.isSessionFailed();
    boolean isSessionFailed() {
        synchronized (mLock) {
            return mSessionFailed;
        }
    }

    /** {@hide} */
    @StagedSessionErrorCode int getStagedSessionErrorCode() {
        return params.isStaged ? mStagedSession.getSessionErrorCode()
                : SessionInfo.STAGED_SESSION_NO_ERROR;
    @SessionErrorCode
    int getSessionErrorCode() {
        synchronized (mLock) {
            return mSessionErrorCode;
        }
    }

    /** {@hide} */
    String getStagedSessionErrorMessage() {
        return params.isStaged ? mStagedSession.getSessionErrorMessage() : "";
    String getSessionErrorMessage() {
        synchronized (mLock) {
            return mSessionErrorMessage;
        }
    }

    /**
@@ -4344,11 +4339,11 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        pw.printPair("params.isStaged", params.isStaged);
        pw.printPair("mParentSessionId", mParentSessionId);
        pw.printPair("mChildSessionIds", getChildSessionIdsLocked());
        pw.printPair("mStagedSessionApplied", isStagedSessionApplied());
        pw.printPair("mStagedSessionFailed", isStagedSessionFailed());
        pw.printPair("mStagedSessionReady", isStagedSessionReady());
        pw.printPair("mStagedSessionErrorCode", getStagedSessionErrorCode());
        pw.printPair("mStagedSessionErrorMessage", getStagedSessionErrorMessage());
        pw.printPair("mSessionApplied", mSessionApplied);
        pw.printPair("mSessionFailed", mSessionFailed);
        pw.printPair("mSessionReady", mSessionReady);
        pw.printPair("mSessionErrorCode", mSessionErrorCode);
        pw.printPair("mSessionErrorMessage", mSessionErrorMessage);
        pw.println();

        pw.decreaseIndent();
@@ -4514,12 +4509,11 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {

            writeBooleanAttribute(out, ATTR_MULTI_PACKAGE, params.isMultiPackage);
            writeBooleanAttribute(out, ATTR_STAGED_SESSION, params.isStaged);
            writeBooleanAttribute(out, ATTR_IS_READY, isStagedSessionReady());
            writeBooleanAttribute(out, ATTR_IS_FAILED, isStagedSessionFailed());
            writeBooleanAttribute(out, ATTR_IS_APPLIED, isStagedSessionApplied());
            out.attributeInt(null, ATTR_STAGED_SESSION_ERROR_CODE, getStagedSessionErrorCode());
            writeStringAttribute(out, ATTR_STAGED_SESSION_ERROR_MESSAGE,
                    getStagedSessionErrorMessage());
            writeBooleanAttribute(out, ATTR_IS_READY, mSessionReady);
            writeBooleanAttribute(out, ATTR_IS_FAILED, mSessionFailed);
            writeBooleanAttribute(out, ATTR_IS_APPLIED, mSessionApplied);
            out.attributeInt(null, ATTR_SESSION_ERROR_CODE, mSessionErrorCode);
            writeStringAttribute(out, ATTR_SESSION_ERROR_MESSAGE, mSessionErrorMessage);
            // TODO(patb,109941548): avoid writing to xml and instead infer / validate this after
            //                       we've read all sessions.
            out.attributeInt(null, ATTR_PARENT_SESSION_ID, mParentSessionId);
@@ -4710,10 +4704,9 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        final boolean isReady = in.getAttributeBoolean(null, ATTR_IS_READY, false);
        final boolean isFailed = in.getAttributeBoolean(null, ATTR_IS_FAILED, false);
        final boolean isApplied = in.getAttributeBoolean(null, ATTR_IS_APPLIED, false);
        final int stagedSessionErrorCode = in.getAttributeInt(null, ATTR_STAGED_SESSION_ERROR_CODE,
        final int sessionErrorCode = in.getAttributeInt(null, ATTR_SESSION_ERROR_CODE,
                SessionInfo.STAGED_SESSION_NO_ERROR);
        final String stagedSessionErrorMessage = readStringAttribute(in,
                ATTR_STAGED_SESSION_ERROR_MESSAGE);
        final String sessionErrorMessage = readStringAttribute(in, ATTR_SESSION_ERROR_MESSAGE);

        if (!isStagedSessionStateValid(isReady, isApplied, isFailed)) {
            throw new IllegalArgumentException("Can't restore staged session with invalid state.");
@@ -4827,6 +4820,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                installerUid, installSource, params, createdMillis, committedMillis, stageDir,
                stageCid, fileArray, checksumsMap, prepared, committed, destroyed, sealed,
                childSessionIdsArray, parentSessionId, isReady, isFailed, isApplied,
                stagedSessionErrorCode, stagedSessionErrorMessage);
                sessionErrorCode, sessionErrorMessage);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ final class PackageSessionVerifier {
    }

    private void onVerificationFailure(StagingManager.StagedSession session, Callback callback,
            @SessionInfo.StagedSessionErrorCode int errorCode, String errorMessage) {
            @SessionInfo.SessionErrorCode int errorCode, String errorMessage) {
        if (!ensureActiveApexSessionIsAborted(session)) {
            Slog.e(TAG, "Failed to abort apex session " + session.sessionId());
            // Safe to ignore active apex session abortion failure since session will be marked
+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import android.content.pm.ApexStagedEvent;
import android.content.pm.IStagedApexObserver;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.PackageInstaller.SessionInfo.StagedSessionErrorCode;
import android.content.pm.PackageInstaller.SessionInfo.SessionErrorCode;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.StagedApexInfo;
@@ -129,7 +129,7 @@ public class StagingManager {
        boolean containsApkSession();
        boolean containsApexSession();
        void setSessionReady();
        void setSessionFailed(@StagedSessionErrorCode int errorCode, String errorMessage);
        void setSessionFailed(@SessionErrorCode int errorCode, String errorMessage);
        void setSessionApplied();
        void installSession(IntentSender statusReceiver);
        boolean hasParentSessionId();
Loading