Loading services/camera/libcameraservice/CameraFlashlight.cpp +29 −6 Original line number Diff line number Diff line Loading @@ -679,7 +679,8 @@ status_t CameraHardwareInterfaceFlashControl::setTorchMode( status_t res; if (enabled) { bool hasFlash = false; res = hasFlashUnitLocked(cameraId, &hasFlash); // Check if it has a flash unit and leave camera device open. res = hasFlashUnitLocked(cameraId, &hasFlash, /*keepDeviceOpen*/true); // invalid camera? if (res) { // hasFlashUnitLocked() returns BAD_INDEX if mDevice is connected to Loading @@ -688,6 +689,8 @@ status_t CameraHardwareInterfaceFlashControl::setTorchMode( } // no flash unit? if (!hasFlash) { // Disconnect camera device if it has no flash. disconnectCameraDevice(); return -ENOSYS; } } else if (mDevice == NULL || cameraId != mCameraId) { Loading Loading @@ -716,21 +719,28 @@ status_t CameraHardwareInterfaceFlashControl::setTorchMode( status_t CameraHardwareInterfaceFlashControl::hasFlashUnit( const String8& cameraId, bool *hasFlash) { Mutex::Autolock l(mLock); return hasFlashUnitLocked(cameraId, hasFlash); // Close device after checking if it has a flash unit. return hasFlashUnitLocked(cameraId, hasFlash, /*keepDeviceOpen*/false); } status_t CameraHardwareInterfaceFlashControl::hasFlashUnitLocked( const String8& cameraId, bool *hasFlash) { const String8& cameraId, bool *hasFlash, bool keepDeviceOpen) { bool closeCameraDevice = false; if (!hasFlash) { return BAD_VALUE; } status_t res; if (mDevice == NULL) { // Connect to camera device to query if it has a flash unit. res = connectCameraDevice(cameraId); if (res) { return res; } // Close camera device only when it is just opened and the caller doesn't want to keep // the camera device open. closeCameraDevice = !keepDeviceOpen; } if (cameraId != mCameraId) { Loading @@ -745,6 +755,15 @@ status_t CameraHardwareInterfaceFlashControl::hasFlashUnitLocked( *hasFlash = false; } if (closeCameraDevice) { res = disconnectCameraDevice(); if (res != OK) { ALOGE("%s: Failed to disconnect camera device. %s (%d)", __FUNCTION__, strerror(-res), res); return res; } } return OK; } Loading Loading @@ -869,9 +888,13 @@ status_t CameraHardwareInterfaceFlashControl::disconnectCameraDevice() { return OK; } if (mParameters.get(CameraParameters::KEY_FLASH_MODE)) { // There is a flash, turn if off. // (If there isn't one, leave the parameter null) mParameters.set(CameraParameters::KEY_FLASH_MODE, CameraParameters::FLASH_MODE_OFF); mDevice->setParameters(mParameters); } mDevice->stopPreview(); status_t res = native_window_api_disconnect(mSurface.get(), NATIVE_WINDOW_API_CAMERA); Loading services/camera/libcameraservice/CameraFlashlight.h +5 −1 Original line number Diff line number Diff line Loading @@ -203,7 +203,11 @@ class CameraHardwareInterfaceFlashControl : public FlashControlBase { status_t getSmallestSurfaceSize(int32_t *width, int32_t *height); // protected by mLock status_t hasFlashUnitLocked(const String8& cameraId, bool *hasFlash); // If this function opens camera device in order to check if it has a flash unit, the // camera device will remain open if keepDeviceOpen is true and the camera device will be // closed if keepDeviceOpen is false. If camera device is already open when calling this // function, keepDeviceOpen is ignored. status_t hasFlashUnitLocked(const String8& cameraId, bool *hasFlash, bool keepDeviceOpen); CameraModule *mCameraModule; const camera_module_callbacks_t *mCallbacks; Loading Loading
services/camera/libcameraservice/CameraFlashlight.cpp +29 −6 Original line number Diff line number Diff line Loading @@ -679,7 +679,8 @@ status_t CameraHardwareInterfaceFlashControl::setTorchMode( status_t res; if (enabled) { bool hasFlash = false; res = hasFlashUnitLocked(cameraId, &hasFlash); // Check if it has a flash unit and leave camera device open. res = hasFlashUnitLocked(cameraId, &hasFlash, /*keepDeviceOpen*/true); // invalid camera? if (res) { // hasFlashUnitLocked() returns BAD_INDEX if mDevice is connected to Loading @@ -688,6 +689,8 @@ status_t CameraHardwareInterfaceFlashControl::setTorchMode( } // no flash unit? if (!hasFlash) { // Disconnect camera device if it has no flash. disconnectCameraDevice(); return -ENOSYS; } } else if (mDevice == NULL || cameraId != mCameraId) { Loading Loading @@ -716,21 +719,28 @@ status_t CameraHardwareInterfaceFlashControl::setTorchMode( status_t CameraHardwareInterfaceFlashControl::hasFlashUnit( const String8& cameraId, bool *hasFlash) { Mutex::Autolock l(mLock); return hasFlashUnitLocked(cameraId, hasFlash); // Close device after checking if it has a flash unit. return hasFlashUnitLocked(cameraId, hasFlash, /*keepDeviceOpen*/false); } status_t CameraHardwareInterfaceFlashControl::hasFlashUnitLocked( const String8& cameraId, bool *hasFlash) { const String8& cameraId, bool *hasFlash, bool keepDeviceOpen) { bool closeCameraDevice = false; if (!hasFlash) { return BAD_VALUE; } status_t res; if (mDevice == NULL) { // Connect to camera device to query if it has a flash unit. res = connectCameraDevice(cameraId); if (res) { return res; } // Close camera device only when it is just opened and the caller doesn't want to keep // the camera device open. closeCameraDevice = !keepDeviceOpen; } if (cameraId != mCameraId) { Loading @@ -745,6 +755,15 @@ status_t CameraHardwareInterfaceFlashControl::hasFlashUnitLocked( *hasFlash = false; } if (closeCameraDevice) { res = disconnectCameraDevice(); if (res != OK) { ALOGE("%s: Failed to disconnect camera device. %s (%d)", __FUNCTION__, strerror(-res), res); return res; } } return OK; } Loading Loading @@ -869,9 +888,13 @@ status_t CameraHardwareInterfaceFlashControl::disconnectCameraDevice() { return OK; } if (mParameters.get(CameraParameters::KEY_FLASH_MODE)) { // There is a flash, turn if off. // (If there isn't one, leave the parameter null) mParameters.set(CameraParameters::KEY_FLASH_MODE, CameraParameters::FLASH_MODE_OFF); mDevice->setParameters(mParameters); } mDevice->stopPreview(); status_t res = native_window_api_disconnect(mSurface.get(), NATIVE_WINDOW_API_CAMERA); Loading
services/camera/libcameraservice/CameraFlashlight.h +5 −1 Original line number Diff line number Diff line Loading @@ -203,7 +203,11 @@ class CameraHardwareInterfaceFlashControl : public FlashControlBase { status_t getSmallestSurfaceSize(int32_t *width, int32_t *height); // protected by mLock status_t hasFlashUnitLocked(const String8& cameraId, bool *hasFlash); // If this function opens camera device in order to check if it has a flash unit, the // camera device will remain open if keepDeviceOpen is true and the camera device will be // closed if keepDeviceOpen is false. If camera device is already open when calling this // function, keepDeviceOpen is ignored. status_t hasFlashUnitLocked(const String8& cameraId, bool *hasFlash, bool keepDeviceOpen); CameraModule *mCameraModule; const camera_module_callbacks_t *mCallbacks; Loading