Android Camera2Enumerator: Remove CameraAccessException to avoid VerifyError

Apparently, a class will fail with VerifyError if it contains catch
statements with an Exception from a newer API, even if the code is never
executed. This happens only on Android versions before 4.4.2 and is a
bug. See https://code.google.com/p/android/issues/detail?id=209129 for
more info.

BUG=b/30376736

Review-Url: https://codereview.webrtc.org/2185833003
Cr-Commit-Position: refs/heads/master@{#13542}
This commit is contained in:
magjed
2016-07-27 08:25:08 -07:00
committed by Commit bot
parent 529f83c521
commit 43e15bb9f0

View File

@ -16,13 +16,13 @@ import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager; import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata; import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.params.StreamConfigurationMap; import android.hardware.camera2.params.StreamConfigurationMap;
import android.os.Build; import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.AndroidException;
import android.util.Range; import android.util.Range;
import java.util.ArrayList; import java.util.ArrayList;
@ -52,7 +52,10 @@ public class Camera2Enumerator implements CameraEnumerator {
public String[] getDeviceNames() { public String[] getDeviceNames() {
try { try {
return cameraManager.getCameraIdList(); return cameraManager.getCameraIdList();
} catch (CameraAccessException e) { // On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
// catch statement with an Exception from a newer API, even if the code is never executed.
// https://code.google.com/p/android/issues/detail?id=209129
} catch (/* CameraAccessException */ AndroidException e) {
Logging.e(TAG, "Camera access exception: " + e); Logging.e(TAG, "Camera access exception: " + e);
return new String[] {}; return new String[] {};
} }
@ -87,7 +90,10 @@ public class Camera2Enumerator implements CameraEnumerator {
private CameraCharacteristics getCameraCharacteristics(String deviceName) { private CameraCharacteristics getCameraCharacteristics(String deviceName) {
try { try {
return cameraManager.getCameraCharacteristics(deviceName); return cameraManager.getCameraCharacteristics(deviceName);
} catch (CameraAccessException e) { // On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
// catch statement with an Exception from a newer API, even if the code is never executed.
// https://code.google.com/p/android/issues/detail?id=209129
} catch (/* CameraAccessException */ AndroidException e) {
Logging.e(TAG, "Camera access exception: " + e); Logging.e(TAG, "Camera access exception: " + e);
return null; return null;
} }