Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f6cf40d authored by Zach Johnson's avatar Zach Johnson Committed by Automerger Merge Worker
Browse files

Merge "CDM: allow system apps with MANAGE_COMPANION_DEVICES to call...

Merge "CDM: allow system apps with MANAGE_COMPANION_DEVICES to call getAssociations" into rvc-dev am: aeba47ae am: 74d36d69 am: c2516653 am: 3d275c40

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

Change-Id: Ic1d778a23752ebe30674bc0e5eae36547a654a44
parents e2953a2a 3d275c40
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -335,8 +335,10 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
        @Override
        public List<String> getAssociations(String callingPackage, int userId)
                throws RemoteException {
            if (!callerCanManageCompanionDevices()) {
                checkCallerIsSystemOr(callingPackage, userId);
                checkUsesFeature(callingPackage, getCallingUserId());
            }
            return new ArrayList<>(CollectionUtils.map(
                    readAllAssociations(userId, callingPackage),
                    a -> a.deviceAddress));
@@ -352,6 +354,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());
        }