blob: 9152870c51930788e346d93b8afe34e7018451c0 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
Chia-chi Yeh4e142112009-12-25 14:48:46 +08002 * Copyright (C) 2009 The Android Open Source Project
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -040019
Amith Yamasanid7993472010-08-18 13:59:28 -070020import android.app.Activity;
Wink Saville5d5a2692013-06-29 07:54:13 -070021import android.app.AlertDialog;
22import android.app.Dialog;
Amith Yamasanid7993472010-08-18 13:59:28 -070023import android.app.admin.DevicePolicyManager;
Paul Jensend96c5fc2014-10-17 22:09:37 -040024import android.content.ActivityNotFoundException;
David Braun4e9f04d2013-09-16 13:45:42 -070025import android.content.ComponentName;
Amith Yamasanid7993472010-08-18 13:59:28 -070026import android.content.Context;
Wink Saville5d5a2692013-06-29 07:54:13 -070027import android.content.DialogInterface;
Amith Yamasanid7993472010-08-18 13:59:28 -070028import android.content.Intent;
Irfan Sheriff167d7182011-09-07 14:51:11 -070029import android.content.pm.PackageManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070030import android.content.res.Resources;
Amith Yamasanid7993472010-08-18 13:59:28 -070031import android.net.ConnectivityManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070032import android.net.NetworkInfo;
Paul Jensend96c5fc2014-10-17 22:09:37 -040033import android.net.Uri;
Nick Pellya57eace2010-10-15 01:19:43 -070034import android.nfc.NfcAdapter;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070035import android.nfc.NfcManager;
Amith Yamasanid7993472010-08-18 13:59:28 -070036import android.os.Bundle;
Amith Yamasanid7993472010-08-18 13:59:28 -070037import android.os.SystemProperties;
Amith Yamasani9627a8e2012-09-23 12:54:14 -070038import android.os.UserHandle;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040039import android.os.UserManager;
Amith Yamasanid7993472010-08-18 13:59:28 -070040import android.preference.Preference;
David Braun4e9f04d2013-09-16 13:45:42 -070041import android.preference.Preference.OnPreferenceChangeListener;
Amith Yamasanid7993472010-08-18 13:59:28 -070042import android.preference.PreferenceScreen;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070043import android.preference.SwitchPreference;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070044import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070045import android.provider.Settings;
Wink Saville5d5a2692013-06-29 07:54:13 -070046import android.telephony.TelephonyManager;
47import android.text.TextUtils;
48import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070049
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080050import com.android.ims.ImsConfig;
51import com.android.ims.ImsManager;
David Braun4e9f04d2013-09-16 13:45:42 -070052import com.android.internal.telephony.SmsApplication;
53import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070054import com.android.internal.telephony.TelephonyIntents;
55import com.android.internal.telephony.TelephonyProperties;
56import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070057import com.android.settings.search.BaseSearchIndexProvider;
58import com.android.settings.search.Indexable;
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080059import com.android.settings.WifiCallingSettings;
Gilles Debunnee78c1872011-06-20 15:00:07 -070060
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070061import java.util.ArrayList;
62import java.util.Arrays;
David Braun4e9f04d2013-09-16 13:45:42 -070063import java.util.Collection;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070064import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070065
Julia Reynolds00d19c72014-06-24 15:22:50 -040066public class WirelessSettings extends SettingsPreferenceFragment
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070067 implements OnPreferenceChangeListener, Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070068 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080069
70 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070071 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090072 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050073 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070074 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080075 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070076 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080077 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070078 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
David Braun4e9f04d2013-09-16 13:45:42 -070079 private static final String KEY_SMS_APPLICATION = "sms_application";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070080 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070081 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080082 private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070083
Chouting Zhang71cc49e2009-08-28 14:36:35 -050084 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
85 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080086
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080087 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070088 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070089 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050090 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070091 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050092
Wink Saville5d5a2692013-06-29 07:54:13 -070093 private ConnectivityManager mCm;
94 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070095 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040096 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070097
98 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
99 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
100
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700101 private AppListPreference mSmsApplicationPreference;
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800102 private PreferenceScreen mButtonWfc;
David Braun4e9f04d2013-09-16 13:45:42 -0700103
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500104 /**
105 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800106 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500107 * preference click events.
108 */
109 @Override
110 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700111 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800112 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
113 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500114 // In ECM mode launch ECM app dialog
115 startActivityForResult(
116 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
117 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500118 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700119 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
120 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500121 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800122 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700123 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500124 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800125
Wink Saville5d5a2692013-06-29 07:54:13 -0700126 private String mManageMobilePlanMessage;
Wink Saville5d5a2692013-06-29 07:54:13 -0700127 public void onManageMobilePlanClick() {
128 log("onManageMobilePlanClick:");
129 mManageMobilePlanMessage = null;
130 Resources resources = getActivity().getResources();
131
Wink Savillee24e5962013-08-28 14:26:27 -0700132 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700133 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700134 // Check for carrier apps that can handle provisioning first
135 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700136 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700137 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700138 if (carrierPackages != null && !carrierPackages.isEmpty()) {
139 if (carrierPackages.size() != 1) {
140 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
141 }
142 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700143 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)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400150 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
151 Intent.CATEGORY_APP_BROWSER);
152 intent.setData(Uri.parse(url));
153 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
154 Intent.FLAG_ACTIVITY_NEW_TASK);
155 try {
156 startActivity(intent);
157 } catch (ActivityNotFoundException e) {
158 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
159 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700160 } else {
161 // No provisioning URL
162 String operatorName = mTm.getSimOperatorName();
163 if (TextUtils.isEmpty(operatorName)) {
164 // Use NetworkOperatorName as second choice in case there is no
165 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
166 operatorName = mTm.getNetworkOperatorName();
167 if (TextUtils.isEmpty(operatorName)) {
168 mManageMobilePlanMessage = resources.getString(
169 R.string.mobile_unknown_sim_operator);
170 } else {
171 mManageMobilePlanMessage = resources.getString(
172 R.string.mobile_no_provisioning_url, operatorName);
173 }
174 } else {
175 mManageMobilePlanMessage = resources.getString(
176 R.string.mobile_no_provisioning_url, operatorName);
177 }
178 }
179 } else if (mTm.hasIccCard() == false) {
180 // No sim card
181 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
182 } else {
183 // NetworkInfo is null, there is no connection
184 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
185 }
186 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
187 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
188 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
189 }
190 }
191
David Braun4e9f04d2013-09-16 13:45:42 -0700192 private void initSmsApplicationSetting() {
193 log("initSmsApplicationSetting:");
194 Collection<SmsApplicationData> smsApplications =
195 SmsApplication.getApplicationCollection(getActivity());
196
197 // If the list is empty the dialog will be empty, but we will not crash.
198 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700199 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700200 int i = 0;
201 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700202 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700203 i++;
204 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700205 String defaultPackageName = null;
206 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
207 if (appName != null) {
208 defaultPackageName = appName.getPackageName();
209 }
210 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700211 }
212
Wink Saville5d5a2692013-06-29 07:54:13 -0700213 @Override
214 public Dialog onCreateDialog(int dialogId) {
215 log("onCreateDialog: dialogId=" + dialogId);
216 switch (dialogId) {
217 case MANAGE_MOBILE_PLAN_DIALOG_ID:
218 return new AlertDialog.Builder(getActivity())
219 .setMessage(mManageMobilePlanMessage)
220 .setCancelable(false)
221 .setPositiveButton(com.android.internal.R.string.ok,
222 new DialogInterface.OnClickListener() {
223 @Override
224 public void onClick(DialogInterface dialog, int id) {
225 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
226 mManageMobilePlanMessage = null;
227 }
228 })
229 .create();
230 }
231 return super.onCreateDialog(dialogId);
232 }
233
234 private void log(String s) {
235 Log.d(TAG, s);
236 }
237
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800238 public static boolean isRadioAllowed(Context context, String type) {
239 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
240 return true;
241 }
242 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700243 String toggleable = Settings.Global.getString(context.getContentResolver(),
244 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800245 return toggleable != null && toggleable.contains(type);
246 }
247
David Braun4e9f04d2013-09-16 13:45:42 -0700248 private boolean isSmsSupported() {
249 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500250 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700251 }
252
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800253 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700254 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800255 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700256 if (savedInstanceState != null) {
257 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
258 }
259 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
260
261 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
262 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700263 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400264 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800265
266 addPreferencesFromResource(R.xml.wireless_settings);
267
Amith Yamasani32505ac2014-11-12 13:46:43 -0800268 final int myUserId = UserHandle.myUserId();
269 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
270 final boolean isRestrictedUser = mUm.getUserInfo(myUserId).isRestricted();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700271
Amith Yamasanid7993472010-08-18 13:59:28 -0700272 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700273 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700274 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500275 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Fabrice Di Megliodaef2e22014-10-15 19:00:35 -0700276 SwitchPreference nsd = (SwitchPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800277
Gilles Debunnee78c1872011-06-20 15:00:07 -0700278 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500279 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700280
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700281 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800282 // Restricted users cannot currently read/write SMS.
283 if (isRestrictedUser) {
284 removePreference(KEY_SMS_APPLICATION);
285 } else {
286 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
287 initSmsApplicationSetting();
288 }
David Braun4e9f04d2013-09-16 13:45:42 -0700289
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800290 if (ImsManager.isWfcEnabledByPlatform(activity)) {
291 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
292 } else {
293 removePreference(KEY_WFC_SETTINGS);
294 }
295
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700296 // Remove NSD checkbox by default
297 getPreferenceScreen().removePreference(nsd);
298 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800299
Christopher Tate6a5929b2012-09-10 15:39:05 -0700300 String toggleable = Settings.Global.getString(activity.getContentResolver(),
301 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800302
tk.mun7c5c1652011-10-13 22:56:18 +0900303 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700304 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900305 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400306 if (!isWimaxEnabled
307 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900308 PreferenceScreen root = getPreferenceScreen();
309 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
310 if (ps != null) root.removePreference(ps);
311 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700312 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900313 && isWimaxEnabled) {
314 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
315 ps.setDependency(KEY_TOGGLE_AIRPLANE);
316 }
317 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400318
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800319 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700320 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800321 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
322 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400323 // Disable VPN.
324 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700325 removePreference(KEY_VPN_SETTINGS);
326 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400327
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800328 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700329 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700330 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700331 }
332
Nick Pelly9894d4a2011-08-09 07:10:16 -0700333 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700334 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700335 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500336 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700337 }
338
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700339 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500340 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
341 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700342 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500343 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700344 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800345 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800346
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400347 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
348 // if it's a wifi-only device, or if the settings are restricted.
349 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
350 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700351 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700352 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800353 }
Sungmin Choi24903152013-10-15 16:11:55 -0700354 // Remove Mobile Network Settings and Manage Mobile Plan
355 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700356 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700357 R.bool.config_show_mobile_plan);
358 if (!isMobilePlanEnabled) {
359 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
360 if (pref != null) {
361 removePreference(KEY_MANAGE_MOBILE_PLAN);
362 }
363 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800364
David Braun4e9f04d2013-09-16 13:45:42 -0700365 // Remove SMS Application if the device does not support SMS
366 if (!isSmsSupported()) {
367 removePreference(KEY_SMS_APPLICATION);
368 }
369
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900370 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700371 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900372 removePreference(KEY_TOGGLE_AIRPLANE);
373 }
374
Oscar Montemayor05411892010-08-03 16:56:09 -0700375 // Enable Proxy selector settings if allowed.
376 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700377 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700378 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800379 // proxy UI disabled until we have better app support
380 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700381 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
382
Amith Yamasani0f85c482011-02-23 17:19:11 -0800383 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700384 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700385 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400386 if (isSecondaryUser || !cm.isTetheringSupported()
387 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800388 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700389 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700390 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700391 p.setTitle(Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700392
393 // Grey out if provisioning is not available.
394 p.setEnabled(!TetherSettings
395 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800396 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700397
398 // Enable link to CMAS app settings depending on the value in config.xml.
399 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
400 com.android.internal.R.bool.config_cellBroadcastAppLinks);
401 try {
402 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700403 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700404 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
405 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
406 }
407 }
408 } catch (IllegalArgumentException ignored) {
409 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
410 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400411 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
412 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700413 PreferenceScreen root = getPreferenceScreen();
414 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
415 if (ps != null) root.removePreference(ps);
416 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800417 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800418
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800419 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700420 public void onStart() {
421 super.onStart();
422
423 initSmsApplicationSetting();
424 }
425
426 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700427 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800428 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700429
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800430 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700431 if (mNfcEnabler != null) {
432 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500433 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700434 if (mNsdEnabler != null) {
435 mNsdEnabler.resume();
436 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800437
438 final Context context = getActivity();
439 if (ImsManager.isWfcEnabledByPlatform(context)) {
440 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
441 context, ImsManager.getWfcMode(context)));
442 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800443 }
Danica Chang32711b62010-08-10 18:41:29 -0700444
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800445 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700446 public void onSaveInstanceState(Bundle outState) {
447 super.onSaveInstanceState(outState);
448
449 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
450 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
451 }
452 }
453
454 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700455 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800456 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700457
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800458 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700459 if (mNfcEnabler != null) {
460 mNfcEnabler.pause();
461 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700462 if (mNsdEnabler != null) {
463 mNsdEnabler.pause();
464 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800465 }
Danica Chang32711b62010-08-10 18:41:29 -0700466
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500467 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700468 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800469 if (requestCode == REQUEST_CODE_EXIT_ECM) {
470 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500471 // Set Airplane mode based on the return value and checkbox state
472 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
473 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500474 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400475 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500476 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700477
478 @Override
479 protected int getHelpResource() {
480 return R.string.help_url_more_networks;
481 }
David Braun4e9f04d2013-09-16 13:45:42 -0700482
483 @Override
484 public boolean onPreferenceChange(Preference preference, Object newValue) {
485 if (preference == mSmsApplicationPreference && newValue != null) {
486 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700487 return true;
488 }
489 return false;
490 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700491
492 /**
493 * For Search.
494 */
495 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
496 new BaseSearchIndexProvider() {
497 @Override
498 public List<SearchIndexableResource> getXmlResourcesToIndex(
499 Context context, boolean enabled) {
500 SearchIndexableResource sir = new SearchIndexableResource(context);
501 sir.xmlResId = R.xml.wireless_settings;
502 return Arrays.asList(sir);
503 }
504
505 @Override
506 public List<String> getNonIndexableKeys(Context context) {
507 final ArrayList<String> result = new ArrayList<String>();
508
509 result.add(KEY_TOGGLE_NSD);
510
Julia Reynolds00d19c72014-06-24 15:22:50 -0400511 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800512 final int myUserId = UserHandle.myUserId();
513 final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER;
514 final boolean isRestrictedUser = um.getUserInfo(myUserId).isRestricted();
515 final boolean isWimaxEnabled = !isSecondaryUser
516 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700517 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400518 if (!isWimaxEnabled
519 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700520 result.add(KEY_WIMAX_SETTINGS);
521 }
522
523 if (isSecondaryUser) { // Disable VPN
524 result.add(KEY_VPN_SETTINGS);
525 }
526
527 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800528 final NfcManager manager = (NfcManager)
529 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700530 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 Lee5e108342014-06-19 22:21:41 +0000553 TelephonyManager tm =
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700554 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Amith Yamasani32505ac2014-11-12 13:46:43 -0800555 if (!tm.isSmsCapable() || isRestrictedUser) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700556 result.add(KEY_SMS_APPLICATION);
557 }
558
559 final PackageManager pm = context.getPackageManager();
560
561 // Remove Airplane Mode settings if it's a stationary device such as a TV.
562 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
563 result.add(KEY_TOGGLE_AIRPLANE);
564 }
565
566 // proxy UI disabled until we have better app support
567 result.add(KEY_PROXY_SETTINGS);
568
569 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800570 ConnectivityManager cm = (ConnectivityManager)
571 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700572 if (isSecondaryUser || !cm.isTetheringSupported()) {
573 result.add(KEY_TETHER_SETTINGS);
574 }
575
576 // Enable link to CMAS app settings depending on the value in config.xml.
577 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
578 com.android.internal.R.bool.config_cellBroadcastAppLinks);
579 try {
580 if (isCellBroadcastAppLinkEnabled) {
581 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
582 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
583 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
584 }
585 }
586 } catch (IllegalArgumentException ignored) {
587 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
588 }
589 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
590 result.add(KEY_CELL_BROADCAST_SETTINGS);
591 }
592
593 return result;
594 }
595 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800596}