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

Commit 28834a66 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I5e42dee6,Ic8571c08

* changes:
  [RefactoredBMS] Ensure backup doesn't reuse ack tokens nearby in time
  [RefactoredBMS] Eliminate a race condition that could lead to calling PBT#finalizeBackup() twice
parents 2fe81c06 f9b74cc7
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

public class RefactoredBackupManagerService implements BackupManagerServiceInterface {

@@ -626,6 +627,7 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter
    private final SparseArray<Operation> mCurrentOperations = new SparseArray<>();
    private final Object mCurrentOpLock = new Object();
    private final Random mTokenGenerator = new Random();
    final AtomicInteger mNextToken = new AtomicInteger();

    private final SparseArray<AdbParams> mAdbBackupRestoreConfirmations = new SparseArray<>();

@@ -665,15 +667,15 @@ public class RefactoredBackupManagerService implements BackupManagerServiceInter
    @GuardedBy("mQueueLock")
    private ArrayList<FullBackupEntry> mFullBackupQueue;

    // Utility: build a new random integer token
    // Utility: build a new random integer token. The low bits are the ordinal of the
    // operation for near-time uniqueness, and the upper bits are random for app-
    // side unpredictability.
    @Override
    public int generateRandomIntegerToken() {
        int token;
        do {
            synchronized (mTokenGenerator) {
                token = mTokenGenerator.nextInt();
            }
        } while (token < 0);
        int token = mTokenGenerator.nextInt();
        if (token < 0) token = -token;
        token &= ~0xFF;
        token |= (mNextToken.incrementAndGet() & 0xFF);
        return token;
    }

+2 −2
Original line number Diff line number Diff line
@@ -227,9 +227,8 @@ public class PerformBackupTask implements BackupRestoreTask {
                    if (!mFinished) {
                        finalizeBackup();
                    } else {
                        Slog.e(TAG, "Duplicate finish");
                        Slog.e(TAG, "Duplicate finish of K/V pass");
                    }
                    mFinished = true;
                    break;
            }
        }
@@ -609,6 +608,7 @@ public class PerformBackupTask implements BackupRestoreTask {
                    break;
            }
        }
        mFinished = true;
        Slog.i(TAG, "K/V backup pass finished.");
        // Only once we're entirely finished do we release the wakelock for k/v backup.
        backupManagerService.getWakelock().release();