Changing the point where the call state is set.

The reason speakerphone was not working while the call was dialing was
because the call went from state DIALING -> DIALING, which was not seen
as a state change, which meant that the call was not updated in the audio
manager, resulting there being no audio focus.

Note this is related to changes made in CL/518284. 

Bug: 16978516
Change-Id: I7b2be0ec21c484f6fbd767055e5e9afefbb526e2
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index 16dc323..93f8fbf 100644
--- a/src/com/android/telecomm/Call.java
+++ b/src/com/android/telecomm/Call.java
@@ -65,7 +65,7 @@
      * Listener for events on the call.
      */
     interface Listener {
-        void onSuccessfulOutgoingCall(Call call);
+        void onSuccessfulOutgoingCall(Call call, CallState callState);
         void onFailedOutgoingCall(Call call, int errorCode, String errorMsg);
         void onCancelledOutgoingCall(Call call);
         void onSuccessfulIncomingCall(Call call);
@@ -94,7 +94,7 @@
 
     abstract static class ListenerBase implements Listener {
         @Override
-        public void onSuccessfulOutgoingCall(Call call) {}
+        public void onSuccessfulOutgoingCall(Call call, CallState callState) {}
         @Override
         public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {}
         @Override
@@ -614,7 +614,6 @@
             ConnectionRequest request, ParcelableConnection connection) {
         Log.v(this, "handleCreateConnectionSuccessful %s", connection);
         mCreateConnectionProcessor = null;
-        setState(getStateFromConnectionState(connection.getState()));
         setTargetPhoneAccount(connection.getPhoneAccount());
         setHandle(connection.getHandle(), connection.getHandlePresentation());
         setCallerDisplayName(
@@ -635,7 +634,8 @@
             mHandler.postDelayed(mDirectToVoicemailRunnable, Timeouts.getDirectToVoicemailMillis());
         } else {
             for (Listener l : mListeners) {
-                l.onSuccessfulOutgoingCall(this);
+                l.onSuccessfulOutgoingCall(this,
+                        getStateFromConnectionState(connection.getState()));
             }
         }
     }
@@ -667,7 +667,6 @@
         if (mIsIncoming) {
             clearConnectionService();
             setDisconnectCause(DisconnectCause.OUTGOING_CANCELED, null);
-            setState(CallState.DISCONNECTED);
 
             Listener[] listeners = mListeners.toArray(new Listener[mListeners.size()]);
             for (int i = 0; i < listeners.length; i++) {
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index e75a9a1..c2af444 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -123,8 +123,9 @@
     }
 
     @Override
-    public void onSuccessfulOutgoingCall(Call call) {
+    public void onSuccessfulOutgoingCall(Call call, CallState callState) {
         Log.v(this, "onSuccessfulOutgoingCall, %s", call);
+        setCallState(call, callState);
         if (mCalls.contains(call)) {
             // The call's ConnectionService has been updated.
             for (CallsManagerListener listener : mListeners) {
@@ -161,6 +162,7 @@
 
     @Override
     public void onFailedIncomingCall(Call call) {
+        setCallState(call, CallState.DISCONNECTED);
         call.removeListener(this);
     }