From d2c0cd4313896924886c3be03b28d092c51eb522 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Thu, 15 Sep 2011 15:51:29 -0700 Subject: [PATCH] Don't do full backup/restore before setup On the restore side, there's a bunch of one-time setup, device provisioning, etc that we're very much not prepared to do in lieu of running setup wizard, at least at this time. On the backup side, it simply doesn't make sense to back up stuff before the device has been set up. Part of bug 5290261 Change-Id: If1c65e88e2da589d6204232d2b59c3e994f4ed3f --- .../android/server/BackupManagerService.java | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java index 2938c45e2c535..6ac6c9807a465 100644 --- a/services/java/com/android/server/BackupManagerService.java +++ b/services/java/com/android/server/BackupManagerService.java @@ -34,6 +34,7 @@ import android.app.backup.IRestoreSession; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentName; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; @@ -4765,6 +4766,11 @@ class BackupManagerService extends IBackupManager.Stub { } } + boolean deviceIsProvisioned() { + final ContentResolver resolver = mContext.getContentResolver(); + return (Settings.Secure.getInt(resolver, Settings.Secure.DEVICE_PROVISIONED, 0) != 0); + } + // Run a *full* backup pass for the given package, writing the resulting data stream // to the supplied file descriptor. This method is synchronous and does not return // to the caller until the backup has been completed. @@ -4785,12 +4791,19 @@ class BackupManagerService extends IBackupManager.Stub { } } - if (DEBUG) Slog.v(TAG, "Requesting full backup: apks=" + includeApks - + " shared=" + includeShared + " all=" + doAllApps - + " pkgs=" + pkgList); - long oldId = Binder.clearCallingIdentity(); try { + // Doesn't make sense to do a full backup prior to setup + if (!deviceIsProvisioned()) { + Slog.i(TAG, "Full backup not supported before setup"); + return; + } + + if (DEBUG) Slog.v(TAG, "Requesting full backup: apks=" + includeApks + + " shared=" + includeShared + " all=" + doAllApps + + " pkgs=" + pkgList); + Slog.i(TAG, "Beginning full backup..."); + FullBackupParams params = new FullBackupParams(fd, includeApks, includeShared, doAllApps, pkgList); final int token = generateToken(); @@ -4822,17 +4835,25 @@ class BackupManagerService extends IBackupManager.Stub { // just eat it } Binder.restoreCallingIdentity(oldId); + Slog.d(TAG, "Full backup processing complete."); } - if (MORE_DEBUG) Slog.d(TAG, "Full backup done; returning to caller"); } public void fullRestore(ParcelFileDescriptor fd) { mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullRestore"); - Slog.i(TAG, "Beginning full restore..."); long oldId = Binder.clearCallingIdentity(); try { + // Check whether the device has been provisioned -- we don't handle + // full restores prior to completing the setup process. + if (!deviceIsProvisioned()) { + Slog.i(TAG, "Full restore not permitted before setup"); + return; + } + + Slog.i(TAG, "Beginning full restore..."); + FullRestoreParams params = new FullRestoreParams(fd); final int token = generateToken(); synchronized (mFullConfirmations) { @@ -4863,7 +4884,7 @@ class BackupManagerService extends IBackupManager.Stub { Slog.w(TAG, "Error trying to close fd after full restore: " + e); } Binder.restoreCallingIdentity(oldId); - Slog.i(TAG, "Full restore completed"); + Slog.i(TAG, "Full restore processing complete."); } }