Merge "[DS] Location does not work with only Cellular data" into lmp-mr1-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6b35ada..c47db4f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1279,5 +1279,8 @@
 
     <!-- DO NOT TRANSLATE. Internal key for a voicemail notification preference. -->
     <string name="voicemail_notification_ringtone_key">voicemail_notification_ringtone_key</string>
+    <!-- DO NOT TRANSLATE. Internal key for a voicemail notification preference. -->
     <string name="voicemail_notification_vibrate_key">voicemail_notification_vibrate_key</string>
+    <!-- DO NOT TRANSLATE. Internal key for tty mode preference. -->
+    <string name="tty_mode_key">button_tty_mode_key</string>
 </resources>
diff --git a/res/xml/call_feature_setting.xml b/res/xml/call_feature_setting.xml
index cef723d..4ae0bf6 100644
--- a/res/xml/call_feature_setting.xml
+++ b/res/xml/call_feature_setting.xml
@@ -94,8 +94,8 @@
         android:persistent="false"
         android:summary="@string/auto_retry_mode_summary"/>
 
-    <ListPreference
-        android:key="button_tty_mode_key"
+    <com.android.phone.settings.TtyModeListPreference
+        android:key="@string/tty_mode_key"
         android:title="@string/tty_mode_option_title"
         android:summary="@string/tty_mode_option_summary"
         android:persistent="false"
diff --git a/res/xml/phone_account_settings.xml b/res/xml/phone_account_settings.xml
index f818baa..ff01d34 100644
--- a/res/xml/phone_account_settings.xml
+++ b/res/xml/phone_account_settings.xml
@@ -28,6 +28,14 @@
         android:defaultValue=""
         android:persistent="false" />
 
+    <com.android.phone.settings.TtyModeListPreference
+        android:key="@string/tty_mode_key"
+        android:title="@string/tty_mode_option_title"
+        android:summary="@string/tty_mode_option_summary"
+        android:persistent="false"
+        android:entries="@array/tty_mode_entries"
+        android:entryValues="@array/tty_mode_values"/>
+
     <PreferenceCategory
         android:key="phone_accounts_call_assistant_settings_category_key"
         android:title="@string/wifi_calling_call_assistant"
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 1d054a6..a971373 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -55,6 +55,7 @@
 import com.android.phone.common.util.SettingsUtil;
 import com.android.phone.settings.AccountSelectionPreference;
 import com.android.phone.settings.CallForwardInfoUtil;
+import com.android.phone.settings.TtyModeListPreference;
 import com.android.phone.settings.VoicemailDialogUtil;
 import com.android.phone.settings.VoicemailNotificationSettingsUtil;
 import com.android.phone.settings.VoicemailProviderListPreference;
@@ -191,8 +192,7 @@
     private CheckBoxPreference mButtonAutoRetry;
     private CheckBoxPreference mButtonHAC;
     private ListPreference mButtonDTMF;
-    private ListPreference mButtonTTY;
-    private Preference mPhoneAccountSettingsPreference;
+    private TtyModeListPreference mButtonTTY;
     private VoicemailProviderListPreference mVoicemailProviders;
     private PreferenceScreen mVoicemailSettingsScreen;
     private PreferenceScreen mVoicemailSettings;
@@ -376,8 +376,6 @@
             int index = mButtonDTMF.findIndexOfValue((String) objValue);
             Settings.System.putInt(mPhone.getContext().getContentResolver(),
                     Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, index);
