diff options
author | Zach Johnson <zachoverflow@google.com> | 2020-06-22 09:31:00 -0700 |
---|---|---|
committer | Zach Johnson <zachoverflow@google.com> | 2020-06-22 19:37:22 +0000 |
commit | d4a628e17b12a7db8635c3bb3f2e25c55bffa890 (patch) | |
tree | 74633a90d470c9ee1b8dbf003ca23daecfe8800d | |
parent | 2bcb70322c88289fa54616e7176ae73da24dd83c (diff) |
CDM: allow system apps with MANAGE_COMPANION_DEVICES to call
getAssociations
Bluetooth needs to find out what devices are
associated for a particular app.
Bug: 157051467
Test: patch for 157051467 did not work before, works after
Change-Id: I8157afd2ccc69aeb87c2eb52cd043ec004cdd9c1
-rw-r--r-- | services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index 6859c5835c80..d6759b3e2cca 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -336,8 +336,10 @@ public class CompanionDeviceManagerService extends SystemService implements Bind @Override public List<String> getAssociations(String callingPackage, int userId) throws RemoteException { - checkCallerIsSystemOr(callingPackage, userId); - checkUsesFeature(callingPackage, getCallingUserId()); + if (!callerCanManageCompanionDevices()) { + checkCallerIsSystemOr(callingPackage, userId); + checkUsesFeature(callingPackage, getCallingUserId()); + } return new ArrayList<>(CollectionUtils.map( readAllAssociations(userId, callingPackage), a -> a.deviceAddress)); @@ -353,6 +355,12 @@ public class CompanionDeviceManagerService extends SystemService implements Bind removeAssociation(getCallingUserId(), callingPackage, deviceMacAddress); } + private boolean callerCanManageCompanionDevices() { + return getContext().checkCallingOrSelfPermission( + android.Manifest.permission.MANAGE_COMPANION_DEVICES) + == PackageManager.PERMISSION_GRANTED; + } + private void checkCallerIsSystemOr(String pkg) throws RemoteException { checkCallerIsSystemOr(pkg, getCallingUserId()); } |