Routing to usb was rejected due to incorrect card number
Fixes regression introduced by: f9f241e45e5a76458e5f5596bca495317981ca3a
The card number is updated by adev_set_parameters,
that is called after out_set_parameters.
As a result, out_set_parameters was using the wrong card number to check
for the card presence (in an attempt to ignore rerouting to an unplug
card).
Thus all routing to USB we denied.
Bug: 64532887
Test: Plug and unplug usb headset (skylab) during Photo playback,
Youtube, Play music and voice call.
Change-Id: I148a0b35067703e6ba3ca3414d3afe9cf6718dc0
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 5b5a434..49eacb0 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2184,6 +2184,15 @@
return out == adev->primary_output || out == adev->voice_tx_output;
}
+static int get_alive_usb_card(struct str_parms* parms) {
+ int card;
+ if ((str_parms_get_int(parms, "card", &card) >= 0) &&
+ !audio_extn_usb_alive(card)) {
+ return card;
+ }
+ return -ENODEV;
+}
+
static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
struct stream_out *out = (struct stream_out *)stream;
@@ -2221,9 +2230,11 @@
// Workaround: If routing to an non existing usb device, fail gracefully
// The routing request will otherwise block during 10 second
- if (audio_is_usb_out_device(new_dev) && !audio_extn_usb_alive(adev->snd_card)) {
- ALOGW("out_set_parameters() ignoring rerouting to non existing USB card %d",
- adev->snd_card);
+ int card;
+ if (audio_is_usb_out_device(new_dev) &&
+ (card = get_alive_usb_card(parms)) >= 0) {
+
+ ALOGW("out_set_parameters() ignoring rerouting to non existing USB card %d", card);
pthread_mutex_unlock(&adev->lock);
pthread_mutex_unlock(&out->lock);
status = -ENOSYS;
@@ -3141,9 +3152,11 @@
// Workaround: If routing to an non existing usb device, fail gracefully
// The routing request will otherwise block during 10 second
- if (audio_is_usb_in_device(val) && !audio_extn_usb_alive(adev->snd_card)) {
- ALOGW("in_set_parameters() ignoring rerouting to non existing USB card %d",
- adev->snd_card);
+ int card;
+ if (audio_is_usb_in_device(val) &&
+ (card = get_alive_usb_card(parms)) >= 0) {
+
+ ALOGW("in_set_parameters() ignoring rerouting to non existing USB card %d", card);
status = -ENOSYS;
} else {