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

Commit f1154511 authored by Gavin Corkery's avatar Gavin Corkery
Browse files

Block until userdata backup/restore has taken place

Currently, userdata backup/restore is performed on a handler thread.
This means that we cannot guarantee that an application will not begin
running during a backup/restore, as we have no guarantees of when
the backup logic will actually execute.

In the onUnlockUser case we can block until the handler thread has
completed its work by using a CountdownLatch. In the general case we
will keep
snapshotAndRestoreUserData on the handler thread, using Package
Manager's token to decide when to unfreeze

Test: atest RollbackTest
Test: atest StagedRollbackTest
Bug: 124032231
Change-Id: I4c818833e48a549e8a3aa8401539f44c14b89b57
parent 2c833c2b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -564,6 +564,10 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
    }

    void onUnlockUser(int userId) {
        // In order to ensure that no package begins running while a backup or restore is taking
        // place, onUnlockUser must remain blocked until all pending backups and restores have
        // completed.
        CountDownLatch latch = new CountDownLatch(1);
        getHandler().post(() -> {
            final List<Rollback> rollbacks;
            synchronized (mLock) {
@@ -576,7 +580,14 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            for (Rollback rollback : changed) {
                saveRollback(rollback);
            }
            latch.countDown();
        });

        try {
            latch.await();
        } catch (InterruptedException ie) {
            throw new IllegalStateException("RollbackManagerHandlerThread interrupted");
        }
    }

    private void updateRollbackLifetimeDurationInMillis() {