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/api/current.txt b/api/current.txt
index 28013d7..e2ae611 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -28314,8 +28314,7 @@
 
   public final class PhoneCapabilities {
     method public static java.lang.String toString(int);
-    field public static final int ADD_CALL = 16; // 0x10
-    field public static final int ALL = 12543; // 0x30ff
+    field public static final int ALL = 12527; // 0x30ef
     field public static final int DISCONNECT_FROM_CONFERENCE = 8192; // 0x2000
     field public static final int HOLD = 1; // 0x1
     field public static final int MANAGE_CONFERENCE = 128; // 0x80
diff --git a/telecomm/java/android/telecom/InCallService.java b/telecomm/java/android/telecom/InCallService.java
index 11da0f2..a85e84d 100644
--- a/telecomm/java/android/telecom/InCallService.java
+++ b/telecomm/java/android/telecom/InCallService.java
@@ -54,6 +54,7 @@
     private static final int MSG_SET_POST_DIAL_WAIT = 4;
     private static final int MSG_ON_AUDIO_STATE_CHANGED = 5;
     private static final int MSG_BRING_TO_FOREGROUND = 6;
+    private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7;
 
     /** Default Handler used to consolidate binder method calls onto a single thread. */
     private final Handler mHandler = new Handler(Looper.getMainLooper()) {
@@ -91,6 +92,9 @@
                 case MSG_BRING_TO_FOREGROUND:
                     mPhone.internalBringToForeground(msg.arg1 == 1);
                     break;
+                case MSG_ON_CAN_ADD_CALL_CHANGED:
+                    mPhone.internalSetCanAddCall(msg.arg1 == 1);
+                    break;
                 default:
                     break;
             }
@@ -136,6 +140,12 @@
         public void bringToForeground(boolean showDialpad) {
             mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
         }
+
+        @Override
+        public void onCanAddCallChanged(boolean canAddCall) {
+            mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
+                    .sendToTarget();
+        }
     }
 
     private Phone mPhone;
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())) {
diff --git a/telecomm/java/android/telecom/PhoneCapabilities.java b/telecomm/java/android/telecom/PhoneCapabilities.java
index 3d3c6bd..f61d39c 100644
--- a/telecomm/java/android/telecom/PhoneCapabilities.java
+++ b/telecomm/java/android/telecom/PhoneCapabilities.java
@@ -46,8 +46,10 @@
      */
     public static final int SWAP_CONFERENCE    = 0x00000008;
 
-    /** Call currently supports adding another call to this one. */
-    public static final int ADD_CALL           = 0x00000010;
+    /**
+     * @hide
+     */
+    public static final int UNUSED             = 0x00000010;
 
     /** Call supports responding via text option. */
     public static final int RESPOND_VIA_TEXT   = 0x00000020;
@@ -96,7 +98,7 @@
     public static final int DISCONNECT_FROM_CONFERENCE = 0x00002000;
 
     public static final int ALL = HOLD | SUPPORT_HOLD | MERGE_CONFERENCE | SWAP_CONFERENCE
-            | ADD_CALL | RESPOND_VIA_TEXT | MUTE | MANAGE_CONFERENCE | SEPARATE_FROM_CONFERENCE
+            | RESPOND_VIA_TEXT | MUTE | MANAGE_CONFERENCE | SEPARATE_FROM_CONFERENCE
             | DISCONNECT_FROM_CONFERENCE;
 
     /**
@@ -136,9 +138,6 @@
         if (can(capabilities, SWAP_CONFERENCE)) {
             builder.append(" SWAP_CONFERENCE");
         }
-        if (can(capabilities, ADD_CALL)) {
-            builder.append(" ADD_CALL");
-        }
         if (can(capabilities, RESPOND_VIA_TEXT)) {
             builder.append(" RESPOND_VIA_TEXT");
         }
diff --git a/telecomm/java/com/android/internal/telecom/IInCallService.aidl b/telecomm/java/com/android/internal/telecom/IInCallService.aidl
index 35f6f65..d26f6cb 100644
--- a/telecomm/java/com/android/internal/telecom/IInCallService.aidl
+++ b/telecomm/java/com/android/internal/telecom/IInCallService.aidl
@@ -43,4 +43,6 @@
     void onAudioStateChanged(in AudioState audioState);
 
     void bringToForeground(boolean showDialpad);
+
+    void onCanAddCallChanged(boolean canAddCall);
 }