Merge "Diable Flaky RoamingDialogFragmentTest tests"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ee16d38..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" />
@@ -317,18 +317,6 @@
             </intent-filter>
         </receiver>
 
-        <!-- Trampoline activity that handles the PERFORM_CDMA_PROVISIONING intent. -->
-        <activity android:name="InCallScreenShowActivation"
-            android:permission="android.permission.PERFORM_CDMA_PROVISIONING"
-            android:label="@string/phoneIconLabel"
-            android:theme="@android:style/Theme.NoDisplay"
-            android:excludeFromRecents="true">
-            <intent-filter>
-                <action android:name="com.android.phone.PERFORM_CDMA_PROVISIONING" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-        </activity>
-
         <!-- "Mobile network settings" screen, used on both
              non-voice-capable tablets and regular phone devices. -->
         <activity android:name="MobileNetworkSettings"
@@ -451,15 +439,6 @@
             </intent-filter>
         </activity>
 
-        <!-- Broadcast Receiver that will process BOOT Complete and launch OTA -->
-        <!-- TODO http://b/23526250 Handle OTASP under system user -->
-        <receiver android:name="OtaStartupReceiver" android:exported="false"
-                androidprv:systemUserOnly="true">
-            <intent-filter android:priority="100">
-                 <action android:name="android.intent.action.BOOT_COMPLETED"/>
-            </intent-filter>
-        </receiver>
-
         <!-- Activation service that trigger OTASP sim provisioning -->
         <service android:name=".otasp.OtaspActivationService" android:launchMode="singleInstance"
                  androidprv:systemUserOnly="true">
@@ -468,7 +447,8 @@
             </intent-filter>
         </service>
 
-        <receiver android:name=".otasp.OtaspSimStateReceiver" android:exported ="false">
+        <receiver android:name=".otasp.OtaspSimStateReceiver" androidprv:systemUserOnly="true"
+                  android:exported ="false">
             <intent-filter>
                 <action android:name="android.telephony.action.CARRIER_CONFIG_CHANGED" />
             </intent-filter>
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-ro/strings.xml b/res/values-ro/strings.xml
index 0873013..aca8be1 100644
--- a/res/values-ro/strings.xml
+++ b/res/values-ro/strings.xml
@@ -226,10 +226,10 @@
     <string name="throttle_time_frame" msgid="1915198770363734685">"Perioada de utilizare a datelor"</string>
     <string name="throttle_rate" msgid="4710388992676803508">"Politica ratei de transfer a datelor"</string>
     <string name="throttle_help" msgid="243651091785169900">"Aflați mai multe"</string>
-    <string name="throttle_status_subtext" msgid="1657318943142085170">"<xliff:g id="USED_0">%1$s</xliff:g> (<xliff:g id="USED_1">%2$d</xliff:g>٪) din <xliff:g id="USED_2">%3$s</xliff:g> perioada maximă\nUrmătoarea perioadă începe în <xliff:g id="USED_3">%4$d</xliff:g> (de) zile (<xliff:g id="USED_4">%5$s</xliff:g>)"</string>
+    <string name="throttle_status_subtext" msgid="1657318943142085170">"<xliff:g id="USED_0">%1$s</xliff:g> (<xliff:g id="USED_1">%2$d</xliff:g>٪) din <xliff:g id="USED_2">%3$s</xliff:g> perioada maximă\nUrmătoarea perioadă începe în <xliff:g id="USED_3">%4$d</xliff:g> zile (<xliff:g id="USED_4">%5$s</xliff:g>)"</string>
     <string name="throttle_data_usage_subtext" msgid="6029276011123694701">"<xliff:g id="USED_0">%1$s</xliff:g> (<xliff:g id="USED_1">%2$d</xliff:g>٪) din <xliff:g id="USED_2">%3$s</xliff:g> perioadă maximă"</string>
     <string name="throttle_data_rate_reduced_subtext" msgid="7492763592720107737">"<xliff:g id="USED_0">%1$s</xliff:g> maximum depășit\nRata de transfer se reduce la <xliff:g id="USED_1">%2$d</xliff:g> Kb/s"</string>
-    <string name="throttle_time_frame_subtext" msgid="7732763021560399960">"<xliff:g id="USED_0">%1$d</xliff:g>٪ din ciclul trecut\nPerioada următoare începe în <xliff:g id="USED_1">%2$d</xliff:g> (de) zile (<xliff:g id="USED_2">%3$s</xliff:g>)"</string>
+    <string name="throttle_time_frame_subtext" msgid="7732763021560399960">"<xliff:g id="USED_0">%1$d</xliff:g>٪ din ciclul trecut\nPerioada următoare începe în <xliff:g id="USED_1">%2$d</xliff:g> zile (<xliff:g id="USED_2">%3$s</xliff:g>)"</string>
     <string name="throttle_rate_subtext" msgid="2149102656120726855">"Rata de transfer a datelor se reduce la <xliff:g id="USED">%1$d</xliff:g> Kb/s, dacă limita de utilizare este depășită."</string>
     <string name="throttle_help_subtext" msgid="3633091498168446044">"Mai multe informații despre politica de utilizare a datelor aplicată de operatorul dvs. de telefonie mobilă"</string>
     <string name="cell_broadcast_sms" msgid="5584192824053625842">"Transmisie celulară a mesajelor SMS"</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/CallController.java b/src/com/android/phone/CallController.java
index 5b08662..a5d340c 100644
--- a/src/com/android/phone/CallController.java
+++ b/src/com/android/phone/CallController.java
@@ -19,7 +19,6 @@
 import com.android.internal.telephony.CallManager;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.TelephonyCapabilities;
 import com.android.phone.CallGatewayManager.RawGatewayInfo;
 import com.android.phone.Constants.CallStatusCode;
 
@@ -226,14 +225,6 @@
             throw new IllegalArgumentException("Unexpected action: " + action);
         }
 
-        // Check to see if this is an OTASP call (the "activation" call
-        // used to provision CDMA devices), and if so, do some
-        // OTASP-specific setup.
-        Phone phone = mApp.mCM.getDefaultPhone();
-        if (TelephonyCapabilities.supportsOtasp(phone)) {
-            checkForOtaspCall(intent);
-        }
-
         CallStatusCode status = placeCallInternal(intent);
 
         switch (status) {
@@ -670,28 +661,6 @@
         mApp.startActivity(intent);
     }
 
-    /**
-     * Checks the current outgoing call to see if it's an OTASP call (the
-     * "activation" call used to provision CDMA devices).  If so, do any
-     * necessary OTASP-specific setup before actually placing the call.
-     */
-    private void checkForOtaspCall(Intent intent) {
-        if (OtaUtils.isOtaspCallIntent(intent)) {
-            Log.i(TAG, "checkForOtaspCall: handling OTASP intent! " + intent);
-
-            // ("OTASP-specific setup" basically means creating and initializing
-            // the OtaUtils instance.  Note that this setup needs to be here in
-            // the CallController.placeCall() sequence, *not* in
-            // OtaUtils.startInteractiveOtasp(), since it's also possible to
-            // start an OTASP call by manually dialing "*228" (in which case
-            // OtaUtils.startInteractiveOtasp() never gets run at all.)
-            OtaUtils.setupOtaspCall(intent);
-        } else {
-            if (DBG) log("checkForOtaspCall: not an OTASP call.");
-        }
-    }
-
-
     //
     // Debugging
     //
diff --git a/src/com/android/phone/CallNotifier.java b/src/com/android/phone/CallNotifier.java
index 7836248..b3d8ade 100644
--- a/src/com/android/phone/CallNotifier.java
+++ b/src/com/android/phone/CallNotifier.java
@@ -16,12 +16,10 @@
 
 package com.android.phone;
 
-import com.android.internal.telephony.Call;
 import com.android.internal.telephony.CallManager;
-import com.android.internal.telephony.Connection;
+
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.TelephonyCapabilities;
 import com.android.internal.telephony.cdma.CdmaInformationRecords.CdmaDisplayInfoRec;
 import com.android.internal.telephony.cdma.CdmaInformationRecords.CdmaSignalInfoRec;
 import com.android.internal.telephony.cdma.SignalToneUtil;
@@ -30,17 +28,14 @@
 import android.bluetooth.BluetoothHeadset;
 import android.bluetooth.BluetoothProfile;
 import android.content.Context;
-import android.media.AudioAttributes;
 import android.media.AudioManager;
 import android.media.ToneGenerator;
 import android.os.AsyncResult;
 import android.os.Handler;
 import android.os.Message;
 import android.os.SystemProperties;
-import android.provider.Settings;
 import android.telecom.TelecomManager;
-import android.telephony.DisconnectCause;
-import android.telephony.PhoneNumberUtils;
+
 import android.telephony.PhoneStateListener;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
@@ -103,8 +98,6 @@
     // We should store all the possible event type values in one place to make sure that
     // they don't step on each others' toes.
     public static final int INTERNAL_SHOW_MESSAGE_NOTIFICATION_DONE = 22;
