From 8455c23fb19cd99a99780fcc670a85dc4a4a54aa Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 11 Jul 2020 23:02:00 +0300 Subject: [PATCH] Wrapped some crashes which connect with empty camera params (#851) Co-authored-by: Mattia Iavarone --- .../cameraview/engine/Camera1Engine.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java index bd5da1e0..7cb41d1a 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java @@ -100,7 +100,13 @@ public class Camera1Engine extends CameraBaseEngine implements @NonNull @Override protected List getPreviewStreamAvailableSizes() { - List sizes = mCamera.getParameters().getSupportedPreviewSizes(); + List sizes; + try { + sizes = mCamera.getParameters().getSupportedPreviewSizes(); + } catch (Exception e) { + LOG.e("getPreviewStreamAvailableSizes:", "Failed to compute preview size. Camera params is empty"); + throw new CameraException(e, CameraException.REASON_FAILED_TO_START_PREVIEW); + } List result = new ArrayList<>(sizes.size()); for (Camera.Size size : sizes) { Size add = new Size(size.width, size.height); @@ -163,11 +169,16 @@ public class Camera1Engine extends CameraBaseEngine implements // Set parameters that might have been set before the camera was opened. LOG.i("onStartEngine:", "Applying default parameters."); - Camera.Parameters params = mCamera.getParameters(); - mCameraOptions = new Camera1Options(params, mCameraId, - getAngles().flip(Reference.SENSOR, Reference.VIEW)); - applyAllParameters(params); - mCamera.setParameters(params); + try { + Camera.Parameters params = mCamera.getParameters(); + mCameraOptions = new Camera1Options(params, mCameraId, + getAngles().flip(Reference.SENSOR, Reference.VIEW)); + applyAllParameters(params); + mCamera.setParameters(params); + } catch (Exception e) { + LOG.e("onStartEngine:", "Failed to connect. Problem with camera params"); + throw new CameraException(e, CameraException.REASON_FAILED_TO_CONNECT); + } mCamera.setDisplayOrientation(getAngles().offset(Reference.SENSOR, Reference.VIEW, Axis.ABSOLUTE)); // <- not allowed during preview LOG.i("onStartEngine:", "Ended");