From e659fb92750490807d5bb6f27ce01d2253bd7c70 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Mon, 10 Oct 2011 16:34:50 -0700 Subject: [PATCH] Gracefully handle "needs init" transport errors at finish Although it's typical for a backup transport to report that it needs an explicit initialization opportunity when the backup is initiated, it can sometimes come to pass that the "needs init" error condition is reported at backup *finish*. In this case the framework side was failing to properly reset all of the relevant state. The end result was to spin hard forever, holding wakelocks and continually failing to actually perform the necessary init operation, possibly continuing even after a reboot. Fixed. Bug 5434579 Change-Id: If1d72c338526e4019ea524c48a11e71e44e77f71 --- .../java/com/android/server/BackupManagerService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java index 5758954794ffb..f9f5458122ffe 100644 --- a/services/java/com/android/server/BackupManagerService.java +++ b/services/java/com/android/server/BackupManagerService.java @@ -1966,6 +1966,9 @@ class BackupManagerService extends IBackupManager.Stub { synchronized (mQueueLock) { mBackupRunning = false; if (mStatus == BackupConstants.TRANSPORT_NOT_INITIALIZED) { + // Make sure we back up everything and perform the one-time init + clearMetadata(); + if (DEBUG) Slog.d(TAG, "Server requires init; rerunning"); backupNow(); } } @@ -1975,6 +1978,12 @@ class BackupManagerService extends IBackupManager.Stub { mWakelock.release(); } + // Remove the PM metadata state. This will generate an init on the next pass. + void clearMetadata() { + final File pmState = new File(mStateDir, PACKAGE_MANAGER_SENTINEL); + if (pmState.exists()) pmState.delete(); + } + // Invoke an agent's doBackup() and start a timeout message spinning on the main // handler in case it doesn't get back to us. int invokeAgentForBackup(String packageName, IBackupAgent agent,