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