hal: Fix wrong output device for voip/music concurrent playback

If music stream is being played through speaker background during
voip call, and later when setForceUse is called with FORCE_NONE
during MODE_NORMAL, phone strategy routing will be switched to handset
device for primary output and this incidentally routes music stream to
handset from HAL side, while device in APM still keeps as speaker for
music. Then after primary output is stopped, it will restore the device
to speaker for music stream, while this routing call is ignored due to
same device on cur_output and output descriptor in APM::stopSource, and makes
music continues on handset.

Handle the restration from HAL side when device mismatch in APM and HAL.

CRs-Fixed: 2070874
Change-Id: I08529cbb148233452d6f8f3e2eed0f88c99dc573
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 662032f..ac7e16d 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2766,6 +2766,8 @@
 {
     struct stream_out *out = (struct stream_out *)stream;
     struct audio_device *adev = out->dev;
+    struct audio_usecase *uc_info;
+    struct listnode *node;
 
     ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__,
           stream, out->usecase, use_case_table[out->usecase]);
@@ -2804,6 +2806,13 @@
             }
         }
         stop_output_stream(out);
+        //restore output device for active usecase when current snd device and output device mismatch
+        list_for_each(node, &adev->usecase_list) {
+            uc_info = node_to_item(node, struct audio_usecase, list);
+            if ((uc_info->type == PCM_PLAYBACK) &&
+                (uc_info->out_snd_device != platform_get_output_snd_device(adev->platform, uc_info->stream.out)))
+                select_devices(adev, uc_info->id);
+        }
         pthread_mutex_unlock(&adev->lock);
     }
     pthread_mutex_unlock(&out->lock);