Enforce BACKUP permission on Service end.

BackupManager runs in the client process, whereas BackupManagerService
runs in the system server process. Therefore, apps permissions need should
be enforced on the service side.

Bug: 158482162
Test: Manually checked that a sample app  encounters SecurityException
      after but not before this CL, when running code similar to the
      sample in http://b/158482162#comment1 to figure out whether
      isBackupServiceActive() for its own uid.
Change-Id: I59693819542a80a065a9c88373393b0ba0dbef65
This commit is contained in:
Tobias Thierer
2020-10-19 19:37:30 +01:00
parent 3a20a22ea6
commit b2ab2c414f
2 changed files with 2 additions and 2 deletions

View File

@@ -445,8 +445,6 @@ public class BackupManager {
@SystemApi
@RequiresPermission(android.Manifest.permission.BACKUP)
public boolean isBackupServiceActive(UserHandle user) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
"isBackupServiceActive");
checkServiceBinder();
if (sService != null) {
try {

View File

@@ -509,6 +509,8 @@ public class BackupManagerService extends IBackupManager.Stub {
*/
@Override
public boolean isBackupServiceActive(int userId) {
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP,
"isBackupServiceActive");
synchronized (mStateLock) {
return !mGlobalDisable && isBackupActivatedForUser(userId);
}