Merge "Force setting initial audio state on first call." into lmp-dev
diff --git a/src/com/android/telecomm/CallAudioManager.java b/src/com/android/telecomm/CallAudioManager.java
index c02e96d..0a013a7 100644
--- a/src/com/android/telecomm/CallAudioManager.java
+++ b/src/com/android/telecomm/CallAudioManager.java
@@ -78,7 +78,7 @@
         if (hasFocus()) {
             if (CallsManager.getInstance().getCalls().isEmpty()) {
                 Log.v(this, "all calls removed, reseting system audio to default state");
-                setInitialAudioState(null);
+                setInitialAudioState(null, false /* force */);
                 mWasSpeakerOn = false;
             }
             updateAudioStreamAndMode();
@@ -260,18 +260,23 @@
 
         // If we transition from not voice call to voice call, we need to set an initial state.
         if (wasNotVoiceCall && mAudioFocusStreamType == AudioManager.STREAM_VOICE_CALL) {
-            setInitialAudioState(call);
+            setInitialAudioState(call, true /* force */);
         }
     }
 
     private void setSystemAudioState(boolean isMuted, int route, int supportedRouteMask) {
+        setSystemAudioState(false /* force */, isMuted, route, supportedRouteMask);
+    }
+
+    private void setSystemAudioState(
+            boolean force, boolean isMuted, int route, int supportedRouteMask) {
         if (!hasFocus()) {
             return;
         }
 
         AudioState oldAudioState = mAudioState;
         saveAudioState(new AudioState(isMuted, route, supportedRouteMask));
-        if (Objects.equals(oldAudioState, mAudioState)) {
+        if (!force && Objects.equals(oldAudioState, mAudioState)) {
             return;
         }
         Log.i(this, "changing audio state from %s to %s", oldAudioState, mAudioState);
@@ -450,10 +455,11 @@
         return new AudioState(false, route, supportedRouteMask);
     }
 
-    private void setInitialAudioState(Call call) {
+    private void setInitialAudioState(Call call, boolean force) {
         AudioState audioState = getInitialAudioState(call);
         Log.v(this, "setInitialAudioState %s, %s", audioState, call);
-        setSystemAudioState(audioState.isMuted, audioState.route, audioState.supportedRouteMask);
+        setSystemAudioState(
+                force, audioState.isMuted, audioState.route, audioState.supportedRouteMask);
     }
 
     private void updateAudioForForegroundCall() {