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.net.ConnectivityManager; 30 import android.net.Uri; 31 import android.os.AsyncResult; 32 import android.os.Bundle; 33 import android.os.Handler; 34 import android.os.Message; 35 import android.os.SystemProperties; 36 import android.preference.CheckBoxPreference; 37 import android.preference.ListPreference; 38 import android.preference.Preference; 39 import android.preference.PreferenceActivity; 40 import android.preference.PreferenceScreen; 41 import android.telephony.TelephonyManager; 42 import android.text.TextUtils; 43 import android.util.Log; 44 import android.view.MenuItem; 45 46 /** 47 * "Mobile network settings" screen. This preference screen lets you 48 * enable/disable mobile data, and control data roaming and other 49 * network-specific mobile data features. It's used on non-voice-capable 50 * tablets as well as regular phone devices. 51 * 52 * Note that this PreferenceActivity is part of the phone app, even though 53 * you reach it from the "Wireless & Networks" section of the main 54 * Settings app. It's not part of the "Call settings" hierarchy that's 55 * available from the Phone app (see CallFeaturesSetting for that.) 56 */ 57 public class MobileNetworkSettings extends PreferenceActivity 58 implements DialogInterface.OnClickListener, 59 DialogInterface.OnDismissListener, Preference.OnPreferenceChangeListener{ 60 61 // debug data 62 private static final String LOG_TAG = "NetworkSettings"; 63 private static final boolean DBG = false; 64 public static final int REQUEST_CODE_EXIT_ECM = 17; 65 66 //String keys for preference lookup 67 private static final String BUTTON_DATA_ENABLED_KEY = "button_data_enabled_key"; 68 private static final String BUTTON_PREFERED_NETWORK_MODE = "preferred_network_mode_key"; 69 private static final String BUTTON_ROAMING_KEY = "button_roaming_key"; 70 private static final String BUTTON_CDMA_LTE_DATA_SERVICE_KEY = "cdma_lte_data_service_key"; 71 72 static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE; 73 74 //Information about logical "up" Activity 75 private static final String UP_ACTIVITY_PACKAGE = "com.android.settings"; 76 private static final String UP_ACTIVITY_CLASS = 77 "com.android.settings.Settings$WirelessSettingsActivity"; 78 79 //UI objects 80 private ListPreference mButtonPreferredNetworkMode; 81 private CheckBoxPreference mButtonDataRoam; 82 private CheckBoxPreference mButtonDataEnabled; 83 private Preference mLteDataServicePref; 84 85 private static final String iface = "rmnet0"; //TODO: this will go away 86 87 private Phone mPhone; 88 private MyHandler mHandler; 89 private boolean mOkClicked; 90 91 //GsmUmts options and Cdma options 92 GsmUmtsOptions mGsmUmtsOptions; 93 CdmaOptions mCdmaOptions; 94 95 private Preference mClickedPreference; 96 97 98 //This is a method implemented for DialogInterface.OnClickListener. 99 // Used to dismiss the dialogs when they come up. 100 public void onClick(DialogInterface dialog, int which) { 101 if (which == DialogInterface.BUTTON_POSITIVE) { 102 mPhone.setDataRoamingEnabled(true); 103 mOkClicked = true; 104 } else { 105 // Reset the toggle 106 mButtonDataRoam.setChecked(false); 107 } 108 } 109 110 public void onDismiss(DialogInterface dialog) { 111 // Assuming that onClick gets called first 112 if (!mOkClicked) { 113 mButtonDataRoam.setChecked(false); 114 } 115 } 116 117 /** 118 * Invoked on each preference click in this hierarchy, overrides 119 * PreferenceActivity's implementation. Used to make sure we track the 120 * preference click events. 121 */ 122 @Override 123 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { 124 /** TODO: Refactor and get rid of the if's using subclasses */ 125 if (mGsmUmtsOptions != null && 126 mGsmUmtsOptions.preferenceTreeClick(preference) == true) { 127 return true; 128 } else if (mCdmaOptions != null && 129 mCdmaOptions.preferenceTreeClick(preference) == true) { 130 if (Boolean.parseBoolean( 131 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { 132 133 mClickedPreference = preference; 134 135 // In ECM mode launch ECM app dialog 136 startActivityForResult( 137 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null), 138 REQUEST_CODE_EXIT_ECM); 139 } 140 return true; 141 } else if (preference == mButtonPreferredNetworkMode) { 142 //displays the value taken from the Settings.System 143 int settingsNetworkMode = android.provider.Settings.Global.getInt(mPhone.getContext(). 144 getContentResolver(), android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 145 preferredNetworkMode); 146 mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode)); 147 return true; 148 } else if (preference == mButtonDataRoam) { 149 if (DBG) log("onPreferenceTreeClick: preference == mButtonDataRoam."); 150 151 //normally called on the toggle click 152 if (mButtonDataRoam.isChecked()) { 153 // First confirm with a warning dialog about charges 154 mOkClicked = false; 155 new AlertDialog.Builder(this).setMessage( 156 getResources().getString(R.string.roaming_warning)) 157 .setTitle(android.R.string.dialog_alert_title) 158 .setIconAttribute(android.R.attr.alertDialogIcon) 159 .setPositiveButton(android.R.string.yes, this) 160 .setNegativeButton(android.R.string.no, this) 161 .show() 162 .setOnDismissListener(this); 163 } else { 164 mPhone.setDataRoamingEnabled(false); 165 } 166 return true; 167 } else if (preference == mButtonDataEnabled) { 168 if (DBG) log("onPreferenceTreeClick: preference == mButtonDataEnabled."); 169 ConnectivityManager cm = 170 (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); 171 172 cm.setMobileDataEnabled(mButtonDataEnabled.isChecked()); 173 return true; 174 } else if (preference == mLteDataServicePref) { 175 String tmpl = android.provider.Settings.Global.getString(getContentResolver(), 176 android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL); 177 if (!TextUtils.isEmpty(tmpl)) { 178 TelephonyManager tm = (TelephonyManager) getSystemService( 179 Context.TELEPHONY_SERVICE); 180 String imsi = tm.getSubscriberId(); 181 if (imsi == null) { 182 imsi = ""; 183 } 184 final String url = TextUtils.isEmpty(tmpl) ? null 185 : TextUtils.expandTemplate(tmpl, imsi).toString(); 186 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 187 startActivity(intent); 188 } else { 189 android.util.Log.e(LOG_TAG, "Missing SETUP_PREPAID_DATA_SERVICE_URL"); 190 } 191 return true; 192 } else { 193 // if the button is anything but the simple toggle preference, 194 // we'll need to disable all preferences to reject all click 195 // events until the sub-activity's UI comes up. 196 preferenceScreen.setEnabled(false); 197 // Let the intents be launched by the Preference manager 198 return false; 199 } 200 } 201 202 @Override 203 protected void onCreate(Bundle icicle) { 204 super.onCreate(icicle); 205 206 addPreferencesFromResource(R.xml.network_setting); 207 208 mPhone = PhoneGlobals.getPhone(); 209 mHandler = new MyHandler(); 210 211 //get UI object references 212 PreferenceScreen prefSet = getPreferenceScreen(); 213 214 mButtonDataEnabled = (CheckBoxPreference) prefSet.findPreference(BUTTON_DATA_ENABLED_KEY); 215 mButtonDataRoam = (CheckBoxPreference) prefSet.findPreference(BUTTON_ROAMING_KEY); 216 mButtonPreferredNetworkMode = (ListPreference) prefSet.findPreference( 217 BUTTON_PREFERED_NETWORK_MODE); 218 mLteDataServicePref = prefSet.findPreference(BUTTON_CDMA_LTE_DATA_SERVICE_KEY); 219 220 boolean isLteOnCdma = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE; 221 if (getResources().getBoolean(R.bool.world_phone) == true) { 222 // set the listener for the mButtonPreferredNetworkMode list preference so we can issue 223 // change Preferred Network Mode. 224 mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this); 225 226 //Get the networkMode from Settings.System and displays it 227 int settingsNetworkMode = android.provider.Settings.Global.getInt(mPhone.getContext(). 228 getContentResolver(),android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 229 preferredNetworkMode); 230 mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode)); 231 mCdmaOptions = new CdmaOptions(this, prefSet, mPhone); 232 mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet); 233 } else { 234 if (!isLteOnCdma) { 235 prefSet.removePreference(mButtonPreferredNetworkMode); 236 } 237 int phoneType = mPhone.getPhoneType(); 238 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { 239 mCdmaOptions = new CdmaOptions(this, prefSet, mPhone); 240 if (isLteOnCdma) { 241 mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this); 242 int settingsNetworkMode = android.provider.Settings.Global.getInt( 243 mPhone.getContext().getContentResolver(), 244 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 245 preferredNetworkMode); 246 mButtonPreferredNetworkMode.setValue( 247 Integer.toString(settingsNetworkMode)); 248 } 249 250 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { 251 mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet); 252 } else { 253 throw new IllegalStateException("Unexpected phone type: " + phoneType); 254 } 255 } 256 257 final boolean missingDataServiceUrl = TextUtils.isEmpty( 258 android.provider.Settings.Global.getString(getContentResolver(), 259 android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL)); 260 if (!isLteOnCdma || missingDataServiceUrl) { 261 prefSet.removePreference(mLteDataServicePref); 262 } else { 263 android.util.Log.d(LOG_TAG, "keep ltePref"); 264 } 265 266 ActionBar actionBar = getActionBar(); 267 if (actionBar != null) { 268 // android.R.id.home will be triggered in onOptionsItemSelected() 269 actionBar.setDisplayHomeAsUpEnabled(true); 270 } 271 } 272 273 @Override 274 protected void onResume() { 275 super.onResume(); 276 277 // upon resumption from the sub-activity, make sure we re-enable the 278 // preferences. 279 getPreferenceScreen().setEnabled(true); 280 281 ConnectivityManager cm = 282 (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); 283 mButtonDataEnabled.setChecked(cm.getMobileDataEnabled()); 284 285 // Set UI state in onResume because a user could go home, launch some 286 // app to change this setting's backend, and re-launch this settings app 287 // and the UI state would be inconsistent with actual state 288 mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled()); 289 290 if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null) { 291 mPhone.getPreferredNetworkType(mHandler.obtainMessage( 292 MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE)); 293 } 294 } 295 296 @Override 297 protected void onPause() { 298 super.onPause(); 299 } 300 301 /** 302 * Implemented to support onPreferenceChangeListener to look for preference 303 * changes specifically on CLIR. 304 * 305 * @param preference is the preference to be changed, should be mButtonCLIR. 306 * @param objValue should be the value of the selection, NOT its localized 307 * display value. 308 */ 309 public boolean onPreferenceChange(Preference preference, Object objValue) { 310 if (preference == mButtonPreferredNetworkMode) { 311 //NOTE onPreferenceChange seems to be called even if there is no change 312 //Check if the button value is changed from the System.Setting 313 mButtonPreferredNetworkMode.setValue((String) objValue); 314 int buttonNetworkMode; 315 buttonNetworkMode = Integer.valueOf((String) objValue).intValue(); 316 int settingsNetworkMode = android.provider.Settings.Global.getInt( 317 mPhone.getContext().getContentResolver(), 318 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, preferredNetworkMode); 319 if (buttonNetworkMode != settingsNetworkMode) { 320 int modemNetworkMode; 321 // if new mode is invalid ignore it 322 switch (buttonNetworkMode) { 323 case Phone.NT_MODE_WCDMA_PREF: 324 case Phone.NT_MODE_GSM_ONLY: 325 case Phone.NT_MODE_WCDMA_ONLY: 326 case Phone.NT_MODE_GSM_UMTS: 327 case Phone.NT_MODE_CDMA: 328 case Phone.NT_MODE_CDMA_NO_EVDO: 329 case Phone.NT_MODE_EVDO_NO_CDMA: 330 case Phone.NT_MODE_GLOBAL: 331 case Phone.NT_MODE_LTE_CDMA_AND_EVDO: 332 case Phone.NT_MODE_LTE_GSM_WCDMA: 333 case Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA: 334 case Phone.NT_MODE_LTE_ONLY: 335 case Phone.NT_MODE_LTE_WCDMA: 336 // This is one of the modes we recognize 337 modemNetworkMode = buttonNetworkMode; 338 break; 339 default: 340 loge("Invalid Network Mode (" + buttonNetworkMode + ") chosen. Ignore."); 341 return true; 342 } 343 344 UpdatePreferredNetworkModeSummary(buttonNetworkMode); 345 346 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), 347 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 348 buttonNetworkMode ); 349 //Set the modem network mode 350 mPhone.setPreferredNetworkType(modemNetworkMode, mHandler 351 .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)); 352 } 353 } 354 355 // always let the preference setting proceed. 356 return true; 357 } 358 359 private class MyHandler extends Handler { 360 361 static final int MESSAGE_GET_PREFERRED_NETWORK_TYPE = 0; 362 static final int MESSAGE_SET_PREFERRED_NETWORK_TYPE = 1; 363 364 @Override 365 public void handleMessage(Message msg) { 366 switch (msg.what) { 367 case MESSAGE_GET_PREFERRED_NETWORK_TYPE: 368 handleGetPreferredNetworkTypeResponse(msg); 369 break; 370 371 case MESSAGE_SET_PREFERRED_NETWORK_TYPE: 372 handleSetPreferredNetworkTypeResponse(msg); 373 break; 374 } 375 } 376 377 private void handleGetPreferredNetworkTypeResponse(Message msg) { 378 AsyncResult ar = (AsyncResult) msg.obj; 379 380 if (ar.exception == null) { 381 int modemNetworkMode = ((int[])ar.result)[0]; 382 383 if (DBG) { 384 log ("handleGetPreferredNetworkTypeResponse: modemNetworkMode = " + 385 modemNetworkMode); 386 } 387 388 int settingsNetworkMode = android.provider.Settings.Global.getInt( 389 mPhone.getContext().getContentResolver(), 390 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 391 preferredNetworkMode); 392 393 if (DBG) { 394 log("handleGetPreferredNetworkTypeReponse: settingsNetworkMode = " + 395 settingsNetworkMode); 396 } 397 398 //check that modemNetworkMode is from an accepted value 399 if (modemNetworkMode == Phone.NT_MODE_WCDMA_PREF || 400 modemNetworkMode == Phone.NT_MODE_GSM_ONLY || 401 modemNetworkMode == Phone.NT_MODE_WCDMA_ONLY || 402 modemNetworkMode == Phone.NT_MODE_GSM_UMTS || 403 modemNetworkMode == Phone.NT_MODE_CDMA || 404 modemNetworkMode == Phone.NT_MODE_CDMA_NO_EVDO || 405 modemNetworkMode == Phone.NT_MODE_EVDO_NO_CDMA || 406 modemNetworkMode == Phone.NT_MODE_GLOBAL || 407 modemNetworkMode == Phone.NT_MODE_LTE_CDMA_AND_EVDO || 408 modemNetworkMode == Phone.NT_MODE_LTE_GSM_WCDMA || 409 modemNetworkMode == Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA || 410 modemNetworkMode == Phone.NT_MODE_LTE_ONLY || 411 modemNetworkMode == Phone.NT_MODE_LTE_WCDMA) { 412 if (DBG) { 413 log("handleGetPreferredNetworkTypeResponse: if 1: modemNetworkMode = " + 414 modemNetworkMode); 415 } 416 417 //check changes in modemNetworkMode and updates settingsNetworkMode 418 if (modemNetworkMode != settingsNetworkMode) { 419 if (DBG) { 420 log("handleGetPreferredNetworkTypeResponse: if 2: " + 421 "modemNetworkMode != settingsNetworkMode"); 422 } 423 424 settingsNetworkMode = modemNetworkMode; 425 426 if (DBG) { log("handleGetPreferredNetworkTypeResponse: if 2: " + 427 "settingsNetworkMode = " + settingsNetworkMode); 428 } 429 430 //changes the Settings.System accordingly to modemNetworkMode 431 android.provider.Settings.Global.putInt( 432 mPhone.getContext().getContentResolver(), 433 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 434 settingsNetworkMode ); 435 } 436 437 UpdatePreferredNetworkModeSummary(modemNetworkMode); 438 // changes the mButtonPreferredNetworkMode accordingly to modemNetworkMode 439 mButtonPreferredNetworkMode.setValue(Integer.toString(modemNetworkMode)); 440 } else { 441 if (DBG) log("handleGetPreferredNetworkTypeResponse: else: reset to default"); 442 resetNetworkModeToDefault(); 443 } 444 } 445 } 446 447 private void handleSetPreferredNetworkTypeResponse(Message msg) { 448 AsyncResult ar = (AsyncResult) msg.obj; 449 450 if (ar.exception == null) { 451 int networkMode = Integer.valueOf( 452 mButtonPreferredNetworkMode.getValue()).intValue(); 453 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), 454 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 455 networkMode ); 456 } else { 457 mPhone.getPreferredNetworkType(obtainMessage(MESSAGE_GET_PREFERRED_NETWORK_TYPE)); 458 } 459 } 460 461 private void resetNetworkModeToDefault() { 462 //set the mButtonPreferredNetworkMode 463 mButtonPreferredNetworkMode.setValue(Integer.toString(preferredNetworkMode)); 464 //set the Settings.System 465 android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), 466 android.provider.Settings.Global.PREFERRED_NETWORK_MODE, 467 preferredNetworkMode ); 468 //Set the Modem 469 mPhone.setPreferredNetworkType(preferredNetworkMode, 470 this.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)); 471 } 472 } 473 474 private void UpdatePreferredNetworkModeSummary(int NetworkMode) { 475 switch(NetworkMode) { 476 case Phone.NT_MODE_WCDMA_PREF: 477 mButtonPreferredNetworkMode.setSummary( 478 R.string.preferred_network_mode_wcdma_perf_summary); 479 break; 480 case Phone.NT_MODE_GSM_ONLY: 481 mButtonPreferredNetworkMode.setSummary( 482 R.string.preferred_network_mode_gsm_only_summary); 483 break; 484 case Phone.NT_MODE_WCDMA_ONLY: 485 mButtonPreferredNetworkMode.setSummary( 486 R.string.preferred_network_mode_wcdma_only_summary); 487 break; 488 case Phone.NT_MODE_GSM_UMTS: 489 mButtonPreferredNetworkMode.setSummary( 490 R.string.preferred_network_mode_gsm_wcdma_summary); 491 break; 492 case Phone.NT_MODE_CDMA: 493 switch (mPhone.getLteOnCdmaMode()) { 494 case PhoneConstants.LTE_ON_CDMA_TRUE: 495 mButtonPreferredNetworkMode.setSummary( 496 R.string.preferred_network_mode_cdma_summary); 497 break; 498 case PhoneConstants.LTE_ON_CDMA_FALSE: 499 default: 500 mButtonPreferredNetworkMode.setSummary( 501 R.string.preferred_network_mode_cdma_evdo_summary); 502 break; 503 } 504 break; 505 case Phone.NT_MODE_CDMA_NO_EVDO: 506 mButtonPreferredNetworkMode.setSummary( 507 R.string.preferred_network_mode_cdma_only_summary); 508 break; 509 case Phone.NT_MODE_EVDO_NO_CDMA: 510 mButtonPreferredNetworkMode.setSummary( 511 R.string.preferred_network_mode_evdo_only_summary); 512 break; 513 case Phone.NT_MODE_LTE_ONLY: 514 mButtonPreferredNetworkMode.setSummary( 515 R.string.preferred_network_mode_lte_summary); 516 break; 517 case Phone.NT_MODE_LTE_GSM_WCDMA: 518 mButtonPreferredNetworkMode.setSummary( 519 R.string.preferred_network_mode_lte_gsm_wcdma_summary); 520 break; 521 case Phone.NT_MODE_LTE_CDMA_AND_EVDO: 522 mButtonPreferredNetworkMode.setSummary( 523 R.string.preferred_network_mode_lte_cdma_evdo_summary); 524 break; 525 case Phone.NT_MODE_LTE_CMDA_EVDO_GSM_WCDMA: 526 mButtonPreferredNetworkMode.setSummary( 527 R.string.preferred_network_mode_global_summary); 528 break; 529 case Phone.NT_MODE_GLOBAL: 530 mButtonPreferredNetworkMode.setSummary( 531 R.string.preferred_network_mode_cdma_evdo_gsm_wcdma_summary); 532 break; 533 case Phone.NT_MODE_LTE_WCDMA: 534 mButtonPreferredNetworkMode.setSummary( 535 R.string.preferred_network_mode_lte_wcdma_summary); 536 break; 537 default: 538 mButtonPreferredNetworkMode.setSummary( 539 R.string.preferred_network_mode_global_summary); 540 } 541 } 542 543 @Override 544 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 545 switch(requestCode) { 546 case REQUEST_CODE_EXIT_ECM: 547 Boolean isChoiceYes = 548 data.getBooleanExtra(EmergencyCallbackModeExitDialog.EXTRA_EXIT_ECM_RESULT, false); 549 if (isChoiceYes) { 550 // If the phone exits from ECM mode, show the CDMA Options 551 mCdmaOptions.showDialog(mClickedPreference); 552 } else { 553 // do nothing 554 } 555 break; 556 557 default: 558 break; 559 } 560 } 561 562 private static void log(String msg) { 563 Log.d(LOG_TAG, msg); 564 } 565 566 private static void loge(String msg) { 567 Log.e(LOG_TAG, msg); 568 } 569 570 @Override 571 public boolean onOptionsItemSelected(MenuItem item) { 572 final int itemId = item.getItemId(); 573 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled() 574 // Commenting out "logical up" capability. This is a workaround for issue 5278083. 575 // 576 // Settings app may not launch this activity via UP_ACTIVITY_CLASS but the other 577 // Activity that looks exactly same as UP_ACTIVITY_CLASS ("SubSettings" Activity). 578 // At that moment, this Activity launches UP_ACTIVITY_CLASS on top of the Activity. 579 // which confuses users. 580 // TODO: introduce better mechanism for "up" capability here. 581 /*Intent intent = new Intent(Intent.ACTION_MAIN); 582 intent.setClassName(UP_ACTIVITY_PACKAGE, UP_ACTIVITY_CLASS); 583 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 584 startActivity(intent);*/ 585 finish(); 586 return true; 587 } 588 return super.onOptionsItemSelected(item); 589 } 590 } 591