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

Commit 44e19a0a authored by Emilian Peev's avatar Emilian Peev
Browse files

CameraProxy: Clear calling identity before scheduling

Camera statistics job scheduling cannot be triggered by
native camera service UID. Clear the binder calling
identity before trying to schedule any jobs.
In addition to that check also the binder calling UID value
itself and make sure we are being called by camera service.

Bug: 77818243
Test: Camera CTS
Change-Id: I5d94671eaf0eb41b5d06abf10494b9e7dc172db5
parent 682ca412
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -165,12 +165,22 @@ public class CameraServiceProxy extends SystemService
    private final ICameraServiceProxy.Stub mCameraServiceProxy = new ICameraServiceProxy.Stub() {
        @Override
        public void pingForUserUpdate() {
            if (Binder.getCallingUid() != Process.CAMERASERVER_UID) {
                Slog.e(TAG, "Calling UID: " + Binder.getCallingUid() + " doesn't match expected " +
                        " camera service UID!");
                return;
            }
            notifySwitchWithRetries(30);
        }

        @Override
        public void notifyCameraState(String cameraId, int newCameraState, int facing,
                String clientName, int apiLevel) {
            if (Binder.getCallingUid() != Process.CAMERASERVER_UID) {
                Slog.e(TAG, "Calling UID: " + Binder.getCallingUid() + " doesn't match expected " +
                        " camera service UID!");
                return;
            }
            String state = cameraStateToString(newCameraState);
            String facingStr = cameraFacingToString(facing);
            if (DEBUG) Slog.v(TAG, "Camera " + cameraId + " facing " + facingStr + " state now " +
@@ -301,7 +311,12 @@ public class CameraServiceProxy extends SystemService
            }
            mCameraUsageHistory.clear();
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            CameraStatsJobService.schedule(mContext);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    private void switchUserLocked(int userHandle) {