-        } else if (preference == mButtonTTY) {
-            handleTTYChange(preference, objValue);
         } else if (preference == mVoicemailProviders) {
             final String newProviderKey = (String) objValue;
 
@@ -1124,23 +1122,10 @@
         mSetupVoicemail = mShowVoicemailPreference &&
                 getIntent().getBooleanExtra(SETUP_VOICEMAIL_EXTRA, false);
 
-        mSubscriptionInfoHelper = new SubscriptionInfoHelper(getIntent());
+        mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
         mSubscriptionInfoHelper.setActionBarTitle(
                 getActionBar(), getResources(), R.string.call_settings_with_label);
         mPhone = mSubscriptionInfoHelper.getPhone();
-   }
-
-    private void initPhoneAccountPreferences() {
-        mPhoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
-
-        TelecomManager telecomManager = TelecomManager.from(this);
-        TelephonyManager telephonyManager =
-                (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-
-        if ((telecomManager.getSimCallManagers().isEmpty() && !SipUtil.isVoipSupported(this))
-                || telephonyManager.getPhoneCount() > 1) {
-            getPreferenceScreen().removePreference(mPhoneAccountSettingsPreference);
-        }
     }
 
     @Override
@@ -1155,7 +1140,15 @@
 
         addPreferencesFromResource(R.xml.call_feature_setting);
 
-        initPhoneAccountPreferences();
+        TelecomManager telecomManager = TelecomManager.from(this);
+        TelephonyManager telephonyManager =
+                (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
+
+        Preference phoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
+        if (telephonyManager.isMultiSimEnabled() || (telecomManager.getSimCallManagers().isEmpty()
+                    && !SipUtil.isVoipSupported(mPhone.getContext()))) {
+            getPreferenceScreen().removePreference(phoneAccountSettingsPreference);
+        }
 
         PreferenceScreen prefSet = getPreferenceScreen();
         mSubMenuVoicemailSettings = (EditPhoneNumberPreference) findPreference(BUTTON_VOICEMAIL_KEY);
@@ -1166,7 +1159,8 @@
         mButtonDTMF = (ListPreference) findPreference(BUTTON_DTMF_KEY);
         mButtonAutoRetry = (CheckBoxPreference) findPreference(BUTTON_RETRY_KEY);
         mButtonHAC = (CheckBoxPreference) findPreference(BUTTON_HAC_KEY);
-        mButtonTTY = (ListPreference) findPreference(BUTTON_TTY_KEY);
+        mButtonTTY = (TtyModeListPreference) findPreference(
+                getResources().getString(R.string.tty_mode_key));
 
         mVoicemailProviders = (VoicemailProviderListPreference) findPreference(
                 BUTTON_VOICEMAIL_PROVIDER_KEY);
@@ -1219,14 +1213,8 @@
             mButtonHAC = null;
         }
 
-        TelecomManager telecomManager = TelecomManager.from(this);
-        if (telecomManager != null && telecomManager.isTtySupported()) {
-            mButtonTTY.setOnPreferenceChangeListener(this);
-            int settingsTtyMode = Settings.Secure.getInt(getContentResolver(),
-                    Settings.Secure.PREFERRED_TTY_MODE,
-                    TelecomManager.TTY_MODE_OFF);
-            mButtonTTY.setValue(Integer.toString(settingsTtyMode));
-            updatePreferredTtyModeSummary(settingsTtyMode);
+        if (!telephonyManager.isMultiSimEnabled() && telecomManager.isTtySupported()) {
+            mButtonTTY.init();
         } else {
             prefSet.removePreference(mButtonTTY);
             mButtonTTY = null;
@@ -1257,19 +1245,19 @@
                         addPreferencesFromResource(R.xml.cdma_call_privacy);
                     }
                 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
-                    fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(this, FdnSetting.class));
+                    fdnButton.setIntent(mSubscriptionInfoHelper.getIntent(FdnSetting.class));
 
                     if (getResources().getBoolean(R.bool.config_additional_call_setting)) {
                         addPreferencesFromResource(R.xml.gsm_umts_call_options);
 
                         Preference callForwardingPref = prefSet.findPreference(CALL_FORWARDING_KEY);
                         callForwardingPref.setIntent(mSubscriptionInfoHelper.getIntent(
-                                this, GsmUmtsCallForwardOptions.class));
+                                GsmUmtsCallForwardOptions.class));
 
                         Preference additionalGsmSettingsPref =
                                 prefSet.findPreference(ADDITIONAL_GSM_SETTINGS_KEY);
                         additionalGsmSettingsPref.setIntent(mSubscriptionInfoHelper.getIntent(
-                                this, GsmUmtsAdditionalCallOptions.class));
+                                GsmUmtsAdditionalCallOptions.class));
                     }
                 } else {
                     throw new IllegalStateException("Unexpected phone type: " + phoneType);
@@ -1314,53 +1302,6 @@
         }
     }
 
