Merge tag 'android-10.0.0_r40' into q

Android 10.0.0 release 40

Change-Id: I5e21fbf09a917c6fcc60ea3969ee3e05ac135502
diff --git a/Android.mk b/Android.mk
index 826a88d..26d26fe 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,6 +1,6 @@
 # TODO:  Find a better way to separate build configs for ADP vs non-ADP devices
 ifneq ($(TARGET_BOARD_AUTO),true)
-  ifneq ($(filter msm8960 msm8226 msm8x26 msm8x84 msm8084 msm8992 msm8994 msm8996 msm8909 msm8952 msm8998 sdm845 sdm710,$(TARGET_BOARD_PLATFORM)),)
+  ifneq ($(filter msm8960 msm8226 msm8x26 msm8974 msm8x74 msm8x84 msm8084 msm8992 msm8994 msm8996 msm8909 msm8952 msm8998 sdm845 sdm710,$(TARGET_BOARD_PLATFORM)),)
 
     MY_LOCAL_PATH := $(call my-dir)
 
diff --git a/hal/Android.mk b/hal/Android.mk
index e6be0a6..edd50bc 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -230,6 +230,8 @@
 
 LOCAL_HEADER_LIBRARIES += libhardware_headers
 
+LOCAL_HEADER_LIBRARIES += generated_kernel_headers
+
 LOCAL_MODULE := audio.primary.$(TARGET_BOARD_PLATFORM)
 
 LOCAL_MODULE_RELATIVE_PATH := hw
diff --git a/hal/acdb.c b/hal/acdb.c
index 58f219a..0c008e1 100644
--- a/hal/acdb.c
+++ b/hal/acdb.c
@@ -99,7 +99,13 @@
         ctl = mixer_get_ctl_by_name(mixer, CVD_VERSION_MIXER_CTL);
         if (!ctl) {
             ALOGE("%s: Could not get ctl for mixer cmd - %s",  __func__, CVD_VERSION_MIXER_CTL);
-            goto cleanup;
+            /* CVD is required for ACDB v2/3, so fail fully there.
+             * For ACDB v1, the CVD version code can be skipped.
+             */
+            if (my_data->acdb_init_v2 || my_data->acdb_init_v3)
+                goto cleanup;
+            else
+                goto card_name;
         }
         mixer_ctl_update(ctl);
 
@@ -114,6 +120,7 @@
         }
     }
 
