summaryrefslogtreecommitdiffstats
path: root/core/java/android/hardware/Camera.java
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2014-06-20 11:22:11 -0700
committerIgor Murashkin <iam@google.com>2014-06-20 11:26:39 -0700
commita1d662716b3da384dfe3a758f079e0cbd089784a (patch)
treee1647dd9fbd0104be0ec6c9b433b003a79328d17 /core/java/android/hardware/Camera.java
parent9285d1bf9c57e5f1da8f8d8ef7a6a38b2f0e4ec3 (diff)
downloadframeworks_base-a1d662716b3da384dfe3a758f079e0cbd089784a.zip
frameworks_base-a1d662716b3da384dfe3a758f079e0cbd089784a.tar.gz
frameworks_base-a1d662716b3da384dfe3a758f079e0cbd089784a.tar.bz2
camera: Get detailed error reporting from api1 Camera if open fails
* Also maps camera2 open errors the same for shim/nonshim paths Change-Id: I08d9d1e30e72025c41bd54b702d7ae95b32257be
Diffstat (limited to 'core/java/android/hardware/Camera.java')
-rw-r--r--core/java/android/hardware/Camera.java84
1 files changed, 42 insertions, 42 deletions
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index 44fc3b6..cc8503b 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -167,7 +167,7 @@ public class Camera {
private boolean mOneShot;
private boolean mWithBuffer;
private boolean mFaceDetectionRunning = false;
- private Object mAutoFocusCallbackLock = new Object();
+ private final Object mAutoFocusCallbackLock = new Object();
private static final int NO_ERROR = 0;
private static final int EACCESS = -13;
@@ -202,14 +202,14 @@ public class Camera {
/**
* A constant meaning the normal camera connect/open will be used.
- * @hide
*/
- public static final int CAMERA_HAL_API_VERSION_NORMAL_OPEN = -2;
+ private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2;
/**
* Used to indicate HAL version un-specified.
*/
private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
+
/**
* Hardware face detection. It does not use much CPU.
*/
@@ -376,18 +376,25 @@ public class Camera {
*
* @param cameraId The hardware camera to access, between 0 and
* {@link #getNumberOfCameras()}-1.
- * @param halVersion The HAL API version this camera device to be opened as. When
- * it is {@value #CAMERA_HAL_API_VERSION_NORMAL_OPEN}, the methods will be equivalent
- * to {@link #open}, but more detailed error information will be returned to managed code.
+ * @param halVersion The HAL API version this camera device to be opened as.
* @return a new Camera object, connected, locked and ready for use.
+ *
+ * @throws IllegalArgumentException if the {@code halVersion} is invalid
+ *
* @throws RuntimeException if opening the camera fails (for example, if the
* camera is in use by another process or device policy manager has disabled
* the camera).
+ *
* @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)
+ * @see #CAMERA_HAL_API_VERSION_1_0
*
* @hide
*/
public static Camera openLegacy(int cameraId, int halVersion) {
+ if (halVersion < CAMERA_HAL_API_VERSION_1_0) {
+ throw new IllegalArgumentException("Invalid HAL version " + halVersion);
+ }
+
return new Camera(cameraId, halVersion);
}
@@ -399,7 +406,7 @@ public class Camera {
* @param halVersion The HAL API version this camera device to be opened as.
*/
private Camera(int cameraId, int halVersion) {
- int err = cameraInit(cameraId, halVersion);
+ int err = cameraInitVersion(cameraId, halVersion);
if (checkInitErrors(err)) {
switch(err) {
case EACCESS:
@@ -428,13 +435,7 @@ public class Camera {
}
}
- private int cameraInit(int cameraId, int halVersion) {
- // This function should be only called by Camera(int cameraId, int halVersion).
- if (halVersion < CAMERA_HAL_API_VERSION_1_0 &&
- halVersion != CAMERA_HAL_API_VERSION_NORMAL_OPEN) {
- throw new IllegalArgumentException("Invalid HAL version " + halVersion);
- }
-
+ private int cameraInitVersion(int cameraId, int halVersion) {
mShutterCallback = null;
mRawImageCallback = null;
mJpegCallback = null;
@@ -457,8 +458,31 @@ public class Camera {
return native_setup(new WeakReference<Camera>(this), cameraId, halVersion, packageName);
}
+ private int cameraInitNormal(int cameraId) {
+ return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT);
+ }
+
+ /**
+ * Connect to the camera service using #connectLegacy
+ *
+ * <p>
+ * This acts the same as normal except that it will return
+ * the detailed error code if open fails instead of
+ * converting everything into {@code NO_INIT}.</p>
+ *
+ * <p>Intended to use by the camera2 shim only, do <i>not</i> use this for other code.</p>
+ *
+ * @return a detailed errno error code, or {@code NO_ERROR} on success
+ *
+ * @hide
+ */
+ public int cameraInitUnspecified(int cameraId) {
+ return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_UNSPECIFIED);
+ }
+
+ /** used by Camera#open, Camera#open(int) */
Camera(int cameraId) {
- int err = cameraInit(cameraId);
+ int err = cameraInitNormal(cameraId);
if (checkInitErrors(err)) {
switch(err) {
case EACCESS:
@@ -472,32 +496,6 @@ public class Camera {
}
}
- /**
- * @hide
- */
- public int cameraInit(int cameraId) {
- mShutterCallback = null;
- mRawImageCallback = null;
- mJpegCallback = null;
- mPreviewCallback = null;
- mPostviewCallback = null;
- mUsingPreviewAllocation = false;
- mZoomListener = null;
-
- Looper looper;
- if ((looper = Looper.myLooper()) != null) {
- mEventHandler = new EventHandler(this, looper);
- } else if ((looper = Looper.getMainLooper()) != null) {
- mEventHandler = new EventHandler(this, looper);
- } else {
- mEventHandler = null;
- }
-
- String packageName = ActivityThread.currentPackageName();
-
- return native_setup(new WeakReference<Camera>(this), cameraId,
- CAMERA_HAL_API_VERSION_UNSPECIFIED, packageName);
- }
/**
* @hide
@@ -519,6 +517,7 @@ public class Camera {
Camera() {
}
+ @Override
protected void finalize() {
release();
}
@@ -1056,7 +1055,7 @@ public class Camera {
private class EventHandler extends Handler
{
- private Camera mCamera;
+ private final Camera mCamera;
public EventHandler(Camera c, Looper looper) {
super(looper);
@@ -2337,6 +2336,7 @@ public class Camera {
* @hide
* @deprecated
*/
+ @Deprecated
public void dump() {
Log.e(TAG, "dump: size=" + mMap.size());
for (String k : mMap.keySet()) {