The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 2 | * Copyright (C) 2009 The Android Open Source Project |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package com.android.settings; |
| 18 | |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 19 | import java.util.HashSet; |
| 20 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 21 | import android.app.Activity; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 22 | import android.app.AlertDialog; |
| 23 | import android.app.Dialog; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 24 | import android.app.admin.DevicePolicyManager; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 25 | import android.content.Context; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 26 | import android.content.DialogInterface; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 27 | import android.content.Intent; |
Irfan Sheriff | 167d718 | 2011-09-07 14:51:11 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 29 | import android.content.res.Resources; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 30 | import android.net.ConnectivityManager; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 31 | import android.net.NetworkInfo; |
| 32 | import android.net.Uri; |
Nick Pelly | a57eace | 2010-10-15 01:19:43 -0700 | [diff] [blame] | 33 | import android.nfc.NfcAdapter; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 34 | import android.os.Bundle; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 35 | import android.os.SystemProperties; |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 36 | import android.os.UserHandle; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 37 | import android.preference.CheckBoxPreference; |
| 38 | import android.preference.Preference; |
| 39 | import android.preference.PreferenceScreen; |
| 40 | import android.provider.Settings; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 41 | import android.telephony.TelephonyManager; |
| 42 | import android.text.TextUtils; |
| 43 | import android.util.Log; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 44 | import com.android.internal.telephony.TelephonyIntents; |
| 45 | import com.android.internal.telephony.TelephonyProperties; |
| 46 | import com.android.settings.nfc.NfcEnabler; |
Irfan Sheriff | 536c3d7 | 2012-04-17 23:17:46 -0700 | [diff] [blame] | 47 | import com.android.settings.NsdEnabler; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 48 | |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 49 | public class WirelessSettings extends RestrictedSettingsFragment { |
Robert Greenwalt | 4929e91 | 2013-07-16 13:09:24 -0700 | [diff] [blame] | 50 | private static final String TAG = "WirelessSettings"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 51 | |
| 52 | private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 53 | private static final String KEY_TOGGLE_NFC = "toggle_nfc"; |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 54 | private static final String KEY_WIMAX_SETTINGS = "wimax_settings"; |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 55 | private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings"; |
Mike Lockwood | 83bcc98 | 2009-07-29 23:25:10 -0700 | [diff] [blame] | 56 | private static final String KEY_VPN_SETTINGS = "vpn_settings"; |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 57 | private static final String KEY_TETHER_SETTINGS = "tether_settings"; |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 58 | private static final String KEY_PROXY_SETTINGS = "proxy_settings"; |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 59 | private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings"; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 60 | private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan"; |
Irfan Sheriff | 536c3d7 | 2012-04-17 23:17:46 -0700 | [diff] [blame] | 61 | private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 62 | private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings"; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 63 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 64 | public static final String EXIT_ECM_RESULT = "exit_ecm_result"; |
| 65 | public static final int REQUEST_CODE_EXIT_ECM = 1; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 66 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 67 | private AirplaneModeEnabler mAirplaneModeEnabler; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 68 | private CheckBoxPreference mAirplaneModePreference; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 69 | private NfcEnabler mNfcEnabler; |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 70 | private NfcAdapter mNfcAdapter; |
Irfan Sheriff | 536c3d7 | 2012-04-17 23:17:46 -0700 | [diff] [blame] | 71 | private NsdEnabler mNsdEnabler; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 72 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 73 | private ConnectivityManager mCm; |
| 74 | private TelephonyManager mTm; |
| 75 | |
| 76 | private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1; |
| 77 | private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage"; |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 78 | private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>(); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 79 | |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 80 | public WirelessSettings() { |
| 81 | super(null); |
| 82 | } |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 83 | /** |
| 84 | * Invoked on each preference click in this hierarchy, overrides |
| 85 | * PreferenceActivity's implementation. Used to make sure we track the |
| 86 | * preference click events. |
| 87 | */ |
| 88 | @Override |
| 89 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 90 | if (mProtectedByRestictionsPrefs.contains(preference) && !hasChallengeSucceeded()) { |
| 91 | restrictionsPinCheck(RESTRICTIONS_PIN_SET); |
| 92 | return false; |
| 93 | } |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 94 | log("onPreferenceTreeClick: preference=" + preference); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 95 | if (preference == mAirplaneModePreference && Boolean.parseBoolean( |
| 96 | SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 97 | // In ECM mode launch ECM app dialog |
| 98 | startActivityForResult( |
| 99 | new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null), |
| 100 | REQUEST_CODE_EXIT_ECM); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 101 | return true; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 102 | } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) { |
| 103 | onManageMobilePlanClick(); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 104 | } |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 105 | // Let the intents be launched by the Preference manager |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 106 | return super.onPreferenceTreeClick(preferenceScreen, preference); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 107 | } |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 108 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 109 | private String mManageMobilePlanMessage; |
| 110 | |
| 111 | public void onManageMobilePlanClick() { |
| 112 | log("onManageMobilePlanClick:"); |
| 113 | mManageMobilePlanMessage = null; |
| 114 | Resources resources = getActivity().getResources(); |
| 115 | |
| 116 | NetworkInfo ni = mCm.getActiveNetworkInfo(); |
| 117 | if (mTm.hasIccCard() && (ni != null)) { |
| 118 | // Get provisioning URL |
Robert Greenwalt | 4929e91 | 2013-07-16 13:09:24 -0700 | [diff] [blame] | 119 | String url = mCm.getMobileProvisioningUrl(); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 120 | if (!TextUtils.isEmpty(url)) { |
| 121 | // Send user to provisioning webpage |
| 122 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 123 | intent.setData(Uri.parse(url)); |
| 124 | startActivity(intent); |
| 125 | mManageMobilePlanMessage = null; |
| 126 | } else { |
| 127 | // No provisioning URL |
| 128 | String operatorName = mTm.getSimOperatorName(); |
| 129 | if (TextUtils.isEmpty(operatorName)) { |
| 130 | // Use NetworkOperatorName as second choice in case there is no |
| 131 | // SPN (Service Provider Name on the SIM). Such as with T-mobile. |
| 132 | operatorName = mTm.getNetworkOperatorName(); |
| 133 | if (TextUtils.isEmpty(operatorName)) { |
| 134 | mManageMobilePlanMessage = resources.getString( |
| 135 | R.string.mobile_unknown_sim_operator); |
| 136 | } else { |
| 137 | mManageMobilePlanMessage = resources.getString( |
| 138 | R.string.mobile_no_provisioning_url, operatorName); |
| 139 | } |
| 140 | } else { |
| 141 | mManageMobilePlanMessage = resources.getString( |
| 142 | R.string.mobile_no_provisioning_url, operatorName); |
| 143 | } |
| 144 | } |
| 145 | } else if (mTm.hasIccCard() == false) { |
| 146 | // No sim card |
| 147 | mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card); |
| 148 | } else { |
| 149 | // NetworkInfo is null, there is no connection |
| 150 | mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet); |
| 151 | } |
| 152 | if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { |
| 153 | log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage); |
| 154 | showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID); |
| 155 | } |
| 156 | } |
| 157 | |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 158 | private void protectByRestrictions(String key) { |
| 159 | Preference pref = findPreference(key); |
| 160 | if (pref != null) { |
| 161 | mProtectedByRestictionsPrefs.add(pref); |
| 162 | } |
| 163 | } |
| 164 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 165 | @Override |
| 166 | public Dialog onCreateDialog(int dialogId) { |
| 167 | log("onCreateDialog: dialogId=" + dialogId); |
| 168 | switch (dialogId) { |
| 169 | case MANAGE_MOBILE_PLAN_DIALOG_ID: |
| 170 | return new AlertDialog.Builder(getActivity()) |
| 171 | .setMessage(mManageMobilePlanMessage) |
| 172 | .setCancelable(false) |
| 173 | .setPositiveButton(com.android.internal.R.string.ok, |
| 174 | new DialogInterface.OnClickListener() { |
| 175 | @Override |
| 176 | public void onClick(DialogInterface dialog, int id) { |
| 177 | log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id); |
| 178 | mManageMobilePlanMessage = null; |
| 179 | } |
| 180 | }) |
| 181 | .create(); |
| 182 | } |
| 183 | return super.onCreateDialog(dialogId); |
| 184 | } |
| 185 | |
| 186 | private void log(String s) { |
| 187 | Log.d(TAG, s); |
| 188 | } |
| 189 | |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 190 | public static boolean isRadioAllowed(Context context, String type) { |
| 191 | if (!AirplaneModeEnabler.isAirplaneModeOn(context)) { |
| 192 | return true; |
| 193 | } |
| 194 | // Here we use the same logic in onCreate(). |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 195 | String toggleable = Settings.Global.getString(context.getContentResolver(), |
| 196 | Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 197 | return toggleable != null && toggleable.contains(type); |
| 198 | } |
| 199 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 200 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 201 | public void onCreate(Bundle savedInstanceState) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 202 | super.onCreate(savedInstanceState); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 203 | if (savedInstanceState != null) { |
| 204 | mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG); |
| 205 | } |
| 206 | log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage); |
| 207 | |
| 208 | mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); |
| 209 | mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 210 | |
| 211 | addPreferencesFromResource(R.xml.wireless_settings); |
| 212 | |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 213 | final boolean isSecondaryUser = UserHandle.myUserId() != UserHandle.USER_OWNER; |
| 214 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 215 | final Activity activity = getActivity(); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 216 | mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE); |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 217 | CheckBoxPreference nfc = (CheckBoxPreference) findPreference(KEY_TOGGLE_NFC); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 218 | PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS); |
Irfan Sheriff | 536c3d7 | 2012-04-17 23:17:46 -0700 | [diff] [blame] | 219 | CheckBoxPreference nsd = (CheckBoxPreference) findPreference(KEY_TOGGLE_NSD); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 220 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 221 | mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 222 | mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam); |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 223 | |
| 224 | // Remove NSD checkbox by default |
| 225 | getPreferenceScreen().removePreference(nsd); |
| 226 | //mNsdEnabler = new NsdEnabler(activity, nsd); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 227 | |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 228 | String toggleable = Settings.Global.getString(activity.getContentResolver(), |
| 229 | Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 230 | |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 231 | //enable/disable wimax depending on the value in config.xml |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 232 | boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean( |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 233 | com.android.internal.R.bool.config_wimaxEnabled); |
| 234 | if (!isWimaxEnabled) { |
| 235 | PreferenceScreen root = getPreferenceScreen(); |
| 236 | Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS); |
| 237 | if (ps != null) root.removePreference(ps); |
| 238 | } else { |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 239 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX ) |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 240 | && isWimaxEnabled) { |
| 241 | Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS); |
| 242 | ps.setDependency(KEY_TOGGLE_AIRPLANE); |
| 243 | } |
| 244 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 245 | protectByRestrictions(KEY_WIMAX_SETTINGS); |
| 246 | |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 247 | // Manually set dependencies for Wifi when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 248 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 249 | findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
| 250 | } |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 251 | if (isSecondaryUser) { // Disable VPN |
| 252 | removePreference(KEY_VPN_SETTINGS); |
| 253 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 254 | protectByRestrictions(KEY_VPN_SETTINGS); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 255 | // Manually set dependencies for Bluetooth when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 256 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 257 | // No bluetooth-dependent items in the list. Code kept in case one is added later. |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 260 | // Manually set dependencies for NFC when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 261 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) { |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 262 | findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 263 | findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 266 | // Remove NFC if its not available |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 267 | mNfcAdapter = NfcAdapter.getDefaultAdapter(activity); |
| 268 | if (mNfcAdapter == null) { |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 269 | getPreferenceScreen().removePreference(nfc); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 270 | getPreferenceScreen().removePreference(androidBeam); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 271 | mNfcEnabler = null; |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 272 | } |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 273 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 274 | // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device. |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 275 | if (isSecondaryUser || Utils.isWifiOnly(getActivity())) { |
| 276 | removePreference(KEY_MOBILE_NETWORK_SETTINGS); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 277 | removePreference(KEY_MANAGE_MOBILE_PLAN); |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 278 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 279 | protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS); |
| 280 | protectByRestrictions(KEY_MANAGE_MOBILE_PLAN); |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 281 | |
Jaewan Kim | 2e41e3d | 2013-04-19 13:40:23 +0900 | [diff] [blame] | 282 | // Remove Airplane Mode settings if it's a stationary device such as a TV. |
| 283 | if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEVISION)) { |
| 284 | removePreference(KEY_TOGGLE_AIRPLANE); |
| 285 | } |
| 286 | |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 287 | // Enable Proxy selector settings if allowed. |
| 288 | Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 289 | DevicePolicyManager mDPM = (DevicePolicyManager) |
| 290 | activity.getSystemService(Context.DEVICE_POLICY_SERVICE); |
Robert Greenwalt | 6f3a98b | 2010-12-28 16:11:12 -0800 | [diff] [blame] | 291 | // proxy UI disabled until we have better app support |
| 292 | getPreferenceScreen().removePreference(mGlobalProxy); |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 293 | mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null); |
| 294 | |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 295 | // Disable Tethering if it's not allowed or if it's a wifi-only device |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 296 | ConnectivityManager cm = |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 297 | (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 298 | if (isSecondaryUser || !cm.isTetheringSupported()) { |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 299 | getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS)); |
Robert Greenwalt | e434bfb | 2010-05-08 15:20:24 -0700 | [diff] [blame] | 300 | } else { |
Robert Greenwalt | e434bfb | 2010-05-08 15:20:24 -0700 | [diff] [blame] | 301 | Preference p = findPreference(KEY_TETHER_SETTINGS); |
Jeff Sharkey | a83a24f | 2011-09-16 01:52:39 -0700 | [diff] [blame] | 302 | p.setTitle(Utils.getTetheringLabel(cm)); |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 303 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 304 | protectByRestrictions(KEY_TETHER_SETTINGS); |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 305 | |
| 306 | // Enable link to CMAS app settings depending on the value in config.xml. |
| 307 | boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean( |
| 308 | com.android.internal.R.bool.config_cellBroadcastAppLinks); |
| 309 | try { |
| 310 | if (isCellBroadcastAppLinkEnabled) { |
| 311 | PackageManager pm = getPackageManager(); |
| 312 | if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") |
| 313 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { |
| 314 | isCellBroadcastAppLinkEnabled = false; // CMAS app disabled |
| 315 | } |
| 316 | } |
| 317 | } catch (IllegalArgumentException ignored) { |
| 318 | isCellBroadcastAppLinkEnabled = false; // CMAS app not installed |
| 319 | } |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 320 | if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) { |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 321 | PreferenceScreen root = getPreferenceScreen(); |
| 322 | Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS); |
| 323 | if (ps != null) root.removePreference(ps); |
| 324 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 325 | protectByRestrictions(KEY_CELL_BROADCAST_SETTINGS); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 326 | } |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 327 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 328 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 329 | public void onResume() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 330 | super.onResume(); |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 331 | |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 332 | mAirplaneModeEnabler.resume(); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 333 | if (mNfcEnabler != null) { |
| 334 | mNfcEnabler.resume(); |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 335 | } |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 336 | if (mNsdEnabler != null) { |
| 337 | mNsdEnabler.resume(); |
| 338 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 339 | } |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 340 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 341 | @Override |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 342 | public void onSaveInstanceState(Bundle outState) { |
| 343 | super.onSaveInstanceState(outState); |
| 344 | |
| 345 | if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { |
| 346 | outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 351 | public void onPause() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 352 | super.onPause(); |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 353 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 354 | mAirplaneModeEnabler.pause(); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 355 | if (mNfcEnabler != null) { |
| 356 | mNfcEnabler.pause(); |
| 357 | } |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 358 | if (mNsdEnabler != null) { |
| 359 | mNsdEnabler.pause(); |
| 360 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 361 | } |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 362 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 363 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 364 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 365 | if (requestCode == REQUEST_CODE_EXIT_ECM) { |
| 366 | Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 367 | // Set Airplane mode based on the return value and checkbox state |
| 368 | mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes, |
| 369 | mAirplaneModePreference.isChecked()); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 370 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame^] | 371 | super.onActivityResult(requestCode, resultCode, data); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 372 | } |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame] | 373 | |
| 374 | @Override |
| 375 | protected int getHelpResource() { |
| 376 | return R.string.help_url_more_networks; |
| 377 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 378 | } |