blob: 17234e9ef047f9375cc845e9510985bb9a2d35e4 [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 Megliodba577f2014-06-06 16:31:45 -070042import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070043import android.provider.Settings;
Yorke Leed4720d92014-06-02 14:52:17 -070044import android.telecomm.PhoneApplication;
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
62public class WirelessSettings extends RestrictedSettingsFragment
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";
Yorke Leed4720d92014-06-02 14:52:17 -070078 private static final String KEY_PHONE_APPLICATION = "phone_application";
Nick Pellyad50ba02010-09-22 10:55:13 -070079
Chouting Zhang71cc49e2009-08-28 14:36:35 -050080 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
81 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080082
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080083 private AirplaneModeEnabler mAirplaneModeEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050084 private CheckBoxPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070085 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050086 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070087 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050088
Wink Saville5d5a2692013-06-29 07:54:13 -070089 private ConnectivityManager mCm;
90 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070091 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040092 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070093
94 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
95 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
96
Jeff Davidsonb9558d92014-03-25 12:21:30 -070097 private AppListPreference mSmsApplicationPreference;
Yorke Leed4720d92014-06-02 14:52:17 -070098 private AppListPreference mDialerApplicationPreference;
David Braun4e9f04d2013-09-16 13:45:42 -070099
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400100 public WirelessSettings() {
101 super(null);
102 }
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500103 /**
104 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800105 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500106 * preference click events.
107 */
108 @Override
109 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Geoffrey Borggaard6e1102d2013-08-07 14:57:43 -0400110 if (ensurePinRestrictedPreference(preference)) {
111 return true;
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400112 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700113 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800114 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
115 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500116 // In ECM mode launch ECM app dialog
117 startActivityForResult(
118 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
119 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500120 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700121 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
122 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500123 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800124 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700125 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500126 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800127
Wink Saville5d5a2692013-06-29 07:54:13 -0700128 private String mManageMobilePlanMessage;
Wink Saville7bee4c22013-08-29 19:58:09 -0700129 private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION
130 = "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION";
Wink Saville5d5a2692013-06-29 07:54:13 -0700131 public void onManageMobilePlanClick() {
132 log("onManageMobilePlanClick:");
133 mManageMobilePlanMessage = null;
134 Resources resources = getActivity().getResources();
135
Wink Savillee24e5962013-08-28 14:26:27 -0700136 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700137 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700138 // Check for carrier apps that can handle provisioning first
139 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
140 provisioningIntent.addCategory(TelephonyIntents.CATEGORY_MCCMNC_PREFIX
141 + mTm.getSimOperator());
142 if (mPm.resolveActivity(provisioningIntent, 0 /* flags */) != null) {
143 startActivity(provisioningIntent);
144 return;
145 }
146
Wink Saville5d5a2692013-06-29 07:54:13 -0700147 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700148 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700149 if (!TextUtils.isEmpty(url)) {
Wink Saville7bee4c22013-08-29 19:58:09 -0700150 Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
Wink Savillee24e5962013-08-28 14:26:27 -0700151 intent.putExtra("EXTRA_URL", url);
152 Context context = getActivity().getBaseContext();
153 context.sendBroadcast(intent);
Wink Saville5d5a2692013-06-29 07:54:13 -0700154 mManageMobilePlanMessage = null;
155 } else {
156 // No provisioning URL
157 String operatorName = mTm.getSimOperatorName();
158 if (TextUtils.isEmpty(operatorName)) {
159 // Use NetworkOperatorName as second choice in case there is no
160 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
161 operatorName = mTm.getNetworkOperatorName();
162 if (TextUtils.isEmpty(operatorName)) {
163 mManageMobilePlanMessage = resources.getString(
164 R.string.mobile_unknown_sim_operator);
165 } else {
166 mManageMobilePlanMessage = resources.getString(
167 R.string.mobile_no_provisioning_url, operatorName);
168 }
169 } else {
170 mManageMobilePlanMessage = resources.getString(
171 R.string.mobile_no_provisioning_url, operatorName);
172 }
173 }
174 } else if (mTm.hasIccCard() == false) {
175 // No sim card
176 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
177 } else {
178 // NetworkInfo is null, there is no connection
179 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
180 }
181 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
182 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
183 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
184 }
185 }
186
David Braun4e9f04d2013-09-16 13:45:42 -0700187 private void initSmsApplicationSetting() {
188 log("initSmsApplicationSetting:");
189 Collection<SmsApplicationData> smsApplications =
190 SmsApplication.getApplicationCollection(getActivity());
191
192 // If the list is empty the dialog will be empty, but we will not crash.
193 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700194 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700195 int i = 0;
196 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700197 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700198 i++;
199 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700200 String defaultPackageName = null;
201 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
202 if (appName != null) {
203 defaultPackageName = appName.getPackageName();
204 }
205 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700206 }
207
Yorke Leed4720d92014-06-02 14:52:17 -0700208 private void initDialerApplicationSetting() {
209 log("initDialerApplicationSetting:");
210 final List<ComponentName> dialers =
211 PhoneApplication.getInstalledPhoneApplications(getActivity());
212
213 final int count = dialers.size();
214 final String[] packageNames = new String[count];
215 for (int i = 0; i < count; i++) {
216 packageNames[i] = dialers.get(i).getPackageName();
217 }
218 String defaultPackageName = null;
219 final ComponentName appName = PhoneApplication.getDefaultPhoneApplication(getActivity());
220 if (appName != null) {
221 defaultPackageName = appName.getPackageName();
222 }
223 mDialerApplicationPreference.setPackageNames(packageNames, defaultPackageName);
224 }
225
Wink Saville5d5a2692013-06-29 07:54:13 -0700226 @Override
227 public Dialog onCreateDialog(int dialogId) {
228 log("onCreateDialog: dialogId=" + dialogId);
229 switch (dialogId) {
230 case MANAGE_MOBILE_PLAN_DIALOG_ID:
231 return new AlertDialog.Builder(getActivity())
232 .setMessage(mManageMobilePlanMessage)
233 .setCancelable(false)
234 .setPositiveButton(com.android.internal.R.string.ok,
235 new DialogInterface.OnClickListener() {
236 @Override
237 public void onClick(DialogInterface dialog, int id) {
238 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
239 mManageMobilePlanMessage = null;
240 }
241 })
242 .create();
243 }
244 return super.onCreateDialog(dialogId);
245 }
246
247 private void log(String s) {
248 Log.d(TAG, s);
249 }
250
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800251 public static boolean isRadioAllowed(Context context, String type) {
252 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
253 return true;
254 }
255 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700256 String toggleable = Settings.Global.getString(context.getContentResolver(),
257 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800258 return toggleable != null && toggleable.contains(type);
259 }
260
David Braun4e9f04d2013-09-16 13:45:42 -0700261 private boolean isSmsSupported() {
262 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500263 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700264 }
265
Yorke Leed4720d92014-06-02 14:52:17 -0700266 private boolean isVoiceCapable() {
267 return mTm.isVoiceCapable();
268 }
269
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800270 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700271 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800272 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700273 if (savedInstanceState != null) {
274 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
275 }
276 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
277
278 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
279 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700280 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400281 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800282
283 addPreferencesFromResource(R.xml.wireless_settings);
284
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700285 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
286
Amith Yamasanid7993472010-08-18 13:59:28 -0700287 final Activity activity = getActivity();
Gilles Debunnee78c1872011-06-20 15:00:07 -0700288 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Nick Pellyad50ba02010-09-22 10:55:13 -0700289 CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500290 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700291 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800292
Gilles Debunnee78c1872011-06-20 15:00:07 -0700293 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500294 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700295
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700296 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
David Braun4e9f04d2013-09-16 13:45:42 -0700297 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700298 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700299
Yorke Leed4720d92014-06-02 14:52:17 -0700300 mDialerApplicationPreference = (AppListPreference) findPreference(KEY_PHONE_APPLICATION);
301 mDialerApplicationPreference.setOnPreferenceChangeListener(this);
302 initDialerApplicationSetting();
303
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700304 // Remove NSD checkbox by default
305 getPreferenceScreen().removePreference(nsd);
306 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800307
Christopher Tate6a5929b2012-09-10 15:39:05 -0700308 String toggleable = Settings.Global.getString(activity.getContentResolver(),
309 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800310
tk.mun7c5c1652011-10-13 22:56:18 +0900311 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700312 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900313 com.android.internal.R.bool.config_wimaxEnabled);
314 if (!isWimaxEnabled) {
315 PreferenceScreen root = getPreferenceScreen();
316 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
317 if (ps != null) root.removePreference(ps);
318 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700319 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900320 && isWimaxEnabled) {
321 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
322 ps.setDependency(KEY_TOGGLE_AIRPLANE);
323 }
324 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400325 protectByRestrictions(KEY_WIMAX_SETTINGS);
326
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800327 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700328 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800329 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
330 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400331 // Disable VPN.
332 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700333 removePreference(KEY_VPN_SETTINGS);
334 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400335
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800336 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700337 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700338 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700339 }
340
Nick Pelly9894d4a2011-08-09 07:10:16 -0700341 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700342 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700343 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500344 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700345 }
346
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700347 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500348 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
349 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700350 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500351 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700352 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800353 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800354
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400355 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
356 // if it's a wifi-only device, or if the settings are restricted.
357 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
358 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700359 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700360 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800361 }
Sungmin Choi24903152013-10-15 16:11:55 -0700362 // Remove Mobile Network Settings and Manage Mobile Plan
363 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700364 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700365 R.bool.config_show_mobile_plan);
366 if (!isMobilePlanEnabled) {
367 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
368 if (pref != null) {
369 removePreference(KEY_MANAGE_MOBILE_PLAN);
370 }
371 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800372
David Braun4e9f04d2013-09-16 13:45:42 -0700373 // Remove SMS Application if the device does not support SMS
374 if (!isSmsSupported()) {
375 removePreference(KEY_SMS_APPLICATION);
376 }
377
Yorke Leed4720d92014-06-02 14:52:17 -0700378 // Remove Dialer setting if the device does not support voice
379 if (!isVoiceCapable()) {
380 removePreference(KEY_PHONE_APPLICATION);
381 }
382
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900383 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700384 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900385 removePreference(KEY_TOGGLE_AIRPLANE);
386 }
387
Oscar Montemayor05411892010-08-03 16:56:09 -0700388 // Enable Proxy selector settings if allowed.
389 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700390 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700391 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800392 // proxy UI disabled until we have better app support
393 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700394 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
395
Amith Yamasani0f85c482011-02-23 17:19:11 -0800396 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700397 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700398 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400399 if (isSecondaryUser || !cm.isTetheringSupported()
400 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800401 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700402 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700403 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700404 p.setTitle(Utils.getTetheringLabel(cm));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800405 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700406
407 // Enable link to CMAS app settings depending on the value in config.xml.
408 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
409 com.android.internal.R.bool.config_cellBroadcastAppLinks);
410 try {
411 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700412 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700413 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
414 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
415 }
416 }
417 } catch (IllegalArgumentException ignored) {
418 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
419 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400420 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
421 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700422 PreferenceScreen root = getPreferenceScreen();
423 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
424 if (ps != null) root.removePreference(ps);
425 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800426 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800427
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800428 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700429 public void onStart() {
430 super.onStart();
431
432 initSmsApplicationSetting();
433 }
434
435 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700436 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800437 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700438
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800439 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700440 if (mNfcEnabler != null) {
441 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500442 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700443 if (mNsdEnabler != null) {
444 mNsdEnabler.resume();
445 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800446 }
Danica Chang32711b62010-08-10 18:41:29 -0700447
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800448 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700449 public void onSaveInstanceState(Bundle outState) {
450 super.onSaveInstanceState(outState);
451
452 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
453 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
454 }
455 }
456
457 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700458 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800459 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700460
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800461 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700462 if (mNfcEnabler != null) {
463 mNfcEnabler.pause();
464 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700465 if (mNsdEnabler != null) {
466 mNsdEnabler.pause();
467 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800468 }
Danica Chang32711b62010-08-10 18:41:29 -0700469
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500470 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700471 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800472 if (requestCode == REQUEST_CODE_EXIT_ECM) {
473 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500474 // Set Airplane mode based on the return value and checkbox state
475 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
476 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500477 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400478 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500479 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700480
481 @Override
482 protected int getHelpResource() {
483 return R.string.help_url_more_networks;
484 }
David Braun4e9f04d2013-09-16 13:45:42 -0700485
486 @Override
487 public boolean onPreferenceChange(Preference preference, Object newValue) {
488 if (preference == mSmsApplicationPreference && newValue != null) {
489 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700490 return true;
Yorke Leed4720d92014-06-02 14:52:17 -0700491 } else if (preference == mDialerApplicationPreference && newValue != null) {
492 PhoneApplication.setDefaultPhoneApplication(newValue.toString(), getActivity());
493 return true;
David Braun4e9f04d2013-09-16 13:45:42 -0700494 }
495 return false;
496 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700497
498 /**
499 * For Search.
500 */
501 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
502 new BaseSearchIndexProvider() {
503 @Override
504 public List<SearchIndexableResource> getXmlResourcesToIndex(
505 Context context, boolean enabled) {
506 SearchIndexableResource sir = new SearchIndexableResource(context);
507 sir.xmlResId = R.xml.wireless_settings;
508 return Arrays.asList(sir);
509 }
510
511 @Override
512 public List<String> getNonIndexableKeys(Context context) {
513 final ArrayList<String> result = new ArrayList<String>();
514
515 result.add(KEY_TOGGLE_NSD);
516
517 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
518 final boolean isWimaxEnabled = !isSecondaryUser && context.getResources().getBoolean(
519 com.android.internal.R.bool.config_wimaxEnabled);
520 if (!isWimaxEnabled) {
521 result.add(KEY_WIMAX_SETTINGS);
522 }
523
524 if (isSecondaryUser) { // Disable VPN
525 result.add(KEY_VPN_SETTINGS);
526 }
527
528 // Remove NFC if not available
529 final NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
530 if (manager != null) {
531 NfcAdapter adapter = manager.getDefaultAdapter();
532 if (adapter == null) {
533 result.add(KEY_TOGGLE_NFC);
534 result.add(KEY_ANDROID_BEAM_SETTINGS);
535 }
536 }
537
538 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
539 if (isSecondaryUser || Utils.isWifiOnly(context)) {
540 result.add(KEY_MOBILE_NETWORK_SETTINGS);
541 result.add(KEY_MANAGE_MOBILE_PLAN);
542 }
543
544 // Remove Mobile Network Settings and Manage Mobile Plan
545 // if config_show_mobile_plan sets false.
546 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
547 R.bool.config_show_mobile_plan);
548 if (!isMobilePlanEnabled) {
549 result.add(KEY_MANAGE_MOBILE_PLAN);
550 }
551
552 // Remove SMS Application if the device does not support SMS
Yorke Leed4720d92014-06-02 14:52:17 -0700553 final TelephonyManager tm =
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700554 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
555 if (!tm.isSmsCapable()) {
556 result.add(KEY_SMS_APPLICATION);
557 }
558
Yorke Leed4720d92014-06-02 14:52:17 -0700559 // Remove Phone Application if the device is not voice capable
560 if (!tm.isVoiceCapable()) {
561 result.add(KEY_PHONE_APPLICATION);
562 }
563
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700564 final PackageManager pm = context.getPackageManager();
565
566 // Remove Airplane Mode settings if it's a stationary device such as a TV.
567 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
568 result.add(KEY_TOGGLE_AIRPLANE);
569 }
570
571 // proxy UI disabled until we have better app support
572 result.add(KEY_PROXY_SETTINGS);
573
574 // Disable Tethering if it's not allowed or if it's a wifi-only device
Yorke Leed4720d92014-06-02 14:52:17 -0700575 final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(
576 Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700577 if (isSecondaryUser || !cm.isTetheringSupported()) {
578 result.add(KEY_TETHER_SETTINGS);
579 }
580
581 // Enable link to CMAS app settings depending on the value in config.xml.
582 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
583 com.android.internal.R.bool.config_cellBroadcastAppLinks);
584 try {
585 if (isCellBroadcastAppLinkEnabled) {
586 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
587 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
588 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
589 }
590 }
591 } catch (IllegalArgumentException ignored) {
592 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
593 }
594 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
595 result.add(KEY_CELL_BROADCAST_SETTINGS);
596 }
597
598 return result;
599 }
600 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800601}