Add button to set CDMA subscription source.

CDMA subscription source allows the user to choose between RUIM and NV
modes for CDMA.

Change-Id: I34809842318bfdd733ecad83209cd9e7b83c07be
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 391ad47..06de61b 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -621,14 +621,14 @@
         <item>"1"</item>
         <item>"2"</item>
     </string-array>
-    <string name="subscription_title">CDMA Subscription TEST</string>
-    <string name="subscription_summary">Change between RUIM/SIM and NV</string>
-    <string name="subscription_dialogtitle">subscription</string>
-    <string-array name="subscription_choices">
+    <string name="cdma_subscription_title">CDMA Subscription</string>
+    <string name="cdma_subscription_summary">Change between RUIM/SIM and NV</string>
+    <string name="cdma_subscription_dialogtitle">subscription</string>
+    <string-array name="cdma_subscription_choices">
         <item>RUIM/SIM</item>
         <item>NV</item>
     </string-array>
-    <string-array name="subscription_values">
+    <string-array name="cdma_subscription_values">
         <item>"0"</item>
         <item>"1"</item>
     </string-array>
diff --git a/res/xml/cdma_options.xml b/res/xml/cdma_options.xml
index 346674c..e26abbe 100644
--- a/res/xml/cdma_options.xml
+++ b/res/xml/cdma_options.xml
@@ -17,11 +17,20 @@
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:settings="http://schemas.android.com/apk/res/com.android.phone">
 
-    <com.android.phone.CdmaRoamingListPreference
-        android:key="cdma_roaming_mode_key"
+    <com.android.phone.CdmaSystemSelectListPreference
+        android:key="cdma_system_select_key"
         android:title="@string/cdma_system_select_title"
         android:summary="@string/cdma_system_select_summary"
         android:entries="@array/cdma_system_select_choices"
         android:entryValues="@array/cdma_system_select_values"
         android:dialogTitle="@string/cdma_system_select_dialogtitle" />
+
+    <com.android.phone.CdmaSubscriptionListPreference
+        android:key="cdma_subscription_key"
+        android:title="@string/cdma_subscription_title"
+        android:summary="@string/cdma_subscription_summary"
+        android:entries="@array/cdma_subscription_choices"
+        android:entryValues="@array/cdma_subscription_values"
+        android:dialogTitle="@string/cdma_subscription_dialogtitle" />
+
 </PreferenceScreen>
diff --git a/res/xml/network_setting.xml b/res/xml/network_setting.xml
index 303f4a9..e02ae0a 100644
--- a/res/xml/network_setting.xml
+++ b/res/xml/network_setting.xml
@@ -32,26 +32,4 @@
         android:entryValues="@array/preferred_network_mode_values"
         android:dialogTitle="@string/preferred_network_mode_dialogtitle" />
 
-    <PreferenceScreen
-        android:key="gsm_umts_options_key"
-        android:title="@string/gsm_umts_options"
-        android:persistent="false">
-
-        <intent android:action="android.intent.action.MAIN"
-            android:targetPackage="com.android.phone"
-            android:targetClass="com.android.phone.GsmUmtsOptions" />
-
-    </PreferenceScreen>
-
-    <PreferenceScreen
-        android:key="cdma_options_key"
-        android:title="@string/cdma_options"
-        android:persistent="false">
-
-        <intent android:action="android.intent.action.MAIN"
-            android:targetPackage="com.android.phone"
-            android:targetClass="com.android.phone.CdmaOptions" />
-
-    </PreferenceScreen>
-
 </PreferenceScreen>
diff --git a/src/com/android/phone/CdmaOptions.java b/src/com/android/phone/CdmaOptions.java
index 09c4f13..83b7384 100644
--- a/src/com/android/phone/CdmaOptions.java
+++ b/src/com/android/phone/CdmaOptions.java
@@ -16,42 +16,100 @@
 
 package com.android.phone;
 
-import android.os.Bundle;
+import android.os.SystemProperties;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
-
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneFactory;
+import android.text.TextUtils;
 
 /**
  * List of Phone-specific settings screens.
  */
