The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 2 | * Copyright (C) 2009 The Android Open Source Project |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 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.settings; |
| 18 | |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 19 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 20 | import android.app.Activity; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 21 | import android.app.AlertDialog; |
| 22 | import android.app.Dialog; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 23 | import android.app.admin.DevicePolicyManager; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 24 | import android.content.ComponentName; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 25 | import android.content.Context; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 26 | import android.content.DialogInterface; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 27 | import android.content.Intent; |
Irfan Sheriff | 167d718 | 2011-09-07 14:51:11 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 29 | import android.content.pm.PackageManager.NameNotFoundException; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 30 | import android.content.res.Resources; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 32 | import android.net.ConnectivityManager; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 33 | import android.net.NetworkInfo; |
Nick Pelly | a57eace | 2010-10-15 01:19:43 -0700 | [diff] [blame] | 34 | import android.nfc.NfcAdapter; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 35 | import android.os.Bundle; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 36 | import android.os.SystemProperties; |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 37 | import android.os.UserHandle; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 38 | import android.preference.CheckBoxPreference; |
| 39 | import android.preference.Preference; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 40 | import android.preference.Preference.OnPreferenceChangeListener; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 41 | import android.preference.PreferenceScreen; |
| 42 | import android.provider.Settings; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 43 | import android.telephony.TelephonyManager; |
| 44 | import android.text.TextUtils; |
| 45 | import android.util.Log; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 46 | |
| 47 | import com.android.internal.telephony.SmsApplication; |
| 48 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 49 | import com.android.internal.telephony.TelephonyIntents; |
| 50 | import com.android.internal.telephony.TelephonyProperties; |
| 51 | import com.android.settings.nfc.NfcEnabler; |
| 52 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 53 | import java.util.Collection; |
| 54 | |
| 55 | public class WirelessSettings extends RestrictedSettingsFragment |
| 56 | implements OnPreferenceChangeListener { |
Robert Greenwalt | 4929e91 | 2013-07-16 13:09:24 -0700 | [diff] [blame] | 57 | private static final String TAG = "WirelessSettings"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 58 | |
| 59 | private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 60 | private static final String KEY_TOGGLE_NFC = "toggle_nfc"; |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 61 | private static final String KEY_WIMAX_SETTINGS = "wimax_settings"; |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 62 | private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings"; |
Mike Lockwood | 83bcc98 | 2009-07-29 23:25:10 -0700 | [diff] [blame] | 63 | private static final String KEY_VPN_SETTINGS = "vpn_settings"; |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 64 | private static final String KEY_TETHER_SETTINGS = "tether_settings"; |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 65 | private static final String KEY_PROXY_SETTINGS = "proxy_settings"; |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 66 | private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings"; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 67 | private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan"; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 68 | private static final String KEY_SMS_APPLICATION = "sms_application"; |
Irfan Sheriff | 536c3d7 | 2012-04-17 23:17:46 -0700 | [diff] [blame] | 69 | private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 70 | private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings"; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 71 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 72 | public static final String EXIT_ECM_RESULT = "exit_ecm_result"; |
| 73 | public static final int REQUEST_CODE_EXIT_ECM = 1; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 74 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 75 | private AirplaneModeEnabler mAirplaneModeEnabler; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 76 | private CheckBoxPreference mAirplaneModePreference; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 77 | private NfcEnabler mNfcEnabler; |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 78 | private NfcAdapter mNfcAdapter; |
Irfan Sheriff | 536c3d7 | 2012-04-17 23:17:46 -0700 | [diff] [blame] | 79 | private NsdEnabler mNsdEnabler; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 80 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 81 | private ConnectivityManager mCm; |
| 82 | private TelephonyManager mTm; |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 83 | private PackageManager mPm; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 84 | |
| 85 | private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1; |
| 86 | private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage"; |
| 87 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 88 | private SmsListPreference mSmsApplicationPreference; |
| 89 | |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 90 | public WirelessSettings() { |
| 91 | super(null); |
| 92 | } |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 93 | /** |
| 94 | * Invoked on each preference click in this hierarchy, overrides |
| 95 | * PreferenceActivity's implementation. Used to make sure we track the |
| 96 | * preference click events. |
| 97 | */ |
| 98 | @Override |
| 99 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Geoffrey Borggaard | 6e1102d | 2013-08-07 14:57:43 -0400 | [diff] [blame] | 100 | if (ensurePinRestrictedPreference(preference)) { |
| 101 | return true; |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 102 | } |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 103 | log("onPreferenceTreeClick: preference=" + preference); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 104 | if (preference == mAirplaneModePreference && Boolean.parseBoolean( |
| 105 | SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 106 | // In ECM mode launch ECM app dialog |
| 107 | startActivityForResult( |
| 108 | new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null), |
| 109 | REQUEST_CODE_EXIT_ECM); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 110 | return true; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 111 | } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) { |
| 112 | onManageMobilePlanClick(); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 113 | } |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 114 | // Let the intents be launched by the Preference manager |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 115 | return super.onPreferenceTreeClick(preferenceScreen, preference); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 116 | } |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 117 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 118 | private String mManageMobilePlanMessage; |
Wink Saville | 7bee4c2 | 2013-08-29 19:58:09 -0700 | [diff] [blame] | 119 | private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION |
| 120 | = "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION"; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 121 | public void onManageMobilePlanClick() { |
| 122 | log("onManageMobilePlanClick:"); |
| 123 | mManageMobilePlanMessage = null; |
| 124 | Resources resources = getActivity().getResources(); |
| 125 | |
Wink Saville | e24e596 | 2013-08-28 14:26:27 -0700 | [diff] [blame] | 126 | NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo(); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 127 | if (mTm.hasIccCard() && (ni != null)) { |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 128 | // Check for carrier apps that can handle provisioning first |
| 129 | Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP); |
| 130 | provisioningIntent.addCategory(TelephonyIntents.CATEGORY_MCCMNC_PREFIX |
| 131 | + mTm.getSimOperator()); |
| 132 | if (mPm.resolveActivity(provisioningIntent, 0 /* flags */) != null) { |
| 133 | startActivity(provisioningIntent); |
| 134 | return; |
| 135 | } |
| 136 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 137 | // Get provisioning URL |
Robert Greenwalt | 4929e91 | 2013-07-16 13:09:24 -0700 | [diff] [blame] | 138 | String url = mCm.getMobileProvisioningUrl(); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 139 | if (!TextUtils.isEmpty(url)) { |
Wink Saville | 7bee4c2 | 2013-08-29 19:58:09 -0700 | [diff] [blame] | 140 | Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION); |
Wink Saville | e24e596 | 2013-08-28 14:26:27 -0700 | [diff] [blame] | 141 | intent.putExtra("EXTRA_URL", url); |
| 142 | Context context = getActivity().getBaseContext(); |
| 143 | context.sendBroadcast(intent); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 144 | mManageMobilePlanMessage = null; |
| 145 | } else { |
| 146 | // No provisioning URL |
| 147 | String operatorName = mTm.getSimOperatorName(); |
| 148 | if (TextUtils.isEmpty(operatorName)) { |
| 149 | // Use NetworkOperatorName as second choice in case there is no |
| 150 | // SPN (Service Provider Name on the SIM). Such as with T-mobile. |
| 151 | operatorName = mTm.getNetworkOperatorName(); |
| 152 | if (TextUtils.isEmpty(operatorName)) { |
| 153 | mManageMobilePlanMessage = resources.getString( |
| 154 | R.string.mobile_unknown_sim_operator); |
| 155 | } else { |
| 156 | mManageMobilePlanMessage = resources.getString( |
| 157 | R.string.mobile_no_provisioning_url, operatorName); |
| 158 | } |
| 159 | } else { |
| 160 | mManageMobilePlanMessage = resources.getString( |
| 161 | R.string.mobile_no_provisioning_url, operatorName); |
| 162 | } |
| 163 | } |
| 164 | } else if (mTm.hasIccCard() == false) { |
| 165 | // No sim card |
| 166 | mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card); |
| 167 | } else { |
| 168 | // NetworkInfo is null, there is no connection |
| 169 | mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet); |
| 170 | } |
| 171 | if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { |
| 172 | log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage); |
| 173 | showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID); |
| 174 | } |
| 175 | } |
| 176 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 177 | private void updateSmsApplicationSetting() { |
| 178 | log("updateSmsApplicationSetting:"); |
| 179 | ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true); |
| 180 | if (appName != null) { |
| 181 | String packageName = appName.getPackageName(); |
| 182 | |
| 183 | CharSequence[] values = mSmsApplicationPreference.getEntryValues(); |
| 184 | for (int i = 0; i < values.length; i++) { |
| 185 | if (packageName.contentEquals(values[i])) { |
| 186 | mSmsApplicationPreference.setValueIndex(i); |
| 187 | mSmsApplicationPreference.setSummary(mSmsApplicationPreference.getEntries()[i]); |
| 188 | break; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | private void initSmsApplicationSetting() { |
| 195 | log("initSmsApplicationSetting:"); |
| 196 | Collection<SmsApplicationData> smsApplications = |
| 197 | SmsApplication.getApplicationCollection(getActivity()); |
| 198 | |
| 199 | // If the list is empty the dialog will be empty, but we will not crash. |
| 200 | int count = smsApplications.size(); |
| 201 | CharSequence[] entries = new CharSequence[count]; |
| 202 | CharSequence[] entryValues = new CharSequence[count]; |
| 203 | Drawable[] entryImages = new Drawable[count]; |
| 204 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 205 | int i = 0; |
| 206 | for (SmsApplicationData smsApplicationData : smsApplications) { |
| 207 | entries[i] = smsApplicationData.mApplicationName; |
| 208 | entryValues[i] = smsApplicationData.mPackageName; |
| 209 | try { |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 210 | entryImages[i] = mPm.getApplicationIcon(smsApplicationData.mPackageName); |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 211 | } catch (NameNotFoundException e) { |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 212 | entryImages[i] = mPm.getDefaultActivityIcon(); |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 213 | } |
| 214 | i++; |
| 215 | } |
| 216 | mSmsApplicationPreference.setEntries(entries); |
| 217 | mSmsApplicationPreference.setEntryValues(entryValues); |
| 218 | mSmsApplicationPreference.setEntryDrawables(entryImages); |
| 219 | updateSmsApplicationSetting(); |
| 220 | } |
| 221 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 222 | @Override |
| 223 | public Dialog onCreateDialog(int dialogId) { |
| 224 | log("onCreateDialog: dialogId=" + dialogId); |
| 225 | switch (dialogId) { |
| 226 | case MANAGE_MOBILE_PLAN_DIALOG_ID: |
| 227 | return new AlertDialog.Builder(getActivity()) |
| 228 | .setMessage(mManageMobilePlanMessage) |
| 229 | .setCancelable(false) |
| 230 | .setPositiveButton(com.android.internal.R.string.ok, |
| 231 | new DialogInterface.OnClickListener() { |
| 232 | @Override |
| 233 | public void onClick(DialogInterface dialog, int id) { |
| 234 | log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id); |
| 235 | mManageMobilePlanMessage = null; |
| 236 | } |
| 237 | }) |
| 238 | .create(); |
| 239 | } |
| 240 | return super.onCreateDialog(dialogId); |
| 241 | } |
| 242 | |
| 243 | private void log(String s) { |
| 244 | Log.d(TAG, s); |
| 245 | } |
| 246 | |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 247 | public static boolean isRadioAllowed(Context context, String type) { |
| 248 | if (!AirplaneModeEnabler.isAirplaneModeOn(context)) { |
| 249 | return true; |
| 250 | } |
| 251 | // Here we use the same logic in onCreate(). |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 252 | String toggleable = Settings.Global.getString(context.getContentResolver(), |
| 253 | Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 254 | return toggleable != null && toggleable.contains(type); |
| 255 | } |
| 256 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 257 | private boolean isSmsSupported() { |
| 258 | // Some tablet has sim card but could not do telephony operations. Skip those. |
David Braun | d5b6001 | 2013-10-01 17:10:46 -0700 | [diff] [blame] | 259 | return (mTm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE); |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 260 | } |
| 261 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 262 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 263 | public void onCreate(Bundle savedInstanceState) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 264 | super.onCreate(savedInstanceState); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 265 | if (savedInstanceState != null) { |
| 266 | mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG); |
| 267 | } |
| 268 | log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage); |
| 269 | |
| 270 | mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); |
| 271 | mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 272 | mPm = getPackageManager(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 273 | |
| 274 | addPreferencesFromResource(R.xml.wireless_settings); |
| 275 | |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 276 | final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER; |
| 277 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 278 | final Activity activity = getActivity(); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 279 | mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE); |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 280 | CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 281 | PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS); |
Irfan Sheriff | 536c3d7 | 2012-04-17 23:17:46 -0700 | [diff] [blame] | 282 | CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 283 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 284 | mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 285 | mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam); |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 286 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 287 | mSmsApplicationPreference = (SmsListPreference) findPreference(KEY_SMS_APPLICATION); |
| 288 | mSmsApplicationPreference.setOnPreferenceChangeListener(this); |
David Braun | be1f0a1 | 2013-09-20 14:15:32 -0700 | [diff] [blame] | 289 | initSmsApplicationSetting(); |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 290 | |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 291 | // Remove NSD checkbox by default |
| 292 | getPreferenceScreen().removePreference(nsd); |
| 293 | //mNsdEnabler = new NsdEnabler(activity, nsd); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 294 | |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 295 | String toggleable = Settings.Global.getString(activity.getContentResolver(), |
| 296 | Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 297 | |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 298 | //enable/disable wimax depending on the value in config.xml |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 299 | boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean( |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 300 | com.android.internal.R.bool.config_wimaxEnabled); |
| 301 | if (!isWimaxEnabled) { |
| 302 | PreferenceScreen root = getPreferenceScreen(); |
| 303 | Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS); |
| 304 | if (ps != null) root.removePreference(ps); |
| 305 | } else { |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 306 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX ) |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 307 | && isWimaxEnabled) { |
| 308 | Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS); |
| 309 | ps.setDependency(KEY_TOGGLE_AIRPLANE); |
| 310 | } |
| 311 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 312 | protectByRestrictions(KEY_WIMAX_SETTINGS); |
| 313 | |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 314 | // Manually set dependencies for Wifi when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 315 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 316 | findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
| 317 | } |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 318 | if (isSecondaryUser) { // Disable VPN |
| 319 | removePreference(KEY_VPN_SETTINGS); |
| 320 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 321 | protectByRestrictions(KEY_VPN_SETTINGS); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 322 | // Manually set dependencies for Bluetooth when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 323 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 324 | // No bluetooth-dependent items in the list. Code kept in case one is added later. |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 327 | // Manually set dependencies for NFC when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 328 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) { |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 329 | findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 330 | findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 333 | // Remove NFC if its not available |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 334 | mNfcAdapter = NfcAdapter.getDefaultAdapter(activity); |
| 335 | if (mNfcAdapter == null) { |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 336 | getPreferenceScreen().removePreference(nfc); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 337 | getPreferenceScreen().removePreference(androidBeam); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 338 | mNfcEnabler = null; |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 339 | } |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 340 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 341 | // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device. |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 342 | if (isSecondaryUser || Utils.isWifiOnly(getActivity())) { |
| 343 | removePreference(KEY_MOBILE_NETWORK_SETTINGS); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 344 | removePreference(KEY_MANAGE_MOBILE_PLAN); |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 345 | } |
Sungmin Choi | 2490315 | 2013-10-15 16:11:55 -0700 | [diff] [blame] | 346 | // Remove Mobile Network Settings and Manage Mobile Plan |
| 347 | // if config_show_mobile_plan sets false. |
| 348 | boolean isMobilePlanEnabled = this.getResources().getBoolean( |
| 349 | R.bool.config_show_mobile_plan); |
| 350 | if (!isMobilePlanEnabled) { |
| 351 | Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN); |
| 352 | if (pref != null) { |
| 353 | removePreference(KEY_MANAGE_MOBILE_PLAN); |
| 354 | } |
| 355 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 356 | protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS); |
| 357 | protectByRestrictions(KEY_MANAGE_MOBILE_PLAN); |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 358 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 359 | // Remove SMS Application if the device does not support SMS |
| 360 | if (!isSmsSupported()) { |
| 361 | removePreference(KEY_SMS_APPLICATION); |
| 362 | } |
| 363 | |
Jaewan Kim | 2e41e3d | 2013-04-19 13:40:23 +0900 | [diff] [blame] | 364 | // Remove Airplane Mode settings if it's a stationary device such as a TV. |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 365 | if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) { |
Jaewan Kim | 2e41e3d | 2013-04-19 13:40:23 +0900 | [diff] [blame] | 366 | removePreference(KEY_TOGGLE_AIRPLANE); |
| 367 | } |
| 368 | |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 369 | // Enable Proxy selector settings if allowed. |
| 370 | Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 371 | DevicePolicyManager mDPM = (DevicePolicyManager) |
| 372 | activity.getSystemService(Context.DEVICE_POLICY_SERVICE); |
Robert Greenwalt | 6f3a98b | 2010-12-28 16:11:12 -0800 | [diff] [blame] | 373 | // proxy UI disabled until we have better app support |
| 374 | getPreferenceScreen().removePreference(mGlobalProxy); |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 375 | mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null); |
| 376 | |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 377 | // Disable Tethering if it's not allowed or if it's a wifi-only device |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 378 | ConnectivityManager cm = |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 379 | (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 380 | if (isSecondaryUser || !cm.isTetheringSupported()) { |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 381 | getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS)); |
Robert Greenwalt | e434bfb | 2010-05-08 15:20:24 -0700 | [diff] [blame] | 382 | } else { |
Robert Greenwalt | e434bfb | 2010-05-08 15:20:24 -0700 | [diff] [blame] | 383 | Preference p = findPreference(KEY_TETHER_SETTINGS); |
Jeff Sharkey | a83a24f | 2011-09-16 01:52:39 -0700 | [diff] [blame] | 384 | p.setTitle(Utils.getTetheringLabel(cm)); |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 385 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 386 | protectByRestrictions(KEY_TETHER_SETTINGS); |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 387 | |
| 388 | // Enable link to CMAS app settings depending on the value in config.xml. |
| 389 | boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean( |
| 390 | com.android.internal.R.bool.config_cellBroadcastAppLinks); |
| 391 | try { |
| 392 | if (isCellBroadcastAppLinkEnabled) { |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 393 | if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 394 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { |
| 395 | isCellBroadcastAppLinkEnabled = false; // CMAS app disabled |
| 396 | } |
| 397 | } |
| 398 | } catch (IllegalArgumentException ignored) { |
| 399 | isCellBroadcastAppLinkEnabled = false; // CMAS app not installed |
| 400 | } |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 401 | if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) { |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 402 | PreferenceScreen root = getPreferenceScreen(); |
| 403 | Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS); |
| 404 | if (ps != null) root.removePreference(ps); |
| 405 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 406 | protectByRestrictions(KEY_CELL_BROADCAST_SETTINGS); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 407 | } |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 408 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 409 | @Override |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 410 | public void onStart() { |
| 411 | super.onStart(); |
| 412 | |
| 413 | initSmsApplicationSetting(); |
| 414 | } |
| 415 | |
| 416 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 417 | public void onResume() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 418 | super.onResume(); |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 419 | |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 420 | mAirplaneModeEnabler.resume(); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 421 | if (mNfcEnabler != null) { |
| 422 | mNfcEnabler.resume(); |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 423 | } |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 424 | if (mNsdEnabler != null) { |
| 425 | mNsdEnabler.resume(); |
| 426 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 427 | } |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 428 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 429 | @Override |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 430 | public void onSaveInstanceState(Bundle outState) { |
| 431 | super.onSaveInstanceState(outState); |
| 432 | |
| 433 | if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { |
| 434 | outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 439 | public void onPause() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 440 | super.onPause(); |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 441 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 442 | mAirplaneModeEnabler.pause(); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 443 | if (mNfcEnabler != null) { |
| 444 | mNfcEnabler.pause(); |
| 445 | } |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 446 | if (mNsdEnabler != null) { |
| 447 | mNsdEnabler.pause(); |
| 448 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 449 | } |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 450 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 451 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 452 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 453 | if (requestCode == REQUEST_CODE_EXIT_ECM) { |
| 454 | Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 455 | // Set Airplane mode based on the return value and checkbox state |
| 456 | mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes, |
| 457 | mAirplaneModePreference.isChecked()); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 458 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 459 | super.onActivityResult(requestCode, resultCode, data); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 460 | } |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame] | 461 | |
| 462 | @Override |
| 463 | protected int getHelpResource() { |
| 464 | return R.string.help_url_more_networks; |
| 465 | } |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 466 | |
| 467 | @Override |
| 468 | public boolean onPreferenceChange(Preference preference, Object newValue) { |
| 469 | if (preference == mSmsApplicationPreference && newValue != null) { |
| 470 | SmsApplication.setDefaultApplication(newValue.toString(), getActivity()); |
| 471 | updateSmsApplicationSetting(); |
| 472 | return true; |
| 473 | } |
| 474 | return false; |
| 475 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 476 | } |