Commit 05d5a876 authored by Christian Fremerey's avatar Christian Fremerey Committed by Commit Bot

[Video Capture] Catch undocumented Android camera exceptions that occur in the wild

Crash reports for Android show several Java exceptions being raised inside 
Android camera APIs. These exceptions are undocumented, and are likely to be 
caused by bugs in the (potentially vendor-customized) Android code.

With this CL, we catch the most frequently reported exceptions in order to fail 
gracefully instead of crashing.

Bug: 707320
Change-Id: Ie4013b65fc87995909c5ac3ed85e0c81dd31b3ca
Reviewed-on: https://chromium-review.googlesource.com/517270Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Commit-Queue: Christian Fremerey <chfremer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#476342}
parent 7b6a209c
...@@ -216,7 +216,12 @@ public class VideoCaptureCamera ...@@ -216,7 +216,12 @@ public class VideoCaptureCamera
// with at least one element, but when the camera is in bad state, they // with at least one element, but when the camera is in bad state, they
// can return null pointers; in that case we use a 0 entry, so we can // can return null pointers; in that case we use a 0 entry, so we can
// retrieve as much information as possible. // retrieve as much information as possible.
List<Integer> pixelFormats = parameters.getSupportedPreviewFormats(); List<Integer> pixelFormats = null;
try {
pixelFormats = parameters.getSupportedPreviewFormats();
} catch (NullPointerException ex) {
Log.e(TAG, "Camera.Parameters.getSupportedPreviewFormats: ", ex);
}
if (pixelFormats == null) { if (pixelFormats == null) {
pixelFormats = new ArrayList<Integer>(); pixelFormats = new ArrayList<Integer>();
} }
...@@ -231,7 +236,12 @@ public class VideoCaptureCamera ...@@ -231,7 +236,12 @@ public class VideoCaptureCamera
continue; continue;
} }
List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange(); List<int[]> listFpsRange = null;
try {
listFpsRange = parameters.getSupportedPreviewFpsRange();
} catch (StringIndexOutOfBoundsException ex) {
Log.e(TAG, "Camera.Parameters.getSupportedPreviewFpsRange: ", ex);
}
if (listFpsRange == null) { if (listFpsRange == null) {
listFpsRange = new ArrayList<int[]>(); listFpsRange = new ArrayList<int[]>();
} }
......
...@@ -291,7 +291,7 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -291,7 +291,7 @@ public class VideoCaptureCamera2 extends VideoCapture {
private Range<Integer> mAeFpsRange; private Range<Integer> mAeFpsRange;
private CameraState mCameraState = CameraState.STOPPED; private CameraState mCameraState = CameraState.STOPPED;
private final float mMaxZoom; private float mMaxZoom = 1.0f;
private Rect mCropRect = new Rect(); private Rect mCropRect = new Rect();
private int mPhotoWidth; private int mPhotoWidth;
private int mPhotoHeight; private int mPhotoHeight;
...@@ -314,7 +314,7 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -314,7 +314,7 @@ public class VideoCaptureCamera2 extends VideoCapture {
Context.CAMERA_SERVICE); Context.CAMERA_SERVICE);
try { try {
return manager.getCameraCharacteristics(Integer.toString(id)); return manager.getCameraCharacteristics(Integer.toString(id));
} catch (CameraAccessException ex) { } catch (CameraAccessException | IllegalArgumentException ex) {
Log.e(TAG, "getCameraCharacteristics: ", ex); Log.e(TAG, "getCameraCharacteristics: ", ex);
} }
return null; return null;
...@@ -571,12 +571,18 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -571,12 +571,18 @@ public class VideoCaptureCamera2 extends VideoCapture {
} }
static int getNumberOfCameras() { static int getNumberOfCameras() {
final CameraManager manager = CameraManager manager = null;
(CameraManager) ContextUtils.getApplicationContext().getSystemService( try {
Context.CAMERA_SERVICE); manager = (CameraManager) ContextUtils.getApplicationContext().getSystemService(
Context.CAMERA_SERVICE);
} catch (IllegalArgumentException ex) {
Log.e(TAG, "getSystemService(Context.CAMERA_SERVICE): ", ex);
return 0;
}
if (manager == null) return 0;
try { try {
return manager.getCameraIdList().length; return manager.getCameraIdList().length;
} catch (CameraAccessException | SecurityException ex) { } catch (CameraAccessException | SecurityException | AssertionError ex) {
// SecurityException is undocumented but seen in the wild: https://crbug/605424. // SecurityException is undocumented but seen in the wild: https://crbug/605424.
Log.e(TAG, "getNumberOfCameras: getCameraIdList(): ", ex); Log.e(TAG, "getNumberOfCameras: getCameraIdList(): ", ex);
return 0; return 0;
...@@ -656,8 +662,10 @@ public class VideoCaptureCamera2 extends VideoCapture { ...@@ -656,8 +662,10 @@ public class VideoCaptureCamera2 extends VideoCapture {
VideoCaptureCamera2(int id, long nativeVideoCaptureDeviceAndroid) { VideoCaptureCamera2(int id, long nativeVideoCaptureDeviceAndroid) {
super(id, nativeVideoCaptureDeviceAndroid); super(id, nativeVideoCaptureDeviceAndroid);
final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(id); final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(id);
mMaxZoom = if (cameraCharacteristics != null) {
cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM); mMaxZoom = cameraCharacteristics.get(
CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
}
} }
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment