Merge "Wiring up Ims framework multi-endpoint APIs." into nyc-dev
am: 26915f5

* commit '26915f571175c8d84db6d1f2fdf54b5cb3f6926e':
  Wiring up Ims framework multi-endpoint APIs.

Change-Id: I11134723fab1cec76fcb87bd0d15a325b03157ec
diff --git a/src/java/com/android/ims/ImsExternalCallStateListener.java b/src/java/com/android/ims/ImsExternalCallStateListener.java
new file mode 100644
index 0000000..3f4f163
--- /dev/null
+++ b/src/java/com/android/ims/ImsExternalCallStateListener.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.ims;
+
+import java.util.List;
+
+/**
+ * Listener for receiving notifications about {@link ImsExternalCallState} information received
+ * from the network via a dialog event package.
+ *
+ * @hide
+ */
+public class ImsExternalCallStateListener {
+    /**
+     * Notifies client when Dialog Event Package update is received
+     *
+     * @param externalCallState the external call state.
+     */
+    public void onImsExternalCallStateUpdate(List<ImsExternalCallState> externalCallState) {
+        // no-op
+    }
+}
diff --git a/src/java/com/android/ims/ImsManager.java b/src/java/com/android/ims/ImsManager.java
index 99c35f8..43fdae9 100644
--- a/src/java/com/android/ims/ImsManager.java
+++ b/src/java/com/android/ims/ImsManager.java
@@ -36,6 +36,7 @@
 import com.android.ims.internal.IImsCallSession;
 import com.android.ims.internal.IImsEcbm;
 import com.android.ims.internal.IImsEcbmListener;
+import com.android.ims.internal.IImsMultiEndpoint;
 import com.android.ims.internal.IImsRegistrationListener;
 import com.android.ims.internal.IImsService;
 import com.android.ims.internal.IImsUt;
@@ -175,6 +176,8 @@
     // ECBM interface
     private ImsEcbm mEcbm = null;
 
+    private ImsMultiEndpoint mMultiEndpoint = null;
+
     /**
      * Gets a manager instance.
      *
@@ -764,6 +767,7 @@
             mUt = null;
             mConfig = null;
             mEcbm = null;
+            mMultiEndpoint = null;
         }
     }
 
@@ -1237,6 +1241,7 @@
             mUt = null;
             mConfig = null;
             mEcbm = null;
+            mMultiEndpoint = null;
 
             if (mContext != null) {
                 Intent intent = new Intent(ACTION_IMS_SERVICE_DOWN);
@@ -1383,6 +1388,7 @@
             }
         }
     }
+
     /**
      * Gets the ECBM interface to request ECBM exit.
      *
@@ -1411,6 +1417,34 @@
     }
 
     /**
+     * Gets the Multi-Endpoint interface to subscribe to multi-enpoint notifications..
+     *
+     * @param serviceId a service id which is obtained from {@link ImsManager#open}
+     * @return the multi-endpoint interface instance
+     * @throws ImsException if getting the multi-endpoint interface results in an error
+     */
+    public ImsMultiEndpoint getMultiEndpointInterface(int serviceId) throws ImsException {
+        if (mMultiEndpoint == null) {
+            checkAndThrowExceptionIfServiceUnavailable();
+
+            try {
+                IImsMultiEndpoint iImsMultiEndpoint = mImsService.getMultiEndpointInterface(
+                        serviceId);
+
+                if (iImsMultiEndpoint == null) {
+                    throw new ImsException("getMultiEndpointInterface()",
+                            ImsReasonInfo.CODE_MULTIENDPOINT_NOT_SUPPORTED);
+                }
+                mMultiEndpoint = new ImsMultiEndpoint(iImsMultiEndpoint);
+            } catch (RemoteException e) {
+                throw new ImsException("getMultiEndpointInterface()", e,
+                        ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
+            }
+        }
+        return mMultiEndpoint;
+    }
+
+    /**
      * Resets ImsManager settings back to factory defaults.
      *
      * @hide
diff --git a/src/java/com/android/ims/ImsMultiEndpoint.java b/src/java/com/android/ims/ImsMultiEndpoint.java
new file mode 100644
index 0000000..2cc19b1
--- /dev/null
+++ b/src/java/com/android/ims/ImsMultiEndpoint.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.ims;
+
+import com.android.ims.internal.IImsMultiEndpoint;
+import com.android.ims.internal.IImsExternalCallStateListener;
+
+import android.os.RemoteException;
+import android.telephony.Rlog;
+
+import java.util.List;
+
+/**
+ * Provides APIs for the IMS multi-endpoint functionality.  Specifically, provides a means for IMS
+ * to subscribe to dialog event packages issued by the network.
+ *
+ * @hide
+ */
+public class ImsMultiEndpoint {
+    /**
+     * Adapter class for {@link IImsExternalCallStateListener}.
+     */
+    private class ImsExternalCallStateListenerProxy extends IImsExternalCallStateListener.Stub {
+        private ImsExternalCallStateListener mListener;
+
+        public ImsExternalCallStateListenerProxy(ImsExternalCallStateListener listener) {
+            mListener = listener;
+        }
+
+
+        /**
+         * Notifies client when Dialog Event Package update is received
+         *
+         * @param externalCallState the external call state.
+         */
+        @Override
+        public void onImsExternalCallStateUpdate(List<ImsExternalCallState> externalCallState) {
+            if (DBG) Rlog.d(TAG, "onImsExternalCallStateUpdate");
+
+            if (mListener != null) {
+                mListener.onImsExternalCallStateUpdate(externalCallState);
+            }
+        }
+    }
+
+    private static final String TAG = "ImsMultiEndpoint";
+    private static final boolean DBG = true;
+
+    private final IImsMultiEndpoint mImsMultiendpoint;
+
+    public ImsMultiEndpoint(IImsMultiEndpoint iImsMultiEndpoint) {
+        if (DBG) Rlog.d(TAG, "ImsMultiEndpoint created");
+        mImsMultiendpoint = iImsMultiEndpoint;
+    }
+
+    public void setExternalCallStateListener(ImsExternalCallStateListener externalCallStateListener)
+            throws ImsException {
+        try {
+            if (DBG) Rlog.d(TAG, "setExternalCallStateListener");
+            mImsMultiendpoint.setListener(new ImsExternalCallStateListenerProxy(
+                    externalCallStateListener));
+        } catch (RemoteException e) {
+            throw new ImsException("setExternalCallStateListener could not be set.", e,
+                    ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
+        }
+    }
+}