Skip to content

Commit aac71ff

Browse files
author
Christopher Tate
committed
Don't back up / restore non-primary users' data
For now only the device owner "user" gets cloud backups. Also, only the device owner account has access to local backup/restore. Bug 6956438 Change-Id: I87d7ba5969e606c23f4214469f9bf2fd47a6c61b
1 parent 38cc2a5 commit aac71ff

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

core/java/android/os/UserId.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public final class UserId {
3333
/** A user id to indicate the currently active user */
3434
public static final int USER_CURRENT = -2;
3535

36+
/** A user id constant to indicate the "owner" user of the device */
37+
public static final int USER_OWNER = 0;
3638

3739
/**
3840
* Enable multi-user related side effects. Set this to false if there are problems with single

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import android.os.RemoteException;
6666
import android.os.ServiceManager;
6767
import android.os.SystemClock;
68+
import android.os.UserId;
6869
import android.os.WorkSource;
6970
import android.os.storage.IMountService;
7071
import android.provider.Settings;
@@ -4845,6 +4846,18 @@ private void writeToJournalLocked(String str) {
48454846
// ----- IBackupManager binder interface -----
48464847

48474848
public void dataChanged(final String packageName) {
4849+
final int callingUserHandle = UserId.getCallingUserId();
4850+
if (callingUserHandle != UserId.USER_OWNER) {
4851+
// App is running under a non-owner user profile. For now, we do not back
4852+
// up data from secondary user profiles.
4853+
// TODO: backups for all user profiles.
4854+
if (MORE_DEBUG) {
4855+
Slog.v(TAG, "dataChanged(" + packageName + ") ignored because it's user "
4856+
+ callingUserHandle);
4857+
}
4858+
return;
4859+
}
4860+
48484861
final HashSet<String> targets = dataChangedTargets(packageName);
48494862
if (targets == null) {
48504863
Slog.w(TAG, "dataChanged but no participant pkg='" + packageName + "'"
@@ -4937,6 +4950,11 @@ public void fullBackup(ParcelFileDescriptor fd, boolean includeApks, boolean inc
49374950
boolean doAllApps, boolean includeSystem, String[] pkgList) {
49384951
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullBackup");
49394952

4953+
final int callingUserHandle = UserId.getCallingUserId();
4954+
if (callingUserHandle != UserId.USER_OWNER) {
4955+
throw new IllegalStateException("Backup supported only for the device owner");
4956+
}
4957+
49404958
// Validate
49414959
if (!doAllApps) {
49424960
if (!includeShared) {
@@ -5001,6 +5019,11 @@ public void fullBackup(ParcelFileDescriptor fd, boolean includeApks, boolean inc
50015019
public void fullRestore(ParcelFileDescriptor fd) {
50025020
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullRestore");
50035021

5022+
final int callingUserHandle = UserId.getCallingUserId();
5023+
if (callingUserHandle != UserId.USER_OWNER) {
5024+
throw new IllegalStateException("Restore supported only for the device owner");
5025+
}
5026+
50045027
long oldId = Binder.clearCallingIdentity();
50055028

50065029
try {

0 commit comments

Comments
 (0)