diff options
author | Igor Murashkin <iam@google.com> | 2013-05-01 15:42:20 -0700 |
---|---|---|
committer | Igor Murashkin <iam@google.com> | 2013-05-02 18:04:38 -0700 |
commit | 93747b9c7724f690b3068300514c05629e0b0a3e (patch) | |
tree | 1c5874e91c55b47fa012c0581c0d6e0abd26cdfe /services/camera/libcameraservice/CameraService.cpp | |
parent | 2628bc9d1261c2942f3506baca348ccd71ea9c86 (diff) | |
download | frameworks_av-93747b9c7724f690b3068300514c05629e0b0a3e.zip frameworks_av-93747b9c7724f690b3068300514c05629e0b0a3e.tar.gz frameworks_av-93747b9c7724f690b3068300514c05629e0b0a3e.tar.bz2 |
Camera: Hotplug - conditionally transition to PRESENT when clients disconnect
Fixes an issue where a client could unconditionally transition to PRESENT
after a client disconnects, even though the underlying HAL status was actually
NOT_PRESENT or ENUMERATING.
Bug: 8780114
Change-Id: I68adb5fc819eec3b046ddcb2507b84bedc999a0f
Diffstat (limited to 'services/camera/libcameraservice/CameraService.cpp')
-rw-r--r-- | services/camera/libcameraservice/CameraService.cpp | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index cdeb92e..757a781 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -928,8 +928,15 @@ void CameraService::Client::disconnect() { ALOGV("Client::disconnect"); BasicClient::disconnect(); mCameraService->setCameraFree(mCameraId); + + StatusVector rejectSourceStates; + rejectSourceStates.push_back(ICameraServiceListener::STATUS_NOT_PRESENT); + rejectSourceStates.push_back(ICameraServiceListener::STATUS_ENUMERATING); + + // Transition to PRESENT if the camera is not in either of above 2 states mCameraService->updateStatus(ICameraServiceListener::STATUS_PRESENT, - mCameraId); + mCameraId, + &rejectSourceStates); } CameraService::Client::OpsCallback::OpsCallback(wp<BasicClient> client): @@ -1111,15 +1118,11 @@ status_t CameraService::dump(int fd, const Vector<String16>& args) { } void CameraService::updateStatus(ICameraServiceListener::Status status, - int32_t cameraId) { + int32_t cameraId, + const StatusVector *rejectSourceStates) { // do not lock mServiceLock here or can get into a deadlock from // connect() -> ProClient::disconnect -> updateStatus Mutex::Autolock lock(mStatusMutex); - updateStatusUnsafe(status, cameraId); -} - -void CameraService::updateStatusUnsafe(ICameraServiceListener::Status status, - int32_t cameraId) { ICameraServiceListener::Status oldStatus = mStatusList[cameraId]; @@ -1139,6 +1142,26 @@ void CameraService::updateStatusUnsafe(ICameraServiceListener::Status status, return; } + if (rejectSourceStates != NULL) { + const StatusVector &rejectList = *rejectSourceStates; + StatusVector::const_iterator it = rejectList.begin(); + + /** + * Sometimes we want to conditionally do a transition. + * For example if a client disconnects, we want to go to PRESENT + * only if we weren't already in NOT_PRESENT or ENUMERATING. + */ + for (; it != rejectList.end(); ++it) { + if (oldStatus == *it) { + ALOGV("%s: Rejecting status transition for Camera ID %d, " + " since the source state was was in one of the bad " + " states.", __FUNCTION__, cameraId); + mStatusList[cameraId] = oldStatus; + return; + } + } + } + /** * ProClients lose their exclusive lock. * - Done before the CameraClient can initialize the HAL device, |