Skip to content

Commit b851f15

Browse files
Christopher TateAndroid (Google) Code Review
authored andcommitted
Merge "Don't do full backup/restore before setup"
2 parents 569584b + d2c0cd4 commit b851f15

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.content.ActivityNotFoundException;
3535
import android.content.BroadcastReceiver;
3636
import android.content.ComponentName;
37+
import android.content.ContentResolver;
3738
import android.content.Context;
3839
import android.content.Intent;
3940
import android.content.IntentFilter;
@@ -4765,6 +4766,11 @@ public void backupNow() {
47654766
}
47664767
}
47674768

4769+
boolean deviceIsProvisioned() {
4770+
final ContentResolver resolver = mContext.getContentResolver();
4771+
return (Settings.Secure.getInt(resolver, Settings.Secure.DEVICE_PROVISIONED, 0) != 0);
4772+
}
4773+
47684774
// Run a *full* backup pass for the given package, writing the resulting data stream
47694775
// to the supplied file descriptor. This method is synchronous and does not return
47704776
// to the caller until the backup has been completed.
@@ -4785,12 +4791,19 @@ public void fullBackup(ParcelFileDescriptor fd, boolean includeApks, boolean inc
47854791
}
47864792
}
47874793

4788-
if (DEBUG) Slog.v(TAG, "Requesting full backup: apks=" + includeApks
4789-
+ " shared=" + includeShared + " all=" + doAllApps
4790-
+ " pkgs=" + pkgList);
4791-
47924794
long oldId = Binder.clearCallingIdentity();
47934795
try {
4796+
// Doesn't make sense to do a full backup prior to setup
4797+
if (!deviceIsProvisioned()) {
4798+
Slog.i(TAG, "Full backup not supported before setup");
4799+
return;
4800+
}
4801+
4802+
if (DEBUG) Slog.v(TAG, "Requesting full backup: apks=" + includeApks
4803+
+ " shared=" + includeShared + " all=" + doAllApps
4804+
+ " pkgs=" + pkgList);
4805+
Slog.i(TAG, "Beginning full backup...");
4806+
47944807
FullBackupParams params = new FullBackupParams(fd, includeApks, includeShared,
47954808
doAllApps, pkgList);
47964809
final int token = generateToken();
@@ -4822,17 +4835,25 @@ public void fullBackup(ParcelFileDescriptor fd, boolean includeApks, boolean inc
48224835
// just eat it
48234836
}
48244837
Binder.restoreCallingIdentity(oldId);
4838+
Slog.d(TAG, "Full backup processing complete.");
48254839
}
4826-
if (MORE_DEBUG) Slog.d(TAG, "Full backup done; returning to caller");
48274840
}
48284841

48294842
public void fullRestore(ParcelFileDescriptor fd) {
48304843
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullRestore");
4831-
Slog.i(TAG, "Beginning full restore...");
48324844

48334845
long oldId = Binder.clearCallingIdentity();
48344846

48354847
try {
4848+
// Check whether the device has been provisioned -- we don't handle
4849+
// full restores prior to completing the setup process.
4850+
if (!deviceIsProvisioned()) {
4851+
Slog.i(TAG, "Full restore not permitted before setup");
4852+
return;
4853+
}
4854+
4855+
Slog.i(TAG, "Beginning full restore...");
4856+
48364857
FullRestoreParams params = new FullRestoreParams(fd);
48374858
final int token = generateToken();
48384859
synchronized (mFullConfirmations) {
@@ -4863,7 +4884,7 @@ public void fullRestore(ParcelFileDescriptor fd) {
48634884
Slog.w(TAG, "Error trying to close fd after full restore: " + e);
48644885
}
48654886
Binder.restoreCallingIdentity(oldId);
4866-
Slog.i(TAG, "Full restore completed");
4887+
Slog.i(TAG, "Full restore processing complete.");
48674888
}
48684889
}
48694890

0 commit comments

Comments
 (0)