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

Commit aac009b0 authored by Shreyas Basarge's avatar Shreyas Basarge
Browse files

Disallow parallel backups

If a backup operation is in progress
when another backup operation is requested,
the new one is skipped. We have to skip the
second one because the current BackupTransport
interface cannot support parallel backups.

Bug: 29010684
Test: Tested manually. Work on GTS test in progress.

Change-Id: I6d8f49897bb42781bafed584a4b75b3b971f75eb
parent 91e5d7fa
Loading
Loading
Loading
Loading
+46 −11
Original line number Diff line number Diff line
@@ -2655,20 +2655,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.
@@ -3050,7 +3063,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();
@@ -3531,6 +3546,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 -----

@@ -4513,6 +4540,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) {