Merge tag 'AUDIO.LA.8.0.r1-10200-KAILUA.0' into staging/lineage-21.0_merge-AUDIO.LA.8.0.r1-10200-KAILUA.0

AUDIO.LA.8.0.r1-10200-KAILUA.0

# By Anand Mohan (1) and others
# Via Gerrit - the friendly Code Review server (3) and others
* tag 'AUDIO.LA.8.0.r1-10200-KAILUA.0':
  pal: avoid implicit device switch during resume if call is active
  PAL: setMixerParameter after all the custom payload updated done
  pal: update the sva/tri/quad mic related mixer path for kalama
  Bluetooth: Add conditional check to call init

Change-Id: I25febeb305bd5ffbb103c9fc76a22484d4784fe7
diff --git a/configs/kalama/mixer_paths_kalama_aim.xml b/configs/kalama/mixer_paths_kalama_aim.xml
index dd86f3d..dd4b367 100644
--- a/configs/kalama/mixer_paths_kalama_aim.xml
+++ b/configs/kalama/mixer_paths_kalama_aim.xml
@@ -887,7 +887,7 @@
         <ctl name="ADC3 MUX" value="INP6" />
         <ctl name="ADC4 ChMap" value="SWRM_TX3_CH2" />
         <ctl name="ADC3 ChMap" value="SWRM_TX2_CH1" />
-        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH1" />
+        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH2" />
         <ctl name="ADC4_MIXER Switch" value="1" />
         <ctl name="ADC3_MIXER Switch" value="1" />
         <ctl name="DMIC1_MIXER Switch" value="1" />
@@ -973,12 +973,14 @@
         <ctl name="VA SMIC MUX0" value="SWR_MIC9" />
         <ctl name="VA SMIC MUX1" value="SWR_MIC4" />
         <ctl name="ADC4 MUX" value="INP5" />
+        <ctl name="ADC3 MUX" value="INP6" />
         <ctl name="ADC4 ChMap" value="SWRM_TX3_CH2" />
         <ctl name="ADC3 ChMap" value="SWRM_TX2_CH1" />
         <ctl name="ADC4_MIXER Switch" value="1" />
         <ctl name="ADC3_MIXER Switch" value="1" />
         <ctl name="VA_AMIC5_MIXER Switch" value="1" />
         <ctl name="VA_AMIC6_MIXER Switch" value="1" />
+        <ctl name="AMIC5_MIXER Switch" value="1" />
         <ctl name="AMIC6_MIXER Switch" value="1" />
     </path>
 
@@ -1003,7 +1005,7 @@
         <ctl name="ADC3 MUX" value="INP6" />
         <ctl name="ADC4 ChMap" value="SWRM_TX3_CH2" />
         <ctl name="ADC3 ChMap" value="SWRM_TX2_CH1" />
-        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH1" />
+        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH2" />
         <ctl name="ADC4_MIXER Switch" value="1" />
         <ctl name="ADC3_MIXER Switch" value="1" />
         <ctl name="DMIC1_MIXER Switch" value="1" />
@@ -1038,7 +1040,7 @@
         <ctl name="ADC3 MUX" value="INP6" />
         <ctl name="ADC4 ChMap" value="SWRM_TX3_CH2" />
         <ctl name="ADC3 ChMap" value="SWRM_TX2_CH1" />
-        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH1" />
+        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH2" />
         <ctl name="DMIC3 ChMap" value="SWRM_TX1_CH4" />
         <ctl name="ADC4_MIXER Switch" value="1" />
         <ctl name="ADC3_MIXER Switch" value="1" />
@@ -1228,22 +1230,20 @@
         <ctl name="TX DEC3 MUX" value="SWR_MIC" />
         <ctl name="TX SMIC MUX1" value="SWR_MIC9" />
         <ctl name="TX SMIC MUX2" value="SWR_MIC4" />
-        <ctl name="TX SMIC MUX3" value="SWR_MIC5" />
+        <ctl name="TX SMIC MUX3" value="SWR_MIC1" />
         <ctl name="ADC4 MUX" value="INP5" />
