blob: ae8fdcf724d324866bf415d4f5f92f0047053d7a [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;
David Braun4e9f04d2013-09-16 13:45:42 -070029import android.content.pm.PackageManager.NameNotFoundException;
Wink Saville5d5a2692013-06-29 07:54:13 -070030import android.content.res.Resources;
David Braun4e9f04d2013-09-16 13:45:42 -070031import android.graphics.drawable.Drawable;
Amith Yamasanid7993472010-08-18 13:59:28 -070032import android.net.ConnectivityManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070033import android.net.NetworkInfo;
Nick Pellya57eace2010-10-15 01:19:43 -070034import android.nfc.NfcAdapter;
Amith Yamasanid7993472010-08-18 13:59:28 -070035import android.os.Bundle;
Amith Yamasanid7993472010-08-18 13:59:28 -070036import android.os.SystemProperties;
Amith Yamasani9627a8e2012-09-23 12:54:14 -070037import android.os.UserHandle;
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;
42import 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;
52
David Braun4e9f04d2013-09-16 13:45:42 -070053import java.util.Collection;
54
55public class WirelessSettings extends RestrictedSettingsFragment
56 implements OnPreferenceChangeListener {
Robert Greenwalt4929e912013-07-16 13:09:24 -070057 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080058
59 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070060 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090061 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050062 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070063 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080064 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070065 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080066 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070067 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
David Braun4e9f04d2013-09-16 13:45:42 -070068 private static final String KEY_SMS_APPLICATION = "sms_application";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070069 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070070 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070071
Chouting Zhang71cc49e2009-08-28 14:36:35 -050072 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
73 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080074
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080075 private AirplaneModeEnabler mAirplaneModeEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050076 private CheckBoxPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070077 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050078 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070079 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050080
Wink Saville5d5a2692013-06-29 07:54:13 -070081 private ConnectivityManager mCm;
82 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070083 private PackageManager mPm;
Wink Saville5d5a2692013-06-29 07:54:13 -070084
85 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
86 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
87
David Braun4e9f04d2013-09-16 13:45:42 -070088 private SmsListPreference mSmsApplicationPreference;
89
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -040090 public WirelessSettings() {
91 super(null);
92 }
Chouting Zhang71cc49e2009-08-28 14:36:35 -050093 /**
94 * Invoked on each preference click in this hierarchy, overrides
95 * PreferenceActivity's implementation. Used to make sure we track the
96 * preference click events.
97 */
98 @Override
99 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Geoffrey Borggaard6e1102d2013-08-07 14:57:43 -0400100 if (ensurePinRestrictedPreference(preference)) {
101 return true;
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400102 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700103 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800104 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
105 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500106 // In ECM mode launch ECM app dialog
107 startActivityForResult(
108 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
109 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500110 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700111 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
112 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500113 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800114 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700115 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500116 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800117
Wink Saville5d5a2692013-06-29 07:54:13 -0700118 private String mManageMobilePlanMessage;
Wink Saville7bee4c22013-08-29 19:58:09 -0700119 private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION
120 = "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION";
Wink Saville5d5a2692013-06-29 07:54:13 -0700121 public void onManageMobilePlanClick() {
122 log("onManageMobilePlanClick:");
123 mManageMobilePlanMessage = null;
124 Resources resources = getActivity().getResources();
125
Wink Savillee24e5962013-08-28 14:26:27 -0700126 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700127 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700128 // Check for carrier apps that can handle provisioning first
129 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
130 provisioningIntent.addCategory(TelephonyIntents.CATEGORY_MCCMNC_PREFIX
131 + mTm.getSimOperator());
132 if (mPm.resolveActivity(provisioningIntent, 0 /* flags */) != null) {
133 startActivity(provisioningIntent);
134 return;
135 }
136
Wink Saville5d5a2692013-06-29 07:54:13 -0700137 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700138 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700139 if (!TextUtils.isEmpty(url)) {
Wink Saville7bee4c22013-08-29 19:58:09 -0700140 Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
Wink Savillee24e5962013-08-28 14:26:27 -0700141 intent.putExtra("EXTRA_URL", url);
142 Context context = getActivity().getBaseContext();
143 context.sendBroadcast(intent);
Wink Saville5d5a2692013-06-29 07:54:13 -0700144 mManageMobilePlanMessage = null;
145 } else {
146 // No provisioning URL
147 String operatorName = mTm.getSimOperatorName();
148 if (TextUtils.isEmpty(operatorName)) {
149 // Use NetworkOperatorName as second choice in case there is no
150 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
151 operatorName = mTm.getNetworkOperatorName();
152 if (TextUtils.isEmpty(operatorName)) {
153 mManageMobilePlanMessage = resources.getString(
154 R.string.mobile_unknown_sim_operator);
155 } else {
156 mManageMobilePlanMessage = resources.getString(
157 R.string.mobile_no_provisioning_url, operatorName);
158 }
159 } else {
160 mManageMobilePlanMessage = resources.getString(
161 R.string.mobile_no_provisioning_url, operatorName);
162 }
163 }
164 } else if (mTm.hasIccCard() == false) {
165 // No sim card
166 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
167 } else {
168 // NetworkInfo is null, there is no connection
169 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
170 }
171 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
172 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
173 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
174 }
175 }
176
David Braun4e9f04d2013-09-16 13:45:42 -0700177 private void updateSmsApplicationSetting() {
178 log("updateSmsApplicationSetting:");
179 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
180 if (appName != null) {
181 String packageName = appName.getPackageName();
182
183 CharSequence[] values = mSmsApplicationPreference.getEntryValues();
184 for (int i = 0; i < values.length; i++) {
185 if (packageName.contentEquals(values[i])) {
186 mSmsApplicationPreference.setValueIndex(i);
187 mSmsApplicationPreference.setSummary(mSmsApplicationPreference.getEntries()[i]);
188 break;
189 }
190 }
191 }
192 }
193
194 private void initSmsApplicationSetting() {
195 log("initSmsApplicationSetting:");
196 Collection<SmsApplicationData> smsApplications =
197 SmsApplication.getApplicationCollection(getActivity());
198
199 // If the list is empty the dialog will be empty, but we will not crash.
200 int count = smsApplications.size();
201 CharSequence[] entries = new CharSequence[count];
202 CharSequence[] entryValues = new CharSequence[count];
203 Drawable[] entryImages = new Drawable[count];
204
David Braun4e9f04d2013-09-16 13:45:42 -0700205 int i = 0;
206 for (SmsApplicationData smsApplicationData : smsApplications) {
207 entries[i] = smsApplicationData.mApplicationName;
208 entryValues[i] = smsApplicationData.mPackageName;
209 try {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700210 entryImages[i] = mPm.getApplicationIcon(smsApplicationData.mPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700211 } catch (NameNotFoundException e) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700212 entryImages[i] = mPm.getDefaultActivityIcon();
David Braun4e9f04d2013-09-16 13:45:42 -0700213 }
214 i++;
215 }
216 mSmsApplicationPreference.setEntries(entries);
217 mSmsApplicationPreference.setEntryValues(entryValues);
218 mSmsApplicationPreference.setEntryDrawables(entryImages);
219 updateSmsApplicationSetting();
220 }
221
Wink Saville5d5a2692013-06-29 07:54:13 -0700222 @Override
223 public Dialog onCreateDialog(int dialogId) {
224 log("onCreateDialog: dialogId=" + dialogId);
225 switch (dialogId) {
226 case MANAGE_MOBILE_PLAN_DIALOG_ID:
227 return new AlertDialog.Builder(getActivity())
228 .setMessage(mManageMobilePlanMessage)
229 .setCancelable(false)
230 .setPositiveButton(com.android.internal.R.string.ok,
231 new DialogInterface.OnClickListener() {
232 @Override
233 public void onClick(DialogInterface dialog, int id) {
234 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
235 mManageMobilePlanMessage = null;
236 }
237 })
238 .create();
239 }
240 return super.onCreateDialog(dialogId);
241 }
242
243 private void log(String s) {
244 Log.d(TAG, s);
245 }
246
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800247 public static boolean isRadioAllowed(Context context, String type) {
248 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
249 return true;
250 }
251 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700252 String toggleable = Settings.Global.getString(context.getContentResolver(),
253 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800254 return toggleable != null && toggleable.contains(type);
255 }
256
David Braun4e9f04d2013-09-16 13:45:42 -0700257 private boolean isSmsSupported() {
258 // Some tablet has sim card but could not do telephony operations. Skip those.
David Braund5b60012013-10-01 17:10:46 -0700259 return (mTm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE);
David Braun4e9f04d2013-09-16 13:45:42 -0700260 }
261
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800262 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700263 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800264 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700265 if (savedInstanceState != null) {
266 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
267 }
268 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
269
270 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
271 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700272 mPm = getPackageManager();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800273
274 addPreferencesFromResource(R.xml.wireless_settings);
275
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700276 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
277
Amith Yamasanid7993472010-08-18 13:59:28 -0700278 final Activity activity = getActivity();
Gilles Debunnee78c1872011-06-20 15:00:07 -0700279 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Nick Pellyad50ba02010-09-22 10:55:13 -0700280 CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500281 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700282 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800283
Gilles Debunnee78c1872011-06-20 15:00:07 -0700284 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500285 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700286
David Braun4e9f04d2013-09-16 13:45:42 -0700287 mSmsApplicationPreference = (SmsListPreference) findPreference(KEY_SMS_APPLICATION);
288 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700289 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700290
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700291 // Remove NSD checkbox by default
292 getPreferenceScreen().removePreference(nsd);
293 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800294
Christopher Tate6a5929b2012-09-10 15:39:05 -0700295 String toggleable = Settings.Global.getString(activity.getContentResolver(),
296 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800297
tk.mun7c5c1652011-10-13 22:56:18 +0900298 //enable/disable wimax depending on the value in config.xml
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700299 boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900300 com.android.internal.R.bool.config_wimaxEnabled);
301 if (!isWimaxEnabled) {
302 PreferenceScreen root = getPreferenceScreen();
303 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
304 if (ps != null) root.removePreference(ps);
305 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700306 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900307 && isWimaxEnabled) {
308 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
309 ps.setDependency(KEY_TOGGLE_AIRPLANE);
310 }
311 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400312 protectByRestrictions(KEY_WIMAX_SETTINGS);
313
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800314 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700315 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800316 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
317 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700318 if (isSecondaryUser) { // Disable VPN
319 removePreference(KEY_VPN_SETTINGS);
320 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400321 protectByRestrictions(KEY_VPN_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800322 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700323 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700324 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700325 }
326
Nick Pelly9894d4a2011-08-09 07:10:16 -0700327 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700328 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700329 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500330 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700331 }
332
Nick Pellyad50ba02010-09-22 10:55:13 -0700333 // Remove NFC if its not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500334 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
335 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700336 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500337 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700338 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800339 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800340
Wink Saville5d5a2692013-06-29 07:54:13 -0700341 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700342 if (isSecondaryUser || Utils.isWifiOnly(getActivity())) {
343 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700344 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800345 }
Sungmin Choi24903152013-10-15 16:11:55 -0700346 // Remove Mobile Network Settings and Manage Mobile Plan
347 // if config_show_mobile_plan sets false.
348 boolean isMobilePlanEnabled = this.getResources().getBoolean(
349 R.bool.config_show_mobile_plan);
350 if (!isMobilePlanEnabled) {
351 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
352 if (pref != null) {
353 removePreference(KEY_MANAGE_MOBILE_PLAN);
354 }
355 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400356 protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS);
357 protectByRestrictions(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800358
David Braun4e9f04d2013-09-16 13:45:42 -0700359 // Remove SMS Application if the device does not support SMS
360 if (!isSmsSupported()) {
361 removePreference(KEY_SMS_APPLICATION);
362 }
363
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900364 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700365 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900366 removePreference(KEY_TOGGLE_AIRPLANE);
367 }
368
Oscar Montemayor05411892010-08-03 16:56:09 -0700369 // Enable Proxy selector settings if allowed.
370 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Amith Yamasanid7993472010-08-18 13:59:28 -0700371 DevicePolicyManager mDPM = (DevicePolicyManager)
372 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800373 // proxy UI disabled until we have better app support
374 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700375 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
376
Amith Yamasani0f85c482011-02-23 17:19:11 -0800377 // Disable Tethering if it's not allowed or if it's a wifi-only device
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800378 ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700379 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700380 if (isSecondaryUser || !cm.isTetheringSupported()) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800381 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700382 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700383 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700384 p.setTitle(Utils.getTetheringLabel(cm));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800385 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400386 protectByRestrictions(KEY_TETHER_SETTINGS);
Jake Hambyef57ed72012-06-21 10:59:22 -0700387
388 // Enable link to CMAS app settings depending on the value in config.xml.
389 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
390 com.android.internal.R.bool.config_cellBroadcastAppLinks);
391 try {
392 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700393 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700394 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
395 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
396 }
397 }
398 } catch (IllegalArgumentException ignored) {
399 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
400 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700401 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700402 PreferenceScreen root = getPreferenceScreen();
403 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
404 if (ps != null) root.removePreference(ps);
405 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400406 protectByRestrictions(KEY_CELL_BROADCAST_SETTINGS);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800407 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800408
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800409 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700410 public void onStart() {
411 super.onStart();
412
413 initSmsApplicationSetting();
414 }
415
416 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700417 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800418 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700419
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800420 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700421 if (mNfcEnabler != null) {
422 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500423 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700424 if (mNsdEnabler != null) {
425 mNsdEnabler.resume();
426 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800427 }
Danica Chang32711b62010-08-10 18:41:29 -0700428
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800429 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700430 public void onSaveInstanceState(Bundle outState) {
431 super.onSaveInstanceState(outState);
432
433 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
434 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
435 }
436 }
437
438 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700439 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800440 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700441
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800442 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700443 if (mNfcEnabler != null) {
444 mNfcEnabler.pause();
445 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700446 if (mNsdEnabler != null) {
447 mNsdEnabler.pause();
448 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800449 }
Danica Chang32711b62010-08-10 18:41:29 -0700450
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500451 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700452 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800453 if (requestCode == REQUEST_CODE_EXIT_ECM) {
454 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500455 // Set Airplane mode based on the return value and checkbox state
456 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
457 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500458 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400459 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500460 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700461
462 @Override
463 protected int getHelpResource() {
464 return R.string.help_url_more_networks;
465 }
David Braun4e9f04d2013-09-16 13:45:42 -0700466
467 @Override
468 public boolean onPreferenceChange(Preference preference, Object newValue) {
469 if (preference == mSmsApplicationPreference && newValue != null) {
470 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
471 updateSmsApplicationSetting();
472 return true;
473 }
474 return false;
475 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800476}