SIP/phone: check the SIP feature before making a SIP call

http://b/3002046

Change-Id: I4fd0d779b9f641996a586ca62199ead472dd8763
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c1e5ee3..1a58fac 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1367,6 +1367,8 @@
     <string name="no_internet_available">To place an Internet call, check your Internet connectiviy first.</string>
     <!-- Message of the alert dialog to notify user that there is no WIFI connectivity. [CHAR LIMIT=NONE] -->
     <string name="no_wifi_available">Internet call is only available on WIFI. Enable your WIFI connectiviy in Settings > Wireless &amp; network settings.</string>
+    <!-- Title of the alert dialog to notify user that Internet call is not supported. [CHAR LIMIT=40] -->
+    <string name="no_voip">Internet call is not supported on this device.</string>
 
     <!-- Do not translate the following strings. Used for the Internet call options. Need to be in-sync with Settings.System.SIP_ strings. -->
     <string translatable="false" name="sip_always">SIP_ALWAYS</string>
diff --git a/src/com/android/phone/SipCallOptionHandler.java b/src/com/android/phone/SipCallOptionHandler.java
index 35e7425..b7b9318 100644
--- a/src/com/android/phone/SipCallOptionHandler.java
+++ b/src/com/android/phone/SipCallOptionHandler.java
@@ -58,7 +58,8 @@
     static final int DIALOG_SELECT_OUTGOING_SIP_PHONE = 1;
     static final int DIALOG_START_SIP_SETTINGS = 2;
     static final int DIALOG_NO_INTERNET_ERROR = 3;
-    static final int DIALOG_SIZE = 4;
+    static final int DIALOG_NO_VOIP = 4;
+    static final int DIALOG_SIZE = 5;
 
     private Intent mIntent;
     private List<SipProfile> mProfileList;
@@ -103,6 +104,7 @@
         //       CallManager would then find the best match for every
         //       outgoing call.)
 
+        boolean voipSupported = SipManager.isVoipSupported(this);
         mSipSharedPreferences = new SipSharedPreferences(this);
         mCallOption = mSipSharedPreferences.getSipCallOption();
         Log.v(TAG, "Call option is " + mCallOption);
@@ -113,8 +115,8 @@
             mUseSipPhone = true;
         }
 
-        if (!mUseSipPhone &&
-                mCallOption.equals(Settings.System.SIP_ASK_ME_EACH_TIME)) {
+        if (!mUseSipPhone && voipSupported
+                && mCallOption.equals(Settings.System.SIP_ASK_ME_EACH_TIME)) {
             showDialog(DIALOG_SELECT_PHONE_TYPE);
             return;
         }
@@ -122,7 +124,11 @@
             mUseSipPhone = true;
         }
         if (mUseSipPhone) {
-            startGetPrimarySipPhoneThread();
+            if (voipSupported) {
+                startGetPrimarySipPhoneThread();
+            } else {
+                showDialog(DIALOG_NO_VOIP);
+            }
         } else {
             setResultAndFinish();
         }
@@ -181,6 +187,14 @@
                     .setOnCancelListener(this)
                     .create();
             break;
+        case DIALOG_NO_VOIP:
+            dialog = new AlertDialog.Builder(this)
+                    .setTitle(R.string.no_voip)
+                    .setIcon(android.R.drawable.ic_dialog_alert)
+                    .setPositiveButton(android.R.string.ok, this)
+                    .setOnCancelListener(this)
+                    .create();
+            break;
         default:
             dialog = null;
         }
@@ -227,7 +241,8 @@
             }
         } else if (dialog == mDialogs[DIALOG_SELECT_OUTGOING_SIP_PHONE]) {
             mOutgoingSipProfile = mProfileList.get(id);
-        } else if (dialog == mDialogs[DIALOG_NO_INTERNET_ERROR]) {
+        } else if ((dialog == mDialogs[DIALOG_NO_INTERNET_ERROR])
+                || (dialog == mDialogs[DIALOG_NO_VOIP])) {
             finish();
             return;
         } else {