status_t CameraFlashlight::deviceClosed(const String8& cameraId) { ALOGV("%s: device %s is closed", __FUNCTION__, cameraId.string()); Mutex::Autolock l(mLock); if (!mFlashlightMapInitialized) { ALOGE("%s: findFlashUnits() must be called before this method."); return NO_INIT; } ssize_t index = mOpenedCameraIds.indexOf(cameraId); if (index == NAME_NOT_FOUND) { ALOGE("%s: couldn't find camera %s in the opened list", __FUNCTION__, cameraId.string()); } else { mOpenedCameraIds.removeAt(index); } // Cannot do anything until all cameras are closed. if (mOpenedCameraIds.size() != 0) return OK; if (mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) { // notify torch available for all cameras with a flash int numCameras = mCameraModule->getNumberOfCameras(); for (int i = 0; i < numCameras; i++) { if (hasFlashUnitLocked(String8::format("%d", i))) { mCallbacks->torch_mode_status_change(mCallbacks, String8::format("%d", i).string(), TORCH_MODE_STATUS_AVAILABLE_OFF); } } } return OK; }
status_t CameraDeviceClientFlashControl::hasFlashUnit(const String8& cameraId, bool *hasFlash) { ALOGV("%s: checking if camera %s has a flash unit", __FUNCTION__, cameraId.string()); Mutex::Autolock l(mLock); return hasFlashUnitLocked(cameraId, hasFlash); }
status_t CameraDeviceClientFlashControl::setTorchMode( const String8& cameraId, bool enabled) { bool hasFlash = false; Mutex::Autolock l(mLock); status_t res = hasFlashUnitLocked(cameraId, &hasFlash); // pre-check if (enabled) { // invalid camera? if (res) { return -EINVAL; } // no flash unit? if (!hasFlash) { return -ENOSYS; } // already opened for a different device? if (mDevice != NULL && cameraId != mCameraId) { return BAD_INDEX; } } else if (mDevice == NULL || cameraId != mCameraId) { // disabling the torch mode of an un-opened or different device. return OK; } else { // disabling the torch mode of currently opened device disconnectCameraDevice(); mTorchEnabled = false; mCallbacks->torch_mode_status_change(mCallbacks, cameraId.string(), TORCH_MODE_STATUS_AVAILABLE_OFF); return OK; } if (mDevice == NULL) { res = connectCameraDevice(cameraId); if (res) { return res; } } res = submitTorchEnabledRequest(); if (res) { return res; } mTorchEnabled = true; mCallbacks->torch_mode_status_change(mCallbacks, cameraId.string(), TORCH_MODE_STATUS_AVAILABLE_ON); return OK; }
status_t CameraHardwareInterfaceFlashControl::setTorchMode( const String8& cameraId, bool enabled) { Mutex::Autolock l(mLock); // pre-check status_t res; if (enabled) { bool hasFlash = false; res = hasFlashUnitLocked(cameraId, &hasFlash); // invalid camera? if (res) { // hasFlashUnitLocked() returns BAD_INDEX if mDevice is connected to // another camera device. return res == BAD_INDEX ? BAD_INDEX : -EINVAL; } // no flash unit? if (!hasFlash) { return -ENOSYS; } } else if (mDevice == NULL || cameraId != mCameraId) { // disabling the torch mode of an un-opened or different device. return OK; } else { // disabling the torch mode of currently opened device disconnectCameraDevice(); mTorchEnabled = false; mCallbacks->torch_mode_status_change(mCallbacks, cameraId.string(), TORCH_MODE_STATUS_AVAILABLE_OFF); return OK; } res = startPreviewAndTorch(); if (res) { return res; } mTorchEnabled = true; mCallbacks->torch_mode_status_change(mCallbacks, cameraId.string(), TORCH_MODE_STATUS_AVAILABLE_ON); return OK; }
status_t CameraFlashlight::prepareDeviceOpen(const String8& cameraId) { ALOGV("%s: prepare for device open", __FUNCTION__); Mutex::Autolock l(mLock); if (!mFlashlightMapInitialized) { ALOGE("%s: findFlashUnits() must be called before this method.", __FUNCTION__); return NO_INIT; } if (mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) { // framework is going to open a camera device, all flash light control // should be closed for backward compatible support. mFlashControl.clear(); if (mOpenedCameraIds.size() == 0) { // notify torch unavailable for all cameras with a flash int numCameras = mCameraModule->getNumberOfCameras(); for (int i = 0; i < numCameras; i++) { if (hasFlashUnitLocked(String8::format("%d", i))) { mCallbacks->torch_mode_status_change(mCallbacks, String8::format("%d", i).string(), TORCH_MODE_STATUS_NOT_AVAILABLE); } } } // close flash control that may be opened by calling hasFlashUnitLocked. mFlashControl.clear(); } if (mOpenedCameraIds.indexOf(cameraId) == NAME_NOT_FOUND) { mOpenedCameraIds.add(cameraId); } return OK; }
status_t CameraHardwareInterfaceFlashControl::hasFlashUnit( const String8& cameraId, bool *hasFlash) { Mutex::Autolock l(mLock); return hasFlashUnitLocked(cameraId, hasFlash); }
bool CameraFlashlight::hasFlashUnit(const String8& cameraId) { status_t res; Mutex::Autolock l(mLock); return hasFlashUnitLocked(cameraId); }