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