Merge "DTAG: show "WLAN call" in in-call UI"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4517173..a5c583b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -58,9 +58,9 @@
     <protected-broadcast android:name= "android.intent.action.stk.session_end" />
     <protected-broadcast android:name= "android.intent.action.stk.icc_status_change" />
     <protected-broadcast android:name= "android.intent.action.stk.alpha_notify" />
-    <protected-broadcast android:name= "android.intent.action.CARRIER_SIGNAL_REDIRECTED" />
-    <protected-broadcast android:name= "android.intent.action.CARRIER_SIGNAL_REQUEST_NETWORK_FAILED" />
-    <protected-broadcast android:name= "android.intent.action.CARRIER_SIGNAL_PCO_VALUE" />
+    <protected-broadcast android:name= "com.android.internal.telephony.CARRIER_SIGNAL_REDIRECTED" />
+    <protected-broadcast android:name= "com.android.internal.telephony.CARRIER_SIGNAL_REQUEST_NETWORK_FAILED" />
+    <protected-broadcast android:name= "com.android.internal.telephony.CARRIER_SIGNAL_PCO_VALUE" />
     <protected-broadcast android:name= "android.intent.action.VOICEMAIL_SMS_RECEIVED" />
     <protected-broadcast android:name= "com.android.intent.isim_refresh" />
     <protected-broadcast android:name= "com.android.ims.IMS_SERVICE_UP" />
diff --git a/res/layout/network_setting.xml b/res/layout/network_setting.xml
new file mode 100644
index 0000000..bfc16dc
--- /dev/null
+++ b/res/layout/network_setting.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+             android:id="@+id/network_setting_content"
+             android:layout_height="match_parent"
+             android:layout_width="match_parent"/>
diff --git a/res/values-hi/strings.xml b/res/values-hi/strings.xml
index 0e26ab1..ea053cf 100644
--- a/res/values-hi/strings.xml
+++ b/res/values-hi/strings.xml
@@ -120,12 +120,12 @@
     <string name="updating_title" msgid="6146755386174019046">"कॉल सेटिंग"</string>
     <string name="call_settings_admin_user_only" msgid="4526094783818216374">"कॉल सेटिंग केवल व्यवस्थापक उपयोगकर्ता द्वारा ही बदली जा सकती हैं."</string>
     <string name="call_settings_with_label" msgid="3401177261468593519">"सेटिंग (<xliff:g id="SUBSCRIPTIONLABEL">%s</xliff:g>)"</string>
-    <string name="error_updating_title" msgid="7970259216988931777">"कॉल सेटिंग त्रुटि"</string>
+    <string name="error_updating_title" msgid="7970259216988931777">"कॉल सेटिंग गड़बड़ी"</string>
     <string name="reading_settings" msgid="1920291699287055284">"सेटिंग पढ़ रहा है..."</string>
     <string name="updating_settings" msgid="8171225533884883252">"सेटिंग के लिए नई जानकारी मिल रही है..."</string>
     <string name="reverting_settings" msgid="4752151682666912828">"सेटिंग वापस ला रहा है..."</string>
     <string name="response_error" msgid="6674110501330139405">"नेटवर्क से अनपेक्षित प्रतिसाद."</string>
-    <string name="exception_error" msgid="7027667130619518211">"नेटवर्क या सिम कार्ड त्रुटि."</string>
+    <string name="exception_error" msgid="7027667130619518211">"नेटवर्क या सिम कार्ड गड़बड़ी."</string>
     <string name="stk_cc_ss_to_dial_error" msgid="2816779198916570502">"SS अनुरोध को DIAL अनुरोध में बदल दिया गया है."</string>
     <string name="stk_cc_ss_to_ussd_error" msgid="7490626178582654236">"SS अनुरोध को USSD अनुरोध में बदल दिया गया है."</string>
     <string name="stk_cc_ss_to_ss_error" msgid="5057846756489053759">"SS अनुरोध को नए SS अनुरोध में बदल दिया गया है."</string>
@@ -162,7 +162,7 @@
     <string name="load_networks_progress" msgid="5230707536168902952">"खोज रहा है..."</string>
     <string name="empty_networks_list" msgid="4249426905018815316">"कोई नेटवर्क नहीं मिला."</string>
     <string name="search_networks" msgid="1601136049300882441">"नेटवर्क खोजें"</string>
-    <string name="network_query_error" msgid="6828516148953325006">"नेटवर्क खोज के दौरान त्रुटि."</string>
+    <string name="network_query_error" msgid="6828516148953325006">"नेटवर्क खोज के दौरान गड़बड़ी."</string>
     <string name="register_on_network" msgid="9055203954040805084">"<xliff:g id="NETWORK">%s</xliff:g> पर पंजीकरण कर रहा है…"</string>
     <string name="not_allowed" msgid="5613353860205691579">"आपका सिम कार्ड इस नेटवर्क पर कनेक्शन की अनुमति नहीं देता है."</string>
     <string name="connect_later" msgid="2308119155752343975">"अभी इस नेटवर्क से कनेक्ट नहीं कर सकते. बाद में पुन: प्रयास करें."</string>
@@ -423,7 +423,7 @@
     <string name="puk2_blocked" msgid="3150263853077280049">"PUK2 स्थायी रूप से अवरोधित है."</string>
     <string name="pin2_attempts" msgid="720736232885011507">\n"आपके पास <xliff:g id="NUMBER">%d</xliff:g> प्रयास शेष हैं."</string>
     <string name="pin2_unblocked" msgid="7791600368153469078">"PIN2 अब अवरोधित नहीं है"</string>
-    <string name="pin2_error_exception" msgid="1088689322248996699">"नेटवर्क या SIM कार्ड त्रुटि"</string>
+    <string name="pin2_error_exception" msgid="1088689322248996699">"नेटवर्क या SIM कार्ड गड़बड़ी"</string>
     <string name="doneButton" msgid="2859593360997984240">"पूर्ण"</string>
     <string name="voicemail_settings_number_label" msgid="8524164258691887790">"ध्‍वनिमेल नबंर"</string>
     <string name="card_title_dialing" msgid="5769417478498348054">"डायल हो रहा है"</string>
@@ -499,7 +499,7 @@
     <item msgid="2883365539347850535">"लंबा"</item>
   </string-array>
     <string name="network_info_message" msgid="7738596060242881930">"नेटवर्क संदेश"</string>
-    <string name="network_error_message" msgid="3394780436230411413">"त्रुटि संदेश"</string>
+    <string name="network_error_message" msgid="3394780436230411413">"गड़बड़ी संदेश"</string>
     <string name="ota_title_activate" msgid="8616918561356194398">"अपना फ़ोन सक्रिय करें"</string>
     <string name="ota_touch_activate" msgid="6553212803262586244">"आपकी फ़ोन सेवा को सक्रिय करने के लिए एक विशेष कॉल करने की आवश्यकता है. \n\n\"सक्रिय करें\" दबाने के बाद, अपने फ़ोन को सक्रिय करने के लिए दिए जाने वाले निर्देश सुनें."</string>
     <string name="ota_hfa_activation_title" msgid="2234246934160473981">"सक्रिय हो रहा है..."</string>
@@ -570,7 +570,7 @@
     <string name="status_hint_label_incoming_wifi_call" msgid="5932176406432044638">"इससे वाई-फ़ाई कॉल"</string>
     <string name="status_hint_label_wifi_call" msgid="8900805254974653903">"वाई-फ़ाई कॉल"</string>
     <string name="emergency_action_launch_hint" msgid="4906759256275562674">"खोलने के लिए पुन: टैप करें"</string>
-    <string name="message_decode_error" msgid="3456481534066924855">"संदेश डीकोड करते समय कोई त्रुटि हुई थी."</string>
+    <string name="message_decode_error" msgid="3456481534066924855">"संदेश डीकोड करते समय कोई गड़बड़ी हुई थी."</string>
     <string name="callFailed_cdma_activation" msgid="2307989779233262164">"सिम कार्ड द्वारा आपकी सेवा को सक्रिय किया गया है और आपके फ़ोन की रोमिंग क्षमताओं को अपडेट किया गया है."</string>
     <string name="callFailed_cdma_call_limit" msgid="1556916577171457086">"बहुत अधिक कॉल सक्रिय हैं. नया कॉल करने से पहले कृपया मौजूदा कॉल समाप्त करें या उन्हें मिला दें."</string>
     <string name="callFailed_imei_not_accepted" msgid="132192626901238542">"कनेक्ट नहीं हो पा रहा है, कृपया कोई मान्य SIM कार्ड डालें."</string>
diff --git a/res/values-ja/strings.xml b/res/values-ja/strings.xml
index c884bae..752e8b0 100644
--- a/res/values-ja/strings.xml
+++ b/res/values-ja/strings.xml
@@ -77,7 +77,7 @@
     <string name="voicemail_settings_with_label" msgid="152724978380748296">"ボイスメール(<xliff:g id="SUBSCRIPTIONLABEL">%s</xliff:g>)"</string>
     <string name="voicemail_abbreviated" msgid="2215592488517217448">"VM:"</string>
     <string name="networks" msgid="8873030692174541976">"通信事業者"</string>
-    <string name="cell_broadcast_settings" msgid="8740238216690502563">"緊急警報"</string>
+    <string name="cell_broadcast_settings" msgid="8740238216690502563">"緊急速報メール"</string>
     <string name="call_settings" msgid="6112441768261754562">"通話設定"</string>
     <string name="additional_gsm_call_settings" msgid="1391795981938800617">"その他の設定"</string>
     <string name="additional_gsm_call_settings_with_label" msgid="1385241520708457376">"その他の設定(<xliff:g id="SUBSCRIPTIONLABEL">%s</xliff:g>)"</string>
@@ -232,11 +232,11 @@
     <string name="throttle_time_frame_subtext" msgid="7732763021560399960">"サイクルの٪<xliff:g id="USED_0">%1$d</xliff:g>を経過\n次の期間は<xliff:g id="USED_1">%2$d</xliff:g>日で始まります(<xliff:g id="USED_2">%3$s</xliff:g>)"</string>
     <string name="throttle_rate_subtext" msgid="2149102656120726855">"データ利用制限を超えると、転送速度が<xliff:g id="USED">%1$d</xliff:g>Kb/秒まで低下します"</string>
     <string name="throttle_help_subtext" msgid="3633091498168446044">"携帯通信会社のモバイルネットワークデータ利用ポリシーの詳細"</string>
-    <string name="cell_broadcast_sms" msgid="5584192824053625842">"緊急警報SMS"</string>
-    <string name="enable_disable_cell_bc_sms" msgid="4851147873691392255">"緊急警報SMS"</string>
-    <string name="cell_bc_sms_enable" msgid="6441688565738921084">"緊急警報SMSは有効になっています"</string>
-    <string name="cell_bc_sms_disable" msgid="3398365088309408749">"緊急警報SMSは無効になっています"</string>
-    <string name="cb_sms_settings" msgid="651715019785107312">"緊急警報SMS設定"</string>
+    <string name="cell_broadcast_sms" msgid="5584192824053625842">"緊急速報メール SMS"</string>
+    <string name="enable_disable_cell_bc_sms" msgid="4851147873691392255">"緊急速報メール SMS"</string>
+    <string name="cell_bc_sms_enable" msgid="6441688565738921084">"緊急速報メール SMS は有効になっています"</string>
+    <string name="cell_bc_sms_disable" msgid="3398365088309408749">"緊急速報メール SMS は無効になっています"</string>
+    <string name="cb_sms_settings" msgid="651715019785107312">"緊急速報メール SMS 設定"</string>
     <string name="enable_disable_emergency_broadcast" msgid="2157014609041245335">"緊急ブロードキャスト"</string>
     <string name="emergency_broadcast_enable" msgid="2645980025414010211">"緊急ブロードキャストは有効になっています"</string>
     <string name="emergency_broadcast_disable" msgid="3665199821267569426">"緊急ブロードキャストは無効になっています"</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 57e417f..a49ceba 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -253,7 +253,7 @@
     <!-- Call forwarding settings screen, setting summary text when forwarding to a specific number when unreachable-->
     <string name="sum_cfnrc_enabled">Forwarding to <xliff:g id="phonenumber" example="555-1212">{0}</xliff:g></string>
     <!-- Call forwarding settings screen, setting summary text when Forward when unreachable is disabled -->
-    <string name="sum_cfnrc_disabled">Disabled</string>
+    <string name="sum_cfnrc_disabled">Off</string>
     <!-- Error message displayed after failing to disable forwarding calls when the phone is unreachable -->
     <string name="disable_cfnrc_forbidden">Your carrier doesn\'t support disabling call forwarding when your phone is unreachable.</string>
 
diff --git a/res/xml/network_setting.xml b/res/xml/network_setting_fragment.xml
similarity index 100%
rename from res/xml/network_setting.xml
rename to res/xml/network_setting_fragment.xml
diff --git a/src/com/android/phone/CdmaOptions.java b/src/com/android/phone/CdmaOptions.java
index a02d3df..a760cda 100644
--- a/src/com/android/phone/CdmaOptions.java
+++ b/src/com/android/phone/CdmaOptions.java
@@ -16,18 +16,14 @@
 
 package com.android.phone;
 
-import android.content.Context;
 import android.content.Intent;
-import android.content.res.Resources;
-import android.net.Uri;
 import android.os.PersistableBundle;
 import android.os.SystemProperties;
 import android.preference.Preference;
-import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
 import android.preference.PreferenceScreen;
 import android.provider.Settings;
 import android.telephony.CarrierConfigManager;
-import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 
 import com.android.internal.telephony.Phone;
@@ -48,19 +44,19 @@
     private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
     private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key_cdma";
 
-    private PreferenceActivity mPrefActivity;
+    private PreferenceFragment mPrefFragment;
     private PreferenceScreen mPrefScreen;
     private Phone mPhone;
 
-    public CdmaOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen, Phone phone) {
-        mPrefActivity = prefActivity;
+    public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) {
+        mPrefFragment = prefFragment;
         mPrefScreen = prefScreen;
         mPhone = phone;
         create();
     }
 
     protected void create() {
-        mPrefActivity.addPreferencesFromResource(R.xml.cdma_options);
+        mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
 
         mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
         boolean removedAPNExpand = false;
@@ -84,7 +80,7 @@
                             // This will setup the Home and Search affordance
                             intent.putExtra(":settings:show_fragment_as_subsetting", true);
                             intent.putExtra("sub_id", mPhone.getSubId());
-                            mPrefActivity.startActivity(intent);
+                            mPrefFragment.startActivity(intent);
                             return true;
                         }
             });
diff --git a/src/com/android/phone/GsmUmtsOptions.java b/src/com/android/phone/GsmUmtsOptions.java
index 2e9d88a..70ba4af 100644
--- a/src/com/android/phone/GsmUmtsOptions.java
+++ b/src/com/android/phone/GsmUmtsOptions.java
@@ -16,12 +16,11 @@
 
 package com.android.phone;
 
-import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
 import android.os.PersistableBundle;
 import android.preference.Preference;
-import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
 import android.preference.PreferenceScreen;
 import android.provider.Settings;
 import android.telephony.CarrierConfigManager;
@@ -43,20 +42,20 @@
     private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key";
     private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
     public static final String EXTRA_SUB_ID = "sub_id";
-    private PreferenceActivity mPrefActivity;
+    private PreferenceFragment mPrefFragment;
     private PreferenceScreen mPrefScreen;
     private int mSubId;
 
-    public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen,
+    public GsmUmtsOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen,
             final int subId) {
-        mPrefActivity = prefActivity;
+        mPrefFragment = prefFragment;
         mPrefScreen = prefScreen;
         mSubId = subId;
         create();
     }
 
     protected void create() {
-        mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options);
+        mPrefFragment.addPreferencesFromResource(R.xml.gsm_umts_options);
         mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
         boolean removedAPNExpand = false;
         mButtonOperatorSelectionExpand =
@@ -67,7 +66,7 @@
             mButtonOperatorSelectionExpand.setEnabled(false);
         } else {
             log("Not a CDMA phone");
-            Resources res = mPrefActivity.getResources();
+            Resources res = mPrefFragment.getResources();
             PersistableBundle carrierConfig =
                     PhoneGlobals.getInstance().getCarrierConfigForSubId(mSubId);
 
@@ -120,7 +119,7 @@
                             // This will setup the Home and Search affordance
                             intent.putExtra(":settings:show_fragment_as_subsetting", true);
                             intent.putExtra(EXTRA_SUB_ID, mSubId);
-                            mPrefActivity.startActivity(intent);
+                            mPrefFragment.startActivity(intent);
                             return true;
                         }
             });
@@ -134,7 +133,7 @@
                             intent.setComponent(new ComponentName("com.android.phone",
                                     "com.android.phone.NetworkSetting"));
                             intent.putExtra(EXTRA_SUB_ID, mSubId);
-                            mPrefActivity.startActivity(intent);
+                            mPrefFragment.startActivity(intent);
                             return true;
                         }
             });
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index 6593e3d..b8c2fb3 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -16,26 +16,16 @@
 
 package com.android.phone;
 
-import android.app.DialogFragment;
-import com.android.ims.ImsManager;
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.PhoneFactory;
-import com.android.internal.telephony.TelephonyIntents;
-import com.android.internal.telephony.TelephonyProperties;
-import com.android.phone.RoamingDialogFragment.RoamingDialogListener;
-import com.android.settingslib.RestrictedLockUtils;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
 import android.app.ActionBar;
+import android.app.DialogFragment;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.Activity;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.os.AsyncResult;
 import android.os.Bundle;
@@ -47,7 +37,7 @@
 import android.os.UserManager;
 import android.preference.ListPreference;
 import android.preference.Preference;
