blob: 722a861fbda59056a55fb8819712d2aeff100663 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
Chia-chi Yeh4e142112009-12-25 14:48:46 +08002 * Copyright (C) 2009 The Android Open Source Project
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08003 *
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
17package com.android.settings;
18
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -040019
Amith Yamasanid7993472010-08-18 13:59:28 -070020import android.app.Activity;
Wink Saville5d5a2692013-06-29 07:54:13 -070021import android.app.AlertDialog;
22import android.app.Dialog;
Amith Yamasanid7993472010-08-18 13:59:28 -070023import android.app.admin.DevicePolicyManager;
Paul Jensend96c5fc2014-10-17 22:09:37 -040024import android.content.ActivityNotFoundException;
Amith Yamasanid7993472010-08-18 13:59:28 -070025import android.content.Context;
Wink Saville5d5a2692013-06-29 07:54:13 -070026import android.content.DialogInterface;
Amith Yamasanid7993472010-08-18 13:59:28 -070027import android.content.Intent;
Irfan Sheriff167d7182011-09-07 14:51:11 -070028import android.content.pm.PackageManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070029import android.content.res.Resources;
Amith Yamasanid7993472010-08-18 13:59:28 -070030import android.net.ConnectivityManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070031import android.net.NetworkInfo;
Paul Jensend96c5fc2014-10-17 22:09:37 -040032import android.net.Uri;
Nick Pellya57eace2010-10-15 01:19:43 -070033import android.nfc.NfcAdapter;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070034import android.nfc.NfcManager;
Amith Yamasanid7993472010-08-18 13:59:28 -070035import android.os.Bundle;
Amith Yamasanid7993472010-08-18 13:59:28 -070036import android.os.SystemProperties;
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +000037import android.os.UserHandle;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040038import android.os.UserManager;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070039import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070040import android.provider.Settings;
Jason Monk39b46742015-09-10 15:52:51 -040041import android.support.v14.preference.SwitchPreference;
42import android.support.v7.preference.Preference;
43import android.support.v7.preference.PreferenceScreen;
Wink Saville5d5a2692013-06-29 07:54:13 -070044import android.telephony.TelephonyManager;
45import android.text.TextUtils;
46import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070047
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080048import com.android.ims.ImsManager;
Chris Wren9d1bfd12016-01-26 18:04:01 -050049import com.android.internal.logging.MetricsProto.MetricsEvent;
Gilles Debunnee78c1872011-06-20 15:00:07 -070050import com.android.internal.telephony.TelephonyIntents;
51import com.android.internal.telephony.TelephonyProperties;
52import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070053import com.android.settings.search.BaseSearchIndexProvider;
54import com.android.settings.search.Indexable;
Sudheer Shanka8b868302016-01-26 13:50:23 +000055import com.android.settingslib.RestrictedLockUtils;
Sudheer Shanka682a9162016-01-13 22:10:18 +000056import com.android.settingslib.RestrictedPreference;
Jason Monk73a24962015-04-13 20:58:05 -040057
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070058import java.util.ArrayList;
59import java.util.Arrays;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070060import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070061
Jason Monk73a24962015-04-13 20:58:05 -040062public class WirelessSettings extends SettingsPreferenceFragment implements Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070063 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080064
65 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070066 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090067 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050068 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070069 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080070 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070071 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080072 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070073 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080074 private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
Doris Linge6f635f2016-06-07 17:56:00 -070075 private static final String KEY_NETWORK_RESET = "network_reset";
Nick Pellyad50ba02010-09-22 10:55:13 -070076
Chouting Zhang71cc49e2009-08-28 14:36:35 -050077 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
78 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080079
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070081 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070082 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050083 private NfcAdapter mNfcAdapter;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050084
Wink Saville5d5a2692013-06-29 07:54:13 -070085 private ConnectivityManager mCm;
86 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070087 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040088 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070089
90 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
91 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
92
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080093 private PreferenceScreen mButtonWfc;
David Braun4e9f04d2013-09-16 13:45:42 -070094
Chouting Zhang71cc49e2009-08-28 14:36:35 -050095 /**
96 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080097 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -050098 * preference click events.
99 */
100 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400101 public boolean onPreferenceTreeClick(Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700102 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800103 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
104 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500105 // In ECM mode launch ECM app dialog
106 startActivityForResult(
107 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
108 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500109 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700110 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
111 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500112 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800113 // Let the intents be launched by the Preference manager
Jason Monk39b46742015-09-10 15:52:51 -0400114 return super.onPreferenceTreeClick(preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500115 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800116
Wink Saville5d5a2692013-06-29 07:54:13 -0700117 private String mManageMobilePlanMessage;
Wink Saville5d5a2692013-06-29 07:54:13 -0700118 public void onManageMobilePlanClick() {
119 log("onManageMobilePlanClick:");
120 mManageMobilePlanMessage = null;
121 Resources resources = getActivity().getResources();
122
Paul Jensen6953eea2015-06-11 10:26:33 -0400123 NetworkInfo ni = mCm.getActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700124 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700125 // Check for carrier apps that can handle provisioning first
126 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700127 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700128 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700129 if (carrierPackages != null && !carrierPackages.isEmpty()) {
130 if (carrierPackages.size() != 1) {
131 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
132 }
133 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700134 startActivity(provisioningIntent);
135 return;
136 }
137
Wink Saville5d5a2692013-06-29 07:54:13 -0700138 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700139 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700140 if (!TextUtils.isEmpty(url)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400141 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
142 Intent.CATEGORY_APP_BROWSER);
143 intent.setData(Uri.parse(url));
144 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
145 Intent.FLAG_ACTIVITY_NEW_TASK);
146 try {
147 startActivity(intent);
148 } catch (ActivityNotFoundException e) {
149 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
150 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700151 } else {
152 // No provisioning URL
153 String operatorName = mTm.getSimOperatorName();
154 if (TextUtils.isEmpty(operatorName)) {
155 // Use NetworkOperatorName as second choice in case there is no
156 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
157 operatorName = mTm.getNetworkOperatorName();
158 if (TextUtils.isEmpty(operatorName)) {
159 mManageMobilePlanMessage = resources.getString(
160 R.string.mobile_unknown_sim_operator);
161 } else {
162 mManageMobilePlanMessage = resources.getString(
163 R.string.mobile_no_provisioning_url, operatorName);
164 }
165 } else {
166 mManageMobilePlanMessage = resources.getString(
167 R.string.mobile_no_provisioning_url, operatorName);
168 }
169 }
170 } else if (mTm.hasIccCard() == false) {
171 // No sim card
172 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
173 } else {
174 // NetworkInfo is null, there is no connection
175 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
176 }
177 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
178 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
179 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
180 }
181 }
182
Wink Saville5d5a2692013-06-29 07:54:13 -0700183 @Override
184 public Dialog onCreateDialog(int dialogId) {
185 log("onCreateDialog: dialogId=" + dialogId);
186 switch (dialogId) {
187 case MANAGE_MOBILE_PLAN_DIALOG_ID:
188 return new AlertDialog.Builder(getActivity())
189 .setMessage(mManageMobilePlanMessage)
190 .setCancelable(false)
191 .setPositiveButton(com.android.internal.R.string.ok,
192 new DialogInterface.OnClickListener() {
193 @Override
194 public void onClick(DialogInterface dialog, int id) {
195 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
196 mManageMobilePlanMessage = null;
197 }
198 })
199 .create();
200 }
201 return super.onCreateDialog(dialogId);
202 }
203
204 private void log(String s) {
205 Log.d(TAG, s);
206 }
207
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800208 @Override
Chris Wren8a963ba2015-03-20 10:29:14 -0400209 protected int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500210 return MetricsEvent.WIRELESS;
Chris Wren8a963ba2015-03-20 10:29:14 -0400211 }
212
213 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700214 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800215 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700216 if (savedInstanceState != null) {
217 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
218 }
219 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
220
221 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
222 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700223 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400224 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800225
226 addPreferencesFromResource(R.xml.wireless_settings);
227
Xiaohui Chen6f038292015-09-02 16:54:00 -0700228 final boolean isAdmin = mUm.isAdminUser();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700229
Amith Yamasanid7993472010-08-18 13:59:28 -0700230 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700231 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700232 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000233 RestrictedPreference androidBeam = (RestrictedPreference) findPreference(
234 KEY_ANDROID_BEAM_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800235
Gilles Debunnee78c1872011-06-20 15:00:07 -0700236 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500237 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700238
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700239 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800240
Christopher Tate6a5929b2012-09-10 15:39:05 -0700241 String toggleable = Settings.Global.getString(activity.getContentResolver(),
242 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800243
tk.mun7c5c1652011-10-13 22:56:18 +0900244 //enable/disable wimax depending on the value in config.xml
Xiaohui Chen6f038292015-09-02 16:54:00 -0700245 final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900246 com.android.internal.R.bool.config_wimaxEnabled);
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000247 if (!isWimaxEnabled || RestrictedLockUtils.hasBaseUserRestriction(activity,
248 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
tk.mun7c5c1652011-10-13 22:56:18 +0900249 PreferenceScreen root = getPreferenceScreen();
Xiaohui Chen6f038292015-09-02 16:54:00 -0700250 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900251 if (ps != null) root.removePreference(ps);
252 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700253 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900254 && isWimaxEnabled) {
Xiaohui Chen6f038292015-09-02 16:54:00 -0700255 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900256 ps.setDependency(KEY_TOGGLE_AIRPLANE);
257 }
258 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400259
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800260 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700261 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800262 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
263 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400264 // Disable VPN.
Xiaohui Chen6f038292015-09-02 16:54:00 -0700265 // TODO: http://b/23693383
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000266 if (!isAdmin || RestrictedLockUtils.hasBaseUserRestriction(activity,
267 UserManager.DISALLOW_CONFIG_VPN, UserHandle.myUserId())) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700268 removePreference(KEY_VPN_SETTINGS);
269 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400270
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800271 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700272 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700273 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700274 }
275
Nick Pelly9894d4a2011-08-09 07:10:16 -0700276 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700277 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700278 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500279 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700280 }
281
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700282 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500283 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
284 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700285 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500286 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700287 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800288 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800289
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400290 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
Sudheer Shanka8b868302016-01-26 13:50:23 +0000291 // if it's a wifi-only device.
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000292 if (!isAdmin || Utils.isWifiOnly(getActivity()) ||
293 RestrictedLockUtils.hasBaseUserRestriction(activity,
294 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700295 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700296 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800297 }
Sungmin Choi24903152013-10-15 16:11:55 -0700298 // Remove Mobile Network Settings and Manage Mobile Plan
299 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700300 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700301 R.bool.config_show_mobile_plan);
302 if (!isMobilePlanEnabled) {
303 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
304 if (pref != null) {
305 removePreference(KEY_MANAGE_MOBILE_PLAN);
306 }
307 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800308
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900309 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700310 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900311 removePreference(KEY_TOGGLE_AIRPLANE);
312 }
313
Oscar Montemayor05411892010-08-03 16:56:09 -0700314 // Enable Proxy selector settings if allowed.
315 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700316 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700317 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800318 // proxy UI disabled until we have better app support
319 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700320 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
321
Amith Yamasani0f85c482011-02-23 17:19:11 -0800322 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700323 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700324 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000325
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000326 final boolean adminDisallowedTetherConfig = RestrictedLockUtils.checkIfRestrictionEnforced(
327 activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
328 if ((!cm.isTetheringSupported() && !adminDisallowedTetherConfig) ||
329 RestrictedLockUtils.hasBaseUserRestriction(activity,
330 UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800331 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Sudheer Shanka8b868302016-01-26 13:50:23 +0000332 } else if (!adminDisallowedTetherConfig) {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700333 Preference p = findPreference(KEY_TETHER_SETTINGS);
Wei Liu6e58d512015-08-24 17:29:04 -0700334 p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700335
336 // Grey out if provisioning is not available.
337 p.setEnabled(!TetherSettings
338 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800339 }
Doris Linge6f635f2016-06-07 17:56:00 -0700340
341 // Remove network reset if not allowed
342 if (RestrictedLockUtils.hasBaseUserRestriction(activity,
343 UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
344 removePreference(KEY_NETWORK_RESET);
345 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800346 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800347
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800348 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700349 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800350 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700351
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800352 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700353 if (mNfcEnabler != null) {
354 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500355 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800356
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700357 // update WFC setting
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800358 final Context context = getActivity();
Pavel Zhamaitsiake2f59b92016-06-20 17:52:48 -0700359 if (ImsManager.isWfcEnabledByPlatform(context) &&
360 ImsManager.isWfcProvisionedOnDevice(context)) {
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700361 getPreferenceScreen().addPreference(mButtonWfc);
362
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800363 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
364 context, ImsManager.getWfcMode(context)));
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700365 } else {
366 removePreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800367 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800368 }
Danica Chang32711b62010-08-10 18:41:29 -0700369
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800370 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700371 public void onSaveInstanceState(Bundle outState) {
372 super.onSaveInstanceState(outState);
373
374 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
375 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
376 }
377 }
378
379 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700380 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800381 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700382
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800383 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700384 if (mNfcEnabler != null) {
385 mNfcEnabler.pause();
386 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800387 }
Danica Chang32711b62010-08-10 18:41:29 -0700388
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500389 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700390 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800391 if (requestCode == REQUEST_CODE_EXIT_ECM) {
392 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500393 // Set Airplane mode based on the return value and checkbox state
394 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
395 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500396 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400397 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500398 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700399
400 @Override
401 protected int getHelpResource() {
402 return R.string.help_url_more_networks;
403 }
David Braun4e9f04d2013-09-16 13:45:42 -0700404
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700405 /**
406 * For Search.
407 */
408 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
409 new BaseSearchIndexProvider() {
410 @Override
411 public List<SearchIndexableResource> getXmlResourcesToIndex(
412 Context context, boolean enabled) {
413 SearchIndexableResource sir = new SearchIndexableResource(context);
414 sir.xmlResId = R.xml.wireless_settings;
415 return Arrays.asList(sir);
416 }
417
418 @Override
419 public List<String> getNonIndexableKeys(Context context) {
420 final ArrayList<String> result = new ArrayList<String>();
421
Julia Reynolds00d19c72014-06-24 15:22:50 -0400422 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Xiaohui Chen44879a32015-07-22 13:53:22 -0700423 final boolean isSecondaryUser = !um.isAdminUser();
Amith Yamasani32505ac2014-11-12 13:46:43 -0800424 final boolean isWimaxEnabled = !isSecondaryUser
425 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700426 com.android.internal.R.bool.config_wimaxEnabled);
Sudheer Shanka8b868302016-01-26 13:50:23 +0000427 if (!isWimaxEnabled) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700428 result.add(KEY_WIMAX_SETTINGS);
429 }
430
431 if (isSecondaryUser) { // Disable VPN
432 result.add(KEY_VPN_SETTINGS);
433 }
434
435 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800436 final NfcManager manager = (NfcManager)
437 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700438 if (manager != null) {
439 NfcAdapter adapter = manager.getDefaultAdapter();
440 if (adapter == null) {
441 result.add(KEY_TOGGLE_NFC);
442 result.add(KEY_ANDROID_BEAM_SETTINGS);
443 }
444 }
445
446 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
447 if (isSecondaryUser || Utils.isWifiOnly(context)) {
448 result.add(KEY_MOBILE_NETWORK_SETTINGS);
449 result.add(KEY_MANAGE_MOBILE_PLAN);
450 }
451
452 // Remove Mobile Network Settings and Manage Mobile Plan
453 // if config_show_mobile_plan sets false.
454 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
455 R.bool.config_show_mobile_plan);
456 if (!isMobilePlanEnabled) {
457 result.add(KEY_MANAGE_MOBILE_PLAN);
458 }
459
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700460 final PackageManager pm = context.getPackageManager();
461
462 // Remove Airplane Mode settings if it's a stationary device such as a TV.
463 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
464 result.add(KEY_TOGGLE_AIRPLANE);
465 }
466
467 // proxy UI disabled until we have better app support
468 result.add(KEY_PROXY_SETTINGS);
469
470 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800471 ConnectivityManager cm = (ConnectivityManager)
472 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700473 if (isSecondaryUser || !cm.isTetheringSupported()) {
474 result.add(KEY_TETHER_SETTINGS);
475 }
476
Pavel Zhamaitsiake2f59b92016-06-20 17:52:48 -0700477 if (!ImsManager.isWfcEnabledByPlatform(context) ||
478 !ImsManager.isWfcProvisionedOnDevice(context)) {
Anju Mathapatiec4706a2015-07-27 17:14:14 +0530479 result.add(KEY_WFC_SETTINGS);
480 }
481
Doris Linge6f635f2016-06-07 17:56:00 -0700482 if (RestrictedLockUtils.hasBaseUserRestriction(context,
483 UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
484 result.add(KEY_NETWORK_RESET);
485 }
486
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700487 return result;
488 }
489 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800490}