blob: fd2e9456a78f662c62e62075d8f3ff2d7942bb14 [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;
Amith Yamasanid7993472010-08-18 13:59:28 -070036import android.preference.CheckBoxPreference;
37import android.preference.Preference;
David Braun4e9f04d2013-09-16 13:45:42 -070038import android.preference.Preference.OnPreferenceChangeListener;
Amith Yamasanid7993472010-08-18 13:59:28 -070039import android.preference.PreferenceScreen;
40import android.provider.Settings;
Wink Saville5d5a2692013-06-29 07:54:13 -070041import android.telephony.TelephonyManager;
42import android.text.TextUtils;
43import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070044
45import com.android.internal.telephony.SmsApplication;
46import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Gilles Debunnee78c1872011-06-20 15:00:07 -070047import com.android.internal.telephony.TelephonyIntents;
48import com.android.internal.telephony.TelephonyProperties;
49import com.android.settings.nfc.NfcEnabler;
50
David Braun4e9f04d2013-09-16 13:45:42 -070051import java.util.Collection;
52
53public class WirelessSettings extends RestrictedSettingsFragment
54 implements OnPreferenceChangeListener {
Robert Greenwalt4929e912013-07-16 13:09:24 -070055 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080056
57 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070058 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090059 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050060 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070061 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080062 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070063 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080064 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070065 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
David Braun4e9f04d2013-09-16 13:45:42 -070066 private static final String KEY_SMS_APPLICATION = "sms_application";
Irfan Sheriff536c3d72012-04-17 23:17:46 -070067 private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery
Jake Hambyef57ed72012-06-21 10:59:22 -070068 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070069
Chouting Zhang71cc49e2009-08-28 14:36:35 -050070 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
71 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080072
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080073 private AirplaneModeEnabler mAirplaneModeEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050074 private CheckBoxPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070075 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050076 private NfcAdapter mNfcAdapter;
Irfan Sheriff536c3d72012-04-17 23:17:46 -070077 private NsdEnabler mNsdEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050078
Wink Saville5d5a2692013-06-29 07:54:13 -070079 private ConnectivityManager mCm;
80 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070081 private PackageManager mPm;
Wink Saville5d5a2692013-06-29 07:54:13 -070082
83 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
84 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
85
Jeff Davidsonb9558d92014-03-25 12:21:30 -070086 private AppListPreference mSmsApplicationPreference;
David Braun4e9f04d2013-09-16 13:45:42 -070087
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -040088 public WirelessSettings() {
89 super(null);
90 }
Chouting Zhang71cc49e2009-08-28 14:36:35 -050091 /**
92 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080093 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -050094 * preference click events.
95 */
96 @Override
97 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Geoffrey Borggaard6e1102d2013-08-07 14:57:43 -040098 if (ensurePinRestrictedPreference(preference)) {
99 return true;
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400100 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700101 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800102 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
103 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500104 // In ECM mode launch ECM app dialog
105 startActivityForResult(
106 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
107 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500108 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700109 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
110 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500111 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800112 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700113 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500114 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800115
Wink Saville5d5a2692013-06-29 07:54:13 -0700116 private String mManageMobilePlanMessage;
Wink Saville7bee4c22013-08-29 19:58:09 -0700117 private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION
118 = "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION";
Wink Saville5d5a2692013-06-29 07:54:13 -0700119 public void onManageMobilePlanClick() {
120 log("onManageMobilePlanClick:");
121 mManageMobilePlanMessage = null;
122 Resources resources = getActivity().getResources();
123
Wink Savillee24e5962013-08-28 14:26:27 -0700124 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700125 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700126 // Check for carrier apps that can handle provisioning first
127 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
128 provisioningIntent.addCategory(TelephonyIntents.CATEGORY_MCCMNC_PREFIX
129 + mTm.getSimOperator());
130 if (mPm.resolveActivity(provisioningIntent, 0 /* flags */) != null) {
131 startActivity(provisioningIntent);
132 return;
133 }
134
Wink Saville5d5a2692013-06-29 07:54:13 -0700135 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700136 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700137 if (!TextUtils.isEmpty(url)) {
Wink Saville7bee4c22013-08-29 19:58:09 -0700138 Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
Wink Savillee24e5962013-08-28 14:26:27 -0700139 intent.putExtra("EXTRA_URL", url);
140 Context context = getActivity().getBaseContext();
141 context.sendBroadcast(intent);
Wink Saville5d5a2692013-06-29 07:54:13 -0700142 mManageMobilePlanMessage = null;
143 } else {
144 // No provisioning URL
145 String operatorName = mTm.getSimOperatorName();
146 if (TextUtils.isEmpty(operatorName)) {
147 // Use NetworkOperatorName as second choice in case there is no
148 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
149 operatorName = mTm.getNetworkOperatorName();
150 if (TextUtils.isEmpty(operatorName)) {
151 mManageMobilePlanMessage = resources.getString(
152 R.string.mobile_unknown_sim_operator);
153 } else {
154 mManageMobilePlanMessage = resources.getString(
155 R.string.mobile_no_provisioning_url, operatorName);
156 }
157 } else {
158 mManageMobilePlanMessage = resources.getString(
159 R.string.mobile_no_provisioning_url, operatorName);
160 }
161 }
162 } else if (mTm.hasIccCard() == false) {
163 // No sim card
164 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
165 } else {
166 // NetworkInfo is null, there is no connection
167 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
168 }
169 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
170 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
171 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
172 }
173 }
174
David Braun4e9f04d2013-09-16 13:45:42 -0700175 private void initSmsApplicationSetting() {
176 log("initSmsApplicationSetting:");
177 Collection<SmsApplicationData> smsApplications =
178 SmsApplication.getApplicationCollection(getActivity());
179
180 // If the list is empty the dialog will be empty, but we will not crash.
181 int count = smsApplications.size();
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700182 String[] packageNames = new String[count];
David Braun4e9f04d2013-09-16 13:45:42 -0700183 int i = 0;
184 for (SmsApplicationData smsApplicationData : smsApplications) {
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700185 packageNames[i] = smsApplicationData.mPackageName;
David Braun4e9f04d2013-09-16 13:45:42 -0700186 i++;
187 }
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700188 String defaultPackageName = null;
189 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
190 if (appName != null) {
191 defaultPackageName = appName.getPackageName();
192 }
193 mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName);
David Braun4e9f04d2013-09-16 13:45:42 -0700194 }
195
Wink Saville5d5a2692013-06-29 07:54:13 -0700196 @Override
197 public Dialog onCreateDialog(int dialogId) {
198 log("onCreateDialog: dialogId=" + dialogId);
199 switch (dialogId) {
200 case MANAGE_MOBILE_PLAN_DIALOG_ID:
201 return new AlertDialog.Builder(getActivity())
202 .setMessage(mManageMobilePlanMessage)
203 .setCancelable(false)
204 .setPositiveButton(com.android.internal.R.string.ok,
205 new DialogInterface.OnClickListener() {
206 @Override
207 public void onClick(DialogInterface dialog, int id) {
208 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
209 mManageMobilePlanMessage = null;
210 }
211 })
212 .create();
213 }
214 return super.onCreateDialog(dialogId);
215 }
216
217 private void log(String s) {
218 Log.d(TAG, s);
219 }
220
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800221 public static boolean isRadioAllowed(Context context, String type) {
222 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
223 return true;
224 }
225 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700226 String toggleable = Settings.Global.getString(context.getContentResolver(),
227 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800228 return toggleable != null && toggleable.contains(type);
229 }
230
David Braun4e9f04d2013-09-16 13:45:42 -0700231 private boolean isSmsSupported() {
232 // Some tablet has sim card but could not do telephony operations. Skip those.
Dave Daynarda3c0a532013-12-29 03:56:58 -0500233 return mTm.isSmsCapable();
David Braun4e9f04d2013-09-16 13:45:42 -0700234 }
235
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800236 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700237 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800238 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700239 if (savedInstanceState != null) {
240 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
241 }
242 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
243
244 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
245 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700246 mPm = getPackageManager();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800247
248 addPreferencesFromResource(R.xml.wireless_settings);
249
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700250 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
251
Amith Yamasanid7993472010-08-18 13:59:28 -0700252 final Activity activity = getActivity();
Gilles Debunnee78c1872011-06-20 15:00:07 -0700253 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Nick Pellyad50ba02010-09-22 10:55:13 -0700254 CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500255 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700256 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800257
Gilles Debunnee78c1872011-06-20 15:00:07 -0700258 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500259 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700260
Jeff Davidsonb9558d92014-03-25 12:21:30 -0700261 mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
David Braun4e9f04d2013-09-16 13:45:42 -0700262 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700263 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700264
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700265 // Remove NSD checkbox by default
266 getPreferenceScreen().removePreference(nsd);
267 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800268
Christopher Tate6a5929b2012-09-10 15:39:05 -0700269 String toggleable = Settings.Global.getString(activity.getContentResolver(),
270 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800271
tk.mun7c5c1652011-10-13 22:56:18 +0900272 //enable/disable wimax depending on the value in config.xml
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700273 boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900274 com.android.internal.R.bool.config_wimaxEnabled);
275 if (!isWimaxEnabled) {
276 PreferenceScreen root = getPreferenceScreen();
277 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
278 if (ps != null) root.removePreference(ps);
279 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700280 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900281 && isWimaxEnabled) {
282 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
283 ps.setDependency(KEY_TOGGLE_AIRPLANE);
284 }
285 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400286 protectByRestrictions(KEY_WIMAX_SETTINGS);
287
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800288 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700289 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800290 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
291 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700292 if (isSecondaryUser) { // Disable VPN
293 removePreference(KEY_VPN_SETTINGS);
294 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400295 protectByRestrictions(KEY_VPN_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800296 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700297 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700298 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700299 }
300
Nick Pelly9894d4a2011-08-09 07:10:16 -0700301 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700302 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700303 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500304 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700305 }
306
Nick Pellyad50ba02010-09-22 10:55:13 -0700307 // Remove NFC if its not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500308 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
309 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700310 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500311 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700312 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800313 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800314
Wink Saville5d5a2692013-06-29 07:54:13 -0700315 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700316 if (isSecondaryUser || Utils.isWifiOnly(getActivity())) {
317 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700318 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800319 }
Sungmin Choi24903152013-10-15 16:11:55 -0700320 // Remove Mobile Network Settings and Manage Mobile Plan
321 // if config_show_mobile_plan sets false.
322 boolean isMobilePlanEnabled = this.getResources().getBoolean(
323 R.bool.config_show_mobile_plan);
324 if (!isMobilePlanEnabled) {
325 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
326 if (pref != null) {
327 removePreference(KEY_MANAGE_MOBILE_PLAN);
328 }
329 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400330 protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS);
331 protectByRestrictions(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800332
David Braun4e9f04d2013-09-16 13:45:42 -0700333 // Remove SMS Application if the device does not support SMS
334 if (!isSmsSupported()) {
335 removePreference(KEY_SMS_APPLICATION);
336 }
337
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900338 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700339 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900340 removePreference(KEY_TOGGLE_AIRPLANE);
341 }
342
Oscar Montemayor05411892010-08-03 16:56:09 -0700343 // Enable Proxy selector settings if allowed.
344 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Amith Yamasanid7993472010-08-18 13:59:28 -0700345 DevicePolicyManager mDPM = (DevicePolicyManager)
346 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800347 // proxy UI disabled until we have better app support
348 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700349 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
350
Amith Yamasani0f85c482011-02-23 17:19:11 -0800351 // Disable Tethering if it's not allowed or if it's a wifi-only device
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800352 ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700353 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700354 if (isSecondaryUser || !cm.isTetheringSupported()) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800355 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700356 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700357 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700358 p.setTitle(Utils.getTetheringLabel(cm));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800359 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400360 protectByRestrictions(KEY_TETHER_SETTINGS);
Jake Hambyef57ed72012-06-21 10:59:22 -0700361
362 // Enable link to CMAS app settings depending on the value in config.xml.
363 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
364 com.android.internal.R.bool.config_cellBroadcastAppLinks);
365 try {
366 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700367 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700368 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
369 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
370 }
371 }
372 } catch (IllegalArgumentException ignored) {
373 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
374 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700375 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700376 PreferenceScreen root = getPreferenceScreen();
377 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
378 if (ps != null) root.removePreference(ps);
379 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400380 protectByRestrictions(KEY_CELL_BROADCAST_SETTINGS);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800381 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800382
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800383 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700384 public void onStart() {
385 super.onStart();
386
387 initSmsApplicationSetting();
388 }
389
390 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700391 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800392 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700393
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800394 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700395 if (mNfcEnabler != null) {
396 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500397 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700398 if (mNsdEnabler != null) {
399 mNsdEnabler.resume();
400 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800401 }
Danica Chang32711b62010-08-10 18:41:29 -0700402
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800403 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700404 public void onSaveInstanceState(Bundle outState) {
405 super.onSaveInstanceState(outState);
406
407 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
408 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
409 }
410 }
411
412 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700413 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800414 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700415
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800416 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700417 if (mNfcEnabler != null) {
418 mNfcEnabler.pause();
419 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700420 if (mNsdEnabler != null) {
421 mNsdEnabler.pause();
422 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800423 }
Danica Chang32711b62010-08-10 18:41:29 -0700424
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500425 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700426 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800427 if (requestCode == REQUEST_CODE_EXIT_ECM) {
428 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500429 // Set Airplane mode based on the return value and checkbox state
430 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
431 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500432 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400433 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500434 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700435
436 @Override
437 protected int getHelpResource() {
438 return R.string.help_url_more_networks;
439 }
David Braun4e9f04d2013-09-16 13:45:42 -0700440
441 @Override
442 public boolean onPreferenceChange(Preference preference, Object newValue) {
443 if (preference == mSmsApplicationPreference && newValue != null) {
444 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
David Braun4e9f04d2013-09-16 13:45:42 -0700445 return true;
446 }
447 return false;
448 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800449}