blob: 436b7bc4df8dc167696872e02ddc6321cf4fc183 [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;
Amith Yamasanid7993472010-08-18 13:59:28 -070033import android.os.Bundle;
Amith Yamasanid7993472010-08-18 13:59:28 -070034import android.os.SystemProperties;
Amith Yamasani9627a8e2012-09-23 12:54:14 -070035import android.os.UserHandle;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040036import android.os.UserManager;
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;
41import android.provider.Settings;
Wink Saville5d5a2692013-06-29 07:54:13 -070042import android.telephony.TelephonyManager;
43import android.text.TextUtils;
44import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070045
46import com.android.internal.telephony.SmsApplication;
47import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070048import com.android.internal.telephony.TelephonyIntents;
49import com.android.internal.telephony.TelephonyProperties;
50import com.android.settings.nfc.NfcEnabler;
51
David Braun4e9f04d2013-09-16 13:45:42 -070052import java.util.Collection;
53
54public class WirelessSettings extends RestrictedSettingsFragment
55 implements OnPreferenceChangeListener {
Robert Greenwalt4929e912013-07-16 13:09:24 -070056 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080057
58 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070059 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090060 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050061 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070062 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080063 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070064 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080065 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070066 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
David Braun4e9f04d2013-09-16 13:45:42 -070067 private static final String KEY_SMS_APPLICATION = "sms_application";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070068 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070069 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070070
Chouting Zhang71cc49e2009-08-28 14:36:35 -050071 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
72 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080073
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080074 private AirplaneModeEnabler mAirplaneModeEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050075 private CheckBoxPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070076 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050077 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070078 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050079
Wink Saville5d5a2692013-06-29 07:54:13 -070080 private ConnectivityManager mCm;
81 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070082 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040083 private UserManager mUm;
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
Jeff Davidsonb9558d92014-03-25 12:21:30 -070088 private AppListPreference mSmsApplicationPreference;
David Braun4e9f04d2013-09-16 13:45:42 -070089
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
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080095 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -050096 * 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 initSmsApplicationSetting() {
178 log("initSmsApplicationSetting:");
179 Collection<SmsApplicationData> smsApplications =
180 SmsApplication.getApplicationCollection(getActivity());
181
182 // If the list is empty the dialog will be empty, but we will not crash.
183 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700184 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700185 int i = 0;
186 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700187 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700188 i++;
189 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700190 String defaultPackageName = null;
191 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
192 if (appName != null) {
193 defaultPackageName = appName.getPackageName();
194 }
195 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700196 }
197
Wink Saville5d5a2692013-06-29 07:54:13 -0700198 @Override
199 public Dialog onCreateDialog(int dialogId) {
200 log("onCreateDialog: dialogId=" + dialogId);
201 switch (dialogId) {
202 case MANAGE_MOBILE_PLAN_DIALOG_ID:
203 return new AlertDialog.Builder(getActivity())
204 .setMessage(mManageMobilePlanMessage)
205 .setCancelable(false)
206 .setPositiveButton(com.android.internal.R.string.ok,
207 new DialogInterface.OnClickListener() {
208 @Override
209 public void onClick(DialogInterface dialog, int id) {
210 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
211 mManageMobilePlanMessage = null;
212 }
213 })
214 .create();
215 }
216 return super.onCreateDialog(dialogId);
217 }
218
219 private void log(String s) {
220 Log.d(TAG, s);
221 }
222
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800223 public static boolean isRadioAllowed(Context context, String type) {
224 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
225 return true;
226 }
227 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700228 String toggleable = Settings.Global.getString(context.getContentResolver(),
229 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800230 return toggleable != null && toggleable.contains(type);
231 }
232
David Braun4e9f04d2013-09-16 13:45:42 -0700233 private boolean isSmsSupported() {
234 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500235 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700236 }
237
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800238 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700239 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800240 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700241 if (savedInstanceState != null) {
242 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
243 }
244 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
245
246 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
247 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700248 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400249 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800250
251 addPreferencesFromResource(R.xml.wireless_settings);
252
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700253 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
254
Amith Yamasanid7993472010-08-18 13:59:28 -0700255 final Activity activity = getActivity();
Gilles Debunnee78c1872011-06-20 15:00:07 -0700256 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Nick Pellyad50ba02010-09-22 10:55:13 -0700257 CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500258 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700259 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800260
Gilles Debunnee78c1872011-06-20 15:00:07 -0700261 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500262 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700263
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700264 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
David Braun4e9f04d2013-09-16 13:45:42 -0700265 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700266 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700267
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700268 // Remove NSD checkbox by default
269 getPreferenceScreen().removePreference(nsd);
270 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800271
Christopher Tate6a5929b2012-09-10 15:39:05 -0700272 String toggleable = Settings.Global.getString(activity.getContentResolver(),
273 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800274
tk.mun7c5c1652011-10-13 22:56:18 +0900275 //enable/disable wimax depending on the value in config.xml
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700276 boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900277 com.android.internal.R.bool.config_wimaxEnabled);
278 if (!isWimaxEnabled) {
279 PreferenceScreen root = getPreferenceScreen();
280 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
281 if (ps != null) root.removePreference(ps);
282 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700283 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900284 && isWimaxEnabled) {
285 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
286 ps.setDependency(KEY_TOGGLE_AIRPLANE);
287 }
288 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400289 protectByRestrictions(KEY_WIMAX_SETTINGS);
290
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800291 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700292 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800293 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
294 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400295 // Disable VPN.
296 if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700297 removePreference(KEY_VPN_SETTINGS);
298 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400299
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800300 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700301 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700302 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700303 }
304
Nick Pelly9894d4a2011-08-09 07:10:16 -0700305 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700306 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700307 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500308 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700309 }
310
Nick Pellyad50ba02010-09-22 10:55:13 -0700311 // Remove NFC if its not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500312 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
313 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700314 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500315 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700316 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800317 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800318
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400319 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
320 // if it's a wifi-only device, or if the settings are restricted.
321 if (isSecondaryUser || Utils.isWifiOnly(getActivity())
322 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700323 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700324 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800325 }
Sungmin Choi24903152013-10-15 16:11:55 -0700326 // Remove Mobile Network Settings and Manage Mobile Plan
327 // if config_show_mobile_plan sets false.
328 boolean isMobilePlanEnabled = this.getResources().getBoolean(
329 R.bool.config_show_mobile_plan);
330 if (!isMobilePlanEnabled) {
331 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
332 if (pref != null) {
333 removePreference(KEY_MANAGE_MOBILE_PLAN);
334 }
335 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800336
David Braun4e9f04d2013-09-16 13:45:42 -0700337 // Remove SMS Application if the device does not support SMS
338 if (!isSmsSupported()) {
339 removePreference(KEY_SMS_APPLICATION);
340 }
341
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900342 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700343 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900344 removePreference(KEY_TOGGLE_AIRPLANE);
345 }
346
Oscar Montemayor05411892010-08-03 16:56:09 -0700347 // Enable Proxy selector settings if allowed.
348 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Amith Yamasanid7993472010-08-18 13:59:28 -0700349 DevicePolicyManager mDPM = (DevicePolicyManager)
350 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800351 // proxy UI disabled until we have better app support
352 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700353 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
354
Amith Yamasani0f85c482011-02-23 17:19:11 -0800355 // Disable Tethering if it's not allowed or if it's a wifi-only device
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800356 ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700357 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400358 if (isSecondaryUser || !cm.isTetheringSupported()
359 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800360 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700361 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700362 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700363 p.setTitle(Utils.getTetheringLabel(cm));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800364 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700365
366 // Enable link to CMAS app settings depending on the value in config.xml.
367 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
368 com.android.internal.R.bool.config_cellBroadcastAppLinks);
369 try {
370 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700371 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700372 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
373 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
374 }
375 }
376 } catch (IllegalArgumentException ignored) {
377 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
378 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400379 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled
380 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700381 PreferenceScreen root = getPreferenceScreen();
382 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
383 if (ps != null) root.removePreference(ps);
384 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800385 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800386
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800387 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700388 public void onStart() {
389 super.onStart();
390
391 initSmsApplicationSetting();
392 }
393
394 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700395 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800396 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700397
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800398 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700399 if (mNfcEnabler != null) {
400 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500401 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700402 if (mNsdEnabler != null) {
403 mNsdEnabler.resume();
404 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800405 }
Danica Chang32711b62010-08-10 18:41:29 -0700406
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800407 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700408 public void onSaveInstanceState(Bundle outState) {
409 super.onSaveInstanceState(outState);
410
411 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
412 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
413 }
414 }
415
416 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700417 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800418 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700419
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800420 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700421 if (mNfcEnabler != null) {
422 mNfcEnabler.pause();
423 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700424 if (mNsdEnabler != null) {
425 mNsdEnabler.pause();
426 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800427 }
Danica Chang32711b62010-08-10 18:41:29 -0700428
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500429 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700430 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800431 if (requestCode == REQUEST_CODE_EXIT_ECM) {
432 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500433 // Set Airplane mode based on the return value and checkbox state
434 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
435 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500436 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400437 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500438 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700439
440 @Override
441 protected int getHelpResource() {
442 return R.string.help_url_more_networks;
443 }
David Braun4e9f04d2013-09-16 13:45:42 -0700444
445 @Override
446 public boolean onPreferenceChange(Preference preference, Object newValue) {
447 if (preference == mSmsApplicationPreference && newValue != null) {
448 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700449 return true;
450 }
451 return false;
452 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800453}