diff --git a/api/current.txt b/api/current.txt
index 5dbe3f32a6568..18b30da6aa250 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -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
Registering the same callback again will replace the handler with the + * new one provided.
+ * + *The first time a callback is registered, it is immediately called + * with the torch mode status of all currently known camera devices.
+ * + *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.
+ * + * @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. + * + *Removing a callback that isn't registered has no effect.
+ * + * @param callback The callback to remove from the notification list + */ + public void unregisterTorchCallback(TorchCallback callback) { + } + /** *Query the capabilities of a camera device. These capabilities are * immutable for a given camera.
@@ -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. + * + *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. + *
+ * + *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. + * + *
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. + * + *
Extend this callback and pass an instance of the subclass to + * {@link CameraManager#registerTorchCallback} to be notified of such status changes. + *
+ * + * @see registerTorchCallback + */ + public static abstract class TorchCallback { + /** + * The torch mode of a camera has become available to use. + * + *The default implementation of this method does nothing.
+ * + * @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. + * + *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. + *
+ * + *The default implementation of this method does nothing.
+ * + * @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}. + * + *The default implementation of this method does nothing.
+ * + * @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. *