Use mapped IDs for calls

With this CL each client gets a unique ID to represent calls.
This has a couple of benefits:
  - avoids one client from modifying another clients call
  - allows for stricter validation of input
  - allows a call to handed off to a different call service
    (with a different call ID)

Bug: 13643568
Change-Id: I6e2039aead5723d01f9442a4e54f5e616711a3b3
diff --git a/src/com/android/telecomm/IncomingCallsManager.java b/src/com/android/telecomm/IncomingCallsManager.java
index 0d98dc4..41b98f2 100644
--- a/src/com/android/telecomm/IncomingCallsManager.java
+++ b/src/com/android/telecomm/IncomingCallsManager.java
@@ -22,8 +22,9 @@
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 
-import java.util.Map;
+import java.util.Set;
 
 /**
  * Used to retrieve details about an incoming call. This is invoked after an incoming call intent.
@@ -31,9 +32,7 @@
 final class IncomingCallsManager {
 
     private final Switchboard mSwitchboard;
-
-    /** Maps call ID to the call. */
-    private final Map<String, Call> mPendingIncomingCalls = Maps.newHashMap();
+    private final Set<Call> mPendingIncomingCalls = Sets.newLinkedHashSet();
 
     /**
      * Persists the specified parameters.
@@ -55,19 +54,18 @@
         ThreadUtil.checkOnMainThread();
         Log.d(this, "retrieveIncomingCall");
 
-        final String callId = call.getId();
         // Just to be safe, lets make sure we're not already processing this call.
-        Preconditions.checkState(!mPendingIncomingCalls.containsKey(callId));
+        Preconditions.checkState(!mPendingIncomingCalls.contains(call));
 
-        mPendingIncomingCalls.put(callId, call);
+        mPendingIncomingCalls.add(call);
 
         Runnable errorCallback = new Runnable() {
             @Override public void run() {
-                handleFailedIncomingCall(callId);
+                handleFailedIncomingCall(call);
             }
         };
 
-        call.getCallService().setIncomingCallId(callId, extras, errorCallback);
+        call.getCallService().setIncomingCallId(call, extras, errorCallback);
     }
 
     /**
@@ -76,27 +74,25 @@
      *
      * @param callInfo The details of the call.
      */
-    void handleSuccessfulIncomingCall(CallInfo callInfo) {
+    void handleSuccessfulIncomingCall(Call call, CallInfo callInfo) {
         ThreadUtil.checkOnMainThread();
 
-        Call call = mPendingIncomingCalls.remove(callInfo.getId());
-        if (call != null) {
-            Log.d(this, "Incoming call %s found.", call.getId());
+        if (mPendingIncomingCalls.contains(call)) {
+            Log.d(this, "Incoming call %s found.", call);
+            mPendingIncomingCalls.remove(call);
             mSwitchboard.handleSuccessfulIncomingCall(call, callInfo);
         }
     }
 
     /**
      * Notifies switchboard of the failed incoming call after removing it from the pending list.
-     *
-     * @param callId The ID of the call.
      */
-    void handleFailedIncomingCall(String callId) {
+    void handleFailedIncomingCall(Call call) {
         ThreadUtil.checkOnMainThread();
 
-        Call call = mPendingIncomingCalls.remove(callId);
-        if (call != null) {
+        if (mPendingIncomingCalls.contains(call)) {
             Log.i(this, "Failed to get details for incoming call %s", call);
+            mPendingIncomingCalls.remove(call);
             // The call was found still waiting for details. Consider it failed.
             mSwitchboard.handleFailedIncomingCall(call);
         }