Merge tag 'LA.UM.8.6.r1-02900-89xx.0' of https://source.codeaurora.cn/quic/la/platform/hardware/qcom/audio into HEAD

"LA.UM.8.6.r1-02900-89xx.0"

Change-Id: Idd795b59803a42c331416871be0fcd998b5454c8
diff --git a/configs/msm8937/audio_effects.xml b/configs/msm8937/audio_effects.xml
index d27ac23..aa6e585 100644
--- a/configs/msm8937/audio_effects.xml
+++ b/configs/msm8937/audio_effects.xml
@@ -41,6 +41,7 @@
         <library name="proxy" path="libeffectproxy.so"/>
         <library name="offload_bundle" path="libqcompostprocbundle.so"/>
         <library name="audio_pre_processing" path="libqcomvoiceprocessing.so"/>
+        <library name="audiosphere" path="libasphere.so"/>
     </libraries>
     <effects>
         <effectProxy name="bassboost" library="proxy" uuid="14804144-a5ee-4d24-aa88-0002a5d5c51b">
@@ -82,6 +83,7 @@
         <effect name="dynamics_processing" library="dynamics_processing" uuid="e0e6539b-1781-7261-676f-6d7573696340"/>
         <effect name="aec" library="audio_pre_processing" uuid="0f8d0d2a-59e5-45fe-b6e4-248c8a799109"/>
         <effect name="ns" library="audio_pre_processing" uuid="1d97bb0b-9e2f-4403-9ae3-58c2554306f8"/>
+        <effect name="audiosphere" library="audiosphere" uuid="184e62ab-2d19-4364-9d1b-c0a40733866c"/>
     </effects>
     <preprocess>
         <stream type="voice_communication">
diff --git a/configs/msm8937/mixer_paths_sdm439_pm8953.xml b/configs/msm8937/mixer_paths_sdm439_pm8953.xml
index 328701c..8fbce19 100644
--- a/configs/msm8937/mixer_paths_sdm439_pm8953.xml
+++ b/configs/msm8937/mixer_paths_sdm439_pm8953.xml
@@ -1317,6 +1317,11 @@
         <path name="headphones" />
     </path>
 
+    <path name="wsa-speaker-and-headphones">
+        <path name="wsa-speaker" />
+        <path name="headphones" />
+    </path>
+
     <path name="usb-headphones">
     </path>
 
diff --git a/configs/msm8953/audio_effects.xml b/configs/msm8953/audio_effects.xml
index d27ac23..aa6e585 100644
--- a/configs/msm8953/audio_effects.xml
+++ b/configs/msm8953/audio_effects.xml
@@ -41,6 +41,7 @@
         <library name="proxy" path="libeffectproxy.so"/>
         <library name="offload_bundle" path="libqcompostprocbundle.so"/>
         <library name="audio_pre_processing" path="libqcomvoiceprocessing.so"/>
+        <library name="audiosphere" path="libasphere.so"/>
     </libraries>
     <effects>
         <effectProxy name="bassboost" library="proxy" uuid="14804144-a5ee-4d24-aa88-0002a5d5c51b">
@@ -82,6 +83,7 @@
         <effect name="dynamics_processing" library="dynamics_processing" uuid="e0e6539b-1781-7261-676f-6d7573696340"/>
         <effect name="aec" library="audio_pre_processing" uuid="0f8d0d2a-59e5-45fe-b6e4-248c8a799109"/>
         <effect name="ns" library="audio_pre_processing" uuid="1d97bb0b-9e2f-4403-9ae3-58c2554306f8"/>
+        <effect name="audiosphere" library="audiosphere" uuid="184e62ab-2d19-4364-9d1b-c0a40733866c"/>
     </effects>
     <preprocess>
         <stream type="voice_communication">
diff --git a/configs/msm8953/audio_platform_info_extcodec.xml b/configs/msm8953/audio_platform_info_extcodec.xml
index 66d2ecc..d7c713d 100644
--- a/configs/msm8953/audio_platform_info_extcodec.xml
+++ b/configs/msm8953/audio_platform_info_extcodec.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<!-- Copyright (c) 2015 - 2016, 2018, The Linux Foundation. All rights reserved.         -->
+<!-- Copyright (c) 2015 - 2016, 2018 - 2019, The Linux Foundation. All rights reserved.         -->
 <!--                                                                        -->
 <!-- Redistribution and use in source and binary forms, with or without     -->
 <!-- modification, are permitted provided that the following conditions are -->
@@ -47,13 +47,11 @@
         <usecase name="USECASE_VOICEMMODE1_CALL" type="out" id="35"/>
         <usecase name="USECASE_VOICEMMODE2_CALL" type="in" id="36"/>
         <usecase name="USECASE_VOICEMMODE2_CALL" type="out" id="36"/>
-        <usecase name="USECASE_AUDIO_SPKR_CALIB_TX" type="in" id="37"/>
+        <usecase name="USECASE_AUDIO_SPKR_CALIB_TX" type="in" id="40"/>
         <usecase name="USECASE_QCHAT_CALL" type="in" id="42"/>
         <usecase name="USECASE_QCHAT_CALL" type="out" id="42"/>
     </pcm_ids>
     <config_params>
-        <param key="spkr_1_tz_name" value="wsatz.11"/>
-        <param key="spkr_2_tz_name" value="wsatz.12"/>
         <param key="native_audio_mode" value="src"/>
         <param key="input_mic_max_count" value="4"/>
     </config_params>
diff --git a/configs/msm8953/msm8953.mk b/configs/msm8953/msm8953.mk
index 8f9975d..cb7363a 100644
--- a/configs/msm8953/msm8953.mk
+++ b/configs/msm8953/msm8953.mk
@@ -238,6 +238,10 @@
 PRODUCT_PROPERTY_OVERRIDES += \
 vendor.audio.flac.sw.decoder.24bit=true
 
+#read wsatz name from thermal zone type
+PRODUCT_PROPERTY_OVERRIDES += \
+vendor.audio.read.wsatz.type=true
+
 #Set AudioFlinger client heap size
 PRODUCT_PROPERTY_OVERRIDES += \
 ro.af.client_heap_size_kbyte=7168
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 48a348a..1187642 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -1025,10 +1025,12 @@
 #ifndef FM_POWER_OPT
 #define audio_extn_fm_set_parameters(adev, parms) (0)
 #define audio_extn_fm_get_parameters(query, reply) (0)
+#define audio_extn_fm_route_on_selected_device(adev, device) (0)
 #else
 void audio_extn_fm_set_parameters(struct audio_device *adev,
                                    struct str_parms *parms);
 void audio_extn_fm_get_parameters(struct str_parms *query, struct str_parms *reply);
+void audio_extn_fm_route_on_selected_device(struct audio_device *adev, audio_devices_t device);
 #endif
 
 #ifndef APTX_DECODER_ENABLED
diff --git a/hal/audio_extn/fm.c b/hal/audio_extn/fm.c
index 9bb0b33..8d7c90e 100644
--- a/hal/audio_extn/fm.c
+++ b/hal/audio_extn/fm.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2019 The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -389,4 +389,25 @@
 exit:
     ALOGV("%s: exit", __func__);
 }
+
+void audio_extn_fm_route_on_selected_device(struct audio_device *adev, audio_devices_t device)
+{
+    struct listnode *node;
+    struct audio_usecase *usecase;
+
+    if (fmmod.is_fm_running) {
+        list_for_each(node, &adev->usecase_list) {
+            usecase = node_to_item(node, struct audio_usecase, list);
+            if (usecase->id == USECASE_AUDIO_PLAYBACK_FM) {
+                if (fmmod.fm_device != device) {
+                    ALOGV("%s selected routing device %x current device %x"
+                          "are different, reroute on selected device", __func__,
+                          fmmod.fm_device, device);
+                    select_devices(adev, usecase->id);
+                }
+            }
+        }
+    }
+}
+
 #endif /* FM_POWER_OPT end */
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index e2e0015..072e3f9 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -1347,20 +1347,28 @@
 {
     int err;
 
-    err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SPKR_TZ_1,
-                            value, len);
-    if (err >= 0) {
-        tz_names.spkr_1_name = strdup(value);
-        str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_TZ_1);
-    }
+    if (property_get_bool("vendor.audio.read.wsatz.type", false)) {
+        if ((!tz_names.spkr_2_name) && (strstr(value, "wsa"))) {
+            tz_names.spkr_2_name = strdup(value);
+        } else if ((!tz_names.spkr_1_name) && (strstr(value, "wsa"))) {
+                   tz_names.spkr_1_name = strdup(value);
+        }
+    } else {
 
-    err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SPKR_TZ_2,
+        err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SPKR_TZ_1,
                             value, len);
