blob: e8c3e15be94e1c63ff229f021be8f79d7338b7a6 [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
Wink Savillee24e5962013-08-28 14:26:27 -0700123 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
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 Zhamaitsiak4ab32562015-02-23 15:34:07 -0800240 if (ImsManager.isWfcEnabledByPlatform(activity)) {
241 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
242 } else {
243 removePreference(KEY_WFC_SETTINGS);
244 }
245
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700246 // Remove NSD checkbox by default
247 getPreferenceScreen().removePreference(nsd);
248 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800249
Christopher Tate6a5929b2012-09-10 15:39:05 -0700250 String toggleable = Settings.Global.getString(activity.getContentResolver(),
251 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800252
tk.mun7c5c1652011-10-13 22:56:18 +0900253 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700254 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900255 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400256 if (!isWimaxEnabled
257 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900258 PreferenceScreen root = getPreferenceScreen();
259 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
260 if (ps != null) root.removePreference(ps);
261 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700262 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900263 && isWimaxEnabled) {
264 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
265 ps.setDependency(KEY_TOGGLE_AIRPLANE);
266 }
267 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400268
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800269 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700270 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800271 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
272 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400273 // Disable VPN.
274 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700275 removePreference(KEY_VPN_SETTINGS);
276 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400277
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800278 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700279 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700280 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700281 }
282
Nick Pelly9894d4a2011-08-09 07:10:16 -0700283 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700284 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700285 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500286 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700287 }
288
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700289 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500290 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
291 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700292 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500293 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700294 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800295 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800296
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400297 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
298 // if it's a wifi-only device, or if the settings are restricted.
299 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
300 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700301 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700302 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800303 }
Sungmin Choi24903152013-10-15 16:11:55 -0700304 // Remove Mobile Network Settings and Manage Mobile Plan
305 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700306 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700307 R.bool.config_show_mobile_plan);
308 if (!isMobilePlanEnabled) {
309 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
310 if (pref != null) {
311 removePreference(KEY_MANAGE_MOBILE_PLAN);
312 }
313 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800314
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900315 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700316 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900317 removePreference(KEY_TOGGLE_AIRPLANE);
318 }
319
Oscar Montemayor05411892010-08-03 16:56:09 -0700320 // Enable Proxy selector settings if allowed.
321 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700322 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700323 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800324 // proxy UI disabled until we have better app support
325 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700326 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
327
Amith Yamasani0f85c482011-02-23 17:19:11 -0800328 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700329 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700330 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400331 if (isSecondaryUser || !cm.isTetheringSupported()
332 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800333 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700334 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700335 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700336 p.setTitle(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 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700342
343 // Enable link to CMAS app settings depending on the value in config.xml.
344 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
345 com.android.internal.R.bool.config_cellBroadcastAppLinks);
346 try {
347 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700348 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700349 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
350 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
351 }
352 }
353 } catch (IllegalArgumentException ignored) {
354 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
355 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400356 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
357 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700358 PreferenceScreen root = getPreferenceScreen();
359 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
360 if (ps != null) root.removePreference(ps);
361 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800362 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800363
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800364 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700365 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800366 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700367
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800368 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700369 if (mNfcEnabler != null) {
370 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500371 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700372 if (mNsdEnabler != null) {
373 mNsdEnabler.resume();
374 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800375
376 final Context context = getActivity();
377 if (ImsManager.isWfcEnabledByPlatform(context)) {
378 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
379 context, ImsManager.getWfcMode(context)));
380 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800381 }
Danica Chang32711b62010-08-10 18:41:29 -0700382
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800383 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700384 public void onSaveInstanceState(Bundle outState) {
385 super.onSaveInstanceState(outState);
386
387 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
388 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
389 }
390 }
391
392 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700393 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800394 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700395
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800396 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700397 if (mNfcEnabler != null) {
398 mNfcEnabler.pause();
399 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700400 if (mNsdEnabler != null) {
401 mNsdEnabler.pause();
402 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800403 }
Danica Chang32711b62010-08-10 18:41:29 -0700404
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500405 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700406 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800407 if (requestCode == REQUEST_CODE_EXIT_ECM) {
408 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500409 // Set Airplane mode based on the return value and checkbox state
410 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
411 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500412 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400413 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500414 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700415
416 @Override
417 protected int getHelpResource() {
418 return R.string.help_url_more_networks;
419 }
David Braun4e9f04d2013-09-16 13:45:42 -0700420
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700421 /**
422 * For Search.
423 */
424 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
425 new BaseSearchIndexProvider() {
426 @Override
427 public List<SearchIndexableResource> getXmlResourcesToIndex(
428 Context context, boolean enabled) {
429 SearchIndexableResource sir = new SearchIndexableResource(context);
430 sir.xmlResId = R.xml.wireless_settings;
431 return Arrays.asList(sir);
432 }
433
434 @Override
435 public List<String> getNonIndexableKeys(Context context) {
436 final ArrayList<String> result = new ArrayList<String>();
437
438 result.add(KEY_TOGGLE_NSD);
439
Julia Reynolds00d19c72014-06-24 15:22:50 -0400440 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800441 final int myUserId = UserHandle.myUserId();
442 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
Amith Yamasani32505ac2014-11-12 13:46:43 -0800443 final boolean isWimaxEnabled = !isSecondaryUser
444 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700445 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400446 if (!isWimaxEnabled
447 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700448 result.add(KEY_WIMAX_SETTINGS);
449 }
450
451 if (isSecondaryUser) { // Disable VPN
452 result.add(KEY_VPN_SETTINGS);
453 }
454
455 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800456 final NfcManager manager = (NfcManager)
457 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700458 if (manager != null) {
459 NfcAdapter adapter = manager.getDefaultAdapter();
460 if (adapter == null) {
461 result.add(KEY_TOGGLE_NFC);
462 result.add(KEY_ANDROID_BEAM_SETTINGS);
463 }
464 }
465
466 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
467 if (isSecondaryUser || Utils.isWifiOnly(context)) {
468 result.add(KEY_MOBILE_NETWORK_SETTINGS);
469 result.add(KEY_MANAGE_MOBILE_PLAN);
470 }
471
472 // Remove Mobile Network Settings and Manage Mobile Plan
473 // if config_show_mobile_plan sets false.
474 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
475 R.bool.config_show_mobile_plan);
476 if (!isMobilePlanEnabled) {
477 result.add(KEY_MANAGE_MOBILE_PLAN);
478 }
479
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700480 final PackageManager pm = context.getPackageManager();
481
482 // Remove Airplane Mode settings if it's a stationary device such as a TV.
483 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
484 result.add(KEY_TOGGLE_AIRPLANE);
485 }
486
487 // proxy UI disabled until we have better app support
488 result.add(KEY_PROXY_SETTINGS);
489
490 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800491 ConnectivityManager cm = (ConnectivityManager)
492 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700493 if (isSecondaryUser || !cm.isTetheringSupported()) {
494 result.add(KEY_TETHER_SETTINGS);
495 }
496
497 // Enable link to CMAS app settings depending on the value in config.xml.
498 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
499 com.android.internal.R.bool.config_cellBroadcastAppLinks);
500 try {
501 if (isCellBroadcastAppLinkEnabled) {
502 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
503 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
504 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
505 }
506 }
507 } catch (IllegalArgumentException ignored) {
508 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
509 }
510 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
511 result.add(KEY_CELL_BROADCAST_SETTINGS);
512 }
513
514 return result;
515 }
516 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800517}