From aa5e64c79deef2b40a77ff4be59ea41befbfa616 Mon Sep 17 00:00:00 2001 From: Jeongik Cha Date: Sat, 17 Nov 2018 05:08:04 +0900 Subject: [PATCH] remove linking against aidl enum using transaction id directly is not recommended so remove permission check in onTransact() and add it into notifySystemEvent() Bug: 119525871 Test: m -j Change-Id: I0f2feb5204876fa9b56b9cdb096f25d2226025ec --- .../camera/libcameraservice/CameraService.cpp | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 4dacd0273e..2f50e3abe2 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -1579,6 +1579,23 @@ Status CameraService::setTorchMode(const String16& cameraId, bool enabled, Status CameraService::notifySystemEvent(int32_t eventId, const std::vector& args) { + const int pid = CameraThreadState::getCallingPid(); + const int selfPid = getpid(); + + // Permission checks + if (pid != selfPid) { + // Ensure we're being called by system_server, or similar process with + // permissions to notify the camera service about system events + if (!checkCallingPermission( + String16("android.permission.CAMERA_SEND_SYSTEM_EVENTS"))) { + const int uid = CameraThreadState::getCallingUid(); + ALOGE("Permission Denial: cannot send updates to camera service about system" + " events from pid=%d, uid=%d", pid, uid); + return STATUS_ERROR_FMT(ERROR_PERMISSION_DENIED, + "No permission to send updates to camera service about system events from pid=%d, uid=%d", pid, uid); + } + } + ATRACE_CALL(); switch(eventId) { @@ -1993,9 +2010,6 @@ void CameraService::logServiceError(const char* msg, int errorCode) { status_t CameraService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { - const int pid = CameraThreadState::getCallingPid(); - const int selfPid = getpid(); - // Permission checks switch (code) { case SHELL_COMMAND_TRANSACTION: { @@ -2022,20 +2036,6 @@ status_t CameraService::onTransact(uint32_t code, const Parcel& data, Parcel* re } return NO_ERROR; } - case BnCameraService::NOTIFYSYSTEMEVENT: { - if (pid != selfPid) { - // Ensure we're being called by system_server, or similar process with - // permissions to notify the camera service about system events - if (!checkCallingPermission( - String16("android.permission.CAMERA_SEND_SYSTEM_EVENTS"))) { - const int uid = CameraThreadState::getCallingUid(); - ALOGE("Permission Denial: cannot send updates to camera service about system" - " events from pid=%d, uid=%d", pid, uid); - return PERMISSION_DENIED; - } - } - break; - } } return BnCameraService::onTransact(code, data, reply, flags);