-    if (err >= 0) {
-        tz_names.spkr_2_name = strdup(value);
-        str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_TZ_2);
-    }
+        if (err >= 0) {
+            tz_names.spkr_1_name = strdup(value);
+            str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_TZ_1);
+        }
 
+        err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SPKR_TZ_2,
+                            value, len);
+        if (err >= 0) {
+            tz_names.spkr_2_name = strdup(value);
+            str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_TZ_2);
+        }
+    }
     ALOGV("%s: tz1: %s, tz2: %s", __func__,
           tz_names.spkr_1_name, tz_names.spkr_2_name);
 }
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index ec87f41..54d01c0 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -3732,6 +3732,8 @@
         if (do_stop) {
             stop_output_stream(out);
         }
+        // if fm is active route on selected device in UI
+        audio_extn_fm_route_on_selected_device(adev, out->devices);
         pthread_mutex_unlock(&adev->lock);
     }
     pthread_mutex_unlock(&out->lock);
@@ -7301,7 +7303,8 @@
 
 #ifndef COMPRESS_VOIP_ENABLED
     if (valid_rate && valid_ch &&
-        in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) {
+        (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION ||
+         in->source == AUDIO_SOURCE_VOICE_COMMUNICATION)) {
         in->usecase = USECASE_AUDIO_RECORD_VOIP;
         in->config = default_pcm_config_voip_copp;
         in->config.period_size = VOIP_IO_BUF_SIZE(in->sample_rate,
@@ -7317,8 +7320,9 @@
 #else
     //XXX needed for voice_extn_compress_voip_open_input_stream
     in->config.rate = config->sample_rate;
-    if ((in->dev->mode == AUDIO_MODE_IN_COMMUNICATION ||
-         voice_extn_compress_voip_is_active(in->dev)) &&
+    if((in->dev->mode == AUDIO_MODE_IN_COMMUNICATION ||
+        in->source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
+        voice_extn_compress_voip_is_active(in->dev)) &&
         (voice_extn_compress_voip_is_format_supported(in->format)) &&
         valid_rate && valid_ch) {
         voice_extn_compress_voip_open_input_stream(in);
@@ -7419,13 +7423,6 @@
     in->bit_width = 16;
     in->af_period_multiplier = 1;
 
-    /* Update config params with the requested sample rate and channels */
-    if ((in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) &&
-          (adev->mode != AUDIO_MODE_IN_CALL)) {
-        ret = -EINVAL;
-        goto err_open;
-    }
-
     if (is_usb_dev && may_use_hifi_record) {
         /* HiFi record selects an appropriate format, channel, rate combo
            depending on sink capabilities*/
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 9e9bc61..5305250 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -2063,7 +2063,6 @@
     }
 
     while ((tdirent = readdir(tdir))) {
-        char buf[50];
         struct dirent *tzdirent;
         DIR *tzdir = NULL;
 
@@ -2071,18 +2070,24 @@
         if (!tzdir)
             continue;
         while ((tzdirent = readdir(tzdir))) {
+            char buf[50] = {0};
             if (strcmp(tzdirent->d_name, "type"))
                 continue;
             snprintf(name, MAX_PATH, TZ_TYPE, tzn);
             ALOGD("Opening %s\n", name);
             read_line_from_file(name, buf, sizeof(buf));
             if (strstr(buf, file)) {
+                if (property_get_bool("vendor.audio.read.wsatz.type", false)) {
+                    struct str_parms *parms = NULL;
+                    buf[strlen(buf) - 1] = '\0';
+                    audio_extn_spkr_prot_set_parameters(parms, buf, 0);
+                }
                 wsa_count++;
-                /*We support max only two WSA speakers*/
-                if (wsa_count == 2)
-                    break;
             }
             tzn++;
+            /*We support max only two WSA speakers*/
+            if (wsa_count == 2)
+                break;
         }
         closedir(tzdir);
     }