Merge "camera2: Add tags for querying capabilities of a camera device"
diff --git a/api/current.txt b/api/current.txt
index c360805..cf6e463 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -11276,6 +11276,7 @@
     field public static final android.hardware.camera2.CameraMetadata.Key LENS_INFO_HYPERFOCAL_DISTANCE;
     field public static final android.hardware.camera2.CameraMetadata.Key LENS_INFO_MINIMUM_FOCUS_DISTANCE;
     field public static final android.hardware.camera2.CameraMetadata.Key LENS_INFO_SHADING_MAP_SIZE;
+    field public static final android.hardware.camera2.CameraMetadata.Key REQUEST_AVAILABLE_CAPABILITIES;
     field public static final android.hardware.camera2.CameraMetadata.Key REQUEST_MAX_NUM_INPUT_STREAMS;
     field public static final android.hardware.camera2.CameraMetadata.Key REQUEST_MAX_NUM_OUTPUT_STREAMS;
     field public static final android.hardware.camera2.CameraMetadata.Key REQUEST_PARTIAL_RESULT_COUNT;
@@ -11472,6 +11473,9 @@
     field public static final int NOISE_REDUCTION_MODE_FAST = 1; // 0x1
     field public static final int NOISE_REDUCTION_MODE_HIGH_QUALITY = 2; // 0x2
     field public static final int NOISE_REDUCTION_MODE_OFF = 0; // 0x0
+    field public static final int REQUEST_AVAILABLE_CAPABILITIES_DNG = 5; // 0x5
+    field public static final int REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR = 2; // 0x2
+    field public static final int REQUEST_AVAILABLE_CAPABILITIES_ZSL = 4; // 0x4
     field public static final int SENSOR_TEST_PATTERN_MODE_COLOR_BARS = 2; // 0x2
     field public static final int SENSOR_TEST_PATTERN_MODE_COLOR_BARS_FADE_TO_GRAY = 3; // 0x3
     field public static final int SENSOR_TEST_PATTERN_MODE_CUSTOM1 = 256; // 0x100
