From 7dff3c94cbf7c8e480e7e3506969d065277c466a Mon Sep 17 00:00:00 2001 From: Phillip Berndt Date: Mon, 29 Aug 2016 19:55:59 +0200 Subject: [PATCH] klte-common: Fix HDR mode This is a follow-up to Ifb15e64b4c351d7195e5ad3f5d5315419790d0f8. The change fixed a crash upon deactivation of torch mode by removing code that forecully set or unset Zero Shutter Lag. This change results in HDR not working anymore, but SEGFAULTing the camera instead. The commit addressed this by disabling HDR entirely. The present change reinstates the removed code, but executes it conditionally only if the camera is not in torch mode. This prevents the crash upon disabling torch mode and simultaneously leaves HDR in a working condition. Torch mode can only be reliably detected when it is activated by checking whether the requested settings have a "flash-mode" of "torch" set. Deactivation simply asks to deactivate the flash, which cannot be told apart from the camera app requesting the same before taking a photo. The CameraWrapper however stores the current settings, so by checking if they contain a "flash-mode" of "torch", it is still possible to detect the mode's deactivation. The only possible problem with this approach could arise if the camera went directly from torch mode to camera mode with HDR, but this apparently does not happen. Change-Id: I71611257868b3bf86041adf7aed931cf92880ddc --- camera/CameraWrapper.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/camera/CameraWrapper.cpp b/camera/CameraWrapper.cpp index 0ee0f2b..b17b4a7 100644 --- a/camera/CameraWrapper.cpp +++ b/camera/CameraWrapper.cpp @@ -122,8 +122,6 @@ static char *camera_fixup_getparams(int __attribute__((unused)) id, ALOGV("%s: original parameters:", __FUNCTION__); params.dump(); - params.set(CameraParameters::KEY_SUPPORTED_SCENE_MODES, "auto"); - const char *recordHint = params.get(CameraParameters::KEY_RECORDING_HINT); bool videoMode = recordHint ? !strcmp(recordHint, "true") : false; @@ -173,8 +171,31 @@ static char *camera_fixup_setparams(int id, const char *settings) ALOGV("%s: original parameters:", __FUNCTION__); params.dump(); + bool wasTorch = false; + if (fixed_set_params[id]) { + /* When torch mode is switched off, it is important not to set ZSL, to + avoid a segmentation violation in libcameraservice.so. Hence, check + if the last call to setparams enabled torch mode */ + CameraParameters old_params; + old_params.unflatten(String8(fixed_set_params[id])); + + const char *old_flashMode = old_params.get(CameraParameters::KEY_FLASH_MODE); + wasTorch = old_flashMode && !strcmp(old_flashMode, CameraParameters::FLASH_MODE_TORCH); + } + const char *recordingHint = params.get(CameraParameters::KEY_RECORDING_HINT); bool isVideo = recordingHint && !strcmp(recordingHint, "true"); + const char *flashMode = params.get(CameraParameters::KEY_FLASH_MODE); + bool isTorch = flashMode && !strcmp(flashMode, CameraParameters::FLASH_MODE_TORCH); + + if (!isTorch && !wasTorch) { + if (isVideo) { + params.set(CameraParameters::KEY_DIS, CameraParameters::DIS_DISABLE); + params.set(CameraParameters::KEY_ZSL, CameraParameters::ZSL_OFF); + } else { + params.set(CameraParameters::KEY_ZSL, CameraParameters::ZSL_ON); + } + } ALOGV("%s: Fixed parameters:", __FUNCTION__); params.dump();