-public class CdmaOptions extends PreferenceActivity {
+public class CdmaOptions {
+    private static final String LOG_TAG = "CdmaOptions";
 
-    private CdmaRoamingListPreference mButtonCdmaRoam;
+    private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
+    private CdmaSubscriptionListPreference mButtonCdmaSubscription;
 
-    private static final String BUTTON_CDMA_ROAMING_KEY = "cdma_roaming_mode_key";
+    private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
+    private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
 
-    @Override
-    protected void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
+    private PreferenceActivity mPrefActivity;
+    private PreferenceScreen mPrefScreen;
 
-        addPreferencesFromResource(R.xml.cdma_options);
+    public CdmaOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen) {
+        mPrefActivity = prefActivity;
+        mPrefScreen = prefScreen;
+        create();
+    }
 
-        PreferenceScreen prefSet = getPreferenceScreen();
-        mButtonCdmaRoam =
-                (CdmaRoamingListPreference) prefSet.findPreference(BUTTON_CDMA_ROAMING_KEY);
-        if (PhoneFactory.getDefaultPhone().getPhoneType() != Phone.PHONE_TYPE_CDMA) {
-            mButtonCdmaRoam.setEnabled(false);
+    protected void create() {
+        mPrefActivity.addPreferencesFromResource(R.xml.cdma_options);
+
+        mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference)mPrefScreen
+                .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
+
+        mButtonCdmaSubscription = (CdmaSubscriptionListPreference)mPrefScreen
+                .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
+
+        mButtonCdmaSystemSelect.setEnabled(true);
+        if(deviceSupportsNvAndRuim()) {
+            log("Both NV and Ruim supported, ENABLE subscription type selection");
+            mButtonCdmaSubscription.setEnabled(true);
+        } else {
+            log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
+            mPrefScreen.removePreference(mPrefScreen
+                                .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY));
         }
     }
 
-    @Override
-    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
-        if (preference.getKey().equals(BUTTON_CDMA_ROAMING_KEY)) {
+    private boolean deviceSupportsNvAndRuim() {
+        // retrieve the list of subscription types supported by device.
+        String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
+        boolean nvSupported = false;
+        boolean ruimSupported = false;
+
+        log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
+        if (!TextUtils.isEmpty(subscriptionsSupported)) {
+            // Searches through the comma-separated list for a match for "NV"
+            // and "RUIM" to update nvSupported and ruimSupported.
+            for (String subscriptionType : subscriptionsSupported.split(",")) {
+                subscriptionType = subscriptionType.trim();
+                if (subscriptionType.equalsIgnoreCase("NV")) {
+                    nvSupported = true;
+                }
+                if (subscriptionType.equalsIgnoreCase("RUIM")) {
+                    ruimSupported = true;
+                }
+            }
+        }
+
+        log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
+                " ruimSupported=" + ruimSupported);
+        return (nvSupported && ruimSupported);
+    }
+
+    public boolean preferenceTreeClick(Preference preference) {
+        if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
+            log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
+            return true;
+        }
+        if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
+            log("preferenceTreeClick: return CDMA_SUBSCRIPTION_KEY true");
             return true;
         }
         return false;
     }
+
+    public void showDialog(Preference preference) {
+        if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
+            mButtonCdmaSystemSelect.showDialog(null);
+        } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
+            mButtonCdmaSubscription.showDialog(null);
+        }
+    }
+
+    protected void log(String s) {
+        android.util.Log.d(LOG_TAG, s);
+    }
 }
