Loading services/backup/java/com/android/server/backup/BackupManagerService.java +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.app.backup.BackupManager; import android.app.backup.BackupManager.OperationType; import android.app.backup.IBackupManager; import android.app.backup.IBackupManagerMonitor; import android.app.backup.IBackupObserver; Loading Loading @@ -284,6 +283,7 @@ public class BackupManagerService extends IBackupManager.Stub { */ @Override public boolean isUserReadyForBackup(int userId) { enforceCallingPermissionOnUserId(userId, "isUserReadyForBackup()"); return mUserServices.get(UserHandle.USER_SYSTEM) != null && mUserServices.get(userId) != null; } Loading services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -301,6 +301,35 @@ public class BackupManagerServiceRoboTest { verify(mUserOneService, never()).initializeTransports(transports, /* observer */ null); } /** * Test that the backup services throws a {@link SecurityException} if the caller does not have * INTERACT_ACROSS_USERS_FULL permission and passes a different user id. */ @Test public void testIsUserReadyForBackup_withoutPermission_throwsSecurityException() { BackupManagerService backupManagerService = createService(); registerUser(backupManagerService, mUserOneId, mUserOneService); setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); expectThrows( SecurityException.class, () -> backupManagerService.isUserReadyForBackup(mUserOneId)); } /** * Test that the backup service does not throw a {@link SecurityException} if the caller has * INTERACT_ACROSS_USERS_FULL permission and passes a different user id. */ @Test public void testIsUserReadyForBackup_withPermission_callsMethodForUser() { BackupManagerService backupManagerService = createService(); registerUser(backupManagerService, UserHandle.USER_SYSTEM, mUserSystemService); registerUser(backupManagerService, mUserOneId, mUserOneService); setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ true); assertThat(backupManagerService.isUserReadyForBackup(mUserOneId)).isTrue(); } /** Test that the backup service routes methods correctly to the user that requests it. */ @Test public void testClearBackupData_onRegisteredUser_callsMethodForUser() throws Exception { Loading Loading
services/backup/java/com/android/server/backup/BackupManagerService.java +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.app.backup.BackupManager; import android.app.backup.BackupManager.OperationType; import android.app.backup.IBackupManager; import android.app.backup.IBackupManagerMonitor; import android.app.backup.IBackupObserver; Loading Loading @@ -284,6 +283,7 @@ public class BackupManagerService extends IBackupManager.Stub { */ @Override public boolean isUserReadyForBackup(int userId) { enforceCallingPermissionOnUserId(userId, "isUserReadyForBackup()"); return mUserServices.get(UserHandle.USER_SYSTEM) != null && mUserServices.get(userId) != null; } Loading
services/robotests/backup/src/com/android/server/backup/BackupManagerServiceRoboTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -301,6 +301,35 @@ public class BackupManagerServiceRoboTest { verify(mUserOneService, never()).initializeTransports(transports, /* observer */ null); } /** * Test that the backup services throws a {@link SecurityException} if the caller does not have * INTERACT_ACROSS_USERS_FULL permission and passes a different user id. */ @Test public void testIsUserReadyForBackup_withoutPermission_throwsSecurityException() { BackupManagerService backupManagerService = createService(); registerUser(backupManagerService, mUserOneId, mUserOneService); setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ false); expectThrows( SecurityException.class, () -> backupManagerService.isUserReadyForBackup(mUserOneId)); } /** * Test that the backup service does not throw a {@link SecurityException} if the caller has * INTERACT_ACROSS_USERS_FULL permission and passes a different user id. */ @Test public void testIsUserReadyForBackup_withPermission_callsMethodForUser() { BackupManagerService backupManagerService = createService(); registerUser(backupManagerService, UserHandle.USER_SYSTEM, mUserSystemService); registerUser(backupManagerService, mUserOneId, mUserOneService); setCallerAndGrantInteractUserPermission(mUserTwoId, /* shouldGrantPermission */ true); assertThat(backupManagerService.isUserReadyForBackup(mUserOneId)).isTrue(); } /** Test that the backup service routes methods correctly to the user that requests it. */ @Test public void testClearBackupData_onRegisteredUser_callsMethodForUser() throws Exception { Loading