Merge "Add VoicemailRingtonePreference to contain lookup logic." into lmp-mr1-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d54b242..5d9f835 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1229,9 +1229,9 @@
     <string name="enable_video_calling_title">Turn on video calling</string>
 
     <!-- Message for dialog shown when the user tries to turn on video calling but enhanced 4G LTE
-         is disabled. -->
+         is disabled. They have to turn on Enhanced 4G LTE capability in network settings first. -->
     <string name="enable_video_calling_dialog_msg">
-        To turn on video calling, you need to enable Enhanced 4G LTE Mode in system settings.
+        To turn on video calling, you need to enable Enhanced 4G LTE Mode in network settings.
     </string>
 
     <!-- Label for action button in dialog which opens mobile network settings, for video calling
diff --git a/sip/src/com/android/services/telephony/sip/SipUtil.java b/sip/src/com/android/services/telephony/sip/SipUtil.java
index f93f02d..df1a03a 100644
--- a/sip/src/com/android/services/telephony/sip/SipUtil.java
+++ b/sip/src/com/android/services/telephony/sip/SipUtil.java
@@ -22,6 +22,7 @@
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
+import android.graphics.BitmapFactory;
 import android.net.Uri;
 import android.net.sip.SipManager;
 import android.net.sip.SipProfile;
@@ -118,7 +119,9 @@
                 .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
                 .setAddress(Uri.parse(profile.getUriString()))
                 .setShortDescription(profile.getDisplayName())
-                .setIconResId(R.drawable.ic_dialer_sip_black_24dp)
+                .setIconBitmap(BitmapFactory.decodeResource(
+                        context.getResources(),
+                        R.drawable.ic_dialer_sip_black_24dp))
                 .setSupportedUriSchemes(supportedUriSchemes);
 
         return builder.build();
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 753341c..e468027 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -56,6 +56,7 @@
 import android.view.WindowManager;
 import android.widget.ListAdapter;
 
+import com.android.ims.ImsManager;
 import com.android.internal.telephony.CallForwardInfo;
 import com.android.internal.telephony.CommandsInterface;
 import com.android.internal.telephony.Phone;
@@ -488,7 +489,27 @@
                 saveVoiceMailAndForwardingNumber(newProviderKey, newProviderSettings);
             }
         } else if (preference == mEnableVideoCalling) {
-            PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
+            if (ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())) {
+                PhoneGlobals.getInstance().phoneMgr.enableVideoCalling((boolean) objValue);
+            } else {
+                AlertDialog.Builder builder = new AlertDialog.Builder(this);
+                DialogInterface.OnClickListener networkSettingsClickListener =
+                        new Dialog.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialog, int which) {
+                                startActivity(new Intent(mPhone.getContext(),
+                                        com.android.phone.MobileNetworkSettings.class));
+                            }
+                        };
+                builder.setMessage(getResources().getString(
+                                R.string.enable_video_calling_dialog_msg))
+                        .setNeutralButton(getResources().getString(
+                                R.string.enable_video_calling_dialog_settings),
+                                networkSettingsClickListener)
+                        .setPositiveButton(android.R.string.ok, null)
+                        .show();
+                return false;
+            }
         }
         // always let the preference setting proceed.
         return true;
@@ -1457,8 +1478,7 @@
         mButtonHAC = (CheckBoxPreference) findPreference(BUTTON_HAC_KEY);
         mButtonTTY = (ListPreference) findPreference(BUTTON_TTY_KEY);
         mVoicemailProviders = (ListPreference) findPreference(BUTTON_VOICEMAIL_PROVIDER_KEY);
-        CheckBoxPreference mEnableVideoCalling =
-                (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
+        mEnableVideoCalling = (CheckBoxPreference) findPreference(ENABLE_VIDEO_CALLING_KEY);
 
         if (mVoicemailProviders != null) {
             mVoicemailProviders.setOnPreferenceChangeListener(this);
@@ -1570,9 +1590,11 @@
                     BUTTON_VOICEMAIL_NOTIFICATION_VIBRATE_KEY, false));
         }
 
