audiopolicy: evaluate all outputs routing when call state changes

When call state changes, it is possible that some outputs are active in
which case their routing must be reevaluated.
This generalizes this behavior already implemented when a device is
connected/disconnected or a forced usage changed.

This is normally not needed as music is paused when a call is active
but there can be some race conditions where music resumes before the
audio mode is actually updated due to the asynchronous nature of audio
focus and audio mode management.

Bug: 78248310
Test: repro steps in bug. Audio smoke tests
Change-Id: If491eb879a90cf29025bedb2bc77210f052bcb6a
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index a54a71f..369f620 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -589,6 +589,16 @@
             setOutputDevice(mPrimaryOutput, rxDevice, force, 0);
         }
     }
+
+    // reevaluate routing on all outputs in case tracks have been started during the call
+    for (size_t i = 0; i < mOutputs.size(); i++) {
+        sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
+        audio_devices_t newDevice = getNewOutputDevice(desc, true /*fromCache*/);
+        if (state != AUDIO_MODE_IN_CALL || desc != mPrimaryOutput) {
+            setOutputDevice(desc, newDevice, (newDevice != AUDIO_DEVICE_NONE), delayMs);
+        }
+    }
+
     // if entering in call state, handle special case of active streams
     // pertaining to sonification strategy see handleIncallSonification()
     if (isStateInCall(state)) {