diff --git a/core/java/android/hardware/camera2/CameraCharacteristics.java b/core/java/android/hardware/camera2/CameraCharacteristics.java
index a8f7e35..819fdb8 100644
--- a/core/java/android/hardware/camera2/CameraCharacteristics.java
+++ b/core/java/android/hardware/camera2/CameraCharacteristics.java
@@ -494,6 +494,98 @@
             new Key<Integer>("android.request.partialResultCount", int.class);
 
     /**
+     * <p>List of capabilities that the camera device
+     * advertises as fully supporting.</p>
+     * <p>A capability is a contract that the camera device makes in order
+     * to be able to satisfy one or more use cases.</p>
+     * <p>Listing a capability guarantees that the whole set of features
+     * required to support a common use will all be available.</p>
+     * <p>Using a subset of the functionality provided by an unsupported
+     * capability may be possible on a specific camera device implementation;
+     * to do this query each of android.request.availableRequestKeys,
+     * android.request.availableResultKeys,
+     * android.request.availableCharacteristicsKeys.</p>
+     * <p>XX: Maybe these should go into android.info.supportedHardwareLevel
+     * as a table instead?</p>
+     * <p>The following capabilities are guaranteed to be available on
+     * {@link CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL android.info.supportedHardwareLevel} <code>==</code> FULL devices:</p>
+     * <ul>
+     * <li>MANUAL_SENSOR</li>
+     * <li>ZSL</li>
+     * </ul>
+     * <p>Other capabilities may be available on either FULL or LIMITED
+     * devices, but the app. should query this field to be sure.</p>
+     *
+     * @see CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL
+     * @see #REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE
+     * @see #REQUEST_AVAILABLE_CAPABILITIES_OPTIONAL
+     * @see #REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR
+     * @see #REQUEST_AVAILABLE_CAPABILITIES_GCAM
+     * @see #REQUEST_AVAILABLE_CAPABILITIES_ZSL
+     * @see #REQUEST_AVAILABLE_CAPABILITIES_DNG
+     */
+    public static final Key<Integer> REQUEST_AVAILABLE_CAPABILITIES =
+            new Key<Integer>("android.request.availableCapabilities", int.class);
+
+    /**
+     * <p>A list of all keys that the camera device has available
+     * to use with CaptureRequest.</p>
+     * <p>Attempting to set a key into a CaptureRequest that is not
+     * listed here will result in an invalid request and will be rejected
+     * by the camera device.</p>
+     * <p>This field can be used to query the feature set of a camera device
+     * at a more granular level than capabilities. This is especially
+     * important for optional keys that are not listed under any capability
+     * in {@link CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES android.request.availableCapabilities}.</p>
+     * <p>TODO: This should be used by #getAvailableCaptureRequestKeys.</p>
+     *
+     * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
+     * @hide
+     */
+    public static final Key<int[]> REQUEST_AVAILABLE_REQUEST_KEYS =
+            new Key<int[]>("android.request.availableRequestKeys", int[].class);
+
+    /**
+     * <p>A list of all keys that the camera device has available
+     * to use with CaptureResult.</p>
+     * <p>Attempting to get a key from a CaptureResult that is not
+     * listed here will always return a <code>null</code> value. Getting a key from
+     * a CaptureResult that is listed here must never return a <code>null</code>
+     * value.</p>
+     * <p>The following keys may return <code>null</code> unless they are enabled:</p>
+     * <ul>
+     * <li>{@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap} (non-null iff {@link CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE android.statistics.lensShadingMapMode} == ON)</li>
+     * </ul>
+     * <p>(Those sometimes-null keys should nevertheless be listed here
+     * if they are available.)</p>
+     * <p>This field can be used to query the feature set of a camera device
+     * at a more granular level than capabilities. This is especially
+     * important for optional keys that are not listed under any capability
+     * in {@link CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES android.request.availableCapabilities}.</p>
+     * <p>TODO: This should be used by #getAvailableCaptureResultKeys.</p>
+     *
+     * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
+     * @see CaptureResult#STATISTICS_LENS_SHADING_MAP
+     * @see CaptureRequest#STATISTICS_LENS_SHADING_MAP_MODE
+     * @hide
+     */
+    public static final Key<int[]> REQUEST_AVAILABLE_RESULT_KEYS =
+            new Key<int[]>("android.request.availableResultKeys", int[].class);
+
+    /**
+     * <p>A list of all keys that the camera device has available
+     * to use with CameraCharacteristics.</p>
+     * <p>This entry follows the same rules as
+     * android.request.availableResultKeys (except that it applies for
+     * CameraCharacteristics instead of CaptureResult). See above for more
+     * details.</p>
+     * <p>TODO: This should be used by CameraCharacteristics#getKeys.</p>
+     * @hide
+     */
+    public static final Key<int[]> REQUEST_AVAILABLE_CHARACTERISTICS_KEYS =
+            new Key<int[]>("android.request.availableCharacteristicsKeys", int[].class);
+
+    /**
      * <p>The list of image formats that are supported by this
      * camera device for output streams.</p>
      * <p>All camera devices will support JPEG and YUV_420_888 formats.</p>
@@ -800,14 +892,20 @@
             new Key<int[]>("android.led.availableLeds", int[].class);
 
     /**
-     * <p>The camera 3 HAL device can implement one of two possible
-     * operational modes; limited and full. Full support is
-     * expected from new higher-end devices. Limited mode has
-     * hardware requirements roughly in line with those for a
-     * camera HAL device v1 implementation, and is expected from
-     * older or inexpensive devices. Full is a strict superset of
-     * limited, and they share the same essential operational flow.</p>
-     * <p>For full details refer to "S3. Operational Modes" in camera3.h</p>
+     * <p>Generally classifies the overall set of the camera device functionality.</p>
+     * <p>Camera devices will come in two flavors: LIMITED and FULL.</p>
+     * <p>A FULL device has the most support possible and will enable the
+     * widest range of use cases such as:</p>
+     * <ul>
+     * <li>30 FPS at maximum resolution (== sensor resolution)</li>
+     * <li>Per frame control</li>
+     * <li>Manual sensor control</li>
+     * <li>Zero Shutter Lag (ZSL)</li>
+     * </ul>
+     * <p>A LIMITED device may have some or none of the above characteristics.
+     * To find out more refer to {@link CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES android.request.availableCapabilities}.</p>
+     *
+     * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
      * @see #INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED
      * @see #INFO_SUPPORTED_HARDWARE_LEVEL_FULL
      */
