Add optional error codes to CallStateException

Bug: 19583351
Change-Id: I5d8b1ccb4ffc68fad6171e443468775760e83fec
diff --git a/src/java/com/android/internal/telephony/CallStateException.java b/src/java/com/android/internal/telephony/CallStateException.java
index 6087124..57cbeb8 100644
--- a/src/java/com/android/internal/telephony/CallStateException.java
+++ b/src/java/com/android/internal/telephony/CallStateException.java
@@ -21,6 +21,13 @@
  */
 public class CallStateException extends Exception
 {
+    private int mError = ERROR_INVALID;
+
+    /** The error code is not valid (Not received a disconnect cause) */
+    public static final int ERROR_INVALID = -1;
+
+    public static final int ERROR_DISCONNECTED = 1;
+
     public
     CallStateException()
     {
@@ -31,4 +38,15 @@
     {
         super(string);
     }
+
+    public
+    CallStateException(int error, String string)
+    {
+        super(string);
+        mError = error;
+    }
+
+    public int getError() {
+        return mError;
+    }
 }
diff --git a/src/java/com/android/internal/telephony/cdma/CDMAPhone.java b/src/java/com/android/internal/telephony/cdma/CDMAPhone.java
index a190a67..db79bef 100644
--- a/src/java/com/android/internal/telephony/cdma/CDMAPhone.java
+++ b/src/java/com/android/internal/telephony/cdma/CDMAPhone.java
@@ -46,8 +46,6 @@
 
 import android.telephony.TelephonyManager;
 
-import com.android.ims.ImsConfig;
-import com.android.ims.ImsManager;
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.CallStateException;
 import com.android.internal.telephony.CallTracker;
@@ -71,7 +69,6 @@
 import com.android.internal.telephony.imsphone.ImsPhone;
 import com.android.internal.telephony.uicc.IccException;
 import com.android.internal.telephony.uicc.IccRecords;
-import com.android.internal.telephony.uicc.RuimRecords;
 import com.android.internal.telephony.uicc.UiccCard;
 import com.android.internal.telephony.uicc.UiccCardApplication;
 import com.android.internal.telephony.uicc.UiccController;
@@ -426,19 +423,7 @@
                     + ((imsPhone != null) ? imsPhone.getServiceState().getState() : "N/A"));
         }
 
-        if (imsPhone == null ||
-                (imsPhone != null && !imsPhone.isVowifiEnabled())) {
-            boolean wfcWiFiOnly = (ImsManager.isWfcEnabledByPlatform(mContext) &&
-                    ImsManager.isWfcEnabledByUser(mContext) &&
-                    (ImsManager.getWfcMode(mContext) ==
-                    ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY));
-            if (wfcWiFiOnly == true) {
-                if (DBG) Rlog.d(LOG_TAG, "WIFI only mode, but no VoWIFI enabled");
-                CallStateException ce = new CallStateException(
-                        "WFC Wi-Fi Only Mode: IMS stack on WIFI not available");
-                throw ce;
-            }
-        }
+        ImsPhone.checkWfcWifiOnlyModeBeforeDial(mImsPhone, mContext);
 
         if (imsUseEnabled && imsPhone != null
                 && (imsPhone.isVolteEnabled() || imsPhone.isVowifiEnabled())
diff --git a/src/java/com/android/internal/telephony/gsm/GSMPhone.java b/src/java/com/android/internal/telephony/gsm/GSMPhone.java
index f562701..3d877df 100755
--- a/src/java/com/android/internal/telephony/gsm/GSMPhone.java
+++ b/src/java/com/android/internal/telephony/gsm/GSMPhone.java
@@ -26,7 +26,6 @@
 import android.os.Message;
 import android.os.Registrant;
 import android.os.RegistrantList;
-import android.os.SystemProperties;
 import android.preference.PreferenceManager;
 import android.provider.Telephony;
 import android.telecom.VideoProfile;
@@ -36,8 +35,6 @@
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 
-import com.android.ims.ImsConfig;
-import com.android.ims.ImsManager;
 import com.android.internal.telephony.CallTracker;
 
 import android.text.TextUtils;
@@ -64,14 +61,12 @@
 import com.android.internal.telephony.Connection;
 import com.android.internal.telephony.IccPhoneBookInterfaceManager;
 import com.android.internal.telephony.MmiCode;
-import com.android.internal.telephony.OperatorInfo;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneBase;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.PhoneNotifier;
 import com.android.internal.telephony.PhoneProxy;
 import com.android.internal.telephony.PhoneSubInfo;
-import com.android.internal.telephony.TelephonyProperties;
 import com.android.internal.telephony.UUSInfo;
 import com.android.internal.telephony.imsphone.ImsPhone;
 import com.android.internal.telephony.test.SimulatedRadioControl;
@@ -822,19 +817,7 @@
                     + ((imsPhone != null) ? imsPhone.getServiceState().getState() : "N/A"));
         }
 
-        if (imsPhone == null ||
-                (imsPhone != null && !imsPhone.isVowifiEnabled())) {
-            boolean wfcWiFiOnly = (ImsManager.isWfcEnabledByPlatform(mContext) &&
-                    ImsManager.isWfcEnabledByUser(mContext) &&
-                    (ImsManager.getWfcMode(mContext) ==
-                    ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY));
-            if (wfcWiFiOnly == true) {
-                if (LOCAL_DEBUG) Rlog.d(LOG_TAG, "WIFI only mode, but no VoWIFI enabled");
-                CallStateException ce = new CallStateException(
-                        "WFC Wi-Fi Only Mode: IMS stack on WIFI not available");
-                throw ce;
-            }
-        }
+        ImsPhone.checkWfcWifiOnlyModeBeforeDial(mImsPhone, mContext);
 
         if (imsUseEnabled && imsPhone != null
                 && (imsPhone.isVolteEnabled() || imsPhone.isVowifiEnabled())
diff --git a/src/java/com/android/internal/telephony/imsphone/ImsPhone.java b/src/java/com/android/internal/telephony/imsphone/ImsPhone.java
index 69e9fd3..d09e1bc 100644
--- a/src/java/com/android/internal/telephony/imsphone/ImsPhone.java
+++ b/src/java/com/android/internal/telephony/imsphone/ImsPhone.java
@@ -42,6 +42,7 @@
 
 import com.android.ims.ImsCallForwardInfo;
 import com.android.ims.ImsCallProfile;
+import com.android.ims.ImsConfig;
 import com.android.ims.ImsEcbm;
 import com.android.ims.ImsEcbmStateListener;
 import com.android.ims.ImsException;
@@ -475,6 +476,21 @@
         mDefaultPhone.notifyNewRingingConnectionP(c);
     }
 
+    public static void checkWfcWifiOnlyModeBeforeDial(ImsPhone imsPhone, Context context)
+            throws CallStateException {
+        if (imsPhone == null ||
+                !imsPhone.isVowifiEnabled()) {
+            boolean wfcWiFiOnly = (ImsManager.isWfcEnabledByPlatform(context) &&
+                    ImsManager.isWfcEnabledByUser(context) &&
+                    (ImsManager.getWfcMode(context) ==
+                            ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY));
+            if (wfcWiFiOnly) {
+                throw new CallStateException(
+                        CallStateException.ERROR_DISCONNECTED,
+                        "WFC Wi-Fi Only Mode: IMS not registered");
+            }
+        }
+    }
 
     @Override
     public Connection