blob: 9cb3d72f80a1297d84ef4ea64d9c65f435be5a07 [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;
David Braun4e9f04d2013-09-16 13:45:42 -070024import android.content.ComponentName;
Amith Yamasanid7993472010-08-18 13:59:28 -070025import android.content.Context;
Wink Saville5d5a2692013-06-29 07:54:13 -070026import android.content.DialogInterface;
Amith Yamasanid7993472010-08-18 13:59:28 -070027import android.content.Intent;
Irfan Sheriff167d7182011-09-07 14:51:11 -070028import android.content.pm.PackageManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070029import android.content.res.Resources;
Amith Yamasanid7993472010-08-18 13:59:28 -070030import android.net.ConnectivityManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070031import android.net.NetworkInfo;
Nick Pellya57eace2010-10-15 01:19:43 -070032import android.nfc.NfcAdapter;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070033import android.nfc.NfcManager;
Amith Yamasanid7993472010-08-18 13:59:28 -070034import android.os.Bundle;
Amith Yamasanid7993472010-08-18 13:59:28 -070035import android.os.SystemProperties;
Amith Yamasani9627a8e2012-09-23 12:54:14 -070036import android.os.UserHandle;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040037import android.os.UserManager;
Amith Yamasanid7993472010-08-18 13:59:28 -070038import android.preference.CheckBoxPreference;
39import android.preference.Preference;
David Braun4e9f04d2013-09-16 13:45:42 -070040import android.preference.Preference.OnPreferenceChangeListener;
Amith Yamasanid7993472010-08-18 13:59:28 -070041import android.preference.PreferenceScreen;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070042import android.preference.SwitchPreference;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070043import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070044import android.provider.Settings;
Wink Saville5d5a2692013-06-29 07:54:13 -070045import android.telephony.TelephonyManager;
46import android.text.TextUtils;
47import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070048
49import com.android.internal.telephony.SmsApplication;
50import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070051import com.android.internal.telephony.TelephonyIntents;
52import com.android.internal.telephony.TelephonyProperties;
53import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070054import com.android.settings.search.BaseSearchIndexProvider;
55import com.android.settings.search.Indexable;
Gilles Debunnee78c1872011-06-20 15:00:07 -070056
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070057import java.util.ArrayList;
58import java.util.Arrays;
David Braun4e9f04d2013-09-16 13:45:42 -070059import java.util.Collection;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070060import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070061
Julia Reynolds00d19c72014-06-24 15:22:50 -040062public class WirelessSettings extends SettingsPreferenceFragment
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070063 implements OnPreferenceChangeListener, Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070064 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080065
66 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070067 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090068 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050069 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070070 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080071 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070072 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080073 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070074 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
David Braun4e9f04d2013-09-16 13:45:42 -070075 private static final String KEY_SMS_APPLICATION = "sms_application";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070076 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070077 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070078
Chouting Zhang71cc49e2009-08-28 14:36:35 -050079 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
80 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080081
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070083 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070084 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050085 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070086 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050087
Wink Saville5d5a2692013-06-29 07:54:13 -070088 private ConnectivityManager mCm;
89 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070090 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040091 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070092
93 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
94 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
95
Jeff Davidsonb9558d92014-03-25 12:21:30 -070096 private AppListPreference mSmsApplicationPreference;
David Braun4e9f04d2013-09-16 13:45:42 -070097
Chouting Zhang71cc49e2009-08-28 14:36:35 -050098 /**
99 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800100 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500101 * preference click events.
102 */
103 @Override
104 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700105 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800106 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
107 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500108 // In ECM mode launch ECM app dialog
109 startActivityForResult(
110 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
111 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500112 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700113 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
114 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500115 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800116 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700117 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500118 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800119
Wink Saville5d5a2692013-06-29 07:54:13 -0700120 private String mManageMobilePlanMessage;
Wink Saville7bee4c22013-08-29 19:58:09 -0700121 private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION
122 = "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION";
Wink Saville5d5a2692013-06-29 07:54:13 -0700123 public void onManageMobilePlanClick() {
124 log("onManageMobilePlanClick:");
125 mManageMobilePlanMessage = null;
126 Resources resources = getActivity().getResources();
127
Wink Savillee24e5962013-08-28 14:26:27 -0700128 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700129 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700130 // Check for carrier apps that can handle provisioning first
131 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700132 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700133 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700134 if (carrierPackages != null && !carrierPackages.isEmpty()) {
135 if (carrierPackages.size() != 1) {
136 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
137 }
138 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700139 startActivity(provisioningIntent);
140 return;
141 }
142
Wink Saville5d5a2692013-06-29 07:54:13 -0700143 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700144 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700145 if (!TextUtils.isEmpty(url)) {
Wink Saville7bee4c22013-08-29 19:58:09 -0700146 Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
Wink Savillee24e5962013-08-28 14:26:27 -0700147 intent.putExtra("EXTRA_URL", url);
148 Context context = getActivity().getBaseContext();
149 context.sendBroadcast(intent);
Wink Saville5d5a2692013-06-29 07:54:13 -0700150 mManageMobilePlanMessage = null;
151 } else {
152 // No provisioning URL
153 String operatorName = mTm.getSimOperatorName();
154 if (TextUtils.isEmpty(operatorName)) {
155 // Use NetworkOperatorName as second choice in case there is no
156 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
157 operatorName = mTm.getNetworkOperatorName();
158 if (TextUtils.isEmpty(operatorName)) {
159 mManageMobilePlanMessage = resources.getString(
160 R.string.mobile_unknown_sim_operator);
161 } else {
162 mManageMobilePlanMessage = resources.getString(
163 R.string.mobile_no_provisioning_url, operatorName);
164 }
165 } else {
166 mManageMobilePlanMessage = resources.getString(
167 R.string.mobile_no_provisioning_url, operatorName);
168 }
169 }
170 } else if (mTm.hasIccCard() == false) {
171 // No sim card
172 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
173 } else {
174 // NetworkInfo is null, there is no connection
175 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
176 }
177 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
178 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
179 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
180 }
181 }
182
David Braun4e9f04d2013-09-16 13:45:42 -0700183 private void initSmsApplicationSetting() {
184 log("initSmsApplicationSetting:");
185 Collection<SmsApplicationData> smsApplications =
186 SmsApplication.getApplicationCollection(getActivity());
187
188 // If the list is empty the dialog will be empty, but we will not crash.
189 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700190 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700191 int i = 0;
192 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700193 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700194 i++;
195 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700196 String defaultPackageName = null;
197 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
198 if (appName != null) {
199 defaultPackageName = appName.getPackageName();
200 }
201 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700202 }
203
Wink Saville5d5a2692013-06-29 07:54:13 -0700204 @Override
205 public Dialog onCreateDialog(int dialogId) {
206 log("onCreateDialog: dialogId=" + dialogId);
207 switch (dialogId) {
208 case MANAGE_MOBILE_PLAN_DIALOG_ID:
209 return new AlertDialog.Builder(getActivity())
210 .setMessage(mManageMobilePlanMessage)
211 .setCancelable(false)
212 .setPositiveButton(com.android.internal.R.string.ok,
213 new DialogInterface.OnClickListener() {
214 @Override
215 public void onClick(DialogInterface dialog, int id) {
216 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
217 mManageMobilePlanMessage = null;
218 }
219 })
220 .create();
221 }
222 return super.onCreateDialog(dialogId);
223 }
224
225 private void log(String s) {
226 Log.d(TAG, s);
227 }
228
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800229 public static boolean isRadioAllowed(Context context, String type) {
230 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
231 return true;
232 }
233 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700234 String toggleable = Settings.Global.getString(context.getContentResolver(),
235 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800236 return toggleable != null && toggleable.contains(type);
237 }
238
David Braun4e9f04d2013-09-16 13:45:42 -0700239 private boolean isSmsSupported() {
240 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500241 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700242 }
243
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800244 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700245 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800246 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700247 if (savedInstanceState != null) {
248 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
249 }
250 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
251
252 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
253 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700254 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400255 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800256
257 addPreferencesFromResource(R.xml.wireless_settings);
258
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700259 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
260
Amith Yamasanid7993472010-08-18 13:59:28 -0700261 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700262 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700263 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500264 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700265 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800266
Gilles Debunnee78c1872011-06-20 15:00:07 -0700267 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500268 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700269
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700270 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
David Braun4e9f04d2013-09-16 13:45:42 -0700271 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700272 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700273
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700274 // Remove NSD checkbox by default
275 getPreferenceScreen().removePreference(nsd);
276 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800277
Christopher Tate6a5929b2012-09-10 15:39:05 -0700278 String toggleable = Settings.Global.getString(activity.getContentResolver(),
279 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800280
tk.mun7c5c1652011-10-13 22:56:18 +0900281 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700282 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900283 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400284 if (!isWimaxEnabled
285 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900286 PreferenceScreen root = getPreferenceScreen();
287 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
288 if (ps != null) root.removePreference(ps);
289 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700290 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900291 && isWimaxEnabled) {
292 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
293 ps.setDependency(KEY_TOGGLE_AIRPLANE);
294 }
295 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400296
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800297 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700298 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800299 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
300 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400301 // Disable VPN.
302 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700303 removePreference(KEY_VPN_SETTINGS);
304 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400305
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800306 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700307 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700308 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700309 }
310
Nick Pelly9894d4a2011-08-09 07:10:16 -0700311 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700312 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700313 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500314 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700315 }
316
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700317 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500318 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
319 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700320 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500321 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700322 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800323 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800324
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400325 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
326 // if it's a wifi-only device, or if the settings are restricted.
327 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
328 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700329 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700330 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800331 }
Sungmin Choi24903152013-10-15 16:11:55 -0700332 // Remove Mobile Network Settings and Manage Mobile Plan
333 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700334 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700335 R.bool.config_show_mobile_plan);
336 if (!isMobilePlanEnabled) {
337 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
338 if (pref != null) {
339 removePreference(KEY_MANAGE_MOBILE_PLAN);
340 }
341 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800342
David Braun4e9f04d2013-09-16 13:45:42 -0700343 // Remove SMS Application if the device does not support SMS
344 if (!isSmsSupported()) {
345 removePreference(KEY_SMS_APPLICATION);
346 }
347
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900348 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700349 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900350 removePreference(KEY_TOGGLE_AIRPLANE);
351 }
352
Oscar Montemayor05411892010-08-03 16:56:09 -0700353 // Enable Proxy selector settings if allowed.
354 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700355 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700356 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800357 // proxy UI disabled until we have better app support
358 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700359 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
360
Amith Yamasani0f85c482011-02-23 17:19:11 -0800361 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700362 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700363 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400364 if (isSecondaryUser || !cm.isTetheringSupported()
365 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800366 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700367 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700368 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700369 p.setTitle(Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700370
371 // Grey out if provisioning is not available.
372 p.setEnabled(!TetherSettings
373 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800374 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700375
376 // Enable link to CMAS app settings depending on the value in config.xml.
377 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
378 com.android.internal.R.bool.config_cellBroadcastAppLinks);
379 try {
380 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700381 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700382 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
383 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
384 }
385 }
386 } catch (IllegalArgumentException ignored) {
387 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
388 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400389 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
390 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700391 PreferenceScreen root = getPreferenceScreen();
392 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
393 if (ps != null) root.removePreference(ps);
394 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800395 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800396
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800397 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700398 public void onStart() {
399 super.onStart();
400
401 initSmsApplicationSetting();
402 }
403
404 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700405 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800406 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700407
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800408 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700409 if (mNfcEnabler != null) {
410 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500411 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700412 if (mNsdEnabler != null) {
413 mNsdEnabler.resume();
414 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800415 }
Danica Chang32711b62010-08-10 18:41:29 -0700416
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800417 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700418 public void onSaveInstanceState(Bundle outState) {
419 super.onSaveInstanceState(outState);
420
421 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
422 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
423 }
424 }
425
426 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700427 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800428 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700429
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800430 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700431 if (mNfcEnabler != null) {
432 mNfcEnabler.pause();
433 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700434 if (mNsdEnabler != null) {
435 mNsdEnabler.pause();
436 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800437 }
Danica Chang32711b62010-08-10 18:41:29 -0700438
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500439 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700440 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800441 if (requestCode == REQUEST_CODE_EXIT_ECM) {
442 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500443 // Set Airplane mode based on the return value and checkbox state
444 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
445 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500446 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400447 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500448 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700449
450 @Override
451 protected int getHelpResource() {
452 return R.string.help_url_more_networks;
453 }
David Braun4e9f04d2013-09-16 13:45:42 -0700454
455 @Override
456 public boolean onPreferenceChange(Preference preference, Object newValue) {
457 if (preference == mSmsApplicationPreference && newValue != null) {
458 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700459 return true;
460 }
461 return false;
462 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700463
464 /**
465 * For Search.
466 */
467 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
468 new BaseSearchIndexProvider() {
469 @Override
470 public List<SearchIndexableResource> getXmlResourcesToIndex(
471 Context context, boolean enabled) {
472 SearchIndexableResource sir = new SearchIndexableResource(context);
473 sir.xmlResId = R.xml.wireless_settings;
474 return Arrays.asList(sir);
475 }
476
477 @Override
478 public List<String> getNonIndexableKeys(Context context) {
479 final ArrayList<String> result = new ArrayList<String>();
480
481 result.add(KEY_TOGGLE_NSD);
482
Julia Reynolds00d19c72014-06-24 15:22:50 -0400483 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700484 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
485 final boolean isWimaxEnabled = !isSecondaryUser && context.getResources().getBoolean(
486 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400487 if (!isWimaxEnabled
488 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700489 result.add(KEY_WIMAX_SETTINGS);
490 }
491
492 if (isSecondaryUser) { // Disable VPN
493 result.add(KEY_VPN_SETTINGS);
494 }
495
496 // Remove NFC if not available
497 final NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
498 if (manager != null) {
499 NfcAdapter adapter = manager.getDefaultAdapter();
500 if (adapter == null) {
501 result.add(KEY_TOGGLE_NFC);
502 result.add(KEY_ANDROID_BEAM_SETTINGS);
503 }
504 }
505
506 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
507 if (isSecondaryUser || Utils.isWifiOnly(context)) {
508 result.add(KEY_MOBILE_NETWORK_SETTINGS);
509 result.add(KEY_MANAGE_MOBILE_PLAN);
510 }
511
512 // Remove Mobile Network Settings and Manage Mobile Plan
513 // if config_show_mobile_plan sets false.
514 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
515 R.bool.config_show_mobile_plan);
516 if (!isMobilePlanEnabled) {
517 result.add(KEY_MANAGE_MOBILE_PLAN);
518 }
519
520 // Remove SMS Application if the device does not support SMS
Yorke Lee5e108342014-06-19 22:21:41 +0000521 TelephonyManager tm =
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700522 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
523 if (!tm.isSmsCapable()) {
524 result.add(KEY_SMS_APPLICATION);
525 }
526
527 final PackageManager pm = context.getPackageManager();
528
529 // Remove Airplane Mode settings if it's a stationary device such as a TV.
530 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
531 result.add(KEY_TOGGLE_AIRPLANE);
532 }
533
534 // proxy UI disabled until we have better app support
535 result.add(KEY_PROXY_SETTINGS);
536
537 // Disable Tethering if it's not allowed or if it's a wifi-only device
Yorke Lee5e108342014-06-19 22:21:41 +0000538 ConnectivityManager cm =
539 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700540 if (isSecondaryUser || !cm.isTetheringSupported()) {
541 result.add(KEY_TETHER_SETTINGS);
542 }
543
544 // Enable link to CMAS app settings depending on the value in config.xml.
545 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
546 com.android.internal.R.bool.config_cellBroadcastAppLinks);
547 try {
548 if (isCellBroadcastAppLinkEnabled) {
549 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
550 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
551 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
552 }
553 }
554 } catch (IllegalArgumentException ignored) {
555 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
556 }
557 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
558 result.add(KEY_CELL_BROADCAST_SETTINGS);
559 }
560
561 return result;
562 }
563 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800564}