OSDN Git Service

Tear down agent after preflight rejection
authorChristopher Tate <ctate@google.com>
Mon, 10 Jul 2017 23:19:41 +0000 (16:19 -0700)
committerChristopher Tate <ctate@google.com>
Tue, 11 Jul 2017 00:25:19 +0000 (17:25 -0700)
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

services/backup/java/com/android/server/backup/BackupManagerService.java

index 4a7eef9..abfc31e 100644 (file)
@@ -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!