-    // Other events from call manager
-    public static final int EVENT_OTA_PROVISION_CHANGE = 20;
 
     /**
      * Initialize the singleton CallNotifier instance.
@@ -177,7 +170,6 @@
      */
     private void registerForNotifications() {
         mCM.registerForDisconnect(this, PHONE_DISCONNECT, null);
-        mCM.registerForCdmaOtaStatusChange(this, EVENT_OTA_PROVISION_CHANGE, null);
         mCM.registerForDisplayInfo(this, PHONE_STATE_DISPLAYINFO, null);
         mCM.registerForSignalInfo(this, PHONE_STATE_SIGNALINFO, null);
         mCM.registerForInCallVoicePrivacyOn(this, PHONE_ENHANCED_VP_ON, null);
@@ -214,11 +206,6 @@
                 PhoneDisplayMessage.dismissMessage();
                 break;
 
-            case EVENT_OTA_PROVISION_CHANGE:
-                if (DBG) log("EVENT_OTA_PROVISION_CHANGE...");
-                mApplication.handleOtaspEvent(msg);
-                break;
-
             case PHONE_ENHANCED_VP_ON:
                 if (DBG) log("PHONE_ENHANCED_VP_ON...");
                 if (!mVoicePrivacyState) {
@@ -375,18 +362,6 @@
                     toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
                     toneLengthMillis = 200;
                     break;
-                 case TONE_OTA_CALL_END:
-                    if (mApplication.cdmaOtaConfigData.otaPlaySuccessFailureTone ==
-                            OtaUtils.OTA_PLAY_SUCCESS_FAILURE_TONE_ON) {
-                        toneType = ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD;
-                        toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
-                        toneLengthMillis = 750;
-                    } else {
-                        toneType = ToneGenerator.TONE_PROP_PROMPT;
-                        toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
-                        toneLengthMillis = 200;
-                    }
-                    break;
                 case TONE_VOICE_PRIVACY:
                     toneType = ToneGenerator.TONE_CDMA_ALERT_NETWORK_LITE;
                     toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
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/InCallScreenShowActivation.java b/src/com/android/phone/InCallScreenShowActivation.java
deleted file mode 100644
index 78cc20b..0000000
--- a/src/com/android/phone/InCallScreenShowActivation.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone;
-
-import android.app.Activity;
-import android.app.PendingIntent;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.PersistableBundle;
-import android.os.SystemProperties;
-import android.telephony.CarrierConfigManager;
-import android.util.Log;
-
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.TelephonyCapabilities;
-
-/**
- * Invisible activity that handles the com.android.phone.PERFORM_CDMA_PROVISIONING intent.
- * This activity is protected by the android.permission.PERFORM_CDMA_PROVISIONING permission.
- *
- * We handle the PERFORM_CDMA_PROVISIONING action by launching an OTASP
- * call via one of the OtaUtils helper methods: startInteractiveOtasp() on
- * regular phones, or startNonInteractiveOtasp() on data-only devices.
- *
- * TODO: The class name InCallScreenShowActivation is misleading, since
- * this activity is totally unrelated to the InCallScreen (which
- * implements the in-call UI.)  Let's eventually rename this to something
- * like CdmaProvisioningLauncher or CdmaProvisioningHandler...
- */
-public class InCallScreenShowActivation extends Activity {
-    private static final String LOG_TAG = "InCallScreenShowActivation";
-    private static final boolean DBG =
-            (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
-
-    @Override
-    protected void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
-
-        Intent intent = getIntent();
-        if (DBG) Log.d(LOG_TAG, "onCreate: intent = " + intent);
-        Bundle extras = intent.getExtras();
-        if (DBG && (extras != null)) {
-            Log.d(LOG_TAG, "      - has extras: size = " + extras.size()); // forces an unparcel()
-            Log.d(LOG_TAG, "      - extras = " + extras);
-        }
-
-        PhoneGlobals app = PhoneGlobals.getInstanceIfPrimary();
-        if (app == null) {
-            // TODO: All CDMA provisioning code should move into a BroadcastReceiver that runs
-            // exclusively in the primary user's context.  This is because the majority of the
-            // telephony logic -- and all of the important bits -- runs only as primary so we don't
-            // have access to the things we need. We still need to maintain an Activity to support
-            // legacy code which starts this using startActivity() but that Activity should be a
-            // simple intent-trampoline for the new BroadcastReceiver.
-            //
-            // Though this conditional protects this code from NPEs on a secondary user due to an
-            // uninitialized PhoneGlobals, there's not a good reason at the time of this writing as
-            // to why a secondary user context shouldn't trigger a CDMA provisioning, or at least
-            // nobody has expressed concern.
-            Log.i(LOG_TAG, "Being asked to provision CDMA SIM from secondary user, skipping.");
-            setResult(RESULT_CANCELED);
-            finish();
-            return;
-        }
-
-        Phone phone = app.getPhone();
-        if (!TelephonyCapabilities.supportsOtasp(phone)) {
-            Log.w(LOG_TAG, "CDMA Provisioning not supported on this device");
-            setResult(RESULT_CANCELED);
-            finish();
-            return;
-        }
-
-        if (intent.getAction().equals(OtaUtils.ACTION_PERFORM_CDMA_PROVISIONING)) {
-
-            PersistableBundle carrierConfig = app.getCarrierConfig();
-
-            boolean usesOtasp = carrierConfig.getBoolean(
-                    CarrierConfigManager.KEY_USE_OTASP_FOR_PROVISIONING_BOOL);
-            if (usesOtasp) {
-                // On voice-capable devices, we perform CDMA provisioning in
-                // "interactive" mode by directly launching the InCallScreen.
-                // boolean interactiveMode = PhoneGlobals.sVoiceCapable;
-                // TODO: Renable interactive mode for device provisioning.
-                boolean interactiveMode = false;
-                Log.i(LOG_TAG, "ACTION_PERFORM_CDMA_PROVISIONING (interactiveMode = "
-                      + interactiveMode + ")...");
-
-                // Testing: this intent extra allows test apps manually
-                // enable/disable "interactive mode", regardless of whether
-                // the current device is voice-capable.  This is allowed only
-                // in userdebug or eng builds.
-                if (intent.hasExtra(OtaUtils.EXTRA_OVERRIDE_INTERACTIVE_MODE)
-                        && (SystemProperties.getInt("ro.debuggable", 0) == 1)) {
-                    interactiveMode =
-                            intent.getBooleanExtra(OtaUtils.EXTRA_OVERRIDE_INTERACTIVE_MODE, false);
-                    Log.d(LOG_TAG, "==> MANUALLY OVERRIDING interactiveMode to " + interactiveMode);
-                }
-
-                // We allow the caller to pass a PendingIntent (as the
-                // EXTRA_NONINTERACTIVE_OTASP_RESULT_PENDING_INTENT extra)
-                // which we'll later use to notify them when the OTASP call
-                // fails or succeeds.
-                //
-                // Stash that away here, and we'll fire it off later in
-                // OtaUtils.sendOtaspResult().
-                app.cdmaOtaScreenState.otaspResultCodePendingIntent =
-                            (PendingIntent) intent.getParcelableExtra(
-                                    OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT);
-
-                if (interactiveMode) {
-                    // On voice-capable devices, launch an OTASP call and arrange
-                    // for the in-call UI to come up.  (The InCallScreen will
-                    // notice that an OTASP call is active, and display the
-                    // special OTASP UI instead of the usual in-call controls.)
-
-                    if (DBG) Log.d(LOG_TAG, "==> Starting interactive CDMA provisioning...");
-                    OtaUtils.startInteractiveOtasp(this);
-
-                    // The result we set here is actually irrelevant, since the
-                    // InCallScreen's "interactive" OTASP sequence never actually
-                    // finish()es; it ends by directly launching the Home
-                    // activity.  So our caller won't actually ever get an
-                    // onActivityResult() call in this case.
-                    setResult(OtaUtils.RESULT_INTERACTIVE_OTASP_STARTED);
-                } else {
-                    // On data-only devices, manually launch the OTASP call
-                    // *without* displaying any UI.  (Our caller, presumably
-                    // SetupWizardActivity, is responsible for displaying some
-                    // sort of progress UI.)
-
-                    if (DBG) Log.d(LOG_TAG, "==> Starting non-interactive CDMA provisioning...");
-                    int callStatus = OtaUtils.startNonInteractiveOtasp(this);
-
-                    if (callStatus == PhoneUtils.CALL_STATUS_DIALED) {
-                        if (DBG) Log.d(LOG_TAG,
-                                "  ==> successful result from startNonInteractiveOtasp(): " +
-                                callStatus);
-                        setResult(OtaUtils.RESULT_NONINTERACTIVE_OTASP_STARTED);
-                    } else {
-                        Log.w(LOG_TAG, "Failure code from startNonInteractiveOtasp(): " +
-                                callStatus);
-                        setResult(OtaUtils.RESULT_NONINTERACTIVE_OTASP_FAILED);
-                    }
-                }
-            } else {
-                Log.i(LOG_TAG, "Skipping activation.");
-            }
-        } else {
-            Log.e(LOG_TAG, "Unexpected intent action: " + intent);
-            setResult(RESULT_CANCELED);
-        }
-
-        finish();
-    }
-}
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/OtaStartupReceiver.java b/src/com/android/phone/OtaStartupReceiver.java
deleted file mode 100644
index 09cb185..0000000
--- a/src/com/android/phone/OtaStartupReceiver.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.os.AsyncResult;
-import android.os.Handler;
-import android.os.Message;
-import android.os.SystemProperties;
-import android.provider.Settings;
-import android.telephony.PhoneStateListener;
-import android.telephony.ServiceState;
-import android.telephony.TelephonyManager;
-
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.ServiceStateTracker;
-import com.android.internal.telephony.TelephonyCapabilities;
-
-import android.util.Log;
-
-/*
- * Handles OTA Start procedure at phone power up. At phone power up, if phone is not OTA
- * provisioned (check MIN value of the Phone) and 'device_provisioned' is not set,
- * OTA Activation screen is shown that helps user activate the phone
- */
-public class OtaStartupReceiver extends BroadcastReceiver {
-    private static final String TAG = "OtaStartupReceiver";
-    private static final boolean DBG = false;
-    private static final int MIN_READY = 10;
-    private static final int SERVICE_STATE_CHANGED = 11;
-    private Context mContext;
-
-    private int mOtaspMode = -1;
-    private boolean mPhoneStateListenerRegistered = false;
-    private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
-        @Override
-        public void onOtaspChanged(int otaspMode) {
-            if (mOtaspMode == otaspMode) {
-                return;
-            }
-            mOtaspMode = otaspMode;
-            Log.v(TAG, "onOtaspChanged: mOtaspMode=" + mOtaspMode);
-
-            if (otaspMode == ServiceStateTracker.OTASP_NEEDED) {
-                Log.i(TAG, "OTASP is needed - performing CDMA provisioning");
-                final Intent intent = new Intent(OtaUtils.ACTION_PERFORM_CDMA_PROVISIONING);
-                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                mContext.startActivity(intent);
-            }
-        }
-    };
-
-
-    private Handler mHandler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MIN_READY:
-                    Log.v(TAG, "Attempting OtaActivation from handler, mOtaspMode=" + mOtaspMode);
-                    OtaUtils.maybeDoOtaCall(mContext, mHandler, MIN_READY);
-                    break;
-                case SERVICE_STATE_CHANGED: {
-                    ServiceState state = (ServiceState) ((AsyncResult) msg.obj).result;
-                    if (DBG) Log.d(TAG, "onServiceStateChanged()...  new state = " + state);
-
-                    // Possible service states:
-                    // - STATE_IN_SERVICE        // Normal operation
-                    // - STATE_OUT_OF_SERVICE    // Still searching for an operator to register to,
-                    //                           // or no radio signal
-                    // - STATE_EMERGENCY_ONLY    // Phone is locked; only emergency numbers are allowed
-                    // - STATE_POWER_OFF         // Radio is explicitly powered off (airplane mode)
-
-                    // Once we reach STATE_IN_SERVICE
-                    // it's finally OK to start OTA provisioning
-                    if (state.getState() == ServiceState.STATE_IN_SERVICE) {
-                        if (DBG) Log.d(TAG, "call OtaUtils.maybeDoOtaCall after network is available");
-                        Phone phone = PhoneGlobals.getPhone();
-                        phone.unregisterForServiceStateChanged(this);
-                        OtaUtils.maybeDoOtaCall(mContext, mHandler, MIN_READY);
-                    }
-                    break;
-                }
-            }
-
-        }
-    };
-
-    @Override
-    public void onReceive(Context context, Intent intent) {
-        mContext = context;
-        if (DBG) {
-            Log.v(TAG, "onReceive: intent action=" + intent.getAction() +
-                    "  mOtaspMode=" + mOtaspMode);
-        }
-
-        PhoneGlobals globals = PhoneGlobals.getInstanceIfPrimary();
-        if (globals == null) {
-            if (DBG) Log.d(TAG, "Not primary user, nothing to do.");
-            return;
-        }
-
-        if (mPhoneStateListenerRegistered == false) {
-            if (DBG) Log.d(TAG, "Register our PhoneStateListener");
-            TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(
-                    Context.TELEPHONY_SERVICE);
-            telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_OTASP_CHANGED);
-            mPhoneStateListenerRegistered = true;
-        } else {
-            if (DBG) Log.d(TAG, "PhoneStateListener already registered");
-        }
-
-        if (!TelephonyCapabilities.supportsOtasp(PhoneGlobals.getPhone())) {
-            if (DBG) Log.d(TAG, "OTASP not supported, nothing to do.");
-            return;
-        }
-
-        if (shouldPostpone(context)) {
-            if (DBG) Log.d(TAG, "Postponing OTASP until wizard runs");
-            return;
-        }
-
-        // Delay OTA provisioning if network is not available yet
-        PhoneGlobals app = PhoneGlobals.getInstance();
-        Phone phone = PhoneGlobals.getPhone();
-        if (app.mCM.getServiceState() != ServiceState.STATE_IN_SERVICE) {
-            if (DBG) Log.w(TAG, "Network is not ready. Registering to receive notification.");
-            phone.registerForServiceStateChanged(mHandler, SERVICE_STATE_CHANGED, null);
-            return;
-        }
-
-        // The following depends on the phone process being persistent. Normally we can't
-        // expect a BroadcastReceiver to persist after returning from this function but it does
-        // because the phone activity is persistent.
-        if (DBG) Log.d(TAG, "call OtaUtils.maybeDoOtaCall");
-        OtaUtils.maybeDoOtaCall(mContext, mHandler, MIN_READY);
-    }
-
-    /**
-     * On devices that provide a phone initialization wizard (such as Google Setup Wizard), we
-     * allow delaying CDMA OTA setup so it can be done in a single wizard. The wizard is responsible
-     * for (1) disabling itself once it has been run and/or (2) setting the 'device_provisioned'
-     * flag to something non-zero and (3) calling the OTA Setup with the action below.
-     *
-     * NB: Typical phone initialization wizards will install themselves as the homescreen
-     * (category "android.intent.category.HOME") with a priority higher than the default.
-     * The wizard should set 'device_provisioned' when it completes, disable itself with the
-     * PackageManager.setComponentEnabledSetting() and then start home screen.
-     *
-     * @return true if setup will be handled by wizard, false if it should be done now.
-     */
-    private boolean shouldPostpone(Context context) {
-        Intent intent = new Intent("android.intent.action.DEVICE_INITIALIZATION_WIZARD");
-        ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent,
-                PackageManager.MATCH_DEFAULT_ONLY);
-        boolean provisioned = Settings.Global.getInt(context.getContentResolver(),
-                Settings.Global.DEVICE_PROVISIONED, 0) != 0;
-        String mode = SystemProperties.get("ro.setupwizard.mode", "REQUIRED");
-        boolean runningSetupWizard = "REQUIRED".equals(mode) || "OPTIONAL".equals(mode);
-        if (DBG) {
-            Log.v(TAG, "resolvInfo = " + resolveInfo + ", provisioned = " + provisioned
-                    + ", runningSetupWizard = " + runningSetupWizard);
-        }
-        return resolveInfo != null && !provisioned && runningSetupWizard;
-    }
-}
diff --git a/src/com/android/phone/OtaUtils.java b/src/com/android/phone/OtaUtils.java
deleted file mode 100644
index b1b0049..0000000
--- a/src/com/android/phone/OtaUtils.java
+++ /dev/null
@@ -1,1585 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone;
-
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.TelephonyCapabilities;
-import com.android.internal.telephony.TelephonyProperties;
-import com.android.phone.OtaUtils.CdmaOtaInCallScreenUiState.State;
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.AlertDialog;
-import android.app.PendingIntent;
-import android.app.PendingIntent.CanceledException;
-import android.content.ActivityNotFoundException;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.AsyncResult;
-import android.os.Handler;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.UserHandle;
-import android.telecom.PhoneAccount;
-import android.telephony.TelephonyManager;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.widget.Button;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-import android.widget.ToggleButton;
-
-/**
- * Handles all OTASP Call related logic and UI functionality.
- * The InCallScreen interacts with this class to perform an OTASP Call.
- *
- * OTASP is a CDMA-specific feature:
- *   OTA or OTASP == Over The Air service provisioning
- *   SPC == Service Programming Code
- *   TODO: Include pointer to more detailed documentation.
- *
- * TODO: This is Over The Air Service Provisioning (OTASP)
- *       A better name would be OtaspUtils.java.
- */
-public class OtaUtils {
-    private static final String LOG_TAG = "OtaUtils";
-    private static final boolean DBG = false;
-
-    public static final int OTA_SHOW_ACTIVATION_SCREEN_OFF = 0;
-    public static final int OTA_SHOW_ACTIVATION_SCREEN_ON = 1;
-    public static final int OTA_SHOW_LISTENING_SCREEN_OFF =0;
-    public static final int OTA_SHOW_LISTENING_SCREEN_ON =1;
-    public static final int OTA_SHOW_ACTIVATE_FAIL_COUNT_OFF = 0;
-    public static final int OTA_SHOW_ACTIVATE_FAIL_COUNT_THREE = 3;
-    public static final int OTA_PLAY_SUCCESS_FAILURE_TONE_OFF = 0;
-    public static final int OTA_PLAY_SUCCESS_FAILURE_TONE_ON = 1;
-
-    // SPC Timeout is 60 seconds
-    public final int OTA_SPC_TIMEOUT = 60;
-    public final int OTA_FAILURE_DIALOG_TIMEOUT = 2;
-
-    // Constants for OTASP-related Intents and intent extras.
-    // Watch out: these must agree with the corresponding constants in
-    // apps/SetupWizard!
-
-    // Intent action to launch an OTASP call.
-    public static final String ACTION_PERFORM_CDMA_PROVISIONING =
-           "com.android.phone.PERFORM_CDMA_PROVISIONING";
-
-    // Intent action to launch activation on a non-voice capable device
-    /**
-     * @deprecated platform no longer supports voiceless cdma provisioning,
-     * only hands free activation.
-     */
-    public static final String ACTION_PERFORM_VOICELESS_CDMA_PROVISIONING =
-            "com.android.phone.PERFORM_VOICELESS_CDMA_PROVISIONING";
-
-    // Intent action to display the InCallScreen in the OTASP "activation" state.
-    public static final String ACTION_DISPLAY_ACTIVATION_SCREEN =
-            "com.android.phone.DISPLAY_ACTIVATION_SCREEN";
-
-    // boolean voiceless provisioning extra that enables a "don't show this again" checkbox
-    // the user can check to never see the activity upon bootup again
-    public static final String EXTRA_VOICELESS_PROVISIONING_OFFER_DONTSHOW =
-            "com.android.phone.VOICELESS_PROVISIONING_OFFER_DONTSHOW";
-
-    // Activity result codes for the ACTION_PERFORM_CDMA_PROVISIONING intent
-    // (see the InCallScreenShowActivation activity.)
-    //
-    // Note: currently, our caller won't ever actually receive the
-    // RESULT_INTERACTIVE_OTASP_STARTED result code; see comments in
-    // InCallScreenShowActivation.onCreate() for details.
-
-    public static final int RESULT_INTERACTIVE_OTASP_STARTED = Activity.RESULT_FIRST_USER;
-    public static final int RESULT_NONINTERACTIVE_OTASP_STARTED = Activity.RESULT_FIRST_USER + 1;
-    public static final int RESULT_NONINTERACTIVE_OTASP_FAILED = Activity.RESULT_FIRST_USER + 2;
-
-    // Testing: Extra for the ACTION_PERFORM_CDMA_PROVISIONING intent that
-    // allows the caller to manually enable/disable "interactive mode" for
-    // the OTASP call.   Only available in userdebug or eng builds.
-    public static final String EXTRA_OVERRIDE_INTERACTIVE_MODE =
-            "ota_override_interactive_mode";
-
-    // Extra for the ACTION_PERFORM_CDMA_PROVISIONING intent, holding a
-    // PendingIntent which the phone app can use to send a result code
-    // back to the caller.
-    public static final String EXTRA_OTASP_RESULT_CODE_PENDING_INTENT =
-            "otasp_result_code_pending_intent";
-
-    // Extra attached to the above PendingIntent that indicates
-    // success or failure.
-    public static final String EXTRA_OTASP_RESULT_CODE = "otasp_result_code";
-
-    // Extra attached to the above PendingIntent that contains an error code.
-    public static final String EXTRA_OTASP_ERROR_CODE = "otasp_error_code";
-
-    public static final int OTASP_UNKNOWN = 0;
-    public static final int OTASP_USER_SKIPPED = 1;  // Only meaningful with interactive OTASP
-    public static final int OTASP_SUCCESS = 2;
-    public static final int OTASP_FAILURE = 3;
-    // failed due to CDMA_OTA_PROVISION_STATUS_SPC_RETRIES_EXCEEDED
-    public static final int OTASP_FAILURE_SPC_RETRIES = 4;
-    // TODO: Distinguish between interactive and non-interactive success
-    // and failure.  Then, have the PendingIntent be sent after
-    // interactive OTASP as well (so the caller can find out definitively
-    // when interactive OTASP completes.)
-
-    private static final String OTASP_NUMBER = "*228";
-    private static final String OTASP_NUMBER_NON_INTERACTIVE = "*22899";
-
-    private Context mContext;
-    private PhoneGlobals mApplication;
-    private OtaWidgetData mOtaWidgetData;
-
-    private static boolean sIsWizardMode = true;
-
-    // How many times do we retry maybeDoOtaCall() if the LTE state is not known yet,
-    // and how long do we wait between retries
-    private static final int OTA_CALL_LTE_RETRIES_MAX = 5;
-    private static final int OTA_CALL_LTE_RETRY_PERIOD = 3000;
-    private static int sOtaCallLteRetries = 0;
-
-    // In "interactive mode", the OtaUtils object is tied to an
-    // InCallScreen instance, where we display a bunch of UI specific to
-    // the OTASP call.  But on devices that are not "voice capable", the
-    // OTASP call runs in a non-interactive mode, and we don't have
-    // an InCallScreen or CallCard or any OTASP UI elements at all.
-    private boolean mInteractive = true;
-
-    /**
-     * OtaWidgetData class represent all OTA UI elements
-     *
-     * TODO(OTASP): It's really ugly for the OtaUtils object to reach into the
-     *     InCallScreen like this and directly manipulate its widgets.
-     *
-     *     Instead, the model/view separation should be more clear: OtaUtils
-     *     should only know about a higher-level abstraction of the
-     *     OTASP-specific UI state (just like how the CallController uses the
-     *     InCallUiState object), and the InCallScreen itself should translate
-     *     that higher-level abstraction into actual onscreen views and widgets.
-     */
-    private class OtaWidgetData {
-        public Button otaEndButton;
-        public Button otaActivateButton;
-        public Button otaSkipButton;
-        public Button otaNextButton;
-        public ToggleButton otaSpeakerButton;
-        public ViewGroup otaUpperWidgets;
-        public View callCardOtaButtonsFailSuccess;
-        public ProgressBar otaTextProgressBar;
-        public TextView otaTextSuccessFail;
-        public View callCardOtaButtonsActivate;
-        public View callCardOtaButtonsListenProgress;
-        public TextView otaTextActivate;
-        public TextView otaTextListenProgress;
-        public AlertDialog spcErrorDialog;
-        public AlertDialog otaFailureDialog;
-        public AlertDialog otaSkipConfirmationDialog;
-        public TextView otaTitle;
-        public Button otaTryAgainButton;
-    }
-
-    /**
-     * OtaUtils constructor.
-     *
-     * @param context the Context of the calling Activity or Application
-     * @param interactive if true, use the InCallScreen to display the progress
-     *                    and result of the OTASP call.  In practice this is
-     *                    true IFF the current device is a voice-capable phone.
-     *
-     * Note if interactive is true, you must also call updateUiWidgets() as soon
-     * as the InCallScreen instance is ready.
-     */
-    public OtaUtils(Context context, boolean interactive) {
-        if (DBG) log("OtaUtils constructor...");
-        mApplication = PhoneGlobals.getInstance();
-        mContext = context;
-        mInteractive = interactive;
-    }
-
-    /**
-     * Starts the OTA provisioning call.  If the MIN isn't available yet, it returns false and adds
-     * an event to return the request to the calling app when it becomes available.
-     *
-     * @param context
-     * @param handler
-     * @param request
-     * @return true if we were able to launch Ota activity or it's not required; false otherwise
-     */
-    public static boolean maybeDoOtaCall(Context context, Handler handler, int request) {
-        PhoneGlobals app = PhoneGlobals.getInstance();
-        Phone phone = PhoneGlobals.getPhone();
-
-        if (ActivityManager.isRunningInTestHarness()) {
-            Log.i(LOG_TAG, "Don't run provisioning when in test harness");
-            return true;
-        }
-
-        if (!TelephonyCapabilities.supportsOtasp(phone)) {
-            // Presumably not a CDMA phone.
-            if (DBG) log("maybeDoOtaCall: OTASP not supported on this device");
-            return true;  // Nothing to do here.
-        }
-
-        if (!phone.isMinInfoReady()) {
-            if (DBG) log("MIN is not ready. Registering to receive notification.");
-            phone.registerForSubscriptionInfoReady(handler, request, null);
-            return false;
-        }
-        phone.unregisterForSubscriptionInfoReady(handler);
-
-        if (getLteOnCdmaMode(context) == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
-            if (sOtaCallLteRetries < OTA_CALL_LTE_RETRIES_MAX) {
-                if (DBG) log("maybeDoOtaCall: LTE state still unknown: retrying");
-                handler.sendEmptyMessageDelayed(request, OTA_CALL_LTE_RETRY_PERIOD);
-                sOtaCallLteRetries++;
-                return false;
-            } else {
-                Log.w(LOG_TAG, "maybeDoOtaCall: LTE state still unknown: giving up");
-                return true;
-            }
-        }
-
-        boolean phoneNeedsActivation = phone.needsOtaServiceProvisioning();
-        if (DBG) log("phoneNeedsActivation is set to " + phoneNeedsActivation);
-
-        int otaShowActivationScreen = context.getResources().getInteger(
-                R.integer.OtaShowActivationScreen);
-        if (DBG) log("otaShowActivationScreen: " + otaShowActivationScreen);
-
-        // Run the OTASP call in "interactive" mode only if
-        // this is a non-LTE "voice capable" device.
-        if (PhoneGlobals.sVoiceCapable && getLteOnCdmaMode(context) == PhoneConstants.LTE_ON_CDMA_FALSE) {
-            if (phoneNeedsActivation
-                    && (otaShowActivationScreen == OTA_SHOW_ACTIVATION_SCREEN_ON)) {
-                app.cdmaOtaProvisionData.isOtaCallIntentProcessed = false;
-                sIsWizardMode = false;
-
-                if (DBG) Log.d(LOG_TAG, "==> Starting interactive CDMA provisioning...");
-                OtaUtils.startInteractiveOtasp(context);
-
-                if (DBG) log("maybeDoOtaCall: voice capable; activation started.");
-            } else {
-                if (DBG) log("maybeDoOtaCall: voice capable; activation NOT started.");
-            }
-        } else {
-            if (phoneNeedsActivation) {
-                app.cdmaOtaProvisionData.isOtaCallIntentProcessed = false;
-                Intent newIntent = new Intent(ACTION_PERFORM_VOICELESS_CDMA_PROVISIONING);
-                newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                newIntent.putExtra(EXTRA_VOICELESS_PROVISIONING_OFFER_DONTSHOW, true);
-                try {
-                    context.startActivity(newIntent);
-                } catch (ActivityNotFoundException e) {
-                    loge("No activity Handling PERFORM_VOICELESS_CDMA_PROVISIONING!");
-                    return false;
-                }
-                if (DBG) log("maybeDoOtaCall: non-interactive; activation intent sent.");
-            } else {
-                if (DBG) log("maybeDoOtaCall: non-interactive, no need for OTASP.");
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Starts a normal "interactive" OTASP call (i.e. CDMA activation
-     * for regular voice-capable phone devices.)
-     *
-     * This method is called from the InCallScreenShowActivation activity when
-     * handling the ACTION_PERFORM_CDMA_PROVISIONING intent.
-     */
-    public static void startInteractiveOtasp(Context context) {
-        if (DBG) log("startInteractiveOtasp()...");
-        PhoneGlobals app = PhoneGlobals.getInstance();
-
-        // There are two ways to start OTASP on voice-capable devices:
-        //
-        // (1) via the PERFORM_CDMA_PROVISIONING intent
-        //     - this is triggered by the "Activate device" button in settings,
-        //       or can be launched automatically upon boot if the device
-        //       thinks it needs to be provisioned.
-        //     - the intent is handled by InCallScreenShowActivation.onCreate(),
-        //       which calls this method
-        //     - we prepare for OTASP by initializing the OtaUtils object
-        //     - we bring up the InCallScreen in the ready-to-activate state
-        //     - when the user presses the "Activate" button we launch the
-        //       call by calling CallController.placeCall() via the
-        //       otaPerformActivation() method.
-        //
-        // (2) by manually making an outgoing call to a special OTASP number
-        //     like "*228" or "*22899".
-        //     - That sequence does NOT involve this method (OtaUtils.startInteractiveOtasp()).
-        //       Instead, the outgoing call request goes straight to CallController.placeCall().
-        //     - CallController.placeCall() notices that it's an OTASP
-        //       call, and initializes the OtaUtils object.
-        //     - The InCallScreen is launched (as the last step of
-        //       CallController.placeCall()).  The InCallScreen notices that
-        //       OTASP is active and shows the correct UI.
-
-        // Here, we start sequence (1):
-        // Do NOT immediately start the call.  Instead, bring up the InCallScreen
-        // in the special "activate" state (see OtaUtils.otaShowActivateScreen()).
-        // We won't actually make the call until the user presses the "Activate"
-        // button.
-
-        Intent activationScreenIntent = new Intent().setClass(context, InCallScreen.class)
-                .setAction(ACTION_DISPLAY_ACTIVATION_SCREEN);
-
-        // Watch out: in the scenario where OTASP gets triggered from the
-        // BOOT_COMPLETED broadcast (see OtaStartupReceiver.java), we might be
-        // running in the PhoneApp's context right now.
-        // So the FLAG_ACTIVITY_NEW_TASK flag is required here.
-        activationScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-        // We're about to start the OTASP sequence, so create and initialize the
-        // OtaUtils instance.  (This needs to happen before bringing up the
-        // InCallScreen.)
-        OtaUtils.setupOtaspCall(activationScreenIntent);
-
-        // And bring up the InCallScreen...
-        Log.i(LOG_TAG, "startInteractiveOtasp: launching InCallScreen in 'activate' state: "
-              + activationScreenIntent);
-        context.startActivity(activationScreenIntent);
-    }
-
-    /**
-     * Starts the OTASP call *without* involving the InCallScreen or
-     * displaying any UI.
-     *
-     * This is used on data-only devices, which don't support any kind of
-     * in-call phone UI.
-     *
-     * @return PhoneUtils.CALL_STATUS_DIALED if we successfully
-     *         dialed the OTASP number, or one of the other
-     *         CALL_STATUS_* constants if there was a failure.
-     */
-    public static int startNonInteractiveOtasp(Context context) {
-        if (DBG) log("startNonInteractiveOtasp()...");
-        PhoneGlobals app = PhoneGlobals.getInstance();
-
-        if (app.otaUtils != null) {
-            // An OtaUtils instance already exists, presumably from a previous OTASP call.
-            Log.i(LOG_TAG, "startNonInteractiveOtasp: "
-                  + "OtaUtils already exists; nuking the old one and starting again...");
-        }
-
-        // Create the OtaUtils instance.
-        app.otaUtils = new OtaUtils(context, false /* non-interactive mode */);
-        if (DBG) log("- created OtaUtils: " + app.otaUtils);
-
-        // ... and kick off the OTASP call.
-        // TODO(InCallScreen redesign): This should probably go through
-        // the CallController, rather than directly calling
-        // PhoneUtils.placeCall().
-        Phone phone = PhoneGlobals.getPhone();
-        String number = OTASP_NUMBER_NON_INTERACTIVE;
-        Log.i(LOG_TAG, "startNonInteractiveOtasp: placing call to '" + number + "'...");
-        int callStatus = PhoneUtils.placeCall(context,
-                                              phone,
-                                              number,
-                                              null,   // contactRef
-                                              false); //isEmergencyCall
-
-        if (callStatus == PhoneUtils.CALL_STATUS_DIALED) {
-            if (DBG) log("  ==> successful return from placeCall(): callStatus = " + callStatus);
-        } else {
-            Log.w(LOG_TAG, "Failure from placeCall() for OTA number '"
-                  + number + "': code " + callStatus);
-            return callStatus;
-        }
-
-        // TODO: Any other special work to do here?
-        // Such as:
-        //
-        // - manually kick off progress updates, either using TelephonyRegistry
-        //   or else by sending PendingIntents directly to our caller?
-        //
-        // - manually silence the in-call audio?  (Probably unnecessary
-        //   if Stingray truly has no audio path from phone baseband
-        //   to the device's speakers.)
-        //
-
-        return callStatus;
-    }
-
-    /**
-     * @return true if the specified Intent is a CALL action that's an attempt
-     * to initate an OTASP call.
-     *
-     * OTASP is a CDMA-specific concept, so this method will always return false
-     * on GSM phones.
-     *
-     * This code was originally part of the InCallScreen.checkIsOtaCall() method.
-     */
-    public static boolean isOtaspCallIntent(Intent intent) {
-        if (DBG) log("isOtaspCallIntent(" + intent + ")...");
-        PhoneGlobals app = PhoneGlobals.getInstance();
-        Phone phone = app.mCM.getDefaultPhone();
-
-        if (intent == null) {
-            return false;
-        }
-        if (!TelephonyCapabilities.supportsOtasp(phone)) {
-            return false;
-        }
-
-        String action = intent.getAction();
-        if (action == null) {
-            return false;
-        }
-        if (!action.equals(Intent.ACTION_CALL)) {
-            if (DBG) log("isOtaspCallIntent: not a CALL action: '" + action + "' ==> not OTASP");
-            return false;
-        }
-
-        if ((app.cdmaOtaScreenState == null) || (app.cdmaOtaProvisionData == null)) {
-            // Uh oh -- something wrong with our internal OTASP state.
-            // (Since this is an OTASP-capable device, these objects
-            // *should* have already been created by PhoneApp.onCreate().)
-            throw new IllegalStateException("isOtaspCallIntent: "
-                                            + "app.cdmaOta* objects(s) not initialized");
-        }
-
-        // This is an OTASP call iff the number we're trying to dial is one of
-        // the magic OTASP numbers.
-        String number;
-        try {
-            number = PhoneUtils.getInitialNumber(intent);
-        } catch (PhoneUtils.VoiceMailNumberMissingException ex) {
-            // This was presumably a "voicemail:" intent, so it's
-            // obviously not an OTASP number.
-            if (DBG) log("isOtaspCallIntent: VoiceMailNumberMissingException => not OTASP");
-            return false;
-        }
-        if (phone.isOtaSpNumber(number)) {
-            if (DBG) log("isOtaSpNumber: ACTION_CALL to '" + number + "' ==> OTASP call!");
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * Set up for an OTASP call.
-     *
-     * This method is called as part of the CallController placeCall() sequence
-     * before initiating an outgoing OTASP call.
-     *
-     * The purpose of this method is mainly to create and initialize the
-     * OtaUtils instance, along with some other misc pre-OTASP cleanup.
-     */
-    public static void setupOtaspCall(Intent intent) {
-        if (DBG) log("setupOtaspCall(): preparing for OTASP call to " + intent);
-        PhoneGlobals app = PhoneGlobals.getInstance();
-
-        if (app.otaUtils != null) {
-            // An OtaUtils instance already exists, presumably from a prior OTASP call.
-            // Nuke the old one and start this call with a fresh instance.
-            Log.i(LOG_TAG, "setupOtaspCall: "
-                  + "OtaUtils already exists; replacing with new instance...");
-        }
-
-        // Create the OtaUtils instance.
-        app.otaUtils = new OtaUtils(app.getApplicationContext(), true /* interactive */);
-        if (DBG) log("- created OtaUtils: " + app.otaUtils);
-
-        // NOTE we still need to call OtaUtils.updateUiWidgets() once the
-        // InCallScreen instance is ready; see InCallScreen.checkOtaspStateOnResume()
-
-        // Make sure the InCallScreen knows that it needs to switch into OTASP mode.
-        //
-        // NOTE in gingerbread and earlier, we used to do
-        //     setInCallScreenMode(InCallScreenMode.OTA_NORMAL);
-        // directly in the InCallScreen, back when this check happened inside the InCallScreen.
-        //
-        // But now, set the global CdmaOtaInCallScreenUiState object into
-        // NORMAL mode, which will then cause the InCallScreen (when it
-        // comes up) to realize that an OTA call is active.
-
-        app.otaUtils.setCdmaOtaInCallScreenUiState(
-            OtaUtils.CdmaOtaInCallScreenUiState.State.NORMAL);
-
-        // TODO(OTASP): note app.inCallUiState.inCallScreenMode and
-        // app.cdmaOtaInCallScreenUiState.state are mostly redundant.  Combine them.
-        // app.inCallUiState.inCallScreenMode = InCallUiState.InCallScreenMode.OTA_NORMAL;
-
-        // TODO(OTASP / bug 5092031): we ideally should call
-        // otaShowListeningScreen() here to make sure that the DTMF dialpad
-        // becomes visible at the start of the "*228" call:
-        //
-        //  // ...and get the OTASP-specific UI into the right state.
-        //  app.otaUtils.otaShowListeningScreen();
-        //  if (app.otaUtils.mInCallScreen != null) {
-        //      app.otaUtils.mInCallScreen.requestUpdateScreen();
-        //  }
-        //
-        // But this doesn't actually work; the call to otaShowListeningScreen()
-        // *doesn't* actually bring up the listening screen, since the
-        // cdmaOtaConfigData.otaShowListeningScreen config parameter hasn't been
-        // initialized (we haven't run readXmlSettings() yet at this point!)
-
-        // Also, since the OTA call is now just starting, clear out
-        // the "committed" flag in app.cdmaOtaProvisionData.
-        if (app.cdmaOtaProvisionData != null) {
-            app.cdmaOtaProvisionData.isOtaCallCommitted = false;
-        }
-    }
-
-    private void setSpeaker(boolean state) {
-        if (DBG) log("setSpeaker : " + state );
-
-        if (!mInteractive) {
-            if (DBG) log("non-interactive mode, ignoring setSpeaker.");
-            return;
-        }
-
-        if (state == PhoneUtils.isSpeakerOn(mContext)) {
-            if (DBG) log("no change. returning");
-            return;
-        }
-
-        PhoneUtils.turnOnSpeaker(mContext, state, true);
-    }
-
-    /**
-     * Handles OTA Provision events from the telephony layer.
-     * These events come in to this method whether or not
-     * the InCallScreen is visible.
-     *
-     * Possible events are:
-     * OTA Commit Event - OTA provisioning was successful
-     * SPC retries exceeded - SPC failure retries has exceeded, and Phone needs to
-     *    power down.
-     */
-    public void onOtaProvisionStatusChanged(AsyncResult r) {
-        int OtaStatus[] = (int[]) r.result;
-        if (DBG) log("Provision status event!");
-        if (DBG) log("onOtaProvisionStatusChanged(): status = "
-                     + OtaStatus[0] + " ==> " + otaProvisionStatusToString(OtaStatus[0]));
-
-        // In practice, in a normal successful OTASP call, events come in as follows:
-        //   - SPL_UNLOCKED within a couple of seconds after the call starts
-        //   - then a delay of around 45 seconds
-        //   - then PRL_DOWNLOADED and MDN_DOWNLOADED and COMMITTED within a span of 2 seconds
-
-        switch(OtaStatus[0]) {
-            case Phone.CDMA_OTA_PROVISION_STATUS_SPC_RETRIES_EXCEEDED:
-                if (DBG) log("onOtaProvisionStatusChanged(): RETRIES EXCEEDED");
-                updateOtaspProgress();
-                mApplication.cdmaOtaProvisionData.otaSpcUptime = SystemClock.elapsedRealtime();
-                if (mInteractive) {
-                    otaShowSpcErrorNotice(OTA_SPC_TIMEOUT);
-                } else {
-                    sendOtaspResult(OTASP_FAILURE_SPC_RETRIES);
-                }
-                // Power.shutdown();
-                break;
-
-            case Phone.CDMA_OTA_PROVISION_STATUS_COMMITTED:
-                if (DBG) {
-                    log("onOtaProvisionStatusChanged(): DONE, isOtaCallCommitted set to true");
-                }
-                mApplication.cdmaOtaProvisionData.isOtaCallCommitted = true;
-                if (mApplication.cdmaOtaScreenState.otaScreenState !=
-                    CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED) {
-                    updateOtaspProgress();
-                }
-
-                break;
-
-            case Phone.CDMA_OTA_PROVISION_STATUS_SPL_UNLOCKED:
-            case Phone.CDMA_OTA_PROVISION_STATUS_A_KEY_EXCHANGED:
-            case Phone.CDMA_OTA_PROVISION_STATUS_SSD_UPDATED:
-            case Phone.CDMA_OTA_PROVISION_STATUS_NAM_DOWNLOADED:
-            case Phone.CDMA_OTA_PROVISION_STATUS_MDN_DOWNLOADED:
-            case Phone.CDMA_OTA_PROVISION_STATUS_IMSI_DOWNLOADED:
-            case Phone.CDMA_OTA_PROVISION_STATUS_PRL_DOWNLOADED:
-            case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_STARTED:
-            case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_STOPPED:
-            case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_ABORTED:
-                // Only update progress when OTA call is in normal state
-                if (getCdmaOtaInCallScreenUiState() == CdmaOtaInCallScreenUiState.State.NORMAL) {
-                    if (DBG) log("onOtaProvisionStatusChanged(): change to ProgressScreen");
-                    updateOtaspProgress();
-                }
-                break;
-
-            default:
-                if (DBG) log("onOtaProvisionStatusChanged(): Ignoring OtaStatus " + OtaStatus[0]);
-                break;
-        }
-    }
-
-    /**
-     * Handle a disconnect event from the OTASP call.
-     */
-    public void onOtaspDisconnect() {
-        if (DBG) log("onOtaspDisconnect()...");
-        // We only handle this event explicitly in non-interactive mode.
-        // (In interactive mode, the InCallScreen does any post-disconnect
-        // cleanup.)
-        if (!mInteractive) {
-            // Send a success or failure indication back to our caller.
-            updateNonInteractiveOtaSuccessFailure();
-        }
-        cleanOtaScreen(true);
-    }
-
-    private void otaShowHome() {
-        if (DBG) log("otaShowHome()...");
-        mApplication.cdmaOtaScreenState.otaScreenState =
-                CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED;
-        // mInCallScreen.endInCallScreenSession();
-        Intent intent = new Intent(Intent.ACTION_MAIN);
-        intent.addCategory (Intent.CATEGORY_HOME);
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
-        return;
-    }
-
-    private void otaSkipActivation() {
-        if (DBG) log("otaSkipActivation()...");
-
-        sendOtaspResult(OTASP_USER_SKIPPED);
-
-        // if (mInteractive) mInCallScreen.finish();
-        return;
-    }
-
-    /**
-     * Actually initiate the OTASP call.  This method is triggered by the
-     * onscreen "Activate" button, and is only used in interactive mode.
-     */
-    private void otaPerformActivation() {
-        if (DBG) log("otaPerformActivation()...");
-        if (!mInteractive) {
-            // We shouldn't ever get here in non-interactive mode!
-            Log.w(LOG_TAG, "otaPerformActivation: not interactive!");
-            return;
-        }
-
-        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
-            // Place an outgoing call to the special OTASP number:
-            Intent newIntent = new Intent(Intent.ACTION_CALL);
-            newIntent.setData(Uri.fromParts(PhoneAccount.SCHEME_TEL, OTASP_NUMBER, null));
-
-            // Initiate the outgoing call:
-            mApplication.callController.placeCall(newIntent);
-
-            // ...and get the OTASP-specific UI into the right state.
-            otaShowListeningScreen();
-            // mInCallScreen.requestUpdateScreen();
-        }
-        return;
-    }
-
-    /**
-     * Show Activation Screen when phone powers up and OTA provision is
-     * required. Also shown when activation fails and user needs
-     * to re-attempt it. Contains ACTIVATE and SKIP buttons
-     * which allow user to start OTA activation or skip the activation process.
-     */
-    public void otaShowActivateScreen() {
-        if (DBG) log("otaShowActivateScreen()...");
-        if (mApplication.cdmaOtaConfigData.otaShowActivationScreen
-                == OTA_SHOW_ACTIVATION_SCREEN_ON) {
-            if (DBG) log("otaShowActivateScreen(): show activation screen");
-            if (!isDialerOpened()) {
-                otaScreenInitialize();
-                mOtaWidgetData.otaSkipButton.setVisibility(sIsWizardMode ?
-                        View.VISIBLE : View.INVISIBLE);
-                mOtaWidgetData.otaTextActivate.setVisibility(View.VISIBLE);
-                mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.VISIBLE);
-            }
-            mApplication.cdmaOtaScreenState.otaScreenState =
-                    CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION;
-        } else {
-            if (DBG) log("otaShowActivateScreen(): show home screen");
-            otaShowHome();
-        }
-     }
-
-    /**
-     * Show "Listen for Instruction" screen during OTA call. Shown when OTA Call
-     * is initiated and user needs to listen for network instructions and press
-     * appropriate DTMF digits to proceed to the "Programming in Progress" phase.
-     */
-    private void otaShowListeningScreen() {
-        if (DBG) log("otaShowListeningScreen()...");
-        if (!mInteractive) {
-            // We shouldn't ever get here in non-interactive mode!
-            Log.w(LOG_TAG, "otaShowListeningScreen: not interactive!");
-            return;
-        }
-
-        if (mApplication.cdmaOtaConfigData.otaShowListeningScreen
-                == OTA_SHOW_LISTENING_SCREEN_ON) {
-            if (DBG) log("otaShowListeningScreen(): show listening screen");
-            if (!isDialerOpened()) {
-                otaScreenInitialize();
-                mOtaWidgetData.otaTextListenProgress.setVisibility(View.VISIBLE);
-                mOtaWidgetData.otaTextListenProgress.setText(R.string.ota_listen);
-                // mOtaWidgetData.otaDtmfDialerView.setVisibility(View.VISIBLE);
-                mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.VISIBLE);
-                mOtaWidgetData.otaSpeakerButton.setVisibility(View.VISIBLE);
-                boolean speakerOn = PhoneUtils.isSpeakerOn(mContext);
-                mOtaWidgetData.otaSpeakerButton.setChecked(speakerOn);
-            }
-            mApplication.cdmaOtaScreenState.otaScreenState =
-                    CdmaOtaScreenState.OtaScreenState.OTA_STATUS_LISTENING;
-        } else {
-            if (DBG) log("otaShowListeningScreen(): show progress screen");
-            otaShowInProgressScreen();
-        }
-    }
-
-    /**
-     * Do any necessary updates (of onscreen UI, for example)
-     * based on the latest status of the OTASP call.
-     */
-    private void updateOtaspProgress() {
-        if (DBG) log("updateOtaspProgress()...  mInteractive = " + mInteractive);
-        if (mInteractive) {
-            // On regular phones we just call through to
-            // otaShowInProgressScreen(), which updates the
-            // InCallScreen's onscreen UI.
-            otaShowInProgressScreen();
-        } else {
-            // We're not using the InCallScreen to show OTA progress.
-
-            // For now, at least, there's nothing to do here.
-            // The overall "success" or "failure" indication we send back
-            // (to our caller) is triggered by the DISCONNECT event;
-            // see updateNonInteractiveOtaSuccessFailure().
-
-            // But if we ever need to send *intermediate* progress updates back
-            // to our caller, we'd do that here, possbily using the same
-            // PendingIntent that we already use to indicate success or failure.
-        }
-    }
-
-    /**
-     * When a non-interactive OTASP call completes, send a success or
-     * failure indication back to our caller.
-     *
-     * This is basically the non-interactive equivalent of
-     * otaShowSuccessFailure().
-     */
-    private void updateNonInteractiveOtaSuccessFailure() {
-        // This is basically the same logic as otaShowSuccessFailure(): we
-        // check the isOtaCallCommitted bit, and if that's true it means
-        // that activation was successful.
-
-        if (DBG) log("updateNonInteractiveOtaSuccessFailure(): isOtaCallCommitted = "
-                     + mApplication.cdmaOtaProvisionData.isOtaCallCommitted);
-        int resultCode =
-                mApplication.cdmaOtaProvisionData.isOtaCallCommitted
-                ? OTASP_SUCCESS : OTASP_FAILURE;
-        sendOtaspResult(resultCode);
-    }
-
-    /**
-     * Sends the specified OTASP result code back to our caller (presumably
-     * SetupWizard) via the PendingIntent that they originally sent along with
-     * the ACTION_PERFORM_CDMA_PROVISIONING intent.
-     */
-    private void sendOtaspResult(int resultCode) {
-        if (DBG) log("sendOtaspResult: resultCode = " + resultCode);
-
-        // Pass the success or failure indication back to our caller by
-        // adding an additional extra to the PendingIntent we already
-        // have.
-        // (NB: there's a PendingIntent send() method that takes a resultCode
-        // directly, but we can't use that here since that call is only
-        // meaningful for pending intents that are actually used as activity
-        // results.)
-
-        Intent extraStuff = new Intent();
-        extraStuff.putExtra(EXTRA_OTASP_RESULT_CODE, resultCode);
-        // When we call PendingIntent.send() below, the extras from this
-        // intent will get merged with any extras already present in
-        // cdmaOtaScreenState.otaspResultCodePendingIntent.
-
-        if (mApplication.cdmaOtaScreenState == null) {
-            Log.e(LOG_TAG, "updateNonInteractiveOtaSuccessFailure: no cdmaOtaScreenState object!");
-            return;
-        }
-        if (mApplication.cdmaOtaScreenState.otaspResultCodePendingIntent == null) {
-            Log.w(LOG_TAG, "updateNonInteractiveOtaSuccessFailure: "
-                  + "null otaspResultCodePendingIntent!");
-            return;
-        }
-
-        try {
-            if (DBG) log("- sendOtaspResult:  SENDING PENDING INTENT: " +
-                         mApplication.cdmaOtaScreenState.otaspResultCodePendingIntent);
-            mApplication.cdmaOtaScreenState.otaspResultCodePendingIntent.send(
-                    mContext,
-                    0, /* resultCode (unused) */
-                    extraStuff);
-        } catch (CanceledException e) {
-            // should never happen because no code cancels the pending intent right now,
-            Log.e(LOG_TAG, "PendingIntent send() failed: " + e);
-        }
-    }
-
-    /**
-     * Show "Programming In Progress" screen during OTA call. Shown when OTA
-     * provisioning is in progress after user has selected an option.
-     */
-    private void otaShowInProgressScreen() {
-        if (DBG) log("otaShowInProgressScreen()...");
-        if (!mInteractive) {
-            // We shouldn't ever get here in non-interactive mode!
-            Log.w(LOG_TAG, "otaShowInProgressScreen: not interactive!");
-            return;
-        }
-
-        mApplication.cdmaOtaScreenState.otaScreenState =
-            CdmaOtaScreenState.OtaScreenState.OTA_STATUS_PROGRESS;
-
-        if ((mOtaWidgetData == null) /* || (mInCallScreen == null) */) {
-            Log.w(LOG_TAG, "otaShowInProgressScreen: UI widgets not set up yet!");
-
-            // TODO(OTASP): our CdmaOtaScreenState is now correct; we just set
-            // it to OTA_STATUS_PROGRESS.  But we still need to make sure that
-            // when the InCallScreen eventually comes to the foreground, it
-            // notices that state and does all the same UI updating we do below.
-            return;
-        }
-
-        if (!isDialerOpened()) {
-            otaScreenInitialize();
-            mOtaWidgetData.otaTextListenProgress.setVisibility(View.VISIBLE);
-            mOtaWidgetData.otaTextListenProgress.setText(R.string.ota_progress);
-            mOtaWidgetData.otaTextProgressBar.setVisibility(View.VISIBLE);
-            mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.VISIBLE);
-            mOtaWidgetData.otaSpeakerButton.setVisibility(View.VISIBLE);
-            boolean speakerOn = PhoneUtils.isSpeakerOn(mContext);
-            mOtaWidgetData.otaSpeakerButton.setChecked(speakerOn);
-        }
-    }
-
-    /**
-     * Show programming failure dialog when OTA provisioning fails.
-     * If OTA provisioning attempts fail more than 3 times, then unsuccessful
-     * dialog is shown. Otherwise a two-second notice is shown with unsuccessful
-     * information. When notice expires, phone returns to activation screen.
-     */
-    private void otaShowProgramFailure(int length) {
-        if (DBG) log("otaShowProgramFailure()...");
-        mApplication.cdmaOtaProvisionData.activationCount++;
-        if ((mApplication.cdmaOtaProvisionData.activationCount <
-                mApplication.cdmaOtaConfigData.otaShowActivateFailTimes)
-                && (mApplication.cdmaOtaConfigData.otaShowActivationScreen ==
-                OTA_SHOW_ACTIVATION_SCREEN_ON)) {
-            if (DBG) log("otaShowProgramFailure(): activationCount"
-                    + mApplication.cdmaOtaProvisionData.activationCount);
-            if (DBG) log("otaShowProgramFailure(): show failure notice");
-            otaShowProgramFailureNotice(length);
-        } else {
-            if (DBG) log("otaShowProgramFailure(): show failure dialog");
-            otaShowProgramFailureDialog();
-        }
-    }
-
-    /**
-     * Show either programming success dialog when OTA provisioning succeeds, or
-     * programming failure dialog when it fails. See {@link #otaShowProgramFailure}
-     * for more details.
-     */
-    public void otaShowSuccessFailure() {
-        if (DBG) log("otaShowSuccessFailure()...");
-        if (!mInteractive) {
-            // We shouldn't ever get here in non-interactive mode!
-            Log.w(LOG_TAG, "otaShowSuccessFailure: not interactive!");
-            return;
-        }
-
-        otaScreenInitialize();
-        if (DBG) log("otaShowSuccessFailure(): isOtaCallCommitted"
-                + mApplication.cdmaOtaProvisionData.isOtaCallCommitted);
-        if (mApplication.cdmaOtaProvisionData.isOtaCallCommitted) {
-            if (DBG) log("otaShowSuccessFailure(), show success dialog");
-            otaShowProgramSuccessDialog();
-        } else {
-            if (DBG) log("otaShowSuccessFailure(), show failure dialog");
-            otaShowProgramFailure(OTA_FAILURE_DIALOG_TIMEOUT);
-        }
-        return;
-    }
-
-    /**
-     * Show programming failure dialog when OTA provisioning fails more than 3
-     * times.
-     */
-    private void otaShowProgramFailureDialog() {
-        if (DBG) log("otaShowProgramFailureDialog()...");
-        mApplication.cdmaOtaScreenState.otaScreenState =
-                CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG;
-        mOtaWidgetData.otaTitle.setText(R.string.ota_title_problem_with_activation);
-        mOtaWidgetData.otaTextSuccessFail.setVisibility(View.VISIBLE);
-        mOtaWidgetData.otaTextSuccessFail.setText(R.string.ota_unsuccessful);
-        mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.VISIBLE);
-        mOtaWidgetData.otaTryAgainButton.setVisibility(View.VISIBLE);
-        //close the dialer if open
-        // if (isDialerOpened()) {
-        //     mOtaCallCardDtmfDialer.closeDialer(false);
-        // }
-    }
-
-    /**
-     * Show programming success dialog when OTA provisioning succeeds.
-     */
-    private void otaShowProgramSuccessDialog() {
-        if (DBG) log("otaShowProgramSuccessDialog()...");
-        mApplication.cdmaOtaScreenState.otaScreenState =
-                CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG;
-        mOtaWidgetData.otaTitle.setText(R.string.ota_title_activate_success);
-        mOtaWidgetData.otaTextSuccessFail.setVisibility(View.VISIBLE);
-        mOtaWidgetData.otaTextSuccessFail.setText(R.string.ota_successful);
-        mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.VISIBLE);
-        mOtaWidgetData.otaNextButton.setVisibility(View.VISIBLE);
-        //close the dialer if open
-        // if (isDialerOpened()) {
-        //     mOtaCallCardDtmfDialer.closeDialer(false);
-        // }
-    }
-
-    /**
-     * Show SPC failure notice when SPC attempts exceed 15 times.
-     * During OTA provisioning, if SPC code is incorrect OTA provisioning will
-     * fail. When SPC attempts are over 15, it shows SPC failure notice for one minute and
-     * then phone will power down.
-     */
-    private void otaShowSpcErrorNotice(int length) {
-        if (DBG) log("otaShowSpcErrorNotice()...");
-        if (mOtaWidgetData.spcErrorDialog == null) {
-            mApplication.cdmaOtaProvisionData.inOtaSpcState = true;
-            DialogInterface.OnKeyListener keyListener;
-            keyListener = new DialogInterface.OnKeyListener() {
-                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
-                    log("Ignoring key events...");
-                    return true;
-                }};
-            mOtaWidgetData.spcErrorDialog = new AlertDialog.Builder(null /* mInCallScreen */)
-                    .setMessage(R.string.ota_spc_failure)
-                    .setOnKeyListener(keyListener)
-                    .create();
-            mOtaWidgetData.spcErrorDialog.getWindow().addFlags(
-                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
-                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
-            mOtaWidgetData.spcErrorDialog.show();
-            //close the dialer if open
-            // if (isDialerOpened()) {
-            //     mOtaCallCardDtmfDialer.closeDialer(false);
-            // }
-            long noticeTime = length*1000;
-            if (DBG) log("otaShowSpcErrorNotice(), remaining SPC noticeTime" + noticeTime);
-            // mInCallScreen.requestCloseSpcErrorNotice(noticeTime);
-        }
-    }
-
-    /**
-     * When SPC notice times out, force phone to power down.
-     */
-    public void onOtaCloseSpcNotice() {
-        if (DBG) log("onOtaCloseSpcNotice(), send shutdown intent");
-        Intent shutdown = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
-        shutdown.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
-        shutdown.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        mContext.startActivity(shutdown);
-    }
-
-    /**
-     * Show two-second notice when OTA provisioning fails and number of failed attempts
-     * is less then 3.
-     */
-    private void otaShowProgramFailureNotice(int length) {
-        if (DBG) log("otaShowProgramFailureNotice()...");
-        if (mOtaWidgetData.otaFailureDialog == null) {
-            mOtaWidgetData.otaFailureDialog = new AlertDialog.Builder(null /* mInCallScreen */)
-                    .setMessage(R.string.ota_failure)
-                    .create();
-            mOtaWidgetData.otaFailureDialog.getWindow().addFlags(
-                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
-                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
-            mOtaWidgetData.otaFailureDialog.show();
-
-            long noticeTime = length*1000;
-            // mInCallScreen.requestCloseOtaFailureNotice(noticeTime);
-        }
-    }
-
-    /**
-     * Handle OTA unsuccessful notice expiry. Dismisses the
-     * two-second notice and shows the activation screen.
-     */
-    public void onOtaCloseFailureNotice() {
-        if (DBG) log("onOtaCloseFailureNotice()...");
-        if (mOtaWidgetData.otaFailureDialog != null) {
-            mOtaWidgetData.otaFailureDialog.dismiss();
-            mOtaWidgetData.otaFailureDialog = null;
-        }
-        otaShowActivateScreen();
-    }
-
-    /**
-     * Initialize all OTA UI elements to be gone. Also set inCallPanel,
-     * callCard and the dialpad handle to be gone. This is called before any OTA screen
-     * gets drawn.
-     */
-    private void otaScreenInitialize() {
-        if (DBG) log("otaScreenInitialize()...");
-
-        if (!mInteractive) {
-            // We should never be doing anything with UI elements in
-            // non-interactive mode.
-            Log.w(LOG_TAG, "otaScreenInitialize: not interactive!");
-            return;
-        }
-
-        // if (mInCallTouchUi != null) mInCallTouchUi.setVisibility(View.GONE);
-        // if (mCallCard != null) {
-        //     mCallCard.setVisibility(View.GONE);
-        //     // TODO: try removing this.
-        //     mCallCard.hideCallCardElements();
-        // }
-
-        mOtaWidgetData.otaTitle.setText(R.string.ota_title_activate);
-        mOtaWidgetData.otaTextActivate.setVisibility(View.GONE);
-        mOtaWidgetData.otaTextListenProgress.setVisibility(View.GONE);
-        mOtaWidgetData.otaTextProgressBar.setVisibility(View.GONE);
-        mOtaWidgetData.otaTextSuccessFail.setVisibility(View.GONE);
-        mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.GONE);
-        mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.GONE);
-        mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.GONE);
-        // mOtaWidgetData.otaDtmfDialerView.setVisibility(View.GONE);
-        mOtaWidgetData.otaSpeakerButton.setVisibility(View.GONE);
-        mOtaWidgetData.otaTryAgainButton.setVisibility(View.GONE);
-        mOtaWidgetData.otaNextButton.setVisibility(View.GONE);
-        mOtaWidgetData.otaUpperWidgets.setVisibility(View.VISIBLE);
-        mOtaWidgetData.otaSkipButton.setVisibility(View.VISIBLE);
-    }
-
-    public void hideOtaScreen() {
-        if (DBG) log("hideOtaScreen()...");
-
-        mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.GONE);
-        mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.GONE);
-        mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.GONE);
-        mOtaWidgetData.otaUpperWidgets.setVisibility(View.GONE);
-    }
-
-    public boolean isDialerOpened() {
-        // boolean retval = (mOtaCallCardDtmfDialer != null && mOtaCallCardDtmfDialer.isOpened());
-        boolean retval = false;
-        if (DBG) log("- isDialerOpened() ==> " + retval);
-        return retval;
-    }
-
-    /**
-     * Show the appropriate OTA screen based on the current state of OTA call.
-     *
-     * This is called from the InCallScreen when the screen needs to be
-     * refreshed (and thus is only ever used in interactive mode.)
-     *
-     * Since this is called as part of the InCallScreen.updateScreen() sequence,
-     * this method does *not* post an mInCallScreen.requestUpdateScreen()
-     * request.
-     */
-    public void otaShowProperScreen() {
-        if (DBG) log("otaShowProperScreen()...");
-        if (!mInteractive) {
-            // We shouldn't ever get here in non-interactive mode!
-            Log.w(LOG_TAG, "otaShowProperScreen: not interactive!");
-            return;
-        }
-
-        // if ((mInCallScreen != null) && mInCallScreen.isForegroundActivity()) {
-        //     if (DBG) log("otaShowProperScreen(): InCallScreen in foreground, currentstate = "
-        //             + mApplication.cdmaOtaScreenState.otaScreenState);
-        //     if (mInCallTouchUi != null) {
-        //         mInCallTouchUi.setVisibility(View.GONE);
-        //     }
-        //     if (mCallCard != null) {
-        //         mCallCard.setVisibility(View.GONE);
-        //     }
-        //     if (mApplication.cdmaOtaScreenState.otaScreenState
-        //             == CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION) {
-        //         otaShowActivateScreen();
-        //     } else if (mApplication.cdmaOtaScreenState.otaScreenState
-        //             == CdmaOtaScreenState.OtaScreenState.OTA_STATUS_LISTENING) {
-        //         otaShowListeningScreen();
-        //     } else if (mApplication.cdmaOtaScreenState.otaScreenState
-        //             == CdmaOtaScreenState.OtaScreenState.OTA_STATUS_PROGRESS) {
-        //         otaShowInProgressScreen();
-        //     }
-
-        //     if (mApplication.cdmaOtaProvisionData.inOtaSpcState) {
-        //         otaShowSpcErrorNotice(getOtaSpcDisplayTime());
-        //     }
-        // }
-    }
-
-    /**
-     * Read configuration values for each OTA screen from config.xml.
-     * These configuration values control visibility of each screen.
-     */
-    private void readXmlSettings() {
-        if (DBG) log("readXmlSettings()...");
-        if (mApplication.cdmaOtaConfigData.configComplete) {
-            return;
-        }
-
-        mApplication.cdmaOtaConfigData.configComplete = true;
-        int tmpOtaShowActivationScreen =
-                mContext.getResources().getInteger(R.integer.OtaShowActivationScreen);
-        mApplication.cdmaOtaConfigData.otaShowActivationScreen = tmpOtaShowActivationScreen;
-        if (DBG) log("readXmlSettings(), otaShowActivationScreen = "
-                + mApplication.cdmaOtaConfigData.otaShowActivationScreen);
-
-        int tmpOtaShowListeningScreen =
-                mContext.getResources().getInteger(R.integer.OtaShowListeningScreen);
-        mApplication.cdmaOtaConfigData.otaShowListeningScreen = tmpOtaShowListeningScreen;
-        if (DBG) log("readXmlSettings(), otaShowListeningScreen = "
-                + mApplication.cdmaOtaConfigData.otaShowListeningScreen);
-
-        int tmpOtaShowActivateFailTimes =
-                mContext.getResources().getInteger(R.integer.OtaShowActivateFailTimes);
-        mApplication.cdmaOtaConfigData.otaShowActivateFailTimes = tmpOtaShowActivateFailTimes;
-        if (DBG) log("readXmlSettings(), otaShowActivateFailTimes = "
-                + mApplication.cdmaOtaConfigData.otaShowActivateFailTimes);
-
-        int tmpOtaPlaySuccessFailureTone =
-                mContext.getResources().getInteger(R.integer.OtaPlaySuccessFailureTone);
-        mApplication.cdmaOtaConfigData.otaPlaySuccessFailureTone = tmpOtaPlaySuccessFailureTone;
-        if (DBG) log("readXmlSettings(), otaPlaySuccessFailureTone = "
-                + mApplication.cdmaOtaConfigData.otaPlaySuccessFailureTone);
-    }
-
-    /**
-     * Handle the click events for OTA buttons.
-     */
-    public void onClickHandler(int id) {
-        switch (id) {
-            case R.id.otaEndButton:
-                onClickOtaEndButton();
-                break;
-
-            case R.id.otaSpeakerButton:
-                onClickOtaSpeakerButton();
-                break;
-
-            case R.id.otaActivateButton:
-                onClickOtaActivateButton();
-                break;
-
-            case R.id.otaSkipButton:
-                onClickOtaActivateSkipButton();
-                break;
-
-            case R.id.otaNextButton:
-                onClickOtaActivateNextButton();
-                break;
-
-            case R.id.otaTryAgainButton:
-                onClickOtaTryAgainButton();
-                break;
-
-            default:
-                if (DBG) log ("onClickHandler: received a click event for unrecognized id");
-                break;
-        }
-    }
-
-    private void onClickOtaTryAgainButton() {
-        if (DBG) log("Activation Try Again Clicked!");
-        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
-            otaShowActivateScreen();
-        }
-    }
-
-    private void onClickOtaEndButton() {
-        if (DBG) log("Activation End Call Button Clicked!");
-        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
-            if (PhoneUtils.hangup(mApplication.mCM) == false) {
-                // If something went wrong when placing the OTA call,
-                // the screen is not updated by the call disconnect
-                // handler and we have to do it here
-                setSpeaker(false);
-                // mInCallScreen.handleOtaCallEnd();
-            }
-        }
-    }
-
-    private void onClickOtaSpeakerButton() {
-        if (DBG) log("OTA Speaker button Clicked!");
-        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
-            boolean isChecked = !PhoneUtils.isSpeakerOn(mContext);
-            setSpeaker(isChecked);
-        }
-    }
-
-    private void onClickOtaActivateButton() {
-        if (DBG) log("Call Activation Clicked!");
-        otaPerformActivation();
-    }
-
-    private void onClickOtaActivateSkipButton() {
-        if (DBG) log("Activation Skip Clicked!");
-        DialogInterface.OnKeyListener keyListener;
-        keyListener = new DialogInterface.OnKeyListener() {
-            public boolean onKey(DialogInterface dialog, int keyCode,
-                    KeyEvent event) {
-                if (DBG) log("Ignoring key events...");
-                return true;
-            }
-        };
-        mOtaWidgetData.otaSkipConfirmationDialog = new AlertDialog.Builder(null /* mInCallScreen */)
-                .setTitle(R.string.ota_skip_activation_dialog_title)
-                .setMessage(R.string.ota_skip_activation_dialog_message)
-                .setPositiveButton(
-                    android.R.string.ok,
-                    // "OK" means "skip activation".
-                    new AlertDialog.OnClickListener() {
-                        public void onClick(DialogInterface dialog, int which) {
-                            otaSkipActivation();
-                        }
-                    })
-                .setNegativeButton(
-                    android.R.string.cancel,
-                    // "Cancel" means just dismiss the dialog.
-                    // Don't actually start an activation call.
-                    null)
-                .setOnKeyListener(keyListener)
-                .create();
-        mOtaWidgetData.otaSkipConfirmationDialog.show();
-    }
-
-    private void onClickOtaActivateNextButton() {
-        if (DBG) log("Dialog Next Clicked!");
-        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
-            mApplication.cdmaOtaScreenState.otaScreenState =
-                    CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED;
-            otaShowHome();
-        }
-    }
-
-    public void dismissAllOtaDialogs() {
-        if (mOtaWidgetData != null) {
-            if (mOtaWidgetData.spcErrorDialog != null) {
-                if (DBG) log("- DISMISSING mSpcErrorDialog.");
-                mOtaWidgetData.spcErrorDialog.dismiss();
-                mOtaWidgetData.spcErrorDialog = null;
-            }
-            if (mOtaWidgetData.otaFailureDialog != null) {
-                if (DBG) log("- DISMISSING mOtaFailureDialog.");
-                mOtaWidgetData.otaFailureDialog.dismiss();
-                mOtaWidgetData.otaFailureDialog = null;
-            }
-        }
-    }
-
-    private int getOtaSpcDisplayTime() {
-        if (DBG) log("getOtaSpcDisplayTime()...");
-        int tmpSpcTime = 1;
-        if (mApplication.cdmaOtaProvisionData.inOtaSpcState) {
-            long tmpOtaSpcRunningTime = 0;
-            long tmpOtaSpcLeftTime = 0;
-            tmpOtaSpcRunningTime = SystemClock.elapsedRealtime();
-            tmpOtaSpcLeftTime =
-                tmpOtaSpcRunningTime - mApplication.cdmaOtaProvisionData.otaSpcUptime;
-            if (tmpOtaSpcLeftTime >= OTA_SPC_TIMEOUT*1000) {
-                tmpSpcTime = 1;
-            } else {
-                tmpSpcTime = OTA_SPC_TIMEOUT - (int)tmpOtaSpcLeftTime/1000;
-            }
-        }
-        if (DBG) log("getOtaSpcDisplayTime(), time for SPC error notice: " + tmpSpcTime);
-        return tmpSpcTime;
-    }
-
-    /**
-     * Initialize the OTA widgets for all OTA screens.
-     */
-    private void initOtaInCallScreen() {
-        if (DBG) log("initOtaInCallScreen()...");
-        // mOtaWidgetData.otaTitle = (TextView) mInCallScreen.findViewById(R.id.otaTitle);
-        // mOtaWidgetData.otaTextActivate = (TextView) mInCallScreen.findViewById(R.id.otaActivate);
-        mOtaWidgetData.otaTextActivate.setVisibility(View.GONE);
-        // mOtaWidgetData.otaTextListenProgress =
-        //         (TextView) mInCallScreen.findViewById(R.id.otaListenProgress);
-        // mOtaWidgetData.otaTextProgressBar =
-        //         (ProgressBar) mInCallScreen.findViewById(R.id.progress_large);
-        mOtaWidgetData.otaTextProgressBar.setIndeterminate(true);
-        // mOtaWidgetData.otaTextSuccessFail =
-        //         (TextView) mInCallScreen.findViewById(R.id.otaSuccessFailStatus);
-
-        // mOtaWidgetData.otaUpperWidgets =
-        //         (ViewGroup) mInCallScreen.findViewById(R.id.otaUpperWidgets);
-        // mOtaWidgetData.callCardOtaButtonsListenProgress =
-        //         (View) mInCallScreen.findViewById(R.id.callCardOtaListenProgress);
-        // mOtaWidgetData.callCardOtaButtonsActivate =
-        //         (View) mInCallScreen.findViewById(R.id.callCardOtaActivate);
-        // mOtaWidgetData.callCardOtaButtonsFailSuccess =
-        //         (View) mInCallScreen.findViewById(R.id.callCardOtaFailOrSuccessful);
-
-        // mOtaWidgetData.otaEndButton = (Button) mInCallScreen.findViewById(R.id.otaEndButton);
-        // mOtaWidgetData.otaEndButton.setOnClickListener(mInCallScreen);
-        // mOtaWidgetData.otaSpeakerButton =
-        //         (ToggleButton) mInCallScreen.findViewById(R.id.otaSpeakerButton);
-        // mOtaWidgetData.otaSpeakerButton.setOnClickListener(mInCallScreen);
-        // mOtaWidgetData.otaActivateButton =
-        //         (Button) mInCallScreen.findViewById(R.id.otaActivateButton);
-        // mOtaWidgetData.otaActivateButton.setOnClickListener(mInCallScreen);
-        // mOtaWidgetData.otaSkipButton = (Button) mInCallScreen.findViewById(R.id.otaSkipButton);
-        // mOtaWidgetData.otaSkipButton.setOnClickListener(mInCallScreen);
-        // mOtaWidgetData.otaNextButton = (Button) mInCallScreen.findViewById(R.id.otaNextButton);
-        // mOtaWidgetData.otaNextButton.setOnClickListener(mInCallScreen);
-        // mOtaWidgetData.otaTryAgainButton =
-        //         (Button) mInCallScreen.findViewById(R.id.otaTryAgainButton);
-        // mOtaWidgetData.otaTryAgainButton.setOnClickListener(mInCallScreen);
-
-        // mOtaWidgetData.otaDtmfDialerView =
-        //         (DTMFTwelveKeyDialerView) mInCallScreen.findViewById(R.id.otaDtmfDialerView);
-        // Sanity-check: the otaDtmfDialerView widget should *always* be present.
-        // if (mOtaWidgetData.otaDtmfDialerView == null) {
-        //     throw new IllegalStateException("initOtaInCallScreen: couldn't find otaDtmfDialerView");
-        // }
-
-        // Create a new DTMFTwelveKeyDialer instance purely for use by the
-        // DTMFTwelveKeyDialerView ("otaDtmfDialerView") that comes from
-        // otacall_card.xml.
-        // mOtaCallCardDtmfDialer = new DTMFTwelveKeyDialer(mInCallScreen,
-        //                                                  mOtaWidgetData.otaDtmfDialerView);
-
-        // Initialize the new DTMFTwelveKeyDialer instance.  This is
-        // needed to play local DTMF tones.
-        // mOtaCallCardDtmfDialer.startDialerSession();
-
-        // mOtaWidgetData.otaDtmfDialerView.setDialer(mOtaCallCardDtmfDialer);
-    }
-
-    /**
-     * Clear out all OTA UI widget elements. Needs to get called
-     * when OTA call ends or InCallScreen is destroyed.
-     * @param disableSpeaker parameter control whether Speaker should be turned off.
-     */
-    public void cleanOtaScreen(boolean disableSpeaker) {
-        if (DBG) log("OTA ends, cleanOtaScreen!");
-
-        mApplication.cdmaOtaScreenState.otaScreenState =
-                CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED;
-        mApplication.cdmaOtaProvisionData.isOtaCallCommitted = false;
-        mApplication.cdmaOtaProvisionData.isOtaCallIntentProcessed = false;
-        mApplication.cdmaOtaProvisionData.inOtaSpcState = false;
-        mApplication.cdmaOtaProvisionData.activationCount = 0;
-        mApplication.cdmaOtaProvisionData.otaSpcUptime = 0;
-        mApplication.cdmaOtaInCallScreenUiState.state = State.UNDEFINED;
-
-        if (mInteractive && (mOtaWidgetData != null)) {
-            // if (mInCallTouchUi != null) mInCallTouchUi.setVisibility(View.VISIBLE);
-            // if (mCallCard != null) {
-            //     mCallCard.setVisibility(View.VISIBLE);
-            //     mCallCard.hideCallCardElements();
-            // }
-
-            // Free resources from the DTMFTwelveKeyDialer instance we created
-            // in initOtaInCallScreen().
-            // if (mOtaCallCardDtmfDialer != null) {
-            //     mOtaCallCardDtmfDialer.stopDialerSession();
-            // }
-
-            mOtaWidgetData.otaTextActivate.setVisibility(View.GONE);
-            mOtaWidgetData.otaTextListenProgress.setVisibility(View.GONE);
-            mOtaWidgetData.otaTextProgressBar.setVisibility(View.GONE);
-            mOtaWidgetData.otaTextSuccessFail.setVisibility(View.GONE);
-            mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.GONE);
-            mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.GONE);
-            mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.GONE);
-            mOtaWidgetData.otaUpperWidgets.setVisibility(View.GONE);
-            // mOtaWidgetData.otaDtmfDialerView.setVisibility(View.GONE);
-            mOtaWidgetData.otaNextButton.setVisibility(View.GONE);
-            mOtaWidgetData.otaTryAgainButton.setVisibility(View.GONE);
-        }
-
-        // turn off the speaker in case it was turned on
-        // but the OTA call could not be completed
-        if (disableSpeaker) {
-            setSpeaker(false);
-        }
-    }
-
-    /**
-     * Defines OTA information that needs to be maintained during
-     * an OTA call when display orientation changes.
-     */
-    public static class CdmaOtaProvisionData {
-        public boolean isOtaCallCommitted;
-        public boolean isOtaCallIntentProcessed;
-        public boolean inOtaSpcState;
-        public int activationCount;
-        public long otaSpcUptime;
-    }
-
-    /**
-     * Defines OTA screen configuration items read from config.xml
-     * and used to control OTA display.
-     */
-    public static class CdmaOtaConfigData {
-        public int otaShowActivationScreen;
-        public int otaShowListeningScreen;
-        public int otaShowActivateFailTimes;
-        public int otaPlaySuccessFailureTone;
-        public boolean configComplete;
-        public CdmaOtaConfigData() {
-            if (DBG) log("CdmaOtaConfigData constructor!");
-            otaShowActivationScreen = OTA_SHOW_ACTIVATION_SCREEN_OFF;
-            otaShowListeningScreen = OTA_SHOW_LISTENING_SCREEN_OFF;
-            otaShowActivateFailTimes = OTA_SHOW_ACTIVATE_FAIL_COUNT_OFF;
-            otaPlaySuccessFailureTone = OTA_PLAY_SUCCESS_FAILURE_TONE_OFF;
-        }
-    }
-
-    /**
-     * The state of the OTA InCallScreen UI.
-     */
-    public static class CdmaOtaInCallScreenUiState {
-        public enum State {
-            UNDEFINED,
-            NORMAL,
-            ENDED
-        }
-
-        public State state;
-
-        public CdmaOtaInCallScreenUiState() {
-            if (DBG) log("CdmaOtaInCallScreenState: constructor init to UNDEFINED");
-            state = CdmaOtaInCallScreenUiState.State.UNDEFINED;
-        }
-    }
-
-    /**
-     * Save the Ota InCallScreen UI state
-     */
-    public void setCdmaOtaInCallScreenUiState(CdmaOtaInCallScreenUiState.State state) {
-        if (DBG) log("setCdmaOtaInCallScreenState: " + state);
-        mApplication.cdmaOtaInCallScreenUiState.state = state;
-    }
-
-    /**
-     * Get the Ota InCallScreen UI state
-     */
-    public CdmaOtaInCallScreenUiState.State getCdmaOtaInCallScreenUiState() {
-        if (DBG) log("getCdmaOtaInCallScreenState: "
-                     + mApplication.cdmaOtaInCallScreenUiState.state);
-        return mApplication.cdmaOtaInCallScreenUiState.state;
-    }
-
-    /**
-     * The OTA screen state machine.
-     */
-    public static class CdmaOtaScreenState {
-        public enum OtaScreenState {
-            OTA_STATUS_UNDEFINED,
-            OTA_STATUS_ACTIVATION,
-            OTA_STATUS_LISTENING,
-            OTA_STATUS_PROGRESS,
-            OTA_STATUS_SUCCESS_FAILURE_DLG
-        }
-
-        public OtaScreenState otaScreenState;
-
-        public CdmaOtaScreenState() {
-            otaScreenState = OtaScreenState.OTA_STATUS_UNDEFINED;
-        }
-
-        /**
-         * {@link PendingIntent} used to report an OTASP result status code
-         * back to our caller. Can be null.
-         *
-         * Our caller (presumably SetupWizard) may create this PendingIntent,
-         * pointing back at itself, and passes it along as an extra with the
-         * ACTION_PERFORM_CDMA_PROVISIONING intent.  Then, when there's an
-         * OTASP result to report, we send that PendingIntent back, adding an
-         * extra called EXTRA_OTASP_RESULT_CODE to indicate the result.
-         *
-         * Possible result values are the OTASP_RESULT_* constants.
-         */
-        public PendingIntent otaspResultCodePendingIntent;
-    }
-
-    /** @see com.android.internal.telephony.Phone */
-    private static String otaProvisionStatusToString(int status) {
-        switch (status) {
-            case Phone.CDMA_OTA_PROVISION_STATUS_SPL_UNLOCKED:
-                return "SPL_UNLOCKED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_SPC_RETRIES_EXCEEDED:
-                return "SPC_RETRIES_EXCEEDED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_A_KEY_EXCHANGED:
-                return "A_KEY_EXCHANGED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_SSD_UPDATED:
-                return "SSD_UPDATED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_NAM_DOWNLOADED:
-                return "NAM_DOWNLOADED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_MDN_DOWNLOADED:
-                return "MDN_DOWNLOADED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_IMSI_DOWNLOADED:
-                return "IMSI_DOWNLOADED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_PRL_DOWNLOADED:
-                return "PRL_DOWNLOADED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_COMMITTED:
-                return "COMMITTED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_STARTED:
-                return "OTAPA_STARTED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_STOPPED:
-                return "OTAPA_STOPPED";
-            case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_ABORTED:
-                return "OTAPA_ABORTED";
-            default:
-                return "<unknown status" + status + ">";
-        }
-    }
-
-    private static int getLteOnCdmaMode(Context context) {
-        final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(
-                Context.TELEPHONY_SERVICE);
-        // If the telephony manager is not available yet, or if it doesn't know the answer yet,
-        // try falling back on the system property that may or may not be there
-        if (telephonyManager == null
-                || telephonyManager.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
-            return SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,
-                    PhoneConstants.LTE_ON_CDMA_UNKNOWN);
-        }
-        return telephonyManager.getLteOnCdmaMode();
-    }
-
-    private static void log(String msg) {
-        Log.d(LOG_TAG, msg);
-    }
-
-    private static void loge(String msg) {
-        Log.e(LOG_TAG, msg);
-    }
-}
diff --git a/src/com/android/phone/OutgoingCallBroadcaster.java b/src/com/android/phone/OutgoingCallBroadcaster.java
index 9a10a1b..6bb1388 100644
--- a/src/com/android/phone/OutgoingCallBroadcaster.java
+++ b/src/com/android/phone/OutgoingCallBroadcaster.java
@@ -190,47 +190,6 @@
             final PhoneGlobals app = PhoneGlobals.getInstance();
             final Phone phone = PhoneGlobals.getPhone();
 
