summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhao Wei Liew <zhaoweiliew@gmail.com>2016-07-10 15:11:43 +0800
committerEthan Chen <intervigil@gmail.com>2016-07-12 17:33:37 -0700
commit14264df5291efe701026ec1eec23bc00bbd77ce3 (patch)
tree0bf01ae23f80d2ab9e65d21ae4d0c7d812483ad8
parent3f9223e404e20a4ad3238fa0c65c60084e73e747 (diff)
downloadandroid_packages_apps_Snap-14264df5291efe701026ec1eec23bc00bbd77ce3.zip
android_packages_apps_Snap-14264df5291efe701026ec1eec23bc00bbd77ce3.tar.gz
android_packages_apps_Snap-14264df5291efe701026ec1eec23bc00bbd77ce3.tar.bz2
Snap: Tighten openLegacy() try-catch block
We only have to enclose the openLegacy() call in a try-catch block. This prevents us from re-calling open() when open() fails and throws a RuntimeException. Change-Id: I81396e453f57215338a0c4da41c4116f2b4d42ca
-rw-r--r--src/com/android/camera/AndroidCameraManagerImpl.java27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/com/android/camera/AndroidCameraManagerImpl.java b/src/com/android/camera/AndroidCameraManagerImpl.java
index 9a7b734..97ec6af 100644
--- a/src/com/android/camera/AndroidCameraManagerImpl.java
+++ b/src/com/android/camera/AndroidCameraManagerImpl.java
@@ -211,25 +211,26 @@ class AndroidCameraManagerImpl implements CameraManager {
switch (msg.what) {
case OPEN_CAMERA:
int cameraId = msg.arg1;
- try {
- Context context = CameraApp.getContext();
-
- boolean backCameraOpenLegacy = context.getResources().getBoolean(R.bool.back_camera_open_legacy);
- boolean frontCameraOpenLegacy = context.getResources().getBoolean(R.bool.front_camera_open_legacy);
+ Context context = CameraApp.getContext();
- CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
+ boolean backCameraOpenLegacy = context.getResources().
+ getBoolean(R.bool.back_camera_open_legacy);
+ boolean frontCameraOpenLegacy = context.getResources().
+ getBoolean(R.bool.front_camera_open_legacy);
- if ((info.facing == CameraInfo.CAMERA_FACING_BACK && backCameraOpenLegacy) ||
- (info.facing == CameraInfo.CAMERA_FACING_FRONT && frontCameraOpenLegacy)) {
+ CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
+ if (info.facing == CameraInfo.CAMERA_FACING_BACK && backCameraOpenLegacy ||
+ info.facing == CameraInfo.CAMERA_FACING_FRONT && frontCameraOpenLegacy) {
+ try {
mCamera = android.hardware.Camera.openLegacy(cameraId,
android.hardware.Camera.CAMERA_HAL_API_VERSION_1_0);
- } else {
+ } catch (RuntimeException e) {
+ /* Retry with open if openLegacy fails */
+ Log.v(TAG, "openLegacy failed. Using open instead");
mCamera = android.hardware.Camera.open(cameraId);
}
- } catch (RuntimeException e) {
- /* Retry with open if openLegacy fails */
- Log.v(TAG, "openLegacy failed. Using open instead");
- mCamera = android.hardware.Camera.open(cameraId);
+ } else {
+ mCamera = android.hardware.Camera.open(cameraId);
}
if (mCamera != null) {
mParametersIsDirty = true;