Wiring up Ims framework multi-endpoint APIs.

Completing wireup of the Ims framework multi-endpoint APIs so that we can
hook into the telephony code.

Note: I followed how the ImsEcbm API was handled, which seemed pretty
similar to the multi-endpoint APIs.

Bug: 27458894
Change-Id: I21c6fc95947692a3cf4541ddb7510e1da702ec84
diff --git a/src/java/com/android/ims/ImsManager.java b/src/java/com/android/ims/ImsManager.java
index 000f990..465ce3f 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;
         }
     }
 
@@ -1229,6 +1233,7 @@
             mUt = null;
             mConfig = null;
             mEcbm = null;
+            mMultiEndpoint = null;
 
             if (mContext != null) {
                 Intent intent = new Intent(ACTION_IMS_SERVICE_DOWN);
@@ -1375,6 +1380,7 @@
             }
         }
     }
+
     /**
      * Gets the ECBM interface to request ECBM exit.
      *
@@ -1403,6 +1409,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