audio policy: fix in call audio setup delay

There is a delay inserted by audio policy manager before switching
device when entering in call mode to allow music playback to be muted
before the device actually switches.

This delay can be significant when high latency outputs (e.g. deep buffers) are
present and should not be applied if the output is not active.

Issue 7612431.

Change-Id: I04b666769033dbfdc861752b030d3f7bdffe9435
diff --git a/audio/AudioPolicyManagerBase.cpp b/audio/AudioPolicyManagerBase.cpp
index 2b37883..6be5483 100644
--- a/audio/AudioPolicyManagerBase.cpp
+++ b/audio/AudioPolicyManagerBase.cpp
@@ -347,12 +347,12 @@
     if (isStateInCall(state)) {
         for (size_t i = 0; i < mOutputs.size(); i++) {
             AudioOutputDescriptor *desc = mOutputs.valueAt(i);
-            //take the biggest latency for all outputs
-            if (delayMs < (int)desc->mLatency*2) {
-                delayMs = desc->mLatency*2;
-            }
-            //mute STRATEGY_MEDIA on all outputs
+            // mute strategy media and delay device switch by the largest latency of any output
+            // where strategy media is active.
             if (desc->strategyRefCount(STRATEGY_MEDIA) != 0) {
+                if (delayMs < (int)desc->mLatency*2) {
+                    delayMs = desc->mLatency*2;
+                }
                 setStrategyMute(STRATEGY_MEDIA, true, mOutputs.keyAt(i));
                 setStrategyMute(STRATEGY_MEDIA, false, mOutputs.keyAt(i), MUTE_TIME_MS,
                     getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/));