blob: 39d0f4cb2d90ac83ee47e03a11b9f8d8a23d0a59 [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;
Wink Saville5d5a2692013-06-29 07:54:13 -070044import android.telephony.TelephonyManager;
45import android.text.TextUtils;
46import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070047
48import com.android.internal.telephony.SmsApplication;
49import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070050import com.android.internal.telephony.TelephonyIntents;
51import com.android.internal.telephony.TelephonyProperties;
52import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070053import com.android.settings.search.BaseSearchIndexProvider;
54import com.android.settings.search.Indexable;
Gilles Debunnee78c1872011-06-20 15:00:07 -070055
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070056import java.util.ArrayList;
57import java.util.Arrays;
David Braun4e9f04d2013-09-16 13:45:42 -070058import java.util.Collection;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070059import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070060
Julia Reynolds00d19c72014-06-24 15:22:50 -040061public class WirelessSettings extends SettingsPreferenceFragment
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070062 implements OnPreferenceChangeListener, Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070063 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080064
65 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070066 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090067 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050068 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070069 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080070 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070071 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080072 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070073 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
David Braun4e9f04d2013-09-16 13:45:42 -070074 private static final String KEY_SMS_APPLICATION = "sms_application";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070075 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070076 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070077
Chouting Zhang71cc49e2009-08-28 14:36:35 -050078 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
79 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080081 private AirplaneModeEnabler mAirplaneModeEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050082 private CheckBoxPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070083 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050084 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070085 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050086
Wink Saville5d5a2692013-06-29 07:54:13 -070087 private ConnectivityManager mCm;
88 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070089 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040090 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070091
92 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
93 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
94
Jeff Davidsonb9558d92014-03-25 12:21:30 -070095 private AppListPreference mSmsApplicationPreference;
David Braun4e9f04d2013-09-16 13:45:42 -070096
Chouting Zhang71cc49e2009-08-28 14:36:35 -050097 /**
98 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080099 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500100 * preference click events.
101 */
102 @Override
103 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -0700104 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800105 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
106 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500107 // In ECM mode launch ECM app dialog
108 startActivityForResult(
109 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
110 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500111 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700112 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
113 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500114 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800115 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700116 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500117 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800118
Wink Saville5d5a2692013-06-29 07:54:13 -0700119 private String mManageMobilePlanMessage;
Wink Saville7bee4c22013-08-29 19:58:09 -0700120 private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION
121 = "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION";
Wink Saville5d5a2692013-06-29 07:54:13 -0700122 public void onManageMobilePlanClick() {
123 log("onManageMobilePlanClick:");
124 mManageMobilePlanMessage = null;
125 Resources resources = getActivity().getResources();
126
Wink Savillee24e5962013-08-28 14:26:27 -0700127 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700128 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700129 // Check for carrier apps that can handle provisioning first
130 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
131 provisioningIntent.addCategory(TelephonyIntents.CATEGORY_MCCMNC_PREFIX
132 + mTm.getSimOperator());
133 if (mPm.resolveActivity(provisioningIntent, 0 /* flags */) != null) {
134 startActivity(provisioningIntent);
135 return;
136 }
137
Wink Saville5d5a2692013-06-29 07:54:13 -0700138 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700139 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700140 if (!TextUtils.isEmpty(url)) {
Wink Saville7bee4c22013-08-29 19:58:09 -0700141 Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
Wink Savillee24e5962013-08-28 14:26:27 -0700142 intent.putExtra("EXTRA_URL", url);
143 Context context = getActivity().getBaseContext();
144 context.sendBroadcast(intent);
Wink Saville5d5a2692013-06-29 07:54:13 -0700145 mManageMobilePlanMessage = null;
146 } else {
147 // No provisioning URL
148 String operatorName = mTm.getSimOperatorName();
149 if (TextUtils.isEmpty(operatorName)) {
150 // Use NetworkOperatorName as second choice in case there is no
151 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
152 operatorName = mTm.getNetworkOperatorName();
153 if (TextUtils.isEmpty(operatorName)) {
154 mManageMobilePlanMessage = resources.getString(
155 R.string.mobile_unknown_sim_operator);
156 } else {
157 mManageMobilePlanMessage = resources.getString(
158 R.string.mobile_no_provisioning_url, operatorName);
159 }
160 } else {
161 mManageMobilePlanMessage = resources.getString(
162 R.string.mobile_no_provisioning_url, operatorName);
163 }
164 }
165 } else if (mTm.hasIccCard() == false) {
166 // No sim card
167 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
168 } else {
169 // NetworkInfo is null, there is no connection
170 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
171 }
172 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
173 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
174 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
175 }
176 }
177
David Braun4e9f04d2013-09-16 13:45:42 -0700178 private void initSmsApplicationSetting() {
179 log("initSmsApplicationSetting:");
180 Collection<SmsApplicationData> smsApplications =
181 SmsApplication.getApplicationCollection(getActivity());
182
183 // If the list is empty the dialog will be empty, but we will not crash.
184 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700185 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700186 int i = 0;
187 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700188 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700189 i++;
190 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700191 String defaultPackageName = null;
192 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
193 if (appName != null) {
194 defaultPackageName = appName.getPackageName();
195 }
196 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700197 }
198
Wink Saville5d5a2692013-06-29 07:54:13 -0700199 @Override
200 public Dialog onCreateDialog(int dialogId) {
201 log("onCreateDialog: dialogId=" + dialogId);
202 switch (dialogId) {
203 case MANAGE_MOBILE_PLAN_DIALOG_ID:
204 return new AlertDialog.Builder(getActivity())
205 .setMessage(mManageMobilePlanMessage)
206 .setCancelable(false)
207 .setPositiveButton(com.android.internal.R.string.ok,
208 new DialogInterface.OnClickListener() {
209 @Override
210 public void onClick(DialogInterface dialog, int id) {
211 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
212 mManageMobilePlanMessage = null;
213 }
214 })
215 .create();
216 }
217 return super.onCreateDialog(dialogId);
218 }
219
220 private void log(String s) {
221 Log.d(TAG, s);
222 }
223
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800224 public static boolean isRadioAllowed(Context context, String type) {
225 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
226 return true;
227 }
228 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700229 String toggleable = Settings.Global.getString(context.getContentResolver(),
230 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800231 return toggleable != null && toggleable.contains(type);
232 }
233
David Braun4e9f04d2013-09-16 13:45:42 -0700234 private boolean isSmsSupported() {
235 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500236 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700237 }
238
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800239 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700240 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800241 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700242 if (savedInstanceState != null) {
243 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
244 }
245 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
246
247 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
248 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700249 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400250 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800251
252 addPreferencesFromResource(R.xml.wireless_settings);
253
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700254 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
255
Amith Yamasanid7993472010-08-18 13:59:28 -0700256 final Activity activity = getActivity();
Gilles Debunnee78c1872011-06-20 15:00:07 -0700257 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Nick Pellyad50ba02010-09-22 10:55:13 -0700258 CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500259 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700260 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800261
Gilles Debunnee78c1872011-06-20 15:00:07 -0700262 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500263 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700264
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700265 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
David Braun4e9f04d2013-09-16 13:45:42 -0700266 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700267 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700268
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700269 // Remove NSD checkbox by default
270 getPreferenceScreen().removePreference(nsd);
271 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800272
Christopher Tate6a5929b2012-09-10 15:39:05 -0700273 String toggleable = Settings.Global.getString(activity.getContentResolver(),
274 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800275
tk.mun7c5c1652011-10-13 22:56:18 +0900276 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700277 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900278 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400279 if (!isWimaxEnabled
280 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900281 PreferenceScreen root = getPreferenceScreen();
282 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
283 if (ps != null) root.removePreference(ps);
284 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700285 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900286 && isWimaxEnabled) {
287 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
288 ps.setDependency(KEY_TOGGLE_AIRPLANE);
289 }
290 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400291
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800292 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700293 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800294 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
295 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400296 // Disable VPN.
297 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700298 removePreference(KEY_VPN_SETTINGS);
299 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400300
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800301 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700302 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700303 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700304 }
305
Nick Pelly9894d4a2011-08-09 07:10:16 -0700306 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700307 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700308 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500309 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700310 }
311
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700312 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500313 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
314 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700315 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500316 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700317 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800318 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800319
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400320 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
321 // if it's a wifi-only device, or if the settings are restricted.
322 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
323 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700324 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700325 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800326 }
Sungmin Choi24903152013-10-15 16:11:55 -0700327 // Remove Mobile Network Settings and Manage Mobile Plan
328 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700329 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700330 R.bool.config_show_mobile_plan);
331 if (!isMobilePlanEnabled) {
332 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
333 if (pref != null) {
334 removePreference(KEY_MANAGE_MOBILE_PLAN);
335 }
336 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800337
David Braun4e9f04d2013-09-16 13:45:42 -0700338 // Remove SMS Application if the device does not support SMS
339 if (!isSmsSupported()) {
340 removePreference(KEY_SMS_APPLICATION);
341 }
342
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900343 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700344 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900345 removePreference(KEY_TOGGLE_AIRPLANE);
346 }
347
Oscar Montemayor05411892010-08-03 16:56:09 -0700348 // Enable Proxy selector settings if allowed.
349 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700350 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700351 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800352 // proxy UI disabled until we have better app support
353 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700354 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
355
Amith Yamasani0f85c482011-02-23 17:19:11 -0800356 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700357 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700358 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400359 if (isSecondaryUser || !cm.isTetheringSupported()
360 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800361 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700362 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700363 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700364 p.setTitle(Utils.getTetheringLabel(cm));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800365 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700366
367 // Enable link to CMAS app settings depending on the value in config.xml.
368 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
369 com.android.internal.R.bool.config_cellBroadcastAppLinks);
370 try {
371 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700372 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700373 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
374 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
375 }
376 }
377 } catch (IllegalArgumentException ignored) {
378 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
379 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400380 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
381 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700382 PreferenceScreen root = getPreferenceScreen();
383 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
384 if (ps != null) root.removePreference(ps);
385 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800386 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800387
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800388 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700389 public void onStart() {
390 super.onStart();
391
392 initSmsApplicationSetting();
393 }
394
395 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700396 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800397 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700398
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800399 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700400 if (mNfcEnabler != null) {
401 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500402 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700403 if (mNsdEnabler != null) {
404 mNsdEnabler.resume();
405 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800406 }
Danica Chang32711b62010-08-10 18:41:29 -0700407
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800408 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700409 public void onSaveInstanceState(Bundle outState) {
410 super.onSaveInstanceState(outState);
411
412 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
413 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
414 }
415 }
416
417 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700418 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800419 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700420
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800421 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700422 if (mNfcEnabler != null) {
423 mNfcEnabler.pause();
424 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700425 if (mNsdEnabler != null) {
426 mNsdEnabler.pause();
427 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800428 }
Danica Chang32711b62010-08-10 18:41:29 -0700429
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500430 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700431 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800432 if (requestCode == REQUEST_CODE_EXIT_ECM) {
433 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500434 // Set Airplane mode based on the return value and checkbox state
435 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
436 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500437 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400438 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500439 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700440
441 @Override
442 protected int getHelpResource() {
443 return R.string.help_url_more_networks;
444 }
David Braun4e9f04d2013-09-16 13:45:42 -0700445
446 @Override
447 public boolean onPreferenceChange(Preference preference, Object newValue) {
448 if (preference == mSmsApplicationPreference && newValue != null) {
449 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700450 return true;
451 }
452 return false;
453 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700454
455 /**
456 * For Search.
457 */
458 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
459 new BaseSearchIndexProvider() {
460 @Override
461 public List<SearchIndexableResource> getXmlResourcesToIndex(
462 Context context, boolean enabled) {
463 SearchIndexableResource sir = new SearchIndexableResource(context);
464 sir.xmlResId = R.xml.wireless_settings;
465 return Arrays.asList(sir);
466 }
467
468 @Override
469 public List<String> getNonIndexableKeys(Context context) {
470 final ArrayList<String> result = new ArrayList<String>();
471
472 result.add(KEY_TOGGLE_NSD);
473
Julia Reynolds00d19c72014-06-24 15:22:50 -0400474 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700475 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
476 final boolean isWimaxEnabled = !isSecondaryUser && context.getResources().getBoolean(
477 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400478 if (!isWimaxEnabled
479 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700480 result.add(KEY_WIMAX_SETTINGS);
481 }
482
483 if (isSecondaryUser) { // Disable VPN
484 result.add(KEY_VPN_SETTINGS);
485 }
486
487 // Remove NFC if not available
488 final NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
489 if (manager != null) {
490 NfcAdapter adapter = manager.getDefaultAdapter();
491 if (adapter == null) {
492 result.add(KEY_TOGGLE_NFC);
493 result.add(KEY_ANDROID_BEAM_SETTINGS);
494 }
495 }
496
497 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
498 if (isSecondaryUser || Utils.isWifiOnly(context)) {
499 result.add(KEY_MOBILE_NETWORK_SETTINGS);
500 result.add(KEY_MANAGE_MOBILE_PLAN);
501 }
502
503 // Remove Mobile Network Settings and Manage Mobile Plan
504 // if config_show_mobile_plan sets false.
505 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
506 R.bool.config_show_mobile_plan);
507 if (!isMobilePlanEnabled) {
508 result.add(KEY_MANAGE_MOBILE_PLAN);
509 }
510
511 // Remove SMS Application if the device does not support SMS
Yorke Lee5e108342014-06-19 22:21:41 +0000512 TelephonyManager tm =
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700513 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
514 if (!tm.isSmsCapable()) {
515 result.add(KEY_SMS_APPLICATION);
516 }
517
518 final PackageManager pm = context.getPackageManager();
519
520 // Remove Airplane Mode settings if it's a stationary device such as a TV.
521 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
522 result.add(KEY_TOGGLE_AIRPLANE);
523 }
524
525 // proxy UI disabled until we have better app support
526 result.add(KEY_PROXY_SETTINGS);
527
528 // Disable Tethering if it's not allowed or if it's a wifi-only device
Yorke Lee5e108342014-06-19 22:21:41 +0000529 ConnectivityManager cm =
530 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700531 if (isSecondaryUser || !cm.isTetheringSupported()) {
532 result.add(KEY_TETHER_SETTINGS);
533 }
534
535 // Enable link to CMAS app settings depending on the value in config.xml.
536 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
537 com.android.internal.R.bool.config_cellBroadcastAppLinks);
538 try {
539 if (isCellBroadcastAppLinkEnabled) {
540 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
541 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
542 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
543 }
544 }
545 } catch (IllegalArgumentException ignored) {
546 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
547 }
548 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
549 result.add(KEY_CELL_BROADCAST_SETTINGS);
550 }
551
552 return result;
553 }
554 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800555}