audio: Fix realtime stream routing behavior

Update adm of pending routing event before handling
routing in audio_hw.

CRs-Fixed: 1061281
Change-Id: Iea6f28a27c9c86406edad558b533ed4a5d9aff43
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 7888e5a..a7a8d19 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -383,13 +383,6 @@
 {
     struct audio_device *adev = out->dev;
 
-    if (out->routing_change) {
-        out->routing_change = false;
-        // must be checked for backward compatibility
-        if (adev->adm_on_routing_change)
-            adev->adm_on_routing_change(adev->adm_data, out->handle);
-    }
-
     if (adev->adm_request_focus_v2)
         adev->adm_request_focus_v2(adev->adm_data, out->handle, ns);
     else if (adev->adm_request_focus)
@@ -400,12 +393,6 @@
 {
     struct audio_device *adev = in->dev;
 
-    if (in->routing_change) {
-        in->routing_change = false;
-        if (adev->adm_on_routing_change)
-            adev->adm_on_routing_change(adev->adm_data, in->capture_handle);
-    }
-
     if (adev->adm_request_focus_v2)
         adev->adm_request_focus_v2(adev->adm_data, in->capture_handle, ns);
     else if (adev->adm_request_focus)
@@ -2504,10 +2491,12 @@
             if (!out->standby) {
                 if (!same_dev) {
                     ALOGV("update routing change");
-                    out->routing_change = true;
                     audio_extn_perf_lock_acquire(&adev->perf_lock_handle, 0,
                                                  adev->perf_lock_opts,
                                                  adev->perf_lock_opts_size);
+                    if (adev->adm_on_routing_change)
+                        adev->adm_on_routing_change(adev->adm_data,
+                                                    out->handle);
                 }
                 select_devices(adev, out->usecase);
                 if (!same_dev)
@@ -3365,7 +3354,9 @@
             /* If recording is in progress, change the tx device to new device */
             if (!in->standby && !in->is_st_session) {
                 ALOGV("update input routing change");
-                in->routing_change = true;
+                if (adev->adm_on_routing_change)
+                        adev->adm_on_routing_change(adev->adm_data,
+                                                    in->capture_handle);
                 ret = select_devices(adev, in->usecase);
             }
         }
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 0633eb0..83ad54d 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -238,8 +238,6 @@
 
     bool realtime;
     int af_period_multiplier;
-    bool routing_change;
-
     struct audio_device *dev;
     void* qaf_stream_handle;
     pthread_cond_t qaf_offload_cond;
@@ -270,8 +268,6 @@
     int bit_width;
     bool realtime;
     int af_period_multiplier;
-    bool routing_change;
-
     struct audio_device *dev;
 };