-        <ctl name="ADC2 MUX" value="INP3" />
+        <ctl name="ADC3 MUX" value="INP6" />
         <ctl name="HDR34 MUX" value="NO_HDR34" />
-        <ctl name="TX2 MODE" value="ADC_LP" />
         <ctl name="TX0 MODE" value="ADC_LP" />
-        <ctl name="TX3 MODE" value="ADC_LP" />
+        <ctl name="TX1 MODE" value="ADC_LP" />
         <ctl name="ADC4 ChMap" value="SWRM_TX3_CH2" />
-        <ctl name="ADC1 ChMap" value="SWRM_TX2_CH1" />
-        <ctl name="ADC2 ChMap" value="SWRM_TX2_CH2" />
+        <ctl name="ADC3 ChMap" value="SWRM_TX2_CH1" />
+        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH2" />
         <ctl name="ADC4_MIXER Switch" value="1" />
-        <ctl name="ADC1_MIXER Switch" value="1" />
-        <ctl name="ADC2_MIXER Switch" value="1" />
+        <ctl name="ADC3_MIXER Switch" value="1" />
+        <ctl name="DMIC1_MIXER Switch" value="1" />
         <ctl name="AMIC5_MIXER Switch" value="1" />
-        <ctl name="AMIC1_MIXER Switch" value="1" />
-        <ctl name="AMIC3_MIXER Switch" value="1" />
+        <ctl name="AMIC6_MIXER Switch" value="1" />
     </path>
 
     <path name="speaker-tmic">
@@ -1255,22 +1255,20 @@
         <ctl name="TX DEC3 MUX" value="SWR_MIC" />
         <ctl name="TX SMIC MUX1" value="SWR_MIC9" />
         <ctl name="TX SMIC MUX2" value="SWR_MIC4" />
-        <ctl name="TX SMIC MUX3" value="SWR_MIC5" />
+        <ctl name="TX SMIC MUX3" value="SWR_MIC1" />
         <ctl name="ADC4 MUX" value="INP5" />
-        <ctl name="ADC2 MUX" value="INP3" />
+        <ctl name="ADC3 MUX" value="INP6" />
         <ctl name="HDR34 MUX" value="NO_HDR34" />
-        <ctl name="TX2 MODE" value="ADC_LP" />
         <ctl name="TX0 MODE" value="ADC_LP" />
-        <ctl name="TX3 MODE" value="ADC_LP" />
+        <ctl name="TX1 MODE" value="ADC_LP" />
         <ctl name="ADC4 ChMap" value="SWRM_TX3_CH2" />
-        <ctl name="ADC1 ChMap" value="SWRM_TX2_CH1" />
-        <ctl name="ADC2 ChMap" value="SWRM_TX2_CH2" />
+        <ctl name="ADC3 ChMap" value="SWRM_TX2_CH1" />
+        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH2" />
         <ctl name="ADC4_MIXER Switch" value="1" />
-        <ctl name="ADC1_MIXER Switch" value="1" />
-        <ctl name="ADC2_MIXER Switch" value="1" />
+        <ctl name="ADC3_MIXER Switch" value="1" />
+        <ctl name="DMIC1_MIXER Switch" value="1" />
         <ctl name="AMIC5_MIXER Switch" value="1" />
-        <ctl name="AMIC1_MIXER Switch" value="1" />
-        <ctl name="AMIC3_MIXER Switch" value="1" />
+        <ctl name="AMIC6_MIXER Switch" value="1" />
     </path>
 
     <path name="voice-speaker-tmic">
@@ -1289,29 +1287,23 @@
         <ctl name="TX DEC4 MUX" value="SWR_MIC" />
         <ctl name="TX SMIC MUX1" value="SWR_MIC9" />
         <ctl name="TX SMIC MUX2" value="SWR_MIC4" />
