blob: 55a2c326d004dfb05e929086d7b9d441ac396d2b [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
Chia-chi Yeh4e142112009-12-25 14:48:46 +08002 * Copyright (C) 2009 The Android Open Source Project
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -040019
Amith Yamasanid7993472010-08-18 13:59:28 -070020import android.app.Activity;
Wink Saville5d5a2692013-06-29 07:54:13 -070021import android.app.AlertDialog;
22import android.app.Dialog;
Amith Yamasanid7993472010-08-18 13:59:28 -070023import android.app.admin.DevicePolicyManager;
Paul Jensend96c5fc2014-10-17 22:09:37 -040024import android.content.ActivityNotFoundException;
Amith Yamasanid7993472010-08-18 13:59:28 -070025import android.content.Context;
Wink Saville5d5a2692013-06-29 07:54:13 -070026import android.content.DialogInterface;
Amith Yamasanid7993472010-08-18 13:59:28 -070027import android.content.Intent;
Irfan Sheriff167d7182011-09-07 14:51:11 -070028import android.content.pm.PackageManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070029import android.content.res.Resources;
Amith Yamasanid7993472010-08-18 13:59:28 -070030import android.net.ConnectivityManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070031import android.net.NetworkInfo;
Paul Jensend96c5fc2014-10-17 22:09:37 -040032import android.net.Uri;
Nick Pellya57eace2010-10-15 01:19:43 -070033import android.nfc.NfcAdapter;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070034import android.nfc.NfcManager;
Amith Yamasanid7993472010-08-18 13:59:28 -070035import android.os.Bundle;
Amith Yamasanid7993472010-08-18 13:59:28 -070036import android.os.SystemProperties;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040037import android.os.UserManager;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070038import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070039import android.provider.Settings;
Jason Monk39b46742015-09-10 15:52:51 -040040import android.support.v14.preference.SwitchPreference;
41import android.support.v7.preference.Preference;
42import android.support.v7.preference.PreferenceScreen;
Wink Saville5d5a2692013-06-29 07:54:13 -070043import android.telephony.TelephonyManager;
44import android.text.TextUtils;
45import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070046
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080047import com.android.ims.ImsManager;
Chris Wren8a963ba2015-03-20 10:29:14 -040048import com.android.internal.logging.MetricsLogger;
Gilles Debunnee78c1872011-06-20 15:00:07 -070049import com.android.internal.telephony.TelephonyIntents;
50import com.android.internal.telephony.TelephonyProperties;
51import com.android.settings.nfc.NfcEnabler;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070052import com.android.settings.search.BaseSearchIndexProvider;
53import com.android.settings.search.Indexable;
Jason Monk73a24962015-04-13 20:58:05 -040054
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070055import java.util.ArrayList;
56import java.util.Arrays;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070057import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070058
Jason Monk73a24962015-04-13 20:58:05 -040059public class WirelessSettings extends SettingsPreferenceFragment implements Indexable {
Robert Greenwalt4929e912013-07-16 13:09:24 -070060 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080061
62 private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
Nick Pellyad50ba02010-09-22 10:55:13 -070063 private static final String KEY_TOGGLE_NFC = "toggle_nfc";
tk.mun7c5c1652011-10-13 22:56:18 +090064 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Jeff Hamilton3d670de2011-09-21 16:44:36 -050065 private static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070066 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Robert Greenwaltc4764d22010-02-12 14:21:37 -080067 private static final String KEY_TETHER_SETTINGS = "tether_settings";
Oscar Montemayor05411892010-08-03 16:56:09 -070068 private static final String KEY_PROXY_SETTINGS = "proxy_settings";
Amith Yamasani0f85c482011-02-23 17:19:11 -080069 private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
Wink Saville5d5a2692013-06-29 07:54:13 -070070 private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
Jake Hambyef57ed72012-06-21 10:59:22 -070071 private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080072 private static final String KEY_WFC_SETTINGS = "wifi_calling_settings";
Nick Pellyad50ba02010-09-22 10:55:13 -070073
Chouting Zhang71cc49e2009-08-28 14:36:35 -050074 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
75 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080076
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080077 private AirplaneModeEnabler mAirplaneModeEnabler;
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -070078 private SwitchPreference mAirplaneModePreference;
Nick Pellyad50ba02010-09-22 10:55:13 -070079 private NfcEnabler mNfcEnabler;
Martijn Coenenbb4bdc22011-07-27 17:31:41 -050080 private NfcAdapter mNfcAdapter;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050081
Wink Saville5d5a2692013-06-29 07:54:13 -070082 private ConnectivityManager mCm;
83 private TelephonyManager mTm;
Andrew Flynn17c008e2013-10-11 09:06:22 -070084 private PackageManager mPm;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040085 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070086
87 private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
88 private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
89
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -080090 private PreferenceScreen mButtonWfc;
David Braun4e9f04d2013-09-16 13:45:42 -070091
Chouting Zhang71cc49e2009-08-28 14:36:35 -050092 /**
93 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080094 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -050095 * preference click events.
96 */
97 @Override
Jason Monk39b46742015-09-10 15:52:51 -040098 public boolean onPreferenceTreeClick(Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -070099 log("onPreferenceTreeClick: preference=" + preference);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800100 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
101 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500102 // In ECM mode launch ECM app dialog
103 startActivityForResult(
104 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
105 REQUEST_CODE_EXIT_ECM);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500106 return true;
Wink Saville5d5a2692013-06-29 07:54:13 -0700107 } else if (preference == findPreference(KEY_MANAGE_MOBILE_PLAN)) {
108 onManageMobilePlanClick();
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500109 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800110 // Let the intents be launched by the Preference manager
Jason Monk39b46742015-09-10 15:52:51 -0400111 return super.onPreferenceTreeClick(preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500112 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800113
Wink Saville5d5a2692013-06-29 07:54:13 -0700114 private String mManageMobilePlanMessage;
Wink Saville5d5a2692013-06-29 07:54:13 -0700115 public void onManageMobilePlanClick() {
116 log("onManageMobilePlanClick:");
117 mManageMobilePlanMessage = null;
118 Resources resources = getActivity().getResources();
119
Paul Jensen6953eea2015-06-11 10:26:33 -0400120 NetworkInfo ni = mCm.getActiveNetworkInfo();
Wink Saville5d5a2692013-06-29 07:54:13 -0700121 if (mTm.hasIccCard() && (ni != null)) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700122 // Check for carrier apps that can handle provisioning first
123 Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700124 List<String> carrierPackages =
Diego Pontorierobe7adcc2014-08-28 13:52:24 -0700125 mTm.getCarrierPackageNamesForIntent(provisioningIntent);
Diego Pontorieroff9f67d2014-08-11 18:25:51 -0700126 if (carrierPackages != null && !carrierPackages.isEmpty()) {
127 if (carrierPackages.size() != 1) {
128 Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
129 }
130 provisioningIntent.setPackage(carrierPackages.get(0));
Andrew Flynn17c008e2013-10-11 09:06:22 -0700131 startActivity(provisioningIntent);
132 return;
133 }
134
Wink Saville5d5a2692013-06-29 07:54:13 -0700135 // Get provisioning URL
Robert Greenwalt4929e912013-07-16 13:09:24 -0700136 String url = mCm.getMobileProvisioningUrl();
Wink Saville5d5a2692013-06-29 07:54:13 -0700137 if (!TextUtils.isEmpty(url)) {
Paul Jensend96c5fc2014-10-17 22:09:37 -0400138 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
139 Intent.CATEGORY_APP_BROWSER);
140 intent.setData(Uri.parse(url));
141 intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
142 Intent.FLAG_ACTIVITY_NEW_TASK);
143 try {
144 startActivity(intent);
145 } catch (ActivityNotFoundException e) {
146 Log.w(TAG, "onManageMobilePlanClick: startActivity failed" + e);
147 }
Wink Saville5d5a2692013-06-29 07:54:13 -0700148 } else {
149 // No provisioning URL
150 String operatorName = mTm.getSimOperatorName();
151 if (TextUtils.isEmpty(operatorName)) {
152 // Use NetworkOperatorName as second choice in case there is no
153 // SPN (Service Provider Name on the SIM). Such as with T-mobile.
154 operatorName = mTm.getNetworkOperatorName();
155 if (TextUtils.isEmpty(operatorName)) {
156 mManageMobilePlanMessage = resources.getString(
157 R.string.mobile_unknown_sim_operator);
158 } else {
159 mManageMobilePlanMessage = resources.getString(
160 R.string.mobile_no_provisioning_url, operatorName);
161 }
162 } else {
163 mManageMobilePlanMessage = resources.getString(
164 R.string.mobile_no_provisioning_url, operatorName);
165 }
166 }
167 } else if (mTm.hasIccCard() == false) {
168 // No sim card
169 mManageMobilePlanMessage = resources.getString(R.string.mobile_insert_sim_card);
170 } else {
171 // NetworkInfo is null, there is no connection
172 mManageMobilePlanMessage = resources.getString(R.string.mobile_connect_to_internet);
173 }
174 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
175 log("onManageMobilePlanClick: message=" + mManageMobilePlanMessage);
176 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
177 }
178 }
179
Wink Saville5d5a2692013-06-29 07:54:13 -0700180 @Override
181 public Dialog onCreateDialog(int dialogId) {
182 log("onCreateDialog: dialogId=" + dialogId);
183 switch (dialogId) {
184 case MANAGE_MOBILE_PLAN_DIALOG_ID:
185 return new AlertDialog.Builder(getActivity())
186 .setMessage(mManageMobilePlanMessage)
187 .setCancelable(false)
188 .setPositiveButton(com.android.internal.R.string.ok,
189 new DialogInterface.OnClickListener() {
190 @Override
191 public void onClick(DialogInterface dialog, int id) {
192 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
193 mManageMobilePlanMessage = null;
194 }
195 })
196 .create();
197 }
198 return super.onCreateDialog(dialogId);
199 }
200
201 private void log(String s) {
202 Log.d(TAG, s);
203 }
204
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800205 @Override
Chris Wren8a963ba2015-03-20 10:29:14 -0400206 protected int getMetricsCategory() {
207 return MetricsLogger.WIRELESS;
208 }
209
210 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700211 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800212 super.onCreate(savedInstanceState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700213 if (savedInstanceState != null) {
214 mManageMobilePlanMessage = savedInstanceState.getString(SAVED_MANAGE_MOBILE_PLAN_MSG);
215 }
216 log("onCreate: mManageMobilePlanMessage=" + mManageMobilePlanMessage);
217
218 mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
219 mTm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Andrew Flynn17c008e2013-10-11 09:06:22 -0700220 mPm = getPackageManager();
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400221 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800222
223 addPreferencesFromResource(R.xml.wireless_settings);
224
Xiaohui Chen6f038292015-09-02 16:54:00 -0700225 final boolean isAdmin = mUm.isAdminUser();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700226
Amith Yamasanid7993472010-08-18 13:59:28 -0700227 final Activity activity = getActivity();
Fabrice Di Meglioe3bced22014-08-06 10:22:52 -0700228 mAirplaneModePreference = (SwitchPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Fabrice Di Meglio4325f802014-08-15 14:14:17 -0700229 SwitchPreference nfc = (SwitchPreference) findPreference(KEY_TOGGLE_NFC);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500230 PreferenceScreen androidBeam = (PreferenceScreen) findPreference(KEY_ANDROID_BEAM_SETTINGS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800231
Gilles Debunnee78c1872011-06-20 15:00:07 -0700232 mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500233 mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700234
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700235 mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800236
Christopher Tate6a5929b2012-09-10 15:39:05 -0700237 String toggleable = Settings.Global.getString(activity.getContentResolver(),
238 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800239
tk.mun7c5c1652011-10-13 22:56:18 +0900240 //enable/disable wimax depending on the value in config.xml
Xiaohui Chen6f038292015-09-02 16:54:00 -0700241 final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900242 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400243 if (!isWimaxEnabled
244 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
tk.mun7c5c1652011-10-13 22:56:18 +0900245 PreferenceScreen root = getPreferenceScreen();
Xiaohui Chen6f038292015-09-02 16:54:00 -0700246 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900247 if (ps != null) root.removePreference(ps);
248 } else {
Christopher Tate6a5929b2012-09-10 15:39:05 -0700249 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX )
tk.mun7c5c1652011-10-13 22:56:18 +0900250 && isWimaxEnabled) {
Xiaohui Chen6f038292015-09-02 16:54:00 -0700251 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900252 ps.setDependency(KEY_TOGGLE_AIRPLANE);
253 }
254 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400255
Chia-chi Yehb90452f2010-01-13 06:11:29 +0800256 // Manually set dependencies for Wifi when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700257 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIFI)) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800258 findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
259 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400260 // Disable VPN.
Xiaohui Chen6f038292015-09-02 16:54:00 -0700261 // TODO: http://b/23693383
262 if (!isAdmin || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700263 removePreference(KEY_VPN_SETTINGS);
264 }
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400265
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800266 // Manually set dependencies for Bluetooth when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700267 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700268 // No bluetooth-dependent items in the list. Code kept in case one is added later.
Nick Pellyad50ba02010-09-22 10:55:13 -0700269 }
270
Nick Pelly9894d4a2011-08-09 07:10:16 -0700271 // Manually set dependencies for NFC when not toggleable.
Christopher Tate6a5929b2012-09-10 15:39:05 -0700272 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_NFC)) {
Nick Pelly9894d4a2011-08-09 07:10:16 -0700273 findPreference(KEY_TOGGLE_NFC).setDependency(KEY_TOGGLE_AIRPLANE);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500274 findPreference(KEY_ANDROID_BEAM_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700275 }
276
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700277 // Remove NFC if not available
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500278 mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
279 if (mNfcAdapter == null) {
Nick Pellyad50ba02010-09-22 10:55:13 -0700280 getPreferenceScreen().removePreference(nfc);
Jeff Hamilton3d670de2011-09-21 16:44:36 -0500281 getPreferenceScreen().removePreference(androidBeam);
Nick Pelly9894d4a2011-08-09 07:10:16 -0700282 mNfcEnabler = null;
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800283 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800284
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400285 // Remove Mobile Network Settings and Manage Mobile Plan for secondary users,
286 // if it's a wifi-only device, or if the settings are restricted.
Xiaohui Chen6f038292015-09-02 16:54:00 -0700287 if (!isAdmin || Utils.isWifiOnly(getActivity())
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400288 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700289 removePreference(KEY_MOBILE_NETWORK_SETTINGS);
Wink Saville5d5a2692013-06-29 07:54:13 -0700290 removePreference(KEY_MANAGE_MOBILE_PLAN);
Amith Yamasani0f85c482011-02-23 17:19:11 -0800291 }
Sungmin Choi24903152013-10-15 16:11:55 -0700292 // Remove Mobile Network Settings and Manage Mobile Plan
293 // if config_show_mobile_plan sets false.
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700294 final boolean isMobilePlanEnabled = this.getResources().getBoolean(
Sungmin Choi24903152013-10-15 16:11:55 -0700295 R.bool.config_show_mobile_plan);
296 if (!isMobilePlanEnabled) {
297 Preference pref = findPreference(KEY_MANAGE_MOBILE_PLAN);
298 if (pref != null) {
299 removePreference(KEY_MANAGE_MOBILE_PLAN);
300 }
301 }
Amith Yamasani0f85c482011-02-23 17:19:11 -0800302
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900303 // Remove Airplane Mode settings if it's a stationary device such as a TV.
Andrew Flynn17c008e2013-10-11 09:06:22 -0700304 if (mPm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
Jaewan Kim2e41e3d2013-04-19 13:40:23 +0900305 removePreference(KEY_TOGGLE_AIRPLANE);
306 }
307
Oscar Montemayor05411892010-08-03 16:56:09 -0700308 // Enable Proxy selector settings if allowed.
309 Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700310 final DevicePolicyManager mDPM = (DevicePolicyManager)
Amith Yamasanid7993472010-08-18 13:59:28 -0700311 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
Robert Greenwalt6f3a98b2010-12-28 16:11:12 -0800312 // proxy UI disabled until we have better app support
313 getPreferenceScreen().removePreference(mGlobalProxy);
Oscar Montemayor05411892010-08-03 16:56:09 -0700314 mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
315
Amith Yamasani0f85c482011-02-23 17:19:11 -0800316 // Disable Tethering if it's not allowed or if it's a wifi-only device
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700317 final ConnectivityManager cm =
Amith Yamasanid7993472010-08-18 13:59:28 -0700318 (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
Xiaohui Chen6f038292015-09-02 16:54:00 -0700319 if (!isAdmin || !cm.isTetheringSupported()
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400320 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800321 getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700322 } else {
Robert Greenwalte434bfb2010-05-08 15:20:24 -0700323 Preference p = findPreference(KEY_TETHER_SETTINGS);
Wei Liu6e58d512015-08-24 17:29:04 -0700324 p.setTitle(com.android.settingslib.Utils.getTetheringLabel(cm));
PauloftheWest29aab7a2014-09-26 16:05:44 -0700325
326 // Grey out if provisioning is not available.
327 p.setEnabled(!TetherSettings
328 .isProvisioningNeededButUnavailable(getActivity()));
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800329 }
Jake Hambyef57ed72012-06-21 10:59:22 -0700330
331 // Enable link to CMAS app settings depending on the value in config.xml.
332 boolean isCellBroadcastAppLinkEnabled = this.getResources().getBoolean(
333 com.android.internal.R.bool.config_cellBroadcastAppLinks);
334 try {
335 if (isCellBroadcastAppLinkEnabled) {
Andrew Flynn17c008e2013-10-11 09:06:22 -0700336 if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
Jake Hambyef57ed72012-06-21 10:59:22 -0700337 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
338 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
339 }
340 }
341 } catch (IllegalArgumentException ignored) {
342 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
343 }
Xiaohui Chen6f038292015-09-02 16:54:00 -0700344 if (!isAdmin || !isCellBroadcastAppLinkEnabled
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400345 || mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_CELL_BROADCASTS)) {
Jake Hambyef57ed72012-06-21 10:59:22 -0700346 PreferenceScreen root = getPreferenceScreen();
347 Preference ps = findPreference(KEY_CELL_BROADCAST_SETTINGS);
348 if (ps != null) root.removePreference(ps);
349 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800350 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800351
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800352 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700353 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800354 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700355
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800356 mAirplaneModeEnabler.resume();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700357 if (mNfcEnabler != null) {
358 mNfcEnabler.resume();
Martijn Coenenbb4bdc22011-07-27 17:31:41 -0500359 }
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800360
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700361 // update WFC setting
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800362 final Context context = getActivity();
363 if (ImsManager.isWfcEnabledByPlatform(context)) {
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700364 getPreferenceScreen().addPreference(mButtonWfc);
365
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800366 mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary(
367 context, ImsManager.getWfcMode(context)));
Pavel Zhamaitsiak3e7e2c52015-07-23 09:31:58 -0700368 } else {
369 removePreference(KEY_WFC_SETTINGS);
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800370 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800371 }
Danica Chang32711b62010-08-10 18:41:29 -0700372
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800373 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700374 public void onSaveInstanceState(Bundle outState) {
375 super.onSaveInstanceState(outState);
376
377 if (!TextUtils.isEmpty(mManageMobilePlanMessage)) {
378 outState.putString(SAVED_MANAGE_MOBILE_PLAN_MSG, mManageMobilePlanMessage);
379 }
380 }
381
382 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700383 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800384 super.onPause();
Danica Chang32711b62010-08-10 18:41:29 -0700385
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800386 mAirplaneModeEnabler.pause();
Nick Pelly9894d4a2011-08-09 07:10:16 -0700387 if (mNfcEnabler != null) {
388 mNfcEnabler.pause();
389 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800390 }
Danica Chang32711b62010-08-10 18:41:29 -0700391
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500392 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700393 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800394 if (requestCode == REQUEST_CODE_EXIT_ECM) {
395 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500396 // Set Airplane mode based on the return value and checkbox state
397 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
398 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500399 }
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400400 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500401 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700402
403 @Override
404 protected int getHelpResource() {
405 return R.string.help_url_more_networks;
406 }
David Braun4e9f04d2013-09-16 13:45:42 -0700407
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700408 /**
409 * For Search.
410 */
411 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
412 new BaseSearchIndexProvider() {
413 @Override
414 public List<SearchIndexableResource> getXmlResourcesToIndex(
415 Context context, boolean enabled) {
416 SearchIndexableResource sir = new SearchIndexableResource(context);
417 sir.xmlResId = R.xml.wireless_settings;
418 return Arrays.asList(sir);
419 }
420
421 @Override
422 public List<String> getNonIndexableKeys(Context context) {
423 final ArrayList<String> result = new ArrayList<String>();
424
Julia Reynolds00d19c72014-06-24 15:22:50 -0400425 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Xiaohui Chen44879a32015-07-22 13:53:22 -0700426 final boolean isSecondaryUser = !um.isAdminUser();
Amith Yamasani32505ac2014-11-12 13:46:43 -0800427 final boolean isWimaxEnabled = !isSecondaryUser
428 && context.getResources().getBoolean(
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700429 com.android.internal.R.bool.config_wimaxEnabled);
Julia Reynolds00d19c72014-06-24 15:22:50 -0400430 if (!isWimaxEnabled
431 || um.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700432 result.add(KEY_WIMAX_SETTINGS);
433 }
434
435 if (isSecondaryUser) { // Disable VPN
436 result.add(KEY_VPN_SETTINGS);
437 }
438
439 // Remove NFC if not available
Amith Yamasani32505ac2014-11-12 13:46:43 -0800440 final NfcManager manager = (NfcManager)
441 context.getSystemService(Context.NFC_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700442 if (manager != null) {
443 NfcAdapter adapter = manager.getDefaultAdapter();
444 if (adapter == null) {
445 result.add(KEY_TOGGLE_NFC);
446 result.add(KEY_ANDROID_BEAM_SETTINGS);
447 }
448 }
449
450 // Remove Mobile Network Settings and Manage Mobile Plan if it's a wifi-only device.
451 if (isSecondaryUser || Utils.isWifiOnly(context)) {
452 result.add(KEY_MOBILE_NETWORK_SETTINGS);
453 result.add(KEY_MANAGE_MOBILE_PLAN);
454 }
455
456 // Remove Mobile Network Settings and Manage Mobile Plan
457 // if config_show_mobile_plan sets false.
458 final boolean isMobilePlanEnabled = context.getResources().getBoolean(
459 R.bool.config_show_mobile_plan);
460 if (!isMobilePlanEnabled) {
461 result.add(KEY_MANAGE_MOBILE_PLAN);
462 }
463
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700464 final PackageManager pm = context.getPackageManager();
465
466 // Remove Airplane Mode settings if it's a stationary device such as a TV.
467 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
468 result.add(KEY_TOGGLE_AIRPLANE);
469 }
470
471 // proxy UI disabled until we have better app support
472 result.add(KEY_PROXY_SETTINGS);
473
474 // Disable Tethering if it's not allowed or if it's a wifi-only device
Amith Yamasani32505ac2014-11-12 13:46:43 -0800475 ConnectivityManager cm = (ConnectivityManager)
476 context.getSystemService(Context.CONNECTIVITY_SERVICE);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700477 if (isSecondaryUser || !cm.isTetheringSupported()) {
478 result.add(KEY_TETHER_SETTINGS);
479 }
480
481 // Enable link to CMAS app settings depending on the value in config.xml.
482 boolean isCellBroadcastAppLinkEnabled = context.getResources().getBoolean(
483 com.android.internal.R.bool.config_cellBroadcastAppLinks);
484 try {
485 if (isCellBroadcastAppLinkEnabled) {
486 if (pm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
487 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
488 isCellBroadcastAppLinkEnabled = false; // CMAS app disabled
489 }
490 }
491 } catch (IllegalArgumentException ignored) {
492 isCellBroadcastAppLinkEnabled = false; // CMAS app not installed
493 }
494 if (isSecondaryUser || !isCellBroadcastAppLinkEnabled) {
495 result.add(KEY_CELL_BROADCAST_SETTINGS);
496 }
497
498 return result;
499 }
500 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800501}