diff --git a/src/com/android/phone/CdmaSubscriptionListPreference.java b/src/com/android/phone/CdmaSubscriptionListPreference.java
new file mode 100644
index 0000000..c45a6b3
--- /dev/null
+++ b/src/com/android/phone/CdmaSubscriptionListPreference.java
@@ -0,0 +1,131 @@
+/*
+ * 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.Context;
+import android.os.AsyncResult;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.preference.ListPreference;
+import android.provider.Settings.Secure;
+import android.util.AttributeSet;
+import android.util.Log;
+
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneFactory;
+
+public class CdmaSubscriptionListPreference extends ListPreference {
+
+    private static final String LOG_TAG = "CdmaSubscriptionListPreference";
+
+    // Used for CDMA subscription mode
+    private static final int CDMA_SUBSCRIPTION_RUIM_SIM = 0;
+    private static final int CDMA_SUBSCRIPTION_NV = 1;
+
+    //preferredSubscriptionMode  0 - RUIM/SIM, preferred
+    //                           1 - NV
+    static final int preferredSubscriptionMode = CDMA_SUBSCRIPTION_NV;
+
+    private Phone mPhone;
+    private CdmaSubscriptionButtonHandler mHandler;
+
+    public CdmaSubscriptionListPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+
+        mPhone = PhoneFactory.getDefaultPhone();
+        mHandler = new CdmaSubscriptionButtonHandler();
+        setCurrentCdmaSubscriptionModeValue();
+    }
+
+    private void setCurrentCdmaSubscriptionModeValue() {
+        int cdmaSubscriptionMode = Secure.getInt(mPhone.getContext().getContentResolver(),
+                android.provider.Settings.Secure.CDMA_SUBSCRIPTION_MODE, preferredSubscriptionMode);
+        setValue(Integer.toString(cdmaSubscriptionMode));
+    }
+
+    public CdmaSubscriptionListPreference(Context context) {
+        this(context, null);
+    }
+
+    @Override
+    protected void showDialog(Bundle state) {
+        setCurrentCdmaSubscriptionModeValue();
+
+        super.showDialog(state);
+    }
+
+    @Override
+    protected void onDialogClosed(boolean positiveResult) {
+        super.onDialogClosed(positiveResult);
+
+        if (!positiveResult) {
+            //The button was dismissed - no need to set new value
+            return;
+        }
+
+        int buttonCdmaSubscriptionMode = Integer.valueOf(getValue()).intValue();
+        Log.d(LOG_TAG, "Setting new value " + buttonCdmaSubscriptionMode);
+        int statusCdmaSubscriptionMode;
+        switch(buttonCdmaSubscriptionMode) {
+            case CDMA_SUBSCRIPTION_NV:
+                statusCdmaSubscriptionMode = Phone.CDMA_SUBSCRIPTION_NV;
+                break;
+            case CDMA_SUBSCRIPTION_RUIM_SIM:
+                statusCdmaSubscriptionMode = Phone.CDMA_SUBSCRIPTION_RUIM_SIM;
+                break;
+            default:
+                statusCdmaSubscriptionMode = Phone.PREFERRED_CDMA_SUBSCRIPTION;
+        }
+
+        // Set the CDMA subscription mode, when mode has been successfully changed
+        // handleSetCdmaSubscriptionMode will be invoked and the value saved.
+        mPhone.setCdmaSubscription(statusCdmaSubscriptionMode, mHandler
+                .obtainMessage(CdmaSubscriptionButtonHandler.MESSAGE_SET_CDMA_SUBSCRIPTION,
+                        getValue()));
+
+    }
+
+    private class CdmaSubscriptionButtonHandler extends Handler {
+
+        private static final int MESSAGE_SET_CDMA_SUBSCRIPTION = 0;
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MESSAGE_SET_CDMA_SUBSCRIPTION:
+                    handleSetCdmaSubscriptionMode(msg);
+                    break;
+            }
+        }
+
+        private void handleSetCdmaSubscriptionMode(Message msg) {
+            mPhone = PhoneFactory.getDefaultPhone();
+            AsyncResult ar = (AsyncResult) msg.obj;
+
+            if (ar.exception == null) {
+                // Get the original string entered by the user
+                int cdmaSubscriptionMode = Integer.valueOf((String) ar.userObj).intValue();
+                Secure.putInt(mPhone.getContext().getContentResolver(),
+                        Secure.CDMA_SUBSCRIPTION_MODE,
+                        cdmaSubscriptionMode );
+            } else {
+                Log.e(LOG_TAG, "Setting Cdma subscription source failed");
+            }
+        }
+    }
+}
diff --git a/src/com/android/phone/CdmaRoamingListPreference.java b/src/com/android/phone/CdmaSystemSelectListPreference.java
similarity index 96%
rename from src/com/android/phone/CdmaRoamingListPreference.java
rename to src/com/android/phone/CdmaSystemSelectListPreference.java
index 11cca0f..9f41ee1 100644
--- a/src/com/android/phone/CdmaRoamingListPreference.java
+++ b/src/com/android/phone/CdmaSystemSelectListPreference.java
@@ -31,7 +31,7 @@
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.TelephonyProperties;
 
-public class CdmaRoamingListPreference extends ListPreference {
+public class CdmaSystemSelectListPreference extends ListPreference {
 
     private static final String LOG_TAG = "CdmaRoamingListPreference";
     private static final boolean DBG = true;
@@ -39,7 +39,7 @@
     private Phone mPhone;
     private MyHandler mHandler = new MyHandler();;
 
-    public CdmaRoamingListPreference(Context context, AttributeSet attrs) {
+    public CdmaSystemSelectListPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
 
         mPhone = PhoneFactory.getDefaultPhone();
@@ -48,7 +48,7 @@
                 mHandler.obtainMessage(MyHandler.MESSAGE_GET_ROAMING_PREFERENCE));
     }
 
-    public CdmaRoamingListPreference(Context context) {
+    public CdmaSystemSelectListPreference(Context context) {
         this(context, null);
     }
 
diff --git a/src/com/android/phone/GsmUmtsOptions.java b/src/com/android/phone/GsmUmtsOptions.java
index 48411f6..223f4f7 100644
--- a/src/com/android/phone/GsmUmtsOptions.java
+++ b/src/com/android/phone/GsmUmtsOptions.java
@@ -16,7 +16,6 @@
 
 package com.android.phone;
 
-import android.os.Bundle;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
@@ -28,7 +27,8 @@
 /**
  * List of Network-specific settings screens.
  */
