Merge "hwcomposer2: add seamlessPossible callback"
diff --git a/include/hardware/audio.h b/include/hardware/audio.h
index feebd23..b047fa0 100644
--- a/include/hardware/audio.h
+++ b/include/hardware/audio.h
@@ -56,7 +56,8 @@
 #define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
 #define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
 #define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
-#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_0
+#define AUDIO_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
+#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_1
 /* Minimal audio HAL version supported by the audio framework */
 #define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0
 
@@ -825,6 +826,31 @@
     int (*set_audio_port_config)(struct audio_hw_device *dev,
                          const struct audio_port_config *config);
 
+    /**
+     * Applies an audio effect to an audio device.
+     *
+     * @param dev the audio HAL device context.
+     * @param device identifies the sink or source device the effect must be applied to.
+     *               "device" is the audio_port_handle_t indicated for the device when
+     *               the audio patch connecting that device was created.
+     * @param effect effect interface handle corresponding to the effect being added.
+     * @return retval operation completion status.
+     */
+    int (*add_device_effect)(struct audio_hw_device *dev,
+                        audio_port_handle_t device, effect_handle_t effect);
+
+    /**
+     * Stops applying an audio effect to an audio device.
+     *
+     * @param dev the audio HAL device context.
+     * @param device identifies the sink or source device this effect was applied to.
+     *               "device" is the audio_port_handle_t indicated for the device when
+     *               the audio patch is created.
+     * @param effect effect interface handle corresponding to the effect being removed.
+     * @return retval operation completion status.
+     */
+    int (*remove_device_effect)(struct audio_hw_device *dev,
+                        audio_port_handle_t device, effect_handle_t effect);
 };
 typedef struct audio_hw_device audio_hw_device_t;
 
diff --git a/include/hardware/audio_effect.h b/include/hardware/audio_effect.h
index 3366e17..a2809ba 100644
--- a/include/hardware/audio_effect.h
+++ b/include/hardware/audio_effect.h
@@ -207,6 +207,8 @@
 // Note that EffectsFactory.c only checks the major version component, so changes to the minor
 // number can only be used for fully backwards compatible changes
 #define EFFECT_LIBRARY_API_VERSION EFFECT_MAKE_API_VERSION(3,0)
+#define EFFECT_LIBRARY_API_VERSION_3_0 EFFECT_MAKE_API_VERSION(3,0)
+#define EFFECT_LIBRARY_API_VERSION_3_1 EFFECT_MAKE_API_VERSION(3,1)
 
 #define AUDIO_EFFECT_LIBRARY_TAG ((('A') << 24) | (('E') << 16) | (('L') << 8) | ('T'))
 
@@ -297,6 +299,48 @@
     ////////////////////////////////////////////////////////////////////////////////
     int32_t (*get_descriptor)(const effect_uuid_t *uuid,
                               effect_descriptor_t *pDescriptor);
+
+    ////////////////////////////////////////////////////////////////////////////////
+    //
+    //    Function:        create_effect_3_1
+    //
+    //    Description:    Creates an effect engine of the specified implementation uuid and
+    //          returns an effect control interface on this engine. The function will allocate the
+    //          resources for an instance of the requested effect engine and return
+    //          a handle on the effect control interface.
+    //
+    //    Input:
+    //          uuid:    pointer to the effect uuid.
+    //          sessionId:  audio session to which this effect instance will be attached.
+    //              All effects created with the same session ID are connected in series and process
+    //              the same signal stream. Knowing that two effects are part of the same effect
+    //              chain can help the library implement some kind of optimizations.
+    //          ioId:   identifies the output or input stream this effect is directed to in
+    //              audio HAL.
+    //              For future use especially with tunneled HW accelerated effects
+    //          deviceId:  identifies the sink or source device this effect is directed to in
+    //              audio HAL. Must be specified if sessionId is AUDIO_SESSION_DEVICE and is
+    //              ignored otherwise.
+    //              deviceId is the audio_port_handle_t used for the device when the audio
+    //              patch is created at the audio HAL.
+    //
+    //    Input/Output:
+    //          pHandle:        address where to return the effect interface handle.
+    //
+    //    Output:
+    //        returned value:    0          successful operation.
+    //                          -ENODEV     library failed to initialize
+    //                          -EINVAL     invalid pEffectUuid or pHandle
+    //                          -ENOENT     no effect with this uuid found
+    //        *pHandle:         updated with the effect interface handle.
+    //
+    ////////////////////////////////////////////////////////////////////////////////
+    int32_t (*create_effect_3_1)(const effect_uuid_t *uuid,
+                         int32_t sessionId,
+                         int32_t ioId,
+                         int32_t deviceId,
+                         effect_handle_t *pHandle);
+
 } audio_effect_library_t;
 
 // Name of the hal_module_info
