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

This commit is contained in:
Zach Johnson
2020-06-23 17:50:22 +00:00
committed by Android (Google) Code Review

View File

@@ -336,8 +336,10 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
@Override @Override
public List<String> getAssociations(String callingPackage, int userId) public List<String> getAssociations(String callingPackage, int userId)
throws RemoteException { throws RemoteException {
checkCallerIsSystemOr(callingPackage, userId); if (!callerCanManageCompanionDevices()) {
checkUsesFeature(callingPackage, getCallingUserId()); checkCallerIsSystemOr(callingPackage, userId);
checkUsesFeature(callingPackage, getCallingUserId());
}
return new ArrayList<>(CollectionUtils.map( return new ArrayList<>(CollectionUtils.map(
readAllAssociations(userId, callingPackage), readAllAssociations(userId, callingPackage),
a -> a.deviceAddress)); a -> a.deviceAddress));
@@ -353,6 +355,12 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
removeAssociation(getCallingUserId(), callingPackage, deviceMacAddress); 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 { private void checkCallerIsSystemOr(String pkg) throws RemoteException {
checkCallerIsSystemOr(pkg, getCallingUserId()); checkCallerIsSystemOr(pkg, getCallingUserId());
} }