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

Commit d2fb6ce7 authored by Austin Borger's avatar Austin Borger
Browse files

CameraService: Check if the camera is disabled via device policy by user.

The current approach to checking the camera device policy is multi-user
agnostic. This patch takes the user into account.

Modifications to the DevicePolicyManager are required for this to work.
The camera service user needs to be able to make cross-user queries, so
a check for its uid was added specifically for getCameraDisabled.

Test: Tested GCA with device policy set via TestDPC
Bug: 230026863
Change-Id: I922def3310f39b41dade06d656569222f4db46d7
parent 6f0d41b5
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -582,13 +582,18 @@ public class CameraServiceProxy extends SystemService
        }

        @Override
        public boolean isCameraDisabled() {
        public boolean isCameraDisabled(int userId) {
            DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
            if (dpm == null) {
                Slog.e(TAG, "Failed to get the device policy manager service");
                return false;
            }
            return dpm.getCameraDisabled(null);
            try {
                return dpm.getCameraDisabled(null, userId);
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
    };

+6 −1
Original line number Diff line number Diff line
@@ -8166,7 +8166,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
        final CallerIdentity caller = getCallerIdentity(who);
        Preconditions.checkCallAuthorization(hasFullCrossUsersPermission(caller, userHandle));
        Preconditions.checkCallAuthorization(hasFullCrossUsersPermission(caller, userHandle)
                || isCameraServerUid(caller));
        if (parent) {
            Preconditions.checkCallAuthorization(
@@ -9677,6 +9678,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        return UserHandle.isSameApp(caller.getUid(), Process.SHELL_UID);
    }
    private boolean isCameraServerUid(CallerIdentity caller) {
        return UserHandle.isSameApp(caller.getUid(), Process.CAMERASERVER_UID);
    }
    private @UserIdInt int getCurrentForegroundUserId() {
        try {
            UserInfo currentUser = mInjector.getIActivityManager().getCurrentUser();