diff options
author | Igor Murashkin <iam@google.com> | 2013-05-08 15:03:34 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-05-08 15:03:34 -0700 |
commit | d354abf5658a9da89762e09ae46404ab6b1c9bae (patch) | |
tree | 2cd7974af0d732b6cf72ae02f1e646b98aef4e15 | |
parent | 1f7d356fa094b975ad2ebf9217be6abba2c70825 (diff) | |
parent | a790258aa5061a18ef455061de914c025fa86ded (diff) | |
download | frameworks_av-d354abf5658a9da89762e09ae46404ab6b1c9bae.zip frameworks_av-d354abf5658a9da89762e09ae46404ab6b1c9bae.tar.gz frameworks_av-d354abf5658a9da89762e09ae46404ab6b1c9bae.tar.bz2 |
am a790258a: am a5751c3a: Merge "Camera: Hotplug - conditionally transition to PRESENT when clients disconnect" into jb-mr2-dev
* commit 'a790258aa5061a18ef455061de914c025fa86ded':
Camera: Hotplug - conditionally transition to PRESENT when clients disconnect
-rw-r--r-- | services/camera/libcameraservice/CameraService.cpp | 37 | ||||
-rw-r--r-- | services/camera/libcameraservice/CameraService.h | 8 |
2 files changed, 33 insertions, 12 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, diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h index bb3fb25..eaa316a 100644 --- a/services/camera/libcameraservice/CameraService.h +++ b/services/camera/libcameraservice/CameraService.h @@ -343,14 +343,12 @@ private: ICameraServiceListener::Status getStatus(int cameraId) const; + typedef Vector<ICameraServiceListener::Status> StatusVector; // Broadcast the new status if it changed (locks the service mutex) void updateStatus( ICameraServiceListener::Status status, - int32_t cameraId); - // Call this one when the service mutex is already held (idempotent) - void updateStatusUnsafe( - ICameraServiceListener::Status status, - int32_t cameraId); + int32_t cameraId, + const StatusVector *rejectSourceStates = NULL); // IBinder::DeathRecipient implementation virtual void binderDied(const wp<IBinder> &who); |