diff --git a/include/hardware/hwcomposer2.h b/include/hardware/hwcomposer2.h
index 21672f5..ba17ec5 100644
--- a/include/hardware/hwcomposer2.h
+++ b/include/hardware/hwcomposer2.h
@@ -303,6 +303,9 @@
     HWC2_FUNCTION_GET_DISPLAY_CONNECTION_TYPE,
     HWC2_FUNCTION_GET_DISPLAY_VSYNC_PERIOD,
     HWC2_FUNCTION_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS,
+    HWC2_FUNCTION_SET_AUTO_LOW_LATENCY_MODE,
+    HWC2_FUNCTION_GET_SUPPORTED_CONTENT_TYPES,
+    HWC2_FUNCTION_SET_CONTENT_TYPE,
 } hwc2_function_descriptor_t;
 
 /* Layer requests returned from getDisplayRequests */
@@ -341,6 +344,14 @@
     HWC2_POWER_MODE_ON = 2,
 } hwc2_power_mode_t;
 
+typedef enum {
+    HWC2_CONTENT_TYPE_NONE = 0,
+    HWC2_CONTENT_TYPE_GRAPHICS = 1,
+    HWC2_CONTENT_TYPE_PHOTO = 2,
+    HWC2_CONTENT_TYPE_CINEMA = 3,
+    HWC2_CONTENT_TYPE_GAME = 4,
+} hwc2_content_type_t;
+
 /* Vsync values passed to setVsyncEnabled */
 typedef enum {
     HWC2_VSYNC_INVALID = 0,
@@ -433,6 +444,15 @@
      * Specified that the display supports brightness operations.
      */
     HWC2_DISPLAY_CAPABILITY_BRIGHTNESS = 3,
+
+    /**
+     * Specifies that the display supports a low latency mode. If the connection
+     * to the display is via HDMI, this specifies whether Auto Low Latency Mode
+     * is supported. If, instead, there is an internal connection to the display,
+     * then this specifies that the display has some other custom low latency
+     * mode.
+     */
+    HWC2_DISPLAY_CAPABILITY_AUTO_LOW_LATENCY_MODE = 5,
 } hwc2_display_capability_t;
 
 /*
@@ -642,6 +662,9 @@
         case HWC2_FUNCTION_GET_DISPLAY_CONNECTION_TYPE: return "GetDisplayConnectionType";
         case HWC2_FUNCTION_GET_DISPLAY_VSYNC_PERIOD: return "GetDisplayVsyncPeriod";
         case HWC2_FUNCTION_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS: return "SetActiveConfigWithConstraints";
+        case HWC2_FUNCTION_SET_AUTO_LOW_LATENCY_MODE: return "SetAutoLowLatencyMode";
+        case HWC2_FUNCTION_GET_SUPPORTED_CONTENT_TYPES: return "GetSupportedContentTypes";
+        case HWC2_FUNCTION_SET_CONTENT_TYPE: return "SetContentType";
 
         default: return "Unknown";
     }
@@ -665,6 +688,17 @@
     }
 }
 
+static inline const char* getContentTypeName(hwc2_content_type_t contentType) {
+    switch(contentType) {
+        case HWC2_CONTENT_TYPE_NONE: return "None";
+        case HWC2_CONTENT_TYPE_GRAPHICS: return "Graphics";
+        case HWC2_CONTENT_TYPE_PHOTO: return "Photo";
+        case HWC2_CONTENT_TYPE_CINEMA: return "Cinema";
+        case HWC2_CONTENT_TYPE_GAME: return "Game";
+        default: return "Unknown";
+    }
+}
+
 static inline const char* getTransformName(hwc_transform_t transform) {
     switch (__BIONIC_CAST(static_cast, int, transform)) {
         case 0: return "None";
@@ -717,6 +751,8 @@
             return "Doze";
         case HWC2_DISPLAY_CAPABILITY_BRIGHTNESS:
             return "Brightness";
+        case HWC2_DISPLAY_CAPABILITY_AUTO_LOW_LATENCY_MODE:
+            return "AutoLowLatencyMode";
         default:
             return "Unknown";
     }
@@ -903,7 +939,9 @@
     GetDisplayConnectionType = HWC2_FUNCTION_GET_DISPLAY_CONNECTION_TYPE,
     GetDisplayVsyncPeriod = HWC2_FUNCTION_GET_DISPLAY_VSYNC_PERIOD,
     SetActiveConfigWithConstraints = HWC2_FUNCTION_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS,
-
+    SetAutoLowLatencyMode = HWC2_FUNCTION_SET_AUTO_LOW_LATENCY_MODE,
+    GetSupportedContentTypes = HWC2_FUNCTION_GET_SUPPORTED_CONTENT_TYPES,
+    SetContentType = HWC2_FUNCTION_SET_CONTENT_TYPE,
 };
 TO_STRING(hwc2_function_descriptor_t, FunctionDescriptor,
         getFunctionDescriptorName)
@@ -921,6 +959,15 @@
 };
 TO_STRING(hwc2_power_mode_t, PowerMode, getPowerModeName)
 
+enum class ContentType : int32_t {
+    None = HWC2_CONTENT_TYPE_NONE,
+    Graphics = HWC2_CONTENT_TYPE_GRAPHICS,
+    Photo = HWC2_CONTENT_TYPE_PHOTO,
+    Cinema = HWC2_CONTENT_TYPE_CINEMA,
+    Game = HWC2_CONTENT_TYPE_GAME,
+};
+TO_STRING(hwc2_content_type_t, ContentType, getContentTypeName)
+
 enum class Transform : int32_t {
     None = 0,
     FlipH = HWC_TRANSFORM_FLIP_H,
@@ -945,6 +992,7 @@
     SkipClientColorTransform = HWC2_DISPLAY_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM,
     Doze = HWC2_DISPLAY_CAPABILITY_DOZE,
     Brightness = HWC2_DISPLAY_CAPABILITY_BRIGHTNESS,
+    AutoLowLatencyMode = HWC2_DISPLAY_CAPABILITY_AUTO_LOW_LATENCY_MODE,
 };
 TO_STRING(hwc2_display_capability_t, DisplayCapability, getDisplayCapabilityName)
 
@@ -2927,6 +2975,66 @@
         hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints,
         hwc_vsync_period_change_timeline_t* outTimeline);
 
+/* setAutoLowLatencyMode(displayToken, on)
+ * Descriptor: HWC2_FUNCTION_SET_AUTO_LOW_LATENCY_MODE
+ * Optional for HWC2 devices
+ *
+ * setAutoLowLatencyMode requests that the display goes into low latency mode. If the display
+ * is connected via HDMI 2.1, then Auto Low Latency Mode should be triggered. If the display is
+ * internally connected, then a custom low latency mode should be triggered (if available).
+ *
+ * Parameters:
+ *   on - indicates whether to turn low latency mode on (=true) or off (=false)
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - when the display is invalid, or
+ *   HWC2_ERROR_UNSUPPORTED - when the display does not support any low latency mode
+ */
+typedef int32_t /*hwc_error_t*/ (*HWC2_PFN_SET_AUTO_LOW_LATENCY_MODE)(hwc2_device_t* device,
+        hwc2_display_t display, bool on);
+
+/* getSupportedContentTypes(..., outSupportedContentTypes)
+ * Descriptor: HWC2_FUNCTION_GET_SUPPORTED_CONTENT_TYPES
+ * Optional for HWC2 devices
+ *
+ * getSupportedContentTypes returns a list of supported content types
+ * (as described in the definition of ContentType above).
+ * This list must not change after initialization.
+ *
+ * Parameters:
+ *   outNumSupportedContentTypes - if outSupportedContentTypes was nullptr, returns the number
+ *       of supported content types; if outSupportedContentTypes was not nullptr, returns the
+ *       number of capabilities stored in outSupportedContentTypes, which must not exceed the
+ *       value stored in outNumSupportedContentTypes prior to the call; pointer will be non-NULL
+ *   outSupportedContentTypes - a list of supported content types.
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
+ */
+typedef int32_t /*hwc_error_t*/ (*HWC2_PFN_GET_SUPPORTED_CONTENT_TYPES)(hwc2_device_t* device,
+        hwc2_display_t display, uint32_t* outNumSupportedContentTypes, uint32_t* outSupportedContentTypes);
+
+/* setContentType(displayToken, contentType)
+ * Descriptor: HWC2_FUNCTION_SET_CONTENT_TYPE
+ * Optional for HWC2 devices
+ *
+ * setContentType instructs the display that the content being shown is of the given contentType
+ * (one of GRAPHICS, PHOTO, CINEMA, GAME).
+ *
+ * According to the HDMI 1.4 specification, supporting all content types is optional. Whether
+ * the display supports a given content type is reported by getSupportedContentTypes.
+ *
+ * Parameters:
+ *   contentType - the type of content that is currently being shown on the display
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - when the display is invalid, or
+ *   HWC2_ERROR_UNSUPPORTED - when the given content type is a valid content type, but is not
+ *                            supported on this display, or
+ *   HWC2_ERROR_BAD_PARAMETER - when the given content type is invalid
+ */
+typedef int32_t /*hwc_error_t*/ (*HWC2_PFN_SET_CONTENT_TYPE)(hwc2_device_t* device,
+        hwc2_display_t display, int32_t /* hwc2_content_type_t */ contentType);
 
 __END_DECLS
 
