From e989348ca34d6714d9a8ddd5a9dac2b61a91e9bf Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Mon, 10 Jul 2017 16:19:41 -0700 Subject: [PATCH] Tear down agent after preflight rejection We were failing to tear down a full-backup target process in several error situations (preflight, quota exceeded, unforeseen), leaving the app in an incoherent execution state for general operation. Now we properly tear down the target in all full-backup early exits. Fix #63540605 Test: run cts -m CtsBackupTestCases -t android.backup.cts.BackupQuotaTest Change-Id: Id8f6fe0381e85a8d8e4015fc6fd34bb840859e7a --- .../android/server/backup/BackupManagerService.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index 4a7eef930f65e..abfc31e29eb53 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -4871,6 +4871,7 @@ public class BackupManagerService implements BackupManagerServiceInterface { final int N = mPackages.size(); final byte[] buffer = new byte[8192]; for (int i = 0; i < N; i++) { + mBackupRunner = null; PackageInfo currentPackage = mPackages.get(i); String packageName = currentPackage.packageName; if (DEBUG) { @@ -5054,7 +5055,13 @@ public class BackupManagerService implements BackupManagerServiceInterface { } EventLog.writeEvent(EventLogTags.FULL_BACKUP_AGENT_FAILURE, packageName, "transport rejected"); - // Do nothing, clean up, and continue looping. + // This failure state can come either a-priori from the transport, or + // from the preflight pass. If we got as far as preflight, we now need + // to tear down the target process. + if (mBackupRunner != null) { + tearDownAgentAndKill(currentPackage.applicationInfo); + } + // ... and continue looping. } else if (backupPackageStatus == BackupTransport.TRANSPORT_QUOTA_EXCEEDED) { sendBackupOnPackageResult(mBackupObserver, packageName, BackupManager.ERROR_TRANSPORT_QUOTA_EXCEEDED); @@ -5063,6 +5070,7 @@ public class BackupManagerService implements BackupManagerServiceInterface { EventLog.writeEvent(EventLogTags.FULL_BACKUP_QUOTA_EXCEEDED, packageName); } + tearDownAgentAndKill(currentPackage.applicationInfo); // Do nothing, clean up, and continue looping. } else if (backupPackageStatus == BackupTransport.AGENT_ERROR) { sendBackupOnPackageResult(mBackupObserver, packageName, @@ -5086,6 +5094,7 @@ public class BackupManagerService implements BackupManagerServiceInterface { EventLog.writeEvent(EventLogTags.FULL_BACKUP_TRANSPORT_FAILURE); // Abort entire backup pass. backupRunStatus = BackupManager.ERROR_TRANSPORT_ABORTED; + tearDownAgentAndKill(currentPackage.applicationInfo); return; } else { // Success!