-        if (ImsUtil.isImsEnabled(mPhone.getContext()) && ENABLE_VT_FLAG) {
-            mEnableVideoCalling.setChecked(
-                    PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled());
+        if (ImsManager.isVtEnabledByPlatform(mPhone.getContext()) && ENABLE_VT_FLAG) {
+            boolean currentValue =
+                    ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
+                    ? PhoneGlobals.getInstance().phoneMgr.isVideoCallingEnabled() : false;
+            mEnableVideoCalling.setChecked(currentValue);
             mEnableVideoCalling.setOnPreferenceChangeListener(this);
         } else {
             prefSet.removePreference(mEnableVideoCalling);
diff --git a/src/com/android/phone/ImsUtil.java b/src/com/android/phone/ImsUtil.java
index 4f7eb7f..c3d780b 100644
--- a/src/com/android/phone/ImsUtil.java
+++ b/src/com/android/phone/ImsUtil.java
@@ -16,18 +16,10 @@
 
 package com.android.phone;
 
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.provider.Settings.SettingNotFoundException;
-import android.util.Log;
-
-import com.android.internal.telephony.Phone;
 import com.android.phone.PhoneGlobals;
 
 public class ImsUtil {
 
-    private static final String TAG = ImsUtil.class.getSimpleName();
     private static boolean sImsPhoneSupported = false;
 
     private ImsUtil() {
@@ -45,30 +37,4 @@
         return sImsPhoneSupported;
 
     }
-
-    /**
-     * @see MobileNetworkSettings#setIMS
-     * @param context The context to get the content resolver from.
-     * @return Whether IMS is turned on by the user system setting.
-     */
-    static boolean isImsEnabled(Context context) {
-        int value = 0;
-        try {
-            value = android.provider.Settings.Global.getInt(
-                    context.getContentResolver(),
-                    android.provider.Settings.Global.ENHANCED_4G_MODE_ENABLED);
-        } catch (SettingNotFoundException e) {
-            return false;
-        }
-
-        switch (value) {
-            case 0:
-                return false;
-            case 1:
-                return true;
-            default:
-                Log.wtf(TAG,"Unexpected value for ENHANCED_4G_MODE_ENABLED: " + value);
-                return false;
-        }
-    }
 }
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 58b8599..b6a4498 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -53,6 +53,7 @@
 import android.util.Log;
 import android.util.Pair;
 
+import com.android.ims.ImsManager;
 import com.android.internal.telephony.CallManager;
 import com.android.internal.telephony.CommandException;
 import com.android.internal.telephony.Connection;
@@ -2084,7 +2085,8 @@
         // enabled video calling, if IMS is disabled we aren't able to support video calling.
         // In the long run, we may instead need to check if there exists a connection service
         // which can support video calling.
-        return mTelephonySharedPreferences.getBoolean(PREF_ENABLE_VIDEO_CALLING, true)
-                && ImsUtil.isImsEnabled(mPhone.getContext());
+        return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
+                && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
+                && mTelephonySharedPreferences.getBoolean(PREF_ENABLE_VIDEO_CALLING, true);
     }
 }
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index c5e5a41..f50db0c 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -21,6 +21,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.graphics.BitmapFactory;
 import android.net.Uri;
 import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
@@ -35,7 +36,6 @@
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.PhoneProxy;
-import com.android.internal.telephony.SubscriptionController;
 import com.android.internal.telephony.TelephonyIntents;
 import com.android.phone.R;
 
@@ -160,7 +160,9 @@
                     .setSubscriptionAddress(
                             Uri.fromParts(PhoneAccount.SCHEME_TEL, subNumber, null))
                     .setCapabilities(capabilities)
-                    .setIconResId(getPhoneAccountIcon(slotId))
+                    .setIconBitmap(BitmapFactory.decodeResource(
+                            mContext.getResources(),
+                            getPhoneAccountIcon(slotId)))
                     .setColor(color)
                     .setShortDescription(description)
                     .setSupportedUriSchemes(Arrays.asList(