From e0602c7ab66cc9f3e3629b7424f6748b4e08af36 Mon Sep 17 00:00:00 2001 From: Mahdi Date: Mon, 17 Dec 2018 01:54:59 +1100 Subject: [PATCH] Swallow RuntimeExcpetions on autoFocus (#332) --- .../com/otaliastudios/cameraview/Camera1.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java index 9fda44b4..a814e7a8 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java @@ -823,15 +823,22 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera mCamera.setParameters(params); mCameraCallbacks.dispatchOnFocusStart(gesture, p); // TODO this is not guaranteed to be called... Fix. - mCamera.autoFocus(new Camera.AutoFocusCallback() { - @Override - public void onAutoFocus(boolean success, Camera camera) { - // TODO lock auto exposure and white balance for a while - mCameraCallbacks.dispatchOnFocusEnd(gesture, success, p); - mHandler.get().removeCallbacks(mPostFocusResetRunnable); - mHandler.get().postDelayed(mPostFocusResetRunnable, mPostFocusResetDelay); - } - }); + try { + mCamera.autoFocus(new Camera.AutoFocusCallback() { + @Override + public void onAutoFocus(boolean success, Camera camera) { + // TODO lock auto exposure and white balance for a while + mCameraCallbacks.dispatchOnFocusEnd(gesture, success, p); + mHandler.get().removeCallbacks(mPostFocusResetRunnable); + mHandler.get().postDelayed(mPostFocusResetRunnable, mPostFocusResetDelay); + } + }); + } catch (RuntimeException e) { + // Handling random auto-focus exception on some devices + // See https://github.com/natario1/CameraView/issues/181 + LOG.e("startAutoFocus:", "Error calling autoFocus", e); + mCameraCallbacks.dispatchOnFocusEnd(gesture, false, p); + } } }); }