-    private void handleTTYChange(Preference preference, Object objValue) {
-        int buttonTtyMode;
-        buttonTtyMode = Integer.valueOf((String) objValue).intValue();
-        int settingsTtyMode = android.provider.Settings.Secure.getInt(
-                getContentResolver(),
-                android.provider.Settings.Secure.PREFERRED_TTY_MODE,
-                TelecomManager.TTY_MODE_OFF);
-        if (DBG) log("handleTTYChange: requesting set TTY mode enable (TTY) to" +
-                Integer.toString(buttonTtyMode));
-
-        if (buttonTtyMode != settingsTtyMode) {
-            switch(buttonTtyMode) {
-            case TelecomManager.TTY_MODE_OFF:
-            case TelecomManager.TTY_MODE_FULL:
-            case TelecomManager.TTY_MODE_HCO:
-            case TelecomManager.TTY_MODE_VCO:
-                android.provider.Settings.Secure.putInt(getContentResolver(),
-                        android.provider.Settings.Secure.PREFERRED_TTY_MODE, buttonTtyMode);
-                break;
-            default:
-                buttonTtyMode = TelecomManager.TTY_MODE_OFF;
-            }
-
-            mButtonTTY.setValue(Integer.toString(buttonTtyMode));
-            updatePreferredTtyModeSummary(buttonTtyMode);
-            Intent ttyModeChanged = new Intent(TelecomManager.ACTION_TTY_PREFERRED_MODE_CHANGED);
-            ttyModeChanged.putExtra(TelecomManager.EXTRA_TTY_PREFERRED_MODE, buttonTtyMode);
-            sendBroadcastAsUser(ttyModeChanged, UserHandle.ALL);
-        }
-    }
-
-    private void updatePreferredTtyModeSummary(int TtyMode) {
-        String [] txts = getResources().getStringArray(R.array.tty_mode_entries);
-        switch(TtyMode) {
-            case TelecomManager.TTY_MODE_OFF:
-            case TelecomManager.TTY_MODE_HCO:
-            case TelecomManager.TTY_MODE_VCO:
-            case TelecomManager.TTY_MODE_FULL:
-                mButtonTTY.setSummary(txts[TtyMode]);
-                break;
-            default:
-                mButtonTTY.setEnabled(false);
-                mButtonTTY.setSummary(txts[TelecomManager.TTY_MODE_OFF]);
-                break;
-        }
-    }
-
     private static void log(String msg) {
         Log.d(LOG_TAG, msg);
     }
@@ -1432,8 +1373,8 @@
      * This is useful for implementing "HomeAsUp" capability for second-level Settings.
      */
     public static void goUpToTopLevelSetting(
-                Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
-        Intent intent = subscriptionInfoHelper.getIntent(activity, CallFeaturesSetting.class);
+            Activity activity, SubscriptionInfoHelper subscriptionInfoHelper) {
+        Intent intent = subscriptionInfoHelper.getIntent(CallFeaturesSetting.class);
         intent.setAction(Intent.ACTION_MAIN);
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         activity.startActivity(intent);
diff --git a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
index 30ce1fa..88d32fb 100644
--- a/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
+++ b/src/com/android/phone/GsmUmtsAdditionalCallOptions.java
@@ -33,7 +33,7 @@
 
         addPreferencesFromResource(R.xml.gsm_umts_additional_options);
 
-        mSubscriptionInfoHelper = new SubscriptionInfoHelper(getIntent());
+        mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
         mSubscriptionInfoHelper.setActionBarTitle(
                 getActionBar(), getResources(), R.string.additional_gsm_call_settings_with_label);
         mPhone = mSubscriptionInfoHelper.getPhone();
diff --git a/src/com/android/phone/GsmUmtsCallForwardOptions.java b/src/com/android/phone/GsmUmtsCallForwardOptions.java
index fe27850..5a16edc 100644
--- a/src/com/android/phone/GsmUmtsCallForwardOptions.java
+++ b/src/com/android/phone/GsmUmtsCallForwardOptions.java
@@ -53,7 +53,7 @@
 
         addPreferencesFromResource(R.xml.callforward_options);
 
-        mSubscriptionInfoHelper = new SubscriptionInfoHelper(getIntent());
+        mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
         mSubscriptionInfoHelper.setActionBarTitle(
                 getActionBar(), getResources(), R.string.call_forwarding_settings_with_label);
         mPhone = mSubscriptionInfoHelper.getPhone();
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index efb61f6..02278a5 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -607,8 +607,6 @@
                 //Set the modem network mode
                 mPhone.setPreferredNetworkType(modemNetworkMode, mHandler
                         .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
-
-                updateBody();
             }
         } else if (preference == mButtonEnabledNetworks) {
             mButtonEnabledNetworks.setValue((String) objValue);
@@ -683,6 +681,7 @@
             return true;
         }
 
