[Multi-user] Make various backup settings be per-user
Use the "forUser" variation of getting/putting settings for the
following backup settings:
- backup_auto_restore
- backup_transport
- packages_to_clear_data_before_full_restore
Bug: 121305979
Test: 1) atest RunBackupFrameworksServicesRoboTests
2) Verify default auto restore is true;
Toggle auto restore in UI -> changes UserBMS state;
Change current transport via bmgr -> changes UserBMS state;
Check settings for user 0 different from user 10;
3) Run backup pass, restore pass
Change-Id: I69e2a4f9c870dd7b5661dfa17f891384825926f5
diff --git a/services/backup/java/com/android/server/backup/UserBackupManagerService.java b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
index 198a258..8d07879 100644
--- a/services/backup/java/com/android/server/backup/UserBackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
@@ -371,8 +371,8 @@
Trampoline trampoline,
Set<ComponentName> transportWhitelist) {
String currentTransport =
- Settings.Secure.getString(
- context.getContentResolver(), Settings.Secure.BACKUP_TRANSPORT);
+ Settings.Secure.getStringForUser(
+ context.getContentResolver(), Settings.Secure.BACKUP_TRANSPORT, userId);
if (TextUtils.isEmpty(currentTransport)) {
currentTransport = null;
}
@@ -434,6 +434,19 @@
transportManager);
}
+ /**
+ * Returns the value of {@link Settings.Secure#USER_SETUP_COMPLETE} for the specified user
+ * {@code userId} as a {@code boolean}.
+ */
+ public static boolean getSetupCompleteSettingForUser(Context context, int userId) {
+ return Settings.Secure.getIntForUser(
+ context.getContentResolver(),
+ Settings.Secure.USER_SETUP_COMPLETE,
+ 0,
+ userId)
+ != 0;
+ }
+
private UserBackupManagerService(
@UserIdInt int userId,
Context context,
@@ -465,12 +478,9 @@
// Set up our bookkeeping
final ContentResolver resolver = context.getContentResolver();
- mSetupComplete =
- Settings.Secure.getIntForUser(
- resolver, Settings.Secure.USER_SETUP_COMPLETE, 0, mUserId)
- != 0;
- mAutoRestore = Settings.Secure.getInt(resolver,
- Settings.Secure.BACKUP_AUTO_RESTORE, 1) != 0;
+ mSetupComplete = getSetupCompleteSettingForUser(context, userId);
+ mAutoRestore = Settings.Secure.getIntForUser(resolver,
+ Settings.Secure.BACKUP_AUTO_RESTORE, 1, userId) != 0;
ContentObserver setupObserver = new SetupObserver(this, mBackupHandler);
resolver.registerContentObserver(
@@ -2807,8 +2817,8 @@
final long oldId = Binder.clearCallingIdentity();
try {
synchronized (this) {
- Settings.Secure.putInt(mContext.getContentResolver(),
- Settings.Secure.BACKUP_AUTO_RESTORE, doAutoRestore ? 1 : 0);
+ Settings.Secure.putIntForUser(mContext.getContentResolver(),
+ Settings.Secure.BACKUP_AUTO_RESTORE, doAutoRestore ? 1 : 0, mUserId);
mAutoRestore = doAutoRestore;
}
} finally {
@@ -3021,8 +3031,8 @@
private void updateStateForTransport(String newTransportName) {
// Publish the name change
- Settings.Secure.putString(mContext.getContentResolver(),
- Settings.Secure.BACKUP_TRANSPORT, newTransportName);
+ Settings.Secure.putStringForUser(mContext.getContentResolver(),
+ Settings.Secure.BACKUP_TRANSPORT, newTransportName, mUserId);
// And update our current-dataset bookkeeping
String callerLogString = "BMS.updateStateForTransport()";
diff --git a/services/backup/java/com/android/server/backup/internal/SetupObserver.java b/services/backup/java/com/android/server/backup/internal/SetupObserver.java
index 41eb966..defcacc 100644
--- a/services/backup/java/com/android/server/backup/internal/SetupObserver.java
+++ b/services/backup/java/com/android/server/backup/internal/SetupObserver.java
@@ -18,6 +18,7 @@
import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
import static com.android.server.backup.BackupManagerService.TAG;
+import static com.android.server.backup.UserBackupManagerService.getSetupCompleteSettingForUser;
import android.content.Context;
import android.database.ContentObserver;
@@ -53,13 +54,7 @@
*/
public void onChange(boolean selfChange) {
boolean previousSetupComplete = mUserBackupManagerService.isSetupComplete();
- boolean newSetupComplete =
- Settings.Secure.getIntForUser(
- mContext.getContentResolver(),
- Settings.Secure.USER_SETUP_COMPLETE,
- 0,
- mUserId)
- != 0;
+ boolean newSetupComplete = getSetupCompleteSettingForUser(mContext, mUserId);
boolean resolvedSetupComplete = previousSetupComplete || newSetupComplete;
mUserBackupManagerService.setSetupComplete(resolvedSetupComplete);
diff --git a/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java b/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
index 0d26ea5..45a398f 100644
--- a/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
+++ b/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
@@ -678,12 +678,13 @@
* Returns whether the package is in the list of the packages for which clear app data should
* be called despite the fact that they have backup agent.
*
- * <p>The list is read from {@link Settings.Secure.PACKAGES_TO_CLEAR_DATA_BEFORE_FULL_RESTORE}.
+ * <p>The list is read from {@link Settings.Secure#PACKAGES_TO_CLEAR_DATA_BEFORE_FULL_RESTORE}.
*/
private boolean shouldForceClearAppDataOnFullRestore(String packageName) {
- String packageListString = Settings.Secure.getString(
+ String packageListString = Settings.Secure.getStringForUser(
mBackupManagerService.getContext().getContentResolver(),
- Settings.Secure.PACKAGES_TO_CLEAR_DATA_BEFORE_FULL_RESTORE);
+ Settings.Secure.PACKAGES_TO_CLEAR_DATA_BEFORE_FULL_RESTORE,
+ mBackupManagerService.getUserId());
if (TextUtils.isEmpty(packageListString)) {
return false;
}