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 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 20 | import android.app.Activity; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 21 | import android.app.AlertDialog; |
| 22 | import android.app.Dialog; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 23 | import android.app.admin.DevicePolicyManager; |
Paul Jensen | d96c5fc | 2014-10-17 22:09:37 -0400 | [diff] [blame] | 24 | import android.content.ActivityNotFoundException; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 25 | import android.content.ComponentName; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 26 | import android.content.Context; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 27 | import android.content.DialogInterface; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 28 | import android.content.Intent; |
Irfan Sheriff | 167d718 | 2011-09-07 14:51:11 -0700 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 30 | import android.content.res.Resources; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 31 | import android.net.ConnectivityManager; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 32 | import android.net.NetworkInfo; |
Paul Jensen | d96c5fc | 2014-10-17 22:09:37 -0400 | [diff] [blame] | 33 | import android.net.Uri; |
Nick Pelly | a57eace | 2010-10-15 01:19:43 -0700 | [diff] [blame] | 34 | import android.nfc.NfcAdapter; |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 35 | import android.nfc.NfcManager; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 36 | import android.os.Bundle; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 37 | import android.os.SystemProperties; |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 38 | import android.os.UserHandle; |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 39 | import android.os.UserManager; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 40 | import android.preference.Preference; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 41 | import android.preference.Preference.OnPreferenceChangeListener; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 42 | import android.preference.PreferenceScreen; |
Fabrice Di Meglio | e3bced2 | 2014-08-06 10:22:52 -0700 | [diff] [blame] | 43 | import android.preference.SwitchPreference; |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 44 | import android.provider.SearchIndexableResource; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 45 | import android.provider.Settings; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 46 | import android.telephony.TelephonyManager; |
| 47 | import android.text.TextUtils; |
| 48 | import android.util.Log; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 49 | |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame^] | 50 | import com.android.ims.ImsConfig; |
| 51 | import com.android.ims.ImsManager; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 52 | import com.android.internal.telephony.SmsApplication; |
| 53 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 54 | import com.android.internal.telephony.TelephonyIntents; |
| 55 | import com.android.internal.telephony.TelephonyProperties; |
| 56 | import com.android.settings.nfc.NfcEnabler; |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 57 | import com.android.settings.search.BaseSearchIndexProvider; |
| 58 | import com.android.settings.search.Indexable; |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame^] | 59 | import com.android.settings.WifiCallingSettings; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 60 | |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 61 | import java.util.ArrayList; |
| 62 | import java.util.Arrays; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 63 | import java.util.Collection; |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 64 | import java.util.List; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 65 | |
Julia Reynolds | 00d19c7 | 2014-06-24 15:22:50 -0400 | [diff] [blame] | 66 | public class WirelessSettings extends SettingsPreferenceFragment |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 67 | implements OnPreferenceChangeListener, Indexable { |
Robert Greenwalt | 4929e91 | 2013-07-16 13:09:24 -0700 | [diff] [blame] | 68 | private static final String TAG = "WirelessSettings"; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 69 | |
| 70 | private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 71 | private static final String KEY_TOGGLE_NFC = "toggle_nfc"; |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 72 | private static final String KEY_WIMAX_SETTINGS = "wimax_settings"; |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 73 | private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings"; |
Mike Lockwood | 83bcc98 | 2009-07-29 23:25:10 -0700 | [diff] [blame] | 74 | private static final String KEY_VPN_SETTINGS = "vpn_settings"; |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 75 | private static final String KEY_TETHER_SETTINGS = "tether_settings"; |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 76 | private static final String KEY_PROXY_SETTINGS = "proxy_settings"; |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 77 | private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings"; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 78 | private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan"; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 79 | private static final String KEY_SMS_APPLICATION = "sms_application"; |
Irfan Sheriff | 536c3d7 | 2012-04-17 23:17:46 -0700 | [diff] [blame] | 80 | private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 81 | private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings"; |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame^] | 82 | private static final String KEY_WFC_SETTINGS = "wifi_calling_settings"; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 83 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 84 | public static final String EXIT_ECM_RESULT = "exit_ecm_result"; |
| 85 | public static final int REQUEST_CODE_EXIT_ECM = 1; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 86 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 87 | private AirplaneModeEnabler mAirplaneModeEnabler; |
Fabrice Di Meglio | e3bced2 | 2014-08-06 10:22:52 -0700 | [diff] [blame] | 88 | private SwitchPreference mAirplaneModePreference; |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 89 | private NfcEnabler mNfcEnabler; |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 90 | private NfcAdapter mNfcAdapter; |
Irfan Sheriff | 536c3d7 | 2012-04-17 23:17:46 -0700 | [diff] [blame] | 91 | private NsdEnabler mNsdEnabler; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 92 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 93 | private ConnectivityManager mCm; |
| 94 | private TelephonyManager mTm; |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 95 | private PackageManager mPm; |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 96 | private UserManager mUm; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 97 | |
| 98 | private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1; |
| 99 | private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage"; |
| 100 | |
Jeff Davidson | b9558d9 | 2014-03-25 12:21:30 -0700 | [diff] [blame] | 101 | private AppListPreference mSmsApplicationPreference; |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame^] | 102 | private PreferenceScreen mButtonWfc; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 103 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 104 | /** |
| 105 | * Invoked on each preference click in this hierarchy, overrides |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 106 | * PreferenceFragment's implementation. Used to make sure we track the |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 107 | * preference click events. |
| 108 | */ |
| 109 | @Override |
| 110 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 111 | log("onPreferenceTreeClick: preference=" + preference); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 112 | if (preference == mAirplaneModePreference && Boolean.parseBoolean( |
| 113 | SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 114 | // In ECM mode launch ECM app dialog |
| 115 | startActivityForResult( |
| 116 | new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null), |
| 117 | REQUEST_CODE_EXIT_ECM); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 118 | return true; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 119 | } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) { |
| 120 | onManageMobilePlanClick(); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 121 | } |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 122 | // Let the intents be launched by the Preference manager |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 123 | return super.onPreferenceTreeClick(preferenceScreen, preference); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 124 | } |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 125 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 126 | private String mManageMobilePlanMessage; |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 127 | public void onManageMobilePlanClick() { |
| 128 | log("onManageMobilePlanClick:"); |
| 129 | mManageMobilePlanMessage = null; |
| 130 | Resources resources = getActivity().getResources(); |
| 131 | |
Wink Saville | e24e596 | 2013-08-28 14:26:27 -0700 | [diff] [blame] | 132 | NetworkInfo ni = mCm.getProvisioningOrActiveNetworkInfo(); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 133 | if (mTm.hasIccCard() && (ni != null)) { |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 134 | // Check for carrier apps that can handle provisioning first |
| 135 | Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP); |
Diego Pontoriero | ff9f67d | 2014-08-11 18:25:51 -0700 | [diff] [blame] | 136 | List<String> carrierPackages = |
Diego Pontoriero | be7adcc | 2014-08-28 13:52:24 -0700 | [diff] [blame] | 137 | mTm.getCarrierPackageNamesForIntent(provisioningIntent); |
Diego Pontoriero | ff9f67d | 2014-08-11 18:25:51 -0700 | [diff] [blame] | 138 | if (carrierPackages != null && !carrierPackages.isEmpty()) { |
| 139 | if (carrierPackages.size() != 1) { |
| 140 | Log.w(TAG, "Multiple matching carrier apps found, launching the first."); |
| 141 | } |
| 142 | provisioningIntent.setPackage(carrierPackages.get(0)); |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 143 | startActivity(provisioningIntent); |
| 144 | return; |
| 145 | } |
| 146 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 147 | // Get provisioning URL |
Robert Greenwalt | 4929e91 | 2013-07-16 13:09:24 -0700 | [diff] [blame] | 148 | String url = mCm.getMobileProvisioningUrl(); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 149 | if (!TextUtils.isEmpty(url)) { |
Paul Jensen | d96c5fc | 2014-10-17 22:09:37 -0400 | [diff] [blame] | 150 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, |
| 151 | Intent.CATEGORY_APP_BROWSER); |
| 152 | intent.setData(Uri.parse(url)); |
| 153 | intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | |
| 154 | Intent.FLAG_ACTIVITY_NEW_TASK); |
| 155 | try { |
| 156 | startActivity(intent); |
| 157 | } catch (ActivityNotFoundException e) { |
| 158 | Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e); |
| 159 | } |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 160 | } else { |
| 161 | // No provisioning URL |
| 162 | String operatorName = mTm.getSimOperatorName(); |
| 163 | if (TextUtils.isEmpty(operatorName)) { |
| 164 | // Use NetworkOperatorName as second choice in case there is no |
| 165 | // SPN (Service Provider Name on the SIM). Such as with T-mobile. |
| 166 | operatorName = mTm.getNetworkOperatorName(); |
| 167 | if (TextUtils.isEmpty(operatorName)) { |
| 168 | mManageMobilePlanMessage = resources.getString( |
| 169 | R.string.mobile_unknown_sim_operator); |
| 170 | } else { |
| 171 | mManageMobilePlanMessage = resources.getString( |
| 172 | R.string.mobile_no_provisioning_url, operatorName); |
| 173 | } |
| 174 | } else { |
| 175 | mManageMobilePlanMessage = resources.getString( |
| 176 | R.string.mobile_no_provisioning_url, operatorName); |
| 177 | } |
| 178 | } |
| 179 | } else if (mTm.hasIccCard() == false) { |
| 180 | // No sim card |
| 181 | mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card); |
| 182 | } else { |
| 183 | // NetworkInfo is null, there is no connection |
| 184 | mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet); |
| 185 | } |
| 186 | if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { |
| 187 | log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage); |
| 188 | showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID); |
| 189 | } |
| 190 | } |
| 191 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 192 | private void initSmsApplicationSetting() { |
| 193 | log("initSmsApplicationSetting:"); |
| 194 | Collection<SmsApplicationData> smsApplications = |
| 195 | SmsApplication.getApplicationCollection(getActivity()); |
| 196 | |
| 197 | // If the list is empty the dialog will be empty, but we will not crash. |
| 198 | int count = smsApplications.size(); |
Jeff Davidson | b9558d9 | 2014-03-25 12:21:30 -0700 | [diff] [blame] | 199 | String[] packageNames = new String[count]; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 200 | int i = 0; |
| 201 | for (SmsApplicationData smsApplicationData : smsApplications) { |
Jeff Davidson | b9558d9 | 2014-03-25 12:21:30 -0700 | [diff] [blame] | 202 | packageNames[i] = smsApplicationData.mPackageName; |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 203 | i++; |
| 204 | } |
Jeff Davidson | b9558d9 | 2014-03-25 12:21:30 -0700 | [diff] [blame] | 205 | String defaultPackageName = null; |
| 206 | ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true); |
| 207 | if (appName != null) { |
| 208 | defaultPackageName = appName.getPackageName(); |
| 209 | } |
| 210 | mSmsApplicationPreference.setPackageNames(packageNames, defaultPackageName); |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 213 | @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 Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 238 | 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 Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 243 | String toggleable = Settings.Global.getString(context.getContentResolver(), |
| 244 | Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 245 | return toggleable != null && toggleable.contains(type); |
| 246 | } |
| 247 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 248 | private boolean isSmsSupported() { |
| 249 | // Some tablet has sim card but could not do telephony operations. Skip those. |
Dave Daynard | a3c0a53 | 2013-12-29 03:56:58 -0500 | [diff] [blame] | 250 | return mTm.isSmsCapable(); |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 251 | } |
| 252 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 253 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 254 | public void onCreate(Bundle savedInstanceState) { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 255 | super.onCreate(savedInstanceState); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 256 | 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); |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 263 | mPm = getPackageManager(); |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 264 | mUm = (UserManager) getSystemService(Context.USER_SERVICE); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 265 | |
| 266 | addPreferencesFromResource(R.xml.wireless_settings); |
| 267 | |
Amith Yamasani | 32505ac | 2014-11-12 13:46:43 -0800 | [diff] [blame] | 268 | final int myUserId = UserHandle.myUserId(); |
| 269 | final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER; |
| 270 | final boolean isRestrictedUser = mUm.getUserInfo(myUserId).isRestricted(); |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 271 | |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 272 | final Activity activity = getActivity(); |
Fabrice Di Meglio | e3bced2 | 2014-08-06 10:22:52 -0700 | [diff] [blame] | 273 | mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE); |
Fabrice Di Meglio | 4325f80 | 2014-08-15 14:14:17 -0700 | [diff] [blame] | 274 | SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 275 | PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS); |
Fabrice Di Meglio | daef2e2 | 2014-10-15 19:00:35 -0700 | [diff] [blame] | 276 | SwitchPreference nsd = (SwitchPreference) findPreference(KEY_TOGGLE_NSD); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 277 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 278 | mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 279 | mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam); |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 280 | |
Jeff Davidson | b9558d9 | 2014-03-25 12:21:30 -0700 | [diff] [blame] | 281 | mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION); |
Amith Yamasani | 32505ac | 2014-11-12 13:46:43 -0800 | [diff] [blame] | 282 | // Restricted users cannot currently read/write SMS. |
| 283 | if (isRestrictedUser) { |
| 284 | removePreference(KEY_SMS_APPLICATION); |
| 285 | } else { |
| 286 | mSmsApplicationPreference.setOnPreferenceChangeListener(this); |
| 287 | initSmsApplicationSetting(); |
| 288 | } |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 289 | |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame^] | 290 | if (ImsManager.isWfcEnabledByPlatform(activity)) { |
| 291 | mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS); |
| 292 | } else { |
| 293 | removePreference(KEY_WFC_SETTINGS); |
| 294 | } |
| 295 | |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 296 | // Remove NSD checkbox by default |
| 297 | getPreferenceScreen().removePreference(nsd); |
| 298 | //mNsdEnabler = new NsdEnabler(activity, nsd); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 299 | |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 300 | String toggleable = Settings.Global.getString(activity.getContentResolver(), |
| 301 | Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 302 | |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 303 | //enable/disable wimax depending on the value in config.xml |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 304 | final boolean isWimaxEnabled = !isSecondaryUser && this.getResources().getBoolean( |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 305 | com.android.internal.R.bool.config_wimaxEnabled); |
Julia Reynolds | 00d19c7 | 2014-06-24 15:22:50 -0400 | [diff] [blame] | 306 | if (!isWimaxEnabled |
| 307 | || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 308 | PreferenceScreen root = getPreferenceScreen(); |
| 309 | Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS); |
| 310 | if (ps != null) root.removePreference(ps); |
| 311 | } else { |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 312 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX ) |
tk.mun | 7c5c165 | 2011-10-13 22:56:18 +0900 | [diff] [blame] | 313 | && isWimaxEnabled) { |
| 314 | Preference ps = (Preference) findPreference(KEY_WIMAX_SETTINGS); |
| 315 | ps.setDependency(KEY_TOGGLE_AIRPLANE); |
| 316 | } |
| 317 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 318 | |
Chia-chi Yeh | b90452f | 2010-01-13 06:11:29 +0800 | [diff] [blame] | 319 | // Manually set dependencies for Wifi when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 320 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 321 | findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
| 322 | } |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 323 | // Disable VPN. |
| 324 | if (isSecondaryUser || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) { |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 325 | removePreference(KEY_VPN_SETTINGS); |
| 326 | } |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 327 | |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 328 | // Manually set dependencies for Bluetooth when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 329 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 330 | // 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] | 331 | } |
| 332 | |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 333 | // Manually set dependencies for NFC when not toggleable. |
Christopher Tate | 6a5929b | 2012-09-10 15:39:05 -0700 | [diff] [blame] | 334 | if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) { |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 335 | findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 336 | findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 339 | // Remove NFC if not available |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 340 | mNfcAdapter = NfcAdapter.getDefaultAdapter(activity); |
| 341 | if (mNfcAdapter == null) { |
Nick Pelly | ad50ba0 | 2010-09-22 10:55:13 -0700 | [diff] [blame] | 342 | getPreferenceScreen().removePreference(nfc); |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 343 | getPreferenceScreen().removePreference(androidBeam); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 344 | mNfcEnabler = null; |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 345 | } |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 346 | |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 347 | // Remove Mobile Network Settings and Manage Mobile Plan for secondary users, |
| 348 | // if it's a wifi-only device, or if the settings are restricted. |
| 349 | if (isSecondaryUser || Utils.isWifiOnly(getActivity()) |
| 350 | || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 351 | removePreference(KEY_MOBILE_NETWORK_SETTINGS); |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 352 | removePreference(KEY_MANAGE_MOBILE_PLAN); |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 353 | } |
Sungmin Choi | 2490315 | 2013-10-15 16:11:55 -0700 | [diff] [blame] | 354 | // Remove Mobile Network Settings and Manage Mobile Plan |
| 355 | // if config_show_mobile_plan sets false. |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 356 | final boolean isMobilePlanEnabled = this.getResources().getBoolean( |
Sungmin Choi | 2490315 | 2013-10-15 16:11:55 -0700 | [diff] [blame] | 357 | R.bool.config_show_mobile_plan); |
| 358 | if (!isMobilePlanEnabled) { |
| 359 | Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN); |
| 360 | if (pref != null) { |
| 361 | removePreference(KEY_MANAGE_MOBILE_PLAN); |
| 362 | } |
| 363 | } |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 364 | |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 365 | // Remove SMS Application if the device does not support SMS |
| 366 | if (!isSmsSupported()) { |
| 367 | removePreference(KEY_SMS_APPLICATION); |
| 368 | } |
| 369 | |
Jaewan Kim | 2e41e3d | 2013-04-19 13:40:23 +0900 | [diff] [blame] | 370 | // Remove Airplane Mode settings if it's a stationary device such as a TV. |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 371 | if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) { |
Jaewan Kim | 2e41e3d | 2013-04-19 13:40:23 +0900 | [diff] [blame] | 372 | removePreference(KEY_TOGGLE_AIRPLANE); |
| 373 | } |
| 374 | |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 375 | // Enable Proxy selector settings if allowed. |
| 376 | Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS); |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 377 | final DevicePolicyManager mDPM = (DevicePolicyManager) |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 378 | activity.getSystemService(Context.DEVICE_POLICY_SERVICE); |
Robert Greenwalt | 6f3a98b | 2010-12-28 16:11:12 -0800 | [diff] [blame] | 379 | // proxy UI disabled until we have better app support |
| 380 | getPreferenceScreen().removePreference(mGlobalProxy); |
Oscar Montemayor | 0541189 | 2010-08-03 16:56:09 -0700 | [diff] [blame] | 381 | mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null); |
| 382 | |
Amith Yamasani | 0f85c48 | 2011-02-23 17:19:11 -0800 | [diff] [blame] | 383 | // Disable Tethering if it's not allowed or if it's a wifi-only device |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 384 | final ConnectivityManager cm = |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 385 | (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 386 | if (isSecondaryUser || !cm.isTetheringSupported() |
| 387 | || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) { |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 388 | getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS)); |
Robert Greenwalt | e434bfb | 2010-05-08 15:20:24 -0700 | [diff] [blame] | 389 | } else { |
Robert Greenwalt | e434bfb | 2010-05-08 15:20:24 -0700 | [diff] [blame] | 390 | Preference p = findPreference(KEY_TETHER_SETTINGS); |
Jeff Sharkey | a83a24f | 2011-09-16 01:52:39 -0700 | [diff] [blame] | 391 | p.setTitle(Utils.getTetheringLabel(cm)); |
PauloftheWest | 29aab7a | 2014-09-26 16:05:44 -0700 | [diff] [blame] | 392 | |
| 393 | // Grey out if provisioning is not available. |
| 394 | p.setEnabled(!TetherSettings |
| 395 | .isProvisioningNeededButUnavailable(getActivity())); |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 396 | } |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 397 | |
| 398 | // Enable link to CMAS app settings depending on the value in config.xml. |
| 399 | boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean( |
| 400 | com.android.internal.R.bool.config_cellBroadcastAppLinks); |
| 401 | try { |
| 402 | if (isCellBroadcastAppLinkEnabled) { |
Andrew Flynn | 17c008e | 2013-10-11 09:06:22 -0700 | [diff] [blame] | 403 | if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 404 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { |
| 405 | isCellBroadcastAppLinkEnabled = false; // CMAS app disabled |
| 406 | } |
| 407 | } |
| 408 | } catch (IllegalArgumentException ignored) { |
| 409 | isCellBroadcastAppLinkEnabled = false; // CMAS app not installed |
| 410 | } |
Julia Reynolds | ee27b9d | 2014-05-09 13:36:20 -0400 | [diff] [blame] | 411 | if (isSecondaryUser || !isCellBroadcastAppLinkEnabled |
| 412 | || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) { |
Jake Hamby | ef57ed7 | 2012-06-21 10:59:22 -0700 | [diff] [blame] | 413 | PreferenceScreen root = getPreferenceScreen(); |
| 414 | Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS); |
| 415 | if (ps != null) root.removePreference(ps); |
| 416 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 417 | } |
Robert Greenwalt | c4764d2 | 2010-02-12 14:21:37 -0800 | [diff] [blame] | 418 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 419 | @Override |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 420 | public void onStart() { |
| 421 | super.onStart(); |
| 422 | |
| 423 | initSmsApplicationSetting(); |
| 424 | } |
| 425 | |
| 426 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 427 | public void onResume() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 428 | super.onResume(); |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 429 | |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 430 | mAirplaneModeEnabler.resume(); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 431 | if (mNfcEnabler != null) { |
| 432 | mNfcEnabler.resume(); |
Martijn Coenen | bb4bdc2 | 2011-07-27 17:31:41 -0500 | [diff] [blame] | 433 | } |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 434 | if (mNsdEnabler != null) { |
| 435 | mNsdEnabler.resume(); |
| 436 | } |
Pavel Zhamaitsiak | 4ab3256 | 2015-02-23 15:34:07 -0800 | [diff] [blame^] | 437 | |
| 438 | final Context context = getActivity(); |
| 439 | if (ImsManager.isWfcEnabledByPlatform(context)) { |
| 440 | mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary( |
| 441 | context, ImsManager.getWfcMode(context))); |
| 442 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 443 | } |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 444 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 445 | @Override |
Wink Saville | 5d5a269 | 2013-06-29 07:54:13 -0700 | [diff] [blame] | 446 | public void onSaveInstanceState(Bundle outState) { |
| 447 | super.onSaveInstanceState(outState); |
| 448 | |
| 449 | if (!TextUtils.isEmpty(mManageMobilePlanMessage)) { |
| 450 | outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 455 | public void onPause() { |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 456 | super.onPause(); |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 457 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 458 | mAirplaneModeEnabler.pause(); |
Nick Pelly | 9894d4a | 2011-08-09 07:10:16 -0700 | [diff] [blame] | 459 | if (mNfcEnabler != null) { |
| 460 | mNfcEnabler.pause(); |
| 461 | } |
Irfan Sheriff | 936e3fa | 2012-05-07 15:51:37 -0700 | [diff] [blame] | 462 | if (mNsdEnabler != null) { |
| 463 | mNsdEnabler.pause(); |
| 464 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 465 | } |
Danica Chang | 32711b6 | 2010-08-10 18:41:29 -0700 | [diff] [blame] | 466 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 467 | @Override |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 468 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame] | 469 | if (requestCode == REQUEST_CODE_EXIT_ECM) { |
| 470 | Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 471 | // Set Airplane mode based on the return value and checkbox state |
| 472 | mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes, |
| 473 | mAirplaneModePreference.isChecked()); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 474 | } |
Geoffrey Borggaard | fe21d9a | 2013-08-02 18:16:27 -0400 | [diff] [blame] | 475 | super.onActivityResult(requestCode, resultCode, data); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 476 | } |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame] | 477 | |
| 478 | @Override |
| 479 | protected int getHelpResource() { |
| 480 | return R.string.help_url_more_networks; |
| 481 | } |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 482 | |
| 483 | @Override |
| 484 | public boolean onPreferenceChange(Preference preference, Object newValue) { |
| 485 | if (preference == mSmsApplicationPreference && newValue != null) { |
| 486 | SmsApplication.setDefaultApplication(newValue.toString(), getActivity()); |
David Braun | 4e9f04d | 2013-09-16 13:45:42 -0700 | [diff] [blame] | 487 | return true; |
| 488 | } |
| 489 | return false; |
| 490 | } |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 491 | |
| 492 | /** |
| 493 | * For Search. |
| 494 | */ |
| 495 | public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
| 496 | new BaseSearchIndexProvider() { |
| 497 | @Override |
| 498 | public List<SearchIndexableResource> getXmlResourcesToIndex( |
| 499 | Context context, boolean enabled) { |
| 500 | SearchIndexableResource sir = new SearchIndexableResource(context); |
| 501 | sir.xmlResId = R.xml.wireless_settings; |
| 502 | return Arrays.asList(sir); |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public List<String> getNonIndexableKeys(Context context) { |
| 507 | final ArrayList<String> result = new ArrayList<String>(); |
| 508 | |
| 509 | result.add(KEY_TOGGLE_NSD); |
| 510 | |
Julia Reynolds | 00d19c7 | 2014-06-24 15:22:50 -0400 | [diff] [blame] | 511 | final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); |
Amith Yamasani | 32505ac | 2014-11-12 13:46:43 -0800 | [diff] [blame] | 512 | final int myUserId = UserHandle.myUserId(); |
| 513 | final boolean isSecondaryUser = myUserId != UserHandle.USER_OWNER; |
| 514 | final boolean isRestrictedUser = um.getUserInfo(myUserId).isRestricted(); |
| 515 | final boolean isWimaxEnabled = !isSecondaryUser |
| 516 | && context.getResources().getBoolean( |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 517 | com.android.internal.R.bool.config_wimaxEnabled); |
Julia Reynolds | 00d19c7 | 2014-06-24 15:22:50 -0400 | [diff] [blame] | 518 | if (!isWimaxEnabled |
| 519 | || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 520 | result.add(KEY_WIMAX_SETTINGS); |
| 521 | } |
| 522 | |
| 523 | if (isSecondaryUser) { // Disable VPN |
| 524 | result.add(KEY_VPN_SETTINGS); |
| 525 | } |
| 526 | |
| 527 | // Remove NFC if not available |
Amith Yamasani | 32505ac | 2014-11-12 13:46:43 -0800 | [diff] [blame] | 528 | final NfcManager manager = (NfcManager) |
| 529 | context.getSystemService(Context.NFC_SERVICE); |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 530 | if (manager != null) { |
| 531 | NfcAdapter adapter = manager.getDefaultAdapter(); |
| 532 | if (adapter == null) { |
| 533 | result.add(KEY_TOGGLE_NFC); |
| 534 | result.add(KEY_ANDROID_BEAM_SETTINGS); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device. |
| 539 | if (isSecondaryUser || Utils.isWifiOnly(context)) { |
| 540 | result.add(KEY_MOBILE_NETWORK_SETTINGS); |
| 541 | result.add(KEY_MANAGE_MOBILE_PLAN); |
| 542 | } |
| 543 | |
| 544 | // Remove Mobile Network Settings and Manage Mobile Plan |
| 545 | // if config_show_mobile_plan sets false. |
| 546 | final boolean isMobilePlanEnabled = context.getResources().getBoolean( |
| 547 | R.bool.config_show_mobile_plan); |
| 548 | if (!isMobilePlanEnabled) { |
| 549 | result.add(KEY_MANAGE_MOBILE_PLAN); |
| 550 | } |
| 551 | |
| 552 | // Remove SMS Application if the device does not support SMS |
Yorke Lee | 5e10834 | 2014-06-19 22:21:41 +0000 | [diff] [blame] | 553 | TelephonyManager tm = |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 554 | (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
Amith Yamasani | 32505ac | 2014-11-12 13:46:43 -0800 | [diff] [blame] | 555 | if (!tm.isSmsCapable() || isRestrictedUser) { |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 556 | result.add(KEY_SMS_APPLICATION); |
| 557 | } |
| 558 | |
| 559 | final PackageManager pm = context.getPackageManager(); |
| 560 | |
| 561 | // Remove Airplane Mode settings if it's a stationary device such as a TV. |
| 562 | if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) { |
| 563 | result.add(KEY_TOGGLE_AIRPLANE); |
| 564 | } |
| 565 | |
| 566 | // proxy UI disabled until we have better app support |
| 567 | result.add(KEY_PROXY_SETTINGS); |
| 568 | |
| 569 | // Disable Tethering if it's not allowed or if it's a wifi-only device |
Amith Yamasani | 32505ac | 2014-11-12 13:46:43 -0800 | [diff] [blame] | 570 | ConnectivityManager cm = (ConnectivityManager) |
| 571 | context.getSystemService(Context.CONNECTIVITY_SERVICE); |
Fabrice Di Meglio | dba577f | 2014-06-06 16:31:45 -0700 | [diff] [blame] | 572 | if (isSecondaryUser || !cm.isTetheringSupported()) { |
| 573 | result.add(KEY_TETHER_SETTINGS); |
| 574 | } |
| 575 | |
| 576 | // Enable link to CMAS app settings depending on the value in config.xml. |
| 577 | boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean( |
| 578 | com.android.internal.R.bool.config_cellBroadcastAppLinks); |
| 579 | try { |
| 580 | if (isCellBroadcastAppLinkEnabled) { |
| 581 | if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver") |
| 582 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { |
| 583 | isCellBroadcastAppLinkEnabled = false; // CMAS app disabled |
| 584 | } |
| 585 | } |
| 586 | } catch (IllegalArgumentException ignored) { |
| 587 | isCellBroadcastAppLinkEnabled = false; // CMAS app not installed |
| 588 | } |
| 589 | if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) { |
| 590 | result.add(KEY_CELL_BROADCAST_SETTINGS); |
| 591 | } |
| 592 | |
| 593 | return result; |
| 594 | } |
| 595 | }; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 596 | } |