camera2-portability: Improve capability conversions' null-safety
This makes it harder for unexpected nulls in CaptureRequest templates to cause
exceptions while unboxing Integer wrappers. Such crashes were observed on some
devices while running on the legacy layer, especially with scene modes.
Change-Id: I0cae95534f138e97f2c589d15e81f77b4f2141f7
diff --git a/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java b/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java
index 288ded7..efa68e8 100644
--- a/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java
+++ b/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2Settings.java
@@ -84,13 +84,21 @@
// TODO: mCurrentZoomIndex
mExposureCompensationIndex =
queryTemplateDefaultOrMakeOneUp(CONTROL_AE_EXPOSURE_COMPENSATION, 0);
+
mCurrentFlashMode = flashModeFromRequest();
- mCurrentFocusMode = AndroidCamera2Capabilities.focusModeFromInt(
- mTemplateSettings.get(CONTROL_AF_MODE));
- mCurrentSceneMode = AndroidCamera2Capabilities.sceneModeFromInt(
- mTemplateSettings.get(CONTROL_SCENE_MODE));
- mWhiteBalance = AndroidCamera2Capabilities.whiteBalanceFromInt(
- mTemplateSettings.get(CONTROL_AWB_MODE));
+ Integer currentFocusMode = mTemplateSettings.get(CONTROL_AF_MODE);
+ if (currentFocusMode != null) {
+ mCurrentFocusMode = AndroidCamera2Capabilities.focusModeFromInt(currentFocusMode);
+ }
+ Integer currentSceneMode = mTemplateSettings.get(CONTROL_SCENE_MODE);
+ if (currentSceneMode != null) {
+ mCurrentSceneMode = AndroidCamera2Capabilities.sceneModeFromInt(currentSceneMode);
+ }
+ Integer whiteBalance = mTemplateSettings.get(CONTROL_AWB_MODE);
+ if (whiteBalance != null) {
+ mWhiteBalance = AndroidCamera2Capabilities.whiteBalanceFromInt(whiteBalance);
+ }
+
mVideoStabilizationEnabled = queryTemplateDefaultOrMakeOneUp(
CONTROL_VIDEO_STABILIZATION_MODE, CONTROL_VIDEO_STABILIZATION_MODE_OFF) ==
CONTROL_VIDEO_STABILIZATION_MODE_ON;