Sent initial data to telecomm on connection creation. (2/3)

Telecomm was not sending the initial state for new connections forcing
the connection services to postpone when they set data on the connection
which resulted in hacky code.  This CL makes use of a
ParcelableConnection to send the intial connection data.

Change-Id: If571414aba19fa1bb282e30632431962b8366cf4
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index 9cd5d6f..27ed0d7 100644
--- a/src/com/android/telecomm/Call.java
+++ b/src/com/android/telecomm/Call.java
@@ -24,8 +24,10 @@
 import android.os.Handler;
 import android.telecomm.CallPropertyPresentation;
 import android.telecomm.CallState;
+import android.telecomm.Connection;
 import android.telecomm.ConnectionRequest;
 import android.telecomm.GatewayInfo;
+import android.telecomm.ParcelableConnection;
 import android.telecomm.PhoneAccountHandle;
 import android.telecomm.Response;
 import android.telecomm.StatusHints;
@@ -567,9 +569,15 @@
     }
 
     @Override
-    public void handleCreateConnectionSuccessful(ConnectionRequest request) {
+    public void handleCreateConnectionSuccessful(
+            ConnectionRequest request, ParcelableConnection connection) {
         mCreateConnectionProcessor = null;
-        mPhoneAccountHandle = request.getAccountHandle();
+        setState(getStateFromConnectionState(connection.getState()));
+        setPhoneAccount(connection.getPhoneAccount());
+        setHandle(connection.getHandle(), connection.getHandlePresentation());
+        setCallerDisplayName(
+                connection.getCallerDisplayName(), connection.getCallerDisplayNamePresentation());
+        setCallVideoProvider(connection.getCallVideoProvider());
 
         if (mIsIncoming) {
             // We do not handle incoming calls immediately when they are verified by the connection
@@ -578,9 +586,6 @@
             // the user or if we want to reject the call.
             mDirectToVoicemailQueryPending = true;
 
-            // Setting the handle triggers the caller info lookup code.
-            setHandle(request.getHandle(), request.getHandlePresentation());
-
             // Timeout the direct-to-voicemail lookup execution so that we dont wait too long before
             // showing the user the incoming call screen.
             mHandler.postDelayed(mDirectToVoicemailRunnable, Timeouts.getDirectToVoicemailMillis());
@@ -1144,4 +1149,22 @@
             Log.w(this, "startActivityFromInCall, activity intent required");
         }
     }
+
+    private CallState getStateFromConnectionState(int state) {
+        switch (state) {
+            case Connection.State.ACTIVE:
+                return CallState.ACTIVE;
+            case Connection.State.DIALING:
+                return CallState.DIALING;
+            case Connection.State.DISCONNECTED:
+                return CallState.DISCONNECTED;
+            case Connection.State.HOLDING:
+                return CallState.ON_HOLD;
+            case Connection.State.NEW:
+                return CallState.NEW;
+            case Connection.State.RINGING:
+                return CallState.RINGING;
+        }
+        return CallState.DISCONNECTED;
+    }
 }