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; |
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; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 29 | import android.content.res.Resources; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 30 | import android.net.ConnectivityManager; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 31 | import android.net.NetworkInfo; |
Paul Jensen | d96c5fc | 2014-10-17 22:09:37 -0400 | [diff] [blame] | 32 | import android.net.Uri; |
Nick Pelly | a57eace | 2010-10-15 01:19:43 -0700 | [diff] [blame] | 33 | import android.nfc.NfcAdapter; |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 34 | import android.nfc.NfcManager; |
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; |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 37 | import android.os.UserManager; |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 38 | import android.provider.SearchIndexableResource; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 39 | import android.provider.Settings; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 40 | import android.support.v14.preference.SwitchPreference; |
| 41 | import android.support.v7.preference.Preference; |
| 42 | import android.support.v7.preference.PreferenceScreen; |
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 | |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame] | 47 | import com.android.ims.ImsManager; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 48 | import com.android.internal.logging.MetricsLogger; |
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; |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 52 | import com.android.settings.search.BaseSearchIndexProvider; |
| 53 | import com.android.settings.search.Indexable; |
Jason Monk | 73a2496 | 2015-04-13 20:58:05 -0400 | [diff] [blame] | 54 | |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 55 | import java.util.ArrayList; |
| 56 | import java.util.Arrays; |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 57 | import java.util.List; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 58 | |
Jason Monk | 73a2496 | 2015-04-13 20:58:05 -0400 | [diff] [blame] | 59 | public class WirelessSettings extends SettingsPreferenceFragment implements Indexable { |
Robert Greenwalt | 4929e91 | 2013-07-16 13:09:24 -0700 | [diff] [blame] | 60 | private static final String TAG = "WirelessSettings"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 61 | |
| 62 | private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 63 | private static final String KEY_TOGGLE_NFC = "toggle_nfc"; |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 64 | private static final String KEY_WIMAX_SETTINGS = "wimax_settings"; |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 65 | private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings"; |
Mike Lockwood | 83bcc98 | 2009-07-29 23:25:10 -0700 | [diff] [blame] | 66 | private static final String KEY_VPN_SETTINGS = "vpn_settings"; |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 67 | private static final String KEY_TETHER_SETTINGS = "tether_settings"; |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 68 | private static final String KEY_PROXY_SETTINGS = "proxy_settings"; |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 69 | private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings"; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 70 | private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan"; |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame] | 71 | private static final String KEY_WFC_SETTINGS = "wifi_calling_settings"; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 72 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 73 | public static final String EXIT_ECM_RESULT = "exit_ecm_result"; |
| 74 | public static final int REQUEST_CODE_EXIT_ECM = 1; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 75 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 76 | private AirplaneModeEnabler mAirplaneModeEnabler; |
Fabrice Di Meglio | e3bced2 | 2014-08-06 10:22:52 -0700 | [diff] [blame] | 77 | private SwitchPreference mAirplaneModePreference; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 78 | private NfcEnabler mNfcEnabler; |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 79 | private NfcAdapter mNfcAdapter; |
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; |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 84 | private UserManager mUm; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 85 | |
| 86 | private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1; |
| 87 | private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage"; |
| 88 | |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame] | 89 | private PreferenceScreen mButtonWfc; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 90 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 91 | /** |
| 92 | * Invoked on each preference click in this hierarchy, overrides |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 93 | * PreferenceFragment's implementation. Used to make sure we track the |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 94 | * preference click events. |
| 95 | */ |
| 96 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 97 | public boolean onPreferenceTreeClick(Preference preference) { |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 98 | log("onPreferenceTreeClick: preference=" + preference); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 99 | if (preference == mAirplaneModePreference && Boolean.parseBoolean( |
| 100 | SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 101 | // In ECM mode launch ECM app dialog |
| 102 | startActivityForResult( |
| 103 | new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null), |
| 104 | REQUEST_CODE_EXIT_ECM); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 105 | return true; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 106 | } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) { |
| 107 | onManageMobilePlanClick(); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 108 | } |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 109 | // Let the intents be launched by the Preference manager |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 110 | return super.onPreferenceTreeClick(preference); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 111 | } |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 112 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 113 | private String mManageMobilePlanMessage; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 114 | public void onManageMobilePlanClick() { |
| 115 | log("onManageMobilePlanClick:"); |
| 116 | mManageMobilePlanMessage = null; |
| 117 | Resources resources = getActivity().getResources(); |
| 118 | |
Paul Jensen | 6953eea | 2015-06-11 10:26:33 -0400 | [diff] [blame] | 119 | NetworkInfo ni = mCm.getActiveNetworkInfo(); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 120 | if (mTm.hasIccCard() && (ni != null)) { |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 121 | // Check for carrier apps that can handle provisioning first |
| 122 | Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP); |
Diego Pontoriero | ff9f67d | 2014-08-11 18:25:51 -0700 | [diff] [blame] | 123 | List<String> carrierPackages = |
Diego Pontoriero | be7adcc | 2014-08-28 13:52:24 -0700 | [diff] [blame] | 124 | mTm.getCarrierPackageNamesForIntent(provisioningIntent); |
Diego Pontoriero | ff9f67d | 2014-08-11 18:25:51 -0700 | [diff] [blame] | 125 | if (carrierPackages != null && !carrierPackages.isEmpty()) { |
| 126 | if (carrierPackages.size() != 1) { |
| 127 | Log.w(TAG, "Multiple matching carrier apps found, launching the first."); |
| 128 | } |
| 129 | provisioningIntent.setPackage(carrierPackages.get(0)); |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 130 | startActivity(provisioningIntent); |
| 131 | return; |
| 132 | } |
| 133 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 134 | // Get provisioning URL |
Robert Greenwalt | 4929e91 | 2013-07-16 13:09:24 -0700 | [diff] [blame] | 135 | String url = mCm.getMobileProvisioningUrl(); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 136 | if (!TextUtils.isEmpty(url)) { |
Paul Jensen | d96c5fc | 2014-10-17 22:09:37 -0400 | [diff] [blame] | 137 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, |
| 138 | Intent.CATEGORY_APP_BROWSER); |
| 139 | intent.setData(Uri.parse(url)); |
| 140 | intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | |
| 141 | Intent.FLAG_ACTIVITY_NEW_TASK); |
| 142 | try { |
| 143 | startActivity(intent); |
| 144 | } catch (ActivityNotFoundException e) { |
| 145 | Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e); |
| 146 | } |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 147 | } else { |
| 148 | // No provisioning URL |
| 149 | String operatorName = mTm.getSimOperatorName(); |
| 150 | if (TextUtils.isEmpty(operatorName)) { |
| 151 | // Use NetworkOperatorName as second choice in case there is no |
| 152 | // SPN (Service Provider Name on the SIM). Such as with T-mobile. |
| 153 | operatorName = mTm.getNetworkOperatorName(); |
| 154 | if (TextUtils.isEmpty(operatorName)) { |
| 155 | mManageMobilePlanMessage = resources.getString( |
| 156 | R.string.mobile_unknown_sim_operator); |
| 157 | } else { |
| 158 | mManageMobilePlanMessage = resources.getString( |
| 159 | R.string.mobile_no_provisioning_url, operatorName); |
| 160 | } |
| 161 | } else { |
| 162 | mManageMobilePlanMessage = resources.getString( |
| 163 | R.string.mobile_no_provisioning_url, operatorName); |
| 164 | } |
| 165 | } |
| 166 | } else if (mTm.hasIccCard() == false) { |
| 167 | // No sim card |
| 168 | mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card); |
| 169 | } else { |
| 170 | // NetworkInfo is null, there is no connection |
| 171 | mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet); |
| 172 | } |
| 173 | if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { |
| 174 | log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage); |
| 175 | showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID); |
| 176 | } |
| 177 | } |
| 178 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 179 | @Override |
| 180 | public Dialog onCreateDialog(int dialogId) { |
| 181 | log("onCreateDialog: dialogId=" + dialogId); |
| 182 | switch (dialogId) { |
| 183 | case MANAGE_MOBILE_PLAN_DIALOG_ID: |
| 184 | return new AlertDialog.Builder(getActivity()) |
| 185 | .setMessage(mManageMobilePlanMessage) |
| 186 | .setCancelable(false) |
| 187 | .setPositiveButton(com.android.internal.R.string.ok, |
| 188 | new DialogInterface.OnClickListener() { |
| 189 | @Override |
| 190 | public void onClick(DialogInterface dialog, int id) { |
| 191 | log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id); |
| 192 | mManageMobilePlanMessage = null; |
| 193 | } |
| 194 | }) |
| 195 | .create(); |
| 196 | } |
| 197 | return super.onCreateDialog(dialogId); |
| 198 | } |
| 199 | |
| 200 | private void log(String s) { |
| 201 | Log.d(TAG, s); |
| 202 | } |
| 203 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 204 | @Override |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 205 | protected int getMetricsCategory() { |
| 206 | return MetricsLogger.WIRELESS; |
| 207 | } |
| 208 | |
| 209 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 210 | public void onCreate(Bundle savedInstanceState) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 211 | super.onCreate(savedInstanceState); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 212 | if (savedInstanceState != null) { |
| 213 | mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG); |
| 214 | } |
| 215 | log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage); |
| 216 | |
| 217 | mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); |
| 218 | mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 219 | mPm = getPackageManager(); |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 220 | mUm = (UserManager) getSystemService(Context.USER_SERVICE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 221 | |
| 222 | addPreferencesFromResource(R.xml.wireless_settings); |
| 223 | |
Xiaohui Chen | 6f03829 | 2015-09-02 16:54:00 -0700 | [diff] [blame] | 224 | final boolean isAdmin = mUm.isAdminUser(); |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 225 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 226 | final Activity activity = getActivity(); |
Fabrice Di Meglio | e3bced2 | 2014-08-06 10:22:52 -0700 | [diff] [blame] | 227 | mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE); |
Fabrice Di Meglio | 4325f80 | 2014-08-15 14:14:17 -0700 | [diff] [blame] | 228 | SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 229 | PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 230 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 231 | mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 232 | mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam); |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 233 | |
Pavel Zhamaitsiak | 3e7e2c5 | 2015-07-23 09:31:58 -0700 | [diff] [blame] | 234 | mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS); |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame] | 235 | |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 236 | String toggleable = Settings.Global.getString(activity.getContentResolver(), |
| 237 | Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 238 | |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 239 | //enable/disable wimax depending on the value in config.xml |
Xiaohui Chen | 6f03829 | 2015-09-02 16:54:00 -0700 | [diff] [blame] | 240 | final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean( |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 241 | com.android.internal.R.bool.config_wimaxEnabled); |
Julia Reynolds | 00d19c7 | 2014-06-24 15:22:50 -0400 | [diff] [blame] | 242 | if (!isWimaxEnabled |
| 243 | || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 244 | PreferenceScreen root = getPreferenceScreen(); |
Xiaohui Chen | 6f03829 | 2015-09-02 16:54:00 -0700 | [diff] [blame] | 245 | Preference ps = findPreference(KEY_WIMAX_SETTINGS); |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 246 | if (ps != null) root.removePreference(ps); |
| 247 | } else { |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 248 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX ) |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 249 | && isWimaxEnabled) { |
Xiaohui Chen | 6f03829 | 2015-09-02 16:54:00 -0700 | [diff] [blame] | 250 | Preference ps = findPreference(KEY_WIMAX_SETTINGS); |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 251 | ps.setDependency(KEY_TOGGLE_AIRPLANE); |
| 252 | } |
| 253 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 254 | |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 255 | // Manually set dependencies for Wifi when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 256 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 257 | findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
| 258 | } |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 259 | // Disable VPN. |
Xiaohui Chen | 6f03829 | 2015-09-02 16:54:00 -0700 | [diff] [blame] | 260 | // TODO: http://b/23693383 |
| 261 | if (!isAdmin || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) { |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 262 | removePreference(KEY_VPN_SETTINGS); |
| 263 | } |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 264 | |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 265 | // Manually set dependencies for Bluetooth when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 266 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 267 | // 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] | 268 | } |
| 269 | |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 270 | // Manually set dependencies for NFC when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 271 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) { |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 272 | findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 273 | findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 276 | // Remove NFC if not available |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 277 | mNfcAdapter = NfcAdapter.getDefaultAdapter(activity); |
| 278 | if (mNfcAdapter == null) { |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 279 | getPreferenceScreen().removePreference(nfc); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 280 | getPreferenceScreen().removePreference(androidBeam); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 281 | mNfcEnabler = null; |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 282 | } |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 283 | |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 284 | // Remove Mobile Network Settings and Manage Mobile Plan for secondary users, |
| 285 | // if it's a wifi-only device, or if the settings are restricted. |
Xiaohui Chen | 6f03829 | 2015-09-02 16:54:00 -0700 | [diff] [blame] | 286 | if (!isAdmin || Utils.isWifiOnly(getActivity()) |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 287 | || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 288 | removePreference(KEY_MOBILE_NETWORK_SETTINGS); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 289 | removePreference(KEY_MANAGE_MOBILE_PLAN); |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 290 | } |
Sungmin Choi | 2490315 | 2013-10-15 16:11:55 -0700 | [diff] [blame] | 291 | // Remove Mobile Network Settings and Manage Mobile Plan |
| 292 | // if config_show_mobile_plan sets false. |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 293 | final boolean isMobilePlanEnabled = this.getResources().getBoolean( |
Sungmin Choi | 2490315 | 2013-10-15 16:11:55 -0700 | [diff] [blame] | 294 | R.bool.config_show_mobile_plan); |
| 295 | if (!isMobilePlanEnabled) { |
| 296 | Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN); |
| 297 | if (pref != null) { |
| 298 | removePreference(KEY_MANAGE_MOBILE_PLAN); |
| 299 | } |
| 300 | } |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 301 | |
Jaewan Kim | 2e41e3d | 2013-04-19 13:40:23 +0900 | [diff] [blame] | 302 | // 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] | 303 | if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) { |
Jaewan Kim | 2e41e3d | 2013-04-19 13:40:23 +0900 | [diff] [blame] | 304 | removePreference(KEY_TOGGLE_AIRPLANE); |
| 305 | } |
| 306 | |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 307 | // Enable Proxy selector settings if allowed. |
| 308 | Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS); |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 309 | final DevicePolicyManager mDPM = (DevicePolicyManager) |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 310 | activity.getSystemService(Context.DEVICE_POLICY_SERVICE); |
Robert Greenwalt | 6f3a98b | 2010-12-28 16:11:12 -0800 | [diff] [blame] | 311 | // proxy UI disabled until we have better app support |
| 312 | getPreferenceScreen().removePreference(mGlobalProxy); |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 313 | mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null); |
| 314 | |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 315 | // 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] | 316 | final ConnectivityManager cm = |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 317 | (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); |
Xiaohui Chen | 6f03829 | 2015-09-02 16:54:00 -0700 | [diff] [blame] | 318 | if (!isAdmin || !cm.isTetheringSupported() |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 319 | || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) { |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 320 | getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS)); |
Robert Greenwalt | e434bfb | 2010-05-08 15:20:24 -0700 | [diff] [blame] | 321 | } else { |
Robert Greenwalt | e434bfb | 2010-05-08 15:20:24 -0700 | [diff] [blame] | 322 | Preference p = findPreference(KEY_TETHER_SETTINGS); |
Wei Liu | 6e58d51 | 2015-08-24 17:29:04 -0700 | [diff] [blame] | 323 | p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm)); |
PauloftheWest | 29aab7a | 2014-09-26 16:05:44 -0700 | [diff] [blame] | 324 | |
| 325 | // Grey out if provisioning is not available. |
| 326 | p.setEnabled(!TetherSettings |
| 327 | .isProvisioningNeededButUnavailable(getActivity())); |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 328 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 329 | } |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 330 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 331 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 332 | public void onResume() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 333 | super.onResume(); |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 334 | |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 335 | mAirplaneModeEnabler.resume(); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 336 | if (mNfcEnabler != null) { |
| 337 | mNfcEnabler.resume(); |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 338 | } |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame] | 339 | |
Pavel Zhamaitsiak | 3e7e2c5 | 2015-07-23 09:31:58 -0700 | [diff] [blame] | 340 | // update WFC setting |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame] | 341 | final Context context = getActivity(); |
| 342 | if (ImsManager.isWfcEnabledByPlatform(context)) { |
Pavel Zhamaitsiak | 3e7e2c5 | 2015-07-23 09:31:58 -0700 | [diff] [blame] | 343 | getPreferenceScreen().addPreference(mButtonWfc); |
| 344 | |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame] | 345 | mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary( |
| 346 | context, ImsManager.getWfcMode(context))); |
Pavel Zhamaitsiak | 3e7e2c5 | 2015-07-23 09:31:58 -0700 | [diff] [blame] | 347 | } else { |
| 348 | removePreference(KEY_WFC_SETTINGS); |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame] | 349 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 350 | } |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 351 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 352 | @Override |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 353 | public void onSaveInstanceState(Bundle outState) { |
| 354 | super.onSaveInstanceState(outState); |
| 355 | |
| 356 | if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { |
| 357 | outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 362 | public void onPause() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 363 | super.onPause(); |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 364 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 365 | mAirplaneModeEnabler.pause(); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 366 | if (mNfcEnabler != null) { |
| 367 | mNfcEnabler.pause(); |
| 368 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 369 | } |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 370 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 371 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 372 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 373 | if (requestCode == REQUEST_CODE_EXIT_ECM) { |
| 374 | Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 375 | // Set Airplane mode based on the return value and checkbox state |
| 376 | mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes, |
| 377 | mAirplaneModePreference.isChecked()); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 378 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 379 | super.onActivityResult(requestCode, resultCode, data); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 380 | } |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame] | 381 | |
| 382 | @Override |
| 383 | protected int getHelpResource() { |
| 384 | return R.string.help_url_more_networks; |
| 385 | } |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 386 | |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 387 | /** |
| 388 | * For Search. |
| 389 | */ |
| 390 | public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
| 391 | new BaseSearchIndexProvider() { |
| 392 | @Override |
| 393 | public List<SearchIndexableResource> getXmlResourcesToIndex( |
| 394 | Context context, boolean enabled) { |
| 395 | SearchIndexableResource sir = new SearchIndexableResource(context); |
| 396 | sir.xmlResId = R.xml.wireless_settings; |
| 397 | return Arrays.asList(sir); |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public List<String> getNonIndexableKeys(Context context) { |
| 402 | final ArrayList<String> result = new ArrayList<String>(); |
| 403 | |
Julia Reynolds | 00d19c7 | 2014-06-24 15:22:50 -0400 | [diff] [blame] | 404 | final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 405 | final boolean isSecondaryUser = !um.isAdminUser(); |
Amith Yamasani | 32505ac | 2014-11-12 13:46:43 -0800 | [diff] [blame] | 406 | final boolean isWimaxEnabled = !isSecondaryUser |
| 407 | && context.getResources().getBoolean( |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 408 | com.android.internal.R.bool.config_wimaxEnabled); |
Julia Reynolds | 00d19c7 | 2014-06-24 15:22:50 -0400 | [diff] [blame] | 409 | if (!isWimaxEnabled |
| 410 | || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 411 | result.add(KEY_WIMAX_SETTINGS); |
| 412 | } |
| 413 | |
| 414 | if (isSecondaryUser) { // Disable VPN |
| 415 | result.add(KEY_VPN_SETTINGS); |
| 416 | } |
| 417 | |
| 418 | // Remove NFC if not available |
Amith Yamasani | 32505ac | 2014-11-12 13:46:43 -0800 | [diff] [blame] | 419 | final NfcManager manager = (NfcManager) |
| 420 | context.getSystemService(Context.NFC_SERVICE); |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 421 | if (manager != null) { |
| 422 | NfcAdapter adapter = manager.getDefaultAdapter(); |
| 423 | if (adapter == null) { |
| 424 | result.add(KEY_TOGGLE_NFC); |
| 425 | result.add(KEY_ANDROID_BEAM_SETTINGS); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device. |
| 430 | if (isSecondaryUser || Utils.isWifiOnly(context)) { |
| 431 | result.add(KEY_MOBILE_NETWORK_SETTINGS); |
| 432 | result.add(KEY_MANAGE_MOBILE_PLAN); |
| 433 | } |
| 434 | |
| 435 | // Remove Mobile Network Settings and Manage Mobile Plan |
| 436 | // if config_show_mobile_plan sets false. |
| 437 | final boolean isMobilePlanEnabled = context.getResources().getBoolean( |
| 438 | R.bool.config_show_mobile_plan); |
| 439 | if (!isMobilePlanEnabled) { |
| 440 | result.add(KEY_MANAGE_MOBILE_PLAN); |
| 441 | } |
| 442 | |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 443 | final PackageManager pm = context.getPackageManager(); |
| 444 | |
| 445 | // Remove Airplane Mode settings if it's a stationary device such as a TV. |
| 446 | if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) { |
| 447 | result.add(KEY_TOGGLE_AIRPLANE); |
| 448 | } |
| 449 | |
| 450 | // proxy UI disabled until we have better app support |
| 451 | result.add(KEY_PROXY_SETTINGS); |
| 452 | |
| 453 | // Disable Tethering if it's not allowed or if it's a wifi-only device |
Amith Yamasani | 32505ac | 2014-11-12 13:46:43 -0800 | [diff] [blame] | 454 | ConnectivityManager cm = (ConnectivityManager) |
| 455 | context.getSystemService(Context.CONNECTIVITY_SERVICE); |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 456 | if (isSecondaryUser || !cm.isTetheringSupported()) { |
| 457 | result.add(KEY_TETHER_SETTINGS); |
| 458 | } |
| 459 | |
Anju Mathapati | ec4706a | 2015-07-27 17:14:14 +0530 | [diff] [blame^] | 460 | if (!ImsManager.isWfcEnabledByPlatform(context)) { |
| 461 | result.add(KEY_WFC_SETTINGS); |
| 462 | } |
| 463 | |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 464 | return result; |
| 465 | } |
| 466 | }; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 467 | } |