audio: stop call before changing playback path route

When an output stream receives a routing command after the
audio mode was changed back to normal, we must first stop the call
and then apply the new routing to playback path. If the playback
path is applied while still in call, the logic will not change
current call use case routing.

Bug: 17016230.
Change-Id: Icea84c017e492e6524dbd4431f8c2a4ef8828c72
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 1bd3421..1fee1d3 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1324,6 +1324,13 @@
          *       Because select_devices() must be called to switch back the music
          *       playback to headset.
          */
+        if ((adev->mode == AUDIO_MODE_NORMAL) &&
+                voice_is_in_call(adev) &&
+                output_drives_call(adev, out)) {
+            ret = voice_stop_call(adev);
+            adev->current_call_output = NULL;
+        }
+
         if (val != 0) {
             out->devices = val;
 
@@ -1344,13 +1351,6 @@
             }
         }
 
-        if ((adev->mode == AUDIO_MODE_NORMAL) &&
-                voice_is_in_call(adev) &&
-                output_drives_call(adev, out)) {
-            ret = voice_stop_call(adev);
-            adev->current_call_output = NULL;
-        }
-
         pthread_mutex_unlock(&adev->lock);
         pthread_mutex_unlock(&out->lock);
     }