-import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
 import android.preference.PreferenceScreen;
 import android.preference.SwitchPreference;
 import android.telephony.CarrierConfigManager;
@@ -59,1285 +49,1338 @@
 import android.util.Log;
 import android.view.MenuItem;
 import android.view.View;
-import android.widget.TabHost.OnTabChangeListener;
-import android.widget.TabHost.TabContentFactory;
-import android.widget.TabHost.TabSpec;
 import android.widget.TabHost;
 
+import com.android.ims.ImsManager;
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
+import com.android.internal.telephony.PhoneFactory;
+import com.android.internal.telephony.TelephonyIntents;
+import com.android.internal.telephony.TelephonyProperties;
+import com.android.settingslib.RestrictedLockUtils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 /**
- * "Mobile network settings" screen.  This preference screen lets you
+ * "Mobile network settings" screen.  This screen lets you
  * enable/disable mobile data, and control data roaming and other
  * network-specific mobile data features.  It's used on non-voice-capable
  * tablets as well as regular phone devices.
  *
- * Note that this PreferenceActivity is part of the phone app, even though
+ * Note that this Activity is part of the phone app, even though
  * you reach it from the "Wireless & Networks" section of the main
  * Settings app.  It's not part of the "Call settings" hierarchy that's
  * available from the Phone app (see CallFeaturesSetting for that.)
  */
