Loading core/java/android/backup/IBackupManager.aidl +7 −0 Original line number Original line Diff line number Diff line Loading @@ -72,6 +72,13 @@ interface IBackupManager { */ */ void setBackupEnabled(boolean isEnabled); void setBackupEnabled(boolean isEnabled); /** * Indicate that any necessary one-time provisioning has occurred. * * <p>Callers must hold the android.permission.BACKUP permission to use this method. */ void setBackupProvisioned(boolean isProvisioned); /** /** * Report whether the backup mechanism is currently enabled. * Report whether the backup mechanism is currently enabled. * * Loading core/java/android/provider/Settings.java +8 −1 Original line number Original line Diff line number Diff line Loading @@ -2291,12 +2291,19 @@ public final class Settings { public static final String USE_LOCATION_FOR_SERVICES = "use_location"; public static final String USE_LOCATION_FOR_SERVICES = "use_location"; /** /** * Controls whether data backup is enabled. * Controls whether settings backup is enabled. * Type: int ( 0 = disabled, 1 = enabled ) * Type: int ( 0 = disabled, 1 = enabled ) * @hide * @hide */ */ public static final String BACKUP_ENABLED = "backup_enabled"; public static final String BACKUP_ENABLED = "backup_enabled"; /** * Indicates whether settings backup has been fully provisioned. * Type: int ( 0 = unprovisioned, 1 = fully provisioned ) * @hide */ public static final String BACKUP_PROVISIONED = "backup_provisioned"; /** /** * Component of the transport to use for backup/restore. * Component of the transport to use for backup/restore. * @hide * @hide Loading services/java/com/android/server/BackupManagerService.java +43 −6 Original line number Original line Diff line number Diff line Loading @@ -81,6 +81,10 @@ class BackupManagerService extends IBackupManager.Stub { // trigger an immediate pass. // trigger an immediate pass. private static final long BACKUP_INTERVAL = AlarmManager.INTERVAL_HOUR; private static final long BACKUP_INTERVAL = AlarmManager.INTERVAL_HOUR; // The amount of time between the initial provisioning of the device and // the first backup pass. private static final long FIRST_BACKUP_INTERVAL = 12 * AlarmManager.INTERVAL_HOUR; private static final String RUN_BACKUP_ACTION = "_backup_run_"; private static final String RUN_BACKUP_ACTION = "_backup_run_"; private static final int MSG_RUN_BACKUP = 1; private static final int MSG_RUN_BACKUP = 1; private static final int MSG_RUN_FULL_BACKUP = 2; private static final int MSG_RUN_FULL_BACKUP = 2; Loading @@ -97,6 +101,7 @@ class BackupManagerService extends IBackupManager.Stub { private AlarmManager mAlarmManager; private AlarmManager mAlarmManager; private boolean mEnabled; // access to this is synchronized on 'this' private boolean mEnabled; // access to this is synchronized on 'this' private boolean mProvisioned; private PowerManager.WakeLock mWakelock; private PowerManager.WakeLock mWakelock; private final BackupHandler mBackupHandler = new BackupHandler(); private final BackupHandler mBackupHandler = new BackupHandler(); private PendingIntent mRunBackupIntent; private PendingIntent mRunBackupIntent; Loading Loading @@ -188,6 +193,9 @@ class BackupManagerService extends IBackupManager.Stub { // Set up our bookkeeping // Set up our bookkeeping boolean areEnabled = Settings.Secure.getInt(context.getContentResolver(), boolean areEnabled = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.BACKUP_ENABLED, 0) != 0; Settings.Secure.BACKUP_ENABLED, 0) != 0; // !!! TODO: mProvisioned needs to default to 0, not 1. mProvisioned = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.BACKUP_PROVISIONED, 1) != 0; mBaseStateDir = new File(Environment.getDataDirectory(), "backup"); mBaseStateDir = new File(Environment.getDataDirectory(), "backup"); mDataDir = Environment.getDownloadCacheDirectory(); mDataDir = Environment.getDownloadCacheDirectory(); Loading Loading @@ -1301,7 +1309,7 @@ class BackupManagerService extends IBackupManager.Stub { } } } } // Enable/disable the backup transport // Enable/disable the backup service public void setBackupEnabled(boolean enable) { public void setBackupEnabled(boolean enable) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "setBackupEnabled"); "setBackupEnabled"); Loading @@ -1314,11 +1322,9 @@ class BackupManagerService extends IBackupManager.Stub { } } synchronized (mQueueLock) { synchronized (mQueueLock) { if (enable && !wasEnabled) { if (enable && !wasEnabled && mProvisioned) { // if we've just been enabled, start scheduling backup passes // if we've just been enabled, start scheduling backup passes long when = System.currentTimeMillis() + BACKUP_INTERVAL; startBackupAlarmsLocked(BACKUP_INTERVAL); mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, when, BACKUP_INTERVAL, mRunBackupIntent); } else if (!enable) { } else if (!enable) { // No longer enabled, so stop running backups // No longer enabled, so stop running backups mAlarmManager.cancel(mRunBackupIntent); mAlarmManager.cancel(mRunBackupIntent); Loading @@ -1326,6 +1332,36 @@ class BackupManagerService extends IBackupManager.Stub { } } } } // Mark the backup service as having been provisioned public void setBackupProvisioned(boolean available) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "setBackupProvisioned"); boolean wasProvisioned = mProvisioned; synchronized (this) { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.BACKUP_PROVISIONED, available ? 1 : 0); mProvisioned = available; } synchronized (mQueueLock) { if (available && !wasProvisioned && mEnabled) { // we're now good to go, so start the backup alarms startBackupAlarmsLocked(FIRST_BACKUP_INTERVAL); } else if (!available) { // No longer enabled, so stop running backups Log.w(TAG, "Backup service no longer provisioned"); mAlarmManager.cancel(mRunBackupIntent); } } } private void startBackupAlarmsLocked(long delayBeforeFirstBackup) { long when = System.currentTimeMillis() + delayBeforeFirstBackup; mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, when, BACKUP_INTERVAL, mRunBackupIntent); } // Report whether the backup mechanism is currently enabled // Report whether the backup mechanism is currently enabled public boolean isBackupEnabled() { public boolean isBackupEnabled() { mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "isBackupEnabled"); mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "isBackupEnabled"); Loading Loading @@ -1506,7 +1542,8 @@ class BackupManagerService extends IBackupManager.Stub { synchronized (mQueueLock) { synchronized (mQueueLock) { long oldId = Binder.clearCallingIdentity(); long oldId = Binder.clearCallingIdentity(); pw.println("Backup Manager is " + (mEnabled ? "enabled" : "disabled")); pw.println("Backup Manager is " + (mEnabled ? "enabled" : "disabled") + " / " + (!mProvisioned ? "not " : "") + "provisioned"); pw.println("Available transports:"); pw.println("Available transports:"); for (String t : listAllTransports()) { for (String t : listAllTransports()) { String pad = (t.equals(mCurrentTransport)) ? " * " : " "; String pad = (t.equals(mCurrentTransport)) ? " * " : " "; Loading Loading
core/java/android/backup/IBackupManager.aidl +7 −0 Original line number Original line Diff line number Diff line Loading @@ -72,6 +72,13 @@ interface IBackupManager { */ */ void setBackupEnabled(boolean isEnabled); void setBackupEnabled(boolean isEnabled); /** * Indicate that any necessary one-time provisioning has occurred. * * <p>Callers must hold the android.permission.BACKUP permission to use this method. */ void setBackupProvisioned(boolean isProvisioned); /** /** * Report whether the backup mechanism is currently enabled. * Report whether the backup mechanism is currently enabled. * * Loading
core/java/android/provider/Settings.java +8 −1 Original line number Original line Diff line number Diff line Loading @@ -2291,12 +2291,19 @@ public final class Settings { public static final String USE_LOCATION_FOR_SERVICES = "use_location"; public static final String USE_LOCATION_FOR_SERVICES = "use_location"; /** /** * Controls whether data backup is enabled. * Controls whether settings backup is enabled. * Type: int ( 0 = disabled, 1 = enabled ) * Type: int ( 0 = disabled, 1 = enabled ) * @hide * @hide */ */ public static final String BACKUP_ENABLED = "backup_enabled"; public static final String BACKUP_ENABLED = "backup_enabled"; /** * Indicates whether settings backup has been fully provisioned. * Type: int ( 0 = unprovisioned, 1 = fully provisioned ) * @hide */ public static final String BACKUP_PROVISIONED = "backup_provisioned"; /** /** * Component of the transport to use for backup/restore. * Component of the transport to use for backup/restore. * @hide * @hide Loading
services/java/com/android/server/BackupManagerService.java +43 −6 Original line number Original line Diff line number Diff line Loading @@ -81,6 +81,10 @@ class BackupManagerService extends IBackupManager.Stub { // trigger an immediate pass. // trigger an immediate pass. private static final long BACKUP_INTERVAL = AlarmManager.INTERVAL_HOUR; private static final long BACKUP_INTERVAL = AlarmManager.INTERVAL_HOUR; // The amount of time between the initial provisioning of the device and // the first backup pass. private static final long FIRST_BACKUP_INTERVAL = 12 * AlarmManager.INTERVAL_HOUR; private static final String RUN_BACKUP_ACTION = "_backup_run_"; private static final String RUN_BACKUP_ACTION = "_backup_run_"; private static final int MSG_RUN_BACKUP = 1; private static final int MSG_RUN_BACKUP = 1; private static final int MSG_RUN_FULL_BACKUP = 2; private static final int MSG_RUN_FULL_BACKUP = 2; Loading @@ -97,6 +101,7 @@ class BackupManagerService extends IBackupManager.Stub { private AlarmManager mAlarmManager; private AlarmManager mAlarmManager; private boolean mEnabled; // access to this is synchronized on 'this' private boolean mEnabled; // access to this is synchronized on 'this' private boolean mProvisioned; private PowerManager.WakeLock mWakelock; private PowerManager.WakeLock mWakelock; private final BackupHandler mBackupHandler = new BackupHandler(); private final BackupHandler mBackupHandler = new BackupHandler(); private PendingIntent mRunBackupIntent; private PendingIntent mRunBackupIntent; Loading Loading @@ -188,6 +193,9 @@ class BackupManagerService extends IBackupManager.Stub { // Set up our bookkeeping // Set up our bookkeeping boolean areEnabled = Settings.Secure.getInt(context.getContentResolver(), boolean areEnabled = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.BACKUP_ENABLED, 0) != 0; Settings.Secure.BACKUP_ENABLED, 0) != 0; // !!! TODO: mProvisioned needs to default to 0, not 1. mProvisioned = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.BACKUP_PROVISIONED, 1) != 0; mBaseStateDir = new File(Environment.getDataDirectory(), "backup"); mBaseStateDir = new File(Environment.getDataDirectory(), "backup"); mDataDir = Environment.getDownloadCacheDirectory(); mDataDir = Environment.getDownloadCacheDirectory(); Loading Loading @@ -1301,7 +1309,7 @@ class BackupManagerService extends IBackupManager.Stub { } } } } // Enable/disable the backup transport // Enable/disable the backup service public void setBackupEnabled(boolean enable) { public void setBackupEnabled(boolean enable) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "setBackupEnabled"); "setBackupEnabled"); Loading @@ -1314,11 +1322,9 @@ class BackupManagerService extends IBackupManager.Stub { } } synchronized (mQueueLock) { synchronized (mQueueLock) { if (enable && !wasEnabled) { if (enable && !wasEnabled && mProvisioned) { // if we've just been enabled, start scheduling backup passes // if we've just been enabled, start scheduling backup passes long when = System.currentTimeMillis() + BACKUP_INTERVAL; startBackupAlarmsLocked(BACKUP_INTERVAL); mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, when, BACKUP_INTERVAL, mRunBackupIntent); } else if (!enable) { } else if (!enable) { // No longer enabled, so stop running backups // No longer enabled, so stop running backups mAlarmManager.cancel(mRunBackupIntent); mAlarmManager.cancel(mRunBackupIntent); Loading @@ -1326,6 +1332,36 @@ class BackupManagerService extends IBackupManager.Stub { } } } } // Mark the backup service as having been provisioned public void setBackupProvisioned(boolean available) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "setBackupProvisioned"); boolean wasProvisioned = mProvisioned; synchronized (this) { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.BACKUP_PROVISIONED, available ? 1 : 0); mProvisioned = available; } synchronized (mQueueLock) { if (available && !wasProvisioned && mEnabled) { // we're now good to go, so start the backup alarms startBackupAlarmsLocked(FIRST_BACKUP_INTERVAL); } else if (!available) { // No longer enabled, so stop running backups Log.w(TAG, "Backup service no longer provisioned"); mAlarmManager.cancel(mRunBackupIntent); } } } private void startBackupAlarmsLocked(long delayBeforeFirstBackup) { long when = System.currentTimeMillis() + delayBeforeFirstBackup; mAlarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, when, BACKUP_INTERVAL, mRunBackupIntent); } // Report whether the backup mechanism is currently enabled // Report whether the backup mechanism is currently enabled public boolean isBackupEnabled() { public boolean isBackupEnabled() { mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "isBackupEnabled"); mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "isBackupEnabled"); Loading Loading @@ -1506,7 +1542,8 @@ class BackupManagerService extends IBackupManager.Stub { synchronized (mQueueLock) { synchronized (mQueueLock) { long oldId = Binder.clearCallingIdentity(); long oldId = Binder.clearCallingIdentity(); pw.println("Backup Manager is " + (mEnabled ? "enabled" : "disabled")); pw.println("Backup Manager is " + (mEnabled ? "enabled" : "disabled") + " / " + (!mProvisioned ? "not " : "") + "provisioned"); pw.println("Available transports:"); pw.println("Available transports:"); for (String t : listAllTransports()) { for (String t : listAllTransports()) { String pad = (t.equals(mCurrentTransport)) ? " * " : " "; String pad = (t.equals(mCurrentTransport)) ? " * " : " "; Loading