Merge "hal: switch to current active device when a2dp suspended"
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index ef31aae..eba044b 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -10444,9 +10444,11 @@
 int check_a2dp_restore_l(struct audio_device *adev, struct stream_out *out, bool restore)
 {
     struct audio_usecase *uc_info;
+    struct audio_usecase *usecase;
     float left_p;
     float right_p;
     struct listnode devices;
+    struct listnode *node;
 
     uc_info = get_usecase_from_list(adev, out->usecase);
     if (uc_info == NULL) {
@@ -10482,9 +10484,17 @@
         pthread_mutex_lock(&out->latch_lock);
         // mute stream and switch to speaker if suspended
         if (!out->a2dp_muted && !out->standby) {
-            ALOGD("%s: selecting speaker and muting stream", __func__);
             assign_devices(&devices, &out->device_list);
             reassign_device_list(&out->device_list, AUDIO_DEVICE_OUT_SPEAKER, "");
+            list_for_each(node, &adev->usecase_list) {
+                usecase = node_to_item(node, struct audio_usecase, list);
+                if ((usecase != uc_info) &&
+                        platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
+                                                      usecase->out_snd_device)) {
+                    assign_devices(&out->device_list, &usecase->stream.out->device_list);
+                    break;
+                }
+            }
             left_p = out->volume_l;
             right_p = out->volume_r;
             out->a2dp_muted = true;
@@ -10503,6 +10513,8 @@
                 usleep(latency * 1000);
             }
             select_devices(adev, out->usecase);
+            ALOGD("%s: switched to device:%s and mute stream",
+                   __func__, platform_get_snd_device_name(uc_info->out_snd_device));
             if (is_offload_usecase(out->usecase)) {
                 if (out->offload_state == OFFLOAD_STATE_PLAYING)
                     compress_resume(out->compr);