blob: 9253eac24cca90d6bac7ef2a2c20357dcba59ea6 [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;
Amith Yamasani9627a8e2012-09-23 12:54:14 -070037import android.os.UserHandle;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040038import android.os.UserManager;
Amith Yamasanid7993472010-08-18 13:59:28 -070039import android.preference.Preference;
40import android.preference.PreferenceScreen;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070041import android.preference.SwitchPreference;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070042import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070043import android.provider.Settings;
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 Wren8a963ba2015-03-20 10:29:14 -040049import com.android.internal.logging.MetricsLogger;
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;
Jason Monk73a24962015-04-13 20:58:05 -040055
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070056import java.util.ArrayList;
57import java.util.Arrays;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070058import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070059
Jason Monk73a24962015-04-13 20:58:05 -040060public class WirelessSettings extends SettingsPreferenceFragment implements Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070061 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080062
63 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070064 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090065 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050066 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070067 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080068 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070069 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080070 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070071 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070072 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070073 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
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;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070083 private NsdEnabler mNsdEnabler;
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
101 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, 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
Amith Yamasanid7993472010-08-18 13:59:28 -0700114 return super.onPreferenceTreeClick(preferenceScreen, 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() {
210 return MetricsLogger.WIRELESS;
211 }
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
Amith Yamasani32505ac2014-11-12 13:46:43 -0800228 final int myUserId = UserHandle.myUserId();
229 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
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);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500234 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Fabrice Di Megliodaef2e22014-10-15 19:00:35 -0700235 SwitchPreference nsd = (SwitchPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800236
Gilles Debunnee78c1872011-06-20 15:00:07 -0700237 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500238 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700239
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700240 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800241
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700242 // Remove NSD checkbox by default
243 getPreferenceScreen().removePreference(nsd);
244 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800245
Christopher Tate6a5929b2012-09-10 15:39:05 -0700246 String toggleable = Settings.Global.getString(activity.getContentResolver(),
247 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800248
tk.mun7c5c1652011-10-13 22:56:18 +0900249 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700250 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900251 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400252 if (!isWimaxEnabled
253 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900254 PreferenceScreen root = getPreferenceScreen();
255 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
256 if (ps != null) root.removePreference(ps);
257 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700258 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900259 && isWimaxEnabled) {
260 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
261 ps.setDependency(KEY_TOGGLE_AIRPLANE);
262 }
263 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400264
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800265 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700266 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800267 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
268 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400269 // Disable VPN.
270 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700271 removePreference(KEY_VPN_SETTINGS);
272 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400273
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800274 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700275 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700276 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700277 }
278
Nick Pelly9894d4a2011-08-09 07:10:16 -0700279 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700280 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700281 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500282 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700283 }
284
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700285 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500286 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
287 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700288 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500289 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700290 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800291 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800292
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400293 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
294 // if it's a wifi-only device, or if the settings are restricted.
295 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
296 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
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);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400327 if (isSecondaryUser || !cm.isTetheringSupported()
328 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800329 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700330 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700331 Preference p = findPreference(KEY_TETHER_SETTINGS);
Wei Liu6e58d512015-08-24 17:29:04 -0700332 p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700333
334 // Grey out if provisioning is not available.
335 p.setEnabled(!TetherSettings
336 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800337 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700338
339 // Enable link to CMAS app settings depending on the value in config.xml.
340 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
341 com.android.internal.R.bool.config_cellBroadcastAppLinks);
342 try {
343 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700344 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700345 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
346 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
347 }
348 }
349 } catch (IllegalArgumentException ignored) {
350 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
351 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400352 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
353 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700354 PreferenceScreen root = getPreferenceScreen();
355 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
356 if (ps != null) root.removePreference(ps);
357 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800358 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800359
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800360 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700361 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800362 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700363
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800364 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700365 if (mNfcEnabler != null) {
366 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500367 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700368 if (mNsdEnabler != null) {
369 mNsdEnabler.resume();
370 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800371
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700372 // update WFC setting
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800373 final Context context = getActivity();
374 if (ImsManager.isWfcEnabledByPlatform(context)) {
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700375 getPreferenceScreen().addPreference(mButtonWfc);
376
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800377 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
378 context, ImsManager.getWfcMode(context)));
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700379 } else {
380 removePreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800381 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800382 }
Danica Chang32711b62010-08-10 18:41:29 -0700383
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800384 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700385 public void onSaveInstanceState(Bundle outState) {
386 super.onSaveInstanceState(outState);
387
388 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
389 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
390 }
391 }
392
393 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700394 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800395 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700396
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800397 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700398 if (mNfcEnabler != null) {
399 mNfcEnabler.pause();
400 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700401 if (mNsdEnabler != null) {
402 mNsdEnabler.pause();
403 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800404 }
Danica Chang32711b62010-08-10 18:41:29 -0700405
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500406 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700407 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800408 if (requestCode == REQUEST_CODE_EXIT_ECM) {
409 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500410 // Set Airplane mode based on the return value and checkbox state
411 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
412 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500413 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400414 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500415 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700416
417 @Override
418 protected int getHelpResource() {
419 return R.string.help_url_more_networks;
420 }
David Braun4e9f04d2013-09-16 13:45:42 -0700421
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700422 /**
423 * For Search.
424 */
425 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
426 new BaseSearchIndexProvider() {
427 @Override
428 public List<SearchIndexableResource> getXmlResourcesToIndex(
429 Context context, boolean enabled) {
430 SearchIndexableResource sir = new SearchIndexableResource(context);
431 sir.xmlResId = R.xml.wireless_settings;
432 return Arrays.asList(sir);
433 }
434
435 @Override
436 public List<String> getNonIndexableKeys(Context context) {
437 final ArrayList<String> result = new ArrayList<String>();
438
439 result.add(KEY_TOGGLE_NSD);
440
Julia Reynolds00d19c72014-06-24 15:22:50 -0400441 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800442 final int myUserId = UserHandle.myUserId();
443 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
Amith Yamasani32505ac2014-11-12 13:46:43 -0800444 final boolean isWimaxEnabled = !isSecondaryUser
445 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700446 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400447 if (!isWimaxEnabled
448 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700449 result.add(KEY_WIMAX_SETTINGS);
450 }
451
452 if (isSecondaryUser) { // Disable VPN
453 result.add(KEY_VPN_SETTINGS);
454 }
455
456 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800457 final NfcManager manager = (NfcManager)
458 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700459 if (manager != null) {
460 NfcAdapter adapter = manager.getDefaultAdapter();
461 if (adapter == null) {
462 result.add(KEY_TOGGLE_NFC);
463 result.add(KEY_ANDROID_BEAM_SETTINGS);
464 }
465 }
466
467 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
468 if (isSecondaryUser || Utils.isWifiOnly(context)) {
469 result.add(KEY_MOBILE_NETWORK_SETTINGS);
470 result.add(KEY_MANAGE_MOBILE_PLAN);
471 }
472
473 // Remove Mobile Network Settings and Manage Mobile Plan
474 // if config_show_mobile_plan sets false.
475 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
476 R.bool.config_show_mobile_plan);
477 if (!isMobilePlanEnabled) {
478 result.add(KEY_MANAGE_MOBILE_PLAN);
479 }
480
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700481 final PackageManager pm = context.getPackageManager();
482
483 // Remove Airplane Mode settings if it's a stationary device such as a TV.
484 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
485 result.add(KEY_TOGGLE_AIRPLANE);
486 }
487
488 // proxy UI disabled until we have better app support
489 result.add(KEY_PROXY_SETTINGS);
490
491 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800492 ConnectivityManager cm = (ConnectivityManager)
493 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700494 if (isSecondaryUser || !cm.isTetheringSupported()) {
495 result.add(KEY_TETHER_SETTINGS);
496 }
497
498 // Enable link to CMAS app settings depending on the value in config.xml.
499 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
500 com.android.internal.R.bool.config_cellBroadcastAppLinks);
501 try {
502 if (isCellBroadcastAppLinkEnabled) {
503 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
504 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
505 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
506 }
507 }
508 } catch (IllegalArgumentException ignored) {
509 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
510 }
511 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
512 result.add(KEY_CELL_BROADCAST_SETTINGS);
513 }
514
515 return result;
516 }
517 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800518}