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
This commit is contained in:
Christopher Tate
2010-02-03 15:11:15 -08:00
parent 3c4a1ebc19
commit cce9da5dc3
3 changed files with 40 additions and 0 deletions

View File

@@ -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.
*
* <p>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.
*

View File

@@ -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 )

View File

@@ -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,