-            // OTASP-specific checks.
-            // TODO: This should probably all happen in
-            // OutgoingCallBroadcaster.onCreate(), since there's no reason to
-            // even bother with the NEW_OUTGOING_CALL broadcast if we're going
-            // to disallow the outgoing call anyway...
-            if (TelephonyCapabilities.supportsOtasp(phone)) {
-                boolean activateState = (app.cdmaOtaScreenState.otaScreenState
-                        == OtaUtils.CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION);
-                boolean dialogState = (app.cdmaOtaScreenState.otaScreenState
-                        == OtaUtils.CdmaOtaScreenState.OtaScreenState
-                        .OTA_STATUS_SUCCESS_FAILURE_DLG);
-                boolean isOtaCallActive = false;
-
-                // TODO: Need cleaner way to check if OTA is active.
-                // Also, this check seems to be broken in one obscure case: if
-                // you interrupt an OTASP call by pressing Back then Skip,
-                // otaScreenState somehow gets left in either PROGRESS or
-                // LISTENING.
-                if ((app.cdmaOtaScreenState.otaScreenState
-                        == OtaUtils.CdmaOtaScreenState.OtaScreenState.OTA_STATUS_PROGRESS)
-                        || (app.cdmaOtaScreenState.otaScreenState
-                        == OtaUtils.CdmaOtaScreenState.OtaScreenState.OTA_STATUS_LISTENING)) {
-                    isOtaCallActive = true;
-                }
-
-                if (activateState || dialogState) {
-                    // The OTASP sequence is active, but either (1) the call
-                    // hasn't started yet, or (2) the call has ended and we're
-                    // showing the success/failure screen.  In either of these
-                    // cases it's OK to make a new outgoing call, but we need
-                    // to take down any OTASP-related UI first.
-                    if (dialogState) app.dismissOtaDialogs();
-                    app.clearOtaState();
-                } else if (isOtaCallActive) {
-                    // The actual OTASP call is active.  Don't allow new
-                    // outgoing calls at all from this state.
-                    Log.w(TAG, "OTASP call is active: disallowing a new outgoing call.");
-                    return false;
-                }
-            }
-
             if (number == null) {
                 if (DBG) Log.v(TAG, "CALL cancelled (null number), returning...");
                 return false;
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index cec5a76..88ff579 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -159,26 +159,6 @@
     // Broadcast receiver for various intent broadcasts (see onCreate())
     private final BroadcastReceiver mReceiver = new PhoneAppBroadcastReceiver();
 
-    /**
-     * The singleton OtaUtils instance used for OTASP calls.
-     *
-     * The OtaUtils instance is created lazily the first time we need to
-     * make an OTASP call, regardless of whether it's an interactive or
-     * non-interactive OTASP call.
-     */
-    public OtaUtils otaUtils;
-
-    // Following are the CDMA OTA information Objects used during OTA Call.
-    // cdmaOtaProvisionData object store static OTA information that needs
-    // to be maintained even during Slider open/close scenarios.
-    // cdmaOtaConfigData object stores configuration info to control visiblity
-    // of each OTA Screens.
-    // cdmaOtaScreenState object store OTA Screen State information.
-    public OtaUtils.CdmaOtaProvisionData cdmaOtaProvisionData;
-    public OtaUtils.CdmaOtaConfigData cdmaOtaConfigData;
-    public OtaUtils.CdmaOtaScreenState cdmaOtaScreenState;
-    public OtaUtils.CdmaOtaInCallScreenUiState cdmaOtaInCallScreenUiState;
-
     Handler mHandler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
@@ -356,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);
 
