blob: b63a5a1a84c91bd68d33b77e7c55c93475985e0c [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);
132 provisioningIntent.addCategory(TelephonyIntents.CATEGORY_MCCMNC_PREFIX
133 + mTm.getSimOperator());
134 if (mPm.resolveActivity(provisioningIntent, 0 /* flags */) != null) {
135 startActivity(provisioningIntent);
136 return;
137 }
138
Wink Saville5d5a2692013-06-29 07:54:13 -0700139 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700140 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700141 if (!TextUtils.isEmpty(url)) {
Wink Saville7bee4c22013-08-29 19:58:09 -0700142 Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
Wink Savillee24e5962013-08-28 14:26:27 -0700143 intent.putExtra("EXTRA_URL", url);
144 Context context = getActivity().getBaseContext();
145 context.sendBroadcast(intent);
Wink Saville5d5a2692013-06-29 07:54:13 -0700146 mManageMobilePlanMessage = null;
147 } else {
148 // No provisioning URL
149 String operatorName = mTm.getSimOperatorName();
150 if (TextUtils.isEmpty(operatorName)) {
151 // Use NetworkOperatorName as second choice in case there is no
152 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
153 operatorName = mTm.getNetworkOperatorName();
154 if (TextUtils.isEmpty(operatorName)) {
155 mManageMobilePlanMessage = resources.getString(
156 R.string.mobile_unknown_sim_operator);
157 } else {
158 mManageMobilePlanMessage = resources.getString(
159 R.string.mobile_no_provisioning_url, operatorName);
160 }
161 } else {
162 mManageMobilePlanMessage = resources.getString(
163 R.string.mobile_no_provisioning_url, operatorName);
164 }
165 }
166 } else if (mTm.hasIccCard() == false) {
167 // No sim card
168 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
169 } else {
170 // NetworkInfo is null, there is no connection
171 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
172 }
173 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
174 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
175 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
176 }
177 }
178
David Braun4e9f04d2013-09-16 13:45:42 -0700179 private void initSmsApplicationSetting() {
180 log("initSmsApplicationSetting:");
181 Collection<SmsApplicationData> smsApplications =
182 SmsApplication.getApplicationCollection(getActivity());
183
184 // If the list is empty the dialog will be empty, but we will not crash.
185 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700186 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700187 int i = 0;
188 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700189 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700190 i++;
191 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700192 String defaultPackageName = null;
193 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
194 if (appName != null) {
195 defaultPackageName = appName.getPackageName();
196 }
197 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700198 }
199
Wink Saville5d5a2692013-06-29 07:54:13 -0700200 @Override
201 public Dialog onCreateDialog(int dialogId) {
202 log("onCreateDialog: dialogId=" + dialogId);
203 switch (dialogId) {
204 case MANAGE_MOBILE_PLAN_DIALOG_ID:
205 return new AlertDialog.Builder(getActivity())
206 .setMessage(mManageMobilePlanMessage)
207 .setCancelable(false)
208 .setPositiveButton(com.android.internal.R.string.ok,
209 new DialogInterface.OnClickListener() {
210 @Override
211 public void onClick(DialogInterface dialog, int id) {
212 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
213 mManageMobilePlanMessage = null;
214 }
215 })
216 .create();
217 }
218 return super.onCreateDialog(dialogId);
219 }
220
221 private void log(String s) {
222 Log.d(TAG, s);
223 }
224
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800225 public static boolean isRadioAllowed(Context context, String type) {
226 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
227 return true;
228 }
229 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700230 String toggleable = Settings.Global.getString(context.getContentResolver(),
231 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800232 return toggleable != null && toggleable.contains(type);
233 }
234
David Braun4e9f04d2013-09-16 13:45:42 -0700235 private boolean isSmsSupported() {
236 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500237 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700238 }
239
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800240 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700241 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800242 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700243 if (savedInstanceState != null) {
244 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
245 }
246 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
247
248 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
249 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700250 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400251 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800252
253 addPreferencesFromResource(R.xml.wireless_settings);
254
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700255 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
256
Amith Yamasanid7993472010-08-18 13:59:28 -0700257 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700258 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Nick Pellyad50ba02010-09-22 10:55:13 -0700259 CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500260 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700261 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800262
Gilles Debunnee78c1872011-06-20 15:00:07 -0700263 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500264 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700265
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700266 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
David Braun4e9f04d2013-09-16 13:45:42 -0700267 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700268 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700269
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700270 // Remove NSD checkbox by default
271 getPreferenceScreen().removePreference(nsd);
272 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800273
Christopher Tate6a5929b2012-09-10 15:39:05 -0700274 String toggleable = Settings.Global.getString(activity.getContentResolver(),
275 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800276
tk.mun7c5c1652011-10-13 22:56:18 +0900277 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700278 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900279 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400280 if (!isWimaxEnabled
281 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900282 PreferenceScreen root = getPreferenceScreen();
283 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
284 if (ps != null) root.removePreference(ps);
285 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700286 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900287 && isWimaxEnabled) {
288 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
289 ps.setDependency(KEY_TOGGLE_AIRPLANE);
290 }
291 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400292
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800293 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700294 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800295 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
296 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400297 // Disable VPN.
298 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700299 removePreference(KEY_VPN_SETTINGS);
300 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400301
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800302 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700303 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700304 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700305 }
306
Nick Pelly9894d4a2011-08-09 07:10:16 -0700307 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700308 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700309 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500310 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700311 }
312
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700313 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500314 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
315 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700316 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500317 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700318 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800319 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800320
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400321 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
322 // if it's a wifi-only device, or if the settings are restricted.
323 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
324 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700325 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700326 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800327 }
Sungmin Choi24903152013-10-15 16:11:55 -0700328 // Remove Mobile Network Settings and Manage Mobile Plan
329 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700330 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700331 R.bool.config_show_mobile_plan);
332 if (!isMobilePlanEnabled) {
333 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
334 if (pref != null) {
335 removePreference(KEY_MANAGE_MOBILE_PLAN);
336 }
337 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800338
David Braun4e9f04d2013-09-16 13:45:42 -0700339 // Remove SMS Application if the device does not support SMS
340 if (!isSmsSupported()) {
341 removePreference(KEY_SMS_APPLICATION);
342 }
343
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900344 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700345 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900346 removePreference(KEY_TOGGLE_AIRPLANE);
347 }
348
Oscar Montemayor05411892010-08-03 16:56:09 -0700349 // Enable Proxy selector settings if allowed.
350 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700351 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700352 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800353 // proxy UI disabled until we have better app support
354 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700355 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
356
Amith Yamasani0f85c482011-02-23 17:19:11 -0800357 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700358 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700359 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400360 if (isSecondaryUser || !cm.isTetheringSupported()
361 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800362 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700363 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700364 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700365 p.setTitle(Utils.getTetheringLabel(cm));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800366 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700367
368 // Enable link to CMAS app settings depending on the value in config.xml.
369 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
370 com.android.internal.R.bool.config_cellBroadcastAppLinks);
371 try {
372 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700373 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700374 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
375 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
376 }
377 }
378 } catch (IllegalArgumentException ignored) {
379 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
380 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400381 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
382 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700383 PreferenceScreen root = getPreferenceScreen();
384 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
385 if (ps != null) root.removePreference(ps);
386 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800387 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800388
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800389 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700390 public void onStart() {
391 super.onStart();
392
393 initSmsApplicationSetting();
394 }
395
396 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700397 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800398 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700399
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800400 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700401 if (mNfcEnabler != null) {
402 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500403 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700404 if (mNsdEnabler != null) {
405 mNsdEnabler.resume();
406 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800407 }
Danica Chang32711b62010-08-10 18:41:29 -0700408
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800409 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700410 public void onSaveInstanceState(Bundle outState) {
411 super.onSaveInstanceState(outState);
412
413 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
414 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
415 }
416 }
417
418 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700419 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800420 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700421
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800422 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700423 if (mNfcEnabler != null) {
424 mNfcEnabler.pause();
425 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700426 if (mNsdEnabler != null) {
427 mNsdEnabler.pause();
428 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800429 }
Danica Chang32711b62010-08-10 18:41:29 -0700430
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500431 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700432 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800433 if (requestCode == REQUEST_CODE_EXIT_ECM) {
434 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500435 // Set Airplane mode based on the return value and checkbox state
436 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
437 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500438 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400439 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500440 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700441
442 @Override
443 protected int getHelpResource() {
444 return R.string.help_url_more_networks;
445 }
David Braun4e9f04d2013-09-16 13:45:42 -0700446
447 @Override
448 public boolean onPreferenceChange(Preference preference, Object newValue) {
449 if (preference == mSmsApplicationPreference && newValue != null) {
450 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700451 return true;
452 }
453 return false;
454 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700455
456 /**
457 * For Search.
458 */
459 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
460 new BaseSearchIndexProvider() {
461 @Override
462 public List<SearchIndexableResource> getXmlResourcesToIndex(
463 Context context, boolean enabled) {
464 SearchIndexableResource sir = new SearchIndexableResource(context);
465 sir.xmlResId = R.xml.wireless_settings;
466 return Arrays.asList(sir);
467 }
468
469 @Override
470 public List<String> getNonIndexableKeys(Context context) {
471 final ArrayList<String> result = new ArrayList<String>();
472
473 result.add(KEY_TOGGLE_NSD);
474
Julia Reynolds00d19c72014-06-24 15:22:50 -0400475 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700476 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
477 final boolean isWimaxEnabled = !isSecondaryUser && context.getResources().getBoolean(
478 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400479 if (!isWimaxEnabled
480 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700481 result.add(KEY_WIMAX_SETTINGS);
482 }
483
484 if (isSecondaryUser) { // Disable VPN
485 result.add(KEY_VPN_SETTINGS);
486 }
487
488 // Remove NFC if not available
489 final NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
490 if (manager != null) {
491 NfcAdapter adapter = manager.getDefaultAdapter();
492 if (adapter == null) {
493 result.add(KEY_TOGGLE_NFC);
494 result.add(KEY_ANDROID_BEAM_SETTINGS);
495 }
496 }
497
498 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
499 if (isSecondaryUser || Utils.isWifiOnly(context)) {
500 result.add(KEY_MOBILE_NETWORK_SETTINGS);
501 result.add(KEY_MANAGE_MOBILE_PLAN);
502 }
503
504 // Remove Mobile Network Settings and Manage Mobile Plan
505 // if config_show_mobile_plan sets false.
506 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
507 R.bool.config_show_mobile_plan);
508 if (!isMobilePlanEnabled) {
509 result.add(KEY_MANAGE_MOBILE_PLAN);
510 }
511
512 // Remove SMS Application if the device does not support SMS
Yorke Lee5e108342014-06-19 22:21:41 +0000513 TelephonyManager tm =
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700514 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
515 if (!tm.isSmsCapable()) {
516 result.add(KEY_SMS_APPLICATION);
517 }
518
519 final PackageManager pm = context.getPackageManager();
520
521 // Remove Airplane Mode settings if it's a stationary device such as a TV.
522 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
523 result.add(KEY_TOGGLE_AIRPLANE);
524 }
525
526 // proxy UI disabled until we have better app support
527 result.add(KEY_PROXY_SETTINGS);
528
529 // Disable Tethering if it's not allowed or if it's a wifi-only device
Yorke Lee5e108342014-06-19 22:21:41 +0000530 ConnectivityManager cm =
531 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700532 if (isSecondaryUser || !cm.isTetheringSupported()) {
533 result.add(KEY_TETHER_SETTINGS);
534 }
535
536 // Enable link to CMAS app settings depending on the value in config.xml.
537 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
538 com.android.internal.R.bool.config_cellBroadcastAppLinks);
539 try {
540 if (isCellBroadcastAppLinkEnabled) {
541 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
542 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
543 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
544 }
545 }
546 } catch (IllegalArgumentException ignored) {
547 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
548 }
549 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
550 result.add(KEY_CELL_BROADCAST_SETTINGS);
551 }
552
553 return result;
554 }
555 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800556}