blob: e9b7419767d9675878d52730d772ffef4caf020a [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.
250 if (mTm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
251 return false;
252 }
253 int simState = mTm.getSimState();
254 return simState != TelephonyManager.SIM_STATE_ABSENT &&
255 simState != TelephonyManager.SIM_STATE_UNKNOWN;
256 }
257
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800258 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700259 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800260 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700261 if (savedInstanceState != null) {
262 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
263 }
264 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
265
266 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
267 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800268
269 addPreferencesFromResource(R.xml.wireless_settings);
270
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700271 final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER;
272
Amith Yamasanid7993472010-08-18 13:59:28 -0700273 final Activity activity = getActivity();
Gilles Debunnee78c1872011-06-20 15:00:07 -0700274 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Nick Pellyad50ba02010-09-22 10:55:13 -0700275 CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500276 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Irfan Sheriff536c3d72012-04-17 23:17:46 -0700277 CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800278
Gilles Debunnee78c1872011-06-20 15:00:07 -0700279 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500280 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700281
David Braun4e9f04d2013-09-16 13:45:42 -0700282 mSmsApplicationPreference = (SmsListPreference) findPreference(KEY_SMS_APPLICATION);
283 mSmsApplicationPreference.setOnPreferenceChangeListener(this);
284
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700285 // Remove NSD checkbox by default
286 getPreferenceScreen().removePreference(nsd);
287 //mNsdEnabler = new NsdEnabler(activity, nsd);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800288
Christopher Tate6a5929b2012-09-10 15:39:05 -0700289 String toggleable = Settings.Global.getString(activity.getContentResolver(),
290 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800291
tk.mun7c5c1652011-10-13 22:56:18 +0900292 //enable/disable wimax depending on the value in config.xml
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700293 boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900294 com.android.internal.R.bool.config_wimaxEnabled);
295 if (!isWimaxEnabled) {
296 PreferenceScreen root = getPreferenceScreen();
297 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
298 if (ps != null) root.removePreference(ps);
299 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700300 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900301 && isWimaxEnabled) {
302 Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS);
303 ps.setDependency(KEY_TOGGLE_AIRPLANE);
304 }
305 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400306 protectByRestrictions(KEY_WIMAX_SETTINGS);
307
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800308 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700309 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800310 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
311 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700312 if (isSecondaryUser) { // Disable VPN
313 removePreference(KEY_VPN_SETTINGS);
314 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400315 protectByRestrictions(KEY_VPN_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800316 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700317 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700318 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700319 }
320
Nick Pelly9894d4a2011-08-09 07:10:16 -0700321 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700322 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700323 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500324 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700325 }
326
Nick Pellyad50ba02010-09-22 10:55:13 -0700327 // Remove NFC if its not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500328 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
329 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700330 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500331 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700332 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800333 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800334
Wink Saville5d5a2692013-06-29 07:54:13 -0700335 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700336 if (isSecondaryUser || Utils.isWifiOnly(getActivity())) {
337 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700338 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800339 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400340 protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS);
341 protectByRestrictions(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800342
David Braun4e9f04d2013-09-16 13:45:42 -0700343 // Remove SMS Application if the device does not support SMS
344 if (!isSmsSupported()) {
345 removePreference(KEY_SMS_APPLICATION);
346 }
347
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900348 // Remove Airplane Mode settings if it's a stationary device such as a TV.
349 if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
350 removePreference(KEY_TOGGLE_AIRPLANE);
351 }
352
Oscar Montemayor05411892010-08-03 16:56:09 -0700353 // Enable Proxy selector settings if allowed.
354 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Amith Yamasanid7993472010-08-18 13:59:28 -0700355 DevicePolicyManager mDPM = (DevicePolicyManager)
356 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800357 // proxy UI disabled until we have better app support
358 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700359 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
360
Amith Yamasani0f85c482011-02-23 17:19:11 -0800361 // Disable Tethering if it's not allowed or if it's a wifi-only device
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800362 ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700363 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700364 if (isSecondaryUser || !cm.isTetheringSupported()) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800365 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700366 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700367 Preference p = findPreference(KEY_TETHER_SETTINGS);
Jeff Sharkeya83a24f2011-09-16 01:52:39 -0700368 p.setTitle(Utils.getTetheringLabel(cm));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800369 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400370 protectByRestrictions(KEY_TETHER_SETTINGS);
Jake Hambyef57ed72012-06-21 10:59:22 -0700371
372 // Enable link to CMAS app settings depending on the value in config.xml.
373 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
374 com.android.internal.R.bool.config_cellBroadcastAppLinks);
375 try {
376 if (isCellBroadcastAppLinkEnabled) {
377 PackageManager pm = getPackageManager();
378 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
379 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
380 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
381 }
382 }
383 } catch (IllegalArgumentException ignored) {
384 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
385 }
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700386 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700387 PreferenceScreen root = getPreferenceScreen();
388 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
389 if (ps != null) root.removePreference(ps);
390 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400391 protectByRestrictions(KEY_CELL_BROADCAST_SETTINGS);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800392 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800393
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800394 @Override
David Braun4e9f04d2013-09-16 13:45:42 -0700395 public void onStart() {
396 super.onStart();
397
398 initSmsApplicationSetting();
399 }
400
401 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700402 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800403 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700404
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800405 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700406 if (mNfcEnabler != null) {
407 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500408 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700409 if (mNsdEnabler != null) {
410 mNsdEnabler.resume();
411 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800412 }
Danica Chang32711b62010-08-10 18:41:29 -0700413
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800414 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700415 public void onSaveInstanceState(Bundle outState) {
416 super.onSaveInstanceState(outState);
417
418 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
419 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
420 }
421 }
422
423 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700424 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800425 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700426
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800427 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700428 if (mNfcEnabler != null) {
429 mNfcEnabler.pause();
430 }
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700431 if (mNsdEnabler != null) {
432 mNsdEnabler.pause();
433 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800434 }
Danica Chang32711b62010-08-10 18:41:29 -0700435
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500436 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700437 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800438 if (requestCode == REQUEST_CODE_EXIT_ECM) {
439 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500440 // Set Airplane mode based on the return value and checkbox state
441 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
442 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500443 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400444 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500445 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700446
447 @Override
448 protected int getHelpResource() {
449 return R.string.help_url_more_networks;
450 }
David Braun4e9f04d2013-09-16 13:45:42 -0700451
452 @Override
453 public boolean onPreferenceChange(Preference preference, Object newValue) {
454 if (preference == mSmsApplicationPreference && newValue != null) {
455 SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
456 updateSmsApplicationSetting();
457 return true;
458 }
459 return false;
460 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800461}