1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.phone; 18 19 import com.android.internal.telephony.Phone; 20 import com.android.internal.telephony.PhoneConstants; 21 import com.android.internal.telephony.TelephonyIntents; 22 import com.android.internal.telephony.TelephonyProperties; 23 24 import android.app.ActionBar; 25 import android.app.AlertDialog; 26 import android.content.Context; 27 import android.content.DialogInterface; 28 import android.content.Intent; 29 import android.content.pm.PackageManager.NameNotFoundException; 30 import android.net.ConnectivityManager; 31 import android.net.Uri; 32 import android.os.AsyncResult; 33 import android.os.Bundle; 34 import android.os.Handler; 35 import android.os.Message; 36 import android.os.SystemProperties; 37 import android.preference.CheckBoxPreference; 38 import android.preference.ListPreference; 39 import android.preference.Preference; 40 import android.preference.PreferenceActivity; 41 import android.preference.PreferenceScreen; 42 import android.telephony.TelephonyManager; 43 import android.text.TextUtils; 44 import android.util.Log; 45 import android.view.MenuItem; 46 47 /** 48 * "Mobile network settings" screen. This preference screen lets you 49 * enable/disable mobile data, and control data roaming and other 50 * network-specific mobile data features. It's used on non-voice-capable 51 * tablets as well as regular phone devices. 52 * 53 * Note that this PreferenceActivity is part of the phone app, even though 54 * you reach it from the "Wireless & Networks" section of the main 55 * Settings app. It's not part of the "Call settings" hierarchy that's 56 * available from the Phone app (see CallFeaturesSetting for that.) 57 */ 58 public class MobileNetworkSettings extends PreferenceActivity 59 implements DialogInterface.OnClickListener, 60 DialogInterface.OnDismissListener, Preference.OnPreferenceChangeListener{ 61 62 // debug data 63 private static final String LOG_TAG = "NetworkSettings"; 64 private static final boolean DBG = true; 65 public static final int REQUEST_CODE_EXIT_ECM = 17; 66 67 //String keys for preference lookup 68 private static final String BUTTON_DATA_ENABLED_KEY = "button_data_enabled_key"; 69 private static final String BUTTON_PREFERED_NETWORK_MODE = "preferred_network_mode_key"; 70 private static final String BUTTON_ROAMING_KEY = "button_roaming_key"; 71 private static final String BUTTON_CDMA_LTE_DATA_SERVICE_KEY = "cdma_lte_data_service_key"; 72 private static final String BUTTON_ENABLED_NETWORKS_KEY = "enabled_networks_key"; 73 private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key"; 74 75 static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE; 76 77 //Information about logical "up" Activity 78 private static final String UP_ACTIVITY_PACKAGE = "com.android.settings"; 79 private static final String UP_ACTIVITY_CLASS = 80 "com.android.settings.Settings$WirelessSettingsActivity"; 81 82 //UI objects 83 private ListPreference mButtonPreferredNetworkMode; 84 private ListPreference mButtonEnabledNetworks; 85 private CheckBoxPreference mButtonDataRoam; 86 private CheckBoxPreference mButtonDataEnabled; 87 private Preference mLteDataServicePref; 88 89 private static final String iface = "rmnet0"; //TODO: this will go away 90 91 private Phone mPhone; 92 private MyHandler mHandler; 93 private boolean mOkClicked; 94 95 //GsmUmts options and Cdma options 96 GsmUmtsOptions mGsmUmtsOptions; 97 CdmaOptions mCdmaOptions; 98 99 private Preference mClickedPreference; 100 private boolean mShow4GForLTE; 101 private boolean mIsGlobalCdma; 102 103 //This is a method implemented for DialogInterface.OnClickListener. 104 // Used to dismiss the dialogs when they come up. 105 public void onClick(DialogInterface dialog, int which) { 106 if (which == DialogInterface.BUTTON_POSITIVE) { 107 mPhone.setDataRoamingEnabled(true); 108 mOkClicked = true; 109 } else { 110 // Reset the toggle 111 mButtonDataRoam.setChecked(false); 112 } 113 } 114 115 public void onDismiss(DialogInterface dialog) { 116 // Assuming that onClick gets called first 117 if (!mOkClicked) { 118 mButtonDataRoam.setChecked(false); 119 } 120 } 121 122 /** 123 * Invoked on each preference click in this hierarchy, overrides 124 * PreferenceActivity's implementation. Used to make sure we track the 125 * preference click events. 126 */ 127 @Override 128 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { 129 /** TODO: Refactor and get rid of the if's using subclasses */ 130 if (mGsmUmtsOptions != null && 131 mGsmUmtsOptions.preferenceTreeClick(preference) == true) { 132 return true; 133 } else if (mCdmaOptions != null && 134 mCdmaOptions.preferenceTreeClick(preference) == true) { 135 if (Boolean.parseBoolean( 136 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { 137 138 mClickedPreference = preference; 139 140 // In ECM mode launch ECM app dialog 141 startActivityForResult( 142 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null), 143 REQUEST_CODE_EXIT_ECM); 144 } 145 return true; 146 } else if (preference == mButtonPreferredNetworkMode) { 147 //displays the value taken from the Settings.System 148 int settingsNetworkMode = android.provider.Settings.Global.getInt(mPhone.getContext(). 149 getContentResolver(), android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 150 preferredNetworkMode); 151 mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode)); 152 return true; 153 } else if (preference == mButtonDataRoam) { 154 if (DBG) log("onPreferenceTreeClick: preference == mButtonDataRoam."); 155 156 //normally called on the toggle click 157 if (mButtonDataRoam.isChecked()) { 158 // First confirm with a warning dialog about charges 159 mOkClicked = false; 160 new AlertDialog.Builder(this).setMessage( 161 getResources().getString(R.string.roaming_warning)) 162 .setTitle(android.R.string.dialog_alert_title) 163 .setIconAttribute(android.R.attr.alertDialogIcon) 164 .setPositiveButton(android.R.string.yes, this) 165 .setNegativeButton(android.R.string.no, this) 166 .show() 167 .setOnDismissListener(this); 168 } else { 169 mPhone.setDataRoamingEnabled(false); 170 } 171 return true; 172 } else if (preference == mButtonDataEnabled) { 173 if (DBG) log("onPreferenceTreeClick: preference == mButtonDataEnabled."); 174 ConnectivityManager cm = 175 (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); 176 177 cm.setMobileDataEnabled(mButtonDataEnabled.isChecked()); 178 return true; 179 } else if (preference == mLteDataServicePref) { 180 String tmpl = android.provider.Settings.Global.getString(getContentResolver(), 181 android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL); 182 if (!TextUtils.isEmpty(tmpl)) { 183 TelephonyManager tm = (TelephonyManager) getSystemService( 184 Context.TELEPHONY_SERVICE); 185 String imsi = tm.getSubscriberId(); 186 if (imsi == null) { 187 imsi = ""; 188 } 189 final String url = TextUtils.isEmpty(tmpl) ? null 190 : TextUtils.expandTemplate(tmpl, imsi).toString(); 191 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 192 startActivity(intent); 193 } else { 194 android.util.Log.e(LOG_TAG, "Missing SETUP_PREPAID_DATA_SERVICE_URL"); 195 } 196 return true; 197 } else if (preference == mButtonEnabledNetworks) { 198 int settingsNetworkMode = android.provider.Settings.Global.getInt(mPhone.getContext(). 199 getContentResolver(), android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 200 preferredNetworkMode); 201 mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode)); 202 return true; 203 } else { 204 // if the button is anything but the simple toggle preference, 205 // we'll need to disable all preferences to reject all click 206 // events until the sub-activity's UI comes up. 207 preferenceScreen.setEnabled(false); 208 // Let the intents be launched by the Preference manager 209 return false; 210 } 211 } 212 213 @Override 214 protected void onCreate(Bundle icicle) { 215 super.onCreate(icicle); 216 217 addPreferencesFromResource(R.xml.network_setting); 218 219 mPhone = PhoneGlobals.getPhone(); 220 mHandler = new MyHandler(); 221 222 try { 223 Context con = createPackageContext("com.android.systemui", 0); 224 int id = con.getResources().getIdentifier("config_show4GForLTE", 225 "bool", "com.android.systemui"); 226 mShow4GForLTE = con.getResources().getBoolean(id); 227 } catch (NameNotFoundException e) { 228 loge("NameNotFoundException for show4GFotLTE"); 229 mShow4GForLTE = false; 230 } 231 232 //get UI object references 233 PreferenceScreen prefSet = getPreferenceScreen(); 234 235 mButtonDataEnabled = (CheckBoxPreference) prefSet.findPreference(BUTTON_DATA_ENABLED_KEY); 236 mButtonDataRoam = (CheckBoxPreference) prefSet.findPreference(BUTTON_ROAMING_KEY); 237 mButtonPreferredNetworkMode = (ListPreference) prefSet.findPreference( 238 BUTTON_PREFERED_NETWORK_MODE); 239 mButtonEnabledNetworks = (ListPreference) prefSet.findPreference( 240 BUTTON_ENABLED_NETWORKS_KEY); 241 242 mLteDataServicePref = prefSet.findPreference(BUTTON_CDMA_LTE_DATA_SERVICE_KEY); 243 244 boolean isLteOnCdma = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE; 245 mIsGlobalCdma = isLteOnCdma && getResources().getBoolean(R.bool.config_show_cdma); 246 if (getResources().getBoolean(R.bool.world_phone) == true) { 247 prefSet.removePreference(mButtonEnabledNetworks); 248 // set the listener for the mButtonPreferredNetworkMode list preference so we can issue 249 // change Preferred Network Mode. 250 mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this); 251 252 //Get the networkMode from Settings.System and displays it 253 int settingsNetworkMode = android.provider.Settings.Global.getInt(mPhone.getContext(). 254 getContentResolver(),android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 255 preferredNetworkMode); 256 mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode)); 257 mCdmaOptions = new CdmaOptions(this, prefSet, mPhone); 258 mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet); 259 } else { 260 prefSet.removePreference(mButtonPreferredNetworkMode); 261 int phoneType = mPhone.getPhoneType(); 262 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { 263 if (isLteOnCdma) { 264 mButtonEnabledNetworks.setEntries( 265 R.array.enabled_networks_cdma_choices); 266 mButtonEnabledNetworks.setEntryValues( 267 R.array.enabled_networks_cdma_values); 268 } 269 mCdmaOptions = new CdmaOptions(this, prefSet, mPhone); 270 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { 271 if (!getResources().getBoolean(R.bool.config_prefer_2g) 272 && !getResources().getBoolean(R.bool.config_enabled_lte)) { 273 mButtonEnabledNetworks.setEntries( 274 R.array.enabled_networks_except_gsm_lte_choices); 275 mButtonEnabledNetworks.setEntryValues( 276 R.array.enabled_networks_except_gsm_lte_values); 277 } else if (!getResources().getBoolean(R.bool.config_prefer_2g)) { 278 int select = (mShow4GForLTE == true) ? 279 R.array.enabled_networks_except_gsm_4g_choices 280 : R.array.enabled_networks_except_gsm_choices; 281 mButtonEnabledNetworks.setEntries(select); 282 mButtonEnabledNetworks.setEntryValues( 283 R.array.enabled_networks_except_gsm_values); 284 } else if (!getResources().getBoolean(R.bool.config_enabled_lte)) { 285 mButtonEnabledNetworks.setEntries( 286 R.array.enabled_networks_except_lte_choices); 287 mButtonEnabledNetworks.setEntryValues( 288 R.array.enabled_networks_except_lte_values); 289 } else if (mIsGlobalCdma) { 290 mButtonEnabledNetworks.setEntries( 291 R.array.enabled_networks_cdma_choices); 292 mButtonEnabledNetworks.setEntryValues( 293 R.array.enabled_networks_cdma_values); 294 } else { 295 int select = (mShow4GForLTE == true) ? R.array.enabled_networks_4g_choices 296 : R.array.enabled_networks_choices; 297 mButtonEnabledNetworks.setEntries(select); 298 mButtonEnabledNetworks.setEntryValues( 299 R.array.enabled_networks_values); 300 } 301 mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet); 302 } else { 303 throw new IllegalStateException("Unexpected phone type: " + phoneType); 304 } 305 mButtonEnabledNetworks.setOnPreferenceChangeListener(this); 306 int settingsNetworkMode = android.provider.Settings.Global.getInt( 307 mPhone.getContext().getContentResolver(), 308 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 309 preferredNetworkMode); 310 if (DBG) log("settingsNetworkMode: " + settingsNetworkMode); 311 mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode)); 312 } 313 314 final boolean missingDataServiceUrl = TextUtils.isEmpty( 315 android.provider.Settings.Global.getString(getContentResolver(), 316 android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL)); 317 if (!isLteOnCdma || missingDataServiceUrl) { 318 prefSet.removePreference(mLteDataServicePref); 319 } else { 320 android.util.Log.d(LOG_TAG, "keep ltePref"); 321 } 322 323 // Read platform settings for carrier settings 324 final boolean isCarrierSettingsEnabled = getResources().getBoolean( 325 R.bool.config_carrier_settings_enable); 326 if (!isCarrierSettingsEnabled) { 327 Preference pref = prefSet.findPreference(BUTTON_CARRIER_SETTINGS_KEY); 328 if (pref != null) { 329 prefSet.removePreference(pref); 330 } 331 } 332 333 ActionBar actionBar = getActionBar(); 334 if (actionBar != null) { 335 // android.R.id.home will be triggered in onOptionsItemSelected() 336 actionBar.setDisplayHomeAsUpEnabled(true); 337 } 338 } 339 340 @Override 341 protected void onResume() { 342 super.onResume(); 343 344 // upon resumption from the sub-activity, make sure we re-enable the 345 // preferences. 346 getPreferenceScreen().setEnabled(true); 347 348 ConnectivityManager cm = 349 (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); 350 mButtonDataEnabled.setChecked(cm.getMobileDataEnabled()); 351 352 // Set UI state in onResume because a user could go home, launch some 353 // app to change this setting's backend, and re-launch this settings app 354 // and the UI state would be inconsistent with actual state 355 mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled()); 356 357 if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null) { 358 mPhone.getPreferredNetworkType(mHandler.obtainMessage( 359 MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE)); 360 } 361 362 if (getPreferenceScreen().findPreference(BUTTON_ENABLED_NETWORKS_KEY) != null) { 363 mPhone.getPreferredNetworkType(mHandler.obtainMessage( 364 MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE)); 365 } 366 } 367 368 @Override 369 protected void onPause() { 370 super.onPause(); 371 } 372 373 /** 374 * Implemented to support onPreferenceChangeListener to look for preference 375 * changes specifically on CLIR. 376 * 377 * @param preference is the preference to be changed, should be mButtonCLIR. 378 * @param objValue should be the value of the selection, NOT its localized 379 * display value. 380 */ 381 public boolean onPreferenceChange(Preference preference, Object objValue) { 382 if (preference == mButtonPreferredNetworkMode) { 383 //NOTE onPreferenceChange seems to be called even if there is no change 384 //Check if the button value is changed from the System.Setting 385 mButtonPreferredNetworkMode.setValue((String) objValue); 386 int buttonNetworkMode; 387 buttonNetworkMode = Integer.valueOf((String) objValue).intValue(); 388 int settingsNetworkMode = android.provider.Settings.Global.getInt( 389 mPhone.getContext().getContentResolver(), 390 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, preferredNetworkMode); 391 if (buttonNetworkMode != settingsNetworkMode) { 392 int modemNetworkMode; 393 // if new mode is invalid ignore it 394 switch (buttonNetworkMode) { 395 case Phone.NT_MODE_WCDMA_PREF: 396 case Phone.NT_MODE_GSM_ONLY: 397 case Phone.NT_MODE_WCDMA_ONLY: 398 case Phone.NT_MODE_GSM_UMTS: 399 case Phone.NT_MODE_CDMA: 400 case Phone.NT_MODE_CDMA_NO_EVDO: 401 case Phone.NT_MODE_EVDO_NO_CDMA: 402 case Phone.NT_MODE_GLOBAL: 403 case Phone.NT_MODE_LTE_CDMA_AND_EVDO: 404 case Phone.NT_MODE_LTE_GSM_WCDMA: 405 case Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA: 406 case Phone.NT_MODE_LTE_ONLY: 407 case Phone.NT_MODE_LTE_WCDMA: 408 // This is one of the modes we recognize 409 modemNetworkMode = buttonNetworkMode; 410 break; 411 default: 412 loge("Invalid Network Mode (" + buttonNetworkMode + ") chosen. Ignore."); 413 return true; 414 } 415 416 UpdatePreferredNetworkModeSummary(buttonNetworkMode); 417 418 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), 419 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 420 buttonNetworkMode ); 421 //Set the modem network mode 422 mPhone.setPreferredNetworkType(modemNetworkMode, mHandler 423 .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)); 424 } 425 } else if (preference == mButtonEnabledNetworks) { 426 mButtonEnabledNetworks.setValue((String) objValue); 427 int buttonNetworkMode; 428 buttonNetworkMode = Integer.valueOf((String) objValue).intValue(); 429 if (DBG) log("buttonNetworkMode: " + buttonNetworkMode); 430 int settingsNetworkMode = android.provider.Settings.Global.getInt( 431 mPhone.getContext().getContentResolver(), 432 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, preferredNetworkMode); 433 if (buttonNetworkMode != settingsNetworkMode) { 434 int modemNetworkMode; 435 // if new mode is invalid ignore it 436 switch (buttonNetworkMode) { 437 case Phone.NT_MODE_WCDMA_PREF: 438 case Phone.NT_MODE_GSM_ONLY: 439 case Phone.NT_MODE_LTE_GSM_WCDMA: 440 case Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA: 441 case Phone.NT_MODE_CDMA: 442 case Phone.NT_MODE_CDMA_NO_EVDO: 443 case Phone.NT_MODE_LTE_CDMA_AND_EVDO: 444 // This is one of the modes we recognize 445 modemNetworkMode = buttonNetworkMode; 446 break; 447 default: 448 loge("Invalid Network Mode (" + buttonNetworkMode + ") chosen. Ignore."); 449 return true; 450 } 451 452 UpdateEnabledNetworksValueAndSummary(buttonNetworkMode); 453 454 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), 455 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 456 buttonNetworkMode ); 457 //Set the modem network mode 458 mPhone.setPreferredNetworkType(modemNetworkMode, mHandler 459 .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)); 460 } 461 } 462 463 // always let the preference setting proceed. 464 return true; 465 } 466 467 private class MyHandler extends Handler { 468 469 static final int MESSAGE_GET_PREFERRED_NETWORK_TYPE = 0; 470 static final int MESSAGE_SET_PREFERRED_NETWORK_TYPE = 1; 471 472 @Override 473 public void handleMessage(Message msg) { 474 switch (msg.what) { 475 case MESSAGE_GET_PREFERRED_NETWORK_TYPE: 476 handleGetPreferredNetworkTypeResponse(msg); 477 break; 478 479 case MESSAGE_SET_PREFERRED_NETWORK_TYPE: 480 handleSetPreferredNetworkTypeResponse(msg); 481 break; 482 } 483 } 484 485 private void handleGetPreferredNetworkTypeResponse(Message msg) { 486 AsyncResult ar = (AsyncResult) msg.obj; 487 488 if (ar.exception == null) { 489 int modemNetworkMode = ((int[])ar.result)[0]; 490 491 if (DBG) { 492 log ("handleGetPreferredNetworkTypeResponse: modemNetworkMode = " + 493 modemNetworkMode); 494 } 495 496 int settingsNetworkMode = android.provider.Settings.Global.getInt( 497 mPhone.getContext().getContentResolver(), 498 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 499 preferredNetworkMode); 500 501 if (DBG) { 502 log("handleGetPreferredNetworkTypeReponse: settingsNetworkMode = " + 503 settingsNetworkMode); 504 } 505 506 //check that modemNetworkMode is from an accepted value 507 if (modemNetworkMode == Phone.NT_MODE_WCDMA_PREF || 508 modemNetworkMode == Phone.NT_MODE_GSM_ONLY || 509 modemNetworkMode == Phone.NT_MODE_WCDMA_ONLY || 510 modemNetworkMode == Phone.NT_MODE_GSM_UMTS || 511 modemNetworkMode == Phone.NT_MODE_CDMA || 512 modemNetworkMode == Phone.NT_MODE_CDMA_NO_EVDO || 513 modemNetworkMode == Phone.NT_MODE_EVDO_NO_CDMA || 514 modemNetworkMode == Phone.NT_MODE_GLOBAL || 515 modemNetworkMode == Phone.NT_MODE_LTE_CDMA_AND_EVDO || 516 modemNetworkMode == Phone.NT_MODE_LTE_GSM_WCDMA || 517 modemNetworkMode == Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA || 518 modemNetworkMode == Phone.NT_MODE_LTE_ONLY || 519 modemNetworkMode == Phone.NT_MODE_LTE_WCDMA) { 520 if (DBG) { 521 log("handleGetPreferredNetworkTypeResponse: if 1: modemNetworkMode = " + 522 modemNetworkMode); 523 } 524 525 //check changes in modemNetworkMode and updates settingsNetworkMode 526 if (modemNetworkMode != settingsNetworkMode) { 527 if (DBG) { 528 log("handleGetPreferredNetworkTypeResponse: if 2: " + 529 "modemNetworkMode != settingsNetworkMode"); 530 } 531 532 settingsNetworkMode = modemNetworkMode; 533 534 if (DBG) { log("handleGetPreferredNetworkTypeResponse: if 2: " + 535 "settingsNetworkMode = " + settingsNetworkMode); 536 } 537 538 //changes the Settings.System accordingly to modemNetworkMode 539 android.provider.Settings.Global.putInt( 540 mPhone.getContext().getContentResolver(), 541 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 542 settingsNetworkMode ); 543 } 544 545 UpdatePreferredNetworkModeSummary(modemNetworkMode); 546 UpdateEnabledNetworksValueAndSummary(modemNetworkMode); 547 // changes the mButtonPreferredNetworkMode accordingly to modemNetworkMode 548 mButtonPreferredNetworkMode.setValue(Integer.toString(modemNetworkMode)); 549 } else { 550 if (DBG) log("handleGetPreferredNetworkTypeResponse: else: reset to default"); 551 resetNetworkModeToDefault(); 552 } 553 } 554 } 555 556 private void handleSetPreferredNetworkTypeResponse(Message msg) { 557 AsyncResult ar = (AsyncResult) msg.obj; 558 559 if (ar.exception == null) { 560 int networkMode = Integer.valueOf( 561 mButtonPreferredNetworkMode.getValue()).intValue(); 562 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), 563 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 564 networkMode ); 565 networkMode = Integer.valueOf( 566 mButtonEnabledNetworks.getValue()).intValue(); 567 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), 568 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 569 networkMode ); 570 } else { 571 mPhone.getPreferredNetworkType(obtainMessage(MESSAGE_GET_PREFERRED_NETWORK_TYPE)); 572 } 573 } 574 575 private void resetNetworkModeToDefault() { 576 //set the mButtonPreferredNetworkMode 577 mButtonPreferredNetworkMode.setValue(Integer.toString(preferredNetworkMode)); 578 mButtonEnabledNetworks.setValue(Integer.toString(preferredNetworkMode)); 579 //set the Settings.System 580 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), 581 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 582 preferredNetworkMode ); 583 //Set the Modem 584 mPhone.setPreferredNetworkType(preferredNetworkMode, 585 this.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)); 586 } 587 } 588 589 private void UpdatePreferredNetworkModeSummary(int NetworkMode) { 590 switch(NetworkMode) { 591 case Phone.NT_MODE_WCDMA_PREF: 592 mButtonPreferredNetworkMode.setSummary( 593 R.string.preferred_network_mode_wcdma_perf_summary); 594 break; 595 case Phone.NT_MODE_GSM_ONLY: 596 mButtonPreferredNetworkMode.setSummary( 597 R.string.preferred_network_mode_gsm_only_summary); 598 break; 599 case Phone.NT_MODE_WCDMA_ONLY: 600 mButtonPreferredNetworkMode.setSummary( 601 R.string.preferred_network_mode_wcdma_only_summary); 602 break; 603 case Phone.NT_MODE_GSM_UMTS: 604 mButtonPreferredNetworkMode.setSummary( 605 R.string.preferred_network_mode_gsm_wcdma_summary); 606 break; 607 case Phone.NT_MODE_CDMA: 608 switch (mPhone.getLteOnCdmaMode()) { 609 case PhoneConstants.LTE_ON_CDMA_TRUE: 610 mButtonPreferredNetworkMode.setSummary( 611 R.string.preferred_network_mode_cdma_summary); 612 break; 613 case PhoneConstants.LTE_ON_CDMA_FALSE: 614 default: 615 mButtonPreferredNetworkMode.setSummary( 616 R.string.preferred_network_mode_cdma_evdo_summary); 617 break; 618 } 619 break; 620 case Phone.NT_MODE_CDMA_NO_EVDO: 621 mButtonPreferredNetworkMode.setSummary( 622 R.string.preferred_network_mode_cdma_only_summary); 623 break; 624 case Phone.NT_MODE_EVDO_NO_CDMA: 625 mButtonPreferredNetworkMode.setSummary( 626 R.string.preferred_network_mode_evdo_only_summary); 627 break; 628 case Phone.NT_MODE_LTE_ONLY: 629 mButtonPreferredNetworkMode.setSummary( 630 R.string.preferred_network_mode_lte_summary); 631 break; 632 case Phone.NT_MODE_LTE_GSM_WCDMA: 633 mButtonPreferredNetworkMode.setSummary( 634 R.string.preferred_network_mode_lte_gsm_wcdma_summary); 635 break; 636 case Phone.NT_MODE_LTE_CDMA_AND_EVDO: 637 mButtonPreferredNetworkMode.setSummary( 638 R.string.preferred_network_mode_lte_cdma_evdo_summary); 639 break; 640 case Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA: 641 mButtonPreferredNetworkMode.setSummary( 642 R.string.preferred_network_mode_global_summary); 643 break; 644 case Phone.NT_MODE_GLOBAL: 645 mButtonPreferredNetworkMode.setSummary( 646 R.string.preferred_network_mode_cdma_evdo_gsm_wcdma_summary); 647 break; 648 case Phone.NT_MODE_LTE_WCDMA: 649 mButtonPreferredNetworkMode.setSummary( 650 R.string.preferred_network_mode_lte_wcdma_summary); 651 break; 652 default: 653 mButtonPreferredNetworkMode.setSummary( 654 R.string.preferred_network_mode_global_summary); 655 } 656 } 657 658 private void UpdateEnabledNetworksValueAndSummary(int NetworkMode) { 659 switch (NetworkMode) { 660 case Phone.NT_MODE_WCDMA_ONLY: 661 case Phone.NT_MODE_GSM_UMTS: 662 case Phone.NT_MODE_WCDMA_PREF: 663 if (!mIsGlobalCdma) { 664 mButtonEnabledNetworks.setValue( 665 Integer.toString(Phone.NT_MODE_WCDMA_PREF)); 666 mButtonEnabledNetworks.setSummary(R.string.network_3G); 667 } else { 668 mButtonEnabledNetworks.setValue( 669 Integer.toString(Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA)); 670 mButtonEnabledNetworks.setSummary(R.string.network_global); 671 } 672 break; 673 case Phone.NT_MODE_GSM_ONLY: 674 if (!mIsGlobalCdma) { 675 mButtonEnabledNetworks.setValue( 676 Integer.toString(Phone.NT_MODE_GSM_ONLY)); 677 mButtonEnabledNetworks.setSummary(R.string.network_2G); 678 } else { 679 mButtonEnabledNetworks.setValue( 680 Integer.toString(Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA)); 681 mButtonEnabledNetworks.setSummary(R.string.network_global); 682 } 683 break; 684 case Phone.NT_MODE_LTE_GSM_WCDMA: 685 case Phone.NT_MODE_LTE_ONLY: 686 case Phone.NT_MODE_LTE_WCDMA: 687 if (!mIsGlobalCdma) { 688 mButtonEnabledNetworks.setValue( 689 Integer.toString(Phone.NT_MODE_LTE_GSM_WCDMA)); 690 mButtonEnabledNetworks.setSummary((mShow4GForLTE == true) 691 ? R.string.network_4G : R.string.network_lte); 692 } else { 693 mButtonEnabledNetworks.setValue( 694 Integer.toString(Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA)); 695 mButtonEnabledNetworks.setSummary(R.string.network_global); 696 } 697 break; 698 case Phone.NT_MODE_LTE_CDMA_AND_EVDO: 699 mButtonEnabledNetworks.setValue( 700 Integer.toString(Phone.NT_MODE_LTE_CDMA_AND_EVDO)); 701 mButtonEnabledNetworks.setSummary(R.string.network_lte); 702 break; 703 case Phone.NT_MODE_CDMA: 704 case Phone.NT_MODE_EVDO_NO_CDMA: 705 case Phone.NT_MODE_GLOBAL: 706 mButtonEnabledNetworks.setValue( 707 Integer.toString(Phone.NT_MODE_CDMA)); 708 mButtonEnabledNetworks.setSummary(R.string.network_3G); 709 break; 710 case Phone.NT_MODE_CDMA_NO_EVDO: 711 mButtonEnabledNetworks.setValue( 712 Integer.toString(Phone.NT_MODE_CDMA_NO_EVDO)); 713 mButtonEnabledNetworks.setSummary(R.string.network_1x); 714 break; 715 case Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA: 716 mButtonEnabledNetworks.setValue( 717 Integer.toString(Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA)); 718 mButtonEnabledNetworks.setSummary(R.string.network_global); 719 break; 720 default: 721 String errMsg = "Invalid Network Mode (" + NetworkMode + "). Ignore."; 722 loge(errMsg); 723 mButtonEnabledNetworks.setSummary(errMsg); 724 } 725 } 726 727 @Override 728 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 729 switch(requestCode) { 730 case REQUEST_CODE_EXIT_ECM: 731 Boolean isChoiceYes = 732 data.getBooleanExtra(EmergencyCallbackModeExitDialog.EXTRA_EXIT_ECM_RESULT, false); 733 if (isChoiceYes) { 734 // If the phone exits from ECM mode, show the CDMA Options 735 mCdmaOptions.showDialog(mClickedPreference); 736 } else { 737 // do nothing 738 } 739 break; 740 741 default: 742 break; 743 } 744 } 745 746 private static void log(String msg) { 747 Log.d(LOG_TAG, msg); 748 } 749 750 private static void loge(String msg) { 751 Log.e(LOG_TAG, msg); 752 } 753 754 @Override 755 public boolean onOptionsItemSelected(MenuItem item) { 756 final int itemId = item.getItemId(); 757 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled() 758 // Commenting out "logical up" capability. This is a workaround for issue 5278083. 759 // 760 // Settings app may not launch this activity via UP_ACTIVITY_CLASS but the other 761 // Activity that looks exactly same as UP_ACTIVITY_CLASS ("SubSettings" Activity). 762 // At that moment, this Activity launches UP_ACTIVITY_CLASS on top of the Activity. 763 // which confuses users. 764 // TODO: introduce better mechanism for "up" capability here. 765 /*Intent intent = new Intent(Intent.ACTION_MAIN); 766 intent.setClassName(UP_ACTIVITY_PACKAGE, UP_ACTIVITY_CLASS); 767 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 768 startActivity(intent);*/ 769 finish(); 770 return true; 771 } 772 return super.onOptionsItemSelected(item); 773 } 774 } 775