-        <ctl name="TX SMIC MUX3" value="SWR_MIC5" />
-        <ctl name="TX SMIC MUX4" value="SWR_MIC8" />
+        <ctl name="TX SMIC MUX3" value="SWR_MIC1" />
+        <ctl name="TX SMIC MUX4" value="SWR_MIC3" />
         <ctl name="HDR34 MUX" value="NO_HDR34" />
         <ctl name="ADC4 MUX" value="INP5" />
-        <ctl name="ADC2 MUX" value="INP3" />
-        <ctl name="ADC3 MUX" value="INP4" />
-        <ctl name="ADC2_BCS Disable" value="1" />
-        <ctl name="TX2 MODE" value="ADC_LP" />
+        <ctl name="ADC3 MUX" value="INP6" />
         <ctl name="TX0 MODE" value="ADC_LP" />
-        <ctl name="TX3 MODE" value="ADC_LP" />
         <ctl name="TX1 MODE" value="ADC_LP" />
         <ctl name="ADC4 ChMap" value="SWRM_TX3_CH2" />
-        <ctl name="ADC1 ChMap" value="SWRM_TX2_CH1" />
-        <ctl name="ADC2 ChMap" value="SWRM_TX2_CH2" />
-        <ctl name="ADC3 ChMap" value="SWRM_TX3_CH1" />
+        <ctl name="ADC3 ChMap" value="SWRM_TX2_CH1" />
+        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH2" />
+        <ctl name="DMIC3 ChMap" value="SWRM_TX1_CH4" />
         <ctl name="ADC4_MIXER Switch" value="1" />
-        <ctl name="ADC1_MIXER Switch" value="1" />
-        <ctl name="ADC2_MIXER Switch" value="1" />
         <ctl name="ADC3_MIXER Switch" value="1" />
+        <ctl name="DMIC1_MIXER Switch" value="1" />
+        <ctl name="DMIC3_MIXER Switch" value="1" />
         <ctl name="AMIC5_MIXER Switch" value="1" />
-        <ctl name="AMIC1_MIXER Switch" value="1" />
-        <ctl name="AMIC3_MIXER Switch" value="1" />
-        <ctl name="AMIC4_MIXER Switch" value="1" />
+        <ctl name="AMIC6_MIXER Switch" value="1" />
     </path>
 
     <path name="speaker-qmic-liquid">
diff --git a/device/src/Bluetooth.cpp b/device/src/Bluetooth.cpp
index 709143e..cf17159 100644
--- a/device/src/Bluetooth.cpp
+++ b/device/src/Bluetooth.cpp
@@ -1341,7 +1341,6 @@
     pluginHandler = NULL;
     pluginCodec = NULL;
 
-    init();
     param_bt_a2dp.reconfig = false;
     param_bt_a2dp.a2dp_suspended = false;
     param_bt_a2dp.a2dp_capture_suspended = false;
@@ -1354,6 +1353,10 @@
             isA2dpOffloadSupported);
     param_bt_a2dp.reconfig_supported = isA2dpOffloadSupported;
     param_bt_a2dp.latency = 0;
+
+    if (isA2dpOffloadSupported) {
+        init();
+    }
 }
 
 BtA2dp::~BtA2dp()
@@ -2075,6 +2078,7 @@
 {
     int32_t status = 0;
     pal_param_bta2dp_t* param_a2dp = (pal_param_bta2dp_t *)param;
+    bool skip_switch = false;
 
     if (isA2dpOffloadSupported == false) {
        PAL_VERBOSE(LOG_TAG, "no supported encoders identified,ignoring a2dp setparam");
@@ -2159,7 +2163,12 @@
                     goto exit;
                 }
             }
-            status = rm->a2dpResume(param_a2dp->dev_id);
+
+            if (param_a2dp->dev_id == PAL_DEVICE_OUT_BLUETOOTH_A2DP && param_a2dp->is_in_call)
+                skip_switch = true;
+
+            if (!skip_switch)
+                status = rm->a2dpResume(param_a2dp->dev_id);
         }
         break;
     }