+card_name:
     /* Get Sound card name */
     snd_card_name = strdup(mixer_get_name(mixer));
     if (!snd_card_name) {
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 17bb6f6..dabc411 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -6282,6 +6282,10 @@
 static int adev_close(hw_device_t *device)
 {
     size_t i;
+    struct audio_device *adev_temp = (struct audio_device *)device;
+
+    if (!adev_temp)
+        return 0;
 
     pthread_mutex_lock(&adev_init_lock);
     if (!device || ((struct audio_device *)device != adev))
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index ae65ef2..8793ae3 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -38,7 +38,7 @@
  * This is the sysfs path for the HDMI audio data block
  */
 #define AUDIO_DATA_BLOCK_PATH "/sys/class/graphics/fb1/audio_data_block"
-#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
+#define MIXER_XML_PATH "mixer_paths.xml"
 
 /*
  * This file will have a maximum of 38 bytes:
@@ -134,6 +134,7 @@
     [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
     [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
     [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
+    [SND_DEVICE_OUT_VOICE_MUSIC_TX] = "voice-music-tx",
     [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
     [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
     [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
@@ -190,6 +191,7 @@
     [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
     [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
     [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
+    [SND_DEVICE_OUT_VOICE_MUSIC_TX] = 3,
     [SND_DEVICE_OUT_USB_HEADSET] = 45,
     [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
     [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
@@ -268,12 +270,35 @@
     return 0;
 }
 
+// Treblized config files will be located in /odm/etc or /vendor/etc.
+static const char *kConfigLocationList[] =
+        {"/odm/etc", "/vendor/etc", "/system/etc"};
+static const int kConfigLocationListSize =
+        (sizeof(kConfigLocationList) / sizeof(kConfigLocationList[0]));
+
+bool resolveConfigFile(char file_name[MIXER_PATH_MAX_LENGTH]) {
+    char full_config_path[MIXER_PATH_MAX_LENGTH];
+    for (int i = 0; i < kConfigLocationListSize; i++) {
+        snprintf(full_config_path,
+                 MIXER_PATH_MAX_LENGTH,
+                 "%s/%s",
+                 kConfigLocationList[i],
+                 file_name);
+        if (F_OK == access(full_config_path, 0)) {
+            strcpy(file_name, full_config_path);
+            return true;
+        }
+    }
+    return false;
+}
+
 void *platform_init(struct audio_device *adev)
 {
     char platform[PROPERTY_VALUE_MAX];
     char baseband[PROPERTY_VALUE_MAX];
     char value[PROPERTY_VALUE_MAX];
     struct platform_data *my_data;
+    char mixer_xml_file[MIXER_PATH_MAX_LENGTH] = MIXER_XML_PATH;
 
     adev->mixer = mixer_open(MIXER_CARD);
 
@@ -282,7 +307,8 @@
         return NULL;
     }
 
-    adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
+    resolveConfigFile(mixer_xml_file);
+    adev->audio_route = audio_route_init(MIXER_CARD, mixer_xml_file);
     if (!adev->audio_route) {
         ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
         return NULL;
@@ -584,6 +610,11 @@
     return ret;
 }
 
+int platform_set_mic_break_det(void *platform __unused, bool enable __unused)
+{
+    return 0;
+}
+
 void platform_set_speaker_gain_in_combo(struct audio_device *adev __unused,
                                         snd_device_t snd_device  __unused,
                                         bool enable __unused) {
@@ -1372,6 +1403,11 @@
     return -ENOSYS;
 }
 
+bool platform_set_microphone_map(void *platform __unused, snd_device_t in_snd_device __unused,
+                                 const struct mic_info *info __unused) {
+    return false;
+}
+
 int platform_get_active_microphones(void *platform __unused, unsigned int channels __unused,
                                     audio_usecase_t usecase __unused,
                                     struct audio_microphone_characteristic_t *mic_array __unused,
diff --git a/hal/msm8960/platform.h b/hal/msm8960/platform.h
index d2bcd0c..f73a042 100644
--- a/hal/msm8960/platform.h
+++ b/hal/msm8960/platform.h
@@ -51,12 +51,14 @@
     SND_DEVICE_OUT_BT_SCO_WB,
     SND_DEVICE_OUT_BT_A2DP,
     SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP,
+    SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP,
     SND_DEVICE_OUT_VOICE_HANDSET_TMUS,
     SND_DEVICE_OUT_VOICE_HANDSET,
     SND_DEVICE_OUT_VOICE_HAC_HANDSET,
     SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES,
     SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES,
     SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET,
+    SND_DEVICE_OUT_VOICE_MUSIC_TX,
     SND_DEVICE_OUT_USB_HEADSET,
     SND_DEVICE_OUT_USB_HEADPHONES,
     SND_DEVICE_OUT_VOICE_USB_HEADSET,
@@ -79,7 +81,9 @@
     SND_DEVICE_IN_VOICE_HEADSET_MIC,
     SND_DEVICE_IN_HDMI_MIC,
     SND_DEVICE_IN_BT_SCO_MIC,
+    SND_DEVICE_IN_BT_SCO_MIC_NREC,
     SND_DEVICE_IN_BT_SCO_MIC_WB,
+    SND_DEVICE_IN_BT_SCO_MIC_WB_NREC,
     SND_DEVICE_IN_CAMCORDER_MIC,
     SND_DEVICE_IN_CAPTURE_VI_FEEDBACK,
     SND_DEVICE_IN_VOICE_DMIC_EF,
diff --git a/post_proc/Android.mk b/post_proc/Android.mk
index ce84e41..c12db2d 100644
--- a/post_proc/Android.mk
+++ b/post_proc/Android.mk
@@ -38,6 +38,9 @@
 
 LOCAL_HEADER_LIBRARIES += libhardware_headers
 LOCAL_HEADER_LIBRARIES += libsystem_headers
+
+LOCAL_HEADER_LIBRARIES += generated_kernel_headers
+
 include $(BUILD_SHARED_LIBRARY)
 endif
 
@@ -70,6 +73,9 @@
 
 LOCAL_HEADER_LIBRARIES += libhardware_headers
 LOCAL_HEADER_LIBRARIES += libsystem_headers
+
+LOCAL_HEADER_LIBRARIES += generated_kernel_headers
+
 include $(BUILD_SHARED_LIBRARY)
 
 endif
@@ -103,6 +109,9 @@
 
 LOCAL_HEADER_LIBRARIES += libhardware_headers
 LOCAL_HEADER_LIBRARIES += libsystem_headers
+
+LOCAL_HEADER_LIBRARIES += generated_kernel_headers
+
 include $(BUILD_SHARED_LIBRARY)
 
 endif