Turn speakerphone on at DIALING state.

When start-with-speakerphone is on, call used to go to speakerphone on
ACTIVE, but should go on DIALING.
Also, bug existed where it would go to speakerphone every time the call
went through HOLD-UNHOLD sequence.

Bug: 20265686
Change-Id: I6d281054b691efe62cde1e02987b498c5ec1dd13
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 5fd4fca..0d57c8a 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -916,14 +916,12 @@
 
     void markCallAsDialing(Call call) {
         setCallState(call, CallState.DIALING);
+        maybeMoveToSpeakerPhone(call);
     }
 
     void markCallAsActive(Call call) {
         setCallState(call, CallState.ACTIVE);
-
-        if (call.getStartWithSpeakerphoneOn()) {
-            setAudioRoute(AudioState.ROUTE_SPEAKER);
-        }
+        maybeMoveToSpeakerPhone(call);
     }
 
     void markCallAsOnHold(Call call) {
@@ -1457,6 +1455,16 @@
     }
 
     /**
+     * Checks to see if the call should be on speakerphone and if so, set it.
+     */
+    private void maybeMoveToSpeakerPhone(Call call) {
+        if (call.getStartWithSpeakerphoneOn()) {
+            setAudioRoute(AudioState.ROUTE_SPEAKER);
+            call.setStartWithSpeakerphoneOn(false);
+        }
+    }
+
+    /**
      * Creates a new call for an existing connection.
      *
      * @param callId The id of the new call.