-public class GsmUmtsOptions extends PreferenceActivity {
+public class GsmUmtsOptions {
+    private static final String LOG_TAG = "GsmUmtsOptions";
 
     private PreferenceScreen mButtonAPNExpand;
     private PreferenceScreen mButtonOperatorSelectionExpand;
@@ -38,29 +38,39 @@
     private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key";
     private static final String BUTTON_PREFER_2G_KEY = "button_prefer_2g_key";
 
+    private PreferenceActivity mPrefActivity;
+    private PreferenceScreen mPrefScreen;
 
-    @Override
-    protected void onCreate(Bundle icicle) {
-        super.onCreate(icicle);
+    public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen) {
+        mPrefActivity = prefActivity;
+        mPrefScreen = prefScreen;
+        create();
+    }
 
-        addPreferencesFromResource(R.xml.gsm_umts_options);
-        PreferenceScreen prefSet = getPreferenceScreen();
-        mButtonAPNExpand = (PreferenceScreen) prefSet.findPreference(BUTTON_APN_EXPAND_KEY);
+    protected void create() {
+        mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options);
+        mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
         mButtonOperatorSelectionExpand =
-                (PreferenceScreen) prefSet.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
-        mButtonPrefer2g = (CheckBoxPreference) prefSet.findPreference(BUTTON_PREFER_2G_KEY);
+                (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
+        mButtonPrefer2g = (CheckBoxPreference) mPrefScreen.findPreference(BUTTON_PREFER_2G_KEY);
         if (PhoneFactory.getDefaultPhone().getPhoneType() != Phone.PHONE_TYPE_GSM) {
+            log("Not a GSM phone");
             mButtonAPNExpand.setEnabled(false);
             mButtonOperatorSelectionExpand.setEnabled(false);
             mButtonPrefer2g.setEnabled(false);
         }
     }
 
-    @Override
-    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+    public boolean preferenceTreeClick(Preference preference) {
         if (preference.getKey().equals(BUTTON_PREFER_2G_KEY)) {
+            log("preferenceTreeClick: return true");
             return true;
         }
+        log("preferenceTreeClick: return false");
         return false;
     }
+
+    protected void log(String s) {
+        android.util.Log.d(LOG_TAG, s);
+    }
 }
diff --git a/src/com/android/phone/Settings.java b/src/com/android/phone/Settings.java
index 38d45d1..71f8c35 100644
--- a/src/com/android/phone/Settings.java
+++ b/src/com/android/phone/Settings.java
@@ -45,30 +45,27 @@
     // debug data
     private static final String LOG_TAG = "NetworkSettings";
     private static final boolean DBG = true;
-    public static final int REQUEST_CODE_EXIT_ECM         = 17;
+    public static final int REQUEST_CODE_EXIT_ECM = 17;
 
     //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_ROAMING_KEY = "cdma_roaming_mode_key";
-
-    private static final String BUTTON_GSM_UMTS_OPTIONS = "gsm_umts_options_key";
-    private static final String BUTTON_CDMA_OPTIONS = "cdma_options_key";
 
     static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE;
 
     //UI objects
     private ListPreference mButtonPreferredNetworkMode;
     private CheckBoxPreference mButtonDataRoam;
-    private CdmaRoamingListPreference mButtonCdmaRoam;
 
     private Phone mPhone;
     private MyHandler mHandler;
     private boolean mOkClicked;
 
     //GsmUmts options and Cdma options
-    GsmUmtsOptions gsmumtsOptions;
-    CdmaOptions cdmaOptions;
+    GsmUmtsOptions mGsmUmtsOptions;
+    CdmaOptions mCdmaOptions;
+
+    private Preference mClickedPreference;
 
 
     //This is a method implemented for DialogInterface.OnClickListener.
@@ -97,13 +94,17 @@
      */
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
-        if (gsmumtsOptions != null &&
-                gsmumtsOptions.onPreferenceTreeClick(preferenceScreen, preference) == true) {
+        /** TODO: Refactor and get rid of the if's using subclasses */
+        if (mGsmUmtsOptions != null &&
+                mGsmUmtsOptions.preferenceTreeClick(preference) == true) {
             return true;
-        } else if (cdmaOptions != null &&
-                   cdmaOptions.onPreferenceTreeClick(preferenceScreen, preference) == 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),
@@ -117,8 +118,7 @@
                     preferredNetworkMode);
             mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
             return true;
-        }
-        else if (preference == mButtonDataRoam) {
+        } else if (preference == mButtonDataRoam) {
             if (DBG) log("onPreferenceTreeClick: preference == mButtonDataRoam.");
 
             //normally called on the toggle click
@@ -133,13 +133,11 @@
                         .setNegativeButton(android.R.string.no, this)
                         .show()
                         .setOnDismissListener(this);
-            }
-            else {
+            } else {
                 mPhone.setDataRoamingEnabled(false);
             }
             return true;
