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: Ifb981f7b60d0fd13c6b8d3bd5605311dcf0e006c
This commit is contained in:
@@ -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 {
|
||||||
|
if (!callerCanManageCompanionDevices()) {
|
||||||
checkCallerIsSystemOr(callingPackage, userId);
|
checkCallerIsSystemOr(callingPackage, userId);
|
||||||
checkUsesFeature(callingPackage, getCallingUserId());
|
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());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user