-public class MobileNetworkSettings extends PreferenceActivity
-        implements Preference.OnPreferenceChangeListener, RoamingDialogListener {
 
-    // debug data
-    private static final String LOG_TAG = "NetworkSettings";
-    private static final boolean DBG = true;
-    public static final int REQUEST_CODE_EXIT_ECM = 17;
-
-    // Number of active Subscriptions to show tabs
-    private static final int TAB_THRESHOLD = 2;
-
-    // fragment tag for roaming data dialog
-    private static final String ROAMING_TAG = "RoamingDialogFragment";
-
-    //String keys for preference lookup
-    private static final String BUTTON_PREFERED_NETWORK_MODE = "preferred_network_mode_key";
-    private static final String BUTTON_ROAMING_KEY = "button_roaming_key";
-    private static final String BUTTON_CDMA_LTE_DATA_SERVICE_KEY = "cdma_lte_data_service_key";
-    private static final String BUTTON_ENABLED_NETWORKS_KEY = "enabled_networks_key";
-    private static final String BUTTON_4G_LTE_KEY = "enhanced_4g_lte";
-    private static final String BUTTON_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
-    private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
-    private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key";
-    private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
-    private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
-
-    static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE;
-
-    //Information about logical "up" Activity
-    private static final String UP_ACTIVITY_PACKAGE = "com.android.settings";
-    private static final String UP_ACTIVITY_CLASS =
-            "com.android.settings.Settings$WirelessSettingsActivity";
-
-    private SubscriptionManager mSubscriptionManager;
-
-    //UI objects
-    private ListPreference mButtonPreferredNetworkMode;
-    private ListPreference mButtonEnabledNetworks;
-    private RestrictedSwitchPreference mButtonDataRoam;
-    private SwitchPreference mButton4glte;
-    private Preference mLteDataServicePref;
-
-    private static final String iface = "rmnet0"; //TODO: this will go away
-    private List<SubscriptionInfo> mActiveSubInfos;
-
-    private UserManager mUm;
-    private Phone mPhone;
-    private MyHandler mHandler;
-    private boolean mOkClicked;
-
-    // We assume the the value returned by mTabHost.getCurrentTab() == slotId
-    private TabHost mTabHost;
-
-    //GsmUmts options and Cdma options
-    GsmUmtsOptions mGsmUmtsOptions;
-    CdmaOptions mCdmaOptions;
-
-    private Preference mClickedPreference;
-    private boolean mShow4GForLTE;
-    private boolean mIsGlobalCdma;
-    private boolean mUnavailable;
-
-    private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
-        /*
-         * Enable/disable the 'Enhanced 4G LTE Mode' when in/out of a call
-         * and depending on TTY mode and TTY support over VoLTE.
-         * @see android.telephony.PhoneStateListener#onCallStateChanged(int,
-         * java.lang.String)
-         */
-        @Override
-        public void onCallStateChanged(int state, String incomingNumber) {
-            if (DBG) log("PhoneStateListener.onCallStateChanged: state=" + state);
-            boolean enabled = (state == TelephonyManager.CALL_STATE_IDLE) &&
-                    ImsManager.isNonTtyOrTtyOnVolteEnabled(getApplicationContext());
-            Preference pref = getPreferenceScreen().findPreference(BUTTON_4G_LTE_KEY);
-            if (pref != null) pref.setEnabled(enabled && hasActiveSubscriptions());
-        }
-    };
-
-    private final BroadcastReceiver mPhoneChangeReceiver = new PhoneChangeReceiver();
-
-    @Override
-    public void onPositiveButtonClick(DialogFragment dialog) {
-        mPhone.setDataRoamingEnabled(true);
-        mButtonDataRoam.setChecked(true);
-    }
-
-    private class PhoneChangeReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (DBG) log("onReceive:");
-            // When the radio changes (ex: CDMA->GSM), refresh all options.
-            mGsmUmtsOptions = null;
-            mCdmaOptions = null;
-            updateBody();
-        }
-    }
-
-    /**
-     * Invoked on each preference click in this hierarchy, overrides
-     * PreferenceActivity's implementation.  Used to make sure we track the
-     * preference click events.
-     */
-    @Override
-    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
-        /** TODO: Refactor and get rid of the if's using subclasses */
-        final int phoneSubId = mPhone.getSubId();
-        if (preference.getKey().equals(BUTTON_4G_LTE_KEY)) {
-            return true;
-        } else if (mGsmUmtsOptions != null &&
-                mGsmUmtsOptions.preferenceTreeClick(preference) == true) {
-            return true;
-        } else if (mCdmaOptions != null &&
-                   mCdmaOptions.preferenceTreeClick(preference) == true) {
-            if (Boolean.parseBoolean(
-                    SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
-
-                mClickedPreference = preference;
-
-                // In ECM mode launch ECM app dialog
-                startActivityForResult(
-                    new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
-                    REQUEST_CODE_EXIT_ECM);
-            }
-            return true;
-        } else if (preference == mButtonPreferredNetworkMode) {
-            //displays the value taken from the Settings.System
-            int settingsNetworkMode = android.provider.Settings.Global.getInt(mPhone.getContext().
-                    getContentResolver(),
-                    android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                    preferredNetworkMode);
-            mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
-            return true;
-        } else if (preference == mLteDataServicePref) {
-            String tmpl = android.provider.Settings.Global.getString(getContentResolver(),
-                        android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL);
-            if (!TextUtils.isEmpty(tmpl)) {
-                TelephonyManager tm = (TelephonyManager) getSystemService(
-                        Context.TELEPHONY_SERVICE);
-                String imsi = tm.getSubscriberId();
-                if (imsi == null) {
-                    imsi = "";
-                }
-                final String url = TextUtils.isEmpty(tmpl) ? null
-                        : TextUtils.expandTemplate(tmpl, imsi).toString();
-                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
-                startActivity(intent);
-            } else {
-                android.util.Log.e(LOG_TAG, "Missing SETUP_PREPAID_DATA_SERVICE_URL");
-            }
-            return true;
-        }  else if (preference == mButtonEnabledNetworks) {
-            int settingsNetworkMode = android.provider.Settings.Global.getInt(mPhone.getContext().
-                            getContentResolver(),
-                    android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                    preferredNetworkMode);
-            mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode));
-            return true;
-        } else if (preference == mButtonDataRoam) {
-            // Do not disable the preference screen if the user clicks Data roaming.
-            return true;
-        } else {
-            // if the button is anything but the simple toggle preference,
-            // we'll need to disable all preferences to reject all click
-            // events until the sub-activity's UI comes up.
-            preferenceScreen.setEnabled(false);
-            // Let the intents be launched by the Preference manager
-            return false;
-        }
-    }
-
-    private final SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangeListener
-            = new SubscriptionManager.OnSubscriptionsChangedListener() {
-        @Override
-        public void onSubscriptionsChanged() {
-            if (DBG) log("onSubscriptionsChanged:");
-            initializeSubscriptions();
-        }
-    };
-
-    private void initializeSubscriptions() {
-        if (isDestroyed()) { // Process preferences in activity only if its not destroyed
-            return;
-        }
-        int currentTab = 0;
-        if (DBG) log("initializeSubscriptions:+");
-
-        // Before updating the the active subscription list check
-        // if tab updating is needed as the list is changing.
-        List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList();
-        TabState state = isUpdateTabsNeeded(sil);
-
-        // Update to the active subscription list
-        mActiveSubInfos.clear();
-        if (sil != null) {
-            mActiveSubInfos.addAll(sil);
-            // If there is only 1 sim then currenTab should represent slot no. of the sim.
-            if (sil.size() == 1) {
-                currentTab = sil.get(0).getSimSlotIndex();
-            }
-        }
-
-        switch (state) {
-            case UPDATE: {
-                if (DBG) log("initializeSubscriptions: UPDATE");
-                currentTab = mTabHost != null ? mTabHost.getCurrentTab() : 0;
-
-                setContentView(com.android.internal.R.layout.common_tab_settings);
-
-                mTabHost = (TabHost) findViewById(android.R.id.tabhost);
-                mTabHost.setup();
-
-                // Update the tabName. Since the mActiveSubInfos are in slot order
-                // we can iterate though the tabs and subscription info in one loop. But
-                // we need to handle the case where a slot may be empty.
-
-                Iterator<SubscriptionInfo> siIterator = mActiveSubInfos.listIterator();
-                SubscriptionInfo si = siIterator.hasNext() ? siIterator.next() : null;
-                for (int simSlotIndex = 0; simSlotIndex  < mActiveSubInfos.size(); simSlotIndex++) {
-                    String tabName;
-                    if (si != null && si.getSimSlotIndex() == simSlotIndex) {
-                        // Slot is not empty and we match
-                        tabName = String.valueOf(si.getDisplayName());
-                        si = siIterator.hasNext() ? siIterator.next() : null;
-                    } else {
-                        // Slot is empty, set name to unknown
-                        tabName = getResources().getString(R.string.unknown);
-                    }
-                    if (DBG) {
-                        log("initializeSubscriptions: tab=" + simSlotIndex + " name=" + tabName);
-                    }
-
-                    mTabHost.addTab(buildTabSpec(String.valueOf(simSlotIndex), tabName));
-                }
-
-                mTabHost.setOnTabChangedListener(mTabListener);
-                mTabHost.setCurrentTab(currentTab);
-                break;
-            }
-            case NO_TABS: {
-                if (DBG) log("initializeSubscriptions: NO_TABS");
-
-                if (mTabHost != null) {
-                    mTabHost.clearAllTabs();
-                    mTabHost = null;
-                }
-                setContentView(com.android.internal.R.layout.common_tab_settings);
-                break;
-            }
-            case DO_NOTHING: {
-                if (DBG) log("initializeSubscriptions: DO_NOTHING");
-                if (mTabHost != null) {
-                    currentTab = mTabHost.getCurrentTab();
-                }
-                break;
-            }
-        }
-        updatePhone(currentTab);
-        updateBody();
-        if (DBG) log("initializeSubscriptions:-");
-    }
+public class MobileNetworkSettings extends Activity  {
 
     private enum TabState {
         NO_TABS, UPDATE, DO_NOTHING
     }
-    private TabState isUpdateTabsNeeded(List<SubscriptionInfo> newSil) {
-        TabState state = TabState.DO_NOTHING;
-        if (newSil == null) {
-            if (mActiveSubInfos.size() >= TAB_THRESHOLD) {
-                if (DBG) log("isUpdateTabsNeeded: NO_TABS, size unknown and was tabbed");
-                state = TabState.NO_TABS;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.network_setting);
+
+        FragmentManager fragmentManager = getFragmentManager();
+        Fragment fragment = fragmentManager.findFragmentById(R.id.network_setting_content);
+        if (fragment == null) {
+            fragmentManager.beginTransaction()
+                    .add(R.id.network_setting_content, new MobileNetworkFragment())
+                    .commit();
+        }
+    }
+
+    public static class MobileNetworkFragment extends PreferenceFragment implements
+            Preference.OnPreferenceChangeListener, RoamingDialogFragment.RoamingDialogListener {
+
+        // debug data
+        private static final String LOG_TAG = "NetworkSettings";
+        private static final boolean DBG = true;
+        public static final int REQUEST_CODE_EXIT_ECM = 17;
+
+        // Number of active Subscriptions to show tabs
+        private static final int TAB_THRESHOLD = 2;
+
+        // fragment tag for roaming data dialog
+        private static final String ROAMING_TAG = "RoamingDialogFragment";
+
+        //String keys for preference lookup
+        private static final String BUTTON_PREFERED_NETWORK_MODE = "preferred_network_mode_key";
+        private static final String BUTTON_ROAMING_KEY = "button_roaming_key";
+        private static final String BUTTON_CDMA_LTE_DATA_SERVICE_KEY = "cdma_lte_data_service_key";
+        private static final String BUTTON_ENABLED_NETWORKS_KEY = "enabled_networks_key";
+        private static final String BUTTON_4G_LTE_KEY = "enhanced_4g_lte";
+        private static final String BUTTON_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
+        private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
+        private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key";
+        private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
+        private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
+
+        private final BroadcastReceiver mPhoneChangeReceiver = new PhoneChangeReceiver();
+
+        static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE;
+
+        //Information about logical "up" Activity
+        private static final String UP_ACTIVITY_PACKAGE = "com.android.settings";
+        private static final String UP_ACTIVITY_CLASS =
+                "com.android.settings.Settings$WirelessSettingsActivity";
+
+        private SubscriptionManager mSubscriptionManager;
+
+        //UI objects
+        private ListPreference mButtonPreferredNetworkMode;
+        private ListPreference mButtonEnabledNetworks;
+        private RestrictedSwitchPreference mButtonDataRoam;
+        private SwitchPreference mButton4glte;
+        private Preference mLteDataServicePref;
+
+        private static final String iface = "rmnet0"; //TODO: this will go away
+        private List<SubscriptionInfo> mActiveSubInfos;
+
+        private UserManager mUm;
+        private Phone mPhone;
+        private MyHandler mHandler;
+        private boolean mOkClicked;
+
+        // We assume the the value returned by mTabHost.getCurrentTab() == slotId
+        private TabHost mTabHost;
+
+        //GsmUmts options and Cdma options
+        GsmUmtsOptions mGsmUmtsOptions;
+        CdmaOptions mCdmaOptions;
+
+        private Preference mClickedPreference;
+        private boolean mShow4GForLTE;
+        private boolean mIsGlobalCdma;
+        private boolean mUnavailable;
+
+        private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
+            /*
+             * Enable/disable the 'Enhanced 4G LTE Mode' when in/out of a call
+             * and depending on TTY mode and TTY support over VoLTE.
+             * @see android.telephony.PhoneStateListener#onCallStateChanged(int,
+             * java.lang.String)
+             */
+            @Override
+            public void onCallStateChanged(int state, String incomingNumber) {
+                if (DBG) log("PhoneStateListener.onCallStateChanged: state=" + state);
+                boolean enabled = (state == TelephonyManager.CALL_STATE_IDLE) &&
+                        ImsManager.isNonTtyOrTtyOnVolteEnabled
+                                (getActivity().getApplicationContext());
+                Preference pref = getPreferenceScreen().findPreference(BUTTON_4G_LTE_KEY);
+                if (pref != null) pref.setEnabled(enabled && hasActiveSubscriptions());
+
             }
-        } else if (newSil.size() < TAB_THRESHOLD && mActiveSubInfos.size() >= TAB_THRESHOLD) {
-            if (DBG) log("isUpdateTabsNeeded: NO_TABS, size went to small");
-            state = TabState.NO_TABS;
-        } else if (newSil.size() >= TAB_THRESHOLD && mActiveSubInfos.size() < TAB_THRESHOLD) {
-            if (DBG) log("isUpdateTabsNeeded: UPDATE, size changed");
-            state = TabState.UPDATE;
-        } else if (newSil.size() >= TAB_THRESHOLD) {
-            Iterator<SubscriptionInfo> siIterator = mActiveSubInfos.iterator();
-            for(SubscriptionInfo newSi : newSil) {
-                SubscriptionInfo curSi = siIterator.next();
-                if (!newSi.getDisplayName().equals(curSi.getDisplayName())) {
-                    if (DBG) log("isUpdateTabsNeeded: UPDATE, new name=" + newSi.getDisplayName());
-                    state = TabState.UPDATE;
+        };
+
+        @Override
+        public void onPositiveButtonClick(DialogFragment dialog) {
+            mPhone.setDataRoamingEnabled(true);
+            mButtonDataRoam.setChecked(true);
+        }
+
+        /**
+         * Invoked on each preference click in this hierarchy, overrides
+         * PreferenceActivity's implementation.  Used to make sure we track the
+         * preference click events.
+         */
+        @Override
+        public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
+                                             Preference preference) {
+            /** TODO: Refactor and get rid of the if's using subclasses */
+            final int phoneSubId = mPhone.getSubId();
+            if (preference.getKey().equals(BUTTON_4G_LTE_KEY)) {
+                return true;
+            } else if (mGsmUmtsOptions != null &&
+                    mGsmUmtsOptions.preferenceTreeClick(preference) == true) {
+                return true;
+            } else if (mCdmaOptions != null &&
+                    mCdmaOptions.preferenceTreeClick(preference) == true) {
+                if (Boolean.parseBoolean(
+                        SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
+
+                    mClickedPreference = preference;
+
+                    // In ECM mode launch ECM app dialog
+                    startActivityForResult(
+                            new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
+                            REQUEST_CODE_EXIT_ECM);
+                }
+                return true;
+            } else if (preference == mButtonPreferredNetworkMode) {
+                //displays the value taken from the Settings.System
+                int settingsNetworkMode = android.provider.Settings.Global.getInt(
+                        mPhone.getContext().getContentResolver(),
+                        android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
+                        preferredNetworkMode);
+                mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
+                return true;
+            } else if (preference == mLteDataServicePref) {
+                String tmpl = android.provider.Settings.Global.getString(
+                        getActivity().getContentResolver(),
+                        android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL);
+                if (!TextUtils.isEmpty(tmpl)) {
+                    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(
+                            Context.TELEPHONY_SERVICE);
+                    String imsi = tm.getSubscriberId();
+                    if (imsi == null) {
+                        imsi = "";
+                    }
+                    final String url = TextUtils.isEmpty(tmpl) ? null
+                            : TextUtils.expandTemplate(tmpl, imsi).toString();
+                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+                    startActivity(intent);
+                } else {
+                    android.util.Log.e(LOG_TAG, "Missing SETUP_PREPAID_DATA_SERVICE_URL");
+                }
+                return true;
+            }  else if (preference == mButtonEnabledNetworks) {
+                int settingsNetworkMode = android.provider.Settings.Global.getInt(
+                        mPhone.getContext().getContentResolver(),
+                        android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
+                        preferredNetworkMode);
+                mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode));
+                return true;
+            } else if (preference == mButtonDataRoam) {
+                // Do not disable the preference screen if the user clicks Data roaming.
+                return true;
+            } else {
+                // if the button is anything but the simple toggle preference,
+                // we'll need to disable all preferences to reject all click
+                // events until the sub-activity's UI comes up.
+                preferenceScreen.setEnabled(false);
+                // Let the intents be launched by the Preference manager
+                return false;
+            }
+        }
+
+        private final SubscriptionManager.OnSubscriptionsChangedListener
+                mOnSubscriptionsChangeListener
+                = new SubscriptionManager.OnSubscriptionsChangedListener() {
+            @Override
+            public void onSubscriptionsChanged() {
+                if (DBG) log("onSubscriptionsChanged:");
+                initializeSubscriptions();
+            }
+        };
+
+        private void initializeSubscriptions() {
+            if (getActivity().isDestroyed()) {
+                // Process preferences in activity only if its not destroyed
+                return;
+            }
+            int currentTab = 0;
+            if (DBG) log("initializeSubscriptions:+");
+
+            // Before updating the the active subscription list check
+            // if tab updating is needed as the list is changing.
+            List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList();
+            MobileNetworkSettings.TabState state = isUpdateTabsNeeded(sil);
+
+            // Update to the active subscription list
+            mActiveSubInfos.clear();
+            if (sil != null) {
+                mActiveSubInfos.addAll(sil);
+                // If there is only 1 sim then currenTab should represent slot no. of the sim.
+                if (sil.size() == 1) {
+                    currentTab = sil.get(0).getSimSlotIndex();
+                }
+            }
+
+            switch (state) {
+                case UPDATE: {
+                    if (DBG) log("initializeSubscriptions: UPDATE");
+                    currentTab = mTabHost != null ? mTabHost.getCurrentTab() : 0;
+
+                    getActivity().setContentView(com.android.internal.R.layout.common_tab_settings);
+
+                    mTabHost = (TabHost) getActivity().findViewById(android.R.id.tabhost);
+                    mTabHost.setup();
+
+                    // Update the tabName. Since the mActiveSubInfos are in slot order
+                    // we can iterate though the tabs and subscription info in one loop. But
+                    // we need to handle the case where a slot may be empty.
+
+                    Iterator<SubscriptionInfo> siIterator = mActiveSubInfos.listIterator();
+                    SubscriptionInfo si = siIterator.hasNext() ? siIterator.next() : null;
+                    for (int simSlotIndex = 0; simSlotIndex  < mActiveSubInfos.size();
+                         simSlotIndex++) {
+                        String tabName;
+                        if (si != null && si.getSimSlotIndex() == simSlotIndex) {
+                            // Slot is not empty and we match
+                            tabName = String.valueOf(si.getDisplayName());
+                            si = siIterator.hasNext() ? siIterator.next() : null;
+                        } else {
+                            // Slot is empty, set name to unknown
+                            tabName = getResources().getString(R.string.unknown);
+                        }
+                        if (DBG) {
+                            log("initializeSubscriptions:tab=" + simSlotIndex + " name=" + tabName);
+                        }
+
+                        mTabHost.addTab(buildTabSpec(String.valueOf(simSlotIndex), tabName));
+                    }
+
+                    mTabHost.setOnTabChangedListener(mTabListener);
+                    mTabHost.setCurrentTab(currentTab);
+                    break;
+                }
+                case NO_TABS: {
+                    if (DBG) log("initializeSubscriptions: NO_TABS");
+
+                    if (mTabHost != null) {
+                        mTabHost.clearAllTabs();
+                        mTabHost = null;
+                    }
+                    getActivity().setContentView(com.android.internal.R.layout.common_tab_settings);
+                    break;
+                }
+                case DO_NOTHING: {
+                    if (DBG) log("initializeSubscriptions: DO_NOTHING");
+                    if (mTabHost != null) {
+                        currentTab = mTabHost.getCurrentTab();
+                    }
                     break;
                 }
             }
-        }
-        if (DBG) {
-            log("isUpdateTabsNeeded:- " + state
-                + " newSil.size()=" + ((newSil != null) ? newSil.size() : 0)
-                + " mActiveSubInfos.size()=" + mActiveSubInfos.size());
-        }
-        return state;
-    }
-
-    private OnTabChangeListener mTabListener = new OnTabChangeListener() {
-        @Override
-        public void onTabChanged(String tabId) {
-            if (DBG) log("onTabChanged:");
-            // The User has changed tab; update the body.
-            updatePhone(Integer.parseInt(tabId));
+            updatePhone(currentTab);
             updateBody();
-        }
-    };
-
-    private void updatePhone(int slotId) {
-        final SubscriptionInfo sir = mSubscriptionManager
-                .getActiveSubscriptionInfoForSimSlotIndex(slotId);
-        if (sir != null) {
-            mPhone = PhoneFactory.getPhone(
-                    SubscriptionManager.getPhoneId(sir.getSubscriptionId()));
-        }
-        if (mPhone == null) {
-            // Do the best we can
-            mPhone = PhoneGlobals.getPhone();
-        }
-        if (DBG) log("updatePhone:- slotId=" + slotId + " sir=" + sir);
-    }
-
-    private TabContentFactory mEmptyTabContent = new TabContentFactory() {
-        @Override
-        public View createTabContent(String tag) {
-            return new View(mTabHost.getContext());
-        }
-    };
-
-    private TabSpec buildTabSpec(String tag, String title) {
-        return mTabHost.newTabSpec(tag).setIndicator(title).setContent(
-                mEmptyTabContent);
-    }
-
-    @Override
-    protected void onCreate(Bundle icicle) {
-        if (DBG) log("onCreate:+");
-        super.onCreate(icicle);
-
-        mHandler = new MyHandler();
-        mUm = (UserManager) getSystemService(Context.USER_SERVICE);
-        mSubscriptionManager = SubscriptionManager.from(this);
-
-        if (mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
-            mUnavailable = true;
-            setContentView(R.layout.telephony_disallowed_preference_screen);
-            return;
+            if (DBG) log("initializeSubscriptions:-");
         }
 
-        addPreferencesFromResource(R.xml.network_setting);
-
-        mButton4glte = (SwitchPreference)findPreference(BUTTON_4G_LTE_KEY);
-        mButton4glte.setOnPreferenceChangeListener(this);
-
-        try {
-            Context con = createPackageContext("com.android.systemui", 0);
-            int id = con.getResources().getIdentifier("config_show4GForLTE",
-                    "bool", "com.android.systemui");
-            mShow4GForLTE = con.getResources().getBoolean(id);
-        } catch (NameNotFoundException e) {
-            loge("NameNotFoundException for show4GFotLTE");
-            mShow4GForLTE = false;
-        }
-
-        //get UI object references
-        PreferenceScreen prefSet = getPreferenceScreen();
-
-        mButtonDataRoam = (RestrictedSwitchPreference) prefSet.findPreference(BUTTON_ROAMING_KEY);
-        mButtonPreferredNetworkMode = (ListPreference) prefSet.findPreference(
-                BUTTON_PREFERED_NETWORK_MODE);
-        mButtonEnabledNetworks = (ListPreference) prefSet.findPreference(
-                BUTTON_ENABLED_NETWORKS_KEY);
-        mButtonDataRoam.setOnPreferenceChangeListener(this);
-
-        mLteDataServicePref = prefSet.findPreference(BUTTON_CDMA_LTE_DATA_SERVICE_KEY);
-
-        // Initialize mActiveSubInfo
-        int max = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
-        mActiveSubInfos = new ArrayList<SubscriptionInfo>(max);
-
-        initializeSubscriptions();
-
-        IntentFilter intentFilter = new IntentFilter(
-                TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
-        registerReceiver(mPhoneChangeReceiver, intentFilter);
-        if (DBG) log("onCreate:-");
-    }
-
-    @Override
-    protected void onDestroy() {
-        super.onDestroy();
-        unregisterReceiver(mPhoneChangeReceiver);
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-        if (DBG) log("onResume:+");
-
-        if (mUnavailable) {
-            if (DBG) log("onResume:- ignore mUnavailable == false");
-            return;
-        }
-
-        // upon resumption from the sub-activity, make sure we re-enable the
-        // preferences.
-        getPreferenceScreen().setEnabled(true);
-
-        // Set UI state in onResume because a user could go home, launch some
-        // app to change this setting's backend, and re-launch this settings app
-        // and the UI state would be inconsistent with actual state
-        mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled());
-
-        if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null
-                || getPreferenceScreen().findPreference(BUTTON_ENABLED_NETWORKS_KEY) != null)  {
-            updatePreferredNetworkUIFromDb();
-        }
-
-        if (ImsManager.isVolteEnabledByPlatform(this)
-                && ImsManager.isVolteProvisionedOnDevice(this)) {
-            TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-            tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
-        }
-
-        // NOTE: Buttons will be enabled/disabled in mPhoneStateListener
-        boolean enh4glteMode = ImsManager.isEnhanced4gLteModeSettingEnabledByUser(this)
-                && ImsManager.isNonTtyOrTtyOnVolteEnabled(this);
-        mButton4glte.setChecked(enh4glteMode);
-
-        mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
-
-        if (DBG) log("onResume:-");
-
-    }
-
-    private boolean hasActiveSubscriptions() {
-        return mActiveSubInfos.size() > 0;
-    }
-
-    private void updateBody() {
-        final Context context = getApplicationContext();
-        PreferenceScreen prefSet = getPreferenceScreen();
-        boolean isLteOnCdma = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE;
-        final int phoneSubId = mPhone.getSubId();
-
-        if (DBG) {
-            log("updateBody: isLteOnCdma=" + isLteOnCdma + " phoneSubId=" + phoneSubId);
-        }
-
-        if (prefSet != null) {
-            prefSet.removeAll();
-            prefSet.addPreference(mButtonDataRoam);
-            prefSet.addPreference(mButtonPreferredNetworkMode);
-            prefSet.addPreference(mButtonEnabledNetworks);
-            prefSet.addPreference(mButton4glte);
-        }
-
-        int settingsNetworkMode = android.provider.Settings.Global.getInt(
-                mPhone.getContext().getContentResolver(),
-                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                preferredNetworkMode);
-
-        PersistableBundle carrierConfig =
-                PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
-        mIsGlobalCdma = isLteOnCdma
-                && carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_CDMA_CHOICES_BOOL);
-        if (carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
-            prefSet.removePreference(mButtonPreferredNetworkMode);
-            prefSet.removePreference(mButtonEnabledNetworks);
-            prefSet.removePreference(mLteDataServicePref);
-        } else if (carrierConfig.getBoolean(CarrierConfigManager
-                    .KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL)
-                && !mPhone.getServiceState().getRoaming()) {
-            prefSet.removePreference(mButtonPreferredNetworkMode);
-            prefSet.removePreference(mButtonEnabledNetworks);
-
-            final int phoneType = mPhone.getPhoneType();
-            if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
-                mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
-                // In World mode force a refresh of GSM Options.
-                if (isWorldMode()) {
-                    mGsmUmtsOptions = null;
+        private MobileNetworkSettings.TabState isUpdateTabsNeeded(List<SubscriptionInfo> newSil) {
+            TabState state = MobileNetworkSettings.TabState.DO_NOTHING;
+            if (newSil == null) {
+                if (mActiveSubInfos.size() >= TAB_THRESHOLD) {
+                    if (DBG) log("isUpdateTabsNeeded: NO_TABS, size unknown and was tabbed");
+                    state = MobileNetworkSettings.TabState.NO_TABS;
                 }
-            } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
+            } else if (newSil.size() < TAB_THRESHOLD && mActiveSubInfos.size() >= TAB_THRESHOLD) {
+                if (DBG) log("isUpdateTabsNeeded: NO_TABS, size went to small");
+                state = MobileNetworkSettings.TabState.NO_TABS;
+            } else if (newSil.size() >= TAB_THRESHOLD && mActiveSubInfos.size() < TAB_THRESHOLD) {
+                if (DBG) log("isUpdateTabsNeeded: UPDATE, size changed");
+                state = MobileNetworkSettings.TabState.UPDATE;
+            } else if (newSil.size() >= TAB_THRESHOLD) {
+                Iterator<SubscriptionInfo> siIterator = mActiveSubInfos.iterator();
+                for(SubscriptionInfo newSi : newSil) {
+                    SubscriptionInfo curSi = siIterator.next();
+                    if (!newSi.getDisplayName().equals(curSi.getDisplayName())) {
+                        if (DBG) log("isUpdateTabsNeeded: UPDATE, new name="
+                                + newSi.getDisplayName());
+                        state = MobileNetworkSettings.TabState.UPDATE;
+                        break;
+                    }
+                }
+            }
+            if (DBG) {
+                Log.i(LOG_TAG, "isUpdateTabsNeeded:- " + state
+                        + " newSil.size()=" + ((newSil != null) ? newSil.size() : 0)
+                        + " mActiveSubInfos.size()=" + mActiveSubInfos.size());
+            }
+            return state;
+        }
+
+        private TabHost.OnTabChangeListener mTabListener = new TabHost.OnTabChangeListener() {
+            @Override
+            public void onTabChanged(String tabId) {
+                if (DBG) log("onTabChanged:");
+                // The User has changed tab; update the body.
+                updatePhone(Integer.parseInt(tabId));
+                updateBody();
+            }
+        };
+
+        private void updatePhone(int slotId) {
+            final SubscriptionInfo sir = mSubscriptionManager
+                    .getActiveSubscriptionInfoForSimSlotIndex(slotId);
+            if (sir != null) {
+                mPhone = PhoneFactory.getPhone(
+                        SubscriptionManager.getPhoneId(sir.getSubscriptionId()));
+            }
+            if (mPhone == null) {
+                // Do the best we can
+                mPhone = PhoneGlobals.getPhone();
+            }
+            Log.i(LOG_TAG, "updatePhone:- slotId=" + slotId + " sir=" + sir);
+        }
+
+        private TabHost.TabContentFactory mEmptyTabContent = new TabHost.TabContentFactory() {
+            @Override
+            public View createTabContent(String tag) {
+                return new View(mTabHost.getContext());
+            }
+        };
+
+        private TabHost.TabSpec buildTabSpec(String tag, String title) {
+            return mTabHost.newTabSpec(tag).setIndicator(title).setContent(
+                    mEmptyTabContent);
+        }
+
+        @Override
+        public void onCreate(Bundle icicle) {
+            Log.i(LOG_TAG, "onCreate:+");
+            super.onCreate(icicle);
+            mHandler = new MyHandler();
+            mUm = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
+            mSubscriptionManager = SubscriptionManager.from(getActivity());
+
+            if (mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
+                mUnavailable = true;
+                getActivity().setContentView(R.layout.telephony_disallowed_preference_screen);
+                return;
+            }
+
+            addPreferencesFromResource(R.xml.network_setting_fragment);
+
+            mButton4glte = (SwitchPreference)findPreference(BUTTON_4G_LTE_KEY);
+            mButton4glte.setOnPreferenceChangeListener(this);
+
+            try {
+                Context con = getActivity().createPackageContext("com.android.systemui", 0);
+                int id = con.getResources().getIdentifier("config_show4GForLTE",
+                        "bool", "com.android.systemui");
+                mShow4GForLTE = con.getResources().getBoolean(id);
+            } catch (PackageManager.NameNotFoundException e) {
+                Log.e(LOG_TAG, "NameNotFoundException for show4GFotLTE");
+                mShow4GForLTE = false;
+            }
+
+            //get UI object references
+            PreferenceScreen prefSet = getPreferenceScreen();
+
+            mButtonDataRoam = (RestrictedSwitchPreference) prefSet.findPreference(
+                    BUTTON_ROAMING_KEY);
+            mButtonPreferredNetworkMode = (ListPreference) prefSet.findPreference(
+                    BUTTON_PREFERED_NETWORK_MODE);
+            mButtonEnabledNetworks = (ListPreference) prefSet.findPreference(
+                    BUTTON_ENABLED_NETWORKS_KEY);
+            mButtonDataRoam.setOnPreferenceChangeListener(this);
+
+            mLteDataServicePref = prefSet.findPreference(BUTTON_CDMA_LTE_DATA_SERVICE_KEY);
+
+            // Initialize mActiveSubInfo
+            int max = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
+            mActiveSubInfos = new ArrayList<SubscriptionInfo>(max);
+
+            IntentFilter intentFilter = new IntentFilter(
+                    TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
+            getActivity().registerReceiver(mPhoneChangeReceiver, intentFilter);
+
+            initializeSubscriptions();
+            Log.i(LOG_TAG, "onCreate:-");
+        }
+
+        private class PhoneChangeReceiver extends BroadcastReceiver {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                Log.i(LOG_TAG, "onReceive:");
+                // When the radio changes (ex: CDMA->GSM), refresh all options.
+                mGsmUmtsOptions = null;
+                mCdmaOptions = null;
+                updateBody();
+            }
+        }
+
+        @Override
+        public void onDestroy() {
+            super.onDestroy();
+            getActivity().unregisterReceiver(mPhoneChangeReceiver);
+        }
+
+        @Override
+        public void onResume() {
+            super.onResume();
+            Log.i(LOG_TAG, "onResume:+");
+
+            if (mUnavailable) {
+                Log.i(LOG_TAG, "onResume:- ignore mUnavailable == false");
+                return;
+            }
+
+            // upon resumption from the sub-activity, make sure we re-enable the
+            // preferences.
+            getPreferenceScreen().setEnabled(true);
+
+            // Set UI state in onResume because a user could go home, launch some
+            // app to change this setting's backend, and re-launch this settings app
+            // and the UI state would be inconsistent with actual state
+            mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled());
+
+            if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null
+                    || getPreferenceScreen().findPreference(BUTTON_ENABLED_NETWORKS_KEY) != null)  {
+                updatePreferredNetworkUIFromDb();
+            }
+
+            if (ImsManager.isVolteEnabledByPlatform(getActivity())
+                    && ImsManager.isVolteProvisionedOnDevice(getActivity())) {
+                TelephonyManager tm =
+                        (TelephonyManager) getActivity().getSystemService(
+                                Context.TELEPHONY_SERVICE);
+                tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
+            }
+
+            // NOTE: Buttons will be enabled/disabled in mPhoneStateListener
+            boolean enh4glteMode = ImsManager.isEnhanced4gLteModeSettingEnabledByUser(getActivity())
+                    && ImsManager.isNonTtyOrTtyOnVolteEnabled(getActivity());
+            mButton4glte.setChecked(enh4glteMode);
+
+            mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
+
+            Log.i(LOG_TAG, "onResume:-");
+
+        }
+
+        private boolean hasActiveSubscriptions() {
+            return mActiveSubInfos.size() > 0;
+        }
+
+        private void updateBody() {
+            Context context = getActivity().getApplicationContext();
+            PreferenceScreen prefSet = getPreferenceScreen();
+            boolean isLteOnCdma = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE;
+            final int phoneSubId = mPhone.getSubId();
+
+            if (DBG) {
+                log("updateBody: isLteOnCdma=" + isLteOnCdma + " phoneSubId=" + phoneSubId);
+            }
+
+            if (prefSet != null) {
+                prefSet.removeAll();
+                prefSet.addPreference(mButtonDataRoam);
+                prefSet.addPreference(mButtonPreferredNetworkMode);
+                prefSet.addPreference(mButtonEnabledNetworks);
+                prefSet.addPreference(mButton4glte);
+            }
+
+            int settingsNetworkMode = android.provider.Settings.Global.getInt(
+                    mPhone.getContext().getContentResolver(),
+                    android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
+                    preferredNetworkMode);
+
+            PersistableBundle carrierConfig =
+                    PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
+            mIsGlobalCdma = isLteOnCdma
+                    && carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_CDMA_CHOICES_BOOL);
+            if (carrierConfig.getBoolean(
+                    CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
+                prefSet.removePreference(mButtonPreferredNetworkMode);
+                prefSet.removePreference(mButtonEnabledNetworks);
+                prefSet.removePreference(mLteDataServicePref);
+            } else if (carrierConfig.getBoolean(CarrierConfigManager
+                    .KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL)
+                    && !mPhone.getServiceState().getRoaming()) {
+                prefSet.removePreference(mButtonPreferredNetworkMode);
+                prefSet.removePreference(mButtonEnabledNetworks);
+
+                final int phoneType = mPhone.getPhoneType();
+                if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
+                    mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
+                    // In World mode force a refresh of GSM Options.
+                    if (isWorldMode()) {
+                        mGsmUmtsOptions = null;
+                    }
+                } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
+                    mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, phoneSubId);
+                } else {
+                    throw new IllegalStateException("Unexpected phone type: " + phoneType);
+                }
+                // Since pref is being hidden from user, set network mode to default
+                // in case it is currently something else. That is possible if user
+                // changed the setting while roaming and is now back to home network.
+                settingsNetworkMode = preferredNetworkMode;
+            } else if (carrierConfig.getBoolean(
+                    CarrierConfigManager.KEY_WORLD_PHONE_BOOL) == true) {
+                prefSet.removePreference(mButtonEnabledNetworks);
+                // set the listener for the mButtonPreferredNetworkMode list preference so we can issue
+                // change Preferred Network Mode.
+                mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this);
+
+                mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
                 mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, phoneSubId);
             } else {
-                throw new IllegalStateException("Unexpected phone type: " + phoneType);
-            }
-            // Since pref is being hidden from user, set network mode to default
-            // in case it is currently something else. That is possible if user
-            // changed the setting while roaming and is now back to home network.
-            settingsNetworkMode = preferredNetworkMode;
-        } else if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL) == true) {
-            prefSet.removePreference(mButtonEnabledNetworks);
-            // set the listener for the mButtonPreferredNetworkMode list preference so we can issue
-            // change Preferred Network Mode.
-            mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this);
+                prefSet.removePreference(mButtonPreferredNetworkMode);
+                final int phoneType = mPhone.getPhoneType();
+                if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
+                    int lteForced = android.provider.Settings.Global.getInt(
+                            mPhone.getContext().getContentResolver(),
+                            android.provider.Settings.Global.LTE_SERVICE_FORCED + mPhone.getSubId(),
+                            0);
 
