packages/apps/Phone: CDMA Settings additions
Wink Saville [Thu, 25 Jun 2009 03:31:14 +0000 (20:31 -0700)]
1. Remove "Operator Selection"
2. Add System select menu item that allows user to choose between "Home Only" and "Automatic"
3. To separate CDMA from GSM/UMTS, a new file (network_setting_cdma.xml) is added

res/values/strings.xml
res/xml/network_setting_cdma.xml [new file with mode: 0644]
src/com/android/phone/Settings.java

index 72496e2..89c344a 100644 (file)
         <item>"2"</item>
         <item>"3"</item>
     </string-array>
+
+    <!-- CDMA System select strings -->
+    <!-- Mobile network settings screen, setting option name -->
+    <string name="cdma_system_select_title">System select</string>
+    <!-- Mobile network settings screen, setting summary text -->
+    <string name="cdma_system_select_summary">Change the cdma roaming mode</string>
+    <!-- System select settings screen title -->
+    <string name="cdma_system_select_dialogtitle">System select</string>
+    <string-array name="cdma_system_select_choices">
+        <!-- System select dialog screen, setting option name -->
+        <item>Home only</item>
+        <!-- Remove the following option "Affiliated Networks" from the option list -->
+        <!-- <item>Affiliated Networks</item> -->
+        <!-- System select dialog screen, setting option name -->
+        <item>Automatic</item>
+    </string-array>
+    <string-array name="cdma_system_select_values">
+        <!-- Do not translate. -->
+        <item>"0"</item>
+        <!-- Remove the following value "1" which corresponds to "Affiliated Networks" above -->
+        <!-- <item>"1"</item>  -->
+        <!-- Do not translate. -->
+        <item>"2"</item>
+    </string-array>
+
     <!-- CDMA Options strings --> 
     <string name="cdma_roaming_mode_title">CDMA Roaming Mode</string>
     <string name="cdma_roaming_mode_summary">Change the cdma roaming mode</string>
diff --git a/res/xml/network_setting_cdma.xml b/res/xml/network_setting_cdma.xml
new file mode 100644 (file)
index 0000000..f389bed
--- /dev/null
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:phone="http://schemas.android.com/apk/res/com.android.phone">
+
+    <PreferenceCategory
+        android:title="@string/mobile_networks"/>
+
+    <CheckBoxPreference
+        android:key="button_roaming_key"
+        android:title="@string/roaming"
+        android:persistent="false"
+        android:summaryOn="@string/roaming_enable"
+        android:summaryOff="@string/roaming_disable"/>
+
+    <!--
+    <ListPreference
+        android:key="preferred_network_mode_key"
+        android:title="@string/preferred_network_mode_title"
+        android:summary="@string/preferred_network_mode_summary"
+        android:entries="@array/preferred_network_mode_choices"
+        android:entryValues="@array/preferred_network_mode_values"
+        android:dialogTitle="@string/preferred_network_mode_dialogtitle" />
+    -->
+
+    <ListPreference
+        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" />
+
+    <!--
+    <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>
index ef77917..09ef0aa 100644 (file)
@@ -37,7 +37,7 @@ import com.android.internal.telephony.PhoneFactory;
  */
 public class Settings extends PreferenceActivity implements DialogInterface.OnClickListener,
         DialogInterface.OnDismissListener, Preference.OnPreferenceChangeListener{
-    
+
     // debug data
     private static final String LOG_TAG = "NetworkSettings";
     private static final boolean DBG = true;
@@ -45,18 +45,30 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
     //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_SYSTEM_SELECT_KEY = "cdma_system_select_key";
+
+    // Used for CDMA roaming mode
+    private static final int CDMA_ROAMING_MODE_HOME = 0;
+    private static final int CDMA_ROAMING_MODE_AFFILIATED = 1;
+    private static final int CDMA_ROAMING_MODE_ANY = 2;
+
+    // PREFERRED_CDMA_ROAMING_MODE  0 - Home Networks only, preferred
+    //                              1 - Roaming on affiliated networks
+    //                              2 - Roaming on any network
+    static final int PREFERRED_CDMA_ROAMING_MODE = 0;
+
     static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE;
-    
+
     //UI objects
     private ListPreference mButtonPreferredNetworkMode;
     private CheckBoxPreference mButtonDataRoam;
-    
+    private ListPreference mButtonCdmaRoam;
+
     private Phone mPhone;
     private MyHandler mHandler;
     private boolean mOkClicked;
-        
-    
+
+
     //This is a method implemented for DialogInterface.OnClickListener.
     //  Used to dismiss the dialogs when they come up.
     public void onClick(DialogInterface dialog, int which) {
@@ -68,16 +80,16 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
             mButtonDataRoam.setChecked(false);
         }
     }
