Merge changes from topic "bug158482162_rvc-qpr-dev" into rvc-qpr-dev

* changes:
  Fix DevicePolicyManager.isBackupServiceEnabled() breakage.
  BackupManagerService: Make new behavior conditional on ChangeId.
  Enforce BACKUP permission on Service end.
This commit is contained in:
Tobias Thierer
2021-03-17 12:09:13 +00:00
committed by Android (Google) Code Review
3 changed files with 37 additions and 10 deletions

View File

@@ -21,10 +21,14 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -391,6 +395,17 @@ public class BackupManager {
return false;
}
/**
* If this change is enabled, the {@code BACKUP} permission needed for
* {@code isBackupServiceActive()} will be enforced on the service end
* rather than client-side in {@link BackupManager}.
* @hide
*/
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
public static final long IS_BACKUP_SERVICE_ACTIVE_ENFORCE_PERMISSION_IN_SERVICE = 158482162;
/**
* Report whether the backup mechanism is currently active.
* When it is inactive, the device will not perform any backup operations, nor will it
@@ -401,8 +416,11 @@ public class BackupManager {
@SystemApi
@RequiresPermission(android.Manifest.permission.BACKUP)
public boolean isBackupServiceActive(UserHandle user) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
"isBackupServiceActive");
if (!CompatChanges.isChangeEnabled(
IS_BACKUP_SERVICE_ACTIVE_ENFORCE_PERMISSION_IN_SERVICE)) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
"isBackupServiceActive");
}
checkServiceBinder();
if (sService != null) {
try {

View File

@@ -30,6 +30,7 @@ import android.app.backup.IBackupObserver;
import android.app.backup.IFullBackupRestoreObserver;
import android.app.backup.IRestoreSession;
import android.app.backup.ISelectBackupTransportCallback;
import android.app.compat.CompatChanges;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
@@ -506,6 +507,12 @@ public class BackupManagerService extends IBackupManager.Stub {
*/
@Override
public boolean isBackupServiceActive(int userId) {
int callingUid = Binder.getCallingUid();
if (CompatChanges.isChangeEnabled(
BackupManager.IS_BACKUP_SERVICE_ACTIVE_ENFORCE_PERMISSION_IN_SERVICE, callingUid)) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
"isBackupServiceActive");
}
synchronized (mStateLock) {
return !mGlobalDisable && isBackupActivatedForUser(userId);
}

View File

@@ -14481,15 +14481,17 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
enforceProfileOrDeviceOwner(admin);
synchronized (getLockObject()) {
try {
IBackupManager ibm = mInjector.getIBackupManager();
return ibm != null && ibm.isBackupServiceActive(
mInjector.userHandleGetCallingUserId());
} catch (RemoteException e) {
throw new IllegalStateException("Failed requesting backup service state.", e);
final int userId = mInjector.userHandleGetCallingUserId();
return mInjector.binderWithCleanCallingIdentity(() -> {
synchronized (getLockObject()) {
try {
IBackupManager ibm = mInjector.getIBackupManager();
return ibm != null && ibm.isBackupServiceActive(userId);
} catch (RemoteException e) {
throw new IllegalStateException("Failed requesting backup service state.", e);
}
}
}
});
}
@Override