blob: e9c39d9d9dc3afeb4f3c7447bb2bcc9c85286be0 [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
50import com.android.internal.telephony.SmsApplication;
51import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070052import com.android.internal.telephony.TelephonyIntents;
53import com.android.internal.telephony.TelephonyProperties;
54import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070055import com.android.settings.search.BaseSearchIndexProvider;
56import com.android.settings.search.Indexable;
Gilles Debunnee78c1872011-06-20 15:00:07 -070057
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";
Nick Pellyad50ba02010-09-22 10:55:13 -070079
Chouting Zhang71cc49e2009-08-28 14:36:35 -050080 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
81 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080083 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070084 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070085 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050086 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070087 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050088
Wink Saville5d5a2692013-06-29 07:54:13 -070089 private ConnectivityManager mCm;
90 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070091 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040092 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070093
94 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
95 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
96
Jeff Davidsonb9558d92014-03-25 12:21:30 -070097 private AppListPreference mSmsApplicationPreference;
David Braun4e9f04d2013-09-16 13:45:42 -070098
Chouting Zhang71cc49e2009-08-28 14:36:35 -050099 /**
100 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800101 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500102 * preference click events.
103 */
104 @Override
105 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700106 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800107 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
108 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500109 // In ECM mode launch ECM app dialog
110 startActivityForResult(
111 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
112 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500113 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700114 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
115 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500116 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800117 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700118 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500119 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800120
Wink Saville5d5a2692013-06-29 07:54:13 -0700121 private String mManageMobilePlanMessage;
Wink Saville5d5a2692013-06-29 07:54:13 -0700122 public void onManageMobilePlanClick() {
123 log("onManageMobilePlanClick:");
124 mManageMobilePlanMessage = null;
125 Resources resources = getActivity().getResources();
126
Wink Savillee24e5962013-08-28 14:26:27 -0700127 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700128 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700129 // Check for carrier apps that can handle provisioning first
130 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700131 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700132 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700133 if (carrierPackages != null && !carrierPackages.isEmpty()) {
134 if (carrierPackages.size() != 1) {
135 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
136 }
137 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700138 startActivity(provisioningIntent);
139 return;
140 }
141
Wink Saville5d5a2692013-06-29 07:54:13 -0700142 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700143 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700144 if (!TextUtils.isEmpty(url)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400145 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
146 Intent.CATEGORY_APP_BROWSER);
147 intent.setData(Uri.parse(url));
148 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
149 Intent.FLAG_ACTIVITY_NEW_TASK);
150 try {
151 startActivity(intent);
152 } catch (ActivityNotFoundException e) {
153 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
154 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700155 } else {
156 // No provisioning URL
157 String operatorName = mTm.getSimOperatorName();
158 if (TextUtils.isEmpty(operatorName)) {
159 // Use NetworkOperatorName as second choice in case there is no
160 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
161 operatorName = mTm.getNetworkOperatorName();
162 if (TextUtils.isEmpty(operatorName)) {
163 mManageMobilePlanMessage = resources.getString(
164 R.string.mobile_unknown_sim_operator);
165 } else {
166 mManageMobilePlanMessage = resources.getString(
167 R.string.mobile_no_provisioning_url, operatorName);
168 }
169 } else {
170 mManageMobilePlanMessage = resources.getString(
171 R.string.mobile_no_provisioning_url, operatorName);
172 }
173 }
174 } else if (mTm.hasIccCard() == false) {
175 // No sim card
176 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
177 } else {
178 // NetworkInfo is null, there is no connection
179 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
180 }
181 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
182 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
183 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
184 }
185 }
186
David Braun4e9f04d2013-09-16 13:45:42 -0700187 private void initSmsApplicationSetting() {
188 log("initSmsApplicationSetting:");
189 Collection<SmsApplicationData> smsApplications =
190 SmsApplication.getApplicationCollection(getActivity());
191
192 // If the list is empty the dialog will be empty, but we will not crash.
193 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700194 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700195 int i = 0;
196 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700197 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700198 i++;
199 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700200 String defaultPackageName = null;
201 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
202 if (appName != null) {
203 defaultPackageName = appName.getPackageName();
204 }
205 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700206 }
207
Wink Saville5d5a2692013-06-29 07:54:13 -0700208 @Override
209 public Dialog onCreateDialog(int dialogId) {
210 log("onCreateDialog: dialogId=" + dialogId);
211 switch (dialogId) {
212 case MANAGE_MOBILE_PLAN_DIALOG_ID:
213 return new AlertDialog.Builder(getActivity())
214 .setMessage(mManageMobilePlanMessage)
215 .setCancelable(false)
216 .setPositiveButton(com.android.internal.R.string.ok,
217 new DialogInterface.OnClickListener() {
218 @Override
219 public void onClick(DialogInterface dialog, int id) {
220 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
221 mManageMobilePlanMessage = null;
222 }
223 })
224 .create();
225 }
226 return super.onCreateDialog(dialogId);
227 }
228
229 private void log(String s) {
230 Log.d(TAG, s);
231 }
232
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800233 public static boolean isRadioAllowed(Context context, String type) {
234 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
235 return true;
236 }
237 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700238 String toggleable = Settings.Global.getString(context.getContentResolver(),
239 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800240 return toggleable != null && toggleable.contains(type);
241 }
242
David Braun4e9f04d2013-09-16 13:45:42 -0700243 private boolean isSmsSupported() {
244 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500245 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700246 }
247
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800248 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700249 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800250 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700251 if (savedInstanceState != null) {
252 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
253 }
254 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
255
256 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
257 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700258 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400259 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800260
261 addPreferencesFromResource(R.xml.wireless_settings);
262
Amith Yamasani32505ac2014-11-12 13:46:43 -0800263 final int myUserId = UserHandle.myUserId();
264 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
265 final boolean isRestrictedUser = mUm.getUserInfo(myUserId).isRestricted();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700266
Amith Yamasanid7993472010-08-18 13:59:28 -0700267 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700268 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700269 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500270 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Fabrice Di Megliodaef2e22014-10-15 19:00:35 -0700271 SwitchPreference nsd = (SwitchPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800272
Gilles Debunnee78c1872011-06-20 15:00:07 -0700273 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500274 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700275
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700276 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800277 // Restricted users cannot currently read/write SMS.
278 if (isRestrictedUser) {
279 removePreference(KEY_SMS_APPLICATION);
280 } else {
281 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
282 initSmsApplicationSetting();
283 }
David Braun4e9f04d2013-09-16 13:45:42 -0700284
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700285 // Remove NSD checkbox by default
286 getPreferenceScreen().removePreference(nsd);
287 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800288
Christopher Tate6a5929b2012-09-10 15:39:05 -0700289 String toggleable = Settings.Global.getString(activity.getContentResolver(),
290 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800291
tk.mun7c5c1652011-10-13 22:56:18 +0900292 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700293 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900294 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400295 if (!isWimaxEnabled
296 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900297 PreferenceScreen root = getPreferenceScreen();
298 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
299 if (ps != null) root.removePreference(ps);
300 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700301 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900302 && isWimaxEnabled) {
303 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
304 ps.setDependency(KEY_TOGGLE_AIRPLANE);
305 }
306 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400307
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800308 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700309 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800310 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
311 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400312 // Disable VPN.
313 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700314 removePreference(KEY_VPN_SETTINGS);
315 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400316
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800317 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700318 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700319 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700320 }
321
Nick Pelly9894d4a2011-08-09 07:10:16 -0700322 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700323 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700324 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500325 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700326 }
327
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700328 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500329 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
330 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700331 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500332 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700333 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800334 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800335
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400336 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
337 // if it's a wifi-only device, or if the settings are restricted.
338 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
339 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700340 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700341 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800342 }
Sungmin Choi24903152013-10-15 16:11:55 -0700343 // Remove Mobile Network Settings and Manage Mobile Plan
344 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700345 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700346 R.bool.config_show_mobile_plan);
347 if (!isMobilePlanEnabled) {
348 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
349 if (pref != null) {
350 removePreference(KEY_MANAGE_MOBILE_PLAN);
351 }
352 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800353
David Braun4e9f04d2013-09-16 13:45:42 -0700354 // Remove SMS Application if the device does not support SMS
355 if (!isSmsSupported()) {
356 removePreference(KEY_SMS_APPLICATION);
357 }
358
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900359 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700360 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900361 removePreference(KEY_TOGGLE_AIRPLANE);
362 }
363
Oscar Montemayor05411892010-08-03 16:56:09 -0700364 // Enable Proxy selector settings if allowed.
365 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700366 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700367 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800368 // proxy UI disabled until we have better app support
369 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700370 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
371
Amith Yamasani0f85c482011-02-23 17:19:11 -0800372 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700373 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700374 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400375 if (isSecondaryUser || !cm.isTetheringSupported()
376 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800377 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700378 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700379 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700380 p.setTitle(Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700381
382 // Grey out if provisioning is not available.
383 p.setEnabled(!TetherSettings
384 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800385 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700386
387 // Enable link to CMAS app settings depending on the value in config.xml.
388 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
389 com.android.internal.R.bool.config_cellBroadcastAppLinks);
390 try {
391 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700392 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700393 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
394 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
395 }
396 }
397 } catch (IllegalArgumentException ignored) {
398 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
399 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400400 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
401 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700402 PreferenceScreen root = getPreferenceScreen();
403 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
404 if (ps != null) root.removePreference(ps);
405 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800406 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800407
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800408 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700409 public void onStart() {
410 super.onStart();
411
412 initSmsApplicationSetting();
413 }
414
415 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700416 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800417 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700418
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800419 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700420 if (mNfcEnabler != null) {
421 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500422 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700423 if (mNsdEnabler != null) {
424 mNsdEnabler.resume();
425 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800426 }
Danica Chang32711b62010-08-10 18:41:29 -0700427
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800428 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700429 public void onSaveInstanceState(Bundle outState) {
430 super.onSaveInstanceState(outState);
431
432 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
433 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
434 }
435 }
436
437 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700438 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800439 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700440
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800441 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700442 if (mNfcEnabler != null) {
443 mNfcEnabler.pause();
444 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700445 if (mNsdEnabler != null) {
446 mNsdEnabler.pause();
447 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800448 }
Danica Chang32711b62010-08-10 18:41:29 -0700449
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500450 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700451 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800452 if (requestCode == REQUEST_CODE_EXIT_ECM) {
453 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500454 // Set Airplane mode based on the return value and checkbox state
455 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
456 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500457 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400458 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500459 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700460
461 @Override
462 protected int getHelpResource() {
463 return R.string.help_url_more_networks;
464 }
David Braun4e9f04d2013-09-16 13:45:42 -0700465
466 @Override
467 public boolean onPreferenceChange(Preference preference, Object newValue) {
468 if (preference == mSmsApplicationPreference && newValue != null) {
469 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700470 return true;
471 }
472 return false;
473 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700474
475 /**
476 * For Search.
477 */
478 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
479 new BaseSearchIndexProvider() {
480 @Override
481 public List<SearchIndexableResource> getXmlResourcesToIndex(
482 Context context, boolean enabled) {
483 SearchIndexableResource sir = new SearchIndexableResource(context);
484 sir.xmlResId = R.xml.wireless_settings;
485 return Arrays.asList(sir);
486 }
487
488 @Override
489 public List<String> getNonIndexableKeys(Context context) {
490 final ArrayList<String> result = new ArrayList<String>();
491
492 result.add(KEY_TOGGLE_NSD);
493
Julia Reynolds00d19c72014-06-24 15:22:50 -0400494 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800495 final int myUserId = UserHandle.myUserId();
496 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
497 final boolean isRestrictedUser = um.getUserInfo(myUserId).isRestricted();
498 final boolean isWimaxEnabled = !isSecondaryUser
499 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700500 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400501 if (!isWimaxEnabled
502 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700503 result.add(KEY_WIMAX_SETTINGS);
504 }
505
506 if (isSecondaryUser) { // Disable VPN
507 result.add(KEY_VPN_SETTINGS);
508 }
509
510 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800511 final NfcManager manager = (NfcManager)
512 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700513 if (manager != null) {
514 NfcAdapter adapter = manager.getDefaultAdapter();
515 if (adapter == null) {
516 result.add(KEY_TOGGLE_NFC);
517 result.add(KEY_ANDROID_BEAM_SETTINGS);
518 }
519 }
520
521 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
522 if (isSecondaryUser || Utils.isWifiOnly(context)) {
523 result.add(KEY_MOBILE_NETWORK_SETTINGS);
524 result.add(KEY_MANAGE_MOBILE_PLAN);
525 }
526
527 // Remove Mobile Network Settings and Manage Mobile Plan
528 // if config_show_mobile_plan sets false.
529 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
530 R.bool.config_show_mobile_plan);
531 if (!isMobilePlanEnabled) {
532 result.add(KEY_MANAGE_MOBILE_PLAN);
533 }
534
535 // Remove SMS Application if the device does not support SMS
Yorke Lee5e108342014-06-19 22:21:41 +0000536 TelephonyManager tm =
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700537 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800538 if (!tm.isSmsCapable() || isRestrictedUser) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700539 result.add(KEY_SMS_APPLICATION);
540 }
541
542 final PackageManager pm = context.getPackageManager();
543
544 // Remove Airplane Mode settings if it's a stationary device such as a TV.
545 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
546 result.add(KEY_TOGGLE_AIRPLANE);
547 }
548
549 // proxy UI disabled until we have better app support
550 result.add(KEY_PROXY_SETTINGS);
551
552 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800553 ConnectivityManager cm = (ConnectivityManager)
554 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700555 if (isSecondaryUser || !cm.isTetheringSupported()) {
556 result.add(KEY_TETHER_SETTINGS);
557 }
558
559 // Enable link to CMAS app settings depending on the value in config.xml.
560 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
561 com.android.internal.R.bool.config_cellBroadcastAppLinks);
562 try {
563 if (isCellBroadcastAppLinkEnabled) {
564 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
565 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
566 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
567 }
568 }
569 } catch (IllegalArgumentException ignored) {
570 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
571 }
572 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
573 result.add(KEY_CELL_BROADCAST_SETTINGS);
574 }
575
576 return result;
577 }
578 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800579}