diff options
-rw-r--r-- | include/camera/CameraHardwareInterface.h | 1 | ||||
-rw-r--r-- | services/camera/libcameraservice/CameraService.cpp | 14 | ||||
-rw-r--r-- | services/camera/libcameraservice/CameraService.h | 1 |
3 files changed, 12 insertions, 4 deletions
diff --git a/include/camera/CameraHardwareInterface.h b/include/camera/CameraHardwareInterface.h index 1529db7..6a66e3c 100644 --- a/include/camera/CameraHardwareInterface.h +++ b/include/camera/CameraHardwareInterface.h @@ -221,6 +221,7 @@ public: */ extern "C" int HAL_getNumberOfCameras(); extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo); +/* HAL should return NULL if it fails to open camera hardware. */ extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId); }; // namespace android diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 3b3904a..ea2c5d4 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -145,7 +145,12 @@ sp<ICamera> CameraService::connect( return NULL; } - client = new Client(this, cameraClient, cameraId, callingPid); + sp<CameraHardwareInterface> hardware = HAL_openCameraHardware(cameraId); + if (hardware == NULL) { + LOGE("Fail to open camera hardware (id=%d)", cameraId); + return NULL; + } + client = new Client(this, cameraClient, hardware, cameraId, callingPid); mClient[cameraId] = client; LOG1("CameraService::connect X"); return client; @@ -285,16 +290,17 @@ void CameraService::playSound(sound_kind kind) { // ---------------------------------------------------------------------------- CameraService::Client::Client(const sp<CameraService>& cameraService, - const sp<ICameraClient>& cameraClient, int cameraId, int clientPid) { + const sp<ICameraClient>& cameraClient, + const sp<CameraHardwareInterface>& hardware, + int cameraId, int clientPid) { int callingPid = getCallingPid(); LOG1("Client::Client E (pid %d)", callingPid); mCameraService = cameraService; mCameraClient = cameraClient; + mHardware = hardware; mCameraId = cameraId; mClientPid = clientPid; - - mHardware = HAL_openCameraHardware(cameraId); mUseOverlay = mHardware->useOverlay(); mMsgEnabled = 0; diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h index 77ccf41..0d69836 100644 --- a/services/camera/libcameraservice/CameraService.h +++ b/services/camera/libcameraservice/CameraService.h @@ -106,6 +106,7 @@ private: friend class CameraService; Client(const sp<CameraService>& cameraService, const sp<ICameraClient>& cameraClient, + const sp<CameraHardwareInterface>& hardware, int cameraId, int clientPid); ~Client(); |