blob: 09d4a54a568f955d7f81dfa854532a1c008944d5 [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.CheckBoxPreference;
41import android.preference.Preference;
David Braun4e9f04d2013-09-16 13:45:42 -070042import android.preference.Preference.OnPreferenceChangeListener;
Amith Yamasanid7993472010-08-18 13:59:28 -070043import android.preference.PreferenceScreen;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070044import android.preference.SwitchPreference;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070045import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070046import android.provider.Settings;
Wink Saville5d5a2692013-06-29 07:54:13 -070047import android.telephony.TelephonyManager;
48import android.text.TextUtils;
49import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070050
51import com.android.internal.telephony.SmsApplication;
52import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070053import com.android.internal.telephony.TelephonyIntents;
54import com.android.internal.telephony.TelephonyProperties;
55import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070056import com.android.settings.search.BaseSearchIndexProvider;
57import com.android.settings.search.Indexable;
Gilles Debunnee78c1872011-06-20 15:00:07 -070058
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";
Nick Pellyad50ba02010-09-22 10:55:13 -070080
Chouting Zhang71cc49e2009-08-28 14:36:35 -050081 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
82 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080083
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080084 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070085 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070086 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050087 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070088 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050089
Wink Saville5d5a2692013-06-29 07:54:13 -070090 private ConnectivityManager mCm;
91 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070092 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040093 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070094
95 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
96 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
97
Jeff Davidsonb9558d92014-03-25 12:21:30 -070098 private AppListPreference mSmsApplicationPreference;
David Braun4e9f04d2013-09-16 13:45:42 -070099
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500100 /**
101 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800102 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500103 * preference click events.
104 */
105 @Override
106 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700107 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800108 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
109 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500110 // In ECM mode launch ECM app dialog
111 startActivityForResult(
112 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
113 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500114 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700115 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
116 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500117 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800118 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700119 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500120 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800121
Wink Saville5d5a2692013-06-29 07:54:13 -0700122 private String mManageMobilePlanMessage;
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)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400146 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
147 Intent.CATEGORY_APP_BROWSER);
148 intent.setData(Uri.parse(url));
149 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
150 Intent.FLAG_ACTIVITY_NEW_TASK);
151 try {
152 startActivity(intent);
153 } catch (ActivityNotFoundException e) {
154 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
155 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700156 } else {
157 // No provisioning URL
158 String operatorName = mTm.getSimOperatorName();
159 if (TextUtils.isEmpty(operatorName)) {
160 // Use NetworkOperatorName as second choice in case there is no
161 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
162 operatorName = mTm.getNetworkOperatorName();
163 if (TextUtils.isEmpty(operatorName)) {
164 mManageMobilePlanMessage = resources.getString(
165 R.string.mobile_unknown_sim_operator);
166 } else {
167 mManageMobilePlanMessage = resources.getString(
168 R.string.mobile_no_provisioning_url, operatorName);
169 }
170 } else {
171 mManageMobilePlanMessage = resources.getString(
172 R.string.mobile_no_provisioning_url, operatorName);
173 }
174 }
175 } else if (mTm.hasIccCard() == false) {
176 // No sim card
177 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
178 } else {
179 // NetworkInfo is null, there is no connection
180 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
181 }
182 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
183 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
184 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
185 }
186 }
187
David Braun4e9f04d2013-09-16 13:45:42 -0700188 private void initSmsApplicationSetting() {
189 log("initSmsApplicationSetting:");
190 Collection<SmsApplicationData> smsApplications =
191 SmsApplication.getApplicationCollection(getActivity());
192
193 // If the list is empty the dialog will be empty, but we will not crash.
194 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700195 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700196 int i = 0;
197 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700198 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700199 i++;
200 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700201 String defaultPackageName = null;
202 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
203 if (appName != null) {
204 defaultPackageName = appName.getPackageName();
205 }
206 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700207 }
208
Wink Saville5d5a2692013-06-29 07:54:13 -0700209 @Override
210 public Dialog onCreateDialog(int dialogId) {
211 log("onCreateDialog: dialogId=" + dialogId);
212 switch (dialogId) {
213 case MANAGE_MOBILE_PLAN_DIALOG_ID:
214 return new AlertDialog.Builder(getActivity())
215 .setMessage(mManageMobilePlanMessage)
216 .setCancelable(false)
217 .setPositiveButton(com.android.internal.R.string.ok,
218 new DialogInterface.OnClickListener() {
219 @Override
220 public void onClick(DialogInterface dialog, int id) {
221 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
222 mManageMobilePlanMessage = null;
223 }
224 })
225 .create();
226 }
227 return super.onCreateDialog(dialogId);
228 }
229
230 private void log(String s) {
231 Log.d(TAG, s);
232 }
233
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800234 public static boolean isRadioAllowed(Context context, String type) {
235 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
236 return true;
237 }
238 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700239 String toggleable = Settings.Global.getString(context.getContentResolver(),
240 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800241 return toggleable != null && toggleable.contains(type);
242 }
243
David Braun4e9f04d2013-09-16 13:45:42 -0700244 private boolean isSmsSupported() {
245 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500246 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700247 }
248
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800249 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700250 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800251 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700252 if (savedInstanceState != null) {
253 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
254 }
255 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
256
257 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
258 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700259 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400260 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800261
262 addPreferencesFromResource(R.xml.wireless_settings);
263
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700264 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
265
Amith Yamasanid7993472010-08-18 13:59:28 -0700266 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700267 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700268 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500269 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700270 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800271
Gilles Debunnee78c1872011-06-20 15:00:07 -0700272 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500273 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700274
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700275 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
David Braun4e9f04d2013-09-16 13:45:42 -0700276 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700277 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700278
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700279 // Remove NSD checkbox by default
280 getPreferenceScreen().removePreference(nsd);
281 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800282
Christopher Tate6a5929b2012-09-10 15:39:05 -0700283 String toggleable = Settings.Global.getString(activity.getContentResolver(),
284 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800285
tk.mun7c5c1652011-10-13 22:56:18 +0900286 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700287 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900288 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400289 if (!isWimaxEnabled
290 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900291 PreferenceScreen root = getPreferenceScreen();
292 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
293 if (ps != null) root.removePreference(ps);
294 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700295 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900296 && isWimaxEnabled) {
297 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
298 ps.setDependency(KEY_TOGGLE_AIRPLANE);
299 }
300 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400301
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800302 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700303 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800304 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
305 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400306 // Disable VPN.
307 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700308 removePreference(KEY_VPN_SETTINGS);
309 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400310
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800311 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700312 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700313 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700314 }
315
Nick Pelly9894d4a2011-08-09 07:10:16 -0700316 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700317 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700318 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500319 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700320 }
321
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700322 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500323 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
324 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700325 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500326 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700327 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800328 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800329
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400330 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
331 // if it's a wifi-only device, or if the settings are restricted.
332 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
333 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700334 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700335 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800336 }
Sungmin Choi24903152013-10-15 16:11:55 -0700337 // Remove Mobile Network Settings and Manage Mobile Plan
338 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700339 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700340 R.bool.config_show_mobile_plan);
341 if (!isMobilePlanEnabled) {
342 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
343 if (pref != null) {
344 removePreference(KEY_MANAGE_MOBILE_PLAN);
345 }
346 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800347
David Braun4e9f04d2013-09-16 13:45:42 -0700348 // Remove SMS Application if the device does not support SMS
349 if (!isSmsSupported()) {
350 removePreference(KEY_SMS_APPLICATION);
351 }
352
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900353 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700354 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900355 removePreference(KEY_TOGGLE_AIRPLANE);
356 }
357
Oscar Montemayor05411892010-08-03 16:56:09 -0700358 // Enable Proxy selector settings if allowed.
359 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700360 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700361 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800362 // proxy UI disabled until we have better app support
363 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700364 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
365
Amith Yamasani0f85c482011-02-23 17:19:11 -0800366 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700367 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700368 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400369 if (isSecondaryUser || !cm.isTetheringSupported()
370 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800371 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700372 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700373 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700374 p.setTitle(Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700375
376 // Grey out if provisioning is not available.
377 p.setEnabled(!TetherSettings
378 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800379 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700380
381 // Enable link to CMAS app settings depending on the value in config.xml.
382 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
383 com.android.internal.R.bool.config_cellBroadcastAppLinks);
384 try {
385 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700386 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700387 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
388 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
389 }
390 }
391 } catch (IllegalArgumentException ignored) {
392 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
393 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400394 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
395 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700396 PreferenceScreen root = getPreferenceScreen();
397 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
398 if (ps != null) root.removePreference(ps);
399 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800400 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800401
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800402 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700403 public void onStart() {
404 super.onStart();
405
406 initSmsApplicationSetting();
407 }
408
409 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700410 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800411 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700412
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800413 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700414 if (mNfcEnabler != null) {
415 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500416 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700417 if (mNsdEnabler != null) {
418 mNsdEnabler.resume();
419 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800420 }
Danica Chang32711b62010-08-10 18:41:29 -0700421
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800422 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700423 public void onSaveInstanceState(Bundle outState) {
424 super.onSaveInstanceState(outState);
425
426 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
427 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
428 }
429 }
430
431 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700432 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800433 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700434
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800435 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700436 if (mNfcEnabler != null) {
437 mNfcEnabler.pause();
438 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700439 if (mNsdEnabler != null) {
440 mNsdEnabler.pause();
441 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800442 }
Danica Chang32711b62010-08-10 18:41:29 -0700443
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500444 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700445 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800446 if (requestCode == REQUEST_CODE_EXIT_ECM) {
447 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500448 // Set Airplane mode based on the return value and checkbox state
449 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
450 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500451 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400452 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500453 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700454
455 @Override
456 protected int getHelpResource() {
457 return R.string.help_url_more_networks;
458 }
David Braun4e9f04d2013-09-16 13:45:42 -0700459
460 @Override
461 public boolean onPreferenceChange(Preference preference, Object newValue) {
462 if (preference == mSmsApplicationPreference && newValue != null) {
463 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700464 return true;
465 }
466 return false;
467 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700468
469 /**
470 * For Search.
471 */
472 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
473 new BaseSearchIndexProvider() {
474 @Override
475 public List<SearchIndexableResource> getXmlResourcesToIndex(
476 Context context, boolean enabled) {
477 SearchIndexableResource sir = new SearchIndexableResource(context);
478 sir.xmlResId = R.xml.wireless_settings;
479 return Arrays.asList(sir);
480 }
481
482 @Override
483 public List<String> getNonIndexableKeys(Context context) {
484 final ArrayList<String> result = new ArrayList<String>();
485
486 result.add(KEY_TOGGLE_NSD);
487
Julia Reynolds00d19c72014-06-24 15:22:50 -0400488 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700489 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
490 final boolean isWimaxEnabled = !isSecondaryUser && context.getResources().getBoolean(
491 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400492 if (!isWimaxEnabled
493 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700494 result.add(KEY_WIMAX_SETTINGS);
495 }
496
497 if (isSecondaryUser) { // Disable VPN
498 result.add(KEY_VPN_SETTINGS);
499 }
500
501 // Remove NFC if not available
502 final NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
503 if (manager != null) {
504 NfcAdapter adapter = manager.getDefaultAdapter();
505 if (adapter == null) {
506 result.add(KEY_TOGGLE_NFC);
507 result.add(KEY_ANDROID_BEAM_SETTINGS);
508 }
509 }
510
511 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
512 if (isSecondaryUser || Utils.isWifiOnly(context)) {
513 result.add(KEY_MOBILE_NETWORK_SETTINGS);
514 result.add(KEY_MANAGE_MOBILE_PLAN);
515 }
516
517 // Remove Mobile Network Settings and Manage Mobile Plan
518 // if config_show_mobile_plan sets false.
519 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
520 R.bool.config_show_mobile_plan);
521 if (!isMobilePlanEnabled) {
522 result.add(KEY_MANAGE_MOBILE_PLAN);
523 }
524
525 // Remove SMS Application if the device does not support SMS
Yorke Lee5e108342014-06-19 22:21:41 +0000526 TelephonyManager tm =
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700527 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
528 if (!tm.isSmsCapable()) {
529 result.add(KEY_SMS_APPLICATION);
530 }
531
532 final PackageManager pm = context.getPackageManager();
533
534 // Remove Airplane Mode settings if it's a stationary device such as a TV.
535 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
536 result.add(KEY_TOGGLE_AIRPLANE);
537 }
538
539 // proxy UI disabled until we have better app support
540 result.add(KEY_PROXY_SETTINGS);
541
542 // Disable Tethering if it's not allowed or if it's a wifi-only device
Yorke Lee5e108342014-06-19 22:21:41 +0000543 ConnectivityManager cm =
544 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700545 if (isSecondaryUser || !cm.isTetheringSupported()) {
546 result.add(KEY_TETHER_SETTINGS);
547 }
548
549 // Enable link to CMAS app settings depending on the value in config.xml.
550 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
551 com.android.internal.R.bool.config_cellBroadcastAppLinks);
552 try {
553 if (isCellBroadcastAppLinkEnabled) {
554 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
555 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
556 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
557 }
558 }
559 } catch (IllegalArgumentException ignored) {
560 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
561 }
562 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
563 result.add(KEY_CELL_BROADCAST_SETTINGS);
564 }
565
566 return result;
567 }
568 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800569}