Make add-call a global property of telecom. (1/4)

ADD_CALL didn't make sense as a property of Connection or Call.
This changes it to be a global property instead.

Bug: 18285352
Change-Id: I658e7a6977a848600272cde2914612c8691bb801
diff --git a/telecomm/java/android/telecom/Phone.java b/telecomm/java/android/telecom/Phone.java
index 5131790..6344181 100644
--- a/telecomm/java/android/telecom/Phone.java
+++ b/telecomm/java/android/telecom/Phone.java
@@ -74,6 +74,16 @@
          * @param call A newly removed {@code Call}.
          */
         public void onCallRemoved(Phone phone, Call call) { }
+
+        /**
+         * Called when the {@code Phone} ability to add more calls changes.  If the phone cannot
+         * support more calls then {@code canAddCall} is set to {@code false}.  If it can, then it
+         * is set to {@code true}.
+         *
+         * @param phone The {@code Phone} calling this method.
+         * @param canAddCall Indicates whether an additional call can be added.
+         */
+        public void onCanAddCallChanged(Phone phone, boolean canAddCall) { }
     }
 
     // A Map allows us to track each Call by its Telecom-specified call ID
@@ -92,6 +102,8 @@
 
     private final List<Listener> mListeners = new CopyOnWriteArrayList<>();
 
+    private boolean mCanAddCall = true;
+
     /** {@hide} */
     Phone(InCallAdapter adapter) {
         mInCallAdapter = adapter;
@@ -149,6 +161,14 @@
         fireBringToForeground(showDialpad);
     }
 
+    /** {@hide} */
+    final void internalSetCanAddCall(boolean canAddCall) {
+        if (mCanAddCall != canAddCall) {
+            mCanAddCall = canAddCall;
+            fireCanAddCallChanged(canAddCall);
+        }
+    }
+
     /**
      * Called to destroy the phone and cleanup any lingering calls.
      * @hide
@@ -191,6 +211,15 @@
     }
 
     /**
+     * Returns if the {@code Phone} can support additional calls.
+     *
+     * @return Whether the phone supports adding more calls.
+     */
+    public final boolean canAddCall() {
+        return mCanAddCall;
+    }
+
+    /**
      * Sets the microphone mute state. When this request is honored, there will be change to
      * the {@link #getAudioState()}.
      *
@@ -266,6 +295,12 @@
         }
     }
 
+    private void fireCanAddCallChanged(boolean canAddCall) {
+        for (Listener listener : mListeners) {
+            listener.onCanAddCallChanged(this, canAddCall);
+        }
+    }
+
     private void checkCallTree(ParcelableCall parcelableCall) {
         if (parcelableCall.getParentCallId() != null &&
                 !mCallByTelecomCallId.containsKey(parcelableCall.getParentCallId())) {