From d4a628e17b12a7db8635c3bb3f2e25c55bffa890 Mon Sep 17 00:00:00 2001 From: Zach Johnson Date: Mon, 22 Jun 2020 09:31:00 -0700 Subject: 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 --- .../server/companion/CompanionDeviceManagerService.java | 12 ++++++++++-- 1 file 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 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()); } -- cgit v1.2.3-59-g8ed1b