hal: check for usb card state before setting in/out device
During record, audio record usecase still uses usb-headset-mic
as input device even if usb-headset is plugged out. It causes
record fail and mute issue happen.
Fix it by adding check for USB card state, and routing input
device to handset, output device to speaker when usb card is
not existed.
CRs-Fixed: 2264971
Change-Id: Ibfe43c4795a76bf386ab9008a632ef07aa1c7f28
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 16ac7f4..1fc0f68 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -5687,6 +5687,13 @@
(devices != AUDIO_DEVICE_OUT_USB_ACCESSORY);
bool direct_dev = is_hdmi || is_usb_dev;
+ if (is_usb_dev && (audio_extn_usb_connected(NULL))) {
+ is_usb_dev = false;
+ devices = AUDIO_DEVICE_OUT_SPEAKER;
+ ALOGW("%s: ignore set device to non existing USB card, use output device(%#x)",
+ __func__, devices);
+ }
+
*stream_out = NULL;
out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
@@ -6788,6 +6795,13 @@
flags,
source);
+ if (is_usb_dev && (audio_extn_usb_connected(NULL))) {
+ is_usb_dev = false;
+ devices = AUDIO_DEVICE_IN_BUILTIN_MIC;
+ ALOGW("%s: ignore set device to non existing USB card, use input device(%#x)",
+ __func__, devices);
+ }
+
*stream_in = NULL;
if (!(is_usb_dev && may_use_hifi_record)) {