Merge "Add workaround for broken vendor camera on/off requests."
diff --git a/src/java/com/android/ims/ImsEcbm.java b/src/java/com/android/ims/ImsEcbm.java
index 9fa9598..53549bf 100644
--- a/src/java/com/android/ims/ImsEcbm.java
+++ b/src/java/com/android/ims/ImsEcbm.java
@@ -78,6 +78,10 @@
         }
     }
 
+    public boolean isBinderAlive() {
+        return miEcbm.asBinder().isBinderAlive();
+    }
+
     /**
      * Adapter class for {@link IImsEcbmListener}.
      */
diff --git a/src/java/com/android/ims/ImsManager.java b/src/java/com/android/ims/ImsManager.java
index 52d356e..7c25829 100644
--- a/src/java/com/android/ims/ImsManager.java
+++ b/src/java/com/android/ims/ImsManager.java
@@ -1615,24 +1615,24 @@
     public ImsUtInterface getSupplementaryServiceConfiguration()
             throws ImsException {
         // FIXME: manage the multiple Ut interfaces based on the session id
-        if (mUt == null || !mImsServiceProxy.isBinderAlive()) {
-            checkAndThrowExceptionIfServiceUnavailable();
-
-            try {
-                IImsUt iUt = mImsServiceProxy.getUtInterface();
-
-                if (iUt == null) {
-                    throw new ImsException("getSupplementaryServiceConfiguration()",
-                            ImsReasonInfo.CODE_UT_NOT_SUPPORTED);
-                }
-
-                mUt = new ImsUt(iUt);
-            } catch (RemoteException e) {
-                throw new ImsException("getSupplementaryServiceConfiguration()", e,
-                        ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
-            }
+        if (mUt != null && mUt.isBinderAlive()) {
+            return mUt;
         }
 
+        checkAndThrowExceptionIfServiceUnavailable();
+        try {
+            IImsUt iUt = mImsServiceProxy.getUtInterface();
+
+            if (iUt == null) {
+                throw new ImsException("getSupplementaryServiceConfiguration()",
+                        ImsReasonInfo.CODE_UT_NOT_SUPPORTED);
+            }
+
+            mUt = new ImsUt(iUt);
+        } catch (RemoteException e) {
+            throw new ImsException("getSupplementaryServiceConfiguration()", e,
+                    ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
+        }
         return mUt;
     }
 
@@ -1810,23 +1810,22 @@
      * @throws ImsException if getting the setting interface results in an error.
      */
     public ImsConfig getConfigInterface() throws ImsException {
-
-        if (mConfig == null || !mImsServiceProxy.isBinderAlive()) {
-            checkAndThrowExceptionIfServiceUnavailable();
-
-            try {
-                IImsConfig config = mImsServiceProxy.getConfigInterface();
-                if (config == null) {
-                    throw new ImsException("getConfigInterface()",
-                            ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
-                }
-                mConfig = new ImsConfig(config, mContext);
-            } catch (RemoteException e) {
-                throw new ImsException("getConfigInterface()", e,
-                        ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
-            }
+        if (mConfig != null && mConfig.isBinderAlive()) {
+            return mConfig;
         }
-        if (DBG) log("getConfigInterface(), mConfig= " + mConfig);
+
+        checkAndThrowExceptionIfServiceUnavailable();
+        try {
+            IImsConfig config = mImsServiceProxy.getConfigInterface();
+            if (config == null) {
+                throw new ImsException("getConfigInterface()",
+                        ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
+            }
+            mConfig = new ImsConfig(config, mContext);
+        } catch (RemoteException e) {
+            throw new ImsException("getConfigInterface()", e,
+                    ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
+        }
         return mConfig;
     }
 
@@ -2369,21 +2368,22 @@
      * @throws ImsException if getting the ECBM interface results in an error
      */
     public ImsEcbm getEcbmInterface(int serviceId) throws ImsException {
-        if (mEcbm == null || !mImsServiceProxy.isBinderAlive()) {
-            checkAndThrowExceptionIfServiceUnavailable();
+        if (mEcbm != null && mEcbm.isBinderAlive()) {
+            return mEcbm;
+        }
 
-            try {
-                IImsEcbm iEcbm = mImsServiceProxy.getEcbmInterface();
+        checkAndThrowExceptionIfServiceUnavailable();
+        try {
+            IImsEcbm iEcbm = mImsServiceProxy.getEcbmInterface();
 
-                if (iEcbm == null) {
-                    throw new ImsException("getEcbmInterface()",
-                            ImsReasonInfo.CODE_ECBM_NOT_SUPPORTED);
-                }
-                mEcbm = new ImsEcbm(iEcbm);
-            } catch (RemoteException e) {
-                throw new ImsException("getEcbmInterface()", e,
-                        ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
+            if (iEcbm == null) {
+                throw new ImsException("getEcbmInterface()",
+                        ImsReasonInfo.CODE_ECBM_NOT_SUPPORTED);
             }
+            mEcbm = new ImsEcbm(iEcbm);
+        } catch (RemoteException e) {
+            throw new ImsException("getEcbmInterface()", e,
+                    ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
         }
         return mEcbm;
     }
@@ -2396,22 +2396,24 @@
      * @throws ImsException if getting the multi-endpoint interface results in an error
      */
     public ImsMultiEndpoint getMultiEndpointInterface(int serviceId) throws ImsException {
-        if (mMultiEndpoint == null || !mImsServiceProxy.isBinderAlive()) {
-            checkAndThrowExceptionIfServiceUnavailable();
-
-            try {
-                IImsMultiEndpoint iImsMultiEndpoint = mImsServiceProxy.getMultiEndpointInterface();
-
-                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);
-            }
+        if (mMultiEndpoint != null && mMultiEndpoint.isBinderAlive()) {
+            return mMultiEndpoint;
         }
+
+        checkAndThrowExceptionIfServiceUnavailable();
+        try {
+            IImsMultiEndpoint iImsMultiEndpoint = mImsServiceProxy.getMultiEndpointInterface();
+
+            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;
     }
 
diff --git a/src/java/com/android/ims/ImsMultiEndpoint.java b/src/java/com/android/ims/ImsMultiEndpoint.java
index 2cc19b1..9692696 100644
--- a/src/java/com/android/ims/ImsMultiEndpoint.java
+++ b/src/java/com/android/ims/ImsMultiEndpoint.java
@@ -78,4 +78,8 @@
                     ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
         }
     }
+
+    public boolean isBinderAlive() {
+        return mImsMultiendpoint.asBinder().isBinderAlive();
+    }
 }
diff --git a/src/java/com/android/ims/ImsUt.java b/src/java/com/android/ims/ImsUt.java
index 4cc7011..d8d70b0 100644
--- a/src/java/com/android/ims/ImsUt.java
+++ b/src/java/com/android/ims/ImsUt.java
@@ -508,6 +508,13 @@
         }
     }
 
+    /**
+     * @return returns true if the binder is alive, false otherwise.
+     */
+    public boolean isBinderAlive() {
+        return miUt.asBinder().isBinderAlive();
+    }
+
     public void transact(Bundle ssInfo, Message result) {
         if (DBG) {
             log("transact :: Ut=" + miUt + ", ssInfo=" + ssInfo);