Add IncomingCallsMangager to perform the incoming call sequence.

IncomingCallsManager binds to the call service and asks it to confirm
the call. If the call service cannot be bound or it failed to confirm
within the timeout, we handle the incoming call as if it failed. The
code to do the actual confirmation is NYI.

Also add handleSuccess/Failed methods to Switchboard.
This still needs some changes to ICallService, ICallServiceAdapter, and
CallServiceWrapper before it will be fully functional.

Change-Id: Ibfd92ce17fb2054e2e0cb209738ad5375bf01492
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index d69af53..ff224e5 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -17,6 +17,7 @@
 package com.android.telecomm;
 
 import android.content.Context;
+import android.telecomm.CallServiceInfo;
 import android.telecomm.CallState;
 import android.text.TextUtils;
 import android.util.Log;
@@ -86,6 +87,23 @@
     }
 
     /**
+     * Starts the incoming call sequence by having switchboard confirm with the specified call
+     * service that an incoming call actually exists for the specified call token. Upon success,
+     * execution returns to {@link #handleSuccessfulIncomingCall} to start the in-call UI.
+     *
+     * @param callServiceInfo The details of the call service to use for this incoming call.
+     * @param callToken The token used by the call service to identify the incoming call.
+     */
+    void processIncomingCallIntent(CallServiceInfo callServiceInfo, String callToken) {
+        // Create a call with no handle. Eventually, switchboard will update the call with
+        // additional information from the call service, but for now we just need one to pass around
+        // with a unique call ID.
+        Call call = new Call(null, null);
+
+        mSwitchboard.confirmIncomingCall(call, callServiceInfo, callToken);
+    }
+
+    /**
      * Attempts to issue/connect the specified call.  From an (arbitrary) application standpoint,
      * all that is required to initiate this flow is to fire either of the CALL, CALL_PRIVILEGED,
      * and CALL_EMERGENCY intents. These are listened to by CallActivity.java which then invokes
@@ -123,6 +141,17 @@
         mInCallController.addCall(call.toCallInfo());
     }
 
+    /**
+     * Adds a new incoming call to the list of live calls and notifies the in-call app.
+     *
+     * @param call The new incoming call.
+     */
+    void handleSuccessfulIncomingCall(Call call) {
+        Preconditions.checkState(call.getState() == CallState.RINGING);
+        addCall(call);
+        mInCallController.addCall(call.toCallInfo());
+    }
+
     /*
      * Sends all the live calls to the in-call app if any exist. If there are no live calls, then
      * tells the in-call controller to unbind since it is not needed.