-            mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
-            mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, phoneSubId);
-        } else {
-            prefSet.removePreference(mButtonPreferredNetworkMode);
-            final int phoneType = mPhone.getPhoneType();
-            if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
-                int lteForced = android.provider.Settings.Global.getInt(
-                        mPhone.getContext().getContentResolver(),
-                        android.provider.Settings.Global.LTE_SERVICE_FORCED + mPhone.getSubId(),
-                        0);
+                    if (isLteOnCdma) {
+                        if (lteForced == 0) {
+                            mButtonEnabledNetworks.setEntries(
+                                    R.array.enabled_networks_cdma_choices);
+                            mButtonEnabledNetworks.setEntryValues(
+                                    R.array.enabled_networks_cdma_values);
+                        } else {
+                            switch (settingsNetworkMode) {
+                                case Phone.NT_MODE_CDMA:
+                                case Phone.NT_MODE_CDMA_NO_EVDO:
+                                case Phone.NT_MODE_EVDO_NO_CDMA:
+                                    mButtonEnabledNetworks.setEntries(
+                                            R.array.enabled_networks_cdma_no_lte_choices);
+                                    mButtonEnabledNetworks.setEntryValues(
+                                            R.array.enabled_networks_cdma_no_lte_values);
+                                    break;
+                                case Phone.NT_MODE_GLOBAL:
+                                case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
+                                case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+                                case Phone.NT_MODE_LTE_ONLY:
+                                    mButtonEnabledNetworks.setEntries(
+                                            R.array.enabled_networks_cdma_only_lte_choices);
+                                    mButtonEnabledNetworks.setEntryValues(
+                                            R.array.enabled_networks_cdma_only_lte_values);
+                                    break;
+                                default:
+                                    mButtonEnabledNetworks.setEntries(
+                                            R.array.enabled_networks_cdma_choices);
+                                    mButtonEnabledNetworks.setEntryValues(
+                                            R.array.enabled_networks_cdma_values);
+                                    break;
+                            }
+                        }
+                    }
+                    mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
 
-                if (isLteOnCdma) {
-                    if (lteForced == 0) {
+                    // In World mode force a refresh of GSM Options.
+                    if (isWorldMode()) {
+                        mGsmUmtsOptions = null;
+                    }
+                } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
+                    if (isSupportTdscdma()) {
+                        mButtonEnabledNetworks.setEntries(
+                                R.array.enabled_networks_tdscdma_choices);
+                        mButtonEnabledNetworks.setEntryValues(
+                                R.array.enabled_networks_tdscdma_values);
+                    } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)
+                            && !getResources().getBoolean(R.bool.config_enabled_lte)) {
+                        mButtonEnabledNetworks.setEntries(
+                                R.array.enabled_networks_except_gsm_lte_choices);
+                        mButtonEnabledNetworks.setEntryValues(
+                                R.array.enabled_networks_except_gsm_lte_values);
+                    } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)) {
+                        int select = (mShow4GForLTE == true) ?
+                                R.array.enabled_networks_except_gsm_4g_choices
+                                : R.array.enabled_networks_except_gsm_choices;
+                        mButtonEnabledNetworks.setEntries(select);
+                        mButtonEnabledNetworks.setEntryValues(
+                                R.array.enabled_networks_except_gsm_values);
+                    } else if (!getResources().getBoolean(R.bool.config_enabled_lte)) {
+                        mButtonEnabledNetworks.setEntries(
+                                R.array.enabled_networks_except_lte_choices);
+                        mButtonEnabledNetworks.setEntryValues(
+                                R.array.enabled_networks_except_lte_values);
+                    } else if (mIsGlobalCdma) {
                         mButtonEnabledNetworks.setEntries(
                                 R.array.enabled_networks_cdma_choices);
                         mButtonEnabledNetworks.setEntryValues(
                                 R.array.enabled_networks_cdma_values);
                     } else {
-                        switch (settingsNetworkMode) {
-                            case Phone.NT_MODE_CDMA:
-                            case Phone.NT_MODE_CDMA_NO_EVDO:
-                            case Phone.NT_MODE_EVDO_NO_CDMA:
-                                mButtonEnabledNetworks.setEntries(
-                                        R.array.enabled_networks_cdma_no_lte_choices);
-                                mButtonEnabledNetworks.setEntryValues(
-                                        R.array.enabled_networks_cdma_no_lte_values);
-                                break;
-                            case Phone.NT_MODE_GLOBAL:
-                            case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
-                            case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
-                            case Phone.NT_MODE_LTE_ONLY:
-                                mButtonEnabledNetworks.setEntries(
-                                        R.array.enabled_networks_cdma_only_lte_choices);
-                                mButtonEnabledNetworks.setEntryValues(
-                                        R.array.enabled_networks_cdma_only_lte_values);
-                                break;
-                            default:
-                                mButtonEnabledNetworks.setEntries(
-                                        R.array.enabled_networks_cdma_choices);
-                                mButtonEnabledNetworks.setEntryValues(
-                                        R.array.enabled_networks_cdma_values);
-                                break;
-                        }
+                        int select = (mShow4GForLTE == true) ? R.array.enabled_networks_4g_choices
+                                : R.array.enabled_networks_choices;
+                        mButtonEnabledNetworks.setEntries(select);
+                        mButtonEnabledNetworks.setEntryValues(
+                                R.array.enabled_networks_values);
                     }
-                }
-                mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
-
-                // In World mode force a refresh of GSM Options.
-                if (isWorldMode()) {
-                    mGsmUmtsOptions = null;
-                }
-            } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
-                if (isSupportTdscdma()) {
-                    mButtonEnabledNetworks.setEntries(
-                            R.array.enabled_networks_tdscdma_choices);
-                    mButtonEnabledNetworks.setEntryValues(
-                            R.array.enabled_networks_tdscdma_values);
-                } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)
-                        && !getResources().getBoolean(R.bool.config_enabled_lte)) {
-                    mButtonEnabledNetworks.setEntries(
-                            R.array.enabled_networks_except_gsm_lte_choices);
-                    mButtonEnabledNetworks.setEntryValues(
-                            R.array.enabled_networks_except_gsm_lte_values);
-                } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)) {
-                    int select = (mShow4GForLTE == true) ?
-                            R.array.enabled_networks_except_gsm_4g_choices
-                            : R.array.enabled_networks_except_gsm_choices;
-                    mButtonEnabledNetworks.setEntries(select);
-                    mButtonEnabledNetworks.setEntryValues(
-                            R.array.enabled_networks_except_gsm_values);
-                } else if (!getResources().getBoolean(R.bool.config_enabled_lte)) {
-                    mButtonEnabledNetworks.setEntries(
-                            R.array.enabled_networks_except_lte_choices);
-                    mButtonEnabledNetworks.setEntryValues(
-                            R.array.enabled_networks_except_lte_values);
-                } else if (mIsGlobalCdma) {
-                    mButtonEnabledNetworks.setEntries(
-                            R.array.enabled_networks_cdma_choices);
-                    mButtonEnabledNetworks.setEntryValues(
-                            R.array.enabled_networks_cdma_values);
+                    mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, phoneSubId);
                 } else {
-                    int select = (mShow4GForLTE == true) ? R.array.enabled_networks_4g_choices
-                            : R.array.enabled_networks_choices;
-                    mButtonEnabledNetworks.setEntries(select);
-                    mButtonEnabledNetworks.setEntryValues(
-                            R.array.enabled_networks_values);
+                    throw new IllegalStateException("Unexpected phone type: " + phoneType);
                 }
-                mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, phoneSubId);
+                if (isWorldMode()) {
+                    mButtonEnabledNetworks.setEntries(
+                            R.array.preferred_network_mode_choices_world_mode);
+                    mButtonEnabledNetworks.setEntryValues(
+                            R.array.preferred_network_mode_values_world_mode);
+                }
+                mButtonEnabledNetworks.setOnPreferenceChangeListener(this);
+                if (DBG) log("settingsNetworkMode: " + settingsNetworkMode);
+            }
+
+            final boolean missingDataServiceUrl = TextUtils.isEmpty(
+                    android.provider.Settings.Global.getString(getActivity().getContentResolver(),
+                            android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL));
+            if (!isLteOnCdma || missingDataServiceUrl) {
+                prefSet.removePreference(mLteDataServicePref);
             } else {
-                throw new IllegalStateException("Unexpected phone type: " + phoneType);
+                android.util.Log.d(LOG_TAG, "keep ltePref");
             }
-            if (isWorldMode()) {
-                mButtonEnabledNetworks.setEntries(
-                        R.array.preferred_network_mode_choices_world_mode);
-                mButtonEnabledNetworks.setEntryValues(
-                        R.array.preferred_network_mode_values_world_mode);
+
+            // Enable enhanced 4G LTE mode settings depending on whether exists on platform
+            if (!(ImsManager.isVolteEnabledByPlatform(getActivity())
+                    && ImsManager.isVolteProvisionedOnDevice(getActivity()))) {
+                Preference pref = prefSet.findPreference(BUTTON_4G_LTE_KEY);
+                if (pref != null) {
+                    prefSet.removePreference(pref);
+                }
             }
-            mButtonEnabledNetworks.setOnPreferenceChangeListener(this);
-            if (DBG) log("settingsNetworkMode: " + settingsNetworkMode);
-        }
 
