Support Add Call (1/2)

Bug: 15006702
Change-Id: I5b99af2da0841897ab87f8b9076f4fae91233b80
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index f081cec..49eff44 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -604,6 +604,29 @@
     }
 
     /**
+     * Checks to see if the specified call is the only high-level call and if so, enable the
+     * "Add-call" button. We allow you to add a second call but not a third or beyond.
+     *
+     * @param call The call to test for add-call.
+     * @return Whether the add-call feature should be enabled for the call.
+     */
+    protected boolean isAddCallCapable(Call call) {
+        if (call.getParentCall() != null) {
+            // Never true for child calls.
+            return false;
+        }
+
+        // Loop through all the other calls and there exists a top level (has no parent) call
+        // that is not the specified call, return false.
+        for (Call otherCall : mCalls) {
+            if (call != otherCall && otherCall.getParentCall() == null) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
      * Returns the first call that it finds with the given states. The states are treated as having
      * priority order so that any call with the first state will be returned before any call with
      * states listed later in the parameter list.
diff --git a/src/com/android/telecomm/InCallController.java b/src/com/android/telecomm/InCallController.java
index 7be1baa..6dac2ce 100644
--- a/src/com/android/telecomm/InCallController.java
+++ b/src/com/android/telecomm/InCallController.java
@@ -277,6 +277,9 @@
         if (call.isConferenceCapable()) {
             capabilities |= CallCapabilities.MERGE_CALLS;
         }
+        if (CallsManager.getInstance().isAddCallCapable(call)) {
+            capabilities |= CallCapabilities.ADD_CALL;
+        }
         CallState state = call.getState();
         if (state == CallState.ABORTED) {
             state = CallState.DISCONNECTED;
@@ -307,4 +310,5 @@
                 capabilities, connectTimeMillis, call.getHandle(), call.getGatewayInfo(),
                 descriptor, call.getHandoffCallServiceDescriptor(), parentCallId, childCallIds);
     }
+
 }