+        updateBody();
         // always let the preference setting proceed.
         return true;
     }
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index b97f3b6..f44599d 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -71,6 +71,8 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -2148,6 +2150,15 @@
     }
 
     @Override
+    public boolean setRoamingOverride(List<String> gsmRoamingList,
+            List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
+            List<String> cdmaNonRoamingList) {
+        enforceCarrierPrivilege();
+        return mPhone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
+                cdmaNonRoamingList);
+    }
+
+    @Override
     public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
         enforceModifyPermission();
 
diff --git a/src/com/android/phone/SubscriptionInfoHelper.java b/src/com/android/phone/SubscriptionInfoHelper.java
index f325b1a..9f0ebd0 100644
--- a/src/com/android/phone/SubscriptionInfoHelper.java
+++ b/src/com/android/phone/SubscriptionInfoHelper.java
@@ -22,6 +22,7 @@
 import android.content.res.Resources;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 
 import com.android.phone.PhoneGlobals;
@@ -45,24 +46,26 @@
     private static final String SUB_LABEL_EXTRA =
             "com.android.phone.settings.SubscriptionInfoHelper.SubscriptionLabel";
 
+    private static Context mContext;
+
     private static int mSubId = NO_SUB_ID;
     private static String mSubLabel;
 
     /**
      * Instantiates the helper, by extracting the subscription id and label from the intent.
      */
