Fix NPE when camera is not in ready state

Fixes #3567
Closes #3570
// FREEBIE
This commit is contained in:
Jake McGinty 2015-07-08 17:37:48 -07:00 committed by Moxie Marlinspike
parent 5fdd5cad4e
commit d6d881b0ca
2 changed files with 8 additions and 2 deletions

View File

@ -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() {

View File

@ -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) {