diff --git a/include/hardware/sound_trigger.h b/include/hardware/sound_trigger.h
index 99346ef..dbb56ce 100644
--- a/include/hardware/sound_trigger.h
+++ b/include/hardware/sound_trigger.h
@@ -41,7 +41,8 @@
 #define SOUND_TRIGGER_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
 #define SOUND_TRIGGER_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION(1, 1)
 #define SOUND_TRIGGER_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION(1, 2)
-#define SOUND_TRIGGER_DEVICE_API_VERSION_CURRENT SOUND_TRIGGER_DEVICE_API_VERSION_1_2
+#define SOUND_TRIGGER_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION(1, 3)
+#define SOUND_TRIGGER_DEVICE_API_VERSION_CURRENT SOUND_TRIGGER_DEVICE_API_VERSION_1_3
 
 /**
  * List of known sound trigger HAL modules. This is the base name of the sound_trigger HAL
@@ -123,6 +124,48 @@
      */
     int (*get_model_state)(const struct sound_trigger_hw_device *dev,
                            sound_model_handle_t sound_model_handle);
+
+    /* Set a model specific ModelParameter with the given value. This parameter
+     * will keep its value for the duration the model is loaded regardless of starting and stopping
+     * recognition. Once the model is unloaded, the value will be lost.
+     * Returns 0 or an error code.
+     * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
+     */
+    int (*set_parameter)(const struct sound_trigger_hw_device *dev,
+                           sound_model_handle_t sound_model_handle,
+                           sound_trigger_model_parameter_t model_param, int32_t value);
+
+    /* Get a model specific ModelParameter. This parameter will keep its value
+     * for the duration the model is loaded regardless of starting and stopping recognition.
+     * Once the model is unloaded, the value will be lost. If the value is not set, a default
+     * value is returned. See sound_trigger_model_parameter_t for parameter default values.
+     * Returns 0 or an error code. On return 0, value pointer will be set.
+     * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
+     */
+    int (*get_parameter)(const struct sound_trigger_hw_device *dev,
+                           sound_model_handle_t sound_model_handle,
+                           sound_trigger_model_parameter_t model_param, int32_t* value);
+
+    /* Get supported parameter attributes with respect to the provided model
+     * handle. Along with determining the valid range, this API is also used
+     * to determine if a given parameter ID is supported at all by the
+     * modelHandle for use with getParameter and setParameter APIs.
+     * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
+     */
+    int (*query_parameter)(const struct sound_trigger_hw_device *dev,
+                           sound_model_handle_t sound_model_handle,
+                           sound_trigger_model_parameter_t model_param,
+                           sound_trigger_model_parameter_range_t* param_range);
+
+    /*
+     * Retrieve verbose extended implementation properties.
+     * The header pointer is intented to be cast to the proper extended
+     * properties struct based on the header version.
+     * The returned pointer is valid throughout the lifetime of the driver.
+     * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
+     */
+    const struct sound_trigger_properties_header* (*get_properties_extended)
+            (const struct sound_trigger_hw_device *dev);
 };
 
 typedef struct sound_trigger_hw_device sound_trigger_hw_device_t;
