blob: cac964db69f00299472ba59011ff62433cafcb9a [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.content.Context;
Wink Saville5d5a2692013-06-29 07:54:13 -070024import android.content.DialogInterface;
Amith Yamasanid7993472010-08-18 13:59:28 -070025import android.content.Intent;
26import android.net.ConnectivityManager;
27import android.os.Bundle;
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +000028import android.os.UserHandle;
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040029import android.os.UserManager;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070030import android.provider.SearchIndexableResource;
Amith Yamasanid7993472010-08-18 13:59:28 -070031import android.provider.Settings;
Jason Monk39b46742015-09-10 15:52:51 -040032import android.support.v7.preference.Preference;
33import android.support.v7.preference.PreferenceScreen;
Wink Saville5d5a2692013-06-29 07:54:13 -070034import android.telephony.TelephonyManager;
Wink Saville5d5a2692013-06-29 07:54:13 -070035import android.util.Log;
David Braun4e9f04d2013-09-16 13:45:42 -070036
Chris Wren9d1bfd12016-01-26 18:04:01 -050037import com.android.internal.logging.MetricsProto.MetricsEvent;
Fan Zhang7f1a4b52016-10-12 12:35:52 -070038import com.android.settings.network.AirplaneModePreferenceController;
39import com.android.settings.network.MobileNetworkPreferenceController;
Fan Zhangf1acdd32016-10-13 09:53:38 -070040import com.android.settings.network.MobilePlanPreferenceController;
41import com.android.settings.network.NetworkResetPreferenceController;
42import com.android.settings.network.ProxyPreferenceController;
Fan Zhang7f1a4b52016-10-12 12:35:52 -070043import com.android.settings.network.TetherPreferenceController;
44import com.android.settings.network.VpnPreferenceController;
Fan Zhangf1acdd32016-10-13 09:53:38 -070045import com.android.settings.network.WifiCallingPreferenceController;
Doris Linge2145702016-10-13 17:16:07 -070046import com.android.settings.nfc.NfcPreferenceController;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070047import com.android.settings.search.BaseSearchIndexProvider;
48import com.android.settings.search.Indexable;
Sudheer Shanka8b868302016-01-26 13:50:23 +000049import com.android.settingslib.RestrictedLockUtils;
Sudheer Shanka682a9162016-01-13 22:10:18 +000050import com.android.settingslib.RestrictedPreference;
Jason Monk73a24962015-04-13 20:58:05 -040051
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070052import java.util.ArrayList;
53import java.util.Arrays;
Fyodor Kupolovca060e32016-06-24 13:01:11 -070054import java.util.Collections;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -070055import java.util.List;
David Braun4e9f04d2013-09-16 13:45:42 -070056
Fan Zhangf1acdd32016-10-13 09:53:38 -070057import static com.android.settings.network.MobilePlanPreferenceController
58 .MANAGE_MOBILE_PLAN_DIALOG_ID;
59
60public class WirelessSettings extends SettingsPreferenceFragment implements Indexable,
61 MobilePlanPreferenceController.MobilePlanPreferenceHost {
Robert Greenwalt4929e912013-07-16 13:09:24 -070062 private static final String TAG = "WirelessSettings";
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080063
tk.mun7c5c1652011-10-13 22:56:18 +090064 private static final String KEY_WIMAX_SETTINGS = "wimax_settings";
Fan Zhang7f1a4b52016-10-12 12:35:52 -070065
Julia Reynoldsee27b9d2014-05-09 13:36:20 -040066 private UserManager mUm;
Wink Saville5d5a2692013-06-29 07:54:13 -070067
Fan Zhang7f1a4b52016-10-12 12:35:52 -070068 private AirplaneModePreferenceController mAirplaneModePreferenceController;
69 private TetherPreferenceController mTetherPreferenceController;
70 private MobileNetworkPreferenceController mMobileNetworkPreferenceController;
71 private VpnPreferenceController mVpnPreferenceController;
Fan Zhangf1acdd32016-10-13 09:53:38 -070072 private NetworkResetPreferenceController mNetworkResetPreferenceController;
73 private WifiCallingPreferenceController mWifiCallingPreferenceController;
74 private ProxyPreferenceController mProxyPreferenceController;
75 private MobilePlanPreferenceController mMobilePlanPreferenceController;
Doris Linge2145702016-10-13 17:16:07 -070076 private NfcPreferenceController mNfcPreferenceController;
David Braun4e9f04d2013-09-16 13:45:42 -070077
Chouting Zhang71cc49e2009-08-28 14:36:35 -050078 /**
79 * Invoked on each preference click in this hierarchy, overrides
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080080 * PreferenceFragment's implementation. Used to make sure we track the
Chouting Zhang71cc49e2009-08-28 14:36:35 -050081 * preference click events.
82 */
83 @Override
Jason Monk39b46742015-09-10 15:52:51 -040084 public boolean onPreferenceTreeClick(Preference preference) {
Wink Saville5d5a2692013-06-29 07:54:13 -070085 log("onPreferenceTreeClick: preference=" + preference);
Fan Zhang7f1a4b52016-10-12 12:35:52 -070086 if (mAirplaneModePreferenceController.handlePreferenceTreeClick(preference)) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -050087 return true;
Fan Zhang7f1a4b52016-10-12 12:35:52 -070088 }
Fan Zhangf1acdd32016-10-13 09:53:38 -070089 if (mMobilePlanPreferenceController.handlePreferenceTreeClick(preference)) {
90 return true;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050091 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +080092 // Let the intents be launched by the Preference manager
Jason Monk39b46742015-09-10 15:52:51 -040093 return super.onPreferenceTreeClick(preference);
Chouting Zhang71cc49e2009-08-28 14:36:35 -050094 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +080095
Wink Saville5d5a2692013-06-29 07:54:13 -070096 @Override
97 public Dialog onCreateDialog(int dialogId) {
98 log("onCreateDialog: dialogId=" + dialogId);
99 switch (dialogId) {
100 case MANAGE_MOBILE_PLAN_DIALOG_ID:
101 return new AlertDialog.Builder(getActivity())
Fan Zhangf1acdd32016-10-13 09:53:38 -0700102 .setMessage(mMobilePlanPreferenceController.getMobilePlanDialogMessage())
103 .setCancelable(false)
104 .setPositiveButton(com.android.internal.R.string.ok,
105 new DialogInterface.OnClickListener() {
106 @Override
107 public void onClick(DialogInterface dialog, int id) {
108 log("MANAGE_MOBILE_PLAN_DIALOG.onClickListener id=" + id);
109 mMobilePlanPreferenceController
110 .setMobilePlanDialogMessage(null);
111 }
112 })
113 .create();
Wink Saville5d5a2692013-06-29 07:54:13 -0700114 }
115 return super.onCreateDialog(dialogId);
116 }
117
Fan Zhang20374fd2016-09-23 12:10:38 -0700118 @Override
119 public int getDialogMetricsCategory(int dialogId) {
120 if (MANAGE_MOBILE_PLAN_DIALOG_ID == dialogId) {
121 return MetricsEvent.DIALOG_MANAGE_MOBILE_PLAN;
122 }
123 return 0;
124 }
125
Wink Saville5d5a2692013-06-29 07:54:13 -0700126 private void log(String s) {
127 Log.d(TAG, s);
128 }
129
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800130 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700131 public int getMetricsCategory() {
Chris Wren9d1bfd12016-01-26 18:04:01 -0500132 return MetricsEvent.WIRELESS;
Chris Wren8a963ba2015-03-20 10:29:14 -0400133 }
134
135 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700136 public void onCreate(Bundle savedInstanceState) {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800137 super.onCreate(savedInstanceState);
Fan Zhang7f1a4b52016-10-12 12:35:52 -0700138
Julia Reynoldsee27b9d2014-05-09 13:36:20 -0400139 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800140
141 addPreferencesFromResource(R.xml.wireless_settings);
142
Xiaohui Chen6f038292015-09-02 16:54:00 -0700143 final boolean isAdmin = mUm.isAdminUser();
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700144
Amith Yamasanid7993472010-08-18 13:59:28 -0700145 final Activity activity = getActivity();
Fan Zhang7f1a4b52016-10-12 12:35:52 -0700146
147 final PreferenceScreen screen = getPreferenceScreen();
148 mAirplaneModePreferenceController = new AirplaneModePreferenceController(activity, this);
149 mTetherPreferenceController = new TetherPreferenceController(activity);
150 mMobileNetworkPreferenceController = new MobileNetworkPreferenceController(activity);
151 mVpnPreferenceController = new VpnPreferenceController(activity);
Fan Zhangf1acdd32016-10-13 09:53:38 -0700152 mWifiCallingPreferenceController = new WifiCallingPreferenceController(activity);
153 mNetworkResetPreferenceController = new NetworkResetPreferenceController(activity);
154 mProxyPreferenceController = new ProxyPreferenceController(activity);
155 mMobilePlanPreferenceController = new MobilePlanPreferenceController(activity, this);
Doris Linge2145702016-10-13 17:16:07 -0700156 mNfcPreferenceController = new NfcPreferenceController(activity);
Fan Zhangf1acdd32016-10-13 09:53:38 -0700157
158 mMobilePlanPreferenceController.onCreate(savedInstanceState);
Fan Zhang7f1a4b52016-10-12 12:35:52 -0700159
160 mAirplaneModePreferenceController.displayPreference(screen);
161 mTetherPreferenceController.displayPreference(screen);
162 mMobileNetworkPreferenceController.displayPreference(screen);
163 mVpnPreferenceController.displayPreference(screen);
Fan Zhangf1acdd32016-10-13 09:53:38 -0700164 mWifiCallingPreferenceController.displayPreference(screen);
165 mNetworkResetPreferenceController.displayPreference(screen);
166 mProxyPreferenceController.displayPreference(screen);
167 mMobilePlanPreferenceController.displayPreference(screen);
Doris Linge2145702016-10-13 17:16:07 -0700168 mNfcPreferenceController.displayPreference(screen);
Irfan Sheriff936e3fa2012-05-07 15:51:37 -0700169
Christopher Tate6a5929b2012-09-10 15:39:05 -0700170 String toggleable = Settings.Global.getString(activity.getContentResolver(),
171 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800172
tk.mun7c5c1652011-10-13 22:56:18 +0900173 //enable/disable wimax depending on the value in config.xml
Xiaohui Chen6f038292015-09-02 16:54:00 -0700174 final boolean isWimaxEnabled = isAdmin && this.getResources().getBoolean(
tk.mun7c5c1652011-10-13 22:56:18 +0900175 com.android.internal.R.bool.config_wimaxEnabled);
Sudheer Shanka9e9e63b2016-02-11 18:48:14 +0000176 if (!isWimaxEnabled || RestrictedLockUtils.hasBaseUserRestriction(activity,
177 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, UserHandle.myUserId())) {
tk.mun7c5c1652011-10-13 22:56:18 +0900178 PreferenceScreen root = getPreferenceScreen();
Xiaohui Chen6f038292015-09-02 16:54:00 -0700179 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
tk.mun7c5c1652011-10-13 22:56:18 +0900180 if (ps != null) root.removePreference(ps);
181 } else {
Fan Zhangf1acdd32016-10-13 09:53:38 -0700182 if (toggleable == null || !toggleable.contains(Settings.Global.RADIO_WIMAX)
tk.mun7c5c1652011-10-13 22:56:18 +0900183 && isWimaxEnabled) {
Xiaohui Chen6f038292015-09-02 16:54:00 -0700184 Preference ps = findPreference(KEY_WIMAX_SETTINGS);
Fan Zhang7f1a4b52016-10-12 12:35:52 -0700185 ps.setDependency(AirplaneModePreferenceController.KEY_TOGGLE_AIRPLANE);
tk.mun7c5c1652011-10-13 22:56:18 +0900186 }
187 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800188 }
Robert Greenwaltc4764d22010-02-12 14:21:37 -0800189
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800190 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700191 public void onResume() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800192 super.onResume();
Danica Chang32711b62010-08-10 18:41:29 -0700193
Fan Zhang7f1a4b52016-10-12 12:35:52 -0700194 mAirplaneModePreferenceController.onResume();
Doris Linge2145702016-10-13 17:16:07 -0700195 mNfcPreferenceController.onResume();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800196 }
Danica Chang32711b62010-08-10 18:41:29 -0700197
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800198 @Override
Wink Saville5d5a2692013-06-29 07:54:13 -0700199 public void onSaveInstanceState(Bundle outState) {
200 super.onSaveInstanceState(outState);
Fan Zhangf1acdd32016-10-13 09:53:38 -0700201 mMobilePlanPreferenceController.onSaveInstanceState(outState);
Wink Saville5d5a2692013-06-29 07:54:13 -0700202 }
203
204 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700205 public void onPause() {
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800206 super.onPause();
Fan Zhang7f1a4b52016-10-12 12:35:52 -0700207 mAirplaneModePreferenceController.onPause();
Doris Linge2145702016-10-13 17:16:07 -0700208 mNfcPreferenceController.onPause();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800209 }
Danica Chang32711b62010-08-10 18:41:29 -0700210
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500211 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700212 public void onActivityResult(int requestCode, int resultCode, Intent data) {
Fan Zhang7f1a4b52016-10-12 12:35:52 -0700213 mAirplaneModePreferenceController.onActivityResult(requestCode, resultCode, data);
Geoffrey Borggaardfe21d9a2013-08-02 18:16:27 -0400214 super.onActivityResult(requestCode, resultCode, data);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500215 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700216
217 @Override
Fan Zhangf1acdd32016-10-13 09:53:38 -0700218 public void showMobilePlanMessageDialog() {
219 showDialog(MANAGE_MOBILE_PLAN_DIALOG_ID);
220 }
221
222 @Override
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700223 protected int getHelpResource() {
224 return R.string.help_url_more_networks;
225 }
David Braun4e9f04d2013-09-16 13:45:42 -0700226
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700227 /**
228 * For Search.
229 */
230 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
Fan Zhangf1acdd32016-10-13 09:53:38 -0700231 new BaseSearchIndexProvider() {
232 @Override
233 public List<SearchIndexableResource> getXmlResourcesToIndex(
234 Context context, boolean enabled) {
235 // Remove wireless settings from search in demo mode
236 if (UserManager.isDeviceInDemoMode(context)) {
237 return Collections.emptyList();
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700238 }
Fan Zhangf1acdd32016-10-13 09:53:38 -0700239 SearchIndexableResource sir = new SearchIndexableResource(context);
240 sir.xmlResId = R.xml.wireless_settings;
241 return Arrays.asList(sir);
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700242 }
243
Fan Zhangf1acdd32016-10-13 09:53:38 -0700244 @Override
245 public List<String> getNonIndexableKeys(Context context) {
246 final ArrayList<String> result = new ArrayList<String>();
247
248 final UserManager um = (UserManager) context.getSystemService(
249 Context.USER_SERVICE);
250 final boolean isSecondaryUser = !um.isAdminUser();
251 final boolean isWimaxEnabled = !isSecondaryUser
252 && context.getResources().getBoolean(
253 com.android.internal.R.bool.config_wimaxEnabled);
254 if (!isWimaxEnabled) {
255 result.add(KEY_WIMAX_SETTINGS);
256 }
257
258 new VpnPreferenceController(context).updateNonIndexableKeys(result);
259
Doris Linge2145702016-10-13 17:16:07 -0700260 new NfcPreferenceController(context).updateNonIndexableKeys(result);
Fan Zhangf1acdd32016-10-13 09:53:38 -0700261 new MobilePlanPreferenceController(context, null /* MobilePlanClickHandler */)
262 .updateNonIndexableKeys(result);
263 new MobileNetworkPreferenceController(context).updateNonIndexableKeys(result);
264
265 // Remove Airplane Mode settings if it's a stationary device such as a TV.
266 new AirplaneModePreferenceController(context, null /* fragment */)
267 .updateNonIndexableKeys(result);
268
269 new ProxyPreferenceController(context).updateNonIndexableKeys(result);
270
271 new TetherPreferenceController(context).updateNonIndexableKeys(result);
272 new WifiCallingPreferenceController(context).updateNonIndexableKeys(result);
273 new NetworkResetPreferenceController(context).updateNonIndexableKeys(result);
274
275 return result;
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700276 }
Fan Zhangf1acdd32016-10-13 09:53:38 -0700277 };
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800278}