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

Commit b3f3b515 authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam Committed by Automerger Merge Worker
Browse files

Persist destroyed staged sessions until they are cleaned up am: 731bd965 am:...

Persist destroyed staged sessions until they are cleaned up am: 731bd965 am: 8d6a58a0 am: 4a95bef9

Change-Id: If969cb2493c1bdad638456f9bceaac9181787cd4
parents b296197c 4a95bef9
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -676,7 +676,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        session = new PackageInstallerSession(mInternalCallback, mContext, mPm, this,
        session = new PackageInstallerSession(mInternalCallback, mContext, mPm, this,
                mInstallThread.getLooper(), mStagingManager, sessionId, userId, callingUid,
                mInstallThread.getLooper(), mStagingManager, sessionId, userId, callingUid,
                installSource, params, createdMillis,
                installSource, params, createdMillis,
                stageDir, stageCid, null, false, false, false, null, SessionInfo.INVALID_ID,
                stageDir, stageCid, null, false, false, false, false, null, SessionInfo.INVALID_ID,
                false, false, false, SessionInfo.STAGED_SESSION_NO_ERROR, "");
                false, false, false, SessionInfo.STAGED_SESSION_NO_ERROR, "");


        synchronized (mSessions) {
        synchronized (mSessions) {
@@ -830,7 +830,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        synchronized (mSessions) {
        synchronized (mSessions) {
            final PackageInstallerSession session = mSessions.get(sessionId);
            final PackageInstallerSession session = mSessions.get(sessionId);


            return session != null
            return (session != null && !(session.isStaged() && session.isDestroyed()))
                    ? session.generateInfoForCaller(true /*withIcon*/, Binder.getCallingUid())
                    ? session.generateInfoForCaller(true /*withIcon*/, Binder.getCallingUid())
                    : null;
                    : null;
        }
        }
@@ -851,7 +851,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        synchronized (mSessions) {
        synchronized (mSessions) {
            for (int i = 0; i < mSessions.size(); i++) {
            for (int i = 0; i < mSessions.size(); i++) {
                final PackageInstallerSession session = mSessions.valueAt(i);
                final PackageInstallerSession session = mSessions.valueAt(i);
                if (session.userId == userId && !session.hasParentSessionId()) {
                if (session.userId == userId && !session.hasParentSessionId()
                        && !(session.isStaged() && session.isDestroyed())) {
                    result.add(session.generateInfoForCaller(false, callingUid));
                    result.add(session.generateInfoForCaller(false, callingUid));
                }
                }
            }
            }
+14 −3
Original line number Original line Diff line number Diff line
@@ -190,6 +190,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    private static final String ATTR_SESSION_STAGE_CID = "sessionStageCid";
    private static final String ATTR_SESSION_STAGE_CID = "sessionStageCid";
    private static final String ATTR_PREPARED = "prepared";
    private static final String ATTR_PREPARED = "prepared";
    private static final String ATTR_COMMITTED = "committed";
    private static final String ATTR_COMMITTED = "committed";
    private static final String ATTR_DESTROYED = "destroyed";
    private static final String ATTR_SEALED = "sealed";
    private static final String ATTR_SEALED = "sealed";
    private static final String ATTR_MULTI_PACKAGE = "multiPackage";
    private static final String ATTR_MULTI_PACKAGE = "multiPackage";
    private static final String ATTR_PARENT_SESSION_ID = "parentSessionId";
    private static final String ATTR_PARENT_SESSION_ID = "parentSessionId";
@@ -533,7 +534,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            int sessionId, int userId, int installerUid, @NonNull InstallSource installSource,
            int sessionId, int userId, int installerUid, @NonNull InstallSource installSource,
            SessionParams params, long createdMillis,
            SessionParams params, long createdMillis,
            File stageDir, String stageCid, InstallationFile[] files, boolean prepared,
            File stageDir, String stageCid, InstallationFile[] files, boolean prepared,
            boolean committed, boolean sealed,
            boolean committed, boolean destroyed, boolean sealed,
            @Nullable int[] childSessionIds, int parentSessionId, boolean isReady,
            @Nullable int[] childSessionIds, int parentSessionId, boolean isReady,
            boolean isFailed, boolean isApplied, int stagedSessionErrorCode,
            boolean isFailed, boolean isApplied, int stagedSessionErrorCode,
            String stagedSessionErrorMessage) {
            String stagedSessionErrorMessage) {
@@ -579,6 +580,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {


        mPrepared = prepared;
        mPrepared = prepared;
        mCommitted = committed;
        mCommitted = committed;
        mDestroyed = destroyed;
        mStagedSessionReady = isReady;
        mStagedSessionReady = isReady;
        mStagedSessionFailed = isFailed;
        mStagedSessionFailed = isFailed;
        mStagedSessionApplied = isApplied;
        mStagedSessionApplied = isApplied;
@@ -713,6 +715,13 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        }
        }
    }
    }


    /** {@hide} */
    boolean isDestroyed() {
        synchronized (mLock) {
            return mDestroyed;
        }
    }

    /** Returns true if a staged session has reached a final state and can be forgotten about  */
    /** Returns true if a staged session has reached a final state and can be forgotten about  */
    public boolean isStagedAndInTerminalState() {
    public boolean isStagedAndInTerminalState() {
        synchronized (mLock) {
        synchronized (mLock) {
@@ -3197,7 +3206,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
     */
     */
    void write(@NonNull XmlSerializer out, @NonNull File sessionsDir) throws IOException {
    void write(@NonNull XmlSerializer out, @NonNull File sessionsDir) throws IOException {
        synchronized (mLock) {
        synchronized (mLock) {
            if (mDestroyed) {
            if (mDestroyed && !params.isStaged) {
                return;
                return;
            }
            }


@@ -3223,6 +3232,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            }
            }
            writeBooleanAttribute(out, ATTR_PREPARED, isPrepared());
            writeBooleanAttribute(out, ATTR_PREPARED, isPrepared());
            writeBooleanAttribute(out, ATTR_COMMITTED, isCommitted());
            writeBooleanAttribute(out, ATTR_COMMITTED, isCommitted());
            writeBooleanAttribute(out, ATTR_DESTROYED, isDestroyed());
            writeBooleanAttribute(out, ATTR_SEALED, isSealed());
            writeBooleanAttribute(out, ATTR_SEALED, isSealed());


            writeBooleanAttribute(out, ATTR_MULTI_PACKAGE, params.isMultiPackage);
            writeBooleanAttribute(out, ATTR_MULTI_PACKAGE, params.isMultiPackage);
@@ -3352,6 +3362,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        final String stageCid = readStringAttribute(in, ATTR_SESSION_STAGE_CID);
        final String stageCid = readStringAttribute(in, ATTR_SESSION_STAGE_CID);
        final boolean prepared = readBooleanAttribute(in, ATTR_PREPARED, true);
        final boolean prepared = readBooleanAttribute(in, ATTR_PREPARED, true);
        final boolean committed = readBooleanAttribute(in, ATTR_COMMITTED);
        final boolean committed = readBooleanAttribute(in, ATTR_COMMITTED);
        final boolean destroyed = readBooleanAttribute(in, ATTR_DESTROYED);
        final boolean sealed = readBooleanAttribute(in, ATTR_SEALED);
        final boolean sealed = readBooleanAttribute(in, ATTR_SEALED);
        final int parentSessionId = readIntAttribute(in, ATTR_PARENT_SESSION_ID,
        final int parentSessionId = readIntAttribute(in, ATTR_PARENT_SESSION_ID,
                SessionInfo.INVALID_ID);
                SessionInfo.INVALID_ID);
@@ -3473,7 +3484,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        return new PackageInstallerSession(callback, context, pm, sessionProvider,
        return new PackageInstallerSession(callback, context, pm, sessionProvider,
                installerThread, stagingManager, sessionId, userId, installerUid,
                installerThread, stagingManager, sessionId, userId, installerUid,
                installSource, params, createdMillis, stageDir, stageCid, fileArray,
                installSource, params, createdMillis, stageDir, stageCid, fileArray,
                prepared, committed, sealed, childSessionIdsArray, parentSessionId,
                prepared, committed, destroyed, sealed, childSessionIdsArray, parentSessionId,
                isReady, isFailed, isApplied, stagedSessionErrorCode, stagedSessionErrorMessage);
                isReady, isFailed, isApplied, stagedSessionErrorCode, stagedSessionErrorMessage);
    }
    }
}
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -137,6 +137,9 @@ public class StagingManager {
        synchronized (mStagedSessions) {
        synchronized (mStagedSessions) {
            for (int i = 0; i < mStagedSessions.size(); i++) {
            for (int i = 0; i < mStagedSessions.size(); i++) {
                final PackageInstallerSession stagedSession = mStagedSessions.valueAt(i);
                final PackageInstallerSession stagedSession = mStagedSessions.valueAt(i);
                if (stagedSession.isDestroyed()) {
                    continue;
                }
                result.add(stagedSession.generateInfoForCaller(false /*icon*/, callingUid));
                result.add(stagedSession.generateInfoForCaller(false /*icon*/, callingUid));
            }
            }
        }
        }
+1 −0
Original line number Original line Diff line number Diff line
@@ -178,6 +178,7 @@ public class PackageInstallerSessionTest {
                /* files */ null,
                /* files */ null,
                /* prepared */ true,
                /* prepared */ true,
                /* committed */ true,
                /* committed */ true,
                /* destroyed */ staged ? true : false,
                /* sealed */ false,  // Setting to true would trigger some PM logic.
                /* sealed */ false,  // Setting to true would trigger some PM logic.
                /* childSessionIds */ childSessionIds != null ? childSessionIds : new int[0],
                /* childSessionIds */ childSessionIds != null ? childSessionIds : new int[0],
                /* parentSessionId */ parentSessionId,
                /* parentSessionId */ parentSessionId,