diff --git a/core/java/android/hardware/camera2/CameraMetadata.java b/core/java/android/hardware/camera2/CameraMetadata.java
index 03ee508..7e2fd1e 100644
--- a/core/java/android/hardware/camera2/CameraMetadata.java
+++ b/core/java/android/hardware/camera2/CameraMetadata.java
@@ -259,6 +259,156 @@
     public static final int LENS_FACING_BACK = 1;
 
     //
+    // Enumeration values for CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
+    //
+
+    /**
+     * <p>The minimal set of capabilities that every camera
+     * device (regardless of {@link CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL android.info.supportedHardwareLevel})
+     * will support.</p>
+     * <p>The full set of features supported by this capability makes
+     * the camera2 api backwards compatible with the camera1
+     * (android.hardware.Camera) API.</p>
+     * <p>TODO: @hide this. Doesn't really mean anything except
+     * act as a catch-all for all the 'base' functionality.</p>
+     *
+     * @see CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL
+     * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
+     */
+    public static final int REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE = 0;
+
+    /**
+     * <p>This is a catch-all capability to include all other
+     * tags or functionality not encapsulated by one of the other
+     * capabilities.</p>
+     * <p>A typical example is all tags marked 'optional'.</p>
+     * <p>TODO: @hide. We may not need this if we @hide all the optional
+     * tags not belonging to a capability.</p>
+     * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
+     */
+    public static final int REQUEST_AVAILABLE_CAPABILITIES_OPTIONAL = 1;
+
+    /**
+     * <p>The camera device can be manually controlled (3A algorithms such
+     * as auto exposure, and auto focus can be
+     * bypassed), this includes but is not limited to:</p>
+     * <ul>
+     * <li>Manual exposure control<ul>
+     * <li>{@link CaptureRequest#SENSOR_EXPOSURE_TIME android.sensor.exposureTime}</li>
+     * <li>{@link CameraCharacteristics#SENSOR_INFO_EXPOSURE_TIME_RANGE android.sensor.info.exposureTimeRange}</li>
+     * </ul>
+     * </li>
+     * <li>Manual sensitivity control<ul>
+     * <li>{@link CaptureRequest#SENSOR_SENSITIVITY android.sensor.sensitivity}</li>
+     * <li>{@link CameraCharacteristics#SENSOR_INFO_SENSITIVITY_RANGE android.sensor.info.sensitivityRange}</li>
+     * <li>{@link CameraCharacteristics#SENSOR_BASE_GAIN_FACTOR android.sensor.baseGainFactor}</li>
+     * </ul>
+     * </li>
+     * <li>Manual lens control<ul>
+     * <li>android.lens.*</li>
+     * </ul>
+     * </li>
+     * <li>Manual flash control<ul>
+     * <li>android.flash.*</li>
+     * </ul>
+     * </li>
+     * <li>Manual black level locking<ul>
+     * <li>{@link CaptureRequest#BLACK_LEVEL_LOCK android.blackLevel.lock}</li>
+     * </ul>
+     * </li>
+     * </ul>
+     * <p>If any of the above 3A algorithms are enabled, then the camera
+     * device will accurately report the values applied by 3A in the
+     * result.</p>
+     *
+     * @see CaptureRequest#BLACK_LEVEL_LOCK
+     * @see CameraCharacteristics#SENSOR_BASE_GAIN_FACTOR
+     * @see CaptureRequest#SENSOR_EXPOSURE_TIME
+     * @see CameraCharacteristics#SENSOR_INFO_EXPOSURE_TIME_RANGE
+     * @see CameraCharacteristics#SENSOR_INFO_SENSITIVITY_RANGE
+     * @see CaptureRequest#SENSOR_SENSITIVITY
+     * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
+     */
+    public static final int REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR = 2;
+
+    /**
+     * <p>TODO: This should be @hide</p>
+     * <ul>
+     * <li>Manual tonemap control<ul>
+     * <li>{@link CaptureRequest#TONEMAP_CURVE_BLUE android.tonemap.curveBlue}</li>
+     * <li>{@link CaptureRequest#TONEMAP_CURVE_GREEN android.tonemap.curveGreen}</li>
+     * <li>{@link CaptureRequest#TONEMAP_CURVE_RED android.tonemap.curveRed}</li>
+     * <li>{@link CaptureRequest#TONEMAP_MODE android.tonemap.mode}</li>
+     * <li>{@link CameraCharacteristics#TONEMAP_MAX_CURVE_POINTS android.tonemap.maxCurvePoints}</li>
+     * </ul>
+     * </li>
+     * <li>Manual white balance control<ul>
+     * <li>{@link CaptureRequest#COLOR_CORRECTION_TRANSFORM android.colorCorrection.transform}</li>
+     * <li>{@link CaptureRequest#COLOR_CORRECTION_GAINS android.colorCorrection.gains}</li>
+     * </ul>
+     * </li>
+     * <li>Lens shading map information<ul>
+     * <li>{@link CaptureResult#STATISTICS_LENS_SHADING_MAP android.statistics.lensShadingMap}</li>
+     * <li>{@link CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE android.lens.info.shadingMapSize}</li>
+     * </ul>
+     * </li>
+     * </ul>
+     * <p>If auto white balance is enabled, then the camera device
+     * will accurately report the values applied by AWB in the result.</p>
+     * <p>The camera device will also support everything in MANUAL_SENSOR
+     * except manual lens control and manual flash control.</p>
+     *
+     * @see CaptureRequest#COLOR_CORRECTION_GAINS
+     * @see CaptureRequest#COLOR_CORRECTION_TRANSFORM
+     * @see CameraCharacteristics#LENS_INFO_SHADING_MAP_SIZE
+     * @see CaptureResult#STATISTICS_LENS_SHADING_MAP
+     * @see CaptureRequest#TONEMAP_CURVE_BLUE
+     * @see CaptureRequest#TONEMAP_CURVE_GREEN
+     * @see CaptureRequest#TONEMAP_CURVE_RED
+     * @see CameraCharacteristics#TONEMAP_MAX_CURVE_POINTS
+     * @see CaptureRequest#TONEMAP_MODE
+     * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
+     */
+    public static final int REQUEST_AVAILABLE_CAPABILITIES_GCAM = 3;
+
+    /**
+     * <p>The camera device supports the Zero Shutter Lag use case.</p>
+     * <ul>
+     * <li>At least one input stream can be used.</li>
+     * <li>RAW_OPAQUE is supported as an output/input format</li>
+     * <li>Using RAW_OPAQUE does not cause a frame rate drop
+     * relative to the sensor's maximum capture rate (at that
+     * resolution).</li>
+     * <li>RAW_OPAQUE will be reprocessable into both YUV_420_888
+     * and JPEG formats.</li>
+     * <li>The maximum available resolution for RAW_OPAQUE streams
+     * (both input/output) will match the maximum available
+     * resolution of JPEG streams.</li>
+     * </ul>
+     * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
+     */
+    public static final int REQUEST_AVAILABLE_CAPABILITIES_ZSL = 4;
+
+    /**
+     * <p>The camera device supports outputting RAW buffers that can be
+     * saved offline into a DNG format. It can reprocess DNG
+     * files (produced from the same camera device) back into YUV.</p>
+     * <ul>
+     * <li>At least one input stream can be used.</li>
+     * <li>RAW16 is supported as output/input format.</li>
+     * <li>RAW16 is reprocessable into both YUV_420_888 and JPEG
+     * formats.</li>
+     * <li>The maximum available resolution for RAW16 streams (both
+     * input/output) will match the value in
+     * android.sensor.info.pixelArraySize.</li>
+     * <li>All DNG-related optional metadata entries are provided
+     * by the camera device.</li>
+     * </ul>
+     * @see CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES
+     */
+    public static final int REQUEST_AVAILABLE_CAPABILITIES_DNG = 5;
+
+    //
     // Enumeration values for CameraCharacteristics#LED_AVAILABLE_LEDS
     //