-        final boolean missingDataServiceUrl = TextUtils.isEmpty(
-                android.provider.Settings.Global.getString(getContentResolver(),
-                        android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL));
-        if (!isLteOnCdma || missingDataServiceUrl) {
-            prefSet.removePreference(mLteDataServicePref);
-        } else {
-            android.util.Log.d(LOG_TAG, "keep ltePref");
-        }
-
-        // Enable enhanced 4G LTE mode settings depending on whether exists on platform
-        if (!(ImsManager.isVolteEnabledByPlatform(this)
-                && ImsManager.isVolteProvisionedOnDevice(this))) {
-            Preference pref = prefSet.findPreference(BUTTON_4G_LTE_KEY);
-            if (pref != null) {
-                prefSet.removePreference(pref);
+            ActionBar actionBar = getActivity().getActionBar();
+            if (actionBar != null) {
+                // android.R.id.home will be triggered in onOptionsItemSelected()
+                actionBar.setDisplayHomeAsUpEnabled(true);
             }
-        }
 
-        ActionBar actionBar = getActionBar();
-        if (actionBar != null) {
-            // android.R.id.home will be triggered in onOptionsItemSelected()
-            actionBar.setDisplayHomeAsUpEnabled(true);
-        }
+            // Enable link to CMAS app settings depending on the value in config.xml.
+            final boolean isCellBroadcastAppLinkEnabled = getActivity().getResources().getBoolean(
+                    com.android.internal.R.bool.config_cellBroadcastAppLinks);
+            if (!mUm.isAdminUser() || !isCellBroadcastAppLinkEnabled
+                    || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
+                PreferenceScreen root = getPreferenceScreen();
+                Preference ps = findPreference(BUTTON_CELL_BROADCAST_SETTINGS);
+                if (ps != null) {
+                    root.removePreference(ps);
+                }
+            }
 
-        // Enable link to CMAS app settings depending on the value in config.xml.
-        final boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
-                com.android.internal.R.bool.config_cellBroadcastAppLinks);
-        if (!mUm.isAdminUser() || !isCellBroadcastAppLinkEnabled
-                || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
+            // Get the networkMode from Settings.System and displays it
+            mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled());
+            mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode));
+            mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
+            UpdatePreferredNetworkModeSummary(settingsNetworkMode);
+            UpdateEnabledNetworksValueAndSummary(settingsNetworkMode);
+            // Display preferred network type based on what modem returns b/18676277
+            mPhone.setPreferredNetworkType(settingsNetworkMode, mHandler
+                    .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
+
+            /**
+             * Enable/disable depending upon if there are any active subscriptions.
+             *
+             * I've decided to put this enable/disable code at the bottom as the
+             * code above works even when there are no active subscriptions, thus
+             * putting it afterwards is a smaller change. This can be refined later,
+             * but you do need to remember that this all needs to work when subscriptions
+             * change dynamically such as when hot swapping sims.
+             */
+            boolean hasActiveSubscriptions = hasActiveSubscriptions();
+            TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(
+                    Context.TELEPHONY_SERVICE);
+            boolean canChange4glte = (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) &&
+                    ImsManager.isNonTtyOrTtyOnVolteEnabled(getActivity().getApplicationContext()) &&
+                    carrierConfig.getBoolean(
+                            CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
+            boolean useVariant4glteTitle = carrierConfig.getBoolean(
+                    CarrierConfigManager.KEY_ENHANCED_4G_LTE_TITLE_VARIANT_BOOL);
+            int enhanced4glteModeTitleId = useVariant4glteTitle ?
+                    R.string.enhanced_4g_lte_mode_title_variant :
+                    R.string.enhanced_4g_lte_mode_title;
+            mButtonDataRoam.setDisabledByAdmin(false);
+            mButtonDataRoam.setEnabled(hasActiveSubscriptions);
+            if (mButtonDataRoam.isEnabled()) {
+                if (RestrictedLockUtils.hasBaseUserRestriction(context,
+                        UserManager.DISALLOW_DATA_ROAMING, UserHandle.myUserId())) {
+                    mButtonDataRoam.setEnabled(false);
+                } else {
+                    mButtonDataRoam.checkRestrictionAndSetDisabled(
+                            UserManager.DISALLOW_DATA_ROAMING);
+                }
+            }
+            mButtonPreferredNetworkMode.setEnabled(hasActiveSubscriptions);
+            mButtonEnabledNetworks.setEnabled(hasActiveSubscriptions);
+            mButton4glte.setTitle(enhanced4glteModeTitleId);
+            mButton4glte.setEnabled(hasActiveSubscriptions && canChange4glte);
+            mLteDataServicePref.setEnabled(hasActiveSubscriptions);
+            Preference ps;
             PreferenceScreen root = getPreferenceScreen();
-            Preference ps = findPreference(BUTTON_CELL_BROADCAST_SETTINGS);
+            ps = findPreference(BUTTON_CELL_BROADCAST_SETTINGS);
             if (ps != null) {
-                root.removePreference(ps);
+                ps.setEnabled(hasActiveSubscriptions);
+            }
+            ps = findPreference(BUTTON_APN_EXPAND_KEY);
+            if (ps != null) {
+                ps.setEnabled(hasActiveSubscriptions);
+            }
+            ps = findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
+            if (ps != null) {
+                ps.setEnabled(hasActiveSubscriptions);
+            }
+            ps = findPreference(BUTTON_CARRIER_SETTINGS_KEY);
+            if (ps != null) {
+                ps.setEnabled(hasActiveSubscriptions);
+            }
+            ps = findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
+            if (ps != null) {
+                ps.setEnabled(hasActiveSubscriptions);
             }
         }
 
-        // Get the networkMode from Settings.System and displays it
-        mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled());
-        mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode));
-        mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
-        UpdatePreferredNetworkModeSummary(settingsNetworkMode);
-        UpdateEnabledNetworksValueAndSummary(settingsNetworkMode);
-        // Display preferred network type based on what modem returns b/18676277
-        mPhone.setPreferredNetworkType(settingsNetworkMode, mHandler
-                .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
+        @Override
+        public void onPause() {
+            super.onPause();
+            if (DBG) log("onPause:+");
+
+            if (ImsManager.isVolteEnabledByPlatform(getActivity())
+                    && ImsManager.isVolteProvisionedOnDevice(getActivity())) {
+                TelephonyManager tm =
+                        (TelephonyManager) getActivity().getSystemService(
+                                Context.TELEPHONY_SERVICE);
+                tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
+            }
+
+            mSubscriptionManager
+                    .removeOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
+            if (DBG) log("onPause:-");
+        }
 
         /**
-         * Enable/disable depending upon if there are any active subscriptions.
+         * Implemented to support onPreferenceChangeListener to look for preference
+         * changes specifically on CLIR.
          *
-         * I've decided to put this enable/disable code at the bottom as the
-         * code above works even when there are no active subscriptions, thus
-         * putting it afterwards is a smaller change. This can be refined later,
-         * but you do need to remember that this all needs to work when subscriptions
-         * change dynamically such as when hot swapping sims.
+         * @param preference is the preference to be changed, should be mButtonCLIR.
+         * @param objValue should be the value of the selection, NOT its localized
+         * display value.
          */
-        boolean hasActiveSubscriptions = hasActiveSubscriptions();
-        TelephonyManager tm = (TelephonyManager) getSystemService(
-                Context.TELEPHONY_SERVICE);
-        boolean canChange4glte = (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) &&
-                ImsManager.isNonTtyOrTtyOnVolteEnabled(getApplicationContext()) &&
-                carrierConfig.getBoolean(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
-        boolean useVariant4glteTitle = carrierConfig.getBoolean(
-                CarrierConfigManager.KEY_ENHANCED_4G_LTE_TITLE_VARIANT_BOOL);
-        int enhanced4glteModeTitleId = useVariant4glteTitle ?
-                R.string.enhanced_4g_lte_mode_title_variant :
-                R.string.enhanced_4g_lte_mode_title;
-        mButtonDataRoam.setDisabledByAdmin(false);
-        mButtonDataRoam.setEnabled(hasActiveSubscriptions);
-        if (mButtonDataRoam.isEnabled()) {
-            if (RestrictedLockUtils.hasBaseUserRestriction(context,
-                    UserManager.DISALLOW_DATA_ROAMING, UserHandle.myUserId())) {
-                mButtonDataRoam.setEnabled(false);
-            } else {
-                mButtonDataRoam.checkRestrictionAndSetDisabled(UserManager.DISALLOW_DATA_ROAMING);
-            }
-        }
-        mButtonPreferredNetworkMode.setEnabled(hasActiveSubscriptions);
-        mButtonEnabledNetworks.setEnabled(hasActiveSubscriptions);
-        mButton4glte.setTitle(enhanced4glteModeTitleId);
-        mButton4glte.setEnabled(hasActiveSubscriptions && canChange4glte);
-        mLteDataServicePref.setEnabled(hasActiveSubscriptions);
-        Preference ps;
-        PreferenceScreen root = getPreferenceScreen();
-        ps = findPreference(BUTTON_CELL_BROADCAST_SETTINGS);
-        if (ps != null) {
-            ps.setEnabled(hasActiveSubscriptions);
-        }
-        ps = findPreference(BUTTON_APN_EXPAND_KEY);
-        if (ps != null) {
-            ps.setEnabled(hasActiveSubscriptions);
-        }
-        ps = findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
-        if (ps != null) {
-            ps.setEnabled(hasActiveSubscriptions);
-        }
-        ps = findPreference(BUTTON_CARRIER_SETTINGS_KEY);
-        if (ps != null) {
-            ps.setEnabled(hasActiveSubscriptions);
-        }
-        ps = findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
-        if (ps != null) {
-            ps.setEnabled(hasActiveSubscriptions);
-        }
-    }
-
-    @Override
-    protected void onPause() {
-        super.onPause();
-        if (DBG) log("onPause:+");
-
-        if (ImsManager.isVolteEnabledByPlatform(this)
-                && ImsManager.isVolteProvisionedOnDevice(this)) {
-            TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-            tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
-        }
-
-        mSubscriptionManager
-            .removeOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
-        if (DBG) log("onPause:-");
-    }
-
-    /**
-     * Implemented to support onPreferenceChangeListener to look for preference
-     * changes specifically on CLIR.
-     *
-     * @param preference is the preference to be changed, should be mButtonCLIR.
-     * @param objValue should be the value of the selection, NOT its localized
-     * display value.
-     */
-    public boolean onPreferenceChange(Preference preference, Object objValue) {
-        final int phoneSubId = mPhone.getSubId();
-        if (preference == mButtonPreferredNetworkMode) {
-            //NOTE onPreferenceChange seems to be called even if there is no change
-            //Check if the button value is changed from the System.Setting
-            mButtonPreferredNetworkMode.setValue((String) objValue);
-            int buttonNetworkMode;
-            buttonNetworkMode = Integer.parseInt((String) objValue);
-            int settingsNetworkMode = android.provider.Settings.Global.getInt(
-                    mPhone.getContext().getContentResolver(),
-                    android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                    preferredNetworkMode);
-            if (buttonNetworkMode != settingsNetworkMode) {
-                int modemNetworkMode;
-                // if new mode is invalid ignore it
-                switch (buttonNetworkMode) {
-                    case Phone.NT_MODE_WCDMA_PREF:
-                    case Phone.NT_MODE_GSM_ONLY:
-                    case Phone.NT_MODE_WCDMA_ONLY:
-                    case Phone.NT_MODE_GSM_UMTS:
-                    case Phone.NT_MODE_CDMA:
-                    case Phone.NT_MODE_CDMA_NO_EVDO:
-                    case Phone.NT_MODE_EVDO_NO_CDMA:
-                    case Phone.NT_MODE_GLOBAL:
-                    case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
-                    case Phone.NT_MODE_LTE_GSM_WCDMA:
-                    case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
-                    case Phone.NT_MODE_LTE_ONLY:
-                    case Phone.NT_MODE_LTE_WCDMA:
-                    case Phone.NT_MODE_TDSCDMA_ONLY:
-                    case Phone.NT_MODE_TDSCDMA_WCDMA:
-                    case Phone.NT_MODE_LTE_TDSCDMA:
-                    case Phone.NT_MODE_TDSCDMA_GSM:
-                    case Phone.NT_MODE_LTE_TDSCDMA_GSM:
-                    case Phone.NT_MODE_TDSCDMA_GSM_WCDMA:
-                    case Phone.NT_MODE_LTE_TDSCDMA_WCDMA:
-                    case Phone.NT_MODE_LTE_TDSCDMA_GSM_WCDMA:
-                    case Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-                    case Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-                        // This is one of the modes we recognize
-                        modemNetworkMode = buttonNetworkMode;
-                        break;
-                    default:
-                        loge("Invalid Network Mode (" + buttonNetworkMode + ") chosen. Ignore.");
-                        return true;
-                }
-
-                android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
+        public boolean onPreferenceChange(Preference preference, Object objValue) {
+            final int phoneSubId = mPhone.getSubId();
+            if (preference == mButtonPreferredNetworkMode) {
+                //NOTE onPreferenceChange seems to be called even if there is no change
+                //Check if the button value is changed from the System.Setting
+                mButtonPreferredNetworkMode.setValue((String) objValue);
+                int buttonNetworkMode;
+                buttonNetworkMode = Integer.parseInt((String) objValue);
+                int settingsNetworkMode = android.provider.Settings.Global.getInt(
+                        mPhone.getContext().getContentResolver(),
                         android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                        buttonNetworkMode );
-                //Set the modem network mode
-                mPhone.setPreferredNetworkType(modemNetworkMode, mHandler
-                        .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
-            }
-        } else if (preference == mButtonEnabledNetworks) {
-            mButtonEnabledNetworks.setValue((String) objValue);
-            int buttonNetworkMode;
-            buttonNetworkMode = Integer.parseInt((String) objValue);
-            if (DBG) log("buttonNetworkMode: " + buttonNetworkMode);
-            int settingsNetworkMode = android.provider.Settings.Global.getInt(
-                    mPhone.getContext().getContentResolver(),
-                    android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                    preferredNetworkMode);
-            if (buttonNetworkMode != settingsNetworkMode) {
-                int modemNetworkMode;
-                // if new mode is invalid ignore it
-                switch (buttonNetworkMode) {
-                    case Phone.NT_MODE_WCDMA_PREF:
-                    case Phone.NT_MODE_GSM_ONLY:
-                    case Phone.NT_MODE_LTE_GSM_WCDMA:
-                    case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
-                    case Phone.NT_MODE_CDMA:
-                    case Phone.NT_MODE_CDMA_NO_EVDO:
-                    case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
-                    case Phone.NT_MODE_TDSCDMA_ONLY:
-                    case Phone.NT_MODE_TDSCDMA_WCDMA:
-                    case Phone.NT_MODE_LTE_TDSCDMA:
-                    case Phone.NT_MODE_TDSCDMA_GSM:
-                    case Phone.NT_MODE_LTE_TDSCDMA_GSM:
-                    case Phone.NT_MODE_TDSCDMA_GSM_WCDMA:
-                    case Phone.NT_MODE_LTE_TDSCDMA_WCDMA:
-                    case Phone.NT_MODE_LTE_TDSCDMA_GSM_WCDMA:
-                    case Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-                    case Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-                        // This is one of the modes we recognize
-                        modemNetworkMode = buttonNetworkMode;
-                        break;
-                    default:
-                        loge("Invalid Network Mode (" + buttonNetworkMode + ") chosen. Ignore.");
-                        return true;
+                        preferredNetworkMode);
+                if (buttonNetworkMode != settingsNetworkMode) {
+                    int modemNetworkMode;
+                    // if new mode is invalid ignore it
+                    switch (buttonNetworkMode) {
+                        case Phone.NT_MODE_WCDMA_PREF:
+                        case Phone.NT_MODE_GSM_ONLY:
+                        case Phone.NT_MODE_WCDMA_ONLY:
+                        case Phone.NT_MODE_GSM_UMTS:
+                        case Phone.NT_MODE_CDMA:
+                        case Phone.NT_MODE_CDMA_NO_EVDO:
+                        case Phone.NT_MODE_EVDO_NO_CDMA:
+                        case Phone.NT_MODE_GLOBAL:
+                        case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
+                        case Phone.NT_MODE_LTE_GSM_WCDMA:
+                        case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+                        case Phone.NT_MODE_LTE_ONLY:
+                        case Phone.NT_MODE_LTE_WCDMA:
+                        case Phone.NT_MODE_TDSCDMA_ONLY:
+                        case Phone.NT_MODE_TDSCDMA_WCDMA:
+                        case Phone.NT_MODE_LTE_TDSCDMA:
+                        case Phone.NT_MODE_TDSCDMA_GSM:
+                        case Phone.NT_MODE_LTE_TDSCDMA_GSM:
+                        case Phone.NT_MODE_TDSCDMA_GSM_WCDMA:
+                        case Phone.NT_MODE_LTE_TDSCDMA_WCDMA:
+                        case Phone.NT_MODE_LTE_TDSCDMA_GSM_WCDMA:
+                        case Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+                        case Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+                            // This is one of the modes we recognize
+                            modemNetworkMode = buttonNetworkMode;
+                            break;
+                        default:
+                            loge("Invalid Network Mode (" +buttonNetworkMode+ ") chosen. Ignore.");
+                            return true;
+                    }
+
+                    android.provider.Settings.Global.putInt(
+                            mPhone.getContext().getContentResolver(),
+                            android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
+                            buttonNetworkMode );
+                    //Set the modem network mode
+                    mPhone.setPreferredNetworkType(modemNetworkMode, mHandler
+                            .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
                 }
-
-                UpdateEnabledNetworksValueAndSummary(buttonNetworkMode);
-
-                android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
+            } else if (preference == mButtonEnabledNetworks) {
+                mButtonEnabledNetworks.setValue((String) objValue);
+                int buttonNetworkMode;
+                buttonNetworkMode = Integer.parseInt((String) objValue);
+                if (DBG) log("buttonNetworkMode: " + buttonNetworkMode);
+                int settingsNetworkMode = android.provider.Settings.Global.getInt(
+                        mPhone.getContext().getContentResolver(),
                         android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                        buttonNetworkMode );
-                //Set the modem network mode
-                mPhone.setPreferredNetworkType(modemNetworkMode, mHandler
-                        .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
-            }
-        } else if (preference == mButton4glte) {
-            SwitchPreference enhanced4gModePref = (SwitchPreference) preference;
-            boolean enhanced4gMode = !enhanced4gModePref.isChecked();
-            enhanced4gModePref.setChecked(enhanced4gMode);
-            ImsManager.setEnhanced4gLteModeSetting(this, enhanced4gModePref.isChecked());
-        } else if (preference == mButtonDataRoam) {
-            if (DBG) log("onPreferenceTreeClick: preference == mButtonDataRoam.");
+                        preferredNetworkMode);
+                if (buttonNetworkMode != settingsNetworkMode) {
+                    int modemNetworkMode;
+                    // if new mode is invalid ignore it
+                    switch (buttonNetworkMode) {
+                        case Phone.NT_MODE_WCDMA_PREF:
+                        case Phone.NT_MODE_GSM_ONLY:
+                        case Phone.NT_MODE_LTE_GSM_WCDMA:
+                        case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+                        case Phone.NT_MODE_CDMA:
+                        case Phone.NT_MODE_CDMA_NO_EVDO:
+                        case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
+                        case Phone.NT_MODE_TDSCDMA_ONLY:
+                        case Phone.NT_MODE_TDSCDMA_WCDMA:
+                        case Phone.NT_MODE_LTE_TDSCDMA:
+                        case Phone.NT_MODE_TDSCDMA_GSM:
+                        case Phone.NT_MODE_LTE_TDSCDMA_GSM:
+                        case Phone.NT_MODE_TDSCDMA_GSM_WCDMA:
+                        case Phone.NT_MODE_LTE_TDSCDMA_WCDMA:
+                        case Phone.NT_MODE_LTE_TDSCDMA_GSM_WCDMA:
+                        case Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+                        case Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+                            // This is one of the modes we recognize
+                            modemNetworkMode = buttonNetworkMode;
+                            break;
+                        default:
+                            loge("Invalid Network Mode (" +buttonNetworkMode+ ") chosen. Ignore.");
+                            return true;
+                    }
 
-            //normally called on the toggle click
-            if (!mButtonDataRoam.isChecked()) {
-                // First confirm with a warning dialog about charges
-                mOkClicked = false;
-                RoamingDialogFragment fragment = new RoamingDialogFragment();
-                fragment.show(getFragmentManager(), ROAMING_TAG);
-                // Don't update the toggle unless the confirm button is actually pressed.
-                return false;
-            } else {
-                mPhone.setDataRoamingEnabled(false);
+                    UpdateEnabledNetworksValueAndSummary(buttonNetworkMode);
+
+                    android.provider.Settings.Global.putInt(
+                            mPhone.getContext().getContentResolver(),
+                            android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
+                            buttonNetworkMode );
+                    //Set the modem network mode
+                    mPhone.setPreferredNetworkType(modemNetworkMode, mHandler
+                            .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
+                }
+            } else if (preference == mButton4glte) {
+                SwitchPreference enhanced4gModePref = (SwitchPreference) preference;
+                boolean enhanced4gMode = !enhanced4gModePref.isChecked();
+                enhanced4gModePref.setChecked(enhanced4gMode);
+                ImsManager.setEnhanced4gLteModeSetting(getActivity(),
+                        enhanced4gModePref.isChecked());
+            } else if (preference == mButtonDataRoam) {
+                if (DBG) log("onPreferenceTreeClick: preference == mButtonDataRoam.");
+
+                //normally called on the toggle click
+                if (!mButtonDataRoam.isChecked()) {
+                    // First confirm with a warning dialog about charges
+                    mOkClicked = false;
+                    RoamingDialogFragment fragment = new RoamingDialogFragment();
+                    fragment.show(getFragmentManager(), ROAMING_TAG);
+                    // Don't update the toggle unless the confirm button is actually pressed.
+                    return false;
+                } else {
+                    mPhone.setDataRoamingEnabled(false);
+                }
+                return true;
             }
+
+            updateBody();
+            // always let the preference setting proceed.
             return true;
         }
 
-        updateBody();
-        // always let the preference setting proceed.
-        return true;
-    }
+        private class MyHandler extends Handler {
 
-    private class MyHandler extends Handler {
+            static final int MESSAGE_SET_PREFERRED_NETWORK_TYPE = 0;
 
-        static final int MESSAGE_SET_PREFERRED_NETWORK_TYPE = 0;
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MESSAGE_SET_PREFERRED_NETWORK_TYPE:
-                    handleSetPreferredNetworkTypeResponse(msg);
-                    break;
-            }
-        }
-
-        private void handleSetPreferredNetworkTypeResponse(Message msg) {
-            if (isDestroyed()) { // Access preferences of activity only if it is not destroyed
-                return;
-            }
-
-            AsyncResult ar = (AsyncResult) msg.obj;
-            final int phoneSubId = mPhone.getSubId();
-
-            if (ar.exception == null) {
-                int networkMode;
-                if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null)  {
-                    networkMode =  Integer.parseInt(mButtonPreferredNetworkMode.getValue());
-                    android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
-                            android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                            networkMode );
-                }
-                if (getPreferenceScreen().findPreference(BUTTON_ENABLED_NETWORKS_KEY) != null)  {
-                    networkMode = Integer.parseInt(mButtonEnabledNetworks.getValue());
-                    android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(),
-                            android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                            networkMode );
-                }
-            } else {
-                if (DBG) {
-                    log("handleSetPreferredNetworkTypeResponse: exception in setting network mode.");
-                }
-                updatePreferredNetworkUIFromDb();
-            }
-        }
-    }
-
-    private void updatePreferredNetworkUIFromDb() {
-        final int phoneSubId = mPhone.getSubId();
-
-        int settingsNetworkMode = android.provider.Settings.Global.getInt(
-                mPhone.getContext().getContentResolver(),
-                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
-                preferredNetworkMode);
-
-        if (DBG) {
-            log("updatePreferredNetworkUIFromDb: settingsNetworkMode = " +
-                    settingsNetworkMode);
-        }
-
-        UpdatePreferredNetworkModeSummary(settingsNetworkMode);
-        UpdateEnabledNetworksValueAndSummary(settingsNetworkMode);
-        // changes the mButtonPreferredNetworkMode accordingly to settingsNetworkMode
-        mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
-    }
-
-    private void UpdatePreferredNetworkModeSummary(int NetworkMode) {
-        switch(NetworkMode) {
-            case Phone.NT_MODE_TDSCDMA_GSM_WCDMA:
-            case Phone.NT_MODE_TDSCDMA_GSM:
-            case Phone.NT_MODE_WCDMA_PREF:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_wcdma_perf_summary);
-                break;
-            case Phone.NT_MODE_GSM_ONLY:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_gsm_only_summary);
-                break;
-            case Phone.NT_MODE_TDSCDMA_WCDMA:
-            case Phone.NT_MODE_WCDMA_ONLY:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_wcdma_only_summary);
-                break;
-            case Phone.NT_MODE_GSM_UMTS:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_gsm_wcdma_summary);
-                break;
-            case Phone.NT_MODE_CDMA:
-                switch (mPhone.getLteOnCdmaMode()) {
-                    case PhoneConstants.LTE_ON_CDMA_TRUE:
-                        mButtonPreferredNetworkMode.setSummary(
-                            R.string.preferred_network_mode_cdma_summary);
-                    break;
-                    case PhoneConstants.LTE_ON_CDMA_FALSE:
-                    default:
-                        mButtonPreferredNetworkMode.setSummary(
-                            R.string.preferred_network_mode_cdma_evdo_summary);
+            @Override
+            public void handleMessage(Message msg) {
+                switch (msg.what) {
+                    case MESSAGE_SET_PREFERRED_NETWORK_TYPE:
+                        handleSetPreferredNetworkTypeResponse(msg);
                         break;
                 }
-                break;
-            case Phone.NT_MODE_CDMA_NO_EVDO:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_cdma_only_summary);
-                break;
-            case Phone.NT_MODE_EVDO_NO_CDMA:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_evdo_only_summary);
-                break;
-            case Phone.NT_MODE_LTE_TDSCDMA:
-            case Phone.NT_MODE_LTE_ONLY:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_lte_summary);
-                break;
-            case Phone.NT_MODE_LTE_TDSCDMA_GSM:
-            case Phone.NT_MODE_LTE_TDSCDMA_GSM_WCDMA:
-            case Phone.NT_MODE_LTE_GSM_WCDMA:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_lte_gsm_wcdma_summary);
-                break;
-            case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_lte_cdma_evdo_summary);
-                break;
-            case Phone.NT_MODE_TDSCDMA_ONLY:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_tdscdma_summary);
-                break;
-            case Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-            case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
-                if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA ||
-                        mIsGlobalCdma ||
-                        isWorldMode()) {
-                    mButtonPreferredNetworkMode.setSummary(
-                            R.string.preferred_network_mode_global_summary);
+            }
+
+            private void handleSetPreferredNetworkTypeResponse(Message msg) {
+                if (getActivity().isDestroyed()) {
+                    // Access preferences of activity only if it is not destroyed
+                    return;
+                }
+
+                AsyncResult ar = (AsyncResult) msg.obj;
+                final int phoneSubId = mPhone.getSubId();
+
+                if (ar.exception == null) {
+                    int networkMode;
+                    if (getPreferenceScreen().findPreference(
+                            BUTTON_PREFERED_NETWORK_MODE) != null)  {
+                        networkMode =  Integer.parseInt(mButtonPreferredNetworkMode.getValue());
+                        android.provider.Settings.Global.putInt(
+                                mPhone.getContext().getContentResolver(),
+                                android.provider.Settings.Global.PREFERRED_NETWORK_MODE
+                                        + phoneSubId,
+                                networkMode );
+                    }
+                    if (getPreferenceScreen().findPreference(BUTTON_ENABLED_NETWORKS_KEY) != null) {
+                        networkMode = Integer.parseInt(mButtonEnabledNetworks.getValue());
+                        android.provider.Settings.Global.putInt(
+                                mPhone.getContext().getContentResolver(),
+                                android.provider.Settings.Global.PREFERRED_NETWORK_MODE
+                                        + phoneSubId,
+                                networkMode );
+                    }
                 } else {
+                    Log.i(LOG_TAG, "handleSetPreferredNetworkTypeResponse:" +
+                            "exception in setting network mode.");
+                    updatePreferredNetworkUIFromDb();
+                }
+            }
+        }
+
+        private void updatePreferredNetworkUIFromDb() {
+            final int phoneSubId = mPhone.getSubId();
+
+            int settingsNetworkMode = android.provider.Settings.Global.getInt(
+                    mPhone.getContext().getContentResolver(),
+                    android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
+                    preferredNetworkMode);
+
+            if (DBG) {
+                log("updatePreferredNetworkUIFromDb: settingsNetworkMode = " +
+                        settingsNetworkMode);
+            }
+
+            UpdatePreferredNetworkModeSummary(settingsNetworkMode);
+            UpdateEnabledNetworksValueAndSummary(settingsNetworkMode);
+            // changes the mButtonPreferredNetworkMode accordingly to settingsNetworkMode
+            mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
+        }
+
+        private void UpdatePreferredNetworkModeSummary(int NetworkMode) {
+            switch(NetworkMode) {
+                case Phone.NT_MODE_TDSCDMA_GSM_WCDMA:
+                case Phone.NT_MODE_TDSCDMA_GSM:
+                case Phone.NT_MODE_WCDMA_PREF:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_wcdma_perf_summary);
+                    break;
+                case Phone.NT_MODE_GSM_ONLY:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_gsm_only_summary);
+                    break;
+                case Phone.NT_MODE_TDSCDMA_WCDMA:
+                case Phone.NT_MODE_WCDMA_ONLY:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_wcdma_only_summary);
+                    break;
+                case Phone.NT_MODE_GSM_UMTS:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_gsm_wcdma_summary);
+                    break;
+                case Phone.NT_MODE_CDMA:
+                    switch (mPhone.getLteOnCdmaMode()) {
+                        case PhoneConstants.LTE_ON_CDMA_TRUE:
+                            mButtonPreferredNetworkMode.setSummary(
+                                    R.string.preferred_network_mode_cdma_summary);
+                            break;
+                        case PhoneConstants.LTE_ON_CDMA_FALSE:
+                        default:
+                            mButtonPreferredNetworkMode.setSummary(
+                                    R.string.preferred_network_mode_cdma_evdo_summary);
+                            break;
+                    }
+                    break;
+                case Phone.NT_MODE_CDMA_NO_EVDO:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_cdma_only_summary);
+                    break;
+                case Phone.NT_MODE_EVDO_NO_CDMA:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_evdo_only_summary);
+                    break;
+                case Phone.NT_MODE_LTE_TDSCDMA:
+                case Phone.NT_MODE_LTE_ONLY:
                     mButtonPreferredNetworkMode.setSummary(
                             R.string.preferred_network_mode_lte_summary);
