Merge "Camera: remove stream_configuration_counter"
diff --git a/include/hardware/camera3.h b/include/hardware/camera3.h
index dd57f30..0e69e7e 100644
--- a/include/hardware/camera3.h
+++ b/include/hardware/camera3.h
@@ -198,6 +198,10 @@
  *     segments and thumbnail (without main image bitstream). Camera framework
  *     uses such stream togerther with a HAL YUV_420_888/IMPLEMENTATION_DEFINED
  *     stream to encode HEIC (ISO/IEC 23008-12) image.
+ *
+ *   - Add is_reconfiguration_required() to camera3_device_ops_t to enable HAL to skip or
+ *     trigger stream reconfiguration depending on new session parameter values.
+ *
  */
 
 /**
@@ -3471,8 +3475,58 @@
             uint32_t num_streams,
             const camera3_stream_t* const* streams);
 
+    /**
+     * is_reconfiguration_required:
+     *
+     * <= CAMERA_DEVICE_API_VERISON_3_5:
+     *
+     *    Not defined and must be NULL
+     *
+     * >= CAMERA_DEVICE_API_VERISON_3_6:
+     *
+     * Check whether complete stream reconfiguration is required for possible new session
+     * parameter values.
+     *
+     * This method must be called by the camera framework in case the client changes
+     * the value of any advertised session parameters. Depending on the specific values
+     * the HAL can decide whether a complete stream reconfiguration is required. In case
+     * the HAL returns -ENVAL, the camera framework must skip the internal reconfiguration.
+     * In case Hal returns 0, the framework must reconfigure the streams and pass the
+     * new session parameter values accordingly.
+     * This call may be done by the framework some time before the request with new parameters
+     * is submitted to the HAL, and the request may be cancelled before it ever gets submitted.
+     * Therefore, the HAL must not use this query as an indication to change its behavior in any
+     * way.
+     * ------------------------------------------------------------------------
+     *
+     * Preconditions:
+     *
+     * The framework can call this method at any time after active
+     * session configuration. There must be no impact on the performance of
+     * pending camera requests in any way. In particular there must not be
+     * any glitches or delays during normal camera streaming.
+     *
+     * Performance requirements:
+     * HW and SW camera settings must not be changed and there must not be
+     * a user-visible impact on camera performance.
+     *
+     * @param oldSessionParams The currently applied session parameters.
+     * @param newSessionParams The new session parameters set by client.
+     *
+     * @return Status Status code for the operation, one of:
+     * 0:                    In case the stream reconfiguration is required
+     *
+     * -EINVAL:              In case the stream reconfiguration is not required.
+     *
+     * -ENOSYS:              In case the camera device does not support the
+     *                       reconfiguration query.
+     */
+    int (*is_reconfiguration_required)(const struct camera3_device*,
+            const camera_metadata_t* old_session_params,
+            const camera_metadata_t* new_session_params);
+
     /* reserved for future use */
