policy_hal: Prevent Sound Trigger capture on USB headset
Sound Trigger detection is not supported on USB headset, so
the capture streams should not start on USB headset. This
change prevents USB headset device selection for Sound
Trigger capture streams.
Change-Id: I238ab26a7a9d206d6b2f8e92b35be74b051b31ed
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index 8216fc8..39cb42e 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1953,17 +1953,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