Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java

Issue 2354883002: Add new Camera2Enumerator.isSupported with Context parameter. (Closed)
Patch Set: Cleanup. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/examples/androidapp/res/values/strings.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java
diff --git a/webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java b/webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java
index c723b0da0b4fa947af68fd7b2e460d644d301ced..3ce85fee789d47a978bcfafcd814c0f83c81131d 100644
--- a/webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java
+++ b/webrtc/api/android/java/src/org/webrtc/Camera2Enumerator.java
@@ -104,10 +104,44 @@ public class Camera2Enumerator implements CameraEnumerator {
}
}
+ /**
+ * Checks if Android version is new enough to support camera2.
+ *
+ * This method will be removed soon. Use isSupported(Context).
+ */
+ @Deprecated
public static boolean isSupported() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}
+ /**
+ * Checks if API is supported and all cameras have better than legacy support.
+ */
+ public static boolean isSupported(Context context) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ return false;
+ }
+
+ CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
+ try {
+ String[] cameraIds = cameraManager.getCameraIdList();
+ for (String id : cameraIds) {
+ CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(id);
+ if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
+ == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
+ return false;
+ }
+ }
+ // 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);
+ return false;
+ }
+ return true;
+ }
+
static int getFpsUnitFactor(Range<Integer>[] fpsRanges) {
if (fpsRanges.length == 0) {
return 1000;
« no previous file with comments | « no previous file | webrtc/examples/androidapp/res/values/strings.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698