-    
+
     public void onDismiss(DialogInterface dialog) {
         // Assuming that onClick gets called first
         if (!mOkClicked) {
             mButtonDataRoam.setChecked(false);
         }
     }
-    
-    /** 
-     * Invoked on each preference click in this hierarchy, overrides 
+
+    /**
+     * Invoked on each preference click in this hierarchy, overrides
      * PreferenceActivity's implementation.  Used to make sure we track the
      * preference click events.
      */
@@ -86,14 +98,14 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
         if (preference == mButtonPreferredNetworkMode) {
             //displays the value taken from the Settings.System
             int settingsNetworkMode = android.provider.Settings.Secure.getInt(mPhone.getContext().
-                    getContentResolver(), android.provider.Settings.Secure.PREFERRED_NETWORK_MODE, 
-                    preferredNetworkMode);            
+                    getContentResolver(), android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
+                    preferredNetworkMode);
             mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
             return true;
         }
         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
@@ -106,12 +118,21 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
                         .setNegativeButton(android.R.string.no, this)
                         .show()
                         .setOnDismissListener(this);
-            } 
+            }
             else {
                 mPhone.setDataRoamingEnabled(false);
             }
             return true;
-        } 
+        }
+        else if (preference == mButtonCdmaRoam) {
+            if (DBG) log("onPreferenceTreeClick: preference == mButtonCdmaRoam.");
+            //displays the value taken from the Settings.System
+            int cdmaRoamingMode = android.provider.Settings.Secure.getInt(
+                    mPhone.getContext().getContentResolver(),
+                    android.provider.Settings.Secure.CDMA_ROAMING_MODE, PREFERRED_CDMA_ROAMING_MODE);
+            mButtonCdmaRoam.setValue(Integer.toString(cdmaRoamingMode));
+            return true;
+        }
         else {
             // if the button is anything but the simple toggle preference,
             // we'll need to disable all preferences to reject all click
@@ -121,52 +142,79 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
             return false;
         }
     }
-    
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
-        addPreferencesFromResource(R.xml.network_setting);
-        
         mPhone = PhoneFactory.getDefaultPhone();
-        mHandler = new MyHandler();
+
+        if (mPhone.getPhoneName().equals("CDMA")) {
+            addPreferencesFromResource(R.xml.network_setting_cdma);
+
+        } else {
+            addPreferencesFromResource(R.xml.network_setting);
+        }
 
         //get UI object references
         PreferenceScreen prefSet = getPreferenceScreen();
 
+        mHandler = new MyHandler();
         mButtonDataRoam = (CheckBoxPreference) prefSet.findPreference(BUTTON_ROAMING_KEY);
-        mButtonPreferredNetworkMode = (ListPreference) prefSet.findPreference(
+
+        // TODO: The radio technology could be changed dynamically after the phone has been created
+        if (mPhone.getPhoneName().equals("CDMA")) {
+            mButtonCdmaRoam =
+                (ListPreference) prefSet.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
+            // set the listener for the mButtonCdmaRoam list preference so we can issue
+            // change CDMA Roaming Mode.
+            mButtonCdmaRoam.setOnPreferenceChangeListener(this);
+
+            //Get the settingsCdmaRoamingMode from Settings.System and displays it
+            int settingsCdmaRoamingMode = android.provider.Settings.Secure.getInt(
+                    mPhone.getContext().getContentResolver(),
+                    android.provider.Settings.Secure.CDMA_ROAMING_MODE,
+                    PREFERRED_CDMA_ROAMING_MODE);
+            mButtonCdmaRoam.setValue(Integer.toString(settingsCdmaRoamingMode));
+        } else {
+            mButtonPreferredNetworkMode = (ListPreference) prefSet.findPreference(
                 BUTTON_PREFERED_NETWORK_MODE);
-        
-        // set the listener for the mButtonPreferredNetworkMode list preference so we can issue 
-        // change Preferred Network Mode.
-        mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this);
-        
-        //Get the networkMode from Settings.System and displays it
-        int settingsNetworkMode = android.provider.Settings.Secure.getInt(mPhone.getContext().
-                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
+
+            // set the listener for the mButtonPreferredNetworkMode list preference so we can issue
+            // change Preferred Network Mode.
+            mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this);
+
+            //Get the networkMode from Settings.System and displays it
+            int settingsNetworkMode = android.provider.Settings.Secure.getInt(mPhone.getContext().
+                 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
+        }
     }
