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

Commit 25af2fc0 authored by Chien-Yu Chen's avatar Chien-Yu Chen Committed by Android (Google) Code Review
Browse files

Merge "CameraManager: add torch mode APIs for flashlight"

parents c0086ea9 c8c109b4
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -12616,6 +12616,8 @@ package android.hardware.camera2 {
    field public static final int CAMERA_DISABLED = 1; // 0x1
    field public static final int CAMERA_DISCONNECTED = 2; // 0x2
    field public static final int CAMERA_ERROR = 3; // 0x3
    field public static final int CAMERA_IN_USE = 4; // 0x4
    field public static final int MAX_CAMERAS_IN_USE = 5; // 0x5
  }
  public abstract class CameraCaptureSession implements java.lang.AutoCloseable {
@@ -12756,7 +12758,10 @@ package android.hardware.camera2 {
    method public java.lang.String[] getCameraIdList() throws android.hardware.camera2.CameraAccessException;
    method public void openCamera(java.lang.String, android.hardware.camera2.CameraDevice.StateCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public void registerAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback, android.os.Handler);
    method public void registerTorchCallback(android.hardware.camera2.CameraManager.TorchCallback, android.os.Handler);
    method public void setTorchMode(java.lang.String, boolean) throws android.hardware.camera2.CameraAccessException;
    method public void unregisterAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback);
    method public void unregisterTorchCallback(android.hardware.camera2.CameraManager.TorchCallback);
  }
  public static abstract class CameraManager.AvailabilityCallback {
@@ -12765,6 +12770,13 @@ package android.hardware.camera2 {
    method public void onCameraUnavailable(java.lang.String);
  }
  public static abstract class CameraManager.TorchCallback {
    ctor public CameraManager.TorchCallback();
    method public void onTorchModeAvailable(java.lang.String);
    method public void onTorchModeChanged(java.lang.String, boolean);
    method public void onTorchModeUnavailable(java.lang.String);
  }
  public abstract class CameraMetadata {
    method public java.util.List<TKey> getKeys();
    field public static final int COLOR_CORRECTION_ABERRATION_MODE_FAST = 1; // 0x1
+12 −0
Original line number Diff line number Diff line
@@ -12884,6 +12884,8 @@ package android.hardware.camera2 {
    field public static final int CAMERA_DISABLED = 1; // 0x1
    field public static final int CAMERA_DISCONNECTED = 2; // 0x2
    field public static final int CAMERA_ERROR = 3; // 0x3
    field public static final int CAMERA_IN_USE = 4; // 0x4
    field public static final int MAX_CAMERAS_IN_USE = 5; // 0x5
  }
  public abstract class CameraCaptureSession implements java.lang.AutoCloseable {
@@ -13024,7 +13026,10 @@ package android.hardware.camera2 {
    method public java.lang.String[] getCameraIdList() throws android.hardware.camera2.CameraAccessException;
    method public void openCamera(java.lang.String, android.hardware.camera2.CameraDevice.StateCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public void registerAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback, android.os.Handler);
    method public void registerTorchCallback(android.hardware.camera2.CameraManager.TorchCallback, android.os.Handler);
    method public void setTorchMode(java.lang.String, boolean) throws android.hardware.camera2.CameraAccessException;
    method public void unregisterAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback);
    method public void unregisterTorchCallback(android.hardware.camera2.CameraManager.TorchCallback);
  }
  public static abstract class CameraManager.AvailabilityCallback {
@@ -13033,6 +13038,13 @@ package android.hardware.camera2 {
    method public void onCameraUnavailable(java.lang.String);
  }
  public static abstract class CameraManager.TorchCallback {
    ctor public CameraManager.TorchCallback();
    method public void onTorchModeAvailable(java.lang.String);
    method public void onTorchModeChanged(java.lang.String, boolean);
    method public void onTorchModeUnavailable(java.lang.String);
  }
  public abstract class CameraMetadata {
    method public java.util.List<TKey> getKeys();
    field public static final int COLOR_CORRECTION_ABERRATION_MODE_FAST = 1; // 0x1
+4 −6
Original line number Diff line number Diff line
@@ -28,16 +28,14 @@ import android.util.AndroidException;
 */
public class CameraAccessException extends AndroidException {
    /**
     * The camera device is in use already
     * @hide
     * The camera device is in use already.
     */
    public static final int CAMERA_IN_USE = 4;

    /**
     * The system-wide limit for number of open cameras has been reached,
     * and more camera devices cannot be opened until previous instances are
     * closed.
     * @hide
     * The system-wide limit for number of open cameras or camera resources has
     * been reached, and more camera devices cannot be opened or torch mode
     * cannot be turned on until previous instances are closed.
     */
    public static final int MAX_CAMERAS_IN_USE = 5;

+144 −2
Original line number Diff line number Diff line
@@ -109,8 +109,11 @@ public final class CameraManager {
     * of the state of individual CameraManager instances.</p>
     *
     * @param callback the new callback to send camera availability notices to
     * @param handler The handler on which the callback should be invoked, or
     * {@code null} to use the current thread's {@link android.os.Looper looper}.
     * @param handler The handler on which the callback should be invoked, or {@code null} to use
     *             the current thread's {@link android.os.Looper looper}.
     *
     * @throws IllegalArgumentException if the handler is {@code null} but the current thread has
     *             no looper.
     */
    public void registerAvailabilityCallback(AvailabilityCallback callback, Handler handler) {
        if (handler == null) {
@@ -137,6 +140,42 @@ public final class CameraManager {
        CameraManagerGlobal.get().unregisterAvailabilityCallback(callback);
    }

    /**
     * Register a callback to be notified about torch mode status.
     *
     * <p>Registering the same callback again will replace the handler with the
     * new one provided.</p>
     *
     * <p>The first time a callback is registered, it is immediately called
     * with the torch mode status of all currently known camera devices.</p>
     *
     * <p>Since this callback will be registered with the camera service, remember to unregister it
     * once it is no longer needed; otherwise the callback will continue to receive events
     * indefinitely and it may prevent other resources from being released. Specifically, the
     * callbacks will be invoked independently of the general activity lifecycle and independently
     * of the state of individual CameraManager instances.</p>
     *
     * @param callback The new callback to send torch mode status to
     * @param handler The handler on which the callback should be invoked, or {@code null} to use
     *             the current thread's {@link android.os.Looper looper}.
     *
     * @throws IllegalArgumentException if the handler is {@code null} but the current thread has
     *             no looper.
     */
    public void registerTorchCallback(TorchCallback callback, Handler handler) {
    }

    /**
     * Remove a previously-added callback; the callback will no longer receive torch mode status
     * callbacks.
     *
     * <p>Removing a callback that isn't registered has no effect.</p>
     *
     * @param callback The callback to remove from the notification list
     */
    public void unregisterTorchCallback(TorchCallback callback) {
    }

    /**
     * <p>Query the capabilities of a camera device. These capabilities are
     * immutable for a given camera.</p>
@@ -383,6 +422,47 @@ public final class CameraManager {
        openCameraDeviceUserAsync(cameraId, callback, handler);
    }

    /**
     * Set the flash unit's torch mode of the camera of the given ID without opening the camera
     * device.
     *
     * <p>Use {@link #getCameraIdList} to get the list of available camera devices and use
     * {@link #getCameraCharacteristics} to check whether the camera device has a flash unit.
     * Note that even if a camera device has a flash unit, turning on the torch mode may fail
     * if the camera device or other camera resources needed to turn on the torch mode are in use.
     * </p>
     *
     * <p> If {@link #setTorchMode} is called to turn on or off the torch mode successfully,
     * {@link CameraManager.TorchCallback#onTorchModeChanged} will be invoked.
     * However, even if turning on the torch mode is successful, the application does not have the
     * exclusive ownership of the flash unit or the camera device. The torch mode will be turned
     * off and becomes unavailable when the camera device that the flash unit belongs to becomes
     * unavailable ({@link CameraManager.TorchCallback#onTorchModeAvailable} will be
     * invoked) or when other camera resources to keep the torch on become unavailable (
     * {@link CameraManager.TorchCallback#onTorchModeUnavailable} will be invoked). Also,
     * other applications are free to call {@link #setTorchMode} to turn off the torch mode (
     * {@link CameraManager.TorchCallback#onTorchModeChanged} will be invoked).
     *
     * @param cameraId
     *             The unique identifier of the camera device that the flash unit belongs to.
     * @param enabled
     *             The desired state of the torch mode for the target camera device. Set to
     *             {@code true} to turn on the torch mode. Set to {@code false} to turn off the
     *             torch mode.
     *
     * @throws CameraAccessException if it failed to access the flash unit.
     *             {@link CameraAccessException#CAMERA_IN_USE} will be thrown if the camera device
     *             is in use. {@link CameraAccessException#MAX_CAMERAS_IN_USE} will be thrown if
     *             other camera resources needed to turn on the torch mode are in use.
     *
     * @throws IllegalArgumentException if cameraId was null, cameraId doesn't match any currently
     *             or previously available camera device, or the camera device doesn't have a
     *             flash unit.
     */
    public void setTorchMode(String cameraId, boolean enabled) throws CameraAccessException {

    }

    /**
     * A callback for camera devices becoming available or
     * unavailable to open.
@@ -427,6 +507,68 @@ public final class CameraManager {
        }
    }

    /**
     * A callback for camera flash torch modes becoming available, unavailable, enabled, or
     * disabled.
     *
     * <p>The torch mode becomes available when the camera device it belongs to is no longer in use
     * and other camera resources it needs are no longer busy. It becomes unavailable when the
     * camera device it belongs to becomes unavailable or other camera resouces it needs become
     * busy due to other higher priority camera activities. The torch mode changes when an
     * application calls {@link #setTorchMode} successfully.
     *
     * <p>Extend this callback and pass an instance of the subclass to
     * {@link CameraManager#registerTorchCallback} to be notified of such status changes.
     * </p>
     *
     * @see registerTorchCallback
     */
    public static abstract class TorchCallback {
        /**
         * The torch mode of a camera has become available to use.
         *
         * <p>The default implementation of this method does nothing.</p>
         *
         * @param cameraId The unique identifier of the camera whose torch mode has become
         *                 available.
         */
        public void onTorchModeAvailable(String cameraId) {
            // default empty implementation
        }

        /**
         * A previously-available torch mode of a camera has become unavailable.
         *
         * <p>If torch mode was previously turned on by calling {@link #setTorchMode}, it will be
         * turned off before {@link CameraManager.TorchCallback#onTorchModeUnavailable} is
         * invoked. {@link #setTorchMode} will fail until the flash unit becomes available again.
         * </p>
         *
         * <p>The default implementation of this method does nothing.</p>
         *
         * @param cameraId The unique identifier of the camera whose torch mode has become
         *                 unavailable.
         */
        public void onTorchModeUnavailable(String cameraId) {
            // default empty implementation
        }

        /**
         * Torch mode of a camera has been turned on or off through {@link #setTorchMode}.
         *
         * <p>The default implementation of this method does nothing.</p>
         *
         * @param cameraId The unique identifier of the camera whose torch mode has been changed.
         *
         * @param enabled The state that the torch mode of the camera has been changed to.
         *                {@code true} when the torch mode has been turned on. {@code false} when
         *                the torch mode has been turned off.
         */
        public void onTorchModeChanged(String cameraId, boolean enabled) {
            // default empty implementation
        }
    }

    /**
     * Return or create the list of currently connected camera devices.
     *