From 2064b8549b36a5ceb76d205353173c23477430d3 Mon Sep 17 00:00:00 2001 From: codeworkx Date: Thu, 22 Dec 2016 20:05:52 +0100 Subject: Snap: make openLegacy an option Using openLegacy on QCamera3 forces it to use QCamera2 and fall back to api v1 which is not what we want on v2 devices. Change-Id: Ic392a4ae9403ebae36940ddf0727237d9cb9e8f0 --- .../android/camera/AndroidCameraManagerImpl.java | 43 ++++++++++++++++------ src/com/android/camera/app/CameraApp.java | 7 ++++ 2 files changed, 39 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/com/android/camera/AndroidCameraManagerImpl.java b/src/com/android/camera/AndroidCameraManagerImpl.java index b151c1914..74f822694 100644 --- a/src/com/android/camera/AndroidCameraManagerImpl.java +++ b/src/com/android/camera/AndroidCameraManagerImpl.java @@ -21,10 +21,12 @@ import static com.android.camera.util.CameraUtil.Assert; import java.io.IOException; import android.annotation.TargetApi; +import android.content.Context; import android.graphics.SurfaceTexture; import android.hardware.Camera; import android.hardware.Camera.AutoFocusCallback; import android.hardware.Camera.AutoFocusMoveCallback; +import android.hardware.Camera.CameraInfo; import android.hardware.Camera.ErrorCallback; import android.hardware.Camera.FaceDetectionListener; import android.hardware.Camera.OnZoomChangeListener; @@ -45,6 +47,10 @@ import com.android.camera.util.ApiHelper; import android.os.ConditionVariable; import java.lang.reflect.Method; +import com.android.camera.app.CameraApp; + +import org.codeaurora.snapcam.R; + /** * A class to implement {@link CameraManager} of the Android camera framework. */ @@ -207,23 +213,38 @@ class AndroidCameraManagerImpl implements CameraManager { try { switch (msg.what) { case OPEN_CAMERA: - try { - Method openMethod = Class.forName("android.hardware.Camera").getMethod( - "openLegacy", int.class, int.class); - mCamera = (android.hardware.Camera) openMethod.invoke( - null, msg.arg1, CAMERA_HAL_API_VERSION_1_0); - } catch (Exception e) { - /* Retry with open if openLegacy doesn't exist/fails */ - Log.v(TAG, "openLegacy failed due to " + e.getMessage() - + ", using open instead"); - mCamera = android.hardware.Camera.open(msg.arg1); + int cameraId = msg.arg1; + 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); + + CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId]; + + if (info.facing == CameraInfo.CAMERA_FACING_BACK && backCameraOpenLegacy || + info.facing == CameraInfo.CAMERA_FACING_FRONT && frontCameraOpenLegacy) { + try { + Method openMethod = Class.forName("android.hardware.Camera").getMethod( + "openLegacy", int.class, int.class); + mCamera = (android.hardware.Camera) openMethod.invoke( + null, cameraId, CAMERA_HAL_API_VERSION_1_0); + } catch (Exception e) { + /* Retry with open if openLegacy doesn't exist/fails */ + Log.v(TAG, "openLegacy failed due to " + e.getMessage() + + ", using open instead"); + mCamera = android.hardware.Camera.open(cameraId); + } + } else { + mCamera = android.hardware.Camera.open(cameraId); } if (mCamera != null) { mParametersIsDirty = true; } else { if (msg.obj != null) { - ((CameraOpenErrorCallback) msg.obj).onDeviceOpenFailure(msg.arg1); + ((CameraOpenErrorCallback) msg.obj).onDeviceOpenFailure(cameraId); } } return; diff --git a/src/com/android/camera/app/CameraApp.java b/src/com/android/camera/app/CameraApp.java index 6261159ec..3c1381f4d 100644 --- a/src/com/android/camera/app/CameraApp.java +++ b/src/com/android/camera/app/CameraApp.java @@ -19,12 +19,14 @@ package com.android.camera.app; import android.app.ActivityManager; import android.app.Application; +import android.content.Context; import com.android.camera.SDCard; import com.android.camera.util.CameraUtil; import com.android.camera.util.UsageStatistics; public class CameraApp extends Application { + private static Application mApp = null; private static long mMaxSystemMemory; public static boolean mIsLowMemoryDevice = false; private static final long LOW_MEMORY_DEVICE_THRESHOLD = 2L*1024*1024*1024; @@ -32,6 +34,7 @@ public class CameraApp extends Application { @Override public void onCreate() { super.onCreate(); + mApp = this; ActivityManager actManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); actManager.getMemoryInfo(memInfo); @@ -44,4 +47,8 @@ public class CameraApp extends Application { CameraUtil.initialize(this); SDCard.initialize(this); } + + public static Context getContext() { + return mApp.getApplicationContext(); + } } -- cgit v1.2.3