blob: 000aa30377fe1e4a79f09f76ffe40b34445fedb9 [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;
Chris Wren8a963ba2015-03-20 10:29:14 -040051import com.android.internal.logging.MetricsLogger;
David Braun4e9f04d2013-09-16 13:45:42 -070052import com.android.internal.telephony.SmsApplication;
53import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070054import com.android.internal.telephony.TelephonyIntents;
55import com.android.internal.telephony.TelephonyProperties;
56import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070057import com.android.settings.search.BaseSearchIndexProvider;
58import com.android.settings.search.Indexable;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070059import java.util.ArrayList;
60import java.util.Arrays;
David Braun4e9f04d2013-09-16 13:45:42 -070061import java.util.Collection;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070062import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070063
Julia Reynolds00d19c72014-06-24 15:22:50 -040064public class WirelessSettings extends SettingsPreferenceFragment
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070065 implements OnPreferenceChangeListener, Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070066 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080067
68 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070069 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090070 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050071 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070072 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080073 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070074 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080075 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070076 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
David Braun4e9f04d2013-09-16 13:45:42 -070077 private static final String KEY_SMS_APPLICATION = "sms_application";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070078 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070079 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080080 private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070081
Chouting Zhang71cc49e2009-08-28 14:36:35 -050082 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
83 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080084
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080085 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070086 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070087 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050088 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070089 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050090
Wink Saville5d5a2692013-06-29 07:54:13 -070091 private ConnectivityManager mCm;
92 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070093 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040094 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070095
96 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
97 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
98
Jeff Davidsonb9558d92014-03-25 12:21:30 -070099 private AppListPreference mSmsApplicationPreference;
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800100 private PreferenceScreen mButtonWfc;
David Braun4e9f04d2013-09-16 13:45:42 -0700101
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500102 /**
103 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800104 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500105 * preference click events.
106 */
107 @Override
108 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700109 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800110 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
111 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500112 // In ECM mode launch ECM app dialog
113 startActivityForResult(
114 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
115 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500116 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700117 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
118 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500119 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800120 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700121 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500122 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800123
Wink Saville5d5a2692013-06-29 07:54:13 -0700124 private String mManageMobilePlanMessage;
Wink Saville5d5a2692013-06-29 07:54:13 -0700125 public void onManageMobilePlanClick() {
126 log("onManageMobilePlanClick:");
127 mManageMobilePlanMessage = null;
128 Resources resources = getActivity().getResources();
129
Wink Savillee24e5962013-08-28 14:26:27 -0700130 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700131 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700132 // Check for carrier apps that can handle provisioning first
133 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700134 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700135 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700136 if (carrierPackages != null && !carrierPackages.isEmpty()) {
137 if (carrierPackages.size() != 1) {
138 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
139 }
140 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700141 startActivity(provisioningIntent);
142 return;
143 }
144
Wink Saville5d5a2692013-06-29 07:54:13 -0700145 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700146 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700147 if (!TextUtils.isEmpty(url)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400148 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
149 Intent.CATEGORY_APP_BROWSER);
150 intent.setData(Uri.parse(url));
151 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
152 Intent.FLAG_ACTIVITY_NEW_TASK);
153 try {
154 startActivity(intent);
155 } catch (ActivityNotFoundException e) {
156 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
157 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700158 } else {
159 // No provisioning URL
160 String operatorName = mTm.getSimOperatorName();
161 if (TextUtils.isEmpty(operatorName)) {
162 // Use NetworkOperatorName as second choice in case there is no
163 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
164 operatorName = mTm.getNetworkOperatorName();
165 if (TextUtils.isEmpty(operatorName)) {
166 mManageMobilePlanMessage = resources.getString(
167 R.string.mobile_unknown_sim_operator);
168 } else {
169 mManageMobilePlanMessage = resources.getString(
170 R.string.mobile_no_provisioning_url, operatorName);
171 }
172 } else {
173 mManageMobilePlanMessage = resources.getString(
174 R.string.mobile_no_provisioning_url, operatorName);
175 }
176 }
177 } else if (mTm.hasIccCard() == false) {
178 // No sim card
179 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
180 } else {
181 // NetworkInfo is null, there is no connection
182 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
183 }
184 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
185 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
186 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
187 }
188 }
189
David Braun4e9f04d2013-09-16 13:45:42 -0700190 private void initSmsApplicationSetting() {
191 log("initSmsApplicationSetting:");
192 Collection<SmsApplicationData> smsApplications =
193 SmsApplication.getApplicationCollection(getActivity());
194
195 // If the list is empty the dialog will be empty, but we will not crash.
196 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700197 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700198 int i = 0;
199 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700200 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700201 i++;
202 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700203 String defaultPackageName = null;
204 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
205 if (appName != null) {
206 defaultPackageName = appName.getPackageName();
207 }
208 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700209 }
210
Wink Saville5d5a2692013-06-29 07:54:13 -0700211 @Override
212 public Dialog onCreateDialog(int dialogId) {
213 log("onCreateDialog: dialogId=" + dialogId);
214 switch (dialogId) {
215 case MANAGE_MOBILE_PLAN_DIALOG_ID:
216 return new AlertDialog.Builder(getActivity())
217 .setMessage(mManageMobilePlanMessage)
218 .setCancelable(false)
219 .setPositiveButton(com.android.internal.R.string.ok,
220 new DialogInterface.OnClickListener() {
221 @Override
222 public void onClick(DialogInterface dialog, int id) {
223 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
224 mManageMobilePlanMessage = null;
225 }
226 })
227 .create();
228 }
229 return super.onCreateDialog(dialogId);
230 }
231
232 private void log(String s) {
233 Log.d(TAG, s);
234 }
235
David Braun4e9f04d2013-09-16 13:45:42 -0700236 private boolean isSmsSupported() {
237 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500238 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700239 }
240
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800241 @Override
Chris Wren8a963ba2015-03-20 10:29:14 -0400242 protected int getMetricsCategory() {
243 return MetricsLogger.WIRELESS;
244 }
245
246 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700247 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800248 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700249 if (savedInstanceState != null) {
250 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
251 }
252 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
253
254 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
255 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700256 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400257 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800258
259 addPreferencesFromResource(R.xml.wireless_settings);
260
Amith Yamasani32505ac2014-11-12 13:46:43 -0800261 final int myUserId = UserHandle.myUserId();
262 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
263 final boolean isRestrictedUser = mUm.getUserInfo(myUserId).isRestricted();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700264
Amith Yamasanid7993472010-08-18 13:59:28 -0700265 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700266 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700267 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500268 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Fabrice Di Megliodaef2e22014-10-15 19:00:35 -0700269 SwitchPreference nsd = (SwitchPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800270
Gilles Debunnee78c1872011-06-20 15:00:07 -0700271 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500272 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700273
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700274 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800275 // Restricted users cannot currently read/write SMS.
276 if (isRestrictedUser) {
277 removePreference(KEY_SMS_APPLICATION);
278 } else {
279 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
280 initSmsApplicationSetting();
281 }
David Braun4e9f04d2013-09-16 13:45:42 -0700282
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800283 if (ImsManager.isWfcEnabledByPlatform(activity)) {
284 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
285 } else {
286 removePreference(KEY_WFC_SETTINGS);
287 }
288
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700289 // Remove NSD checkbox by default
290 getPreferenceScreen().removePreference(nsd);
291 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800292
Christopher Tate6a5929b2012-09-10 15:39:05 -0700293 String toggleable = Settings.Global.getString(activity.getContentResolver(),
294 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800295
tk.mun7c5c1652011-10-13 22:56:18 +0900296 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700297 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900298 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400299 if (!isWimaxEnabled
300 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900301 PreferenceScreen root = getPreferenceScreen();
302 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
303 if (ps != null) root.removePreference(ps);
304 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700305 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900306 && isWimaxEnabled) {
307 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
308 ps.setDependency(KEY_TOGGLE_AIRPLANE);
309 }
310 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400311
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800312 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700313 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800314 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
315 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400316 // Disable VPN.
317 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700318 removePreference(KEY_VPN_SETTINGS);
319 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400320
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800321 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700322 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700323 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700324 }
325
Nick Pelly9894d4a2011-08-09 07:10:16 -0700326 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700327 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700328 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500329 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700330 }
331
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700332 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500333 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
334 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700335 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500336 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700337 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800338 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800339
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400340 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
341 // if it's a wifi-only device, or if the settings are restricted.
342 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
343 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700344 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700345 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800346 }
Sungmin Choi24903152013-10-15 16:11:55 -0700347 // Remove Mobile Network Settings and Manage Mobile Plan
348 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700349 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700350 R.bool.config_show_mobile_plan);
351 if (!isMobilePlanEnabled) {
352 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
353 if (pref != null) {
354 removePreference(KEY_MANAGE_MOBILE_PLAN);
355 }
356 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800357
David Braun4e9f04d2013-09-16 13:45:42 -0700358 // Remove SMS Application if the device does not support SMS
359 if (!isSmsSupported()) {
360 removePreference(KEY_SMS_APPLICATION);
361 }
362
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900363 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700364 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900365 removePreference(KEY_TOGGLE_AIRPLANE);
366 }
367
Oscar Montemayor05411892010-08-03 16:56:09 -0700368 // Enable Proxy selector settings if allowed.
369 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700370 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700371 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800372 // proxy UI disabled until we have better app support
373 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700374 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
375
Amith Yamasani0f85c482011-02-23 17:19:11 -0800376 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700377 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700378 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400379 if (isSecondaryUser || !cm.isTetheringSupported()
380 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800381 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700382 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700383 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700384 p.setTitle(Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700385
386 // Grey out if provisioning is not available.
387 p.setEnabled(!TetherSettings
388 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800389 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700390
391 // Enable link to CMAS app settings depending on the value in config.xml.
392 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
393 com.android.internal.R.bool.config_cellBroadcastAppLinks);
394 try {
395 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700396 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700397 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
398 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
399 }
400 }
401 } catch (IllegalArgumentException ignored) {
402 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
403 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400404 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
405 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700406 PreferenceScreen root = getPreferenceScreen();
407 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
408 if (ps != null) root.removePreference(ps);
409 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800410 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800411
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800412 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700413 public void onStart() {
414 super.onStart();
415
416 initSmsApplicationSetting();
417 }
418
419 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700420 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800421 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700422
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800423 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700424 if (mNfcEnabler != null) {
425 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500426 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700427 if (mNsdEnabler != null) {
428 mNsdEnabler.resume();
429 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800430
431 final Context context = getActivity();
432 if (ImsManager.isWfcEnabledByPlatform(context)) {
433 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
434 context, ImsManager.getWfcMode(context)));
435 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800436 }
Danica Chang32711b62010-08-10 18:41:29 -0700437
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800438 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700439 public void onSaveInstanceState(Bundle outState) {
440 super.onSaveInstanceState(outState);
441
442 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
443 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
444 }
445 }
446
447 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700448 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800449 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700450
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800451 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700452 if (mNfcEnabler != null) {
453 mNfcEnabler.pause();
454 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700455 if (mNsdEnabler != null) {
456 mNsdEnabler.pause();
457 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800458 }
Danica Chang32711b62010-08-10 18:41:29 -0700459
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500460 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700461 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800462 if (requestCode == REQUEST_CODE_EXIT_ECM) {
463 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500464 // Set Airplane mode based on the return value and checkbox state
465 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
466 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500467 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400468 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500469 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700470
471 @Override
472 protected int getHelpResource() {
473 return R.string.help_url_more_networks;
474 }
David Braun4e9f04d2013-09-16 13:45:42 -0700475
476 @Override
477 public boolean onPreferenceChange(Preference preference, Object newValue) {
478 if (preference == mSmsApplicationPreference && newValue != null) {
479 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700480 return true;
481 }
482 return false;
483 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700484
485 /**
486 * For Search.
487 */
488 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
489 new BaseSearchIndexProvider() {
490 @Override
491 public List<SearchIndexableResource> getXmlResourcesToIndex(
492 Context context, boolean enabled) {
493 SearchIndexableResource sir = new SearchIndexableResource(context);
494 sir.xmlResId = R.xml.wireless_settings;
495 return Arrays.asList(sir);
496 }
497
498 @Override
499 public List<String> getNonIndexableKeys(Context context) {
500 final ArrayList<String> result = new ArrayList<String>();
501
502 result.add(KEY_TOGGLE_NSD);
503
Julia Reynolds00d19c72014-06-24 15:22:50 -0400504 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800505 final int myUserId = UserHandle.myUserId();
506 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
507 final boolean isRestrictedUser = um.getUserInfo(myUserId).isRestricted();
508 final boolean isWimaxEnabled = !isSecondaryUser
509 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700510 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400511 if (!isWimaxEnabled
512 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700513 result.add(KEY_WIMAX_SETTINGS);
514 }
515
516 if (isSecondaryUser) { // Disable VPN
517 result.add(KEY_VPN_SETTINGS);
518 }
519
520 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800521 final NfcManager manager = (NfcManager)
522 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700523 if (manager != null) {
524 NfcAdapter adapter = manager.getDefaultAdapter();
525 if (adapter == null) {
526 result.add(KEY_TOGGLE_NFC);
527 result.add(KEY_ANDROID_BEAM_SETTINGS);
528 }
529 }
530
531 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
532 if (isSecondaryUser || Utils.isWifiOnly(context)) {
533 result.add(KEY_MOBILE_NETWORK_SETTINGS);
534 result.add(KEY_MANAGE_MOBILE_PLAN);
535 }
536
537 // Remove Mobile Network Settings and Manage Mobile Plan
538 // if config_show_mobile_plan sets false.
539 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
540 R.bool.config_show_mobile_plan);
541 if (!isMobilePlanEnabled) {
542 result.add(KEY_MANAGE_MOBILE_PLAN);
543 }
544
545 // Remove SMS Application if the device does not support SMS
Yorke Lee5e108342014-06-19 22:21:41 +0000546 TelephonyManager tm =
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700547 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800548 if (!tm.isSmsCapable() || isRestrictedUser) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700549 result.add(KEY_SMS_APPLICATION);
550 }
551
552 final PackageManager pm = context.getPackageManager();
553
554 // Remove Airplane Mode settings if it's a stationary device such as a TV.
555 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
556 result.add(KEY_TOGGLE_AIRPLANE);
557 }
558
559 // proxy UI disabled until we have better app support
560 result.add(KEY_PROXY_SETTINGS);
561
562 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800563 ConnectivityManager cm = (ConnectivityManager)
564 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700565 if (isSecondaryUser || !cm.isTetheringSupported()) {
566 result.add(KEY_TETHER_SETTINGS);
567 }
568
569 // Enable link to CMAS app settings depending on the value in config.xml.
570 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
571 com.android.internal.R.bool.config_cellBroadcastAppLinks);
572 try {
573 if (isCellBroadcastAppLinkEnabled) {
574 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
575 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
576 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
577 }
578 }
579 } catch (IllegalArgumentException ignored) {
580 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
581 }
582 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
583 result.add(KEY_CELL_BROADCAST_SETTINGS);
584 }
585
586 return result;
587 }
588 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800589}