diff --git a/modules/camera/3_4/arc/exif_utils.cpp b/modules/camera/3_4/arc/exif_utils.cpp
index 5e8c756..e951e83 100644
--- a/modules/camera/3_4/arc/exif_utils.cpp
+++ b/modules/camera/3_4/arc/exif_utils.cpp
@@ -475,15 +475,15 @@
 
 bool ExifUtils::GenerateYuvThumbnail(std::vector<uint8_t>* scaled_buffer) {
   size_t y_plane_size = yu12_width_ * yu12_height_;
-  const uint8* y_plane = yu12_buffer_;
-  const uint8* u_plane = y_plane + y_plane_size;
-  const uint8* v_plane = u_plane + y_plane_size / 4;
+  const uint8_t* y_plane = yu12_buffer_;
+  const uint8_t* u_plane = y_plane + y_plane_size;
+  const uint8_t* v_plane = u_plane + y_plane_size / 4;
 
   size_t scaled_y_plane_size = thumbnail_width_ * thumbnail_height_;
   scaled_buffer->resize(scaled_y_plane_size * 3 / 2);
-  uint8* scaled_y_plane = scaled_buffer->data();
-  uint8* scaled_u_plane = scaled_y_plane + scaled_y_plane_size;
-  uint8* scaled_v_plane = scaled_u_plane + scaled_y_plane_size / 4;
+  uint8_t* scaled_y_plane = scaled_buffer->data();
+  uint8_t* scaled_u_plane = scaled_y_plane + scaled_y_plane_size;
+  uint8_t* scaled_v_plane = scaled_u_plane + scaled_y_plane_size / 4;
 
   int result = libyuv::I420Scale(
       y_plane, yu12_width_, u_plane, yu12_width_ / 2, v_plane, yu12_width_ / 2,
diff --git a/modules/input/evdev/SwitchInputMapper.cpp b/modules/input/evdev/SwitchInputMapper.cpp
index bb79d01..1b2e749 100644
--- a/modules/input/evdev/SwitchInputMapper.cpp
+++ b/modules/input/evdev/SwitchInputMapper.cpp
@@ -47,13 +47,26 @@
     {SW_FRONT_PROXIMITY, INPUT_USAGE_SWITCH_UNKNOWN},
     {SW_ROTATE_LOCK, INPUT_USAGE_SWITCH_UNKNOWN},
     {SW_LINEIN_INSERT, INPUT_USAGE_SWITCH_UNKNOWN},
-    {0x0e /* unused */, INPUT_USAGE_SWITCH_UNKNOWN},
+    {SW_MUTE_DEVICE, INPUT_USAGE_SWITCH_UNKNOWN},
+    {SW_PEN_INSERTED, INPUT_USAGE_SWITCH_UNKNOWN},
+    {SW_HPHL_OVERCURRENT, INPUT_USAGE_SWITCH_UNKNOWN},
+    {SW_HPHR_OVERCURRENT, INPUT_USAGE_SWITCH_UNKNOWN},
+    {SW_UNSUPPORT_INSERT, INPUT_USAGE_SWITCH_UNKNOWN},
+    {0x13 /* unused */, INPUT_USAGE_SWITCH_UNKNOWN},
+    {0x14 /* unused */, INPUT_USAGE_SWITCH_UNKNOWN},
+    {0x15 /* unused */, INPUT_USAGE_SWITCH_UNKNOWN},
+    {0x16 /* unused */, INPUT_USAGE_SWITCH_UNKNOWN},
+    {0x17 /* unused */, INPUT_USAGE_SWITCH_UNKNOWN},
+    {0x18 /* unused */, INPUT_USAGE_SWITCH_UNKNOWN},
+    {0x19 /* unused */, INPUT_USAGE_SWITCH_UNKNOWN},
     {SW_MAX, INPUT_USAGE_SWITCH_UNKNOWN},
 };
 
 SwitchInputMapper::SwitchInputMapper()
     : InputMapper() {
-    static_assert(SW_CNT <= 32, "More than 32 switches defined in linux/input.h");
+    // If this gets larger than 64, then the mSwitchValues and mUpdatedSwitchMask
+    // variables need to be changed to support more than 64 bits.
+    static_assert(SW_CNT <= 64, "More than 64 switches defined in linux/input.h");
 }
 
 bool SwitchInputMapper::configureInputReport(InputDeviceNode* devNode,
diff --git a/modules/input/evdev/SwitchInputMapper.h b/modules/input/evdev/SwitchInputMapper.h
index e25c3a5..dbd5a03 100644
--- a/modules/input/evdev/SwitchInputMapper.h
+++ b/modules/input/evdev/SwitchInputMapper.h
@@ -39,8 +39,8 @@
     void processSwitch(int32_t switchCode, int32_t switchValue);
     void sync(nsecs_t when);
 
-    BitSet32 mSwitchValues;
-    BitSet32 mUpdatedSwitchMask;
+    BitSet64 mSwitchValues;
+    BitSet64 mUpdatedSwitchMask;
 };
 
 }  // namespace android