blob: 5b1d64478faca291abc70316509982dabe16d408 [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";
Nick Pellyad50ba02010-09-22 10:55:13 -070075
Chouting Zhang71cc49e2009-08-28 14:36:35 -050076 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
77 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080078
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080079 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070080 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070081 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050082 private NfcAdapter mNfcAdapter;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050083
Wink Saville5d5a2692013-06-29 07:54:13 -070084 private ConnectivityManager mCm;
85 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070086 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040087 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070088
89 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
90 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
91
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080092 private PreferenceScreen mButtonWfc;
David Braun4e9f04d2013-09-16 13:45:42 -070093
Chouting Zhang71cc49e2009-08-28 14:36:35 -050094 /**
95 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080096 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -050097 * preference click events.
98 */
99 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400100 public boolean onPreferenceTreeClick(Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700101 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800102 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
103 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500104 // In ECM mode launch ECM app dialog
105 startActivityForResult(
106 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
107 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500108 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700109 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
110 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500111 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800112 // Let the intents be launched by the Preference manager
Jason Monk39b46742015-09-10 15:52:51 -0400113 return super.onPreferenceTreeClick(preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500114 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800115
Wink Saville5d5a2692013-06-29 07:54:13 -0700116 private String mManageMobilePlanMessage;
Wink Saville5d5a2692013-06-29 07:54:13 -0700117 public void onManageMobilePlanClick() {
118 log("onManageMobilePlanClick:");
119 mManageMobilePlanMessage = null;
120 Resources resources = getActivity().getResources();
121
Paul Jensen6953eea2015-06-11 10:26:33 -0400122 NetworkInfo ni = mCm.getActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700123 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700124 // Check for carrier apps that can handle provisioning first
125 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700126 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700127 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700128 if (carrierPackages != null && !carrierPackages.isEmpty()) {
129 if (carrierPackages.size() != 1) {
130 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
131 }
132 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700133 startActivity(provisioningIntent);
134 return;
135 }
136
Wink Saville5d5a2692013-06-29 07:54:13 -0700137 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700138 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700139 if (!TextUtils.isEmpty(url)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400140 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
141 Intent.CATEGORY_APP_BROWSER);
142 intent.setData(Uri.parse(url));
143 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
144 Intent.FLAG_ACTIVITY_NEW_TASK);
145 try {
146 startActivity(intent);
147 } catch (ActivityNotFoundException e) {
148 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
149 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700150 } else {
151 // No provisioning URL
152 String operatorName = mTm.getSimOperatorName();
153 if (TextUtils.isEmpty(operatorName)) {
154 // Use NetworkOperatorName as second choice in case there is no
155 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
156 operatorName = mTm.getNetworkOperatorName();
157 if (TextUtils.isEmpty(operatorName)) {
158 mManageMobilePlanMessage = resources.getString(
159 R.string.mobile_unknown_sim_operator);
160 } else {
161 mManageMobilePlanMessage = resources.getString(
162 R.string.mobile_no_provisioning_url, operatorName);
163 }
164 } else {
165 mManageMobilePlanMessage = resources.getString(
166 R.string.mobile_no_provisioning_url, operatorName);
167 }
168 }
169 } else if (mTm.hasIccCard() == false) {
170 // No sim card
171 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
172 } else {
173 // NetworkInfo is null, there is no connection
174 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
175 }
176 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
177 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
178 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
179 }
180 }
181
Wink Saville5d5a2692013-06-29 07:54:13 -0700182 @Override
183 public Dialog onCreateDialog(int dialogId) {
184 log("onCreateDialog: dialogId=" + dialogId);
185 switch (dialogId) {
186 case MANAGE_MOBILE_PLAN_DIALOG_ID:
187 return new AlertDialog.Builder(getActivity())
188 .setMessage(mManageMobilePlanMessage)
189 .setCancelable(false)
190 .setPositiveButton(com.android.internal.R.string.ok,
191 new DialogInterface.OnClickListener() {
192 @Override
193 public void onClick(DialogInterface dialog, int id) {
194 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
195 mManageMobilePlanMessage = null;
196 }
197 })
198 .create();
199 }
200 return super.onCreateDialog(dialogId);
201 }
202
203 private void log(String s) {
204 Log.d(TAG, s);
205 }
206
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800207 @Override
Chris Wren8a963ba2015-03-20 10:29:14 -0400208 protected int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500209 return MetricsEvent.WIRELESS;
Chris Wren8a963ba2015-03-20 10:29:14 -0400210 }
211
212 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700213 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800214 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700215 if (savedInstanceState != null) {
216 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
217 }
218 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
219
220 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
221 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700222 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400223 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800224
225 addPreferencesFromResource(R.xml.wireless_settings);
226
Xiaohui Chen6f038292015-09-02 16:54:00 -0700227 final boolean isAdmin = mUm.isAdminUser();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700228
Amith Yamasanid7993472010-08-18 13:59:28 -0700229 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700230 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700231 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000232 RestrictedPreference androidBeam = (RestrictedPreference) findPreference(
233 KEY_ANDROID_BEAM_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800234
Gilles Debunnee78c1872011-06-20 15:00:07 -0700235 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500236 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700237
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700238 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800239
Christopher Tate6a5929b2012-09-10 15:39:05 -0700240 String toggleable = Settings.Global.getString(activity.getContentResolver(),
241 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800242
tk.mun7c5c1652011-10-13 22:56:18 +0900243 //enable/disable wimax depending on the value in config.xml
Xiaohui Chen6f038292015-09-02 16:54:00 -0700244 final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900245 com.android.internal.R.bool.config_wimaxEnabled);
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000246 if (!isWimaxEnabled || RestrictedLockUtils.hasBaseUserRestriction(activity,
247 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
tk.mun7c5c1652011-10-13 22:56:18 +0900248 PreferenceScreen root = getPreferenceScreen();
Xiaohui Chen6f038292015-09-02 16:54:00 -0700249 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900250 if (ps != null) root.removePreference(ps);
251 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700252 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900253 && isWimaxEnabled) {
Xiaohui Chen6f038292015-09-02 16:54:00 -0700254 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900255 ps.setDependency(KEY_TOGGLE_AIRPLANE);
256 }
257 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400258
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800259 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700260 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800261 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
262 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400263 // Disable VPN.
Xiaohui Chen6f038292015-09-02 16:54:00 -0700264 // TODO: http://b/23693383
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000265 if (!isAdmin || RestrictedLockUtils.hasBaseUserRestriction(activity,
266 UserManager.DISALLOW_CONFIG_VPN, UserHandle.myUserId())) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700267 removePreference(KEY_VPN_SETTINGS);
268 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400269
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800270 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700271 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700272 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700273 }
274
Nick Pelly9894d4a2011-08-09 07:10:16 -0700275 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700276 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700277 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500278 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700279 }
280
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700281 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500282 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
283 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700284 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500285 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700286 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800287 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800288
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400289 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
Sudheer Shanka8b868302016-01-26 13:50:23 +0000290 // if it's a wifi-only device.
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000291 if (!isAdmin || Utils.isWifiOnly(getActivity()) ||
292 RestrictedLockUtils.hasBaseUserRestriction(activity,
293 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700294 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700295 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800296 }
Sungmin Choi24903152013-10-15 16:11:55 -0700297 // Remove Mobile Network Settings and Manage Mobile Plan
298 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700299 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700300 R.bool.config_show_mobile_plan);
301 if (!isMobilePlanEnabled) {
302 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
303 if (pref != null) {
304 removePreference(KEY_MANAGE_MOBILE_PLAN);
305 }
306 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800307
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900308 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700309 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900310 removePreference(KEY_TOGGLE_AIRPLANE);
311 }
312
Oscar Montemayor05411892010-08-03 16:56:09 -0700313 // Enable Proxy selector settings if allowed.
314 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700315 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700316 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800317 // proxy UI disabled until we have better app support
318 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700319 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
320
Amith Yamasani0f85c482011-02-23 17:19:11 -0800321 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700322 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700323 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Sudheer Shanka682a9162016-01-13 22:10:18 +0000324
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000325 final boolean adminDisallowedTetherConfig = RestrictedLockUtils.checkIfRestrictionEnforced(
326 activity, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
327 if ((!cm.isTetheringSupported() && !adminDisallowedTetherConfig) ||
328 RestrictedLockUtils.hasBaseUserRestriction(activity,
329 UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800330 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Sudheer Shanka8b868302016-01-26 13:50:23 +0000331 } else if (!adminDisallowedTetherConfig) {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700332 Preference p = findPreference(KEY_TETHER_SETTINGS);
Wei Liu6e58d512015-08-24 17:29:04 -0700333 p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700334
335 // Grey out if provisioning is not available.
336 p.setEnabled(!TetherSettings
337 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800338 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800339 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800340
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800341 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700342 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800343 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700344
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800345 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700346 if (mNfcEnabler != null) {
347 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500348 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800349
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700350 // update WFC setting
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800351 final Context context = getActivity();
352 if (ImsManager.isWfcEnabledByPlatform(context)) {
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700353 getPreferenceScreen().addPreference(mButtonWfc);
354
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800355 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
356 context, ImsManager.getWfcMode(context)));
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700357 } else {
358 removePreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800359 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800360 }
Danica Chang32711b62010-08-10 18:41:29 -0700361
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800362 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700363 public void onSaveInstanceState(Bundle outState) {
364 super.onSaveInstanceState(outState);
365
366 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
367 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
368 }
369 }
370
371 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700372 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800373 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700374
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800375 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700376 if (mNfcEnabler != null) {
377 mNfcEnabler.pause();
378 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800379 }
Danica Chang32711b62010-08-10 18:41:29 -0700380
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500381 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700382 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800383 if (requestCode == REQUEST_CODE_EXIT_ECM) {
384 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500385 // Set Airplane mode based on the return value and checkbox state
386 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
387 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500388 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400389 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500390 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700391
392 @Override
393 protected int getHelpResource() {
394 return R.string.help_url_more_networks;
395 }
David Braun4e9f04d2013-09-16 13:45:42 -0700396
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700397 /**
398 * For Search.
399 */
400 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
401 new BaseSearchIndexProvider() {
402 @Override
403 public List<SearchIndexableResource> getXmlResourcesToIndex(
404 Context context, boolean enabled) {
405 SearchIndexableResource sir = new SearchIndexableResource(context);
406 sir.xmlResId = R.xml.wireless_settings;
407 return Arrays.asList(sir);
408 }
409
410 @Override
411 public List<String> getNonIndexableKeys(Context context) {
412 final ArrayList<String> result = new ArrayList<String>();
413
Julia Reynolds00d19c72014-06-24 15:22:50 -0400414 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Xiaohui Chen44879a32015-07-22 13:53:22 -0700415 final boolean isSecondaryUser = !um.isAdminUser();
Amith Yamasani32505ac2014-11-12 13:46:43 -0800416 final boolean isWimaxEnabled = !isSecondaryUser
417 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700418 com.android.internal.R.bool.config_wimaxEnabled);
Sudheer Shanka8b868302016-01-26 13:50:23 +0000419 if (!isWimaxEnabled) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700420 result.add(KEY_WIMAX_SETTINGS);
421 }
422
423 if (isSecondaryUser) { // Disable VPN
424 result.add(KEY_VPN_SETTINGS);
425 }
426
427 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800428 final NfcManager manager = (NfcManager)
429 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700430 if (manager != null) {
431 NfcAdapter adapter = manager.getDefaultAdapter();
432 if (adapter == null) {
433 result.add(KEY_TOGGLE_NFC);
434 result.add(KEY_ANDROID_BEAM_SETTINGS);
435 }
436 }
437
438 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
439 if (isSecondaryUser || Utils.isWifiOnly(context)) {
440 result.add(KEY_MOBILE_NETWORK_SETTINGS);
441 result.add(KEY_MANAGE_MOBILE_PLAN);
442 }
443
444 // Remove Mobile Network Settings and Manage Mobile Plan
445 // if config_show_mobile_plan sets false.
446 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
447 R.bool.config_show_mobile_plan);
448 if (!isMobilePlanEnabled) {
449 result.add(KEY_MANAGE_MOBILE_PLAN);
450 }
451
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700452 final PackageManager pm = context.getPackageManager();
453
454 // Remove Airplane Mode settings if it's a stationary device such as a TV.
455 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
456 result.add(KEY_TOGGLE_AIRPLANE);
457 }
458
459 // proxy UI disabled until we have better app support
460 result.add(KEY_PROXY_SETTINGS);
461
462 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800463 ConnectivityManager cm = (ConnectivityManager)
464 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700465 if (isSecondaryUser || !cm.isTetheringSupported()) {
466 result.add(KEY_TETHER_SETTINGS);
467 }
468
Anju Mathapatiec4706a2015-07-27 17:14:14 +0530469 if (!ImsManager.isWfcEnabledByPlatform(context)) {
470 result.add(KEY_WFC_SETTINGS);
471 }
472
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700473 return result;
474 }
475 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800476}