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

Commit 70bdd979 authored by JW Wang's avatar JW Wang
Browse files

Put rollbacks into #mRollbacks (9/n)

Now we check Rollback#isNewRollback for rollbacks that were originally
in #mNewRollbacks.

for (Rollback newRollback : mNewRollbacks) {
  // Do something with newRollback...
}

will be replaced by:

for (Rollback newRollback : mRollbacks) {
  if (newRollback.isNewRollback()) {
    // Do something with newRollback...
  }
}

Since mRollbacks includes new rollbacks, be careful not to apply
operations not appropriate to new rollbacks when iterating over
mRollbacks. Luckily most of the code is future-proof that needs no
changes.

Note now #mNewRollbacks is always empty. We will remove it in the next
CL.

Bug: 147400979
Test: atest RollbackTest StagedRollbackTest
Change-Id: Ia3a4116b352228adc0b152d42c85920f375beb28
parent 13ef57fd
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -216,6 +216,10 @@ public final class RollbackManager {
     * across device reboot, by simulating what happens on reboot without
     * actually rebooting the device.
     *
     * Note rollbacks in the process of enabling will be lost after calling
     * this method since they are not persisted yet. Don't call this method
     * in the middle of the install process.
     *
     * @throws SecurityException if the caller does not have appropriate permissions.
     *
     * @hide
+12 −11
Original line number Diff line number Diff line
@@ -241,14 +241,14 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                    }
                    synchronized (mLock) {
                        Rollback found = null;
                        for (Rollback newRollback : mNewRollbacks) {
                            if (newRollback.hasToken(token)) {
                                found = newRollback;
                        for (Rollback rollback : mRollbacks) {
                            if (rollback.isNewRollback() && rollback.hasToken(token)) {
                                found = rollback;
                                break;
                            }
                        }
                        if (found != null) {
                            mNewRollbacks.remove(found);
                            mRollbacks.remove(found);
                            found.delete(mAppDataRollbackHelper);
                        }
                    }
@@ -810,7 +810,7 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            newRollback = getNewRollbackForPackageSessionLocked(packageSession.getSessionId());
            if (newRollback == null) {
                newRollback = createNewRollbackLocked(parentSession);
                mNewRollbacks.add(newRollback);
                mRollbacks.add(newRollback);
                newRollback.setIsNewRollback(true);
            }
        }
@@ -836,7 +836,8 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            Iterator<Rollback> iter = mRollbacks.iterator();
            while (iter.hasNext()) {
                Rollback rollback = iter.next();
                if (rollback.getStagedSessionId() == sessionId) {
                if (rollback.getStagedSessionId() == sessionId
                        || (rollback.isNewRollback() && rollback.containsSessionId(sessionId))) {
                    Slog.w(TAG, "Delete rollback id=" + rollback.info.getRollbackId()
                            + " for session id=" + sessionId);
                    iter.remove();
@@ -1201,7 +1202,7 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
                synchronized (mLock) {
                    newRollback = getNewRollbackForPackageSessionLocked(sessionId);
                    if (newRollback != null && newRollback.notifySessionWithSuccess()) {
                        mNewRollbacks.remove(newRollback);
                        mRollbacks.remove(newRollback);
                        newRollback.setIsNewRollback(false);
                    } else {
                        // Not all child sessions finished with success.
@@ -1385,11 +1386,11 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
    @WorkerThread
    @GuardedBy("mLock")
    Rollback getNewRollbackForPackageSessionLocked(int packageSessionId) {
        // We expect mNewRollbacks to be a very small list; linear search
        // We expect mRollbacks to be a very small list; linear search
        // should be plenty fast.
        for (Rollback newRollback: mNewRollbacks) {
            if (newRollback.containsSessionId(packageSessionId)) {
                return newRollback;
        for (Rollback rollback: mRollbacks) {
            if (rollback.isNewRollback() && rollback.containsSessionId(packageSessionId)) {
                return rollback;
            }
        }
        return null;