@@ -366,11 +346,6 @@
             PhoneUtils.setAudioMode(mCM);
         }
 
-        cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
-        cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
-        cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
-        cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();
-
         // XXX pre-load the SimProvider so that it's ready
         resolver.getType(Uri.parse("content://icc/adn"));
 
@@ -434,43 +409,6 @@
     }
 
     /**
-     * Handles OTASP-related events from the telephony layer.
-     *
-     * While an OTASP call is active, the CallNotifier forwards
-     * OTASP-related telephony events to this method.
-     */
-    void handleOtaspEvent(Message msg) {
-        if (DBG) Log.d(LOG_TAG, "handleOtaspEvent(message " + msg + ")...");
-
-        if (otaUtils == null) {
-            // We shouldn't be getting OTASP events without ever
-            // having started the OTASP call in the first place!
-            Log.w(LOG_TAG, "handleOtaEvents: got an event but otaUtils is null! "
-                  + "message = " + msg);
-            return;
-        }
-
-        otaUtils.onOtaProvisionStatusChanged((AsyncResult) msg.obj);
-    }
-
-    /**
-     * Similarly, handle the disconnect event of an OTASP call
-     * by forwarding it to the OtaUtils instance.
-     */
-    /* package */ void handleOtaspDisconnect() {
-        if (DBG) Log.d(LOG_TAG, "handleOtaspDisconnect()...");
-
-        if (otaUtils == null) {
-            // We shouldn't be getting OTASP events without ever
-            // having started the OTASP call in the first place!
-            Log.w(LOG_TAG, "handleOtaspDisconnect: otaUtils is null!");
-            return;
-        }
-
-        otaUtils.onOtaspDisconnect();
-    }
-
-    /**
      * Sets the activity responsible for un-PUK-blocking the device
      * so that we may close it when we receive a positive result.
      * mPUKEntryActivity is also used to indicate to the device that
@@ -618,15 +556,8 @@
         PhoneUtils.displayMMIComplete(mmiCode.getPhone(), getInstance(), mmiCode, null, null);
     }
 
-    private void initForNewRadioTechnology(int phoneId) {
+    private void initForNewRadioTechnology() {
         if (DBG) Log.d(LOG_TAG, "initForNewRadioTechnology...");
-
-        final Phone phone = PhoneFactory.getPhone(phoneId);
-        if (phone == null || !TelephonyCapabilities.supportsOtasp(phone)) {
-            // Clean up OTA for non-CDMA since it is only valid for CDMA.
-            clearOtaState();
-        }
-
         notifier.updateCallNotifierRegistrationsAfterRadioTechnologyChange();
     }
 
@@ -758,16 +689,13 @@
                         intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE)));
             } else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
                 String newPhone = intent.getStringExtra(PhoneConstants.PHONE_NAME_KEY);
-                int phoneId = intent.getIntExtra(PhoneConstants.PHONE_KEY,
-                        SubscriptionManager.INVALID_PHONE_INDEX);
-                Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " (" + phoneId
-                        + ") is active.");
-                initForNewRadioTechnology(phoneId);
+                Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
+                initForNewRadioTechnology();
             } else if (action.equals(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED)) {
                 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)) {
@@ -812,24 +740,6 @@
         }
     }
 
-    // it is safe to call clearOtaState() even if the InCallScreen isn't active
-    public void clearOtaState() {
-        if (DBG) Log.d(LOG_TAG, "- clearOtaState ...");
-        if (otaUtils != null) {
-            otaUtils.cleanOtaScreen(true);
-            if (DBG) Log.d(LOG_TAG, "  - clearOtaState clears OTA screen");
-        }
-    }
-
-    // it is safe to call dismissOtaDialogs() even if the InCallScreen isn't active
-    public void dismissOtaDialogs() {
-        if (DBG) Log.d(LOG_TAG, "- dismissOtaDialogs ...");
-        if (otaUtils != null) {
-            otaUtils.dismissAllOtaDialogs();
-            if (DBG) Log.d(LOG_TAG, "  - dismissOtaDialogs clears OTA dialogs");
-        }
-    }
-
     public Phone getPhoneInEcm() {
         return phoneInEcm;
     }
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index d66f219..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();
 
@@ -3560,6 +3636,9 @@
     public int setAllowedCarriers(int slotId, List<CarrierIdentifier> carriers) {
         enforceModifyPermission();
         int subId = SubscriptionManager.getSubId(slotId)[0];
+        if (carriers == null) {
+            throw new NullPointerException("carriers cannot be null");
+        }
         int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
         return retVal[0];
     }
@@ -3706,4 +3785,20 @@
         workSource = new WorkSource(uid, packageName);
         return workSource;
     }
+
+    /**
+     * Set SIM card power state. Request is equivalent to inserting or removing the card.
+     *
+     * @param slotId SIM slot id.
+     * @param powerUp True if powering up the SIM, otherwise powering down
+     *
+     **/
+    @Override
+    public void setSimPowerStateForSlot(int slotId, boolean powerUp) {
+        enforceModifyPermission();
+        Phone phone = PhoneFactory.getPhone(slotId);
+        if (phone != null) {
+            phone.setSimPowerState(powerUp);
+        }
+    }
 }
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/AndroidManifest.xml b/tests/AndroidManifest.xml
index 7962738..0aa5be2 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -38,16 +38,6 @@
             </intent-filter>
         </activity>
 
