OSDN Git Service

Add null check in BackupManagerService$PerformBackupTask.handleCancel()
authorAnton Philippov <philippov@google.com>
Mon, 27 Mar 2017 13:49:04 +0000 (14:49 +0100)
committerAnton Philippov <philippov@google.com>
Tue, 28 Mar 2017 11:25:44 +0000 (11:25 +0000)
handleCancel() can be called before we start backing up any particular
package, therefore we need to properly handle log messages in that case.

Bug: 36638539
Test: manual
Change-Id: Ic96e2fbad5c0a79640a3419d187e8b5e4d265de3
(cherry picked from commit 519a87db8fabb49f299aa384aeb5cfe4dfedf907)

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

index 037804e..57d3570 100644 (file)
@@ -3537,21 +3537,23 @@ public class BackupManagerService {
                     return;
                 }
                 mCancelAll = cancelAll;
-                // Whoops, the current agent timed out running doBackup().  Tidy up and restage
-                // it for the next time we run a backup pass.
-                // !!! TODO: keep track of failure counts per agent, and blacklist those which
-                // fail repeatedly (i.e. have proved themselves to be buggy).
-                Slog.e(TAG, "Cancel backing up " + mCurrentPackage.packageName);
-                EventLog.writeEvent(EventLogTags.BACKUP_AGENT_FAILURE, mCurrentPackage.packageName);
+                final String logPackageName = (mCurrentPackage != null)
+                        ? mCurrentPackage.packageName
+                        : "no_package_yet";
+                Slog.i(TAG, "Cancel backing up " + logPackageName);
+                EventLog.writeEvent(EventLogTags.BACKUP_AGENT_FAILURE, logPackageName);
+                addBackupTrace("cancel of " + logPackageName + ", cancelAll=" + cancelAll);
                 mMonitor = monitorEvent(mMonitor,
                         BackupManagerMonitor.LOG_EVENT_ID_KEY_VALUE_BACKUP_CANCEL,
                         mCurrentPackage, BackupManagerMonitor.LOG_EVENT_CATEGORY_AGENT,
                         putMonitoringExtra(null, BackupManagerMonitor.EXTRA_LOG_CANCEL_ALL,
                                 mCancelAll));
-                addBackupTrace(
-                        "cancel of " + mCurrentPackage.packageName + ", cancelAll=" + cancelAll);
                 errorCleanup();
                 if (!cancelAll) {
+                    // The current agent either timed out or was cancelled running doBackup().
+                    // Restage it for the next time we run a backup pass.
+                    // !!! TODO: keep track of failure counts per agent, and blacklist those which
+                    // fail repeatedly (i.e. have proved themselves to be buggy).
                     executeNextState(
                             mQueue.isEmpty() ? BackupState.FINAL : BackupState.RUNNING_QUEUE);
                     dataChangedImpl(mCurrentPackage.packageName);