summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcodeworkx <codeworkx@cyanogenmod.org>2016-12-22 19:05:52 (GMT)
committerDaniel Hillenbrand <codeworkx@cyanogenmod.org>2016-12-23 14:26:13 (GMT)
commit2064b8549b36a5ceb76d205353173c23477430d3 (patch)
tree37ba578e5a84374cbee183f632e0e2e22b9efba4
parent1a7d451750e1bccc734baa7870c6858cc2a01218 (diff)
downloadandroid_packages_apps_Snap-cm-14.1-wip.zip
android_packages_apps_Snap-cm-14.1-wip.tar.gz
android_packages_apps_Snap-cm-14.1-wip.tar.bz2
Snap: make openLegacy an optioncm-14.1-wip
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
-rw-r--r--res/values/config.xml6
-rw-r--r--src/com/android/camera/AndroidCameraManagerImpl.java43
-rw-r--r--src/com/android/camera/app/CameraApp.java7
3 files changed, 45 insertions, 11 deletions
diff --git a/res/values/config.xml b/res/values/config.xml
index 2c47154..d856599 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -29,6 +29,12 @@
of the fullscreen pano preview. -->
<bool name="enable_warped_pano_preview">false</bool>
+ <!-- Opens back camera using openLegacy() and forces api v1 -->
+ <bool name="back_camera_open_legacy">true</bool>
+
+ <!-- Opens front camera using openLegacy() and forces api v1 -->
+ <bool name="front_camera_open_legacy">true</bool>
+
<!-- Set's parameter "lge-camera" for LGE devices. -->
<bool name="lge_camera">false</bool>
diff --git a/src/com/android/camera/AndroidCameraManagerImpl.java b/src/com/android/camera/AndroidCameraManagerImpl.java
index b151c19..74f8226 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 6261159..3c1381f 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();
+ }
}