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

Commit ba9e399f authored by Shreyas Basarge's avatar Shreyas Basarge Committed by Android (Google) Code Review
Browse files

Merge "Disallow parallel backups"

parents 6a4b9a33 aac009b0
Loading
Loading
Loading
Loading
+46 −11
Original line number Diff line number Diff line
@@ -2682,20 +2682,33 @@ public class BackupManagerService {
            mStateDir = new File(mBaseStateDir, dirName);
            mCurrentOpToken = generateToken();

            mCurrentState = BackupState.INITIAL;
            mFinished = false;

            synchronized (mCurrentOpLock) {
                if (isBackupOperationInProgress()) {
                    if (DEBUG) {
                        Slog.d(TAG, "Skipping backup since one is already in progress.");
                    }
                    mCancelAll = true;
                    mFullBackupTask = null;
                    mCurrentState = BackupState.FINAL;
                    addBackupTrace("Skipped. Backup already in progress.");
                } else {
                    mCurrentState = BackupState.INITIAL;
                    CountDownLatch latch = new CountDownLatch(1);
                    String[] fullBackups =
                            mPendingFullBackups.toArray(new String[mPendingFullBackups.size()]);
                    mFullBackupTask =
                            new PerformFullTransportBackupTask(/*fullBackupRestoreObserver*/ null,
                            fullBackups, /*updateSchedule*/ false, /*runningJob*/ null, latch,
                                    fullBackups, /*updateSchedule*/ false, /*runningJob*/ null,
                                    latch,
                                    mObserver, mMonitor, mUserInitiated);

                    registerTask();
                    addBackupTrace("STATE => INITIAL");
                }
            }
        }

        /**
         * Put this task in the repository of running tasks.
@@ -3077,7 +3090,9 @@ public class BackupManagerService {
                mWakelock.acquire();
                (new Thread(mFullBackupTask, "full-transport-requested")).start();
            } else if (mCancelAll) {
                if (mFullBackupTask != null) {
                    mFullBackupTask.unregisterTask();
                }
                sendBackupFinished(mObserver, BackupManager.ERROR_BACKUP_CANCELLED);
            } else {
                mFullBackupTask.unregisterTask();
@@ -3561,6 +3576,18 @@ public class BackupManagerService {
        }
    }

    private boolean isBackupOperationInProgress() {
        synchronized (mCurrentOpLock) {
            for (int i = 0; i < mCurrentOperations.size(); i++) {
                Operation op = mCurrentOperations.valueAt(i);
                if (op.type == OP_TYPE_BACKUP && op.state == OP_PENDING) {
                    return true;
                }
            }
        }
        return false;
    }


    // ----- Full backup/restore to a file/socket -----

@@ -4543,6 +4570,14 @@ public class BackupManagerService {
            mCurrentOpToken = generateToken();
            mBackupRunnerOpToken = generateToken();

            if (isBackupOperationInProgress()) {
                if (DEBUG) {
                    Slog.d(TAG, "Skipping full backup. A backup is already in progress.");
                }
                mCancelAll = true;
                return;
            }

            registerTask();

            for (String pkg : whichPackages) {