-                }
-                break;
-            case Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-            case Phone.NT_MODE_GLOBAL:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_cdma_evdo_gsm_wcdma_summary);
-                break;
-            case Phone.NT_MODE_LTE_TDSCDMA_WCDMA:
-            case Phone.NT_MODE_LTE_WCDMA:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_lte_wcdma_summary);
-                break;
-            default:
-                mButtonPreferredNetworkMode.setSummary(
-                        R.string.preferred_network_mode_global_summary);
-        }
-    }
-
-    private void UpdateEnabledNetworksValueAndSummary(int NetworkMode) {
-        switch (NetworkMode) {
-            case Phone.NT_MODE_TDSCDMA_WCDMA:
-            case Phone.NT_MODE_TDSCDMA_GSM_WCDMA:
-            case Phone.NT_MODE_TDSCDMA_GSM:
-                mButtonEnabledNetworks.setValue(
-                        Integer.toString(Phone.NT_MODE_TDSCDMA_GSM_WCDMA));
-                mButtonEnabledNetworks.setSummary(R.string.network_3G);
-                break;
-            case Phone.NT_MODE_WCDMA_ONLY:
-            case Phone.NT_MODE_GSM_UMTS:
-            case Phone.NT_MODE_WCDMA_PREF:
-                if (!mIsGlobalCdma) {
-                    mButtonEnabledNetworks.setValue(
-                            Integer.toString(Phone.NT_MODE_WCDMA_PREF));
-                    mButtonEnabledNetworks.setSummary(R.string.network_3G);
-                } else {
-                    mButtonEnabledNetworks.setValue(
-                            Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
-                    mButtonEnabledNetworks.setSummary(R.string.network_global);
-                }
-                break;
-            case Phone.NT_MODE_GSM_ONLY:
-                if (!mIsGlobalCdma) {
-                    mButtonEnabledNetworks.setValue(
-                            Integer.toString(Phone.NT_MODE_GSM_ONLY));
-                    mButtonEnabledNetworks.setSummary(R.string.network_2G);
-                } else {
-                    mButtonEnabledNetworks.setValue(
-                            Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
-                    mButtonEnabledNetworks.setSummary(R.string.network_global);
-                }
-                break;
-            case Phone.NT_MODE_LTE_GSM_WCDMA:
-                if (isWorldMode()) {
-                    mButtonEnabledNetworks.setSummary(
-                            R.string.preferred_network_mode_lte_gsm_umts_summary);
-                    controlCdmaOptions(false);
-                    controlGsmOptions(true);
                     break;
-                }
-            case Phone.NT_MODE_LTE_ONLY:
-            case Phone.NT_MODE_LTE_WCDMA:
-                if (!mIsGlobalCdma) {
-                    mButtonEnabledNetworks.setValue(
-                            Integer.toString(Phone.NT_MODE_LTE_GSM_WCDMA));
-                    mButtonEnabledNetworks.setSummary((mShow4GForLTE == true)
-                            ? R.string.network_4G : R.string.network_lte);
-                } else {
-                    mButtonEnabledNetworks.setValue(
-                            Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
-                    mButtonEnabledNetworks.setSummary(R.string.network_global);
-                }
-                break;
-            case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
-                if (isWorldMode()) {
-                    mButtonEnabledNetworks.setSummary(
-                            R.string.preferred_network_mode_lte_cdma_summary);
-                    controlCdmaOptions(true);
-                    controlGsmOptions(false);
-                } else {
-                    mButtonEnabledNetworks.setValue(
-                            Integer.toString(Phone.NT_MODE_LTE_CDMA_AND_EVDO));
-                    mButtonEnabledNetworks.setSummary(R.string.network_lte);
-                }
-                break;
-            case Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-                mButtonEnabledNetworks.setValue(
-                        Integer.toString(Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
-                mButtonEnabledNetworks.setSummary(R.string.network_3G);
-                break;
-            case Phone.NT_MODE_CDMA:
-            case Phone.NT_MODE_EVDO_NO_CDMA:
-            case Phone.NT_MODE_GLOBAL:
-                mButtonEnabledNetworks.setValue(
-                        Integer.toString(Phone.NT_MODE_CDMA));
-                mButtonEnabledNetworks.setSummary(R.string.network_3G);
-                break;
-            case Phone.NT_MODE_CDMA_NO_EVDO:
-                mButtonEnabledNetworks.setValue(
-                        Integer.toString(Phone.NT_MODE_CDMA_NO_EVDO));
-                mButtonEnabledNetworks.setSummary(R.string.network_1x);
-                break;
-            case Phone.NT_MODE_TDSCDMA_ONLY:
-                mButtonEnabledNetworks.setValue(
-                        Integer.toString(Phone.NT_MODE_TDSCDMA_ONLY));
-                mButtonEnabledNetworks.setSummary(R.string.network_3G);
-                break;
-            case Phone.NT_MODE_LTE_TDSCDMA_GSM:
-            case Phone.NT_MODE_LTE_TDSCDMA_GSM_WCDMA:
-            case Phone.NT_MODE_LTE_TDSCDMA:
-            case Phone.NT_MODE_LTE_TDSCDMA_WCDMA:
-            case Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
-            case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
-                if (isSupportTdscdma()) {
-                    mButtonEnabledNetworks.setValue(
-                            Integer.toString(Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
-                    mButtonEnabledNetworks.setSummary(R.string.network_lte);
-                } else {
-                    if (isWorldMode()) {
-                        controlCdmaOptions(true);
-                        controlGsmOptions(false);
-                    }
-                    mButtonEnabledNetworks.setValue(
-                            Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
+                case Phone.NT_MODE_LTE_TDSCDMA_GSM:
+                case Phone.NT_MODE_LTE_TDSCDMA_GSM_WCDMA:
+                case Phone.NT_MODE_LTE_GSM_WCDMA:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_lte_gsm_wcdma_summary);
+                    break;
+                case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_lte_cdma_evdo_summary);
+                    break;
+                case Phone.NT_MODE_TDSCDMA_ONLY:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_tdscdma_summary);
+                    break;
+                case Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+                case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
                     if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA ||
                             mIsGlobalCdma ||
                             isWorldMode()) {
-                        mButtonEnabledNetworks.setSummary(R.string.network_global);
+                        mButtonPreferredNetworkMode.setSummary(
+                                R.string.preferred_network_mode_global_summary);
                     } else {
+                        mButtonPreferredNetworkMode.setSummary(
+                                R.string.preferred_network_mode_lte_summary);
+                    }
+                    break;
+                case Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+                case Phone.NT_MODE_GLOBAL:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_cdma_evdo_gsm_wcdma_summary);
+                    break;
+                case Phone.NT_MODE_LTE_TDSCDMA_WCDMA:
+                case Phone.NT_MODE_LTE_WCDMA:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_lte_wcdma_summary);
+                    break;
+                default:
+                    mButtonPreferredNetworkMode.setSummary(
+                            R.string.preferred_network_mode_global_summary);
+            }
+        }
+
+        private void UpdateEnabledNetworksValueAndSummary(int NetworkMode) {
+            switch (NetworkMode) {
+                case Phone.NT_MODE_TDSCDMA_WCDMA:
+                case Phone.NT_MODE_TDSCDMA_GSM_WCDMA:
+                case Phone.NT_MODE_TDSCDMA_GSM:
+                    mButtonEnabledNetworks.setValue(
+                            Integer.toString(Phone.NT_MODE_TDSCDMA_GSM_WCDMA));
+                    mButtonEnabledNetworks.setSummary(R.string.network_3G);
+                    break;
+                case Phone.NT_MODE_WCDMA_ONLY:
+                case Phone.NT_MODE_GSM_UMTS:
+                case Phone.NT_MODE_WCDMA_PREF:
+                    if (!mIsGlobalCdma) {
+                        mButtonEnabledNetworks.setValue(
+                                Integer.toString(Phone.NT_MODE_WCDMA_PREF));
+                        mButtonEnabledNetworks.setSummary(R.string.network_3G);
+                    } else {
+                        mButtonEnabledNetworks.setValue(
+                                Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
+                        mButtonEnabledNetworks.setSummary(R.string.network_global);
+                    }
+                    break;
+                case Phone.NT_MODE_GSM_ONLY:
+                    if (!mIsGlobalCdma) {
+                        mButtonEnabledNetworks.setValue(
+                                Integer.toString(Phone.NT_MODE_GSM_ONLY));
+                        mButtonEnabledNetworks.setSummary(R.string.network_2G);
+                    } else {
+                        mButtonEnabledNetworks.setValue(
+                                Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
+                        mButtonEnabledNetworks.setSummary(R.string.network_global);
+                    }
+                    break;
+                case Phone.NT_MODE_LTE_GSM_WCDMA:
+                    if (isWorldMode()) {
+                        mButtonEnabledNetworks.setSummary(
+                                R.string.preferred_network_mode_lte_gsm_umts_summary);
+                        controlCdmaOptions(false);
+                        controlGsmOptions(true);
+                        break;
+                    }
+                case Phone.NT_MODE_LTE_ONLY:
+                case Phone.NT_MODE_LTE_WCDMA:
+                    if (!mIsGlobalCdma) {
+                        mButtonEnabledNetworks.setValue(
+                                Integer.toString(Phone.NT_MODE_LTE_GSM_WCDMA));
                         mButtonEnabledNetworks.setSummary((mShow4GForLTE == true)
                                 ? R.string.network_4G : R.string.network_lte);
+                    } else {
+                        mButtonEnabledNetworks.setValue(
+                                Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
+                        mButtonEnabledNetworks.setSummary(R.string.network_global);
                     }
-                }
-                break;
-            default:
-                String errMsg = "Invalid Network Mode (" + NetworkMode + "). Ignore.";
-                loge(errMsg);
-                mButtonEnabledNetworks.setSummary(errMsg);
-        }
-    }
-
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        switch(requestCode) {
-        case REQUEST_CODE_EXIT_ECM:
-            Boolean isChoiceYes =
-                data.getBooleanExtra(EmergencyCallbackModeExitDialog.EXTRA_EXIT_ECM_RESULT, false);
-            if (isChoiceYes) {
-                // If the phone exits from ECM mode, show the CDMA Options
-                mCdmaOptions.showDialog(mClickedPreference);
-            } else {
-                // do nothing
+                    break;
+                case Phone.NT_MODE_LTE_CDMA_AND_EVDO:
+                    if (isWorldMode()) {
+                        mButtonEnabledNetworks.setSummary(
+                                R.string.preferred_network_mode_lte_cdma_summary);
+                        controlCdmaOptions(true);
+                        controlGsmOptions(false);
+                    } else {
+                        mButtonEnabledNetworks.setValue(
+                                Integer.toString(Phone.NT_MODE_LTE_CDMA_AND_EVDO));
+                        mButtonEnabledNetworks.setSummary(R.string.network_lte);
+                    }
+                    break;
+                case Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+                    mButtonEnabledNetworks.setValue(
+                            Integer.toString(Phone.NT_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
+                    mButtonEnabledNetworks.setSummary(R.string.network_3G);
+                    break;
+                case Phone.NT_MODE_CDMA:
+                case Phone.NT_MODE_EVDO_NO_CDMA:
+                case Phone.NT_MODE_GLOBAL:
+                    mButtonEnabledNetworks.setValue(
+                            Integer.toString(Phone.NT_MODE_CDMA));
+                    mButtonEnabledNetworks.setSummary(R.string.network_3G);
+                    break;
+                case Phone.NT_MODE_CDMA_NO_EVDO:
+                    mButtonEnabledNetworks.setValue(
+                            Integer.toString(Phone.NT_MODE_CDMA_NO_EVDO));
+                    mButtonEnabledNetworks.setSummary(R.string.network_1x);
+                    break;
+                case Phone.NT_MODE_TDSCDMA_ONLY:
+                    mButtonEnabledNetworks.setValue(
+                            Integer.toString(Phone.NT_MODE_TDSCDMA_ONLY));
+                    mButtonEnabledNetworks.setSummary(R.string.network_3G);
+                    break;
+                case Phone.NT_MODE_LTE_TDSCDMA_GSM:
+                case Phone.NT_MODE_LTE_TDSCDMA_GSM_WCDMA:
+                case Phone.NT_MODE_LTE_TDSCDMA:
+                case Phone.NT_MODE_LTE_TDSCDMA_WCDMA:
+                case Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+                case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+                    if (isSupportTdscdma()) {
+                        mButtonEnabledNetworks.setValue(
+                                Integer.toString(Phone.NT_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
+                        mButtonEnabledNetworks.setSummary(R.string.network_lte);
+                    } else {
+                        if (isWorldMode()) {
+                            controlCdmaOptions(true);
+                            controlGsmOptions(false);
+                        }
+                        mButtonEnabledNetworks.setValue(
+                                Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
+                        if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA ||
+                                mIsGlobalCdma ||
+                                isWorldMode()) {
+                            mButtonEnabledNetworks.setSummary(R.string.network_global);
+                        } else {
+                            mButtonEnabledNetworks.setSummary((mShow4GForLTE == true)
+                                    ? R.string.network_4G : R.string.network_lte);
+                        }
+                    }
+                    break;
+                default:
+                    String errMsg = "Invalid Network Mode (" + NetworkMode + "). Ignore.";
+                    loge(errMsg);
+                    mButtonEnabledNetworks.setSummary(errMsg);
             }
-            break;
-
-        default:
-            break;
         }
-    }
 
-    private static void log(String msg) {
-        Log.d(LOG_TAG, msg);
-    }
+        @Override
+        public void onActivityResult(int requestCode, int resultCode, Intent data) {
+            switch(requestCode) {
+                case REQUEST_CODE_EXIT_ECM:
+                    Boolean isChoiceYes = data.getBooleanExtra(
+                            EmergencyCallbackModeExitDialog.EXTRA_EXIT_ECM_RESULT, false);
+                    if (isChoiceYes) {
+                        // If the phone exits from ECM mode, show the CDMA Options
+                        mCdmaOptions.showDialog(mClickedPreference);
+                    } else {
+                        // do nothing
+                    }
+                    break;
 
-    private static void loge(String msg) {
-        Log.e(LOG_TAG, msg);
-    }
+                default:
+                    break;
+            }
+        }
 
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        final int itemId = item.getItemId();
-        if (itemId == android.R.id.home) {  // See ActionBar#setDisplayHomeAsUpEnabled()
-            // Commenting out "logical up" capability. This is a workaround for issue 5278083.
-            //
-            // Settings app may not launch this activity via UP_ACTIVITY_CLASS but the other
-            // Activity that looks exactly same as UP_ACTIVITY_CLASS ("SubSettings" Activity).
-            // At that moment, this Activity launches UP_ACTIVITY_CLASS on top of the Activity.
-            // which confuses users.
-            // TODO: introduce better mechanism for "up" capability here.
+        private static void log(String msg) {
+            Log.d(LOG_TAG, msg);
+        }
+
+        private static void loge(String msg) {
+            Log.e(LOG_TAG, msg);
+        }
+
+        @Override
+        public boolean onOptionsItemSelected(MenuItem item) {
+            final int itemId = item.getItemId();
+            if (itemId == android.R.id.home) {  // See ActionBar#setDisplayHomeAsUpEnabled()
+                // Commenting out "logical up" capability. This is a workaround for issue 5278083.
+                //
+                // Settings app may not launch this activity via UP_ACTIVITY_CLASS but the other
+                // Activity that looks exactly same as UP_ACTIVITY_CLASS ("SubSettings" Activity).
+                // At that moment, this Activity launches UP_ACTIVITY_CLASS on top of the Activity.
+                // which confuses users.
+                // TODO: introduce better mechanism for "up" capability here.
             /*Intent intent = new Intent(Intent.ACTION_MAIN);
             intent.setClassName(UP_ACTIVITY_PACKAGE, UP_ACTIVITY_CLASS);
             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
             startActivity(intent);*/
-            finish();
-            return true;
-        }
-        return super.onOptionsItemSelected(item);
-    }
-
-    private boolean isWorldMode() {
-        boolean worldModeOn = false;
-        final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-        final String configString = getResources().getString(R.string.config_world_mode);
-
-        if (!TextUtils.isEmpty(configString)) {
-            String[] configArray = configString.split(";");
-            // Check if we have World mode configuration set to True only or config is set to True
-            // and SIM GID value is also set and matches to the current SIM GID.
-            if (configArray != null &&
-                   ((configArray.length == 1 && configArray[0].equalsIgnoreCase("true")) ||
-                       (configArray.length == 2 && !TextUtils.isEmpty(configArray[1]) &&
-                           tm != null && configArray[1].equalsIgnoreCase(tm.getGroupIdLevel1())))) {
-                               worldModeOn = true;
-            }
-        }
-
-        if (DBG) {
-            log("isWorldMode=" + worldModeOn);
-        }
-
-        return worldModeOn;
-    }
-
-    private void controlGsmOptions(boolean enable) {
-        PreferenceScreen prefSet = getPreferenceScreen();
-        if (prefSet == null) {
-            return;
-        }
-
-        if (mGsmUmtsOptions == null) {
-            mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, mPhone.getSubId());
-        }
-        PreferenceScreen apnExpand =
-                (PreferenceScreen) prefSet.findPreference(BUTTON_APN_EXPAND_KEY);
-        PreferenceScreen operatorSelectionExpand =
-                (PreferenceScreen) prefSet.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
-        PreferenceScreen carrierSettings =
-                (PreferenceScreen) prefSet.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
-        if (apnExpand != null) {
-            apnExpand.setEnabled(isWorldMode() || enable);
-        }
-        if (operatorSelectionExpand != null) {
-            if (enable) {
-                operatorSelectionExpand.setEnabled(true);
-            } else {
-                prefSet.removePreference(operatorSelectionExpand);
-            }
-        }
-        if (carrierSettings != null) {
-            prefSet.removePreference(carrierSettings);
-        }
-    }
-
-    private void controlCdmaOptions(boolean enable) {
-        PreferenceScreen prefSet = getPreferenceScreen();
-        if (prefSet == null) {
-            return;
-        }
-        if (enable && mCdmaOptions == null) {
-            mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
-        }
-        CdmaSystemSelectListPreference systemSelect =
-                (CdmaSystemSelectListPreference)prefSet.findPreference
-                        (BUTTON_CDMA_SYSTEM_SELECT_KEY);
-        if (systemSelect != null) {
-            systemSelect.setEnabled(enable);
-        }
-    }
-
-    private boolean isSupportTdscdma() {
-        if (getResources().getBoolean(R.bool.config_support_tdscdma)) {
-            return true;
-        }
-
-        String operatorNumeric = mPhone.getServiceState().getOperatorNumeric();
-        String[] numericArray = getResources().getStringArray(
-                R.array.config_support_tdscdma_roaming_on_networks);
-        if (numericArray.length == 0 || operatorNumeric == null) {
-            return false;
-        }
-        for (String numeric : numericArray) {
-            if (operatorNumeric.equals(numeric)) {
+                getActivity().finish();
                 return true;
             }
+            return super.onOptionsItemSelected(item);
         }
-        return false;
+
+        private boolean isWorldMode() {
+            boolean worldModeOn = false;
+            final TelephonyManager tm =
+                    (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
+            final String configString = getResources().getString(R.string.config_world_mode);
+
+            if (!TextUtils.isEmpty(configString)) {
+                String[] configArray = configString.split(";");
+                // Check if we have World mode configuration set to True only or config is set to True
+                // and SIM GID value is also set and matches to the current SIM GID.
+                if (configArray != null &&
+                        ((configArray.length == 1 && configArray[0].equalsIgnoreCase("true"))
+                                || (configArray.length == 2 && !TextUtils.isEmpty(configArray[1])
+                                && tm != null
+                                && configArray[1].equalsIgnoreCase(tm.getGroupIdLevel1())))) {
+                    worldModeOn = true;
+                }
+            }
+
+            Log.d(LOG_TAG, "isWorldMode=" + worldModeOn);
+
+            return worldModeOn;
+        }
+
+        private void controlGsmOptions(boolean enable) {
+            PreferenceScreen prefSet = getPreferenceScreen();
+            if (prefSet == null) {
+                return;
+            }
+
+            if (mGsmUmtsOptions == null) {
+                mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, mPhone.getSubId());
+            }
+            PreferenceScreen apnExpand =
+                    (PreferenceScreen) prefSet.findPreference(BUTTON_APN_EXPAND_KEY);
+            PreferenceScreen operatorSelectionExpand =
+                    (PreferenceScreen) prefSet.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
+            PreferenceScreen carrierSettings =
+                    (PreferenceScreen) prefSet.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
+            if (apnExpand != null) {
+                apnExpand.setEnabled(isWorldMode() || enable);
+            }
+            if (operatorSelectionExpand != null) {
+                if (enable) {
+                    operatorSelectionExpand.setEnabled(true);
+                } else {
+                    prefSet.removePreference(operatorSelectionExpand);
+                }
+            }
+            if (carrierSettings != null) {
+                prefSet.removePreference(carrierSettings);
+            }
+        }
+
+        private void controlCdmaOptions(boolean enable) {
+            PreferenceScreen prefSet = getPreferenceScreen();
+            if (prefSet == null) {
+                return;
+            }
+            if (enable && mCdmaOptions == null) {
+                mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
+            }
+            CdmaSystemSelectListPreference systemSelect =
+                    (CdmaSystemSelectListPreference)prefSet.findPreference
+                            (BUTTON_CDMA_SYSTEM_SELECT_KEY);
+            if (systemSelect != null) {
+                systemSelect.setEnabled(enable);
+            }
+        }
+
+        private boolean isSupportTdscdma() {
+            if (getResources().getBoolean(R.bool.config_support_tdscdma)) {
+                return true;
+            }
+
+            String operatorNumeric = mPhone.getServiceState().getOperatorNumeric();
+            String[] numericArray = getResources().getStringArray(
+                    R.array.config_support_tdscdma_roaming_on_networks);
+            if (numericArray.length == 0 || operatorNumeric == null) {
+                return false;
+            }
+            for (String numeric : numericArray) {
+                if (operatorNumeric.equals(numeric)) {
+                    return true;
+                }
+            }
+            return false;
+        }
     }
 }
+
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 842eb06..88ff579 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -336,7 +336,7 @@
             registerReceiver(mReceiver, intentFilter);
 
             //set the default values for the preferences in the phone.
-            PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);
+            PreferenceManager.setDefaultValues(this, R.xml.network_setting_fragment, false);
 
             PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);
 
@@ -695,7 +695,7 @@
                 handleServiceStateChanged(intent);
             } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
                 int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY, 0);
-                phoneInEcm = getPhone(phoneId);
+                phoneInEcm = PhoneFactory.getPhone(phoneId);
                 Log.d(LOG_TAG, "Emergency Callback Mode. phoneId:" + phoneId);
                 if (phoneInEcm != null) {
                     if (TelephonyCapabilities.supportsEcm(phoneInEcm)) {
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 4ad77d9..c2c4e46 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -80,6 +80,7 @@
 import com.android.internal.telephony.MccTable;
 import com.android.internal.telephony.OperatorInfo;
 import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstantConversions;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.ProxyController;
@@ -88,7 +89,9 @@
 import com.android.internal.telephony.SubscriptionController;
 import com.android.internal.telephony.uicc.IccIoResult;
 import com.android.internal.telephony.uicc.IccUtils;
+import com.android.internal.telephony.uicc.SIMRecords;
 import com.android.internal.telephony.uicc.UiccCard;
+import com.android.internal.telephony.uicc.UiccCardApplication;
 import com.android.internal.telephony.uicc.UiccController;
 import com.android.internal.util.HexDump;
 import com.android.phone.settings.VisualVoicemailSettingsUtil;
@@ -160,6 +163,8 @@
     private static final int CMD_GET_ALLOWED_CARRIERS = 45;
     private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
     private static final int CMD_HANDLE_USSD_REQUEST = 47;
+    private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
+    private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
 
     /** The singleton instance. */
     private static PhoneInterfaceManager sInstance;
@@ -860,6 +865,56 @@
                     }
                     break;
 
+                case EVENT_GET_FORBIDDEN_PLMNS_DONE:
+                    ar = (AsyncResult) msg.obj;
+                    request = (MainThreadRequest) ar.userObj;
+                    if (ar.exception == null && ar.result != null) {
+                        request.result = ar.result;
+                    } else {
+                        request.result = new IllegalArgumentException(
+                                "Failed to retrieve Forbidden Plmns");
+                        if (ar.result == null) {
+                            loge("getForbiddenPlmns: Empty response");
+                        } else {
+                            loge("getForbiddenPlmns: Unknown exception");
+                        }
+                    }
+                    synchronized (request) {
+                        request.notifyAll();
+                    }
+                    break;
+
+                case CMD_GET_FORBIDDEN_PLMNS:
+                    request = (MainThreadRequest) msg.obj;
+                    uiccCard = getUiccCardFromRequest(request);
+                    if (uiccCard == null) {
+                        loge("getForbiddenPlmns() UiccCard is null");
+                        request.result = new IllegalArgumentException(
+                                "getForbiddenPlmns() UiccCard is null");
+                        synchronized (request) {
+                            request.notifyAll();
+                        }
+                        break;
+                    }
+                    Integer appType = (Integer) request.argument;
+                    UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
+                    if (uiccApp == null) {
+                        loge("getForbiddenPlmns() no app with specified type -- "
+                                + appType);
+                        request.result = new IllegalArgumentException("Failed to get UICC App");
+                        synchronized (request) {
+                            request.notifyAll();
+                        }
+                        break;
+                    } else {
+                        if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
+                                + " specified type -- " + appType);
+                    }
+                    onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
+                    ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
+                              onCompleted);
+                    break;
+
                 default:
                     Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
                     break;
@@ -1521,16 +1576,16 @@
     public int getCallStateForSlot(int slotId) {
         Phone phone = PhoneFactory.getPhone(slotId);
         return phone == null ? TelephonyManager.CALL_STATE_IDLE :
-            DefaultPhoneNotifier.convertCallState(phone.getState());
+            PhoneConstantConversions.convertCallState(phone.getState());
     }
 
     @Override
     public int getDataState() {
         Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
         if (phone != null) {
-            return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
+            return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
         } else {
-            return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED);
+            return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
         }
     }
 
@@ -2424,6 +2479,26 @@
         return result;
     }
 
