Skip to content

Commit 27cb3f8

Browse files
Christopher TateAndroid (Google) Code Review
authored andcommitted
Merge "Eliminate "backup enabled but not provisioned" failure modes" into jb-dev
2 parents dc9445b + 97ea122 commit 27cb3f8

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

services/java/com/android/server/BackupManagerService.java

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import android.content.pm.PackageManager;
4949
import android.content.pm.Signature;
5050
import android.content.pm.PackageManager.NameNotFoundException;
51+
import android.database.ContentObserver;
5152
import android.net.Uri;
5253
import android.os.Binder;
5354
import android.os.Build;
@@ -252,6 +253,34 @@ public String toString() {
252253
IBackupTransport mLocalTransport, mGoogleTransport;
253254
ActiveRestoreSession mActiveRestoreSession;
254255

256+
// Watch the device provisioning operation during setup
257+
ContentObserver mProvisionedObserver;
258+
259+
class ProvisionedObserver extends ContentObserver {
260+
public ProvisionedObserver(Handler handler) {
261+
super(handler);
262+
}
263+
264+
public void onChange(boolean selfChange) {
265+
final boolean wasProvisioned = mProvisioned;
266+
final boolean isProvisioned = deviceIsProvisioned();
267+
// latch: never unprovision
268+
mProvisioned = wasProvisioned || isProvisioned;
269+
if (MORE_DEBUG) {
270+
Slog.d(TAG, "Provisioning change: was=" + wasProvisioned
271+
+ " is=" + isProvisioned + " now=" + mProvisioned);
272+
}
273+
274+
synchronized (mQueueLock) {
275+
if (mProvisioned && !wasProvisioned && mEnabled) {
276+
// we're now good to go, so start the backup alarms
277+
if (MORE_DEBUG) Slog.d(TAG, "Now provisioned, so starting backups");
278+
startBackupAlarmsLocked(FIRST_BACKUP_INTERVAL);
279+
}
280+
}
281+
}
282+
}
283+
255284
class RestoreGetSetsParams {
256285
public IBackupTransport transport;
257286
public ActiveRestoreSession session;
@@ -695,12 +724,19 @@ public BackupManagerService(Context context) {
695724
mBackupHandler = new BackupHandler(mHandlerThread.getLooper());
696725

697726
// Set up our bookkeeping
698-
boolean areEnabled = Settings.Secure.getInt(context.getContentResolver(),
727+
final ContentResolver resolver = context.getContentResolver();
728+
boolean areEnabled = Settings.Secure.getInt(resolver,
699729
Settings.Secure.BACKUP_ENABLED, 0) != 0;
700-
mProvisioned = Settings.Secure.getInt(context.getContentResolver(),
701-
Settings.Secure.BACKUP_PROVISIONED, 0) != 0;
702-
mAutoRestore = Settings.Secure.getInt(context.getContentResolver(),
730+
mProvisioned = Settings.Secure.getInt(resolver,
731+
Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
732+
mAutoRestore = Settings.Secure.getInt(resolver,
703733
Settings.Secure.BACKUP_AUTO_RESTORE, 1) != 0;
734+
735+
mProvisionedObserver = new ProvisionedObserver(mBackupHandler);
736+
resolver.registerContentObserver(
737+
Settings.Secure.getUriFor(Settings.Secure.DEVICE_PROVISIONED),
738+
false, mProvisionedObserver);
739+
704740
// If Encrypted file systems is enabled or disabled, this call will return the
705741
// correct directory.
706742
mBaseStateDir = new File(Environment.getSecureDataDirectory(), "backup");
@@ -5172,24 +5208,9 @@ public void setAutoRestore(boolean doAutoRestore) {
51725208
public void setBackupProvisioned(boolean available) {
51735209
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
51745210
"setBackupProvisioned");
5175-
5176-
boolean wasProvisioned = mProvisioned;
5177-
synchronized (this) {
5178-
Settings.Secure.putInt(mContext.getContentResolver(),
5179-
Settings.Secure.BACKUP_PROVISIONED, available ? 1 : 0);
5180-
mProvisioned = available;
5181-
}
5182-
5183-
synchronized (mQueueLock) {
5184-
if (available && !wasProvisioned && mEnabled) {
5185-
// we're now good to go, so start the backup alarms
5186-
startBackupAlarmsLocked(FIRST_BACKUP_INTERVAL);
5187-
} else if (!available) {
5188-
// No longer enabled, so stop running backups
5189-
Slog.w(TAG, "Backup service no longer provisioned");
5190-
mAlarmManager.cancel(mRunBackupIntent);
5191-
}
5192-
}
5211+
/*
5212+
* This is now a no-op; provisioning is simply the device's own setup state.
5213+
*/
51935214
}
51945215

51955216
private void startBackupAlarmsLocked(long delayBeforeFirstBackup) {

0 commit comments

Comments
 (0)