[CDM] Perm Sync toggle fixes
Bug: 290063372
Fix: 300388336
Test: m
Change-Id: Ia1dd9c913f2fa5bc64c9806b515e93265371814e
diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java
index 330e35b..ba45339 100644
--- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java
+++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java
@@ -887,6 +887,11 @@
@Override
public PermissionSyncRequest getPermissionSyncRequest(int associationId) {
+ // TODO: temporary fix, will remove soon
+ AssociationInfo association = mAssociationStore.getAssociationById(associationId);
+ if (association == null) {
+ return null;
+ }
getAssociationWithCallerChecks(associationId);
return mSystemDataTransferProcessor.getPermissionSyncRequest(associationId);
}
diff --git a/services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferProcessor.java b/services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferProcessor.java
index 42b5a8b..e5c847a 100644
--- a/services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferProcessor.java
+++ b/services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferProcessor.java
@@ -139,7 +139,7 @@
@UserIdInt int userId, int associationId) {
if (PackageUtils.isPackageAllowlisted(mContext, mPackageManager, packageName)) {
Slog.i(LOG_TAG, "User consent Intent should be skipped. Returning null.");
- // Auto enable perm sync for the whitelisted packages, but don't override user decision
+ // Auto enable perm sync for the allowlisted packages, but don't override user decision
PermissionSyncRequest request = getPermissionSyncRequest(associationId);
if (request == null) {
PermissionSyncRequest newRequest = new PermissionSyncRequest(associationId);
@@ -224,20 +224,30 @@
* Enable perm sync for the association
*/
public void enablePermissionsSync(int associationId) {
- int userId = mAssociationStore.getAssociationById(associationId).getUserId();
- PermissionSyncRequest request = new PermissionSyncRequest(associationId);
- request.setUserConsented(true);
- mSystemDataTransferRequestStore.writeRequest(userId, request);
+ final long callingIdentityToken = Binder.clearCallingIdentity();
+ try {
+ int userId = mAssociationStore.getAssociationById(associationId).getUserId();
+ PermissionSyncRequest request = new PermissionSyncRequest(associationId);
+ request.setUserConsented(true);
+ mSystemDataTransferRequestStore.writeRequest(userId, request);
+ } finally {
+ Binder.restoreCallingIdentity(callingIdentityToken);
+ }
}
/**
* Disable perm sync for the association
*/
public void disablePermissionsSync(int associationId) {
- int userId = mAssociationStore.getAssociationById(associationId).getUserId();
- PermissionSyncRequest request = new PermissionSyncRequest(associationId);
- request.setUserConsented(false);
- mSystemDataTransferRequestStore.writeRequest(userId, request);
+ final long callingIdentityToken = Binder.clearCallingIdentity();
+ try {
+ int userId = mAssociationStore.getAssociationById(associationId).getUserId();
+ PermissionSyncRequest request = new PermissionSyncRequest(associationId);
+ request.setUserConsented(false);
+ mSystemDataTransferRequestStore.writeRequest(userId, request);
+ } finally {
+ Binder.restoreCallingIdentity(callingIdentityToken);
+ }
}
/**
@@ -245,23 +255,34 @@
*/
@Nullable
public PermissionSyncRequest getPermissionSyncRequest(int associationId) {
- int userId = mAssociationStore.getAssociationById(associationId).getUserId();
- List<SystemDataTransferRequest> requests =
- mSystemDataTransferRequestStore.readRequestsByAssociationId(userId, associationId);
- for (SystemDataTransferRequest request : requests) {
- if (request instanceof PermissionSyncRequest) {
- return (PermissionSyncRequest) request;
+ final long callingIdentityToken = Binder.clearCallingIdentity();
+ try {
+ int userId = mAssociationStore.getAssociationById(associationId).getUserId();
+ List<SystemDataTransferRequest> requests =
+ mSystemDataTransferRequestStore.readRequestsByAssociationId(userId,
+ associationId);
+ for (SystemDataTransferRequest request : requests) {
+ if (request instanceof PermissionSyncRequest) {
+ return (PermissionSyncRequest) request;
+ }
}
+ return null;
+ } finally {
+ Binder.restoreCallingIdentity(callingIdentityToken);
}
- return null;
}
/**
* Remove perm sync request for the association.
*/
public void removePermissionSyncRequest(int associationId) {
- int userId = mAssociationStore.getAssociationById(associationId).getUserId();
- mSystemDataTransferRequestStore.removeRequestsByAssociationId(userId, associationId);
+ final long callingIdentityToken = Binder.clearCallingIdentity();
+ try {
+ int userId = mAssociationStore.getAssociationById(associationId).getUserId();
+ mSystemDataTransferRequestStore.removeRequestsByAssociationId(userId, associationId);
+ } finally {
+ Binder.restoreCallingIdentity(callingIdentityToken);
+ }
}
private void onReceivePermissionRestore(byte[] message) {