-        <!-- Test activity mimicking the PERFORM_CDMA_PROVISIONING behavior of
-             SetupWizard, useful for testing "non-interactive" OTASP. -->
-        <activity android:name="OtaspTestActivity"
-                  android:label="OtaspTest">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
-        </activity>
-
         <service android:name="SendInstantTextTestService"
                  android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" >
             <intent-filter>
diff --git a/tests/src/com/android/phone/tests/OtaspTestActivity.java b/tests/src/com/android/phone/tests/OtaspTestActivity.java
deleted file mode 100644
index ead86c3..0000000
--- a/tests/src/com/android/phone/tests/OtaspTestActivity.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone.tests;
-
-import android.app.Activity;
-import android.app.PendingIntent;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-
-import com.android.phone.OtaUtils;
-
-/**
- * Test activity that mimics the PERFORM_CDMA_PROVISIONING behavior of
- * SetupWizard, useful for testing "non-interactive" OTASP.
- * @see OtaUtils.startNonInteractiveOtasp
- *
- */
-public class OtaspTestActivity extends Activity implements View.OnClickListener {
-    private static final String LOG_TAG = "OtaspTestActivity";
-
-    // Request code used with startActivityForResult()
-    private static final int PERFORM_CDMA_PROVISIONING_REQUEST_CODE = 1;
-
-    // UI elements
-    private TextView mLabel;
-    private ProgressBar mProgressBar;
-    private TextView mResult;
-    private Button mButton;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        Intent intent = getIntent();
-        Log.i(LOG_TAG, "##### onCreate: intent = " + intent);
-        Bundle extras = intent.getExtras();
-        if (extras != null) {
-            Log.i(LOG_TAG, "      - has extras: size = " + extras.size()); // forces an unparcel()
-            Log.i(LOG_TAG, "      - extras = " + extras);
-        }
-
-        // Construct our basic UI:
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.otasp_test_activity);
-
-        mLabel = (TextView) findViewById(R.id.label1);
-        mLabel.setText("OTA Test Activity");
-
-        mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
-        mResult = (TextView) findViewById(R.id.result1);
-
-        mButton = (Button) findViewById(R.id.button1);
-        mButton.setText("Make test call");
-        mButton.setOnClickListener(this);
-
-
-        // We can be launched either:
-        //
-        // (1) Directly from the launcher, in which case the current intent
-        //     will simply be an ACTION_MAIN intent
-        //
-        // (2) Via the PendingIntent that we sent along (when we originally
-        //     fired off the ACTION_PERFORM_CDMA_PROVISIONING intent) that
-        //     allows the phone app to send us back a result code.
-        //     We can identify this case by the presence of the
-        //     EXTRA_OTASP_RESULT_CODE extra.
-
-        if (intent.hasExtra(OtaUtils.EXTRA_OTASP_RESULT_CODE)) {
-            // Got a result from the OTASP call!
-            Log.i(LOG_TAG, "==> onCreate: got a result from the OTASP call!");
-
-            int resultCode = intent.getIntExtra(OtaUtils.EXTRA_OTASP_RESULT_CODE,
-                                                OtaUtils.OTASP_UNKNOWN);
-            Log.i(LOG_TAG, "    - resultCode = " + resultCode);
-
-            String resultString;
-            switch (resultCode) {
-                case OtaUtils.OTASP_USER_SKIPPED:
-                    resultString = "User skipped!";
-                    break;
-                case OtaUtils.OTASP_SUCCESS:
-                    resultString = "Success!";
-                    break;
-                case OtaUtils.OTASP_FAILURE:
-                    resultString = "FAILURE";
-                    break;
-                default:
-                    resultString = "Unexpected code: " + resultCode;
-                    break;
-            }
-            Log.i(LOG_TAG, "    - result: " + resultString);
-            mResult.setText(resultString);
-            mResult.setVisibility(View.VISIBLE);
-            mProgressBar.setVisibility(View.INVISIBLE);
-
-        } else {
-            // We must have gotten here directly from the launcher.
-            // Leave the UI in its initial state.
-            Log.i(LOG_TAG, "==> onCreate: entered from the launcher.");
-        }
-    }
-
-    @Override
-    protected void onNewIntent(Intent intent) {
-        Log.i(LOG_TAG, "onNewIntent: intent=" + intent);
-        Bundle extras = intent.getExtras();
-        if (extras != null) Log.i(LOG_TAG, "      - intent extras = " + extras);
-
-        // This method isn't actually used since this test activity is not
-        // launched in "singleTop" mode.
-
-        // Activities that *are* launched in singleTop mode, like the SetupWizard,
-        // would have to handle the various PendingIntents here just like
-        // we do above in onCreate().
-    }
-
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        Log.i(LOG_TAG, "onActivityResult: request " + requestCode
-              + " result " + resultCode + " data " + data);
-
-        // Note we receive this call immediately before onResume(), when
-        // we get re-started after launching the PERFORM_CDMA_PROVISIONING
-        // intent.
-
-        if (requestCode == PERFORM_CDMA_PROVISIONING_REQUEST_CODE) {
-            // The InCallScreenShowActivation activity can set the following
-            // result codes:
-            //
-            //   RESULT_INTERACTIVE_OTASP_STARTED
-            //   RESULT_NONINTERACTIVE_OTASP_STARTED
-            //   RESULT_NONINTERACTIVE_OTASP_FAILED
-            //
-            // but note that in practice we won't ever *get* the
-            // RESULT_INTERACTIVE_OTASP_STARTED result code, since the
-            // "interactive" OTASP sequence never actually finish()es;
-            // it ends by directly launching the Home activity.
-            //
-            // However, in non-interactive OTASP, the
-            // InCallScreenShowActivation activity will set one of the
-            // RESULT_NONINTERACTIVE_* codes and immediately
-            // finish(), so we *will* see that result here.
-            //
-            // Also, resultCode will be RESULT_CANCELED (= 0) if the
-            // InCallScreenShowActivation activity didn't return any
-            // result, or crashed.
-
-            switch (resultCode) {
-                case OtaUtils.RESULT_INTERACTIVE_OTASP_STARTED:
-                    Log.i(LOG_TAG, "==> onActivityResult: INTERACTIVE_OTASP_STARTED");
-                    break;
-                case OtaUtils.RESULT_NONINTERACTIVE_OTASP_STARTED:
-                    Log.i(LOG_TAG, "==> onActivityResult: NONINTERACTIVE_OTASP_STARTED");
-                    break;
-                case OtaUtils.RESULT_NONINTERACTIVE_OTASP_FAILED:
-                    Log.w(LOG_TAG, "==> onActivityResult: NONINTERACTIVE_OTASP_FAILED");
-                    // This means we couldn't even *initiate* an outgoing call
-                    // to start the OTASP process.  Not sure what could cause this.
-                    // TODO: Update UI to indicate the error.
-                    break;
-                case RESULT_CANCELED:
-                    Log.i(LOG_TAG, "==> onActivityResult: CANCELED");
-                    break;
-                default:
-                    Log.i(LOG_TAG, "==> onActivityResult: unknown result: " + resultCode);
-                    break;
-            }
-        }
-    }
-
-    @Override
-    protected void onResume() {
-        Log.i(LOG_TAG, "onResume()...");
-        super.onResume();
-    }
-
-    @Override
-    protected void onPause() {
-        Log.i(LOG_TAG, "onPause()...");
-        super.onPause();
-    }
-
-    // View.OnClickListener implementation
-    @Override
-    public void onClick(View view) {
-        int id = view.getId();
-        Log.i(LOG_TAG, "onClick(View " + view + ", id " + id + ")...");
-
-        switch (id) {
-            case R.id.button1:
-                Log.i(LOG_TAG, "onClick: button1...");
-                makeTestCall();
-                break;
-            default:
-                Log.w(LOG_TAG, "onClick: unexpected View: " + view);
-                break;
-        }
-    }
-
-    private void makeTestCall() {
-        Log.i(LOG_TAG, "##### makeTestCall()...");
-
-        mProgressBar.setVisibility(View.VISIBLE);
-        mResult.setVisibility(View.INVISIBLE);
-
-        try {
-            Intent performProvisioningIntent =
-                    new Intent(OtaUtils.ACTION_PERFORM_CDMA_PROVISIONING);
-
-            // Set the magic extra to force "non-interactive mode" for the
-            // OTASP call.
-            performProvisioningIntent.putExtra(OtaUtils.EXTRA_OVERRIDE_INTERACTIVE_MODE, false);
-
-            // Pass a PendingIntent along with the
-            // ACTION_PERFORM_CDMA_PROVISIONING intent, which allows
-            // results to be sent back to us.
-            Intent resultIntent = new Intent(this, this.getClass());
-            PendingIntent pendingResultIntent =
-                    PendingIntent.getActivity(this, 0,
-                                              resultIntent, 0);
-            performProvisioningIntent.putExtra(OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT,
-                                               pendingResultIntent);
-
-            Log.i(LOG_TAG, "- Firing off PERFORM_CDMA_PROVISIONING intent: "
-                  + performProvisioningIntent);
-            Bundle extras = performProvisioningIntent.getExtras();
-            if (extras != null) Log.i(LOG_TAG, "      - intent extras = " + extras);
-
-            // Originally, we would simply call
-            //     startActivity(performProvisioningIntent);
-            // to launch the InCallScreenShowActivation activity and *not* expect
-            // a result.  (Note that calling the plain startActivity()
-            // method *guarantees* that your onActivityResult() method
-            // will NOT be called at all.)
-
-            // Now, we ask for a result:
-            startActivityForResult(performProvisioningIntent,
-                                   PERFORM_CDMA_PROVISIONING_REQUEST_CODE);
-
-            // On a non-voice-capable device, the InCallScreenShowActivation activity
-            // will kick off the OTASP call and immediately return, passing
-            // the code RESULT_STARTED_NONINTERACTIVE_OTASP to our
-            // onActivityResult method.
-
-        } catch (ActivityNotFoundException e) {
-            Log.w(LOG_TAG, "Couldn't show activiation UI; ActivityNotFoundException: " + e);
-        }
-    }
-}
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..903ef8f 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.test.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));