Merge "Enfore caller permission check before reading whether a user is ready for backup."
This commit is contained in:
committed by
Android (Google) Code Review
commit
431faf4e31
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user