Merge "CDM: allow system apps with MANAGE_COMPANION_DEVICES to call getAssociations" into rvc-dev am: aeba47ae73

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11953546

Change-Id: I696517ec6099d5e45463a1d0095e9edff212928e
This commit is contained in:
Zach Johnson
2020-06-23 17:52:12 +00:00
committed by Automerger Merge Worker

View File

@@ -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());
}