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