From a6b5ba56036f19bdd816ef03ad37beccf0150050 Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Wed, 2 Jul 2014 16:30:53 -0700 Subject: [PATCH] Camera2: Remove hidden parts of public CameraDevice - Remove everything @hide in CameraDevice - Move bits that are still needed into CameraDeviceImpl Change-Id: Ie22059a0eb5c4238142a8a1e8dbcf1a422e845aa --- .../android/hardware/camera2/CameraDevice.java | 207 --------------------- .../camera2/impl/CameraCaptureSessionImpl.java | 30 +-- .../hardware/camera2/impl/CameraDeviceImpl.java | 167 +++++++++++++++-- .../hardware/camera2/impl/ListenerProxies.java | 16 +- 4 files changed, 170 insertions(+), 250 deletions(-) diff --git a/core/java/android/hardware/camera2/CameraDevice.java b/core/java/android/hardware/camera2/CameraDevice.java index c4615119dc3b..6a9d56544184 100644 --- a/core/java/android/hardware/camera2/CameraDevice.java +++ b/core/java/android/hardware/camera2/CameraDevice.java @@ -130,15 +130,6 @@ public abstract class CameraDevice implements AutoCloseable { public abstract String getId(); /** - *

Set up a new output set of Surfaces for the camera device.

- * - * @deprecated Use {@link #createCaptureSession} instead - * @hide - */ - @Deprecated - public abstract void configureOutputs(List outputs) throws CameraAccessException; - - /** *

Create a new camera capture session by providing the target output set of Surfaces to the * camera device.

* @@ -276,68 +267,6 @@ public abstract class CameraDevice implements AutoCloseable { throws CameraAccessException; /** - *

Submit a request for an image to be captured by this CameraDevice.

- * - * @deprecated Use {@link CameraCaptureSession#capture} instead - * @hide - */ - @Deprecated - public abstract int capture(CaptureRequest request, CaptureListener listener, Handler handler) - throws CameraAccessException; - - /** - * Submit a list of requests to be captured in sequence as a burst. - * - * @deprecated Use {@link CameraCaptureSession#captureBurst} instead - * @hide - */ - @Deprecated - public abstract int captureBurst(List requests, CaptureListener listener, - Handler handler) throws CameraAccessException; - - /** - * Request endlessly repeating capture of images by this CameraDevice. - * - * @deprecated Use {@link CameraCaptureSession#setRepeatingRequest} instead - * @hide - */ - @Deprecated - public abstract int setRepeatingRequest(CaptureRequest request, CaptureListener listener, - Handler handler) throws CameraAccessException; - - /** - *

Request endlessly repeating capture of a sequence of images by this - * CameraDevice.

- * - * @deprecated Use {@link CameraCaptureSession#setRepeatingBurst} instead - * @hide - */ - @Deprecated - public abstract int setRepeatingBurst(List requests, CaptureListener listener, - Handler handler) throws CameraAccessException; - - /** - *

Cancel any ongoing repeating capture set by either - * {@link #setRepeatingRequest setRepeatingRequest} or - * {@link #setRepeatingBurst}. - * - * @deprecated Use {@link CameraCaptureSession#stopRepeating} instead - * @hide - */ - @Deprecated - public abstract void stopRepeating() throws CameraAccessException; - - /** - * Flush all captures currently pending and in-progress as fast as - * possible. - * - * @deprecated Use {@link CameraCaptureSession#abortCaptures} instead - * @hide - */ - @Deprecated - public abstract void flush() throws CameraAccessException; - - /** * Close the connection to this camera device as quickly as possible. * *

Immediately after this call, all calls to the camera device or active session interface @@ -356,96 +285,6 @@ public abstract class CameraDevice implements AutoCloseable { public abstract void close(); /** - *

A listener for tracking the progress of a {@link CaptureRequest} - * submitted to the camera device.

- * - * @deprecated Use {@link CameraCaptureSession.CaptureListener} instead - * @hide - */ - @Deprecated - public static abstract class CaptureListener { - - /** - * This constant is used to indicate that no images were captured for - * the request. - * - * @hide - */ - public static final int NO_FRAMES_CAPTURED = -1; - - /** - * This method is called when the camera device has started capturing - * the output image for the request, at the beginning of image exposure. - * - * @see android.media.MediaActionSound - */ - public void onCaptureStarted(CameraDevice camera, - CaptureRequest request, long timestamp) { - // default empty implementation - } - - /** - * This method is called when some results from an image capture are - * available. - * - * @hide - */ - public void onCapturePartial(CameraDevice camera, - CaptureRequest request, CaptureResult result) { - // default empty implementation - } - - /** - * This method is called when an image capture makes partial forward progress; some - * (but not all) results from an image capture are available. - * - */ - public void onCaptureProgressed(CameraDevice camera, - CaptureRequest request, CaptureResult partialResult) { - // default empty implementation - } - - /** - * This method is called when an image capture has fully completed and all the - * result metadata is available. - */ - public void onCaptureCompleted(CameraDevice camera, - CaptureRequest request, TotalCaptureResult result) { - // default empty implementation - } - - /** - * This method is called instead of {@link #onCaptureCompleted} when the - * camera device failed to produce a {@link CaptureResult} for the - * request. - */ - public void onCaptureFailed(CameraDevice camera, - CaptureRequest request, CaptureFailure failure) { - // default empty implementation - } - - /** - * This method is called independently of the others in CaptureListener, - * when a capture sequence finishes and all {@link CaptureResult} - * or {@link CaptureFailure} for it have been returned via this listener. - */ - public void onCaptureSequenceCompleted(CameraDevice camera, - int sequenceId, long frameNumber) { - // default empty implementation - } - - /** - * This method is called independently of the others in CaptureListener, - * when a capture sequence aborts before any {@link CaptureResult} - * or {@link CaptureFailure} for it have been returned via this listener. - */ - public void onCaptureSequenceAborted(CameraDevice camera, - int sequenceId) { - // default empty implementation - } - } - - /** * A listener for notifications about the state of a camera * device. * @@ -542,40 +381,6 @@ public abstract class CameraDevice implements AutoCloseable { public abstract void onOpened(CameraDevice camera); // Must implement /** - * The method called when a camera device has no outputs configured. - * - * @deprecated Use {@link #onOpened} instead. - * @hide - */ - @Deprecated - public void onUnconfigured(CameraDevice camera) { - // Default empty implementation - } - - /** - * The method called when a camera device begins processing - * {@link CaptureRequest capture requests}. - * - * @deprecated Use {@link CameraCaptureSession.StateListener#onActive} instead. - * @hide - */ - @Deprecated - public void onActive(CameraDevice camera) { - // Default empty implementation - } - - /** - * The method called when a camera device is busy. - * - * @deprecated Use {@link CameraCaptureSession.StateListener#onConfigured} instead. - * @hide - */ - @Deprecated - public void onBusy(CameraDevice camera) { - // Default empty implementation - } - - /** * The method called when a camera device has been closed with * {@link CameraDevice#close}. * @@ -591,18 +396,6 @@ public abstract class CameraDevice implements AutoCloseable { } /** - * The method called when a camera device has finished processing all - * submitted capture requests and has reached an idle state. - * - * @deprecated Use {@link CameraCaptureSession.StateListener#onReady} instead. - * @hide - */ - @Deprecated - public void onIdle(CameraDevice camera) { - // Default empty implementation - } - - /** * The method called when a camera device is no longer available for * use. * diff --git a/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java b/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java index 690093b3b057..dffff9a57167 100644 --- a/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java +++ b/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java @@ -103,7 +103,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { * Use the same handler as the device's StateListener for all the internal coming events * * This ensures total ordering between CameraDevice.StateListener and - * CameraDevice.CaptureListener events. + * CameraDeviceImpl.CaptureListener events. */ mSequenceDrainer = new TaskDrainer<>(mDeviceHandler, new SequenceDrainListener(), /*name*/"seq"); @@ -347,7 +347,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { /** * Forward callbacks from - * CameraDevice.CaptureListener to the CameraCaptureSession.CaptureListener. + * CameraDeviceImpl.CaptureListener to the CameraCaptureSession.CaptureListener. * *

In particular, all calls are automatically split to go both to our own * internal listener, and to the user-specified listener (by transparently posting @@ -356,9 +356,9 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { *

When a capture sequence finishes, update the pending checked sequences set.

*/ @SuppressWarnings("deprecation") - private CameraDevice.CaptureListener createCaptureListenerProxy( + private CameraDeviceImpl.CaptureListener createCaptureListenerProxy( Handler handler, CaptureListener listener) { - CameraDevice.CaptureListener localListener = new CameraDevice.CaptureListener() { + CameraDeviceImpl.CaptureListener localListener = new CameraDeviceImpl.CaptureListener() { @Override public void onCaptureSequenceCompleted(CameraDevice camera, int sequenceId, long frameNumber) { @@ -386,23 +386,23 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { return localListener; } - InvokeDispatcher localSink = + InvokeDispatcher localSink = new InvokeDispatcher<>(localListener); InvokeDispatcher userListenerSink = new InvokeDispatcher<>(listener); HandlerDispatcher handlerPassthrough = new HandlerDispatcher<>(userListenerSink, handler); - DuckTypingDispatcher duckToSession + DuckTypingDispatcher duckToSession = new DuckTypingDispatcher<>(handlerPassthrough, CaptureListener.class); - ArgumentReplacingDispatcher - replaceDeviceWithSession = new ArgumentReplacingDispatcher<>(duckToSession, - /*argumentIndex*/0, this); + ArgumentReplacingDispatcher + replaceDeviceWithSession = new ArgumentReplacingDispatcher<>(duckToSession, + /*argumentIndex*/0, this); - BroadcastDispatcher broadcaster = - new BroadcastDispatcher( - replaceDeviceWithSession, - localSink); + BroadcastDispatcher broadcaster = + new BroadcastDispatcher( + replaceDeviceWithSession, + localSink); return new ListenerProxies.DeviceCaptureListenerProxy(broadcaster); } @@ -418,10 +418,10 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { * *

* */ - CameraDevice.StateListener getDeviceStateListener() { + CameraDeviceImpl.StateListenerKK getDeviceStateListener() { final CameraCaptureSession session = this; - return new CameraDevice.StateListener() { + return new CameraDeviceImpl.StateListenerKK() { private boolean mBusy = false; private boolean mActive = false; diff --git a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java index 3a94e02fc1c1..63e96440c217 100644 --- a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java +++ b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java @@ -21,8 +21,10 @@ import static android.hardware.camera2.CameraAccessException.CAMERA_IN_USE; import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraCaptureSession; import android.hardware.camera2.CameraCharacteristics; +import android.hardware.camera2.CameraDevice; import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.CaptureResult; +import android.hardware.camera2.CaptureFailure; import android.hardware.camera2.ICameraDeviceCallbacks; import android.hardware.camera2.ICameraDeviceUser; import android.hardware.camera2.TotalCaptureResult; @@ -47,7 +49,7 @@ import java.util.TreeSet; /** * HAL2.1+ implementation of CameraDevice. Use CameraManager#open to instantiate */ -public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { +public class CameraDeviceImpl extends CameraDevice { private final String TAG; private final boolean DEBUG; @@ -62,7 +64,7 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { private final CameraDeviceCallbacks mCallbacks = new CameraDeviceCallbacks(); private final StateListener mDeviceListener; - private volatile StateListener mSessionStateListener; + private volatile StateListenerKK mSessionStateListener; private final Handler mDeviceHandler; private volatile boolean mClosing = false; @@ -103,7 +105,7 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { private final Runnable mCallOnOpened = new Runnable() { @Override public void run() { - StateListener sessionListener = null; + StateListenerKK sessionListener = null; synchronized(mInterfaceLock) { if (mRemoteDevice == null) return; // Camera already closed @@ -119,7 +121,7 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { private final Runnable mCallOnUnconfigured = new Runnable() { @Override public void run() { - StateListener sessionListener = null; + StateListenerKK sessionListener = null; synchronized(mInterfaceLock) { if (mRemoteDevice == null) return; // Camera already closed @@ -128,14 +130,13 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { if (sessionListener != null) { sessionListener.onUnconfigured(CameraDeviceImpl.this); } - mDeviceListener.onUnconfigured(CameraDeviceImpl.this); } }; private final Runnable mCallOnActive = new Runnable() { @Override public void run() { - StateListener sessionListener = null; + StateListenerKK sessionListener = null; synchronized(mInterfaceLock) { if (mRemoteDevice == null) return; // Camera already closed @@ -144,14 +145,13 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { if (sessionListener != null) { sessionListener.onActive(CameraDeviceImpl.this); } - mDeviceListener.onActive(CameraDeviceImpl.this); } }; private final Runnable mCallOnBusy = new Runnable() { @Override public void run() { - StateListener sessionListener = null; + StateListenerKK sessionListener = null; synchronized(mInterfaceLock) { if (mRemoteDevice == null) return; // Camera already closed @@ -160,7 +160,6 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { if (sessionListener != null) { sessionListener.onBusy(CameraDeviceImpl.this); } - mDeviceListener.onBusy(CameraDeviceImpl.this); } }; @@ -172,7 +171,7 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { if (mClosedOnce) { throw new AssertionError("Don't post #onClosed more than once"); } - StateListener sessionListener = null; + StateListenerKK sessionListener = null; synchronized(mInterfaceLock) { sessionListener = mSessionStateListener; } @@ -187,7 +186,7 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { private final Runnable mCallOnIdle = new Runnable() { @Override public void run() { - StateListener sessionListener = null; + StateListenerKK sessionListener = null; synchronized(mInterfaceLock) { if (mRemoteDevice == null) return; // Camera already closed @@ -196,14 +195,13 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { if (sessionListener != null) { sessionListener.onIdle(CameraDeviceImpl.this); } - mDeviceListener.onIdle(CameraDeviceImpl.this); } }; private final Runnable mCallOnDisconnected = new Runnable() { @Override public void run() { - StateListener sessionListener = null; + StateListenerKK sessionListener = null; synchronized(mInterfaceLock) { if (mRemoteDevice == null) return; // Camera already closed @@ -313,7 +311,6 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { return mCameraId; } - @Override public void configureOutputs(List outputs) throws CameraAccessException { // Treat a null input the same an empty list if (outputs == null) { @@ -425,6 +422,15 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { } } + /** + * For use by backwards-compatibility code only. + */ + public void setSessionListener(StateListenerKK sessionListener) { + synchronized(mInterfaceLock) { + mSessionStateListener = sessionListener; + } + } + @Override public CaptureRequest.Builder createCaptureRequest(int templateType) throws CameraAccessException { @@ -449,7 +455,6 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { } } - @Override public int capture(CaptureRequest request, CaptureListener listener, Handler handler) throws CameraAccessException { if (DEBUG) { @@ -460,7 +465,6 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { return submitCaptureRequest(requestList, listener, handler, /*streaming*/false); } - @Override public int captureBurst(List requests, CaptureListener listener, Handler handler) throws CameraAccessException { if (requests == null || requests.isEmpty()) { @@ -611,7 +615,6 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { } } - @Override public int setRepeatingRequest(CaptureRequest request, CaptureListener listener, Handler handler) throws CameraAccessException { List requestList = new ArrayList(); @@ -619,7 +622,6 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { return submitCaptureRequest(requestList, listener, handler, /*streaming*/true); } - @Override public int setRepeatingBurst(List requests, CaptureListener listener, Handler handler) throws CameraAccessException { if (requests == null || requests.isEmpty()) { @@ -628,7 +630,6 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { return submitCaptureRequest(requests, listener, handler, /*streaming*/true); } - @Override public void stopRepeating() throws CameraAccessException { synchronized(mInterfaceLock) { @@ -679,7 +680,6 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { } } - @Override public void flush() throws CameraAccessException { synchronized(mInterfaceLock) { checkIfCameraClosedOrInError(); @@ -737,6 +737,133 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice { } } + /** + *

A listener for tracking the progress of a {@link CaptureRequest} + * submitted to the camera device.

+ * + */ + public static abstract class CaptureListener { + + /** + * This constant is used to indicate that no images were captured for + * the request. + * + * @hide + */ + public static final int NO_FRAMES_CAPTURED = -1; + + /** + * This method is called when the camera device has started capturing + * the output image for the request, at the beginning of image exposure. + * + * @see android.media.MediaActionSound + */ + public void onCaptureStarted(CameraDevice camera, + CaptureRequest request, long timestamp) { + // default empty implementation + } + + /** + * This method is called when some results from an image capture are + * available. + * + * @hide + */ + public void onCapturePartial(CameraDevice camera, + CaptureRequest request, CaptureResult result) { + // default empty implementation + } + + /** + * This method is called when an image capture makes partial forward progress; some + * (but not all) results from an image capture are available. + * + */ + public void onCaptureProgressed(CameraDevice camera, + CaptureRequest request, CaptureResult partialResult) { + // default empty implementation + } + + /** + * This method is called when an image capture has fully completed and all the + * result metadata is available. + */ + public void onCaptureCompleted(CameraDevice camera, + CaptureRequest request, TotalCaptureResult result) { + // default empty implementation + } + + /** + * This method is called instead of {@link #onCaptureCompleted} when the + * camera device failed to produce a {@link CaptureResult} for the + * request. + */ + public void onCaptureFailed(CameraDevice camera, + CaptureRequest request, CaptureFailure failure) { + // default empty implementation + } + + /** + * This method is called independently of the others in CaptureListener, + * when a capture sequence finishes and all {@link CaptureResult} + * or {@link CaptureFailure} for it have been returned via this listener. + */ + public void onCaptureSequenceCompleted(CameraDevice camera, + int sequenceId, long frameNumber) { + // default empty implementation + } + + /** + * This method is called independently of the others in CaptureListener, + * when a capture sequence aborts before any {@link CaptureResult} + * or {@link CaptureFailure} for it have been returned via this listener. + */ + public void onCaptureSequenceAborted(CameraDevice camera, + int sequenceId) { + // default empty implementation + } + } + + /** + * A listener for notifications about the state of a camera device, adding in the callbacks that + * were part of the earlier KK API design, but now only used internally. + */ + public static abstract class StateListenerKK extends StateListener { + /** + * The method called when a camera device has no outputs configured. + * + */ + public void onUnconfigured(CameraDevice camera) { + // Default empty implementation + } + + /** + * The method called when a camera device begins processing + * {@link CaptureRequest capture requests}. + * + */ + public void onActive(CameraDevice camera) { + // Default empty implementation + } + + /** + * The method called when a camera device is busy. + * + */ + public void onBusy(CameraDevice camera) { + // Default empty implementation + } + + /** + * The method called when a camera device has finished processing all + * submitted capture requests and has reached an idle state. + * + */ + public void onIdle(CameraDevice camera) { + // Default empty implementation + } + } + static class CaptureListenerHolder { private final boolean mRepeating; diff --git a/core/java/android/hardware/camera2/impl/ListenerProxies.java b/core/java/android/hardware/camera2/impl/ListenerProxies.java index ab9a4d5c6292..f44f9ada5249 100644 --- a/core/java/android/hardware/camera2/impl/ListenerProxies.java +++ b/core/java/android/hardware/camera2/impl/ListenerProxies.java @@ -36,13 +36,13 @@ public class ListenerProxies { // TODO: replace with codegen - public static class DeviceStateListenerProxy extends CameraDevice.StateListener { - private final MethodNameInvoker mProxy; + public static class DeviceStateListenerProxy extends CameraDeviceImpl.StateListenerKK { + private final MethodNameInvoker mProxy; public DeviceStateListenerProxy( - Dispatchable dispatchTarget) { + Dispatchable dispatchTarget) { dispatchTarget = checkNotNull(dispatchTarget, "dispatchTarget must not be null"); - mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDevice.StateListener.class); + mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDeviceImpl.StateListenerKK.class); } @Override @@ -87,13 +87,13 @@ public class ListenerProxies { } @SuppressWarnings("deprecation") - public static class DeviceCaptureListenerProxy extends CameraDevice.CaptureListener { - private final MethodNameInvoker mProxy; + public static class DeviceCaptureListenerProxy extends CameraDeviceImpl.CaptureListener { + private final MethodNameInvoker mProxy; public DeviceCaptureListenerProxy( - Dispatchable dispatchTarget) { + Dispatchable dispatchTarget) { dispatchTarget = checkNotNull(dispatchTarget, "dispatchTarget must not be null"); - mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDevice.CaptureListener.class); + mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDeviceImpl.CaptureListener.class); } @Override -- 2.11.0