-    
+
     @Override
     protected void onResume() {
         super.onResume();
-        
+
         // 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());
-        mPhone.getPreferredNetworkType(mHandler.obtainMessage(
-                MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE));
+        if (mPhone.getPhoneName().equals("CDMA")) {
+            mPhone.queryCdmaRoamingPreference(
+                    mHandler.obtainMessage(MyHandler.MESSAGE_QUERY_ROAMING_PREFERENCE));
+        } else {
+            mPhone.getPreferredNetworkType(mHandler.obtainMessage(
+                    MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE));
+        }
     }
-    
+
     /**
      * Implemented to support onPreferenceChangeListener to look for preference
      * changes specifically on CLIR.
@@ -186,7 +234,7 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
                     mPhone.getContext().getContentResolver(),
                     android.provider.Settings.Secure.PREFERRED_NETWORK_MODE, preferredNetworkMode);
             if (buttonNetworkMode != settingsNetworkMode) {
-                int modemNetworkMode; 
+                int modemNetworkMode;
                 switch(buttonNetworkMode) {
                     case Phone.NT_MODE_GLOBAL:
                         modemNetworkMode = Phone.NT_MODE_GLOBAL;
@@ -214,16 +262,48 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
                         break;
                     default:
                         modemNetworkMode = Phone.PREFERRED_NT_MODE;
-                } 
+                }
                 UpdatePreferredNetworkModeSummary(buttonNetworkMode);
 
                 android.provider.Settings.Secure.putInt(mPhone.getContext().getContentResolver(),
-                        android.provider.Settings.Secure.PREFERRED_NETWORK_MODE, 
+                        android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
                         buttonNetworkMode );
                 //Set the modem network mode
                 mPhone.setPreferredNetworkType(modemNetworkMode, mHandler
                         .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
             }
+        } else if (preference == mButtonCdmaRoam) {
+            //NOTE onPreferenceChange seems to be called even if there is no change
+            //Check if the button value is changed from the System.Setting
+            mButtonCdmaRoam.setValue((String) objValue);
+            int buttonCdmaRoamingMode;
+            buttonCdmaRoamingMode = Integer.valueOf((String) objValue).intValue();
+            int settingsCdmaRoamingMode = android.provider.Settings.Secure.getInt(
+                    mPhone.getContext().getContentResolver(),
+                    android.provider.Settings.Secure.CDMA_ROAMING_MODE, PREFERRED_CDMA_ROAMING_MODE);
+            if (buttonCdmaRoamingMode != settingsCdmaRoamingMode) {
+                int statusCdmaRoamingMode;
+                switch(buttonCdmaRoamingMode) {
+                    case CDMA_ROAMING_MODE_ANY:
+                        statusCdmaRoamingMode = Phone.CDMA_RM_ANY;
+                        break;
+                        /*
+                    case CDMA_ROAMING_MODE_AFFILIATED:
+                        statusCdmaRoamingMode = Phone.CDMA_RM_AFFILIATED;
+                        break;
+                        */
+                    case CDMA_ROAMING_MODE_HOME:
+                    default:
+                        statusCdmaRoamingMode = Phone.CDMA_RM_HOME;
+                }
+                //Set the Settings.System network mode
+                android.provider.Settings.Secure.putInt(mPhone.getContext().getContentResolver(),
+                        android.provider.Settings.Secure.CDMA_ROAMING_MODE,
+                        buttonCdmaRoamingMode );
+                //Set the roaming preference mode
+                mPhone.setCdmaRoamingPreference(statusCdmaRoamingMode, mHandler
+                        .obtainMessage(MyHandler.MESSAGE_SET_ROAMING_PREFERENCE));
+            }
         }
 
         // always let the preference setting proceed.
@@ -234,43 +314,52 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
 
         private static final int MESSAGE_GET_PREFERRED_NETWORK_TYPE = 0;
         private static final int MESSAGE_SET_PREFERRED_NETWORK_TYPE = 1;
-        
+        private static final int MESSAGE_QUERY_ROAMING_PREFERENCE = 2;
+        private static final int MESSAGE_SET_ROAMING_PREFERENCE = 3;
+
         @Override
         public void handleMessage(Message msg) {
             switch (msg.what) {
                 case MESSAGE_GET_PREFERRED_NETWORK_TYPE:
                     handleGetPreferredNetworkTypeResponse(msg);
                     break;
-                    
+
                 case MESSAGE_SET_PREFERRED_NETWORK_TYPE:
                     handleSetPreferredNetworkTypeResponse(msg);
                     break;
-            }
+                case MESSAGE_QUERY_ROAMING_PREFERENCE:
+                    handleQueryCdmaRoamingPreference(msg);
+                    break;
+
+                case MESSAGE_SET_ROAMING_PREFERENCE:
+                    handleSetCdmaRoamingPreference(msg);
+                    break;
+             }
         }
