blob: d94b8a7039221bbce6d2c5860b09d2ecc03b2b27 [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;
David Braun4e9f04d2013-09-16 13:45:42 -070025import android.content.ComponentName;
Amith Yamasanid7993472010-08-18 13:59:28 -070026import android.content.Context;
Wink Saville5d5a2692013-06-29 07:54:13 -070027import android.content.DialogInterface;
Amith Yamasanid7993472010-08-18 13:59:28 -070028import android.content.Intent;
Irfan Sheriff167d7182011-09-07 14:51:11 -070029import android.content.pm.PackageManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070030import android.content.res.Resources;
Amith Yamasanid7993472010-08-18 13:59:28 -070031import android.net.ConnectivityManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070032import android.net.NetworkInfo;
Paul Jensend96c5fc2014-10-17 22:09:37 -040033import android.net.Uri;
Nick Pellya57eace2010-10-15 01:19:43 -070034import android.nfc.NfcAdapter;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070035import android.nfc.NfcManager;
Amith Yamasanid7993472010-08-18 13:59:28 -070036import android.os.Bundle;
Amith Yamasanid7993472010-08-18 13:59:28 -070037import android.os.SystemProperties;
Amith Yamasani9627a8e2012-09-23 12:54:14 -070038import android.os.UserHandle;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040039import android.os.UserManager;
Amith Yamasanid7993472010-08-18 13:59:28 -070040import android.preference.Preference;
David Braun4e9f04d2013-09-16 13:45:42 -070041import android.preference.Preference.OnPreferenceChangeListener;
Amith Yamasanid7993472010-08-18 13:59:28 -070042import android.preference.PreferenceScreen;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070043import android.preference.SwitchPreference;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070044import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070045import android.provider.Settings;
Wink Saville5d5a2692013-06-29 07:54:13 -070046import android.telephony.TelephonyManager;
47import android.text.TextUtils;
48import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070049
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080050import com.android.ims.ImsManager;
David Braun4e9f04d2013-09-16 13:45:42 -070051import com.android.internal.telephony.SmsApplication;
52import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070053import com.android.internal.telephony.TelephonyIntents;
54import com.android.internal.telephony.TelephonyProperties;
55import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070056import com.android.settings.search.BaseSearchIndexProvider;
57import com.android.settings.search.Indexable;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070058import java.util.ArrayList;
59import java.util.Arrays;
David Braun4e9f04d2013-09-16 13:45:42 -070060import java.util.Collection;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070061import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070062
Julia Reynolds00d19c72014-06-24 15:22:50 -040063public class WirelessSettings extends SettingsPreferenceFragment
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070064 implements OnPreferenceChangeListener, Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070065 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080066
67 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070068 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090069 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050070 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070071 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080072 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070073 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080074 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070075 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
David Braun4e9f04d2013-09-16 13:45:42 -070076 private static final String KEY_SMS_APPLICATION = "sms_application";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070077 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070078 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080079 private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070080
Chouting Zhang71cc49e2009-08-28 14:36:35 -050081 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
82 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080083
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080084 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070085 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070086 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050087 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070088 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050089
Wink Saville5d5a2692013-06-29 07:54:13 -070090 private ConnectivityManager mCm;
91 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070092 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040093 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070094
95 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
96 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
97
Jeff Davidsonb9558d92014-03-25 12:21:30 -070098 private AppListPreference mSmsApplicationPreference;
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080099 private PreferenceScreen mButtonWfc;
David Braun4e9f04d2013-09-16 13:45:42 -0700100
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500101 /**
102 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800103 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500104 * preference click events.
105 */
106 @Override
107 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700108 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800109 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
110 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500111 // In ECM mode launch ECM app dialog
112 startActivityForResult(
113 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
114 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500115 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700116 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
117 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500118 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800119 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700120 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500121 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800122
Wink Saville5d5a2692013-06-29 07:54:13 -0700123 private String mManageMobilePlanMessage;
Wink Saville5d5a2692013-06-29 07:54:13 -0700124 public void onManageMobilePlanClick() {
125 log("onManageMobilePlanClick:");
126 mManageMobilePlanMessage = null;
127 Resources resources = getActivity().getResources();
128
Wink Savillee24e5962013-08-28 14:26:27 -0700129 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700130 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700131 // Check for carrier apps that can handle provisioning first
132 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700133 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700134 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700135 if (carrierPackages != null && !carrierPackages.isEmpty()) {
136 if (carrierPackages.size() != 1) {
137 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
138 }
139 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700140 startActivity(provisioningIntent);
141 return;
142 }
143
Wink Saville5d5a2692013-06-29 07:54:13 -0700144 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700145 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700146 if (!TextUtils.isEmpty(url)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400147 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
148 Intent.CATEGORY_APP_BROWSER);
149 intent.setData(Uri.parse(url));
150 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
151 Intent.FLAG_ACTIVITY_NEW_TASK);
152 try {
153 startActivity(intent);
154 } catch (ActivityNotFoundException e) {
155 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
156 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700157 } else {
158 // No provisioning URL
159 String operatorName = mTm.getSimOperatorName();
160 if (TextUtils.isEmpty(operatorName)) {
161 // Use NetworkOperatorName as second choice in case there is no
162 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
163 operatorName = mTm.getNetworkOperatorName();
164 if (TextUtils.isEmpty(operatorName)) {
165 mManageMobilePlanMessage = resources.getString(
166 R.string.mobile_unknown_sim_operator);
167 } else {
168 mManageMobilePlanMessage = resources.getString(
169 R.string.mobile_no_provisioning_url, operatorName);
170 }
171 } else {
172 mManageMobilePlanMessage = resources.getString(
173 R.string.mobile_no_provisioning_url, operatorName);
174 }
175 }
176 } else if (mTm.hasIccCard() == false) {
177 // No sim card
178 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
179 } else {
180 // NetworkInfo is null, there is no connection
181 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
182 }
183 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
184 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
185 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
186 }
187 }
188
David Braun4e9f04d2013-09-16 13:45:42 -0700189 private void initSmsApplicationSetting() {
190 log("initSmsApplicationSetting:");
191 Collection<SmsApplicationData> smsApplications =
192 SmsApplication.getApplicationCollection(getActivity());
193
194 // If the list is empty the dialog will be empty, but we will not crash.
195 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700196 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700197 int i = 0;
198 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700199 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700200 i++;
201 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700202 String defaultPackageName = null;
203 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
204 if (appName != null) {
205 defaultPackageName = appName.getPackageName();
206 }
207 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700208 }
209
Wink Saville5d5a2692013-06-29 07:54:13 -0700210 @Override
211 public Dialog onCreateDialog(int dialogId) {
212 log("onCreateDialog: dialogId=" + dialogId);
213 switch (dialogId) {
214 case MANAGE_MOBILE_PLAN_DIALOG_ID:
215 return new AlertDialog.Builder(getActivity())
216 .setMessage(mManageMobilePlanMessage)
217 .setCancelable(false)
218 .setPositiveButton(com.android.internal.R.string.ok,
219 new DialogInterface.OnClickListener() {
220 @Override
221 public void onClick(DialogInterface dialog, int id) {
222 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
223 mManageMobilePlanMessage = null;
224 }
225 })
226 .create();
227 }
228 return super.onCreateDialog(dialogId);
229 }
230
231 private void log(String s) {
232 Log.d(TAG, s);
233 }
234
David Braun4e9f04d2013-09-16 13:45:42 -0700235 private boolean isSmsSupported() {
236 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500237 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700238 }
239
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800240 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700241 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800242 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700243 if (savedInstanceState != null) {
244 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
245 }
246 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
247
248 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
249 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700250 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400251 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800252
253 addPreferencesFromResource(R.xml.wireless_settings);
254
Amith Yamasani32505ac2014-11-12 13:46:43 -0800255 final int myUserId = UserHandle.myUserId();
256 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
257 final boolean isRestrictedUser = mUm.getUserInfo(myUserId).isRestricted();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700258
Amith Yamasanid7993472010-08-18 13:59:28 -0700259 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700260 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700261 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500262 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Fabrice Di Megliodaef2e22014-10-15 19:00:35 -0700263 SwitchPreference nsd = (SwitchPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800264
Gilles Debunnee78c1872011-06-20 15:00:07 -0700265 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500266 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700267
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700268 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800269 // Restricted users cannot currently read/write SMS.
270 if (isRestrictedUser) {
271 removePreference(KEY_SMS_APPLICATION);
272 } else {
273 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
274 initSmsApplicationSetting();
275 }
David Braun4e9f04d2013-09-16 13:45:42 -0700276
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800277 if (ImsManager.isWfcEnabledByPlatform(activity)) {
278 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
279 } else {
280 removePreference(KEY_WFC_SETTINGS);
281 }
282
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700283 // Remove NSD checkbox by default
284 getPreferenceScreen().removePreference(nsd);
285 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800286
Christopher Tate6a5929b2012-09-10 15:39:05 -0700287 String toggleable = Settings.Global.getString(activity.getContentResolver(),
288 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800289
tk.mun7c5c1652011-10-13 22:56:18 +0900290 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700291 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900292 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400293 if (!isWimaxEnabled
294 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900295 PreferenceScreen root = getPreferenceScreen();
296 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
297 if (ps != null) root.removePreference(ps);
298 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700299 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900300 && isWimaxEnabled) {
301 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
302 ps.setDependency(KEY_TOGGLE_AIRPLANE);
303 }
304 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400305
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800306 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700307 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800308 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
309 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400310 // Disable VPN.
311 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700312 removePreference(KEY_VPN_SETTINGS);
313 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400314
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800315 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700316 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700317 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700318 }
319
Nick Pelly9894d4a2011-08-09 07:10:16 -0700320 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700321 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700322 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500323 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700324 }
325
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700326 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500327 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
328 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700329 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500330 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700331 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800332 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800333
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400334 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
335 // if it's a wifi-only device, or if the settings are restricted.
336 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
337 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700338 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700339 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800340 }
Sungmin Choi24903152013-10-15 16:11:55 -0700341 // Remove Mobile Network Settings and Manage Mobile Plan
342 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700343 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700344 R.bool.config_show_mobile_plan);
345 if (!isMobilePlanEnabled) {
346 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
347 if (pref != null) {
348 removePreference(KEY_MANAGE_MOBILE_PLAN);
349 }
350 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800351
David Braun4e9f04d2013-09-16 13:45:42 -0700352 // Remove SMS Application if the device does not support SMS
353 if (!isSmsSupported()) {
354 removePreference(KEY_SMS_APPLICATION);
355 }
356
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900357 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700358 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900359 removePreference(KEY_TOGGLE_AIRPLANE);
360 }
361
Oscar Montemayor05411892010-08-03 16:56:09 -0700362 // Enable Proxy selector settings if allowed.
363 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700364 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700365 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800366 // proxy UI disabled until we have better app support
367 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700368 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
369
Amith Yamasani0f85c482011-02-23 17:19:11 -0800370 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700371 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700372 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400373 if (isSecondaryUser || !cm.isTetheringSupported()
374 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800375 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700376 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700377 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700378 p.setTitle(Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700379
380 // Grey out if provisioning is not available.
381 p.setEnabled(!TetherSettings
382 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800383 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700384
385 // Enable link to CMAS app settings depending on the value in config.xml.
386 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
387 com.android.internal.R.bool.config_cellBroadcastAppLinks);
388 try {
389 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700390 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700391 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
392 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
393 }
394 }
395 } catch (IllegalArgumentException ignored) {
396 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
397 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400398 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
399 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700400 PreferenceScreen root = getPreferenceScreen();
401 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
402 if (ps != null) root.removePreference(ps);
403 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800404 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800405
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800406 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700407 public void onStart() {
408 super.onStart();
409
410 initSmsApplicationSetting();
411 }
412
413 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700414 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800415 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700416
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800417 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700418 if (mNfcEnabler != null) {
419 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500420 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700421 if (mNsdEnabler != null) {
422 mNsdEnabler.resume();
423 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800424
425 final Context context = getActivity();
426 if (ImsManager.isWfcEnabledByPlatform(context)) {
427 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
428 context, ImsManager.getWfcMode(context)));
429 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800430 }
Danica Chang32711b62010-08-10 18:41:29 -0700431
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800432 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700433 public void onSaveInstanceState(Bundle outState) {
434 super.onSaveInstanceState(outState);
435
436 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
437 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
438 }
439 }
440
441 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700442 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800443 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700444
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800445 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700446 if (mNfcEnabler != null) {
447 mNfcEnabler.pause();
448 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700449 if (mNsdEnabler != null) {
450 mNsdEnabler.pause();
451 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800452 }
Danica Chang32711b62010-08-10 18:41:29 -0700453
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500454 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700455 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800456 if (requestCode == REQUEST_CODE_EXIT_ECM) {
457 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500458 // Set Airplane mode based on the return value and checkbox state
459 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
460 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500461 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400462 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500463 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700464
465 @Override
466 protected int getHelpResource() {
467 return R.string.help_url_more_networks;
468 }
David Braun4e9f04d2013-09-16 13:45:42 -0700469
470 @Override
471 public boolean onPreferenceChange(Preference preference, Object newValue) {
472 if (preference == mSmsApplicationPreference && newValue != null) {
473 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700474 return true;
475 }
476 return false;
477 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700478
479 /**
480 * For Search.
481 */
482 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
483 new BaseSearchIndexProvider() {
484 @Override
485 public List<SearchIndexableResource> getXmlResourcesToIndex(
486 Context context, boolean enabled) {
487 SearchIndexableResource sir = new SearchIndexableResource(context);
488 sir.xmlResId = R.xml.wireless_settings;
489 return Arrays.asList(sir);
490 }
491
492 @Override
493 public List<String> getNonIndexableKeys(Context context) {
494 final ArrayList<String> result = new ArrayList<String>();
495
496 result.add(KEY_TOGGLE_NSD);
497
Julia Reynolds00d19c72014-06-24 15:22:50 -0400498 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800499 final int myUserId = UserHandle.myUserId();
500 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
501 final boolean isRestrictedUser = um.getUserInfo(myUserId).isRestricted();
502 final boolean isWimaxEnabled = !isSecondaryUser
503 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700504 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400505 if (!isWimaxEnabled
506 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700507 result.add(KEY_WIMAX_SETTINGS);
508 }
509
510 if (isSecondaryUser) { // Disable VPN
511 result.add(KEY_VPN_SETTINGS);
512 }
513
514 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800515 final NfcManager manager = (NfcManager)
516 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700517 if (manager != null) {
518 NfcAdapter adapter = manager.getDefaultAdapter();
519 if (adapter == null) {
520 result.add(KEY_TOGGLE_NFC);
521 result.add(KEY_ANDROID_BEAM_SETTINGS);
522 }
523 }
524
525 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
526 if (isSecondaryUser || Utils.isWifiOnly(context)) {
527 result.add(KEY_MOBILE_NETWORK_SETTINGS);
528 result.add(KEY_MANAGE_MOBILE_PLAN);
529 }
530
531 // Remove Mobile Network Settings and Manage Mobile Plan
532 // if config_show_mobile_plan sets false.
533 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
534 R.bool.config_show_mobile_plan);
535 if (!isMobilePlanEnabled) {
536 result.add(KEY_MANAGE_MOBILE_PLAN);
537 }
538
539 // Remove SMS Application if the device does not support SMS
Yorke Lee5e108342014-06-19 22:21:41 +0000540 TelephonyManager tm =
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700541 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800542 if (!tm.isSmsCapable() || isRestrictedUser) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700543 result.add(KEY_SMS_APPLICATION);
544 }
545
546 final PackageManager pm = context.getPackageManager();
547
548 // Remove Airplane Mode settings if it's a stationary device such as a TV.
549 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
550 result.add(KEY_TOGGLE_AIRPLANE);
551 }
552
553 // proxy UI disabled until we have better app support
554 result.add(KEY_PROXY_SETTINGS);
555
556 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800557 ConnectivityManager cm = (ConnectivityManager)
558 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700559 if (isSecondaryUser || !cm.isTetheringSupported()) {
560 result.add(KEY_TETHER_SETTINGS);
561 }
562
563 // Enable link to CMAS app settings depending on the value in config.xml.
564 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
565 com.android.internal.R.bool.config_cellBroadcastAppLinks);
566 try {
567 if (isCellBroadcastAppLinkEnabled) {
568 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
569 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
570 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
571 }
572 }
573 } catch (IllegalArgumentException ignored) {
574 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
575 }
576 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
577 result.add(KEY_CELL_BROADCAST_SETTINGS);
578 }
579
580 return result;
581 }
582 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800583}