+    /**
+     * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
+     * on a particular subscription
+     */
+    public String[] getForbiddenPlmns(int subId, int appType) {
+        mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
+                "Requires READ_PRIVILEGED_PHONE_STATE");
+        if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
+            loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
+            return null;
+        }
+        Object response = sendRequest(
+            CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
+        if (response instanceof String[]) {
+            return (String[]) response;
+        }
+        // Response is an Exception of some kind, which is signalled to the user as a NULL retval
+        return null;
+    }
+
     @Override
     public String sendEnvelopeWithStatus(int subId, String content) {
         enforceModifyPermissionOrCarrierPrivilege(subId);
@@ -2985,6 +3060,7 @@
     }
 
     @Override
+    @Deprecated
     public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
         enforceModifyPermission();
 
diff --git a/src/com/android/phone/PhoneSearchIndexablesProvider.java b/src/com/android/phone/PhoneSearchIndexablesProvider.java
index f1dacd9..85ea653 100644
--- a/src/com/android/phone/PhoneSearchIndexablesProvider.java
+++ b/src/com/android/phone/PhoneSearchIndexablesProvider.java
@@ -37,7 +37,7 @@
     private static final String TAG = "PhoneSearchIndexablesProvider";
 
     private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] {
-            new SearchIndexableResource(1, R.xml.network_setting,
+            new SearchIndexableResource(1, R.xml.network_setting_fragment,
                     MobileNetworkSettings.class.getName(),
                     R.mipmap.ic_launcher_phone),
     };
diff --git a/src/com/android/phone/RoamingDialogFragment.java b/src/com/android/phone/RoamingDialogFragment.java
index ec2967f..21c6946 100644
--- a/src/com/android/phone/RoamingDialogFragment.java
+++ b/src/com/android/phone/RoamingDialogFragment.java
@@ -18,6 +18,8 @@
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.DialogFragment;
+import android.app.Fragment;
+import android.app.FragmentManager;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnClickListener;
@@ -44,10 +46,12 @@
     public void onAttach(Context context) {
         super.onAttach(context);
         // Verify host activity implemented callback interface
+        FragmentManager fragmentManager = getFragmentManager();
+        Fragment fragment = fragmentManager.findFragmentById(R.id.network_setting_content);
         try {
-            mListener = (RoamingDialogListener) getActivity();
+            mListener = (RoamingDialogListener) fragment;
         } catch (ClassCastException e) {
-            throw new ClassCastException(getActivity().toString() +
+            throw new ClassCastException(fragment.toString() +
                     "must implement RoamingDialogListener");
         }
     }
diff --git a/src/com/android/phone/otasp/OtaspSimStateReceiver.java b/src/com/android/phone/otasp/OtaspSimStateReceiver.java
index c0409ba..213aa9f 100644
--- a/src/com/android/phone/otasp/OtaspSimStateReceiver.java
+++ b/src/com/android/phone/otasp/OtaspSimStateReceiver.java
@@ -24,7 +24,6 @@
 import android.telephony.TelephonyManager;
 import android.util.Log;
 import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.ServiceStateTracker;
 import com.android.phone.PhoneGlobals;
 
 public class OtaspSimStateReceiver extends BroadcastReceiver {
@@ -36,10 +35,10 @@
         @Override
         public void onOtaspChanged(int otaspMode) {
             logd("onOtaspChanged: otaspMode=" + otaspMode);
-            if (otaspMode == ServiceStateTracker.OTASP_NEEDED) {
+            if (otaspMode == TelephonyManager.OTASP_NEEDED) {
                 logd("otasp activation required, start otaspActivationService");
                 mContext.startService(new Intent(mContext, OtaspActivationService.class));
-            } else if (otaspMode == ServiceStateTracker.OTASP_NOT_NEEDED) {
+            } else if (otaspMode == TelephonyManager.OTASP_NOT_NEEDED) {
                 OtaspActivationService.updateActivationState(mContext, true);
             }
         }
diff --git a/src/com/android/phone/vvm/VvmSimStateTracker.java b/src/com/android/phone/vvm/VvmSimStateTracker.java
index df9b8a6..fd6aaee 100644
--- a/src/com/android/phone/vvm/VvmSimStateTracker.java
+++ b/src/com/android/phone/vvm/VvmSimStateTracker.java
@@ -81,12 +81,19 @@
         }
 
         public void listen() {
-            getTelephonyManager(mContext, mPhoneAccountHandle)
-                    .listen(this, PhoneStateListener.LISTEN_SERVICE_STATE);
+            TelephonyManager telephonyManager = getTelephonyManager(mContext, mPhoneAccountHandle);
+            if(telephonyManager == null){
+                VvmLog.e(TAG, "Cannot create TelephonyManager from " + mPhoneAccountHandle);
+                return;
+            }
+            telephonyManager.listen(this, PhoneStateListener.LISTEN_SERVICE_STATE);
         }
 
         public void unlisten() {
-            getTelephonyManager(mContext, mPhoneAccountHandle)
+            // TelephonyManager does not need to be pinned to an account when removing a
+            // PhoneStateListener, and mPhoneAccountHandle might be invalid at this point
+            // (e.g. SIM removal)
+            mContext.getSystemService(TelephonyManager.class)
                     .listen(this, PhoneStateListener.LISTEN_NONE);
             sListeners.put(mPhoneAccountHandle, null);
         }
diff --git a/src/com/android/services/telephony/ConferenceParticipantConnection.java b/src/com/android/services/telephony/ConferenceParticipantConnection.java
index ed7ad44..19dda54 100644
--- a/src/com/android/services/telephony/ConferenceParticipantConnection.java
+++ b/src/com/android/services/telephony/ConferenceParticipantConnection.java
@@ -16,6 +16,7 @@
 
 package com.android.services.telephony;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 
@@ -70,7 +71,7 @@
             address = null;
         } else {
             String countryIso = getCountryIso(parentConnection.getCall().getPhone());
-            address = getParticipantAddress(participant, countryIso);
+            address = getParticipantAddress(participant.getHandle(), countryIso);
         }
         setAddress(address, presentation);
         setCallerDisplayName(participant.getDisplayName(), presentation);
@@ -212,21 +213,19 @@
      * Conference event package data contains SIP URIs, so we try to extract the phone number and
      * format into a typical tel: style URI.
      *
-     * @param participant The conference participant.
+     * @param address The conference participant's address.
      * @param countryIso The country ISO of the current subscription; used when formatting the
      *                   participant phone number to E.164 format.
      * @return The participant's address URI.
      */
-    private Uri getParticipantAddress(ConferenceParticipant participant, String countryIso) {
-        Uri address = participant.getHandle();
+    @VisibleForTesting
+    public static Uri getParticipantAddress(Uri address, String countryIso) {
         if (address == null) {
             return address;
         }
-
-        // If the participant's address is already a TEL scheme, just return it as is.
-        if (PhoneAccount.SCHEME_TEL.equals(address.getScheme())) {
-            return address;
-        }
+        // Even if address is already in tel: format, still parse it and rebuild.
+        // This is to recognize tel URIs such as:
+        // tel:6505551212;phone-context=ims.mnc012.mcc034.3gppnetwork.org
 
         // Conference event package participants are identified using SIP URIs (see RFC3261).
         // A valid SIP uri has the format: sip:user:password@host:port;uri-parameters?headers
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index a20edc2..f66daec 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -43,12 +43,12 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.CallStateException;
+import com.android.internal.telephony.GsmCdmaPhone;
 import com.android.internal.telephony.IccCard;
 import com.android.internal.telephony.IccCardConstants;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.PhoneFactory;
-import com.android.internal.telephony.SubscriptionController;
 import com.android.internal.telephony.imsphone.ImsExternalCallTracker;
 import com.android.internal.telephony.imsphone.ImsPhone;
 import com.android.phone.MMIDialogActivity;
@@ -889,6 +889,18 @@
         try {
             if (phone != null) {
                 originalConnection = phone.dial(number, null, videoState, extras);
+
+                if (phone instanceof GsmCdmaPhone) {
+                    GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
+                    if (gsmCdmaPhone.isNotificationOfWfcCallRequired(number)) {
+                        // Send connection event to InCall UI to inform the user of the fact they
+                        // are potentially placing an international call on WFC.
+                        Log.i(this, "placeOutgoingConnection - sending international call on WFC " +
+                                "confirmation event");
+                        connection.sendConnectionEvent(
+                                TelephonyManager.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC, null);
+                    }
+                }
             }
         } catch (CallStateException e) {
             Log.e(this, e, "placeOutgoingConnection, phone.dial exception: " + e);
diff --git a/tests/src/com/android/phone/RoamingDialogFragmentTest.java b/tests/src/com/android/phone/RoamingDialogFragmentTest.java
index 96a3fda..62633e0 100644
--- a/tests/src/com/android/phone/RoamingDialogFragmentTest.java
+++ b/tests/src/com/android/phone/RoamingDialogFragmentTest.java
@@ -21,6 +21,7 @@
 import android.provider.Settings.SettingNotFoundException;
 import android.support.test.espresso.matcher.PreferenceMatchers;
 import android.support.test.rule.ActivityTestRule;
+import android.support.test.filters.FlakyTest;
 import com.google.common.truth.Truth;
 import junit.framework.AssertionFailedError;
 import org.junit.Before;
@@ -68,6 +69,7 @@
         }
     }
 
+    @FlakyTest
     @Test
     public void dataRoamingDialogPersistsOnRotation() {
         // click on the data roaming preference to trigger warning dialog
@@ -82,6 +84,7 @@
 
     }
 
+    @FlakyTest
     @Test
     public void dataRoamingEnabledWhenPositiveButtonClicked() throws SettingNotFoundException {
         // click on the data roaming preference to trigger warning dialog
@@ -95,6 +98,7 @@
                 Global.DATA_ROAMING)).isEqualTo(1);
     }
 
+    @FlakyTest
     @Test
     public void dialogDismissedOnNegativeButtonClicked() {
         // click on the data roaming preference to trigger warning dialog
@@ -107,6 +111,7 @@
         onView(withText(R.string.roaming_alert_title)).check(doesNotExist());
     }
 
+    @FlakyTest
     @Test
     public void dataRoamingStaysDisabledWhenDialogCanceled() throws SettingNotFoundException {
         // click on the data roaming preference to trigger warning dialog
diff --git a/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java b/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java
new file mode 100644
index 0000000..73fe0af
--- /dev/null
+++ b/tests/src/com/android/services/telephony/ConferenceParticipantConnectionTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 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.services.telephony;
+
+import android.net.Uri;
+import android.support.test.runner.AndroidJUnit4;
+import android.telecom.Conference;
+import android.telecom.ConferenceParticipant;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static com.android.services.telephony.ConferenceParticipantConnection.getParticipantAddress;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests proper parsing of conference event package participant addresses.
+ */
+@RunWith(AndroidJUnit4.class)
+public class ConferenceParticipantConnectionTest {
+
+    @Test
+    public void testParticipantParseSimpleTel() {
+        assertUrisEqual(Uri.parse("tel:+16505551212"),
+                getParticipantAddress(Uri.parse("tel:6505551212"), "US"));
+    }
+
+    @Test
+    public void testParticipantParseTelExtended() {
+        assertUrisEqual(Uri.parse("tel:+16505551212"),
+                getParticipantAddress(Uri.parse("tel:6505551212;phone-context=blah"), "US"));
+    }
+
+    @Test
+    public void testParticipantParseSip() {
+        assertUrisEqual(Uri.parse("tel:+16505551212"),
+                getParticipantAddress(Uri.parse("sip:16505551212;phone-context=blah.com@host.com"),
+                        "US"));
+    }
+
+    @Test
+    public void testParticipantParseSip2() {
+        assertUrisEqual(Uri.parse("tel:+12125551212"),
+                getParticipantAddress(Uri.parse("sip:+1-212-555-1212@something.com;user=phone"),
+                        "US"));
+    }
+
+    @Test
+    public void testParticipantParseTelJp() {
+        assertUrisEqual(Uri.parse("tel:+819066570660"),
+                getParticipantAddress(Uri.parse(
+                        "tel:09066570660;phone-context=ims.mnc020.mcc440.3gppnetwork.org"),
+                        "JP"));
+    }
+
+    @Test
+    public void testParticipantParseSipJp() {
+        assertUrisEqual(Uri.parse("tel:+819066571180"),
+                getParticipantAddress(Uri.parse(
+                        "sip:+819066571180@ims.mnc020.mcc440.3gppnetwork.org;user=phone"),
+                        "JP"));
+    }
+
+    private void assertUrisEqual(Uri expected, Uri actual) {
+        assertEquals(expected.getScheme(), actual.getScheme());
+        assertEquals(expected.getSchemeSpecificPart(), actual.getSchemeSpecificPart());
+    }
+}
diff --git a/tests/src/com/android/services/telephony/EmergencyCallStateListenerTest.java b/tests/src/com/android/services/telephony/EmergencyCallStateListenerTest.java
index d54c1e3..a9221e9 100644
--- a/tests/src/com/android/services/telephony/EmergencyCallStateListenerTest.java
+++ b/tests/src/com/android/services/telephony/EmergencyCallStateListenerTest.java
@@ -20,6 +20,7 @@
 import android.os.Handler;
 import android.telephony.ServiceState;
 import android.support.test.runner.AndroidJUnit4;
+import android.support.test.filters.FlakyTest;
 import android.test.suitebuilder.annotation.SmallTest;
 
 import com.android.TelephonyTestBase;
@@ -182,6 +183,7 @@
      * Result: callback's onComplete is called with the isRadioReady=true.
      */
     @Test
+    @FlakyTest
     @SmallTest
     public void testTimeout_EmergencyCalls() {
         ServiceState state = new ServiceState();
@@ -191,11 +193,11 @@
         when(mMockPhone.getServiceState()).thenReturn(state);
         when(mMockPhone.getServiceStateTracker()).thenReturn(mMockServiceStateTracker);
         when(mMockServiceStateTracker.isRadioOn()).thenReturn(true);
-        mListener.waitForRadioOn(mMockPhone, mCallback);
-        mListener.setTimeBetweenRetriesMillis(500);
+        mListener.setTimeBetweenRetriesMillis(100);
 
         // Wait for the timer to expire and check state manually in onRetryTimeout
-        waitForHandlerActionDelayed(mListener.getHandler(), TIMEOUT_MS, 600);
+        mListener.waitForRadioOn(mMockPhone, mCallback);
+        waitForHandlerActionDelayed(mListener.getHandler(), TIMEOUT_MS, 500);
 
         verify(mCallback).onComplete(eq(mListener), eq(true));
     }
@@ -212,6 +214,7 @@
      * - setRadioPower was send twice (tried to turn on the radio)
      */
     @Test
+    @FlakyTest
     @SmallTest
     public void testTimeout_RetryFailure() {
         ServiceState state = new ServiceState();
@@ -220,12 +223,12 @@
         when(mMockPhone.getServiceState()).thenReturn(state);
         when(mMockPhone.getServiceStateTracker()).thenReturn(mMockServiceStateTracker);
         when(mMockServiceStateTracker.isRadioOn()).thenReturn(false);
-        mListener.waitForRadioOn(mMockPhone, mCallback);
-        mListener.setTimeBetweenRetriesMillis(100);
+        mListener.setTimeBetweenRetriesMillis(50);
         mListener.setMaxNumRetries(2);
 
         // Wait for the timer to expire and check state manually in onRetryTimeout
-        waitForHandlerActionDelayed(mListener.getHandler(), TIMEOUT_MS, 600);
+        mListener.waitForRadioOn(mMockPhone, mCallback);
+        waitForHandlerActionDelayed(mListener.getHandler(), TIMEOUT_MS, 500);
 
         verify(mCallback).onComplete(eq(mListener), eq(false));
         verify(mMockPhone, times(2)).setRadioPower(eq(true));