blob: 6724cc129a6ef1ecfcd162a4f77f97199980aafb [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;
83
84 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
85 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
86
David Braun4e9f04d2013-09-16 13:45:42 -070087 private SmsListPreference mSmsApplicationPreference;
88
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -040089 public WirelessSettings() {
90 super(null);
91 }
Chouting Zhang71cc49e2009-08-28 14:36:35 -050092 /**
93 * Invoked on each preference click in this hierarchy, overrides
94 * PreferenceActivity's implementation. Used to make sure we track the
95 * preference click events.
96 */
97 @Override
98 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
Geoffrey Borggaard6e1102d2013-08-07 14:57:43 -040099 if (ensurePinRestrictedPreference(preference)) {
100 return true;
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400101 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700102 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800103 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
104 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500105 // In ECM mode launch ECM app dialog
106 startActivityForResult(
107 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
108 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500109 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700110 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
111 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500112 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800113 // Let the intents be launched by the Preference manager
Amith Yamasanid7993472010-08-18 13:59:28 -0700114 return super.onPreferenceTreeClick(preferenceScreen, preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500115 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800116
Wink Saville5d5a2692013-06-29 07:54:13 -0700117 private String mManageMobilePlanMessage;
Wink Saville7bee4c22013-08-29 19:58:09 -0700118 private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION
119 = "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION";
Wink Saville5d5a2692013-06-29 07:54:13 -0700120 public void onManageMobilePlanClick() {
121 log("onManageMobilePlanClick:");
122 mManageMobilePlanMessage = null;
123 Resources resources = getActivity().getResources();
124
Wink Savillee24e5962013-08-28 14:26:27 -0700125 NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700126 if (mTm.hasIccCard() && (ni != null)) {
127 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700128 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700129 if (!TextUtils.isEmpty(url)) {
Wink Saville7bee4c22013-08-29 19:58:09 -0700130 Intent intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
Wink Savillee24e5962013-08-28 14:26:27 -0700131 intent.putExtra("EXTRA_URL", url);
132 Context context = getActivity().getBaseContext();
133 context.sendBroadcast(intent);
Wink Saville5d5a2692013-06-29 07:54:13 -0700134 mManageMobilePlanMessage = null;
135 } else {
136 // No provisioning URL
137 String operatorName = mTm.getSimOperatorName();
138 if (TextUtils.isEmpty(operatorName)) {
139 // Use NetworkOperatorName as second choice in case there is no
140 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
141 operatorName = mTm.getNetworkOperatorName();
142 if (TextUtils.isEmpty(operatorName)) {
143 mManageMobilePlanMessage = resources.getString(
144 R.string.mobile_unknown_sim_operator);
145 } else {
146 mManageMobilePlanMessage = resources.getString(
147 R.string.mobile_no_provisioning_url, operatorName);
148 }
149 } else {
150 mManageMobilePlanMessage = resources.getString(
151 R.string.mobile_no_provisioning_url, operatorName);
152 }
153 }
154 } else if (mTm.hasIccCard() == false) {
155 // No sim card
156 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
157 } else {
158 // NetworkInfo is null, there is no connection
159 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
160 }
161 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
162 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
163 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
164 }
165 }
166
David Braun4e9f04d2013-09-16 13:45:42 -0700167 private void updateSmsApplicationSetting() {
168 log("updateSmsApplicationSetting:");
169 ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
170 if (appName != null) {
171 String packageName = appName.getPackageName();
172
173 CharSequence[] values = mSmsApplicationPreference.getEntryValues();
174 for (int i = 0; i < values.length; i++) {
175 if (packageName.contentEquals(values[i])) {
176 mSmsApplicationPreference.setValueIndex(i);
177 mSmsApplicationPreference.setSummary(mSmsApplicationPreference.getEntries()[i]);
178 break;
179 }
180 }
181 }
182 }
183
184 private void initSmsApplicationSetting() {
185 log("initSmsApplicationSetting:");
186 Collection<SmsApplicationData> smsApplications =
187 SmsApplication.getApplicationCollection(getActivity());
188
189 // If the list is empty the dialog will be empty, but we will not crash.
190 int count = smsApplications.size();
191 CharSequence[] entries = new CharSequence[count];
192 CharSequence[] entryValues = new CharSequence[count];
193 Drawable[] entryImages = new Drawable[count];
194
195 PackageManager packageManager = getPackageManager();
196 int i = 0;
197 for (SmsApplicationData smsApplicationData : smsApplications) {
198 entries[i] = smsApplicationData.mApplicationName;
199 entryValues[i] = smsApplicationData.mPackageName;
200 try {
201 entryImages[i] = packageManager.getApplicationIcon(smsApplicationData.mPackageName);
202 } catch (NameNotFoundException e) {
203 entryImages[i] = packageManager.getDefaultActivityIcon();
204 }
205 i++;
206 }
207 mSmsApplicationPreference.setEntries(entries);
208 mSmsApplicationPreference.setEntryValues(entryValues);
209 mSmsApplicationPreference.setEntryDrawables(entryImages);
210 updateSmsApplicationSetting();
211 }
212
Wink Saville5d5a2692013-06-29 07:54:13 -0700213 @Override
214 public Dialog onCreateDialog(int dialogId) {
215 log("onCreateDialog: dialogId=" + dialogId);
216 switch (dialogId) {
217 case MANAGE_MOBILE_PLAN_DIALOG_ID:
218 return new AlertDialog.Builder(getActivity())
219 .setMessage(mManageMobilePlanMessage)
220 .setCancelable(false)
221 .setPositiveButton(com.android.internal.R.string.ok,
222 new DialogInterface.OnClickListener() {
223 @Override
224 public void onClick(DialogInterface dialog, int id) {
225 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
226 mManageMobilePlanMessage = null;
227 }
228 })
229 .create();
230 }
231 return super.onCreateDialog(dialogId);
232 }
233
234 private void log(String s) {
235 Log.d(TAG, s);
236 }
237
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800238 public static boolean isRadioAllowed(Context context, String type) {
239 if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
240 return true;
241 }
242 // Here we use the same logic in onCreate().
Christopher Tate6a5929b2012-09-10 15:39:05 -0700243 String toggleable = Settings.Global.getString(context.getContentResolver(),
244 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800245 return toggleable != null && toggleable.contains(type);
246 }
247
David Braun4e9f04d2013-09-16 13:45:42 -0700248 private boolean isSmsSupported() {
249 // Some tablet has sim card but could not do telephony operations. Skip those.
David Braund5b60012013-10-01 17:10:46 -0700250 return (mTm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE);
David Braun4e9f04d2013-09-16 13:45:42 -0700251 }
252
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800253 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700254 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800255 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700256 if (savedInstanceState != null) {
257 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
258 }
259 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
260
261 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
262 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800263
264 addPreferencesFromResource(R.xml.wireless_settings);
265
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700266 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
267
Amith Yamasanid7993472010-08-18 13:59:28 -0700268 final Activity activity = getActivity();
Gilles Debunnee78c1872011-06-20 15:00:07 -0700269 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Nick Pellyad50ba02010-09-22 10:55:13 -0700270 CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500271 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700272 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800273
Gilles Debunnee78c1872011-06-20 15:00:07 -0700274 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500275 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700276
David Braun4e9f04d2013-09-16 13:45:42 -0700277 mSmsApplicationPreference = (SmsListPreference) findPreference(KEY_SMS_APPLICATION);
278 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
David Braunbe1f0a12013-09-20 14:15:32 -0700279 initSmsApplicationSetting();
David Braun4e9f04d2013-09-16 13:45:42 -0700280
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700281 // Remove NSD checkbox by default
282 getPreferenceScreen().removePreference(nsd);
283 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800284
Christopher Tate6a5929b2012-09-10 15:39:05 -0700285 String toggleable = Settings.Global.getString(activity.getContentResolver(),
286 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800287
tk.mun7c5c1652011-10-13 22:56:18 +0900288 //enable/disable wimax depending on the value in config.xml
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700289 boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900290 com.android.internal.R.bool.config_wimaxEnabled);
291 if (!isWimaxEnabled) {
292 PreferenceScreen root = getPreferenceScreen();
293 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
294 if (ps != null) root.removePreference(ps);
295 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700296 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900297 && isWimaxEnabled) {
298 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
299 ps.setDependency(KEY_TOGGLE_AIRPLANE);
300 }
301 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400302 protectByRestrictions(KEY_WIMAX_SETTINGS);
303
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800304 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700305 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800306 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
307 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700308 if (isSecondaryUser) { // Disable VPN
309 removePreference(KEY_VPN_SETTINGS);
310 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400311 protectByRestrictions(KEY_VPN_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800312 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700313 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700314 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700315 }
316
Nick Pelly9894d4a2011-08-09 07:10:16 -0700317 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700318 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700319 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500320 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700321 }
322
Nick Pellyad50ba02010-09-22 10:55:13 -0700323 // Remove NFC if its not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500324 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
325 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700326 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500327 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700328 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800329 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800330
Wink Saville5d5a2692013-06-29 07:54:13 -0700331 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700332 if (isSecondaryUser || Utils.isWifiOnly(getActivity())) {
333 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700334 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800335 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400336 protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS);
337 protectByRestrictions(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800338
David Braun4e9f04d2013-09-16 13:45:42 -0700339 // Remove SMS Application if the device does not support SMS
340 if (!isSmsSupported()) {
341 removePreference(KEY_SMS_APPLICATION);
342 }
343
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900344 // Remove Airplane Mode settings if it's a stationary device such as a TV.
345 if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
346 removePreference(KEY_TOGGLE_AIRPLANE);
347 }
348
Oscar Montemayor05411892010-08-03 16:56:09 -0700349 // Enable Proxy selector settings if allowed.
350 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Amith Yamasanid7993472010-08-18 13:59:28 -0700351 DevicePolicyManager mDPM = (DevicePolicyManager)
352 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800353 // proxy UI disabled until we have better app support
354 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700355 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
356
Amith Yamasani0f85c482011-02-23 17:19:11 -0800357 // Disable Tethering if it's not allowed or if it's a wifi-only device
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800358 ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700359 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700360 if (isSecondaryUser || !cm.isTetheringSupported()) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800361 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700362 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700363 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700364 p.setTitle(Utils.getTetheringLabel(cm));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800365 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400366 protectByRestrictions(KEY_TETHER_SETTINGS);
Jake Hambyef57ed72012-06-21 10:59:22 -0700367
368 // Enable link to CMAS app settings depending on the value in config.xml.
369 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
370 com.android.internal.R.bool.config_cellBroadcastAppLinks);
371 try {
372 if (isCellBroadcastAppLinkEnabled) {
373 PackageManager pm = getPackageManager();
374 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
375 == 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());
452 updateSmsApplicationSetting();
453 return true;
454 }
455 return false;
456 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800457}