@@ -2246,7 +2255,12 @@
                     goto exit;
                 }
             }
-            rm->a2dpCaptureResume(param_a2dp->dev_id);
+
+            if (param_a2dp->dev_id == PAL_DEVICE_IN_BLUETOOTH_A2DP && param_a2dp->is_in_call)
+                skip_switch = true;
+
+            if (!skip_switch)
+                rm->a2dpCaptureResume(param_a2dp->dev_id);
         }
         break;
     }
diff --git a/inc/PalDefs.h b/inc/PalDefs.h
index e6abbc3..be8c472 100644
--- a/inc/PalDefs.h
+++ b/inc/PalDefs.h
@@ -1176,6 +1176,7 @@
     bool     is_force_switch;
     uint32_t latency;
     pal_device_id_t   dev_id;
+    bool     is_in_call;
 } pal_param_bta2dp_t;
 
 typedef struct pal_param_upd_event_detection {
diff --git a/resource_manager/src/ResourceManager.cpp b/resource_manager/src/ResourceManager.cpp
index dbebbe9..b989f58 100644
--- a/resource_manager/src/ResourceManager.cpp
+++ b/resource_manager/src/ResourceManager.cpp
@@ -9315,7 +9315,7 @@
             std::shared_ptr<Device> dev = nullptr;
             struct pal_device dattr;
             pal_device_id_t st_device;
-            pal_param_bta2dp_t param_bt_a2dp;
+            pal_param_bta2dp_t param_bt_a2dp = {};
 
             PAL_INFO(LOG_TAG, "Device %d connected = %d",
                         device_connection->id,
@@ -9645,7 +9645,7 @@
             std::vector <Stream *> activeA2dpStreams;
             struct pal_device dattr;
             pal_param_bta2dp_t *current_param_bt_a2dp = nullptr;
-            pal_param_bta2dp_t param_bt_a2dp;
+            pal_param_bta2dp_t param_bt_a2dp = {};
             int retrycnt = 20;
             const int retryPeriodMs = 100;
 
@@ -9710,6 +9710,7 @@
             struct pal_device a2dp_dattr;
             pal_param_bta2dp_t *current_param_bt_a2dp = nullptr;
             pal_param_bta2dp_t *param_bt_a2dp = nullptr;
+            bool skip_switch = false;
 
             mResourceManagerMutex.unlock();
             param_bt_a2dp = (pal_param_bta2dp_t*)param_payload;
@@ -9740,7 +9741,10 @@
                 goto exit_no_unlock;
             }
 
-            if (param_bt_a2dp->a2dp_suspended == false) {
+            if (param_bt_a2dp->dev_id == PAL_DEVICE_OUT_BLUETOOTH_A2DP && param_bt_a2dp->is_in_call)
+                skip_switch = true;
+
+            if (param_bt_a2dp->a2dp_suspended == false && !skip_switch) {
                 struct pal_device sco_tx_dattr;
                 struct pal_device sco_rx_dattr;
                 std::shared_ptr<Device> sco_tx_dev = nullptr;
@@ -9929,6 +9933,7 @@
             struct pal_device a2dp_dattr;
             pal_param_bta2dp_t* current_param_bt_a2dp = nullptr;
             pal_param_bta2dp_t* param_bt_a2dp = nullptr;
+            bool skip_switch = false;
 
             mResourceManagerMutex.unlock();
             param_bt_a2dp = (pal_param_bta2dp_t*)param_payload;
@@ -9959,7 +9964,10 @@
                 goto exit_no_unlock;
             }
 
-            if (param_bt_a2dp->a2dp_capture_suspended == false) {
+            if (param_bt_a2dp->dev_id == PAL_DEVICE_IN_BLUETOOTH_A2DP && param_bt_a2dp->is_in_call)
+                skip_switch = true;
+
+            if (param_bt_a2dp->a2dp_capture_suspended == false && !skip_switch) {
                 /* Handle bt sco out running usecase */
                 struct pal_device sco_rx_dattr;
                 struct pal_stream_attributes sAttr;