Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 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 | |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 19 | import com.android.ims.ImsManager; |
| 20 | import com.android.ims.ImsException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 21 | import com.android.internal.telephony.Phone; |
| 22 | import com.android.internal.telephony.PhoneConstants; |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 23 | import com.android.internal.telephony.PhoneFactory; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import com.android.internal.telephony.TelephonyIntents; |
| 25 | import com.android.internal.telephony.TelephonyProperties; |
| 26 | |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 27 | import java.util.ArrayList; |
| 28 | import java.util.List; |
| 29 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.app.ActionBar; |
| 31 | import android.app.AlertDialog; |
| 32 | import android.content.Context; |
| 33 | import android.content.DialogInterface; |
| 34 | import android.content.Intent; |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 35 | import android.content.SharedPreferences; |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager.NameNotFoundException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Bundle; |
| 40 | import android.os.Handler; |
| 41 | import android.os.Message; |
| 42 | import android.os.SystemProperties; |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 43 | import android.os.UserHandle; |
Julia Reynolds | a4ca38a | 2014-05-12 16:51:26 -0400 | [diff] [blame] | 44 | import android.os.UserManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.preference.ListPreference; |
| 46 | import android.preference.Preference; |
| 47 | import android.preference.PreferenceActivity; |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 48 | import android.preference.PreferenceGroup; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.preference.PreferenceScreen; |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 50 | import android.preference.SwitchPreference; |
Etan Cohen | 24c7ea6 | 2014-11-13 17:14:33 -0800 | [diff] [blame^] | 51 | import android.telephony.PhoneStateListener; |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 52 | import android.telephony.SubscriptionInfo; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 53 | import android.telephony.SubscriptionManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.telephony.TelephonyManager; |
| 55 | import android.text.TextUtils; |
| 56 | import android.util.Log; |
| 57 | import android.view.MenuItem; |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 58 | import android.view.View; |
| 59 | import android.widget.ListView; |
| 60 | import android.widget.TabHost; |
| 61 | import android.widget.TabHost.OnTabChangeListener; |
| 62 | import android.widget.TabHost.TabContentFactory; |
| 63 | import android.widget.TabHost.TabSpec; |
| 64 | import android.widget.TabWidget; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * "Mobile network settings" screen. This preference screen lets you |
| 68 | * enable/disable mobile data, and control data roaming and other |
| 69 | * network-specific mobile data features. It's used on non-voice-capable |
| 70 | * tablets as well as regular phone devices. |
| 71 | * |
| 72 | * Note that this PreferenceActivity is part of the phone app, even though |
| 73 | * you reach it from the "Wireless & Networks" section of the main |
| 74 | * Settings app. It's not part of the "Call settings" hierarchy that's |
| 75 | * available from the Phone app (see CallFeaturesSetting for that.) |
| 76 | */ |
| 77 | public class MobileNetworkSettings extends PreferenceActivity |
| 78 | implements DialogInterface.OnClickListener, |
| 79 | DialogInterface.OnDismissListener, Preference.OnPreferenceChangeListener{ |
| 80 | |
| 81 | // debug data |
| 82 | private static final String LOG_TAG = "NetworkSettings"; |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 83 | private static final boolean DBG = true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 84 | public static final int REQUEST_CODE_EXIT_ECM = 17; |
| 85 | |
| 86 | //String keys for preference lookup |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | private static final String BUTTON_PREFERED_NETWORK_MODE = "preferred_network_mode_key"; |
| 88 | private static final String BUTTON_ROAMING_KEY = "button_roaming_key"; |
| 89 | private static final String BUTTON_CDMA_LTE_DATA_SERVICE_KEY = "cdma_lte_data_service_key"; |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 90 | private static final String BUTTON_ENABLED_NETWORKS_KEY = "enabled_networks_key"; |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 91 | private static final String BUTTON_4G_LTE_KEY = "enhanced_4g_lte"; |
| 92 | private static final String BUTTON_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings"; |
Rohit Sisodia (a21406) | dfa0410 | 2014-11-05 16:42:24 -0600 | [diff] [blame] | 93 | private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key"; |
| 94 | private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key"; |
| 95 | private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key"; |
| 96 | private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key"; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 97 | |
| 98 | static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE; |
| 99 | |
| 100 | //Information about logical "up" Activity |
| 101 | private static final String UP_ACTIVITY_PACKAGE = "com.android.settings"; |
| 102 | private static final String UP_ACTIVITY_CLASS = |
| 103 | "com.android.settings.Settings$WirelessSettingsActivity"; |
| 104 | |
| 105 | //UI objects |
| 106 | private ListPreference mButtonPreferredNetworkMode; |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 107 | private ListPreference mButtonEnabledNetworks; |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 108 | private SwitchPreference mButtonDataRoam; |
| 109 | private SwitchPreference mButton4glte; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | private Preference mLteDataServicePref; |
| 111 | |
| 112 | private static final String iface = "rmnet0"; //TODO: this will go away |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 113 | private List<SubscriptionInfo> mSelectableSubInfos = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 114 | |
Julia Reynolds | a4ca38a | 2014-05-12 16:51:26 -0400 | [diff] [blame] | 115 | private UserManager mUm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | private Phone mPhone; |
| 117 | private MyHandler mHandler; |
| 118 | private boolean mOkClicked; |
| 119 | |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 120 | private TabHost mTabHost; |
| 121 | private TabWidget mTabWidget; |
| 122 | private ListView mListView; |
| 123 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | //GsmUmts options and Cdma options |
| 125 | GsmUmtsOptions mGsmUmtsOptions; |
| 126 | CdmaOptions mCdmaOptions; |
| 127 | |
| 128 | private Preference mClickedPreference; |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 129 | private boolean mShow4GForLTE; |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 130 | private boolean mIsGlobalCdma; |
Julia Reynolds | a4ca38a | 2014-05-12 16:51:26 -0400 | [diff] [blame] | 131 | private boolean mUnavailable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | |
Etan Cohen | 24c7ea6 | 2014-11-13 17:14:33 -0800 | [diff] [blame^] | 133 | private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 134 | /* |
| 135 | * Enable/disable the 'Enhanced 4G LTE Mode' when in/out of a call. |
| 136 | * @see android.telephony.PhoneStateListener#onCallStateChanged(int, |
| 137 | * java.lang.String) |
| 138 | */ |
| 139 | @Override |
| 140 | public void onCallStateChanged(int state, String incomingNumber) { |
| 141 | if (DBG) log("PhoneStateListener.onCallStateChanged: state=" + state); |
| 142 | Preference pref = getPreferenceScreen().findPreference(BUTTON_4G_LTE_KEY); |
| 143 | if (pref != null) { |
| 144 | pref.setEnabled(state == TelephonyManager.CALL_STATE_IDLE); |
| 145 | } |
| 146 | } |
| 147 | }; |
| 148 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | //This is a method implemented for DialogInterface.OnClickListener. |
| 150 | // Used to dismiss the dialogs when they come up. |
| 151 | public void onClick(DialogInterface dialog, int which) { |
| 152 | if (which == DialogInterface.BUTTON_POSITIVE) { |
| 153 | mPhone.setDataRoamingEnabled(true); |
| 154 | mOkClicked = true; |
| 155 | } else { |
| 156 | // Reset the toggle |
| 157 | mButtonDataRoam.setChecked(false); |
| 158 | } |
| 159 | } |
| 160 | |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 161 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | public void onDismiss(DialogInterface dialog) { |
| 163 | // Assuming that onClick gets called first |
PauloftheWest | adc6507 | 2014-09-09 11:32:13 -0700 | [diff] [blame] | 164 | mButtonDataRoam.setChecked(mOkClicked); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Invoked on each preference click in this hierarchy, overrides |
| 169 | * PreferenceActivity's implementation. Used to make sure we track the |
| 170 | * preference click events. |
| 171 | */ |
| 172 | @Override |
| 173 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
| 174 | /** TODO: Refactor and get rid of the if's using subclasses */ |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 175 | final int phoneSubId = mPhone.getSubId(); |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 176 | if (preference.getKey().equals(BUTTON_4G_LTE_KEY)) { |
| 177 | return true; |
| 178 | } else if (mGsmUmtsOptions != null && |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 179 | mGsmUmtsOptions.preferenceTreeClick(preference) == true) { |
| 180 | return true; |
| 181 | } else if (mCdmaOptions != null && |
| 182 | mCdmaOptions.preferenceTreeClick(preference) == true) { |
| 183 | if (Boolean.parseBoolean( |
| 184 | SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { |
| 185 | |
| 186 | mClickedPreference = preference; |
| 187 | |
| 188 | // In ECM mode launch ECM app dialog |
| 189 | startActivityForResult( |
| 190 | new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null), |
| 191 | REQUEST_CODE_EXIT_ECM); |
| 192 | } |
| 193 | return true; |
| 194 | } else if (preference == mButtonPreferredNetworkMode) { |
| 195 | //displays the value taken from the Settings.System |
| 196 | int settingsNetworkMode = android.provider.Settings.Global.getInt(mPhone.getContext(). |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 197 | getContentResolver(), |
| 198 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 199 | preferredNetworkMode); |
| 200 | mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode)); |
| 201 | return true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 202 | } else if (preference == mLteDataServicePref) { |
| 203 | String tmpl = android.provider.Settings.Global.getString(getContentResolver(), |
| 204 | android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL); |
| 205 | if (!TextUtils.isEmpty(tmpl)) { |
| 206 | TelephonyManager tm = (TelephonyManager) getSystemService( |
| 207 | Context.TELEPHONY_SERVICE); |
| 208 | String imsi = tm.getSubscriberId(); |
| 209 | if (imsi == null) { |
| 210 | imsi = ""; |
| 211 | } |
| 212 | final String url = TextUtils.isEmpty(tmpl) ? null |
| 213 | : TextUtils.expandTemplate(tmpl, imsi).toString(); |
| 214 | Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
| 215 | startActivity(intent); |
| 216 | } else { |
| 217 | android.util.Log.e(LOG_TAG, "Missing SETUP_PREPAID_DATA_SERVICE_URL"); |
| 218 | } |
| 219 | return true; |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 220 | } else if (preference == mButtonEnabledNetworks) { |
| 221 | int settingsNetworkMode = android.provider.Settings.Global.getInt(mPhone.getContext(). |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 222 | getContentResolver(), |
| 223 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 224 | preferredNetworkMode); |
| 225 | mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode)); |
| 226 | return true; |
PauloftheWest | adc6507 | 2014-09-09 11:32:13 -0700 | [diff] [blame] | 227 | } else if (preference == mButtonDataRoam) { |
| 228 | // Do not disable the preference screen if the user clicks Data roaming. |
| 229 | return true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 230 | } else { |
| 231 | // if the button is anything but the simple toggle preference, |
| 232 | // we'll need to disable all preferences to reject all click |
| 233 | // events until the sub-activity's UI comes up. |
| 234 | preferenceScreen.setEnabled(false); |
| 235 | // Let the intents be launched by the Preference manager |
| 236 | return false; |
| 237 | } |
| 238 | } |
| 239 | |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 240 | private void setIMS(boolean turnOn) { |
Libin.Tang@motorola.com | ac00bb2 | 2014-10-10 15:06:21 -0500 | [diff] [blame] | 241 | int value = (turnOn) ? 1:0; |
| 242 | android.provider.Settings.Global.putInt( |
| 243 | mPhone.getContext().getContentResolver(), |
Etan Cohen | 7c8f52b | 2014-10-22 15:14:55 -0700 | [diff] [blame] | 244 | android.provider.Settings.Global.ENHANCED_4G_MODE_ENABLED, value); |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 245 | } |
| 246 | |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 247 | private OnTabChangeListener mTabListener = new OnTabChangeListener() { |
| 248 | @Override |
| 249 | public void onTabChanged(String tabId) { |
| 250 | final int slotId = Integer.parseInt(tabId); |
| 251 | final SubscriptionInfo sir = findRecordBySlotId(slotId); |
| 252 | mPhone = PhoneFactory.getPhone(SubscriptionManager.getPhoneId(sir.getSubscriptionId())); |
| 253 | |
| 254 | // The User has changed tab; update the body. |
| 255 | updateBody(); |
| 256 | } |
| 257 | }; |
| 258 | |
| 259 | private TabContentFactory mEmptyTabContent = new TabContentFactory() { |
| 260 | @Override |
| 261 | public View createTabContent(String tag) { |
| 262 | return new View(mTabHost.getContext()); |
| 263 | } |
| 264 | }; |
| 265 | |
| 266 | private TabSpec buildTabSpec(String tag, String title) { |
| 267 | return mTabHost.newTabSpec(tag).setIndicator(title).setContent( |
| 268 | mEmptyTabContent); |
| 269 | } |
| 270 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 271 | @Override |
| 272 | protected void onCreate(Bundle icicle) { |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 273 | setTheme(R.style.Theme_Material_Settings); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | super.onCreate(icicle); |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 275 | final Context context = getApplicationContext(); |
| 276 | |
| 277 | mSelectableSubInfos = new ArrayList<SubscriptionInfo>(); |
| 278 | final TelephonyManager tm = |
| 279 | (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
| 280 | |
| 281 | for (int i = 0; i < tm.getSimCount(); i++) { |
| 282 | SubscriptionInfo sir = findRecordBySlotId(i); |
| 283 | if (sir != null) { |
| 284 | mSelectableSubInfos.add(sir); |
| 285 | } |
| 286 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 287 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 288 | mPhone = PhoneGlobals.getPhone(); |
| 289 | mHandler = new MyHandler(); |
Julia Reynolds | a4ca38a | 2014-05-12 16:51:26 -0400 | [diff] [blame] | 290 | mUm = (UserManager) getSystemService(Context.USER_SERVICE); |
| 291 | |
| 292 | if (mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
| 293 | mUnavailable = true; |
| 294 | setContentView(R.layout.telephony_disallowed_preference_screen); |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | addPreferencesFromResource(R.xml.network_setting); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 299 | |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 300 | mButton4glte = (SwitchPreference)findPreference(BUTTON_4G_LTE_KEY); |
| 301 | |
| 302 | mButton4glte.setOnPreferenceChangeListener(this); |
Etan Cohen | 46b0a81 | 2014-08-18 15:43:29 -0700 | [diff] [blame] | 303 | mButton4glte.setChecked(ImsManager.isEnhanced4gLteModeSettingEnabledByUser(this)); |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 304 | |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 305 | try { |
| 306 | Context con = createPackageContext("com.android.systemui", 0); |
| 307 | int id = con.getResources().getIdentifier("config_show4GForLTE", |
| 308 | "bool", "com.android.systemui"); |
| 309 | mShow4GForLTE = con.getResources().getBoolean(id); |
| 310 | } catch (NameNotFoundException e) { |
| 311 | loge("NameNotFoundException for show4GFotLTE"); |
| 312 | mShow4GForLTE = false; |
| 313 | } |
| 314 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 | //get UI object references |
| 316 | PreferenceScreen prefSet = getPreferenceScreen(); |
| 317 | |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 318 | mButtonDataRoam = (SwitchPreference) prefSet.findPreference(BUTTON_ROAMING_KEY); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 319 | mButtonPreferredNetworkMode = (ListPreference) prefSet.findPreference( |
| 320 | BUTTON_PREFERED_NETWORK_MODE); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 321 | mButtonEnabledNetworks = (ListPreference) prefSet.findPreference( |
| 322 | BUTTON_ENABLED_NETWORKS_KEY); |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 323 | mButtonDataRoam.setOnPreferenceChangeListener(this); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 324 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 325 | mLteDataServicePref = prefSet.findPreference(BUTTON_CDMA_LTE_DATA_SERVICE_KEY); |
| 326 | |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 327 | if (mSelectableSubInfos.size() > 1) { |
| 328 | setContentView(R.layout.network_settings); |
| 329 | |
| 330 | mTabHost = (TabHost) findViewById(android.R.id.tabhost); |
| 331 | mTabWidget = (TabWidget) findViewById(android.R.id.tabs); |
| 332 | mListView = (ListView) findViewById(android.R.id.list); |
| 333 | |
| 334 | mTabHost.setup(); |
| 335 | mTabHost.setOnTabChangedListener(mTabListener); |
| 336 | mTabHost.clearAllTabs(); |
| 337 | |
| 338 | for (int i = 0; i < mSelectableSubInfos.size(); i++) { |
| 339 | mTabHost.addTab(buildTabSpec(String.valueOf(i), |
| 340 | String.valueOf(mSelectableSubInfos.get(i).getDisplayName()))); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | updateBody(); |
| 345 | } |
| 346 | |
| 347 | @Override |
| 348 | protected void onResume() { |
| 349 | super.onResume(); |
| 350 | |
| 351 | if (mUnavailable) { |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | // upon resumption from the sub-activity, make sure we re-enable the |
| 356 | // preferences. |
| 357 | getPreferenceScreen().setEnabled(true); |
| 358 | |
| 359 | // Set UI state in onResume because a user could go home, launch some |
| 360 | // app to change this setting's backend, and re-launch this settings app |
| 361 | // and the UI state would be inconsistent with actual state |
| 362 | mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled()); |
| 363 | |
| 364 | if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null) { |
| 365 | mPhone.getPreferredNetworkType(mHandler.obtainMessage( |
| 366 | MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE)); |
| 367 | } |
| 368 | |
| 369 | if (getPreferenceScreen().findPreference(BUTTON_ENABLED_NETWORKS_KEY) != null) { |
| 370 | mPhone.getPreferredNetworkType(mHandler.obtainMessage( |
| 371 | MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE)); |
| 372 | } |
Etan Cohen | 24c7ea6 | 2014-11-13 17:14:33 -0800 | [diff] [blame^] | 373 | |
| 374 | if (ImsManager.isVolteEnabledByPlatform(this)) { |
| 375 | TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 376 | tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); |
| 377 | } |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | private void updateBody() { |
| 381 | final Context context = getApplicationContext(); |
| 382 | final TelephonyManager tm = |
| 383 | (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
| 384 | PreferenceScreen prefSet = getPreferenceScreen(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 385 | boolean isLteOnCdma = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE; |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 386 | final int phoneSubId = mPhone.getSubId(); |
| 387 | |
| 388 | if (prefSet != null) { |
| 389 | prefSet.removeAll(); |
| 390 | prefSet.addPreference(mButtonDataRoam); |
| 391 | prefSet.addPreference(mButtonPreferredNetworkMode); |
| 392 | prefSet.addPreference(mButtonEnabledNetworks); |
PauloftheWest | e3c2f8f | 2014-11-13 16:01:43 -0800 | [diff] [blame] | 393 | prefSet.addPreference(mButton4glte); |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | int settingsNetworkMode = android.provider.Settings.Global.getInt( |
| 397 | mPhone.getContext().getContentResolver(), |
| 398 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
| 399 | preferredNetworkMode); |
| 400 | |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 401 | mIsGlobalCdma = isLteOnCdma && getResources().getBoolean(R.bool.config_show_cdma); |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 402 | int shouldHideCarrierSettings = android.provider.Settings.Global.getInt( |
| 403 | mPhone.getContext().getContentResolver(), |
| 404 | android.provider.Settings.Global.HIDE_CARRIER_NETWORK_SETTINGS, 0); |
| 405 | if (shouldHideCarrierSettings == 1 ) { |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 406 | prefSet.removePreference(mButtonPreferredNetworkMode); |
| 407 | prefSet.removePreference(mButtonEnabledNetworks); |
| 408 | prefSet.removePreference(mLteDataServicePref); |
| 409 | } else if (getResources().getBoolean(R.bool.world_phone) == true) { |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 410 | prefSet.removePreference(mButtonEnabledNetworks); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 411 | // set the listener for the mButtonPreferredNetworkMode list preference so we can issue |
| 412 | // change Preferred Network Mode. |
| 413 | mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this); |
| 414 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | mCdmaOptions = new CdmaOptions(this, prefSet, mPhone); |
| 416 | mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet); |
| 417 | } else { |
Sungmin Choi | 4e9f0aa | 2013-09-17 17:27:24 -0700 | [diff] [blame] | 418 | prefSet.removePreference(mButtonPreferredNetworkMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 419 | int phoneType = mPhone.getPhoneType(); |
| 420 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 421 | if (isLteOnCdma) { |
| 422 | mButtonEnabledNetworks.setEntries( |
| 423 | R.array.enabled_networks_cdma_choices); |
| 424 | mButtonEnabledNetworks.setEntryValues( |
| 425 | R.array.enabled_networks_cdma_values); |
| 426 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | mCdmaOptions = new CdmaOptions(this, prefSet, mPhone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 429 | if (!getResources().getBoolean(R.bool.config_prefer_2g) |
| 430 | && !getResources().getBoolean(R.bool.config_enabled_lte)) { |
| 431 | mButtonEnabledNetworks.setEntries( |
| 432 | R.array.enabled_networks_except_gsm_lte_choices); |
| 433 | mButtonEnabledNetworks.setEntryValues( |
| 434 | R.array.enabled_networks_except_gsm_lte_values); |
| 435 | } else if (!getResources().getBoolean(R.bool.config_prefer_2g)) { |
| 436 | int select = (mShow4GForLTE == true) ? |
| 437 | R.array.enabled_networks_except_gsm_4g_choices |
| 438 | : R.array.enabled_networks_except_gsm_choices; |
| 439 | mButtonEnabledNetworks.setEntries(select); |
| 440 | mButtonEnabledNetworks.setEntryValues( |
| 441 | R.array.enabled_networks_except_gsm_values); |
| 442 | } else if (!getResources().getBoolean(R.bool.config_enabled_lte)) { |
| 443 | mButtonEnabledNetworks.setEntries( |
| 444 | R.array.enabled_networks_except_lte_choices); |
| 445 | mButtonEnabledNetworks.setEntryValues( |
| 446 | R.array.enabled_networks_except_lte_values); |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 447 | } else if (mIsGlobalCdma) { |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 448 | mButtonEnabledNetworks.setEntries( |
| 449 | R.array.enabled_networks_cdma_choices); |
| 450 | mButtonEnabledNetworks.setEntryValues( |
| 451 | R.array.enabled_networks_cdma_values); |
| 452 | } else { |
| 453 | int select = (mShow4GForLTE == true) ? R.array.enabled_networks_4g_choices |
| 454 | : R.array.enabled_networks_choices; |
| 455 | mButtonEnabledNetworks.setEntries(select); |
| 456 | mButtonEnabledNetworks.setEntryValues( |
| 457 | R.array.enabled_networks_values); |
| 458 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 459 | mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet); |
| 460 | } else { |
| 461 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 462 | } |
Rohit Sisodia (a21406) | 3a4447b | 2014-10-10 14:05:11 -0500 | [diff] [blame] | 463 | if (isWorldMode()) { |
| 464 | mButtonEnabledNetworks.setEntries( |
| 465 | R.array.preferred_network_mode_choices_world_mode); |
| 466 | mButtonEnabledNetworks.setEntryValues( |
| 467 | R.array.preferred_network_mode_values_world_mode); |
| 468 | } |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 469 | mButtonEnabledNetworks.setOnPreferenceChangeListener(this); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 470 | if (DBG) log("settingsNetworkMode: " + settingsNetworkMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | final boolean missingDataServiceUrl = TextUtils.isEmpty( |
| 474 | android.provider.Settings.Global.getString(getContentResolver(), |
| 475 | android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL)); |
| 476 | if (!isLteOnCdma || missingDataServiceUrl) { |
| 477 | prefSet.removePreference(mLteDataServicePref); |
| 478 | } else { |
| 479 | android.util.Log.d(LOG_TAG, "keep ltePref"); |
| 480 | } |
| 481 | |
Etan Cohen | f5f0dae | 2014-09-04 17:33:06 -0700 | [diff] [blame] | 482 | // Enable enhanced 4G LTE mode settings depending on whether exists on platform |
Etan Cohen | 4afb0a6 | 2014-10-23 18:51:20 -0700 | [diff] [blame] | 483 | if (!ImsManager.isVolteEnabledByPlatform(this)) { |
Hyejin Kim | f830f76 | 2014-08-12 14:38:12 +0900 | [diff] [blame] | 484 | Preference pref = prefSet.findPreference(BUTTON_4G_LTE_KEY); |
| 485 | if (pref != null) { |
| 486 | prefSet.removePreference(pref); |
| 487 | } |
| 488 | } |
| 489 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 490 | ActionBar actionBar = getActionBar(); |
| 491 | if (actionBar != null) { |
| 492 | // android.R.id.home will be triggered in onOptionsItemSelected() |
| 493 | actionBar.setDisplayHomeAsUpEnabled(true); |
| 494 | } |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 495 | |
| 496 | final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER; |
| 497 | // Enable link to CMAS app settings depending on the value in config.xml. |
| 498 | final boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean( |
| 499 | com.android.internal.R.bool.config_cellBroadcastAppLinks); |
| 500 | if (isSecondaryUser || !isCellBroadcastAppLinkEnabled |
| 501 | || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) { |
| 502 | PreferenceScreen root = getPreferenceScreen(); |
| 503 | Preference ps = findPreference(BUTTON_CELL_BROADCAST_SETTINGS); |
| 504 | if (ps != null) { |
| 505 | root.removePreference(ps); |
| 506 | } |
| 507 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 508 | |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 509 | //Get the networkMode from Settings.System and displays it |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 510 | mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled()); |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 511 | mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode)); |
| 512 | mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode)); |
| 513 | UpdatePreferredNetworkModeSummary(settingsNetworkMode); |
| 514 | UpdateEnabledNetworksValueAndSummary(settingsNetworkMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | @Override |
| 518 | protected void onPause() { |
| 519 | super.onPause(); |
Etan Cohen | 24c7ea6 | 2014-11-13 17:14:33 -0800 | [diff] [blame^] | 520 | |
| 521 | if (ImsManager.isVolteEnabledByPlatform(this)) { |
| 522 | TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 523 | tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); |
| 524 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Implemented to support onPreferenceChangeListener to look for preference |
| 529 | * changes specifically on CLIR. |
| 530 | * |
| 531 | * @param preference is the preference to be changed, should be mButtonCLIR. |
| 532 | * @param objValue should be the value of the selection, NOT its localized |
| 533 | * display value. |
| 534 | */ |
| 535 | public boolean onPreferenceChange(Preference preference, Object objValue) { |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 536 | final int phoneSubId = mPhone.getSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 537 | if (preference == mButtonPreferredNetworkMode) { |
| 538 | //NOTE onPreferenceChange seems to be called even if there is no change |
| 539 | //Check if the button value is changed from the System.Setting |
| 540 | mButtonPreferredNetworkMode.setValue((String) objValue); |
| 541 | int buttonNetworkMode; |
| 542 | buttonNetworkMode = Integer.valueOf((String) objValue).intValue(); |
| 543 | int settingsNetworkMode = android.provider.Settings.Global.getInt( |
| 544 | mPhone.getContext().getContentResolver(), |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 545 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
| 546 | preferredNetworkMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 547 | if (buttonNetworkMode != settingsNetworkMode) { |
| 548 | int modemNetworkMode; |
| 549 | // if new mode is invalid ignore it |
| 550 | switch (buttonNetworkMode) { |
| 551 | case Phone.NT_MODE_WCDMA_PREF: |
| 552 | case Phone.NT_MODE_GSM_ONLY: |
| 553 | case Phone.NT_MODE_WCDMA_ONLY: |
| 554 | case Phone.NT_MODE_GSM_UMTS: |
| 555 | case Phone.NT_MODE_CDMA: |
| 556 | case Phone.NT_MODE_CDMA_NO_EVDO: |
| 557 | case Phone.NT_MODE_EVDO_NO_CDMA: |
| 558 | case Phone.NT_MODE_GLOBAL: |
| 559 | case Phone.NT_MODE_LTE_CDMA_AND_EVDO: |
| 560 | case Phone.NT_MODE_LTE_GSM_WCDMA: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 561 | case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA: |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 562 | case Phone.NT_MODE_LTE_ONLY: |
| 563 | case Phone.NT_MODE_LTE_WCDMA: |
| 564 | // This is one of the modes we recognize |
| 565 | modemNetworkMode = buttonNetworkMode; |
| 566 | break; |
| 567 | default: |
| 568 | loge("Invalid Network Mode (" + buttonNetworkMode + ") chosen. Ignore."); |
| 569 | return true; |
| 570 | } |
| 571 | |
| 572 | UpdatePreferredNetworkModeSummary(buttonNetworkMode); |
| 573 | |
| 574 | android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 575 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 576 | buttonNetworkMode ); |
| 577 | //Set the modem network mode |
| 578 | mPhone.setPreferredNetworkType(modemNetworkMode, mHandler |
| 579 | .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)); |
| 580 | } |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 581 | } else if (preference == mButtonEnabledNetworks) { |
| 582 | mButtonEnabledNetworks.setValue((String) objValue); |
| 583 | int buttonNetworkMode; |
| 584 | buttonNetworkMode = Integer.valueOf((String) objValue).intValue(); |
| 585 | if (DBG) log("buttonNetworkMode: " + buttonNetworkMode); |
| 586 | int settingsNetworkMode = android.provider.Settings.Global.getInt( |
| 587 | mPhone.getContext().getContentResolver(), |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 588 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
| 589 | preferredNetworkMode); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 590 | if (buttonNetworkMode != settingsNetworkMode) { |
| 591 | int modemNetworkMode; |
| 592 | // if new mode is invalid ignore it |
| 593 | switch (buttonNetworkMode) { |
| 594 | case Phone.NT_MODE_WCDMA_PREF: |
| 595 | case Phone.NT_MODE_GSM_ONLY: |
| 596 | case Phone.NT_MODE_LTE_GSM_WCDMA: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 597 | case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA: |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 598 | case Phone.NT_MODE_CDMA: |
| 599 | case Phone.NT_MODE_CDMA_NO_EVDO: |
| 600 | case Phone.NT_MODE_LTE_CDMA_AND_EVDO: |
| 601 | // This is one of the modes we recognize |
| 602 | modemNetworkMode = buttonNetworkMode; |
| 603 | break; |
| 604 | default: |
| 605 | loge("Invalid Network Mode (" + buttonNetworkMode + ") chosen. Ignore."); |
| 606 | return true; |
| 607 | } |
| 608 | |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 609 | UpdateEnabledNetworksValueAndSummary(buttonNetworkMode); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 610 | |
| 611 | android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 612 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 613 | buttonNetworkMode ); |
| 614 | //Set the modem network mode |
| 615 | mPhone.setPreferredNetworkType(modemNetworkMode, mHandler |
| 616 | .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)); |
| 617 | } |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 618 | } else if (preference == mButton4glte) { |
Etan Cohen | caeb371 | 2014-08-21 14:56:53 -0700 | [diff] [blame] | 619 | SwitchPreference ltePref = (SwitchPreference)preference; |
| 620 | ltePref.setChecked(!ltePref.isChecked()); |
| 621 | setIMS(ltePref.isChecked()); |
| 622 | |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 623 | ImsManager imsMan = ImsManager.getInstance(getBaseContext(), |
| 624 | SubscriptionManager.getDefaultVoiceSubId()); |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 625 | if (imsMan != null) { |
Etan Cohen | caeb371 | 2014-08-21 14:56:53 -0700 | [diff] [blame] | 626 | |
Etan Cohen | e76b88d | 2014-08-08 16:00:20 -0700 | [diff] [blame] | 627 | try { |
| 628 | imsMan.setAdvanced4GMode(ltePref.isChecked()); |
| 629 | } catch (ImsException ie) { |
| 630 | // do nothing |
| 631 | } |
PauloftheWest | 5f907c3 | 2014-07-25 07:10:44 -0700 | [diff] [blame] | 632 | } |
| 633 | } else if (preference == mButtonDataRoam) { |
| 634 | if (DBG) log("onPreferenceTreeClick: preference == mButtonDataRoam."); |
| 635 | |
| 636 | //normally called on the toggle click |
| 637 | if (!mButtonDataRoam.isChecked()) { |
| 638 | // First confirm with a warning dialog about charges |
| 639 | mOkClicked = false; |
| 640 | new AlertDialog.Builder(this).setMessage( |
| 641 | getResources().getString(R.string.roaming_warning)) |
| 642 | .setTitle(android.R.string.dialog_alert_title) |
| 643 | .setIconAttribute(android.R.attr.alertDialogIcon) |
| 644 | .setPositiveButton(android.R.string.yes, this) |
| 645 | .setNegativeButton(android.R.string.no, this) |
| 646 | .show() |
| 647 | .setOnDismissListener(this); |
| 648 | } else { |
| 649 | mPhone.setDataRoamingEnabled(false); |
| 650 | } |
| 651 | return true; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | // always let the preference setting proceed. |
| 655 | return true; |
| 656 | } |
| 657 | |
| 658 | private class MyHandler extends Handler { |
| 659 | |
| 660 | static final int MESSAGE_GET_PREFERRED_NETWORK_TYPE = 0; |
| 661 | static final int MESSAGE_SET_PREFERRED_NETWORK_TYPE = 1; |
| 662 | |
| 663 | @Override |
| 664 | public void handleMessage(Message msg) { |
| 665 | switch (msg.what) { |
| 666 | case MESSAGE_GET_PREFERRED_NETWORK_TYPE: |
| 667 | handleGetPreferredNetworkTypeResponse(msg); |
| 668 | break; |
| 669 | |
| 670 | case MESSAGE_SET_PREFERRED_NETWORK_TYPE: |
| 671 | handleSetPreferredNetworkTypeResponse(msg); |
| 672 | break; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | private void handleGetPreferredNetworkTypeResponse(Message msg) { |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 677 | final int phoneSubId = mPhone.getSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 678 | AsyncResult ar = (AsyncResult) msg.obj; |
| 679 | |
| 680 | if (ar.exception == null) { |
| 681 | int modemNetworkMode = ((int[])ar.result)[0]; |
| 682 | |
| 683 | if (DBG) { |
| 684 | log ("handleGetPreferredNetworkTypeResponse: modemNetworkMode = " + |
| 685 | modemNetworkMode); |
| 686 | } |
| 687 | |
| 688 | int settingsNetworkMode = android.provider.Settings.Global.getInt( |
| 689 | mPhone.getContext().getContentResolver(), |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 690 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 691 | preferredNetworkMode); |
| 692 | |
| 693 | if (DBG) { |
| 694 | log("handleGetPreferredNetworkTypeReponse: settingsNetworkMode = " + |
| 695 | settingsNetworkMode); |
| 696 | } |
| 697 | |
| 698 | //check that modemNetworkMode is from an accepted value |
| 699 | if (modemNetworkMode == Phone.NT_MODE_WCDMA_PREF || |
| 700 | modemNetworkMode == Phone.NT_MODE_GSM_ONLY || |
| 701 | modemNetworkMode == Phone.NT_MODE_WCDMA_ONLY || |
| 702 | modemNetworkMode == Phone.NT_MODE_GSM_UMTS || |
| 703 | modemNetworkMode == Phone.NT_MODE_CDMA || |
| 704 | modemNetworkMode == Phone.NT_MODE_CDMA_NO_EVDO || |
| 705 | modemNetworkMode == Phone.NT_MODE_EVDO_NO_CDMA || |
| 706 | modemNetworkMode == Phone.NT_MODE_GLOBAL || |
| 707 | modemNetworkMode == Phone.NT_MODE_LTE_CDMA_AND_EVDO || |
| 708 | modemNetworkMode == Phone.NT_MODE_LTE_GSM_WCDMA || |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 709 | modemNetworkMode == Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA || |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 710 | modemNetworkMode == Phone.NT_MODE_LTE_ONLY || |
| 711 | modemNetworkMode == Phone.NT_MODE_LTE_WCDMA) { |
| 712 | if (DBG) { |
| 713 | log("handleGetPreferredNetworkTypeResponse: if 1: modemNetworkMode = " + |
| 714 | modemNetworkMode); |
| 715 | } |
| 716 | |
Junda Liu | 468d784 | 2014-06-24 15:56:12 -0700 | [diff] [blame] | 717 | //check changes in modemNetworkMode |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 718 | if (modemNetworkMode != settingsNetworkMode) { |
| 719 | if (DBG) { |
| 720 | log("handleGetPreferredNetworkTypeResponse: if 2: " + |
| 721 | "modemNetworkMode != settingsNetworkMode"); |
| 722 | } |
| 723 | |
| 724 | settingsNetworkMode = modemNetworkMode; |
| 725 | |
| 726 | if (DBG) { log("handleGetPreferredNetworkTypeResponse: if 2: " + |
| 727 | "settingsNetworkMode = " + settingsNetworkMode); |
| 728 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | UpdatePreferredNetworkModeSummary(modemNetworkMode); |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 732 | UpdateEnabledNetworksValueAndSummary(modemNetworkMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 733 | // changes the mButtonPreferredNetworkMode accordingly to modemNetworkMode |
| 734 | mButtonPreferredNetworkMode.setValue(Integer.toString(modemNetworkMode)); |
| 735 | } else { |
| 736 | if (DBG) log("handleGetPreferredNetworkTypeResponse: else: reset to default"); |
| 737 | resetNetworkModeToDefault(); |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | private void handleSetPreferredNetworkTypeResponse(Message msg) { |
| 743 | AsyncResult ar = (AsyncResult) msg.obj; |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 744 | final int phoneSubId = mPhone.getSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 745 | |
| 746 | if (ar.exception == null) { |
| 747 | int networkMode = Integer.valueOf( |
| 748 | mButtonPreferredNetworkMode.getValue()).intValue(); |
| 749 | android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 750 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 751 | networkMode ); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 752 | networkMode = Integer.valueOf( |
| 753 | mButtonEnabledNetworks.getValue()).intValue(); |
| 754 | android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 755 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 756 | networkMode ); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 757 | } else { |
| 758 | mPhone.getPreferredNetworkType(obtainMessage(MESSAGE_GET_PREFERRED_NETWORK_TYPE)); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | private void resetNetworkModeToDefault() { |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 763 | final int phoneSubId = mPhone.getSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 764 | //set the mButtonPreferredNetworkMode |
| 765 | mButtonPreferredNetworkMode.setValue(Integer.toString(preferredNetworkMode)); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 766 | mButtonEnabledNetworks.setValue(Integer.toString(preferredNetworkMode)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 767 | //set the Settings.System |
| 768 | android.provider.Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 769 | android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 770 | preferredNetworkMode ); |
| 771 | //Set the Modem |
| 772 | mPhone.setPreferredNetworkType(preferredNetworkMode, |
| 773 | this.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)); |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | private void UpdatePreferredNetworkModeSummary(int NetworkMode) { |
| 778 | switch(NetworkMode) { |
| 779 | case Phone.NT_MODE_WCDMA_PREF: |
| 780 | mButtonPreferredNetworkMode.setSummary( |
| 781 | R.string.preferred_network_mode_wcdma_perf_summary); |
| 782 | break; |
| 783 | case Phone.NT_MODE_GSM_ONLY: |
| 784 | mButtonPreferredNetworkMode.setSummary( |
| 785 | R.string.preferred_network_mode_gsm_only_summary); |
| 786 | break; |
| 787 | case Phone.NT_MODE_WCDMA_ONLY: |
| 788 | mButtonPreferredNetworkMode.setSummary( |
| 789 | R.string.preferred_network_mode_wcdma_only_summary); |
| 790 | break; |
| 791 | case Phone.NT_MODE_GSM_UMTS: |
| 792 | mButtonPreferredNetworkMode.setSummary( |
| 793 | R.string.preferred_network_mode_gsm_wcdma_summary); |
| 794 | break; |
| 795 | case Phone.NT_MODE_CDMA: |
| 796 | switch (mPhone.getLteOnCdmaMode()) { |
| 797 | case PhoneConstants.LTE_ON_CDMA_TRUE: |
| 798 | mButtonPreferredNetworkMode.setSummary( |
| 799 | R.string.preferred_network_mode_cdma_summary); |
| 800 | break; |
| 801 | case PhoneConstants.LTE_ON_CDMA_FALSE: |
| 802 | default: |
| 803 | mButtonPreferredNetworkMode.setSummary( |
| 804 | R.string.preferred_network_mode_cdma_evdo_summary); |
| 805 | break; |
| 806 | } |
| 807 | break; |
| 808 | case Phone.NT_MODE_CDMA_NO_EVDO: |
| 809 | mButtonPreferredNetworkMode.setSummary( |
| 810 | R.string.preferred_network_mode_cdma_only_summary); |
| 811 | break; |
| 812 | case Phone.NT_MODE_EVDO_NO_CDMA: |
| 813 | mButtonPreferredNetworkMode.setSummary( |
| 814 | R.string.preferred_network_mode_evdo_only_summary); |
| 815 | break; |
| 816 | case Phone.NT_MODE_LTE_ONLY: |
| 817 | mButtonPreferredNetworkMode.setSummary( |
| 818 | R.string.preferred_network_mode_lte_summary); |
| 819 | break; |
| 820 | case Phone.NT_MODE_LTE_GSM_WCDMA: |
| 821 | mButtonPreferredNetworkMode.setSummary( |
| 822 | R.string.preferred_network_mode_lte_gsm_wcdma_summary); |
| 823 | break; |
| 824 | case Phone.NT_MODE_LTE_CDMA_AND_EVDO: |
| 825 | mButtonPreferredNetworkMode.setSummary( |
| 826 | R.string.preferred_network_mode_lte_cdma_evdo_summary); |
| 827 | break; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 828 | case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA: |
Amit Mahajan | f85c95a | 2014-11-07 14:49:19 -0800 | [diff] [blame] | 829 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Amit Mahajan | af65e4f | 2014-11-05 15:25:11 -0800 | [diff] [blame] | 830 | mButtonPreferredNetworkMode.setSummary( |
| 831 | R.string.preferred_network_mode_global_summary); |
| 832 | } else { |
| 833 | mButtonPreferredNetworkMode.setSummary( |
| 834 | R.string.preferred_network_mode_lte_summary); |
| 835 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 836 | break; |
| 837 | case Phone.NT_MODE_GLOBAL: |
| 838 | mButtonPreferredNetworkMode.setSummary( |
| 839 | R.string.preferred_network_mode_cdma_evdo_gsm_wcdma_summary); |
| 840 | break; |
| 841 | case Phone.NT_MODE_LTE_WCDMA: |
| 842 | mButtonPreferredNetworkMode.setSummary( |
| 843 | R.string.preferred_network_mode_lte_wcdma_summary); |
| 844 | break; |
| 845 | default: |
| 846 | mButtonPreferredNetworkMode.setSummary( |
| 847 | R.string.preferred_network_mode_global_summary); |
| 848 | } |
| 849 | } |
| 850 | |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 851 | private void UpdateEnabledNetworksValueAndSummary(int NetworkMode) { |
| 852 | switch (NetworkMode) { |
| 853 | case Phone.NT_MODE_WCDMA_ONLY: |
| 854 | case Phone.NT_MODE_GSM_UMTS: |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 855 | case Phone.NT_MODE_WCDMA_PREF: |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 856 | if (!mIsGlobalCdma) { |
| 857 | mButtonEnabledNetworks.setValue( |
| 858 | Integer.toString(Phone.NT_MODE_WCDMA_PREF)); |
Sungmin Choi | b0449b3 | 2013-10-14 17:22:38 -0700 | [diff] [blame] | 859 | mButtonEnabledNetworks.setSummary(R.string.network_3G); |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 860 | } else { |
| 861 | mButtonEnabledNetworks.setValue( |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 862 | Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA)); |
Sungmin Choi | b0449b3 | 2013-10-14 17:22:38 -0700 | [diff] [blame] | 863 | mButtonEnabledNetworks.setSummary(R.string.network_global); |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 864 | } |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 865 | break; |
| 866 | case Phone.NT_MODE_GSM_ONLY: |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 867 | if (!mIsGlobalCdma) { |
| 868 | mButtonEnabledNetworks.setValue( |
| 869 | Integer.toString(Phone.NT_MODE_GSM_ONLY)); |
Sungmin Choi | b0449b3 | 2013-10-14 17:22:38 -0700 | [diff] [blame] | 870 | mButtonEnabledNetworks.setSummary(R.string.network_2G); |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 871 | } else { |
| 872 | mButtonEnabledNetworks.setValue( |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 873 | Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA)); |
Sungmin Choi | b0449b3 | 2013-10-14 17:22:38 -0700 | [diff] [blame] | 874 | mButtonEnabledNetworks.setSummary(R.string.network_global); |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 875 | } |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 876 | break; |
| 877 | case Phone.NT_MODE_LTE_GSM_WCDMA: |
Rohit Sisodia (a21406) | dfa0410 | 2014-11-05 16:42:24 -0600 | [diff] [blame] | 878 | if (isWorldMode()) { |
Rohit Sisodia (a21406) | 3a4447b | 2014-10-10 14:05:11 -0500 | [diff] [blame] | 879 | mButtonEnabledNetworks.setSummary( |
| 880 | R.string.preferred_network_mode_lte_gsm_umts_summary); |
Rohit Sisodia (a21406) | dfa0410 | 2014-11-05 16:42:24 -0600 | [diff] [blame] | 881 | controlCdmaOptions(false); |
| 882 | controlGsmOptions(true); |
Rohit Sisodia (a21406) | 3a4447b | 2014-10-10 14:05:11 -0500 | [diff] [blame] | 883 | break; |
| 884 | } |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 885 | case Phone.NT_MODE_LTE_ONLY: |
| 886 | case Phone.NT_MODE_LTE_WCDMA: |
| 887 | if (!mIsGlobalCdma) { |
| 888 | mButtonEnabledNetworks.setValue( |
| 889 | Integer.toString(Phone.NT_MODE_LTE_GSM_WCDMA)); |
Sungmin Choi | b0449b3 | 2013-10-14 17:22:38 -0700 | [diff] [blame] | 890 | mButtonEnabledNetworks.setSummary((mShow4GForLTE == true) |
| 891 | ? R.string.network_4G : R.string.network_lte); |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 892 | } else { |
| 893 | mButtonEnabledNetworks.setValue( |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 894 | Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA)); |
Sungmin Choi | b0449b3 | 2013-10-14 17:22:38 -0700 | [diff] [blame] | 895 | mButtonEnabledNetworks.setSummary(R.string.network_global); |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 896 | } |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 897 | break; |
| 898 | case Phone.NT_MODE_LTE_CDMA_AND_EVDO: |
Rohit Sisodia (a21406) | dfa0410 | 2014-11-05 16:42:24 -0600 | [diff] [blame] | 899 | if (isWorldMode()) { |
Rohit Sisodia (a21406) | 3a4447b | 2014-10-10 14:05:11 -0500 | [diff] [blame] | 900 | mButtonEnabledNetworks.setSummary( |
| 901 | R.string.preferred_network_mode_lte_cdma_summary); |
Rohit Sisodia (a21406) | dfa0410 | 2014-11-05 16:42:24 -0600 | [diff] [blame] | 902 | controlCdmaOptions(true); |
| 903 | controlGsmOptions(false); |
Rohit Sisodia (a21406) | 3a4447b | 2014-10-10 14:05:11 -0500 | [diff] [blame] | 904 | } else { |
| 905 | mButtonEnabledNetworks.setValue( |
| 906 | Integer.toString(Phone.NT_MODE_LTE_CDMA_AND_EVDO)); |
| 907 | mButtonEnabledNetworks.setSummary(R.string.network_lte); |
| 908 | } |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 909 | break; |
| 910 | case Phone.NT_MODE_CDMA: |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 911 | case Phone.NT_MODE_EVDO_NO_CDMA: |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 912 | case Phone.NT_MODE_GLOBAL: |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 913 | mButtonEnabledNetworks.setValue( |
| 914 | Integer.toString(Phone.NT_MODE_CDMA)); |
Sungmin Choi | b0449b3 | 2013-10-14 17:22:38 -0700 | [diff] [blame] | 915 | mButtonEnabledNetworks.setSummary(R.string.network_3G); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 916 | break; |
| 917 | case Phone.NT_MODE_CDMA_NO_EVDO: |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 918 | mButtonEnabledNetworks.setValue( |
| 919 | Integer.toString(Phone.NT_MODE_CDMA_NO_EVDO)); |
Sungmin Choi | b0449b3 | 2013-10-14 17:22:38 -0700 | [diff] [blame] | 920 | mButtonEnabledNetworks.setSummary(R.string.network_1x); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 921 | break; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 922 | case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA: |
Rohit Sisodia (a21406) | dfa0410 | 2014-11-05 16:42:24 -0600 | [diff] [blame] | 923 | if (isWorldMode()) { |
| 924 | controlCdmaOptions(true); |
| 925 | controlGsmOptions(false); |
| 926 | } |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 927 | mButtonEnabledNetworks.setValue( |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 928 | Integer.toString(Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA)); |
Amit Mahajan | f85c95a | 2014-11-07 14:49:19 -0800 | [diff] [blame] | 929 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Amit Mahajan | af65e4f | 2014-11-05 15:25:11 -0800 | [diff] [blame] | 930 | mButtonEnabledNetworks.setSummary(R.string.network_global); |
| 931 | } else { |
| 932 | mButtonEnabledNetworks.setSummary((mShow4GForLTE == true) |
| 933 | ? R.string.network_4G : R.string.network_lte); |
| 934 | } |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 935 | break; |
| 936 | default: |
Sungmin Choi | 6bb4d44 | 2013-10-15 22:54:10 -0700 | [diff] [blame] | 937 | String errMsg = "Invalid Network Mode (" + NetworkMode + "). Ignore."; |
| 938 | loge(errMsg); |
| 939 | mButtonEnabledNetworks.setSummary(errMsg); |
Sungmin Choi | 2127037 | 2013-09-17 17:19:51 -0700 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 943 | @Override |
| 944 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 945 | switch(requestCode) { |
| 946 | case REQUEST_CODE_EXIT_ECM: |
| 947 | Boolean isChoiceYes = |
| 948 | data.getBooleanExtra(EmergencyCallbackModeExitDialog.EXTRA_EXIT_ECM_RESULT, false); |
| 949 | if (isChoiceYes) { |
| 950 | // If the phone exits from ECM mode, show the CDMA Options |
| 951 | mCdmaOptions.showDialog(mClickedPreference); |
| 952 | } else { |
| 953 | // do nothing |
| 954 | } |
| 955 | break; |
| 956 | |
| 957 | default: |
| 958 | break; |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | private static void log(String msg) { |
| 963 | Log.d(LOG_TAG, msg); |
| 964 | } |
| 965 | |
| 966 | private static void loge(String msg) { |
| 967 | Log.e(LOG_TAG, msg); |
| 968 | } |
| 969 | |
| 970 | @Override |
| 971 | public boolean onOptionsItemSelected(MenuItem item) { |
| 972 | final int itemId = item.getItemId(); |
| 973 | if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled() |
| 974 | // Commenting out "logical up" capability. This is a workaround for issue 5278083. |
| 975 | // |
| 976 | // Settings app may not launch this activity via UP_ACTIVITY_CLASS but the other |
| 977 | // Activity that looks exactly same as UP_ACTIVITY_CLASS ("SubSettings" Activity). |
| 978 | // At that moment, this Activity launches UP_ACTIVITY_CLASS on top of the Activity. |
| 979 | // which confuses users. |
| 980 | // TODO: introduce better mechanism for "up" capability here. |
| 981 | /*Intent intent = new Intent(Intent.ACTION_MAIN); |
| 982 | intent.setClassName(UP_ACTIVITY_PACKAGE, UP_ACTIVITY_CLASS); |
| 983 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 984 | startActivity(intent);*/ |
| 985 | finish(); |
| 986 | return true; |
| 987 | } |
| 988 | return super.onOptionsItemSelected(item); |
| 989 | } |
Rohit Sisodia (a21406) | 3a4447b | 2014-10-10 14:05:11 -0500 | [diff] [blame] | 990 | |
| 991 | private boolean isWorldMode() { |
| 992 | boolean worldModeOn = false; |
| 993 | final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
| 994 | final String configString = getResources().getString(R.string.config_world_mode); |
| 995 | |
| 996 | if (!TextUtils.isEmpty(configString)) { |
| 997 | String[] configArray = configString.split(";"); |
| 998 | // Check if we have World mode configuration set to True only or config is set to True |
| 999 | // and SIM GID value is also set and matches to the current SIM GID. |
| 1000 | if (configArray != null && |
| 1001 | ((configArray.length == 1 && configArray[0].equalsIgnoreCase("true")) || |
| 1002 | (configArray.length == 2 && !TextUtils.isEmpty(configArray[1]) && |
| 1003 | tm != null && configArray[1].equalsIgnoreCase(tm.getGroupIdLevel1())))) { |
| 1004 | worldModeOn = true; |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | if (DBG) { |
| 1009 | log("World mode is set to" + worldModeOn); |
| 1010 | } |
| 1011 | |
| 1012 | return worldModeOn; |
| 1013 | } |
Rohit Sisodia (a21406) | dfa0410 | 2014-11-05 16:42:24 -0600 | [diff] [blame] | 1014 | |
| 1015 | private void controlGsmOptions(boolean enable) { |
| 1016 | PreferenceScreen prefSet = getPreferenceScreen(); |
| 1017 | if (prefSet == null) { |
| 1018 | return; |
| 1019 | } |
| 1020 | |
| 1021 | if (enable && mGsmUmtsOptions == null) { |
| 1022 | mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet); |
| 1023 | } |
| 1024 | PreferenceScreen apnExpand = |
| 1025 | (PreferenceScreen) prefSet.findPreference(BUTTON_APN_EXPAND_KEY); |
| 1026 | PreferenceScreen operatorSelectionExpand = |
| 1027 | (PreferenceScreen) prefSet.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY); |
| 1028 | PreferenceScreen carrierSettings = |
| 1029 | (PreferenceScreen) prefSet.findPreference(BUTTON_CARRIER_SETTINGS_KEY); |
| 1030 | if (apnExpand != null) { |
| 1031 | apnExpand.setEnabled(enable); |
| 1032 | } |
| 1033 | if (operatorSelectionExpand != null) { |
| 1034 | operatorSelectionExpand.setEnabled(enable); |
| 1035 | } |
| 1036 | if (carrierSettings != null) { |
| 1037 | prefSet.removePreference(carrierSettings); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | private void controlCdmaOptions(boolean enable) { |
| 1042 | PreferenceScreen prefSet = getPreferenceScreen(); |
| 1043 | if (prefSet == null) { |
| 1044 | return; |
| 1045 | } |
| 1046 | if (enable && mCdmaOptions == null) { |
| 1047 | mCdmaOptions = new CdmaOptions(this, prefSet, mPhone); |
| 1048 | } |
| 1049 | CdmaSystemSelectListPreference systemSelect = |
| 1050 | (CdmaSystemSelectListPreference)prefSet.findPreference |
| 1051 | (BUTTON_CDMA_SYSTEM_SELECT_KEY); |
| 1052 | if (systemSelect != null) { |
| 1053 | systemSelect.setEnabled(enable); |
| 1054 | } |
| 1055 | } |
PauloftheWest | 3c6ce5e | 2014-11-03 07:09:47 -0800 | [diff] [blame] | 1056 | |
| 1057 | /** |
| 1058 | * finds a record with slotId. |
| 1059 | * Since the number of SIMs are few, an array is fine. |
| 1060 | */ |
| 1061 | public static SubscriptionInfo findRecordBySlotId(final int slotId) { |
| 1062 | final List<SubscriptionInfo> subInfoList = |
| 1063 | SubscriptionManager.getActiveSubscriptionInfoList(); |
| 1064 | final int subInfoLength = subInfoList.size(); |
| 1065 | |
| 1066 | for (int i = 0; i < subInfoLength; ++i) { |
| 1067 | final SubscriptionInfo sir = subInfoList.get(i); |
| 1068 | if (sir.getSimSlotIndex() == slotId) { |
| 1069 | //Right now we take the first subscription on a SIM. |
| 1070 | return sir; |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | return null; |
| 1075 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1076 | } |