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

Commit b2c5cacd authored by Richard Uhler's avatar Richard Uhler
Browse files

RollbackManager: Check for applied staged sessions on boot.

Bug: 112431924
Test: atest RollbackTest

Change-Id: I5062993da04a4c1a8f3fa2a1cb97e0a488b630d3
parent ac0d0f9b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -44,4 +44,11 @@ public final class RollbackManagerService extends SystemService {
    public void onUnlockUser(int user) {
        mService.onUnlockUser(user);
    }

    @Override
    public void onBootPhase(int phase) {
        if (phase == SystemService.PHASE_BOOT_COMPLETED) {
            mService.onBootCompleted();
        }
    }
}
+41 −0
Original line number Diff line number Diff line
@@ -486,6 +486,47 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
        });
    }

    void onBootCompleted() {
        getHandler().post(() -> {
            // Check to see if any staged sessions with rollback enabled have
            // been applied.
            List<RollbackData> staged = new ArrayList<>();
            synchronized (mLock) {
                ensureRollbackDataLoadedLocked();
                for (RollbackData data : mAvailableRollbacks) {
                    if (data.stagedSessionId != -1) {
                        staged.add(data);
                    }
                }
            }

            for (RollbackData data : staged) {
                PackageInstaller installer = mContext.getPackageManager().getPackageInstaller();
                PackageInstaller.SessionInfo session = installer.getSessionInfo(
                        data.stagedSessionId);
                if (session != null) {
                    if (session.isSessionApplied()) {
                        synchronized (mLock) {
                            data.isAvailable = true;
                        }
                        try {
                            mRollbackStore.saveAvailableRollback(data);
                        } catch (IOException ioe) {
                            Log.e(TAG, "Unable to save rollback info for : "
                                    + data.rollbackId, ioe);
                        }
                    } else if (session.isSessionFailed()) {
                        // TODO: Do we need to remove this from
                        // mAvailableRollbacks, or is it okay to leave as
                        // unavailable until the next reboot when it will go
                        // away on its own?
                        mRollbackStore.deleteAvailableRollback(data);
                    }
                }
            }
        });
    }

    /**
     * Load rollback data from storage if it has not already been loaded.
     * After calling this funciton, mAvailableRollbacks and