Merge "Set Orientation TKV for Enqore during device switch"
diff --git a/configs/kalama/mixer_paths_kalama_aim.xml b/configs/kalama/mixer_paths_kalama_aim.xml
index dd4b367..c85fb7d 100644
--- a/configs/kalama/mixer_paths_kalama_aim.xml
+++ b/configs/kalama/mixer_paths_kalama_aim.xml
@@ -1094,17 +1094,12 @@
         <ctl name="TX_AIF1_CAP Mixer DEC3" value="1" />
         <ctl name="TX DEC2 MUX" value="SWR_MIC" />
         <ctl name="TX DEC3 MUX" value="SWR_MIC" />
-        <ctl name="TX SMIC MUX2" value="SWR_MIC4" />
-        <ctl name="TX SMIC MUX3" value="SWR_MIC5" />
-        <ctl name="TX0 MODE" value="ADC_LP" />
-        <ctl name="TX3 MODE" value="ADC_LP" />
-        <ctl name="ADC2 MUX" value="INP3" />
-        <ctl name="ADC1 ChMap" value="SWRM_TX2_CH1" />
-        <ctl name="ADC2 ChMap" value="SWRM_TX2_CH2" />
-        <ctl name="ADC1_MIXER Switch" value="1" />
-        <ctl name="ADC2_MIXER Switch" value="1" />
-        <ctl name="AMIC1_MIXER Switch" value="1" />
-        <ctl name="AMIC3_MIXER Switch" value="1" />
+        <ctl name="TX SMIC MUX2" value="SWR_MIC1" />
+        <ctl name="TX SMIC MUX3" value="SWR_MIC3" />
+        <ctl name="DMIC1 ChMap" value="SWRM_TX1_CH2" />
+        <ctl name="DMIC3 ChMap" value="SWRM_TX1_CH4" />
+        <ctl name="DMIC1_MIXER Switch" value="1" />
+        <ctl name="DMIC3_MIXER Switch" value="1" />
     </path>
 
     <path name="speaker-dmic-endfire">
diff --git a/configs/kalama/resourcemanager_kalama_rb5_gen2_dvt.xml b/configs/kalama/resourcemanager_kalama_rb5_gen2_dvt.xml
index 6ef74c6..fec0183 100644
--- a/configs/kalama/resourcemanager_kalama_rb5_gen2_dvt.xml
+++ b/configs/kalama/resourcemanager_kalama_rb5_gen2_dvt.xml
@@ -28,7 +28,7 @@
 
 * Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
 *
-* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+* Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted (subject to the limitations in the
@@ -912,11 +912,13 @@
         </out-device>
         <out-device>
             <id>PAL_DEVICE_OUT_HDMI</id>
-            <back_end_name>DISPLAY_PORT-RX</back_end_name>
-            <max_channels>32</max_channels>
+            <back_end_name>MI2S-LPAIF-RX-SECONDARY</back_end_name>
+            <max_channels>2</max_channels>
             <channels>2</channels>
             <fractional_sr>1</fractional_sr>
-            <snd_device_name>display-port</snd_device_name>
+            <snd_device_name>hdmi-port</snd_device_name>
+            <samplerate>48000</samplerate>
+            <bit_width>16</bit_width>
             <usecase>
                 <name>PAL_STREAM_VOICE_CALL</name>
                 <priority>1</priority>
diff --git a/resource_manager/src/ResourceManager.cpp b/resource_manager/src/ResourceManager.cpp
index 61d7ed2..ffd926e 100644
--- a/resource_manager/src/ResourceManager.cpp
+++ b/resource_manager/src/ResourceManager.cpp
@@ -8983,7 +8983,7 @@
     }
 
     getOrphanStream_l(orphanStreams, retryStreams);
-    if (activeStreams.empty() && orphanStreams.empty()) {
+    if (activeStreams.empty() && orphanStreams.empty() && retryStreams.empty()) {
         PAL_DBG(LOG_TAG, "no active streams found");
         mActiveStreamMutex.unlock();
         goto exit;
@@ -9009,6 +9009,24 @@
         }
     }
 