-        
+
         private void handleGetPreferredNetworkTypeResponse(Message msg) {
             AsyncResult ar = (AsyncResult) msg.obj;
-            
+
             if (ar.exception == null) {
                 int modemNetworkMode = ((int[])ar.result)[0];
-                
+
                 if (DBG) {
-                    log ("handleGetPreferredNetworkTypeResponse: modemNetworkMode = " + 
+                    log ("handleGetPreferredNetworkTypeResponse: modemNetworkMode = " +
                             modemNetworkMode);
                 }
-                
+
                 int settingsNetworkMode = android.provider.Settings.Secure.getInt(
                         mPhone.getContext().getContentResolver(),
-                        android.provider.Settings.Secure.PREFERRED_NETWORK_MODE, 
+                        android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
                         preferredNetworkMode);
-                
+
                 if (DBG) {
-                    log("handleGetPreferredNetworkTypeReponse: settingsNetworkMode = " + 
+                    log("handleGetPreferredNetworkTypeReponse: settingsNetworkMode = " +
                             settingsNetworkMode);
                 }
-                
+
                 //check that modemNetworkMode is from an accepted value
-                if (modemNetworkMode == Phone.NT_MODE_WCDMA_PREF ||  
+                if (modemNetworkMode == Phone.NT_MODE_WCDMA_PREF ||
                         modemNetworkMode == Phone.NT_MODE_GSM_ONLY ||
                         modemNetworkMode == Phone.NT_MODE_WCDMA_ONLY ||
                         modemNetworkMode == Phone.NT_MODE_GSM_UMTS ||
@@ -279,33 +368,33 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
                         modemNetworkMode == Phone.NT_MODE_EVDO_NO_CDMA ||
                         modemNetworkMode == Phone.NT_MODE_GLOBAL ) {
                     if (DBG) {
-                        log("handleGetPreferredNetworkTypeResponse: if 1: modemNetworkMode = " + 
+                        log("handleGetPreferredNetworkTypeResponse: if 1: modemNetworkMode = " +
                                 modemNetworkMode);
                     }
-                
-                    //check changes in modemNetworkMode and updates settingsNetworkMode 
+
+                    //check changes in modemNetworkMode and updates settingsNetworkMode
                     if (modemNetworkMode != settingsNetworkMode) {
                         if (DBG) {
                             log("handleGetPreferredNetworkTypeResponse: if 2: " +
                                     "modemNetworkMode != settingsNetworkMode");
                         }
-                        
+
                         settingsNetworkMode = modemNetworkMode;
-                        
-                        if (DBG) { log("handleGetPreferredNetworkTypeResponse: if 2: " + 
+
+                        if (DBG) { log("handleGetPreferredNetworkTypeResponse: if 2: " +
                                 "settingsNetworkMode = " + settingsNetworkMode);
                         }
-                        
+
                         //changes the Settings.System accordingly to modemNetworkMode
                         android.provider.Settings.Secure.putInt(
                                 mPhone.getContext().getContentResolver(),
-                                android.provider.Settings.Secure.PREFERRED_NETWORK_MODE, 
+                                android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
                                 settingsNetworkMode );
                     }
 
                     UpdatePreferredNetworkModeSummary(modemNetworkMode);
                     // changes the mButtonPreferredNetworkMode accordingly to modemNetworkMode
-                    mButtonPreferredNetworkMode.setValue(Integer.toString(modemNetworkMode)); 
+                    mButtonPreferredNetworkMode.setValue(Integer.toString(modemNetworkMode));
                 } else {
                     if (DBG) log("handleGetPreferredNetworkTypeResponse: else: reset to default");
                     resetNetworkModeToDefault();
@@ -320,26 +409,88 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
                 int networkMode = Integer.valueOf(
                         mButtonPreferredNetworkMode.getValue()).intValue();
                 android.provider.Settings.Secure.putInt(mPhone.getContext().getContentResolver(),
-                        android.provider.Settings.Secure.PREFERRED_NETWORK_MODE, 
+                        android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
                         networkMode );
             } else {
                 mPhone.getPreferredNetworkType(obtainMessage(MESSAGE_GET_PREFERRED_NETWORK_TYPE));
             }
         }
-        
+
         private void resetNetworkModeToDefault() {
             //set the mButtonPreferredNetworkMode
             mButtonPreferredNetworkMode.setValue(Integer.toString(preferredNetworkMode));
-            //set the Settings.System 
+            //set the Settings.System
             android.provider.Settings.Secure.putInt(mPhone.getContext().getContentResolver(),
-                        android.provider.Settings.Secure.PREFERRED_NETWORK_MODE, 
-                        preferredNetworkMode );            
+                        android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
+                        preferredNetworkMode );
             //Set the Modem
-            mPhone.setPreferredNetworkType(preferredNetworkMode, 
+            mPhone.setPreferredNetworkType(preferredNetworkMode,
                     this.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
         }
+
+        private void handleQueryCdmaRoamingPreference(Message msg) {
+            mPhone = PhoneFactory.getDefaultPhone();
+            AsyncResult ar = (AsyncResult) msg.obj;
+
+            if (ar.exception == null) {
+                int statusCdmaRoamingMode = ((int[])ar.result)[0];
+                int settingsRoamingMode = android.provider.Settings.Secure.getInt(
+                        mPhone.getContext().getContentResolver(),
+                        android.provider.Settings.Secure.CDMA_ROAMING_MODE,
+                        PREFERRED_CDMA_ROAMING_MODE);
+                //check that statusCdmaRoamingMode is from an accepted value
+                if (statusCdmaRoamingMode == Phone.CDMA_RM_HOME ||
+                        statusCdmaRoamingMode == Phone.CDMA_RM_AFFILIATED ||
+                        statusCdmaRoamingMode == Phone.CDMA_RM_ANY ) {
+                    //check changes in statusCdmaRoamingMode and updates settingsRoamingMode
+                    if (statusCdmaRoamingMode != settingsRoamingMode) {
+                        settingsRoamingMode = statusCdmaRoamingMode;
+                        //changes the Settings.System accordingly to statusCdmaRoamingMode
+                        android.provider.Settings.Secure.putInt(
+                                mPhone.getContext().getContentResolver(),
+                                android.provider.Settings.Secure.CDMA_ROAMING_MODE,
+                                settingsRoamingMode );
+                    }
+                    //changes the mButtonPreferredNetworkMode accordingly to modemNetworkMode
+                    mButtonCdmaRoam.setValue(
+                            Integer.toString(statusCdmaRoamingMode));
+                } else {
+                    resetCdmaRoamingModeToDefault();
+                }
+            }
+        }
+
+        private void handleSetCdmaRoamingPreference(Message msg) {
+            mPhone = PhoneFactory.getDefaultPhone();
+            AsyncResult ar = (AsyncResult) msg.obj;
+
+            if (ar.exception == null) {
+                int cdmaRoamingMode = Integer.valueOf(mButtonCdmaRoam.getValue()).intValue();
+                android.provider.Settings.Secure.putInt(mPhone.getContext().getContentResolver(),
+                        android.provider.Settings.Secure.CDMA_ROAMING_MODE,
+                        cdmaRoamingMode );
+            } else {
+                mPhone.queryCdmaRoamingPreference(obtainMessage(MESSAGE_QUERY_ROAMING_PREFERENCE));
+            }
+        }
+
+        private void resetCdmaRoamingModeToDefault() {
+            mPhone = PhoneFactory.getDefaultPhone();
+            //set cdmaRoamingMode to default
+            int cdmaRoamingMode = PREFERRED_CDMA_ROAMING_MODE;
+            int statusCdmaRoamingMode = Phone.CDMA_RM_HOME;
+            //set the mButtonCdmaRoam
+            mButtonCdmaRoam.setValue(Integer.toString(cdmaRoamingMode));
+            //set the Settings.System
+            android.provider.Settings.Secure.putInt(mPhone.getContext().getContentResolver(),
+                        android.provider.Settings.Secure.CDMA_ROAMING_MODE,
+                        cdmaRoamingMode );
+            //Set the Status
+            mPhone.setCdmaRoamingPreference(statusCdmaRoamingMode,
+                    this.obtainMessage(MyHandler.MESSAGE_SET_ROAMING_PREFERENCE));
+        }
     }
-        
+
     private void UpdatePreferredNetworkModeSummary(int NetworkMode) {
         switch(NetworkMode) {
             case Phone.NT_MODE_WCDMA_PREF:
@@ -369,7 +520,7 @@ public class Settings extends PreferenceActivity implements DialogInterface.OnCl
                 mButtonPreferredNetworkMode.setSummary("Preferred network mode: Global");
         }
     }
-    
+
     private static void log(String msg) {
         Log.d(LOG_TAG, msg);
     }