blob: fc572fb253c848eb069ef6e3d83a16d2b796f94a [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;
Fyodor Kupolovca060e32016-06-24 13:01:11 -070060import java.util.Collections;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070061import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070062
Jason Monk73a24962015-04-13 20:58:05 -040063public class WirelessSettings extends SettingsPreferenceFragment implements Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070064 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080065
66 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070067 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090068 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050069 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070070 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080071 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070072 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080073 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070074 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080075 private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
Doris Linge6f635f2016-06-07 17:56:00 -070076 private static final String KEY_NETWORK_RESET = "network_reset";
Nick Pellyad50ba02010-09-22 10:55:13 -070077
Chouting Zhang71cc49e2009-08-28 14:36:35 -050078 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
79 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080081 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070082 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070083 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050084 private NfcAdapter mNfcAdapter;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050085
Wink Saville5d5a2692013-06-29 07:54:13 -070086 private ConnectivityManager mCm;
87 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070088 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040089 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070090
91 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
92 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
93
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080094 private PreferenceScreen mButtonWfc;
David Braun4e9f04d2013-09-16 13:45:42 -070095
Chouting Zhang71cc49e2009-08-28 14:36:35 -050096 /**
97 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080098 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -050099 * preference click events.
100 */
101 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400102 public boolean onPreferenceTreeClick(Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700103 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800104 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
105 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500106 // In ECM mode launch ECM app dialog
107 startActivityForResult(
108 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
109 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500110 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700111 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
112 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500113 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800114 // Let the intents be launched by the Preference manager
Jason Monk39b46742015-09-10 15:52:51 -0400115 return super.onPreferenceTreeClick(preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500116 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800117
Wink Saville5d5a2692013-06-29 07:54:13 -0700118 private String mManageMobilePlanMessage;
Wink Saville5d5a2692013-06-29 07:54:13 -0700119 public void onManageMobilePlanClick() {
120 log("onManageMobilePlanClick:");
121 mManageMobilePlanMessage = null;
122 Resources resources = getActivity().getResources();
123
Paul Jensen6953eea2015-06-11 10:26:33 -0400124 NetworkInfo ni = mCm.getActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700125 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700126 // Check for carrier apps that can handle provisioning first
127 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700128 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700129 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700130 if (carrierPackages != null && !carrierPackages.isEmpty()) {
131 if (carrierPackages.size() != 1) {
132 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
133 }
134 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700135 startActivity(provisioningIntent);
136 return;
137 }
138
Wink Saville5d5a2692013-06-29 07:54:13 -0700139 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700140 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700141 if (!TextUtils.isEmpty(url)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400142 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
143 Intent.CATEGORY_APP_BROWSER);
144 intent.setData(Uri.parse(url));
145 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
146 Intent.FLAG_ACTIVITY_NEW_TASK);
147 try {
148 startActivity(intent);
149 } catch (ActivityNotFoundException e) {
150 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
151 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700152 } else {
153 // No provisioning URL
154 String operatorName = mTm.getSimOperatorName();
155 if (TextUtils.isEmpty(operatorName)) {
156 // Use NetworkOperatorName as second choice in case there is no
157 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
158 operatorName = mTm.getNetworkOperatorName();
159 if (TextUtils.isEmpty(operatorName)) {
160 mManageMobilePlanMessage = resources.getString(
161 R.string.mobile_unknown_sim_operator);
162 } else {
163 mManageMobilePlanMessage = resources.getString(
164 R.string.mobile_no_provisioning_url, operatorName);
165 }
166 } else {
167 mManageMobilePlanMessage = resources.getString(
168 R.string.mobile_no_provisioning_url, operatorName);
169 }
170 }
171 } else if (mTm.hasIccCard() == false) {
172 // No sim card
173 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
174 } else {
175 // NetworkInfo is null, there is no connection
176 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
177 }
178 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
179 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
180 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
181 }
182 }
183
Wink Saville5d5a2692013-06-29 07:54:13 -0700184 @Override
185 public Dialog onCreateDialog(int dialogId) {
186 log("onCreateDialog: dialogId=" + dialogId);
187 switch (dialogId) {
188 case MANAGE_MOBILE_PLAN_DIALOG_ID:
189 return new AlertDialog.Builder(getActivity())
190 .setMessage(mManageMobilePlanMessage)
191 .setCancelable(false)
192 .setPositiveButton(com.android.internal.R.string.ok,
193 new DialogInterface.OnClickListener() {
194 @Override
195 public void onClick(DialogInterface dialog, int id) {
196 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
197 mManageMobilePlanMessage = null;
198 }
199 })
200 .create();
201 }
202 return super.onCreateDialog(dialogId);
203 }
204
205 private void log(String s) {
206 Log.d(TAG, s);
207 }
208
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800209 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700210 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500211 return MetricsEvent.WIRELESS;
Chris Wren8a963ba2015-03-20 10:29:14 -0400212 }
213
214 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700215 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800216 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700217 if (savedInstanceState != null) {
218 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
219 }
220 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
221
222 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
223 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700224 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400225 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800226
227 addPreferencesFromResource(R.xml.wireless_settings);
228
Xiaohui Chen6f038292015-09-02 16:54:00 -0700229 final boolean isAdmin = mUm.isAdminUser();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700230
Amith Yamasanid7993472010-08-18 13:59:28 -0700231 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700232 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700233 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000234 RestrictedPreference androidBeam = (RestrictedPreference) findPreference(
235 KEY_ANDROID_BEAM_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800236
Fan Zhangaa71afe2016-09-22 10:43:12 -0700237 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference,
238 mMetricsFeatureProvider);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500239 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700240
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700241 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800242
Christopher Tate6a5929b2012-09-10 15:39:05 -0700243 String toggleable = Settings.Global.getString(activity.getContentResolver(),
244 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800245
tk.mun7c5c1652011-10-13 22:56:18 +0900246 //enable/disable wimax depending on the value in config.xml
Xiaohui Chen6f038292015-09-02 16:54:00 -0700247 final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900248 com.android.internal.R.bool.config_wimaxEnabled);
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000249 if (!isWimaxEnabled || RestrictedLockUtils.hasBaseUserRestriction(activity,
250 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
tk.mun7c5c1652011-10-13 22:56:18 +0900251 PreferenceScreen root = getPreferenceScreen();
Xiaohui Chen6f038292015-09-02 16:54:00 -0700252 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900253 if (ps != null) root.removePreference(ps);
254 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700255 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900256 && isWimaxEnabled) {
Xiaohui Chen6f038292015-09-02 16:54:00 -0700257 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900258 ps.setDependency(KEY_TOGGLE_AIRPLANE);
259 }
260 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400261
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800262 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700263 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800264 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
265 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400266 // Disable VPN.
Xiaohui Chen6f038292015-09-02 16:54:00 -0700267 // TODO: http://b/23693383
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000268 if (!isAdmin || RestrictedLockUtils.hasBaseUserRestriction(activity,
269 UserManager.DISALLOW_CONFIG_VPN, UserHandle.myUserId())) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700270 removePreference(KEY_VPN_SETTINGS);
271 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400272
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800273 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700274 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700275 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700276 }
277
Nick Pelly9894d4a2011-08-09 07:10:16 -0700278 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700279 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700280 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500281 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700282 }
283
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700284 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500285 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
286 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700287 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500288 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700289 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800290 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800291
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400292 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
Sudheer Shanka8b868302016-01-26 13:50:23 +0000293 // if it's a wifi-only device.
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000294 if (!isAdmin || Utils.isWifiOnly(getActivity()) ||
295 RestrictedLockUtils.hasBaseUserRestriction(activity,
296 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700297 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700298 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800299 }
Sungmin Choi24903152013-10-15 16:11:55 -0700300 // Remove Mobile Network Settings and Manage Mobile Plan
301 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700302 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700303 R.bool.config_show_mobile_plan);
304 if (!isMobilePlanEnabled) {
305 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
306 if (pref != null) {
307 removePreference(KEY_MANAGE_MOBILE_PLAN);
308 }
309 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800310
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900311 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700312 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900313 removePreference(KEY_TOGGLE_AIRPLANE);
314 }
315
Oscar Montemayor05411892010-08-03 16:56:09 -0700316 // Enable Proxy selector settings if allowed.
317 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700318 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700319 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800320 // proxy UI disabled until we have better app support
321 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700322 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
323
Amith Yamasani0f85c482011-02-23 17:19:11 -0800324 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700325 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700326 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000327
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000328 final boolean adminDisallowedTetherConfig = RestrictedLockUtils.checkIfRestrictionEnforced(
329 activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
330 if ((!cm.isTetheringSupported() && !adminDisallowedTetherConfig) ||
331 RestrictedLockUtils.hasBaseUserRestriction(activity,
332 UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800333 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Sudheer Shanka8b868302016-01-26 13:50:23 +0000334 } else if (!adminDisallowedTetherConfig) {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700335 Preference p = findPreference(KEY_TETHER_SETTINGS);
Wei Liu6e58d512015-08-24 17:29:04 -0700336 p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700337
338 // Grey out if provisioning is not available.
339 p.setEnabled(!TetherSettings
340 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800341 }
Doris Linge6f635f2016-06-07 17:56:00 -0700342
343 // Remove network reset if not allowed
344 if (RestrictedLockUtils.hasBaseUserRestriction(activity,
345 UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
346 removePreference(KEY_NETWORK_RESET);
347 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800348 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800349
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800350 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700351 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800352 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700353
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800354 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700355 if (mNfcEnabler != null) {
356 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500357 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800358
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700359 // update WFC setting
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800360 final Context context = getActivity();
Pavel Zhamaitsiake2f59b92016-06-20 17:52:48 -0700361 if (ImsManager.isWfcEnabledByPlatform(context) &&
362 ImsManager.isWfcProvisionedOnDevice(context)) {
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700363 getPreferenceScreen().addPreference(mButtonWfc);
364
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800365 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
366 context, ImsManager.getWfcMode(context)));
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700367 } else {
368 removePreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800369 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800370 }
Danica Chang32711b62010-08-10 18:41:29 -0700371
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800372 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700373 public void onSaveInstanceState(Bundle outState) {
374 super.onSaveInstanceState(outState);
375
376 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
377 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
378 }
379 }
380
381 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700382 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800383 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700384
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800385 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700386 if (mNfcEnabler != null) {
387 mNfcEnabler.pause();
388 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800389 }
Danica Chang32711b62010-08-10 18:41:29 -0700390
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500391 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700392 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800393 if (requestCode == REQUEST_CODE_EXIT_ECM) {
394 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500395 // Set Airplane mode based on the return value and checkbox state
396 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
397 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500398 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400399 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500400 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700401
402 @Override
403 protected int getHelpResource() {
404 return R.string.help_url_more_networks;
405 }
David Braun4e9f04d2013-09-16 13:45:42 -0700406
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700407 /**
408 * For Search.
409 */
410 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
411 new BaseSearchIndexProvider() {
412 @Override
413 public List<SearchIndexableResource> getXmlResourcesToIndex(
414 Context context, boolean enabled) {
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700415 // Remove wireless settings from search in demo mode
416 if (UserManager.isDeviceInDemoMode(context)) {
417 return Collections.emptyList();
418 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700419 SearchIndexableResource sir = new SearchIndexableResource(context);
420 sir.xmlResId = R.xml.wireless_settings;
421 return Arrays.asList(sir);
422 }
423
424 @Override
425 public List<String> getNonIndexableKeys(Context context) {
426 final ArrayList<String> result = new ArrayList<String>();
427
Julia Reynolds00d19c72014-06-24 15:22:50 -0400428 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Xiaohui Chen44879a32015-07-22 13:53:22 -0700429 final boolean isSecondaryUser = !um.isAdminUser();
Amith Yamasani32505ac2014-11-12 13:46:43 -0800430 final boolean isWimaxEnabled = !isSecondaryUser
431 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700432 com.android.internal.R.bool.config_wimaxEnabled);
Sudheer Shanka8b868302016-01-26 13:50:23 +0000433 if (!isWimaxEnabled) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700434 result.add(KEY_WIMAX_SETTINGS);
435 }
436
437 if (isSecondaryUser) { // Disable VPN
438 result.add(KEY_VPN_SETTINGS);
439 }
440
441 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800442 final NfcManager manager = (NfcManager)
443 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700444 if (manager != null) {
445 NfcAdapter adapter = manager.getDefaultAdapter();
446 if (adapter == null) {
447 result.add(KEY_TOGGLE_NFC);
448 result.add(KEY_ANDROID_BEAM_SETTINGS);
449 }
450 }
451
452 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
453 if (isSecondaryUser || Utils.isWifiOnly(context)) {
454 result.add(KEY_MOBILE_NETWORK_SETTINGS);
455 result.add(KEY_MANAGE_MOBILE_PLAN);
456 }
457
458 // Remove Mobile Network Settings and Manage Mobile Plan
459 // if config_show_mobile_plan sets false.
460 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
461 R.bool.config_show_mobile_plan);
462 if (!isMobilePlanEnabled) {
463 result.add(KEY_MANAGE_MOBILE_PLAN);
464 }
465
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700466 final PackageManager pm = context.getPackageManager();
467
468 // Remove Airplane Mode settings if it's a stationary device such as a TV.
469 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
470 result.add(KEY_TOGGLE_AIRPLANE);
471 }
472
473 // proxy UI disabled until we have better app support
474 result.add(KEY_PROXY_SETTINGS);
475
476 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800477 ConnectivityManager cm = (ConnectivityManager)
478 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700479 if (isSecondaryUser || !cm.isTetheringSupported()) {
480 result.add(KEY_TETHER_SETTINGS);
481 }
482
Pavel Zhamaitsiake2f59b92016-06-20 17:52:48 -0700483 if (!ImsManager.isWfcEnabledByPlatform(context) ||
484 !ImsManager.isWfcProvisionedOnDevice(context)) {
Anju Mathapatiec4706a2015-07-27 17:14:14 +0530485 result.add(KEY_WFC_SETTINGS);
486 }
487
Doris Linge6f635f2016-06-07 17:56:00 -0700488 if (RestrictedLockUtils.hasBaseUserRestriction(context,
489 UserManager.DISALLOW_NETWORK_RESET, UserHandle.myUserId())) {
490 result.add(KEY_NETWORK_RESET);
491 }
492
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700493 return result;
494 }
495 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800496}