-    public SubscriptionInfoHelper(Intent intent) {
+    public SubscriptionInfoHelper(Context context, Intent intent) {
+        mContext = context;
         mSubId = intent.getIntExtra(SUB_ID_EXTRA, NO_SUB_ID);
         mSubLabel = intent.getStringExtra(SUB_LABEL_EXTRA);
     }
 
     /**
-     * @param context The context.
      * @param newActivityClass The class of the activity for the intent to start.
      * @return Intent containing extras for the subscription id and label if they exist.
      */
-    public Intent getIntent(Context context, Class newActivityClass) {
-        Intent intent = new Intent(context, newActivityClass);
+    public Intent getIntent(Class newActivityClass) {
+        Intent intent = new Intent(mContext, newActivityClass);
 
         if (hasSubId()) {
             intent.putExtra(SUB_ID_EXTRA, mSubId);
@@ -106,6 +109,10 @@
             return;
         }
 
+        if (!TelephonyManager.from(mContext).isMultiSimEnabled()) {
+            return;
+        }
+
         String title = String.format(res.getString(resId), mSubLabel);
         actionBar.setTitle(title);
     }
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index 83fa5da..56cd0cb 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -85,15 +85,20 @@
                 (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
         mAccountList = (PreferenceCategory) getPreferenceScreen().findPreference(
                 ACCOUNTS_LIST_CATEGORY_KEY);
-        if (telephonyManager.getPhoneCount() > 1) {
+        TtyModeListPreference ttyModeListPreference =
+                (TtyModeListPreference) getPreferenceScreen().findPreference(
+                        getResources().getString(R.string.tty_mode_key));
+        if (telephonyManager.isMultiSimEnabled()) {
             initAccountList();
+            ttyModeListPreference.init();
         } else {
             getPreferenceScreen().removePreference(mAccountList);
+            getPreferenceScreen().removePreference(ttyModeListPreference);
         }
 
         mDefaultOutgoingAccount = (AccountSelectionPreference)
                 getPreferenceScreen().findPreference(DEFAULT_OUTGOING_ACCOUNT_KEY);
-        if (mTelecomManager.getCallCapablePhoneAccounts().size() > 1) {
+        if (mTelecomManager.hasMultipleCallCapableAccounts()) {
             mDefaultOutgoingAccount.setListener(this);
             updateDefaultOutgoingAccountsModel();
         } else {
diff --git a/src/com/android/phone/settings/TtyModeListPreference.java b/src/com/android/phone/settings/TtyModeListPreference.java
new file mode 100644
index 0000000..e8ef099
--- /dev/null
+++ b/src/com/android/phone/settings/TtyModeListPreference.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.phone.settings;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.UserHandle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.provider.Settings;
+import android.telecom.TelecomManager;
+import android.util.AttributeSet;
+import android.util.Log;
+
+import com.android.phone.PhoneGlobals;
+import com.android.phone.R;
+
+public class TtyModeListPreference extends ListPreference
+        implements Preference.OnPreferenceChangeListener {
+    private static final String LOG_TAG = TtyModeListPreference.class.getSimpleName();
+    private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
+
+    public TtyModeListPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public void init() {
+        setOnPreferenceChangeListener(this);
+
+        int settingsTtyMode = Settings.Secure.getInt(getContext().getContentResolver(),
+                Settings.Secure.PREFERRED_TTY_MODE,
+                TelecomManager.TTY_MODE_OFF);
+        setValue(Integer.toString(settingsTtyMode));
+        updatePreferredTtyModeSummary(settingsTtyMode);
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object objValue) {
+        if (preference == this) {
+            int buttonTtyMode;
+            buttonTtyMode = Integer.valueOf((String) objValue).intValue();
+            int settingsTtyMode = android.provider.Settings.Secure.getInt(
+                    getContext().getContentResolver(),
+                    Settings.Secure.PREFERRED_TTY_MODE,
+                    TelecomManager.TTY_MODE_OFF);
+            if (DBG) log("handleTTYChange: requesting set TTY mode enable (TTY) to" +
+                    Integer.toString(buttonTtyMode));
+
+            if (buttonTtyMode != settingsTtyMode) {
+                switch(buttonTtyMode) {
+                    case TelecomManager.TTY_MODE_OFF:
+                    case TelecomManager.TTY_MODE_FULL:
+                    case TelecomManager.TTY_MODE_HCO:
+                    case TelecomManager.TTY_MODE_VCO:
+                        Settings.Secure.putInt(
+                                getContext().getContentResolver(),
+                                Settings.Secure.PREFERRED_TTY_MODE,
+                                buttonTtyMode);
+                        break;
+                    default:
+                        buttonTtyMode = TelecomManager.TTY_MODE_OFF;
+                }
+
+                setValue(Integer.toString(buttonTtyMode));
+                updatePreferredTtyModeSummary(buttonTtyMode);
+                Intent ttyModeChanged =
+                        new Intent(TelecomManager.ACTION_TTY_PREFERRED_MODE_CHANGED);
+                ttyModeChanged.putExtra(TelecomManager.EXTRA_TTY_PREFERRED_MODE, buttonTtyMode);
+                getContext().sendBroadcastAsUser(ttyModeChanged, UserHandle.ALL);
+            }
+        }
+        return true;
+    }
+
+    private void updatePreferredTtyModeSummary(int TtyMode) {
+        String [] txts = getContext().getResources().getStringArray(R.array.tty_mode_entries);
+        switch(TtyMode) {
+            case TelecomManager.TTY_MODE_OFF:
+            case TelecomManager.TTY_MODE_HCO:
+            case TelecomManager.TTY_MODE_VCO:
+            case TelecomManager.TTY_MODE_FULL:
+                setSummary(txts[TtyMode]);
+                break;
+            default:
+                setEnabled(false);
+                setSummary(txts[TelecomManager.TTY_MODE_OFF]);
+                break;
+        }
+    }
+
+    private static void log(String msg) {
+        Log.d(LOG_TAG, msg);
+    }
+}
diff --git a/src/com/android/phone/settings/VoicemailRingtonePreference.java b/src/com/android/phone/settings/VoicemailRingtonePreference.java
index 3dbb99f..4ee4e64 100644
--- a/src/com/android/phone/settings/VoicemailRingtonePreference.java
+++ b/src/com/android/phone/settings/VoicemailRingtonePreference.java
@@ -3,7 +3,6 @@
 import android.content.Context;
 import android.media.RingtoneManager;
 import android.net.Uri;
-import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
 import android.preference.Preference;
@@ -11,7 +10,6 @@
 import android.util.AttributeSet;
 
 import com.android.internal.telephony.Phone;
-import com.android.phone.PhoneGlobals;
 import com.android.phone.common.util.SettingsUtil;
 
 /**
@@ -44,6 +42,9 @@
     public void init(Phone phone) {
         mPhone = phone;
 
+        // Requesting the ringtone will trigger migration if necessary.
+        VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
+
         final Preference preference = this;
         final String preferenceKey =
                 VoicemailNotificationSettingsUtil.getVoicemailRingtoneSharedPrefsKey(mPhone);
diff --git a/src/com/android/phone/settings/fdn/DeleteFdnContactScreen.java b/src/com/android/phone/settings/fdn/DeleteFdnContactScreen.java
index d54de43..fa32a25 100644
--- a/src/com/android/phone/settings/fdn/DeleteFdnContactScreen.java
+++ b/src/com/android/phone/settings/fdn/DeleteFdnContactScreen.java
@@ -95,7 +95,7 @@
     private void resolveIntent() {
         Intent intent = getIntent();
 
-        mSubscriptionInfoHelper = new SubscriptionInfoHelper(intent);
+        mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, intent);
 
         mName =  intent.getStringExtra(INTENT_EXTRA_NAME);
         mNumber =  intent.getStringExtra(INTENT_EXTRA_NUMBER);
diff --git a/src/com/android/phone/settings/fdn/EditFdnContactScreen.java b/src/com/android/phone/settings/fdn/EditFdnContactScreen.java
index 944eaad..00bd9fc 100644
--- a/src/com/android/phone/settings/fdn/EditFdnContactScreen.java
+++ b/src/com/android/phone/settings/fdn/EditFdnContactScreen.java
@@ -216,7 +216,7 @@
     private void resolveIntent() {
         Intent intent = getIntent();
 
-        mSubscriptionInfoHelper = new SubscriptionInfoHelper(intent);
+        mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, intent);
 
         mName =  intent.getStringExtra(INTENT_EXTRA_NAME);
         mNumber =  intent.getStringExtra(INTENT_EXTRA_NUMBER);
@@ -335,7 +335,7 @@
     private void deleteSelected() {
         // delete ONLY if this is NOT a new contact.
         if (!mAddContact) {
-            Intent intent = mSubscriptionInfoHelper.getIntent(this, DeleteFdnContactScreen.class);
+            Intent intent = mSubscriptionInfoHelper.getIntent(DeleteFdnContactScreen.class);
             intent.putExtra(INTENT_EXTRA_NAME, mName);
             intent.putExtra(INTENT_EXTRA_NUMBER, mNumber);
             startActivity(intent);
diff --git a/src/com/android/phone/settings/fdn/FdnList.java b/src/com/android/phone/settings/fdn/FdnList.java
index d7bfde2..0174a82 100644
--- a/src/com/android/phone/settings/fdn/FdnList.java
+++ b/src/com/android/phone/settings/fdn/FdnList.java
@@ -57,7 +57,7 @@
             actionBar.setDisplayHomeAsUpEnabled(true);
         }
 
-        mSubscriptionInfoHelper = new SubscriptionInfoHelper(getIntent());
+        mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
         mSubscriptionInfoHelper.setActionBarTitle(
                 getActionBar(), getResources(), R.string.fdn_list_with_label);
     }
@@ -101,7 +101,7 @@
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case android.R.id.home:  // See ActionBar#setDisplayHomeAsUpEnabled()
-                Intent intent = mSubscriptionInfoHelper.getIntent(this, FdnSetting.class);
+                Intent intent = mSubscriptionInfoHelper.getIntent(FdnSetting.class);
                 intent.setAction(Intent.ACTION_MAIN);
                 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                 startActivity(intent);
@@ -132,7 +132,7 @@
 
     private void addContact() {
         //If there is no INTENT_EXTRA_NAME provided, EditFdnContactScreen treats it as an "add".
-        Intent intent = mSubscriptionInfoHelper.getIntent(this, EditFdnContactScreen.class);
+        Intent intent = mSubscriptionInfoHelper.getIntent(EditFdnContactScreen.class);
         startActivity(intent);
     }
 
@@ -154,7 +154,7 @@
             String name = mCursor.getString(NAME_COLUMN);
             String number = mCursor.getString(NUMBER_COLUMN);
 
-            Intent intent = mSubscriptionInfoHelper.getIntent(this, EditFdnContactScreen.class);
+            Intent intent = mSubscriptionInfoHelper.getIntent(EditFdnContactScreen.class);
             intent.putExtra(INTENT_EXTRA_NAME, name);
             intent.putExtra(INTENT_EXTRA_NUMBER, number);
             startActivity(intent);
@@ -166,7 +166,7 @@
             String name = mCursor.getString(NAME_COLUMN);
             String number = mCursor.getString(NUMBER_COLUMN);
 
-            Intent intent = mSubscriptionInfoHelper.getIntent(this, DeleteFdnContactScreen.class);
+            Intent intent = mSubscriptionInfoHelper.getIntent(DeleteFdnContactScreen.class);
             intent.putExtra(INTENT_EXTRA_NAME, name);
             intent.putExtra(INTENT_EXTRA_NUMBER, number);
             startActivity(intent);
diff --git a/src/com/android/phone/settings/fdn/FdnSetting.java b/src/com/android/phone/settings/fdn/FdnSetting.java
index acbe0b8..b825f7a 100644
--- a/src/com/android/phone/settings/fdn/FdnSetting.java
+++ b/src/com/android/phone/settings/fdn/FdnSetting.java
@@ -455,7 +455,7 @@
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
-        mSubscriptionInfoHelper = new SubscriptionInfoHelper(getIntent());
+        mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
         mPhone = mSubscriptionInfoHelper.getPhone();
 
         addPreferencesFromResource(R.xml.fdn_setting);
@@ -473,7 +473,7 @@
 
         PreferenceScreen fdnListPref =
                 (PreferenceScreen) prefSet.findPreference(FDN_LIST_PREF_SCREEN_KEY);
-        fdnListPref.setIntent(mSubscriptionInfoHelper.getIntent(this, FdnList.class));
+        fdnListPref.setIntent(mSubscriptionInfoHelper.getIntent(FdnList.class));
 
         // Only reset the pin change dialog if we're not in the middle of changing it.
         if (icicle == null) {
diff --git a/src/com/android/services/telephony/DisconnectCauseUtil.java b/src/com/android/services/telephony/DisconnectCauseUtil.java
index 8f38ee1..0e9c0d0 100644
--- a/src/com/android/services/telephony/DisconnectCauseUtil.java
+++ b/src/com/android/services/telephony/DisconnectCauseUtil.java
@@ -132,7 +132,10 @@
                 return DisconnectCause.UNKNOWN;
 
             default:
-                throw new IllegalStateException("Unrecognized Telephony DisconnectCause");
+                Log.w("DisconnectCauseUtil.toTelecomDisconnectCauseCode",
+                        "Unrecognized Telephony DisconnectCause "
+                        + telephonyDisconnectCause);
+                return DisconnectCause.UNKNOWN;
         }
     }
 
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 9877269..7f92c92 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -60,7 +60,14 @@
                     AsyncResult ar = (AsyncResult) msg.obj;
                     com.android.internal.telephony.Connection connection =
                          (com.android.internal.telephony.Connection) ar.result;
-                    setOriginalConnection(connection);
+                    if ((connection.getAddress() != null &&
+                                    mOriginalConnection.getAddress() != null &&
+                            mOriginalConnection.getAddress().contains(connection.getAddress())) ||
+                            connection.getStateBeforeHandover() == mOriginalConnection.getState()) {
+                        Log.d(TelephonyConnection.this, "SettingOriginalConnection " +
+                                mOriginalConnection.toString() + " with " + connection.toString());
+                        setOriginalConnection(connection);
+                    }
                     break;
                 case MSG_RINGBACK_TONE:
                     Log.v(TelephonyConnection.this, "MSG_RINGBACK_TONE");