+    // retry all streams which failed to switch to desired device previously.
+    for (sIter = retryStreams.begin(); sIter != retryStreams.end(); sIter++) {
+        (*sIter)->lockStreamMutex();
+        if (std::find((*sIter)->suspendedDevIds.begin(), (*sIter)->suspendedDevIds.end(),
+            a2dpDattr.id) != (*sIter)->suspendedDevIds.end()) {
+            std::vector<std::shared_ptr<Device>> devices;
+            (*sIter)->getAssociatedDevices(devices);
+            if (devices.size() > 0) {
+                for (auto device : devices) {
+                    streamDevDisconnect.push_back({ (*sIter), device->getSndDeviceId() });
+                }
+            }
+            restoredStreams.push_back((*sIter));
+            streamDevConnect.push_back({ (*sIter), &a2dpDattr });
+        }
+        (*sIter)->unlockStreamMutex();
+    }
+
     if (restoredStreams.empty()) {
         PAL_DBG(LOG_TAG, "no streams to be restored");
         mActiveStreamMutex.unlock();
@@ -9981,6 +9999,11 @@
                 struct pal_stream_attributes sAttr;
                 Stream* stream = NULL;
                 std::vector<Stream*> activestreams;
+                struct pal_device sco_tx_dattr;
+                std::shared_ptr<Device> sco_tx_dev = nullptr;
+                std::vector<Stream*>::iterator sIter;
+                pal_stream_type_t streamType;
+
 
                 mActiveStreamMutex.lock();
                 sco_rx_dattr.id = PAL_DEVICE_OUT_BLUETOOTH_SCO;
@@ -10001,6 +10024,26 @@
                         mActiveStreamMutex.lock();
                     }
                 }
+
+                /* Handle bt sco running usecase */
+                sco_tx_dattr.id = PAL_DEVICE_IN_BLUETOOTH_SCO_HEADSET;
+                if (isDeviceAvailable(sco_tx_dattr.id)) {
+                    sco_tx_dev = Device::getInstance(&sco_tx_dattr, rm);
+                    getActiveStream_l(activestreams, sco_tx_dev);
+                    for (sIter = activestreams.begin(); sIter != activestreams.end(); sIter++) {
+                        status = (*sIter)->getStreamType(&streamType);
+                        if (0 != status) {
+                            PAL_ERR(LOG_TAG, "getStreamType failed with status = %d", status);
+                            continue;
+                        }
+                        if ((streamType == PAL_STREAM_VOIP_TX) ||
+                            (streamType == PAL_STREAM_DEEP_BUFFER)) {
+                            (*sIter)->suspendedDevIds.clear();
+                            (*sIter)->suspendedDevIds.push_back(a2dp_dattr.id);
+                            PAL_DBG(LOG_TAG, "a2dp resumed, mark sco streams as to route them later");
+                        }
+                    }
+                }
                 mActiveStreamMutex.unlock();
             }
 
diff --git a/session/src/SessionAlsaPcm.cpp b/session/src/SessionAlsaPcm.cpp
index 0fefbdf..e34436a 100644
--- a/session/src/SessionAlsaPcm.cpp
+++ b/session/src/SessionAlsaPcm.cpp
@@ -2426,8 +2426,10 @@
         {
             pal_param_device_rotation_t *rotation =
                                          (pal_param_device_rotation_t *)payload;
-            status = handleDeviceRotation(streamHandle, rotation->rotation_type,
-                                          device, mixer, builder, rxAifBackEnds);
+            if (!rxAifBackEnds.empty()) {
+                status = handleDeviceRotation(streamHandle, rotation->rotation_type,
+                                              device, mixer, builder, rxAifBackEnds);
+            }
             goto exit;
         }
         case PAL_PARAM_ID_LOAD_SOUND_MODEL: