Force setting initial audio state on first call.

Bug: 17449052
Change-Id: I091e9ffa56e5dc5e6fefb4b7fe8c4a5f31d0750f
diff --git a/src/com/android/telecomm/CallAudioManager.java b/src/com/android/telecomm/CallAudioManager.java
index b42f5d8..df60300 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);
@@ -444,10 +449,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() {