Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6b5ba56 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

Camera2: Remove hidden parts of public CameraDevice

- Remove everything @hide in CameraDevice
- Move bits that are still needed into CameraDeviceImpl

Change-Id: Ie22059a0eb5c4238142a8a1e8dbcf1a422e845aa
parent 7875a886
Loading
Loading
Loading
Loading
+0 −207
Original line number Diff line number Diff line
@@ -129,15 +129,6 @@ public abstract class CameraDevice implements AutoCloseable {
     */
    public abstract String getId();

    /**
     * <p>Set up a new output set of Surfaces for the camera device.</p>
     *
     * @deprecated Use {@link #createCaptureSession} instead
     * @hide
     */
    @Deprecated
    public abstract void configureOutputs(List<Surface> outputs) throws CameraAccessException;

    /**
     * <p>Create a new camera capture session by providing the target output set of Surfaces to the
     * camera device.</p>
@@ -275,68 +266,6 @@ public abstract class CameraDevice implements AutoCloseable {
    public abstract CaptureRequest.Builder createCaptureRequest(int templateType)
            throws CameraAccessException;

    /**
     * <p>Submit a request for an image to be captured by this CameraDevice.</p>
     *
     * @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<CaptureRequest> 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;

    /**
     * <p>Request endlessly repeating capture of a sequence of images by this
     * CameraDevice.</p>
     *
     * @deprecated Use {@link CameraCaptureSession#setRepeatingBurst} instead
     * @hide
     */
    @Deprecated
    public abstract int setRepeatingBurst(List<CaptureRequest> requests, CaptureListener listener,
            Handler handler) throws CameraAccessException;

    /**
     * <p>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.
     *
@@ -355,96 +284,6 @@ public abstract class CameraDevice implements AutoCloseable {
    @Override
    public abstract void close();

    /**
     * <p>A listener for tracking the progress of a {@link CaptureRequest}
     * submitted to the camera device.</p>
     *
     * @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.
@@ -541,40 +380,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}.
@@ -590,18 +395,6 @@ public abstract class CameraDevice implements AutoCloseable {
            // Default empty implementation
        }

        /**
         * 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.
+15 −15
Original line number Diff line number Diff line
@@ -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.
     *
     * <p>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 {
     * <p>When a capture sequence finishes, update the pending checked sequences set.</p>
     */
    @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,21 +386,21 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
            return localListener;
        }

        InvokeDispatcher<CameraDevice.CaptureListener> localSink =
        InvokeDispatcher<CameraDeviceImpl.CaptureListener> localSink =
                new InvokeDispatcher<>(localListener);

        InvokeDispatcher<CaptureListener> userListenerSink =
                new InvokeDispatcher<>(listener);
        HandlerDispatcher<CaptureListener> handlerPassthrough =
                new HandlerDispatcher<>(userListenerSink, handler);
        DuckTypingDispatcher<CameraDevice.CaptureListener, CaptureListener> duckToSession
        DuckTypingDispatcher<CameraDeviceImpl.CaptureListener, CaptureListener> duckToSession
                = new DuckTypingDispatcher<>(handlerPassthrough, CaptureListener.class);
        ArgumentReplacingDispatcher<CameraDevice.CaptureListener, CameraCaptureSessionImpl>
        ArgumentReplacingDispatcher<CameraDeviceImpl.CaptureListener, CameraCaptureSessionImpl>
                replaceDeviceWithSession = new ArgumentReplacingDispatcher<>(duckToSession,
                        /*argumentIndex*/0, this);

        BroadcastDispatcher<CameraDevice.CaptureListener> broadcaster =
                new BroadcastDispatcher<CameraDevice.CaptureListener>(
        BroadcastDispatcher<CameraDeviceImpl.CaptureListener> broadcaster =
                new BroadcastDispatcher<CameraDeviceImpl.CaptureListener>(
                    replaceDeviceWithSession,
                    localSink);

@@ -418,10 +418,10 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession {
     * </ul>
     * </p>
     * */
    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;

+147 −20
Original line number Diff line number Diff line
@@ -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<Surface> 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<CaptureRequest> 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<CaptureRequest> requestList = new ArrayList<CaptureRequest>();
@@ -619,7 +622,6 @@ public class CameraDeviceImpl extends android.hardware.camera2.CameraDevice {
        return submitCaptureRequest(requestList, listener, handler, /*streaming*/true);
    }

    @Override
    public int setRepeatingBurst(List<CaptureRequest> 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 {
        }
    }

    /**
     * <p>A listener for tracking the progress of a {@link CaptureRequest}
     * submitted to the camera device.</p>
     *
     */
    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;
+8 −8
Original line number Diff line number Diff line
@@ -36,13 +36,13 @@ public class ListenerProxies {

    // TODO: replace with codegen

    public static class DeviceStateListenerProxy extends CameraDevice.StateListener {
        private final MethodNameInvoker<CameraDevice.StateListener> mProxy;
    public static class DeviceStateListenerProxy extends CameraDeviceImpl.StateListenerKK {
        private final MethodNameInvoker<CameraDeviceImpl.StateListenerKK> mProxy;

        public DeviceStateListenerProxy(
                Dispatchable<CameraDevice.StateListener> dispatchTarget) {
                Dispatchable<CameraDeviceImpl.StateListenerKK> 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<CameraDevice.CaptureListener> mProxy;
    public static class DeviceCaptureListenerProxy extends CameraDeviceImpl.CaptureListener {
        private final MethodNameInvoker<CameraDeviceImpl.CaptureListener> mProxy;

        public DeviceCaptureListenerProxy(
                Dispatchable<CameraDevice.CaptureListener> dispatchTarget) {
                Dispatchable<CameraDeviceImpl.CaptureListener> dispatchTarget) {
            dispatchTarget = checkNotNull(dispatchTarget, "dispatchTarget must not be null");
            mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDevice.CaptureListener.class);
            mProxy = new MethodNameInvoker<>(dispatchTarget, CameraDeviceImpl.CaptureListener.class);
        }

        @Override