-    void *reserved[7];
+    void *reserved[6];
 } camera3_device_ops_t;
 
 /**********************************************************************
diff --git a/include/hardware/camera_common.h b/include/hardware/camera_common.h
index f428cfb..16651a9 100644
--- a/include/hardware/camera_common.h
+++ b/include/hardware/camera_common.h
@@ -121,10 +121,18 @@
  *******************************************************************************
  * Version: 2.5 [CAMERA_MODULE_API_VERSION_2_5]
  *
- * This camera module version adds support to query characteristics of a
- * non-standalone physical camera, which can only be accessed as part of a
- * logical camera. It also adds camera stream combination query.
+ * This camera module version adds below API changes:
  *
+ * 1. Support to query characteristics of a non-standalone physical camera, which can
+ *    only be accessed as part of a logical camera. It also adds camera stream combination
+ *    query.
+ *
+ * 2. Ability to query whether a particular camera stream combination is
+ *    supported by the camera device.
+ *
+ * 3. Device state change notification. This module version also supports
+ *    notification about the overall device state change, such as
+ *    folding/unfolding, or covering/uncovering of shutter.
  */
 
 /**
@@ -799,6 +807,47 @@
 
 } camera_stream_combination_t;
 
+/**
+ * device_state_t:
+ *
+ * Possible physical states of the overall device, for use with
+ * notify_device_state_change.
+ */
+typedef enum device_state {
+    /**
+     * The device is in its normal physical configuration. This is the default if the
+     * device does not support multiple different states.
+     */
+    NORMAL = 0,
+
+    /**
+     * Camera device(s) facing backward are covered.
+     */
+    BACK_COVERED = 1 << 0,
+
+    /**
+     * Camera device(s) facing foward are covered.
+     */
+    FRONT_COVERED = 1 << 1,
+
+    /**
+     * The device is folded.  If not set, the device is unfolded or does not
+     * support folding.
+     *
+     * The exact point when this status change happens during the folding
+     * operation is device-specific.
+     */
+    FOLDED = 1 << 2,
+
+    /**
+     * First vendor-specific device state. All bits above and including this one
+     * are for vendor state values.  Values below this one must only be used
+     * for framework-defined states.
+     */
+    VENDOR_STATE_START = 1LL << 32
+
+} device_state_t;
+
 typedef struct camera_module {
     /**
      * Common methods of the camera module.  This *must* be the first member of
@@ -1121,8 +1170,47 @@
     int (*is_stream_combination_supported)(int camera_id,
             const camera_stream_combination_t *streams);
 
+    /**
+     * notify_device_state_change:
+     *
+     * Notify the camera module that the state of the overall device has
+     * changed in some way that the HAL may want to know about.
+     *
+     * For example, a physical shutter may have been uncovered or covered,
+     * or a camera may have been covered or uncovered by an add-on keyboard
+     * or other accessory.
+     *
+     * The state is a bitfield of potential states, and some physical configurations
+     * could plausibly correspond to multiple different combinations of state bits.
+     * The HAL must ignore any state bits it is not actively using to determine
+     * the appropriate camera configuration.
+     *
+     * For example, on some devices the FOLDED state could mean that
+     * backward-facing cameras are covered by the fold, so FOLDED by itself implies
+     * BACK_COVERED. But other devices may support folding but not cover any cameras
+     * when folded, so for those FOLDED would not imply any of the other flags.
+     * Since these relationships are very device-specific, it is difficult to specify
+     * a comprehensive policy.  But as a recommendation, it is suggested that if a flag
+     * necessarily implies other flags are set as well, then those flags should be set.
+     * So even though FOLDED would be enough to infer BACK_COVERED on some devices, the
+     * BACK_COVERED flag should also be set for clarity.
+     *
+     * This method may be invoked by the HAL client at any time. It must not
+     * cause any active camera device sessions to be closed, but may dynamically
+     * change which physical camera a logical multi-camera is using for its
+     * active and future output.
+     *
+     * The method must be invoked by the HAL client at least once before the
+     * client calls ICameraDevice::open on any camera device interfaces listed
+     * by this provider, to establish the initial device state.
+     *
+     * Note that the deviceState is 64-bit bitmask, with system defined states in
+     * lower 32-bit and vendor defined states in upper 32-bit.
+     */
+    void (*notify_device_state_change)(uint64_t deviceState);
+
     /* reserved for future use */
-    void* reserved[3];
+    void* reserved[2];
 } camera_module_t;
 
 __END_DECLS
diff --git a/tests/hardware/struct-offset.cpp b/tests/hardware/struct-offset.cpp
index 0b0f053..0cf145a 100644
--- a/tests/hardware/struct-offset.cpp
+++ b/tests/hardware/struct-offset.cpp
@@ -218,7 +218,8 @@
     CHECK_MEMBER_AT(camera_module_t, init, 152, 296);
     CHECK_MEMBER_AT(camera_module_t, get_physical_camera_info, 156, 304);
     CHECK_MEMBER_AT(camera_module_t, is_stream_combination_supported, 160, 312);
-    CHECK_MEMBER_AT(camera_module_t, reserved, 164, 320);
+    CHECK_MEMBER_AT(camera_module_t, notify_device_state_change, 164, 320);
+    CHECK_MEMBER_AT(camera_module_t, reserved, 168, 328);
 
     //Types defined in camera3.h
     CHECK_MEMBER_AT(camera3_device_ops_t, initialize, 0, 0);
@@ -230,6 +231,6 @@
     CHECK_MEMBER_AT(camera3_device_ops_t, dump, 24, 48);
     CHECK_MEMBER_AT(camera3_device_ops_t, flush, 28, 56);
     CHECK_MEMBER_AT(camera3_device_ops_t, signal_stream_flush, 32, 64);
-    CHECK_MEMBER_AT(camera3_device_ops_t, reserved, 36, 72);
+    CHECK_MEMBER_AT(camera3_device_ops_t, is_reconfiguration_required, 36, 72);
+    CHECK_MEMBER_AT(camera3_device_ops_t, reserved, 40, 80);
 }
-