summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcodeworkx <daniel.hillenbrand@codeworkx.de>2017-01-28 14:56:35 +0100
committerArne Coucheron <arco68@gmail.com>2018-01-26 01:09:27 +0100
commiteaad57426c2bb2a0e61a65b24ba1c7feeccf3255 (patch)
tree86c3927ae07dc0011d6adf8ec80e959250c27f80
parent518a24e549fd845443ea1946afa8abdbd45f4870 (diff)
downloadandroid_packages_apps_Snap-eaad57426c2bb2a0e61a65b24ba1c7feeccf3255.zip
android_packages_apps_Snap-eaad57426c2bb2a0e61a65b24ba1c7feeccf3255.tar.gz
android_packages_apps_Snap-eaad57426c2bb2a0e61a65b24ba1c7feeccf3255.tar.bz2
Snap: detect and use Camera2 if available
Also add overlay option to enable support for Camera2 to retain current behaviour. Change-Id: I20939e33f4bb687e4abea11bbcdb9bf246b156e4
-rw-r--r--res/values/config.xml3
-rw-r--r--src/com/android/camera/CameraActivity.java20
-rw-r--r--src/com/android/camera/util/CameraUtil.java26
-rw-r--r--src/com/android/camera/util/PersistUtil.java6
4 files changed, 45 insertions, 10 deletions
diff --git a/res/values/config.xml b/res/values/config.xml
index d5a9dcb..a02c6b7 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -28,6 +28,9 @@
of the fullscreen pano preview. -->
<bool name="enable_warped_pano_preview">true</bool>
+ <!-- Enable support for camera api v2 -->
+ <bool name="support_camera_api_v2">false</bool>
+
<!-- Opens back camera using openLegacy() and forces api v1 -->
<bool name="back_camera_open_legacy">true</bool>
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index 110df5e..3c89fda 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -192,11 +192,15 @@ public class CameraActivity extends Activity
private static boolean PIE_MENU_ENABLED = false;
private boolean mDeveloperMenuEnabled = false;
+ private boolean mCamera2supported = false;
+ private boolean mCamera2enabled = false;
+
/** This data adapter is used by FilmStripView. */
private LocalDataAdapter mDataAdapter;
/** This data adapter represents the real local camera data. */
private LocalDataAdapter mWrappedDataAdapter;
+ private Context mContext;
private PanoramaStitchingManager mPanoramaManager;
private PlaceholderManager mPlaceholderManager;
private int mCurrentModuleIndex;
@@ -1489,6 +1493,9 @@ public class CameraActivity extends Activity
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
+
+ mContext = getApplicationContext();
+
// Check if this is in the secure camera mode.
Intent intent = getIntent();
String action = intent.getAction();
@@ -1566,8 +1573,14 @@ public class CameraActivity extends Activity
}
}
- boolean cam2on = PersistUtil.getCamera2Mode();
- if (cam2on && (moduleIndex == ModuleSwitcher.PHOTO_MODULE_INDEX ||
+ // Check if the device supports Camera API 2
+ mCamera2supported = CameraUtil.isCamera2Supported(mContext);
+ Log.d(TAG, "Camera API 2 supported: " + mCamera2supported);
+
+ mCamera2enabled = mCamera2supported && mContext.getResources().getBoolean(R.bool.support_camera_api_v2);
+ Log.d(TAG, "Camera API 2 enabled: " + mCamera2enabled);
+
+ if (mCamera2enabled && (moduleIndex == ModuleSwitcher.PHOTO_MODULE_INDEX ||
moduleIndex == ModuleSwitcher.VIDEO_MODULE_INDEX))
moduleIndex = ModuleSwitcher.CAPTURE_MODULE_INDEX;
@@ -2134,9 +2147,8 @@ public class CameraActivity extends Activity
@Override
public void onModuleSelected(int moduleIndex) {
- boolean cam2on = PersistUtil.getCamera2Mode();
mForceReleaseCamera = moduleIndex == ModuleSwitcher.CAPTURE_MODULE_INDEX ||
- (cam2on && moduleIndex == ModuleSwitcher.PHOTO_MODULE_INDEX);
+ (mCamera2enabled && moduleIndex == ModuleSwitcher.PHOTO_MODULE_INDEX);
if (mForceReleaseCamera) {
moduleIndex = ModuleSwitcher.CAPTURE_MODULE_INDEX;
}
diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java
index a6bb45e..8f40c11 100644
--- a/src/com/android/camera/util/CameraUtil.java
+++ b/src/com/android/camera/util/CameraUtil.java
@@ -36,6 +36,8 @@ import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
+import android.hardware.camera2.CameraAccessException;
+import android.hardware.camera2.CameraCharacteristics;
import android.location.Location;
import android.media.MediaRecorder;
import android.net.Uri;
@@ -404,6 +406,30 @@ public class CameraUtil {
}
}
+ public static boolean isCamera2Supported(Context context) {
+ android.hardware.camera2.CameraManager manager = (android.hardware.camera2.CameraManager)context.getSystemService(Context.CAMERA_SERVICE);
+
+ try {
+ CameraCharacteristics characteristics = manager.getCameraCharacteristics(manager.getCameraIdList()[0]);
+ int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
+
+ switch (deviceLevel) {
+ case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
+ return true;
+ case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
+ return true;
+ case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3:
+ return true;
+ default:
+ return false;
+ }
+ } catch(CameraAccessException | NumberFormatException e) {
+ Log.e(TAG, "exception trying to get camera characteristics");
+ }
+
+ return false;
+ }
+
public static CameraManager.CameraProxy openCamera(
Activity activity, final int cameraId,
Handler handler, final CameraManager.CameraOpenErrorCallback cb) {
diff --git a/src/com/android/camera/util/PersistUtil.java b/src/com/android/camera/util/PersistUtil.java
index 968e51c..c0f4455 100644
--- a/src/com/android/camera/util/PersistUtil.java
+++ b/src/com/android/camera/util/PersistUtil.java
@@ -50,8 +50,6 @@ public class PersistUtil {
SystemProperties.getInt("persist.vendor.camera.longshot.shotnum", 50);
private static final String PERSIST_CAMERA_PREVIEW_SIZE =
SystemProperties.get("persist.vendor.camera.preview.size", "");
- private static final boolean PERSIST_CAMERA_CAMERA2 =
- SystemProperties.getBoolean("persist.vendor.camera.camera2", false);
private static final boolean PERSIST_CAMERA_ZSL =
SystemProperties.getBoolean("persist.vendor.camera.zsl.disabled", false);
private static final int PERSIST_CAMERA2_DEBUG =
@@ -150,10 +148,6 @@ public class PersistUtil {
return result;
}
- public static boolean getCamera2Mode() {
- return PERSIST_CAMERA_CAMERA2;
- }
-
public static boolean getCameraZSLDisabled() {
return PERSIST_CAMERA_ZSL;
}