From cce9da5dc3d515f98c260af41a03e61e57b4e7a6 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Wed, 3 Feb 2010 15:11:15 -0800 Subject: [PATCH] Add auto-restore setting and Backup Manager awareness thereof This setting, like BACKUP_ENABLE, should never be set directly in the secure settings database. Instead, it should be manipulated through the new IBackupManager method setAutoRestore(boolean). Change-Id: I5c3226ca85b6148bb756d753d7f9e4ea76e878c4 --- core/java/android/backup/IBackupManager.aidl | 15 +++++++++++++++ core/java/android/provider/Settings.java | 8 ++++++++ .../android/server/BackupManagerService.java | 17 +++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/core/java/android/backup/IBackupManager.aidl b/core/java/android/backup/IBackupManager.aidl index cb775f7504dc4..bf6c79f685c4a 100644 --- a/core/java/android/backup/IBackupManager.aidl +++ b/core/java/android/backup/IBackupManager.aidl @@ -72,6 +72,21 @@ interface IBackupManager { */ void setBackupEnabled(boolean isEnabled); + /** + * Enable/disable automatic restore of application data at install time. When + * enabled, installation of any package will involve the Backup Manager. If data + * exists for the newly-installed package, either from the device's current [enabled] + * backup dataset or from the restore set used in the last wholesale restore operation, + * that data will be supplied to the new package's restore agent before the package + * is made generally available for launch. + * + *

Callers must hold the android.permission.BACKUP permission to use this method. + * + * @param doAutoRestore When true, enables the automatic app-data restore facility. When + * false, this facility will be disabled. + */ + void setAutoRestore(boolean doAutoRestore); + /** * Indicate that any necessary one-time provisioning has occurred. * diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 23a9f496e6a25..71280057d3ea6 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -2424,6 +2424,14 @@ public final class Settings { */ public static final String BACKUP_ENABLED = "backup_enabled"; + /** + * Controls whether application data is automatically restored from backup + * at install time. + * Type: int ( 0 = disabled, 1 = enabled ) + * @hide + */ + public static final String BACKUP_AUTO_RESTORE = "backup_auto_restore"; + /** * Indicates whether settings backup has been fully provisioned. * Type: int ( 0 = unprovisioned, 1 = fully provisioned ) diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java index 0562c5535a13e..0c1e0602ea3b8 100644 --- a/services/java/com/android/server/BackupManagerService.java +++ b/services/java/com/android/server/BackupManagerService.java @@ -118,6 +118,7 @@ class BackupManagerService extends IBackupManager.Stub { boolean mEnabled; // access to this is synchronized on 'this' boolean mProvisioned; + boolean mAutoRestore; PowerManager.WakeLock mWakelock; HandlerThread mHandlerThread = new HandlerThread("backup", Process.THREAD_PRIORITY_BACKGROUND); BackupHandler mBackupHandler; @@ -340,6 +341,8 @@ class BackupManagerService extends IBackupManager.Stub { Settings.Secure.BACKUP_ENABLED, 0) != 0; mProvisioned = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.BACKUP_PROVISIONED, 0) != 0; + mAutoRestore = Settings.Secure.getInt(context.getContentResolver(), + Settings.Secure.BACKUP_AUTO_RESTORE, 0) != 0; // If Encrypted file systems is enabled or disabled, this call will return the // correct directory. mBaseStateDir = new File(Environment.getSecureDataDirectory(), "backup"); @@ -2019,6 +2022,20 @@ class BackupManagerService extends IBackupManager.Stub { } } + // Enable/disable automatic restore of app data at install time + public void setAutoRestore(boolean doAutoRestore) { + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, + "setBackupEnabled"); + + Log.i(TAG, "Auto restore => " + doAutoRestore); + + synchronized (this) { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.BACKUP_AUTO_RESTORE, doAutoRestore ? 1 : 0); + mAutoRestore = doAutoRestore; + } + } + // Mark the backup service as having been provisioned public void setBackupProvisioned(boolean available) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,