From d6d881b0cac20ecb5915cf094386aa44662e4ec6 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Wed, 8 Jul 2015 17:37:48 -0700 Subject: [PATCH] Fix NPE when camera is not in ready state Fixes #3567 Closes #3570 // FREEBIE --- .../thoughtcrime/securesms/components/camera/CameraView.java | 5 +++-- .../securesms/components/camera/QuickCamera.java | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/components/camera/CameraView.java b/src/org/thoughtcrime/securesms/components/camera/CameraView.java index 859abfb63d..eceb53161c 100644 --- a/src/org/thoughtcrime/securesms/components/camera/CameraView.java +++ b/src/org/thoughtcrime/securesms/components/camera/CameraView.java @@ -22,6 +22,7 @@ import android.content.pm.ActivityInfo; import android.hardware.Camera; import android.hardware.Camera.PreviewCallback; import android.os.Build; +import android.support.annotation.Nullable; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; @@ -240,8 +241,8 @@ public class CameraView extends FrameLayout { if (camera != null) camera.setOneShotPreviewCallback(callback); } - public Camera.Parameters getCameraParameters() { - return camera.getParameters(); + public @Nullable Camera.Parameters getCameraParameters() { + return camera == null || !cameraReady ? null : camera.getParameters(); } void previewCreated() { diff --git a/src/org/thoughtcrime/securesms/components/camera/QuickCamera.java b/src/org/thoughtcrime/securesms/components/camera/QuickCamera.java index 805b8dbf0c..4eba2df59a 100644 --- a/src/org/thoughtcrime/securesms/components/camera/QuickCamera.java +++ b/src/org/thoughtcrime/securesms/components/camera/QuickCamera.java @@ -70,6 +70,11 @@ import java.util.List; } final Parameters cameraParameters = getCameraParameters(); + if (cameraParameters == null) { + Log.w(TAG, "camera not in capture-ready state"); + return; + } + setOneShotPreviewCallback(new Camera.PreviewCallback() { @Override public void onPreviewFrame(byte[] data, final Camera camera) {