diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-03 21:04:15 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-03 21:04:15 +0000 |
commit | 6ab0fea9b07d52283a153dc4597453ff71c979ff (patch) | |
tree | c97f9c6115074291fa699476dbe9ff208363eca7 | |
parent | f9848dff4e5b04d64fa1f66dcf03ee311188bcbc (diff) | |
parent | 48132b70ae8a4d366a95d11cfe3549a5f6485698 (diff) |
Snap for 7256547 from 48132b70ae8a4d366a95d11cfe3549a5f6485698 to rvc-qpr3-release
Change-Id: I904032f9a134d7e0a5de141a32cb31b3b9c393b2
-rw-r--r-- | services/camera/libcameraservice/CameraService.cpp | 43 | ||||
-rw-r--r-- | services/camera/libcameraservice/CameraService.h | 6 |
2 files changed, 38 insertions, 11 deletions
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 24288d6baf..e2fcb5a97c 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -252,10 +252,16 @@ void CameraService::pingCameraServiceProxy() { proxyBinder->pingForUserUpdate(); } -void CameraService::broadcastTorchModeStatus(const String8& cameraId, TorchModeStatus status) { +void CameraService::broadcastTorchModeStatus(const String8& cameraId, TorchModeStatus status, + SystemCameraKind systemCameraKind) { Mutex::Autolock lock(mStatusListenerLock); - for (auto& i : mListenerList) { + if (shouldSkipStatusUpdates(systemCameraKind, i->isVendorListener(), i->getListenerPid(), + i->getListenerUid())) { + ALOGV("Skipping torch callback for system-only camera device %s", + cameraId.c_str()); + continue; + } i->getListener()->onTorchStatusChanged(mapToInterface(status), String16{cameraId}); } } @@ -341,7 +347,7 @@ void CameraService::addStates(const String8 id) { Mutex::Autolock al(mTorchStatusMutex); mTorchStatusMap.add(id, TorchModeStatus::AVAILABLE_OFF); - broadcastTorchModeStatus(id, TorchModeStatus::AVAILABLE_OFF); + broadcastTorchModeStatus(id, TorchModeStatus::AVAILABLE_OFF, deviceKind); } updateCameraNumAndIds(); @@ -502,12 +508,19 @@ void CameraService::disconnectClient(const String8& id, sp<BasicClient> clientTo void CameraService::onTorchStatusChanged(const String8& cameraId, TorchModeStatus newStatus) { + SystemCameraKind systemCameraKind = SystemCameraKind::PUBLIC; + status_t res = getSystemCameraKind(cameraId, &systemCameraKind); + if (res != OK) { + ALOGE("%s: Could not get system camera kind for camera id %s", __FUNCTION__, + cameraId.string()); + return; + } Mutex::Autolock al(mTorchStatusMutex); - onTorchStatusChangedLocked(cameraId, newStatus); + onTorchStatusChangedLocked(cameraId, newStatus, systemCameraKind); } void CameraService::onTorchStatusChangedLocked(const String8& cameraId, - TorchModeStatus newStatus) { + TorchModeStatus newStatus, SystemCameraKind systemCameraKind) { ALOGI("%s: Torch status changed for cameraId=%s, newStatus=%d", __FUNCTION__, cameraId.string(), newStatus); @@ -556,8 +569,7 @@ void CameraService::onTorchStatusChangedLocked(const String8& cameraId, } } } - - broadcastTorchModeStatus(cameraId, newStatus); + broadcastTorchModeStatus(cameraId, newStatus, systemCameraKind); } static bool hasPermissionsForSystemCamera(int callingPid, int callingUid) { @@ -1864,6 +1876,10 @@ Status CameraService::setTorchMode(const String16& cameraId, bool enabled, String8 id = String8(cameraId.string()); int uid = CameraThreadState::getCallingUid(); + if (shouldRejectSystemCameraConnection(id)) { + return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT, "Unable to set torch mode" + " for system only device %s: ", id.string()); + } // verify id is valid. auto state = getCameraState(id); if (state == nullptr) { @@ -2220,6 +2236,11 @@ Status CameraService::addListenerHelper(const sp<ICameraServiceListener>& listen return shouldSkipStatusUpdates(deviceKind, isVendorListener, clientPid, clientUid);}), cameraStatuses->end()); + //cameraStatuses will have non-eligible camera ids removed. + std::set<String16> idsChosenForCallback; + for (const auto &s : *cameraStatuses) { + idsChosenForCallback.insert(String16(s.cameraId)); + } /* * Immediately signal current torch status to this listener only @@ -2229,7 +2250,11 @@ Status CameraService::addListenerHelper(const sp<ICameraServiceListener>& listen Mutex::Autolock al(mTorchStatusMutex); for (size_t i = 0; i < mTorchStatusMap.size(); i++ ) { String16 id = String16(mTorchStatusMap.keyAt(i).string()); - listener->onTorchStatusChanged(mapToInterface(mTorchStatusMap.valueAt(i)), id); + // The camera id is visible to the client. Fine to send torch + // callback. + if (idsChosenForCallback.find(id) != idsChosenForCallback.end()) { + listener->onTorchStatusChanged(mapToInterface(mTorchStatusMap.valueAt(i)), id); + } } } @@ -3772,7 +3797,7 @@ void CameraService::updateStatus(StatusInternal status, const String8& cameraId, TorchModeStatus::AVAILABLE_OFF : TorchModeStatus::NOT_AVAILABLE; if (torchStatus != newTorchStatus) { - onTorchStatusChangedLocked(cameraId, newTorchStatus); + onTorchStatusChangedLocked(cameraId, newTorchStatus, deviceKind); } } } diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h index 685ed5ee1d..5c4c96bae7 100644 --- a/services/camera/libcameraservice/CameraService.h +++ b/services/camera/libcameraservice/CameraService.h @@ -995,7 +995,8 @@ private: // handle torch mode status change and invoke callbacks. mTorchStatusMutex // should be locked. void onTorchStatusChangedLocked(const String8& cameraId, - hardware::camera::common::V1_0::TorchModeStatus newStatus); + hardware::camera::common::V1_0::TorchModeStatus newStatus, + SystemCameraKind systemCameraKind); // get a camera's torch status. mTorchStatusMutex should be locked. status_t getTorchStatusLocked(const String8 &cameraId, @@ -1084,7 +1085,8 @@ private: static void pingCameraServiceProxy(); void broadcastTorchModeStatus(const String8& cameraId, - hardware::camera::common::V1_0::TorchModeStatus status); + hardware::camera::common::V1_0::TorchModeStatus status, + SystemCameraKind systemCameraKind); void disconnectClient(const String8& id, sp<BasicClient> clientToDisconnect); |