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