catch Camera RuntimeExceptions

fixes #3895
Closes #4083
// FREEBIE
This commit is contained in:
Jake McGinty 2015-09-17 11:24:39 -07:00 committed by Moxie Marlinspike
parent 336962eb55
commit a7e05c4cd6

View File

@ -114,6 +114,7 @@ public class CameraView extends FrameLayout {
host.onCameraFail(result); host.onCameraFail(result);
return; return;
} }
try {
cameraReady = true; cameraReady = true;
if (getActivity().getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { if (getActivity().getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
onOrientationChange.enable(); onOrientationChange.enable();
@ -127,6 +128,14 @@ public class CameraView extends FrameLayout {
requestLayout(); requestLayout();
invalidate(); invalidate();
Log.w(TAG, "onResume() completed"); Log.w(TAG, "onResume() completed");
} catch (RuntimeException re) {
Log.w(TAG, "exception when starting camera preview", re);
try {
previewDestroyed();
} catch (RuntimeException re2) {
Log.w(TAG, "also failed to release camera", re2);
}
}
} }
}); });
} }
@ -272,9 +281,12 @@ public class CameraView extends FrameLayout {
} }
void previewDestroyed() { void previewDestroyed() {
try {
if (camera != null) { if (camera != null) {
previewStopped(); previewStopped();
camera.release(); camera.release();
}
} finally {
camera = null; camera = null;
} }
} }