blob: 7aaa0a6a9fef616226ad4bdb76a6aede73b29b3e [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;
Amith Yamasanid7993472010-08-18 13:59:28 -070037import android.preference.CheckBoxPreference;
38import android.preference.Preference;
David Braun4e9f04d2013-09-16 13:45:42 -070039import android.preference.Preference.OnPreferenceChangeListener;
Amith Yamasanid7993472010-08-18 13:59:28 -070040import android.preference.PreferenceScreen;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070041import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070042import android.provider.Settings;
Wink Saville5d5a2692013-06-29 07:54:13 -070043import android.telephony.TelephonyManager;
44import android.text.TextUtils;
45import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070046
47import com.android.internal.telephony.SmsApplication;
48import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070049import com.android.internal.telephony.TelephonyIntents;
50import com.android.internal.telephony.TelephonyProperties;
51import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070052import com.android.settings.search.BaseSearchIndexProvider;
53import com.android.settings.search.Indexable;
Gilles Debunnee78c1872011-06-20 15:00:07 -070054
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070055import java.util.ArrayList;
56import java.util.Arrays;
David Braun4e9f04d2013-09-16 13:45:42 -070057import java.util.Collection;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070058import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070059
60public class WirelessSettings extends RestrictedSettingsFragment
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070061 implements OnPreferenceChangeListener, Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070062 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080063
64 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070065 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090066 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050067 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070068 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080069 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070070 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080071 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070072 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
David Braun4e9f04d2013-09-16 13:45:42 -070073 private static final String KEY_SMS_APPLICATION = "sms_application";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070074 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070075 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070076
Chouting Zhang71cc49e2009-08-28 14:36:35 -050077 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
78 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080079
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080080 private AirplaneModeEnabler mAirplaneModeEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050081 private CheckBoxPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070082 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050083 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070084 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050085
Wink Saville5d5a2692013-06-29 07:54:13 -070086 private ConnectivityManager mCm;
87 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070088 private PackageManager mPm;
Wink Saville5d5a2692013-06-29 07:54:13 -070089
90 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
91 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
92
Jeff Davidsonb9558d92014-03-25 12:21:30 -070093 private AppListPreference mSmsApplicationPreference;
David Braun4e9f04d2013-09-16 13:45:42 -070094
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -040095 public WirelessSettings() {
96 super(null);
97 }
Chouting Zhang71cc49e2009-08-28 14:36:35 -050098 /**
99 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800100 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500101 * preference click events.
102 */
103 @Override
104 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Geoffrey Borggaard6e1102d2013-08-07 14:57:43 -0400105 if (ensurePinRestrictedPreference(preference)) {
106 return true;
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400107 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700108 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800109 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
110 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500111 // In ECM mode launch ECM app dialog
112 startActivityForResult(
113 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
114 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500115 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700116 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
117 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500118 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800119 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700120 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500121 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800122
Wink Saville5d5a2692013-06-29 07:54:13 -0700123 private String mManageMobilePlanMessage;
Wink Saville7bee4c22013-08-29 19:58:09 -0700124 private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION
125 = "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION";
Wink Saville5d5a2692013-06-29 07:54:13 -0700126 public void onManageMobilePlanClick() {
127 log("onManageMobilePlanClick:");
128 mManageMobilePlanMessage = null;
129 Resources resources = getActivity().getResources();
130
Wink Savillee24e5962013-08-28 14:26:27 -0700131 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700132 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700133 // Check for carrier apps that can handle provisioning first
134 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
135 provisioningIntent.addCategory(TelephonyIntents.CATEGORY_MCCMNC_PREFIX
136 + mTm.getSimOperator());
137 if (mPm.resolveActivity(provisioningIntent, 0 /* flags */) != null) {
138 startActivity(provisioningIntent);
139 return;
140 }
141
Wink Saville5d5a2692013-06-29 07:54:13 -0700142 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700143 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700144 if (!TextUtils.isEmpty(url)) {
Wink Saville7bee4c22013-08-29 19:58:09 -0700145 Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
Wink Savillee24e5962013-08-28 14:26:27 -0700146 intent.putExtra("EXTRA_URL", url);
147 Context context = getActivity().getBaseContext();
148 context.sendBroadcast(intent);
Wink Saville5d5a2692013-06-29 07:54:13 -0700149 mManageMobilePlanMessage = null;
150 } else {
151 // No provisioning URL
152 String operatorName = mTm.getSimOperatorName();
153 if (TextUtils.isEmpty(operatorName)) {
154 // Use NetworkOperatorName as second choice in case there is no
155 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
156 operatorName = mTm.getNetworkOperatorName();
157 if (TextUtils.isEmpty(operatorName)) {
158 mManageMobilePlanMessage = resources.getString(
159 R.string.mobile_unknown_sim_operator);
160 } else {
161 mManageMobilePlanMessage = resources.getString(
162 R.string.mobile_no_provisioning_url, operatorName);
163 }
164 } else {
165 mManageMobilePlanMessage = resources.getString(
166 R.string.mobile_no_provisioning_url, operatorName);
167 }
168 }
169 } else if (mTm.hasIccCard() == false) {
170 // No sim card
171 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
172 } else {
173 // NetworkInfo is null, there is no connection
174 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
175 }
176 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
177 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
178 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
179 }
180 }
181
David Braun4e9f04d2013-09-16 13:45:42 -0700182 private void initSmsApplicationSetting() {
183 log("initSmsApplicationSetting:");
184 Collection<SmsApplicationData> smsApplications =
185 SmsApplication.getApplicationCollection(getActivity());
186
187 // If the list is empty the dialog will be empty, but we will not crash.
188 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700189 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700190 int i = 0;
191 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700192 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700193 i++;
194 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700195 String defaultPackageName = null;
196 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
197 if (appName != null) {
198 defaultPackageName = appName.getPackageName();
199 }
200 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700201 }
202
Wink Saville5d5a2692013-06-29 07:54:13 -0700203 @Override
204 public Dialog onCreateDialog(int dialogId) {
205 log("onCreateDialog: dialogId=" + dialogId);
206 switch (dialogId) {
207 case MANAGE_MOBILE_PLAN_DIALOG_ID:
208 return new AlertDialog.Builder(getActivity())
209 .setMessage(mManageMobilePlanMessage)
210 .setCancelable(false)
211 .setPositiveButton(com.android.internal.R.string.ok,
212 new DialogInterface.OnClickListener() {
213 @Override
214 public void onClick(DialogInterface dialog, int id) {
215 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
216 mManageMobilePlanMessage = null;
217 }
218 })
219 .create();
220 }
221 return super.onCreateDialog(dialogId);
222 }
223
224 private void log(String s) {
225 Log.d(TAG, s);
226 }
227
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800228 public static boolean isRadioAllowed(Context context, String type) {
229 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
230 return true;
231 }
232 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700233 String toggleable = Settings.Global.getString(context.getContentResolver(),
234 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800235 return toggleable != null && toggleable.contains(type);
236 }
237
David Braun4e9f04d2013-09-16 13:45:42 -0700238 private boolean isSmsSupported() {
239 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500240 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700241 }
242
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800243 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700244 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800245 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700246 if (savedInstanceState != null) {
247 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
248 }
249 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
250
251 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
252 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700253 mPm = getPackageManager();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800254
255 addPreferencesFromResource(R.xml.wireless_settings);
256
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700257 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
258
Amith Yamasanid7993472010-08-18 13:59:28 -0700259 final Activity activity = getActivity();
Gilles Debunnee78c1872011-06-20 15:00:07 -0700260 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Nick Pellyad50ba02010-09-22 10:55:13 -0700261 CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500262 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700263 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800264
Gilles Debunnee78c1872011-06-20 15:00:07 -0700265 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500266 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700267
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700268 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
David Braun4e9f04d2013-09-16 13:45:42 -0700269 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700270 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700271
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700272 // Remove NSD checkbox by default
273 getPreferenceScreen().removePreference(nsd);
274 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800275
Christopher Tate6a5929b2012-09-10 15:39:05 -0700276 String toggleable = Settings.Global.getString(activity.getContentResolver(),
277 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800278
tk.mun7c5c1652011-10-13 22:56:18 +0900279 //enable/disable wimax depending on the value in config.xml
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700280 final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900281 com.android.internal.R.bool.config_wimaxEnabled);
282 if (!isWimaxEnabled) {
283 PreferenceScreen root = getPreferenceScreen();
284 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
285 if (ps != null) root.removePreference(ps);
286 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700287 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900288 && isWimaxEnabled) {
289 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
290 ps.setDependency(KEY_TOGGLE_AIRPLANE);
291 }
292 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400293 protectByRestrictions(KEY_WIMAX_SETTINGS);
294
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800295 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700296 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800297 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
298 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700299 if (isSecondaryUser) { // Disable VPN
300 removePreference(KEY_VPN_SETTINGS);
301 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400302 protectByRestrictions(KEY_VPN_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800303 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700304 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700305 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700306 }
307
Nick Pelly9894d4a2011-08-09 07:10:16 -0700308 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700309 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700310 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500311 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700312 }
313
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700314 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500315 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
316 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700317 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500318 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700319 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800320 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800321
Wink Saville5d5a2692013-06-29 07:54:13 -0700322 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700323 if (isSecondaryUser || Utils.isWifiOnly(getActivity())) {
324 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 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400337 protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS);
338 protectByRestrictions(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800339
David Braun4e9f04d2013-09-16 13:45:42 -0700340 // Remove SMS Application if the device does not support SMS
341 if (!isSmsSupported()) {
342 removePreference(KEY_SMS_APPLICATION);
343 }
344
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900345 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700346 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900347 removePreference(KEY_TOGGLE_AIRPLANE);
348 }
349
Oscar Montemayor05411892010-08-03 16:56:09 -0700350 // Enable Proxy selector settings if allowed.
351 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700352 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700353 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800354 // proxy UI disabled until we have better app support
355 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700356 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
357
Amith Yamasani0f85c482011-02-23 17:19:11 -0800358 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700359 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700360 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700361 if (isSecondaryUser || !cm.isTetheringSupported()) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800362 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700363 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700364 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700365 p.setTitle(Utils.getTetheringLabel(cm));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800366 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400367 protectByRestrictions(KEY_TETHER_SETTINGS);
Jake Hambyef57ed72012-06-21 10:59:22 -0700368
369 // Enable link to CMAS app settings depending on the value in config.xml.
370 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
371 com.android.internal.R.bool.config_cellBroadcastAppLinks);
372 try {
373 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700374 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700375 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
376 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
377 }
378 }
379 } catch (IllegalArgumentException ignored) {
380 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
381 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700382 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700383 PreferenceScreen root = getPreferenceScreen();
384 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
385 if (ps != null) root.removePreference(ps);
386 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400387 protectByRestrictions(KEY_CELL_BROADCAST_SETTINGS);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800388 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800389
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800390 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700391 public void onStart() {
392 super.onStart();
393
394 initSmsApplicationSetting();
395 }
396
397 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700398 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800399 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700400
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800401 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700402 if (mNfcEnabler != null) {
403 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500404 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700405 if (mNsdEnabler != null) {
406 mNsdEnabler.resume();
407 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800408 }
Danica Chang32711b62010-08-10 18:41:29 -0700409
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800410 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700411 public void onSaveInstanceState(Bundle outState) {
412 super.onSaveInstanceState(outState);
413
414 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
415 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
416 }
417 }
418
419 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700420 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800421 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700422
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800423 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700424 if (mNfcEnabler != null) {
425 mNfcEnabler.pause();
426 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700427 if (mNsdEnabler != null) {
428 mNsdEnabler.pause();
429 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800430 }
Danica Chang32711b62010-08-10 18:41:29 -0700431
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500432 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700433 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800434 if (requestCode == REQUEST_CODE_EXIT_ECM) {
435 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500436 // Set Airplane mode based on the return value and checkbox state
437 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
438 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500439 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400440 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500441 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700442
443 @Override
444 protected int getHelpResource() {
445 return R.string.help_url_more_networks;
446 }
David Braun4e9f04d2013-09-16 13:45:42 -0700447
448 @Override
449 public boolean onPreferenceChange(Preference preference, Object newValue) {
450 if (preference == mSmsApplicationPreference && newValue != null) {
451 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700452 return true;
453 }
454 return false;
455 }
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700456
457 /**
458 * For Search.
459 */
460 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
461 new BaseSearchIndexProvider() {
462 @Override
463 public List<SearchIndexableResource> getXmlResourcesToIndex(
464 Context context, boolean enabled) {
465 SearchIndexableResource sir = new SearchIndexableResource(context);
466 sir.xmlResId = R.xml.wireless_settings;
467 return Arrays.asList(sir);
468 }
469
470 @Override
471 public List<String> getNonIndexableKeys(Context context) {
472 final ArrayList<String> result = new ArrayList<String>();
473
474 result.add(KEY_TOGGLE_NSD);
475
476 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
477 final boolean isWimaxEnabled = !isSecondaryUser && context.getResources().getBoolean(
478 com.android.internal.R.bool.config_wimaxEnabled);
479 if (!isWimaxEnabled) {
480 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
512 TelephonyManager tm =
513 (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
529 ConnectivityManager cm =
530 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
531 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}