blob: 36cd346ee4a492e99c2e11933f463bcb211a08aa [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;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040037import android.os.UserManager;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070038import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070039import android.provider.Settings;
Jason Monk39b46742015-09-10 15:52:51 -040040import android.support.v14.preference.SwitchPreference;
41import android.support.v7.preference.Preference;
42import android.support.v7.preference.PreferenceScreen;
Wink Saville5d5a2692013-06-29 07:54:13 -070043import android.telephony.TelephonyManager;
44import android.text.TextUtils;
45import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070046
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080047import com.android.ims.ImsManager;
Chris Wren8a963ba2015-03-20 10:29:14 -040048import com.android.internal.logging.MetricsLogger;
Gilles Debunnee78c1872011-06-20 15:00:07 -070049import com.android.internal.telephony.TelephonyIntents;
50import com.android.internal.telephony.TelephonyProperties;
51import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070052import com.android.settings.search.BaseSearchIndexProvider;
53import com.android.settings.search.Indexable;
Sudheer Shanka8b868302016-01-26 13:50:23 +000054import com.android.settingslib.RestrictedLockUtils;
Sudheer Shanka682a9162016-01-13 22:10:18 +000055import com.android.settingslib.RestrictedPreference;
Jason Monk73a24962015-04-13 20:58:05 -040056
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070057import java.util.ArrayList;
58import java.util.Arrays;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070059import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070060
Jason Monk73a24962015-04-13 20:58:05 -040061public class WirelessSettings extends SettingsPreferenceFragment implements Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070062 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080063
64 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070065 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090066 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050067 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070068 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080069 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070070 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080071 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070072 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080073 private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070074
Chouting Zhang71cc49e2009-08-28 14:36:35 -050075 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
76 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080077
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080078 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070079 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070080 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050081 private NfcAdapter mNfcAdapter;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050082
Wink Saville5d5a2692013-06-29 07:54:13 -070083 private ConnectivityManager mCm;
84 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070085 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040086 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070087
88 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
89 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
90
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080091 private PreferenceScreen mButtonWfc;
David Braun4e9f04d2013-09-16 13:45:42 -070092
Chouting Zhang71cc49e2009-08-28 14:36:35 -050093 /**
94 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080095 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -050096 * preference click events.
97 */
98 @Override
Jason Monk39b46742015-09-10 15:52:51 -040099 public boolean onPreferenceTreeClick(Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700100 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800101 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
102 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500103 // In ECM mode launch ECM app dialog
104 startActivityForResult(
105 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
106 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500107 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700108 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
109 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500110 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800111 // Let the intents be launched by the Preference manager
Jason Monk39b46742015-09-10 15:52:51 -0400112 return super.onPreferenceTreeClick(preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500113 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800114
Wink Saville5d5a2692013-06-29 07:54:13 -0700115 private String mManageMobilePlanMessage;
Wink Saville5d5a2692013-06-29 07:54:13 -0700116 public void onManageMobilePlanClick() {
117 log("onManageMobilePlanClick:");
118 mManageMobilePlanMessage = null;
119 Resources resources = getActivity().getResources();
120
Paul Jensen6953eea2015-06-11 10:26:33 -0400121 NetworkInfo ni = mCm.getActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700122 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700123 // Check for carrier apps that can handle provisioning first
124 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700125 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700126 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700127 if (carrierPackages != null && !carrierPackages.isEmpty()) {
128 if (carrierPackages.size() != 1) {
129 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
130 }
131 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700132 startActivity(provisioningIntent);
133 return;
134 }
135
Wink Saville5d5a2692013-06-29 07:54:13 -0700136 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700137 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700138 if (!TextUtils.isEmpty(url)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400139 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
140 Intent.CATEGORY_APP_BROWSER);
141 intent.setData(Uri.parse(url));
142 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
143 Intent.FLAG_ACTIVITY_NEW_TASK);
144 try {
145 startActivity(intent);
146 } catch (ActivityNotFoundException e) {
147 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
148 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700149 } else {
150 // No provisioning URL
151 String operatorName = mTm.getSimOperatorName();
152 if (TextUtils.isEmpty(operatorName)) {
153 // Use NetworkOperatorName as second choice in case there is no
154 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
155 operatorName = mTm.getNetworkOperatorName();
156 if (TextUtils.isEmpty(operatorName)) {
157 mManageMobilePlanMessage = resources.getString(
158 R.string.mobile_unknown_sim_operator);
159 } else {
160 mManageMobilePlanMessage = resources.getString(
161 R.string.mobile_no_provisioning_url, operatorName);
162 }
163 } else {
164 mManageMobilePlanMessage = resources.getString(
165 R.string.mobile_no_provisioning_url, operatorName);
166 }
167 }
168 } else if (mTm.hasIccCard() == false) {
169 // No sim card
170 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
171 } else {
172 // NetworkInfo is null, there is no connection
173 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
174 }
175 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
176 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
177 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
178 }
179 }
180
Wink Saville5d5a2692013-06-29 07:54:13 -0700181 @Override
182 public Dialog onCreateDialog(int dialogId) {
183 log("onCreateDialog: dialogId=" + dialogId);
184 switch (dialogId) {
185 case MANAGE_MOBILE_PLAN_DIALOG_ID:
186 return new AlertDialog.Builder(getActivity())
187 .setMessage(mManageMobilePlanMessage)
188 .setCancelable(false)
189 .setPositiveButton(com.android.internal.R.string.ok,
190 new DialogInterface.OnClickListener() {
191 @Override
192 public void onClick(DialogInterface dialog, int id) {
193 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
194 mManageMobilePlanMessage = null;
195 }
196 })
197 .create();
198 }
199 return super.onCreateDialog(dialogId);
200 }
201
202 private void log(String s) {
203 Log.d(TAG, s);
204 }
205
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800206 @Override
Chris Wren8a963ba2015-03-20 10:29:14 -0400207 protected int getMetricsCategory() {
208 return MetricsLogger.WIRELESS;
209 }
210
211 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700212 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800213 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700214 if (savedInstanceState != null) {
215 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
216 }
217 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
218
219 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
220 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700221 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400222 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800223
224 addPreferencesFromResource(R.xml.wireless_settings);
225
Xiaohui Chen6f038292015-09-02 16:54:00 -0700226 final boolean isAdmin = mUm.isAdminUser();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700227
Amith Yamasanid7993472010-08-18 13:59:28 -0700228 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700229 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700230 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000231 RestrictedPreference androidBeam = (RestrictedPreference) findPreference(
232 KEY_ANDROID_BEAM_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800233
Gilles Debunnee78c1872011-06-20 15:00:07 -0700234 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500235 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700236
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700237 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800238
Christopher Tate6a5929b2012-09-10 15:39:05 -0700239 String toggleable = Settings.Global.getString(activity.getContentResolver(),
240 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800241
tk.mun7c5c1652011-10-13 22:56:18 +0900242 //enable/disable wimax depending on the value in config.xml
Xiaohui Chen6f038292015-09-02 16:54:00 -0700243 final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900244 com.android.internal.R.bool.config_wimaxEnabled);
Sudheer Shanka8b868302016-01-26 13:50:23 +0000245 if (!isWimaxEnabled) {
tk.mun7c5c1652011-10-13 22:56:18 +0900246 PreferenceScreen root = getPreferenceScreen();
Xiaohui Chen6f038292015-09-02 16:54:00 -0700247 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900248 if (ps != null) root.removePreference(ps);
249 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700250 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900251 && isWimaxEnabled) {
Xiaohui Chen6f038292015-09-02 16:54:00 -0700252 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900253 ps.setDependency(KEY_TOGGLE_AIRPLANE);
254 }
255 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400256
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800257 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700258 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800259 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
260 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400261 // Disable VPN.
Xiaohui Chen6f038292015-09-02 16:54:00 -0700262 // TODO: http://b/23693383
Sudheer Shanka682a9162016-01-13 22:10:18 +0000263 if (!isAdmin) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700264 removePreference(KEY_VPN_SETTINGS);
265 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400266
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800267 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700268 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700269 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700270 }
271
Nick Pelly9894d4a2011-08-09 07:10:16 -0700272 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700273 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700274 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500275 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700276 }
277
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700278 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500279 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
280 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700281 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500282 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700283 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800284 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800285
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400286 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
Sudheer Shanka8b868302016-01-26 13:50:23 +0000287 // if it's a wifi-only device.
288 if (!isAdmin || Utils.isWifiOnly(getActivity())) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700289 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700290 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800291 }
Sungmin Choi24903152013-10-15 16:11:55 -0700292 // Remove Mobile Network Settings and Manage Mobile Plan
293 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700294 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700295 R.bool.config_show_mobile_plan);
296 if (!isMobilePlanEnabled) {
297 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
298 if (pref != null) {
299 removePreference(KEY_MANAGE_MOBILE_PLAN);
300 }
301 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800302
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900303 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700304 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900305 removePreference(KEY_TOGGLE_AIRPLANE);
306 }
307
Oscar Montemayor05411892010-08-03 16:56:09 -0700308 // Enable Proxy selector settings if allowed.
309 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700310 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700311 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800312 // proxy UI disabled until we have better app support
313 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700314 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
315
Amith Yamasani0f85c482011-02-23 17:19:11 -0800316 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700317 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700318 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000319
Sudheer Shanka8b868302016-01-26 13:50:23 +0000320 final boolean adminDisallowedTetherConfig = mUm.hasUserRestriction(
321 UserManager.DISALLOW_CONFIG_TETHERING);
322 if (!isAdmin || (!cm.isTetheringSupported() && !adminDisallowedTetherConfig)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800323 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Sudheer Shanka8b868302016-01-26 13:50:23 +0000324 } else if (!adminDisallowedTetherConfig) {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700325 Preference p = findPreference(KEY_TETHER_SETTINGS);
Wei Liu6e58d512015-08-24 17:29:04 -0700326 p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700327
328 // Grey out if provisioning is not available.
329 p.setEnabled(!TetherSettings
330 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800331 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800332 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800333
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800334 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700335 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800336 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700337
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800338 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700339 if (mNfcEnabler != null) {
340 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500341 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800342
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700343 // update WFC setting
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800344 final Context context = getActivity();
345 if (ImsManager.isWfcEnabledByPlatform(context)) {
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700346 getPreferenceScreen().addPreference(mButtonWfc);
347
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800348 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
349 context, ImsManager.getWfcMode(context)));
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700350 } else {
351 removePreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800352 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800353 }
Danica Chang32711b62010-08-10 18:41:29 -0700354
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800355 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700356 public void onSaveInstanceState(Bundle outState) {
357 super.onSaveInstanceState(outState);
358
359 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
360 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
361 }
362 }
363
364 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700365 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800366 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700367
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800368 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700369 if (mNfcEnabler != null) {
370 mNfcEnabler.pause();
371 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800372 }
Danica Chang32711b62010-08-10 18:41:29 -0700373
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500374 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700375 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800376 if (requestCode == REQUEST_CODE_EXIT_ECM) {
377 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500378 // Set Airplane mode based on the return value and checkbox state
379 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
380 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500381 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400382 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500383 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700384
385 @Override
386 protected int getHelpResource() {
387 return R.string.help_url_more_networks;
388 }
David Braun4e9f04d2013-09-16 13:45:42 -0700389
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700390 /**
391 * For Search.
392 */
393 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
394 new BaseSearchIndexProvider() {
395 @Override
396 public List<SearchIndexableResource> getXmlResourcesToIndex(
397 Context context, boolean enabled) {
398 SearchIndexableResource sir = new SearchIndexableResource(context);
399 sir.xmlResId = R.xml.wireless_settings;
400 return Arrays.asList(sir);
401 }
402
403 @Override
404 public List<String> getNonIndexableKeys(Context context) {
405 final ArrayList<String> result = new ArrayList<String>();
406
Julia Reynolds00d19c72014-06-24 15:22:50 -0400407 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Xiaohui Chen44879a32015-07-22 13:53:22 -0700408 final boolean isSecondaryUser = !um.isAdminUser();
Amith Yamasani32505ac2014-11-12 13:46:43 -0800409 final boolean isWimaxEnabled = !isSecondaryUser
410 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700411 com.android.internal.R.bool.config_wimaxEnabled);
Sudheer Shanka8b868302016-01-26 13:50:23 +0000412 if (!isWimaxEnabled) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700413 result.add(KEY_WIMAX_SETTINGS);
414 }
415
416 if (isSecondaryUser) { // Disable VPN
417 result.add(KEY_VPN_SETTINGS);
418 }
419
420 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800421 final NfcManager manager = (NfcManager)
422 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700423 if (manager != null) {
424 NfcAdapter adapter = manager.getDefaultAdapter();
425 if (adapter == null) {
426 result.add(KEY_TOGGLE_NFC);
427 result.add(KEY_ANDROID_BEAM_SETTINGS);
428 }
429 }
430
431 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
432 if (isSecondaryUser || Utils.isWifiOnly(context)) {
433 result.add(KEY_MOBILE_NETWORK_SETTINGS);
434 result.add(KEY_MANAGE_MOBILE_PLAN);
435 }
436
437 // Remove Mobile Network Settings and Manage Mobile Plan
438 // if config_show_mobile_plan sets false.
439 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
440 R.bool.config_show_mobile_plan);
441 if (!isMobilePlanEnabled) {
442 result.add(KEY_MANAGE_MOBILE_PLAN);
443 }
444
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700445 final PackageManager pm = context.getPackageManager();
446
447 // Remove Airplane Mode settings if it's a stationary device such as a TV.
448 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
449 result.add(KEY_TOGGLE_AIRPLANE);
450 }
451
452 // proxy UI disabled until we have better app support
453 result.add(KEY_PROXY_SETTINGS);
454
455 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800456 ConnectivityManager cm = (ConnectivityManager)
457 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700458 if (isSecondaryUser || !cm.isTetheringSupported()) {
459 result.add(KEY_TETHER_SETTINGS);
460 }
461
Anju Mathapatiec4706a2015-07-27 17:14:14 +0530462 if (!ImsManager.isWfcEnabledByPlatform(context)) {
463 result.add(KEY_WFC_SETTINGS);
464 }
465
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700466 return result;
467 }
468 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800469}