Merge "policy_hal: avoid VOIP_RX flag is removed for voip call"
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index d84ed16..95c9bd3 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1954,17 +1954,40 @@
         }
     }
 
+    // This workaround prevents Sound Trigger capture streams from
+    // starting on USB headset. Sound Trigger is not supported on
+    // USB headset, so the capture streams should not select USB
+    // headset device. Temporarily remove USB headset devices from
+    // the available devices list while selecting device.
+    bool isSoundTrigger = inputSource == AUDIO_SOURCE_HOTWORD &&
+        mSoundTriggerSessions.indexOfKey(session) >= 0;
+    DeviceVector USBDevices = mAvailableInputDevices.getDevicesFromType(
+                AUDIO_DEVICE_IN_USB_HEADSET);
 
-    return AudioPolicyManager::getInputForAttr(attr,
-                                               input,
-                                               riid,
-                                               session,
-                                               uid,
-                                               config,
-                                               flags,
-                                               selectedDeviceId,
-                                               inputType,
-                                               portId);
+    if (isSoundTrigger) {
+        for (size_t i = 0; i < USBDevices.size(); i++) {
+            mAvailableInputDevices.remove(USBDevices[i]);
+        }
+    }
+
+    status_t status = AudioPolicyManager::getInputForAttr(attr,
+                                                          input,
+                                                          riid,
+                                                          session,
+                                                          uid,
+                                                          config,
+                                                          flags,
+                                                          selectedDeviceId,
+                                                          inputType,
+                                                          portId);
+
+    if (isSoundTrigger) {
+        for (size_t i = 0; i < USBDevices.size(); i++) {
+            mAvailableInputDevices.add(USBDevices[i]);
+        }
+    }
+
+    return status;
 }
 
 uint32_t AudioPolicyManagerCustom::activeNonSoundTriggerInputsCountOnDevices(audio_devices_t devices) const