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

Commit 0bf44865 authored by Oli Lan's avatar Oli Lan
Browse files

Do not enable rollback for apk session if no rollback found for staged session.

This fixes an issue where rollback may be made available for an apk within
a staged session even if there is no matching rollback for the staged session.

Bug: 139414218
Test: manual test: mixed apk/apex staged install created; rollback expired for the apex;
device rebooted; checked that the new code was activated and rollback not enabled for
the apk part.
Test: atest StagedRollbackTest
Test: atest CtsRollbackManagerHostTestCases

Change-Id: Iea72b7dc74f79c81627ee7eee0ef91ce6676ae52
parent 47114169
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -118,6 +118,10 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
    @GuardedBy("mLock")
    private final List<Rollback> mRollbacks;

    // Apk sessions from a staged session with no matching rollback.
    @GuardedBy("mLock")
    private final IntArray mOrphanedApkSessionIds = new IntArray();

    private final RollbackStore mRollbackStore;

    private final Context mContext;
@@ -655,6 +659,11 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                // hasn't actually been updated.
                onPackageReplaced(apexPackageName);
            }

            synchronized (mLock) {
                mOrphanedApkSessionIds.clear();
            }

            mPackageHealthObserver.onBootCompletedAsync();
        });
    }
@@ -865,6 +874,16 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            }
        }

        // Check to see if this is the apk session for a staged session for which rollback was
        // cancelled.
        synchronized (mLock) {
            if (mOrphanedApkSessionIds.indexOf(parentSession.getSessionId()) != -1) {
                Slog.w(TAG, "Not enabling rollback for apk as no matching staged session "
                        + "rollback exists");
                return false;
            }
        }

        NewRollback newRollback;
        synchronized (mLock) {
            // See if we already have a NewRollback that contains this package
@@ -1122,6 +1141,13 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                        break;
                    }
                }
                if (rollback == null) {
                    // Did not find rollback matching originalSessionId.
                    Slog.e(TAG, "notifyStagedApkSession did not find rollback for session "
                            + originalSessionId
                            + ". Adding orphaned apk session " + apkSessionId);
                    mOrphanedApkSessionIds.add(apkSessionId);
                }
            }

            if (rollback != null) {