-        }
-        else {
+        } 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.
@@ -175,22 +173,15 @@
                     getContentResolver(),android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
                     preferredNetworkMode);
             mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
-            // The intent code that resided here in the past has been moved into the
-            // more conventional location in network_setting.xml
-
+            mCdmaOptions = new CdmaOptions(this, prefSet);
+            mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet);
         } else {
             prefSet.removePreference(mButtonPreferredNetworkMode);
-            prefSet.removePreference(prefSet.findPreference(BUTTON_GSM_UMTS_OPTIONS));
-            prefSet.removePreference(prefSet.findPreference(BUTTON_CDMA_OPTIONS));
             int phoneType = mPhone.getPhoneType();
             if (phoneType == Phone.PHONE_TYPE_CDMA) {
-                addPreferencesFromResource(R.xml.cdma_options);
-                mButtonCdmaRoam =
-                    (CdmaRoamingListPreference) prefSet.findPreference(BUTTON_CDMA_ROAMING_KEY);
-                cdmaOptions = new CdmaOptions();
+                mCdmaOptions = new CdmaOptions(this, prefSet);
             } else if (phoneType == Phone.PHONE_TYPE_GSM) {
-                addPreferencesFromResource(R.xml.gsm_umts_options);
-                gsmumtsOptions = new GsmUmtsOptions();
+                mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet);
             } else {
                 throw new IllegalStateException("Unexpected phone type: " + phoneType);
             }
@@ -426,8 +417,8 @@
             Boolean isChoiceYes =
                 data.getBooleanExtra(EmergencyCallbackModeExitDialog.EXTRA_EXIT_ECM_RESULT, false);
             if (isChoiceYes) {
-                // If the phone exits from ECM mode, show the system selection Options
-                mButtonCdmaRoam.showDialog(null);
+                // If the phone exits from ECM mode, show the CDMA Options
+                mCdmaOptions.showDialog(mClickedPreference);
             } else {
                 // do nothing
             }