|
48 | 48 | import android.content.pm.PackageManager; |
49 | 49 | import android.content.pm.Signature; |
50 | 50 | import android.content.pm.PackageManager.NameNotFoundException; |
| 51 | +import android.database.ContentObserver; |
51 | 52 | import android.net.Uri; |
52 | 53 | import android.os.Binder; |
53 | 54 | import android.os.Build; |
@@ -252,6 +253,34 @@ public String toString() { |
252 | 253 | IBackupTransport mLocalTransport, mGoogleTransport; |
253 | 254 | ActiveRestoreSession mActiveRestoreSession; |
254 | 255 |
|
| 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 | + |
255 | 284 | class RestoreGetSetsParams { |
256 | 285 | public IBackupTransport transport; |
257 | 286 | public ActiveRestoreSession session; |
@@ -695,12 +724,19 @@ public BackupManagerService(Context context) { |
695 | 724 | mBackupHandler = new BackupHandler(mHandlerThread.getLooper()); |
696 | 725 |
|
697 | 726 | // 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, |
699 | 729 | 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, |
703 | 733 | 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 | + |
704 | 740 | // If Encrypted file systems is enabled or disabled, this call will return the |
705 | 741 | // correct directory. |
706 | 742 | mBaseStateDir = new File(Environment.getSecureDataDirectory(), "backup"); |
@@ -5172,24 +5208,9 @@ public void setAutoRestore(boolean doAutoRestore) { |
5172 | 5208 | public void setBackupProvisioned(boolean available) { |
5173 | 5209 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, |
5174 | 5210 | "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 | + */ |
5193 | 5214 | } |
5194 | 5215 |
|
5195 | 5216 | private void startBackupAlarmsLocked(long delayBeforeFirstBackup) { |
|
0 commit comments