John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 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.systemui.qs.tiles; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 22 | import android.content.res.Resources; |
| 23 | import android.provider.Settings; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 24 | import android.service.quicksettings.Tile; |
Fabian Kozynski | ab141ea | 2019-02-25 11:14:13 -0500 | [diff] [blame] | 25 | import android.text.TextUtils; |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 26 | import android.util.Log; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 27 | import android.view.View; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 28 | import android.view.ViewGroup; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 29 | import android.widget.Switch; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 30 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 31 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 32 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 33 | import com.android.settingslib.wifi.AccessPoint; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 34 | import com.android.systemui.R; |
Jason Monk | ec34da8 | 2017-02-24 15:57:05 -0500 | [diff] [blame] | 35 | import com.android.systemui.plugins.ActivityStarter; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 36 | import com.android.systemui.plugins.qs.DetailAdapter; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 37 | import com.android.systemui.plugins.qs.QSIconView; |
| 38 | import com.android.systemui.plugins.qs.QSTile; |
| 39 | import com.android.systemui.plugins.qs.QSTile.SignalState; |
Evan Laird | 369ded0 | 2017-09-21 14:11:00 -0400 | [diff] [blame] | 40 | import com.android.systemui.qs.AlphaControlledSignalTileView; |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 41 | import com.android.systemui.qs.QSDetailItems; |
| 42 | import com.android.systemui.qs.QSDetailItems.Item; |
| 43 | import com.android.systemui.qs.QSHost; |
Amin Shaikh | a5902ea | 2018-03-29 14:23:29 -0400 | [diff] [blame] | 44 | import com.android.systemui.qs.tileimpl.QSIconViewImpl; |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 45 | import com.android.systemui.qs.tileimpl.QSTileImpl; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 46 | import com.android.systemui.statusbar.policy.NetworkController; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 47 | import com.android.systemui.statusbar.policy.NetworkController.AccessPointController; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 48 | import com.android.systemui.statusbar.policy.NetworkController.IconState; |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.NetworkController.SignalCallback; |
Fabian Kozynski | 04e4cdf | 2018-12-17 14:00:51 -0500 | [diff] [blame] | 50 | import com.android.systemui.statusbar.policy.WifiIcons; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 51 | |
| 52 | import java.util.List; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 53 | |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 54 | import javax.inject.Inject; |
| 55 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 56 | /** Quick settings tile: Wifi **/ |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 57 | public class WifiTile extends QSTileImpl<SignalState> { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 58 | private static final Intent WIFI_SETTINGS = new Intent(Settings.ACTION_WIFI_SETTINGS); |
| 59 | |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 60 | protected final NetworkController mController; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 61 | private final AccessPointController mWifiController; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 62 | private final WifiDetailAdapter mDetailAdapter; |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 63 | private final QSTile.SignalState mStateBeforeClick = newTileState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 64 | |
Jason Monk | f117961 | 2015-09-23 11:11:00 -0400 | [diff] [blame] | 65 | protected final WifiSignalCallback mSignalCallback = new WifiSignalCallback(); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 66 | private final ActivityStarter mActivityStarter; |
Amin Shaikh | a5902ea | 2018-03-29 14:23:29 -0400 | [diff] [blame] | 67 | private boolean mExpectDisabled; |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 68 | |
Jason Monk | 5d57720 | 2018-12-26 15:43:06 -0500 | [diff] [blame] | 69 | @Inject |
Jason Monk | c0e0e2b | 2018-12-26 16:47:41 -0500 | [diff] [blame] | 70 | public WifiTile(QSHost host, NetworkController networkController, |
| 71 | ActivityStarter activityStarter) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 72 | super(host); |
Jason Monk | c0e0e2b | 2018-12-26 16:47:41 -0500 | [diff] [blame] | 73 | mController = networkController; |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 74 | mWifiController = mController.getAccessPointController(); |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 75 | mDetailAdapter = (WifiDetailAdapter) createDetailAdapter(); |
Jason Monk | c0e0e2b | 2018-12-26 16:47:41 -0500 | [diff] [blame] | 76 | mActivityStarter = activityStarter; |
Jason Monk | fa452ef | 2018-12-26 17:26:10 -0500 | [diff] [blame] | 77 | mController.observe(getLifecycle(), mSignalCallback); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
Jason Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 81 | public SignalState newTileState() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 82 | return new SignalState(); |
| 83 | } |
| 84 | |
| 85 | @Override |
Jason Monk | 1c6116c | 2017-09-06 17:33:01 -0400 | [diff] [blame] | 86 | public void handleSetListening(boolean listening) { |
Jason Monk | 0d6a1c4 | 2015-04-20 16:38:51 -0400 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public void setDetailListening(boolean listening) { |
| 91 | if (listening) { |
| 92 | mWifiController.addAccessPointCallback(mDetailAdapter); |
| 93 | } else { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 94 | mWifiController.removeAccessPointCallback(mDetailAdapter); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 95 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 99 | public DetailAdapter getDetailAdapter() { |
| 100 | return mDetailAdapter; |
| 101 | } |
| 102 | |
| 103 | @Override |
Jason Monk | be3235a | 2017-04-05 09:29:53 -0400 | [diff] [blame] | 104 | protected DetailAdapter createDetailAdapter() { |
| 105 | return new WifiDetailAdapter(); |
| 106 | } |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 107 | |
| 108 | @Override |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 109 | public QSIconView createTileView(Context context) { |
Evan Laird | 369ded0 | 2017-09-21 14:11:00 -0400 | [diff] [blame] | 110 | return new AlphaControlledSignalTileView(context); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 114 | public Intent getLongClickIntent() { |
| 115 | return WIFI_SETTINGS; |
| 116 | } |
| 117 | |
| 118 | @Override |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 119 | protected void handleClick() { |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 120 | // Secondary clicks are header clicks, just toggle. |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 121 | mState.copyTo(mStateBeforeClick); |
Amin Shaikh | d03a743 | 2018-03-01 15:46:55 -0500 | [diff] [blame] | 122 | boolean wifiEnabled = mState.value; |
| 123 | // Immediately enter transient state when turning on wifi. |
| 124 | refreshState(wifiEnabled ? null : ARG_SHOW_TRANSIENT_ENABLING); |
| 125 | mController.setWifiEnabled(!wifiEnabled); |
Amin Shaikh | a5902ea | 2018-03-29 14:23:29 -0400 | [diff] [blame] | 126 | mExpectDisabled = wifiEnabled; |
| 127 | if (mExpectDisabled) { |
| 128 | mHandler.postDelayed(() -> { |
| 129 | if (mExpectDisabled) { |
| 130 | mExpectDisabled = false; |
| 131 | refreshState(); |
| 132 | } |
| 133 | }, QSIconViewImpl.QS_ANIM_LENGTH); |
| 134 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Override |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 138 | protected void handleSecondaryClick() { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 139 | if (!mWifiController.canConfigWifi()) { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 140 | mActivityStarter.postStartActivityDismissingKeyguard( |
| 141 | new Intent(Settings.ACTION_WIFI_SETTINGS), 0); |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 142 | return; |
| 143 | } |
Jason Monk | 48e093e | 2016-07-15 10:37:07 -0400 | [diff] [blame] | 144 | showDetail(true); |
Jason Monk | 3c3b650 | 2017-07-27 15:41:26 -0400 | [diff] [blame] | 145 | if (!mState.value) { |
| 146 | mController.setWifiEnabled(true); |
| 147 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | @Override |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 151 | public CharSequence getTileLabel() { |
| 152 | return mContext.getString(R.string.quick_settings_wifi_label); |
| 153 | } |
| 154 | |
| 155 | @Override |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 156 | protected void handleUpdateState(SignalState state, Object arg) { |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 157 | if (DEBUG) Log.d(TAG, "handleUpdateState arg=" + arg); |
Amin Shaikh | a5902ea | 2018-03-29 14:23:29 -0400 | [diff] [blame] | 158 | final CallbackInfo cb = mSignalCallback.mInfo; |
| 159 | if (mExpectDisabled) { |
| 160 | if (cb.enabled) { |
| 161 | return; // Ignore updates until disabled event occurs. |
| 162 | } else { |
| 163 | mExpectDisabled = false; |
| 164 | } |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 165 | } |
Amin Shaikh | d03a743 | 2018-03-01 15:46:55 -0500 | [diff] [blame] | 166 | boolean transientEnabling = arg == ARG_SHOW_TRANSIENT_ENABLING; |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 167 | boolean wifiConnected = cb.enabled && (cb.wifiSignalIconId > 0) && (cb.ssid != null); |
| 168 | boolean wifiNotConnected = (cb.wifiSignalIconId > 0) && (cb.ssid == null); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 169 | boolean enabledChanging = state.value != cb.enabled; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 170 | if (enabledChanging) { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 171 | mDetailAdapter.setItemsVisible(cb.enabled); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 172 | fireToggleStateChanged(cb.enabled); |
| 173 | } |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame] | 174 | if (state.slash == null) { |
| 175 | state.slash = new SlashState(); |
Evan Laird | 8d2e540 | 2017-06-08 10:36:57 -0400 | [diff] [blame] | 176 | state.slash.rotation = 6; |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame] | 177 | } |
| 178 | state.slash.isSlashed = false; |
Amin Shaikh | d03a743 | 2018-03-01 15:46:55 -0500 | [diff] [blame] | 179 | boolean isTransient = transientEnabling || cb.isTransient; |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 180 | state.secondaryLabel = getSecondaryLabel(isTransient, cb.statusLabel); |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame] | 181 | state.state = Tile.STATE_ACTIVE; |
Jason Monk | 2db4619 | 2017-02-01 17:18:22 -0500 | [diff] [blame] | 182 | state.dualTarget = true; |
Amin Shaikh | d03a743 | 2018-03-01 15:46:55 -0500 | [diff] [blame] | 183 | state.value = transientEnabling || cb.enabled; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 184 | state.activityIn = cb.enabled && cb.activityIn; |
| 185 | state.activityOut = cb.enabled && cb.activityOut; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 186 | final StringBuffer minimalContentDescription = new StringBuffer(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 187 | final Resources r = mContext.getResources(); |
Amin Shaikh | d03a743 | 2018-03-01 15:46:55 -0500 | [diff] [blame] | 188 | if (isTransient) { |
Amin Shaikh | 2cea879 | 2019-04-30 09:19:01 -0400 | [diff] [blame^] | 189 | state.icon = ResourceIcon.get( |
| 190 | com.android.internal.R.drawable.ic_signal_wifi_transient_animation); |
Jason Monk | 110e5f6 | 2017-03-31 13:45:12 -0400 | [diff] [blame] | 191 | state.label = r.getString(R.string.quick_settings_wifi_label); |
| 192 | } else if (!state.value) { |
Jason Monk | 395617f | 2017-05-05 14:07:58 -0400 | [diff] [blame] | 193 | state.slash.isSlashed = true; |
| 194 | state.state = Tile.STATE_INACTIVE; |
Fabian Kozynski | 04e4cdf | 2018-12-17 14:00:51 -0500 | [diff] [blame] | 195 | state.icon = ResourceIcon.get(WifiIcons.QS_WIFI_DISABLED); |
John Spurlock | c1d48a5 | 2014-08-01 12:12:32 -0400 | [diff] [blame] | 196 | state.label = r.getString(R.string.quick_settings_wifi_label); |
John Spurlock | c1d48a5 | 2014-08-01 12:12:32 -0400 | [diff] [blame] | 197 | } else if (wifiConnected) { |
John Spurlock | 2d69581 | 2014-10-30 13:25:21 -0400 | [diff] [blame] | 198 | state.icon = ResourceIcon.get(cb.wifiSignalIconId); |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 199 | state.label = removeDoubleQuotes(cb.ssid); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 200 | } else if (wifiNotConnected) { |
Jason Monk | be83cc0 | 2016-03-31 13:38:59 -0400 | [diff] [blame] | 201 | state.icon = ResourceIcon.get(R.drawable.ic_qs_wifi_disconnected); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 202 | state.label = r.getString(R.string.quick_settings_wifi_label); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 203 | } else { |
Amin Shaikh | dd73e16 | 2019-04-02 07:50:27 -0400 | [diff] [blame] | 204 | state.icon = ResourceIcon.get(WifiIcons.QS_WIFI_NO_NETWORK); |
John Spurlock | 012d4a2 | 2014-06-04 00:40:18 -0400 | [diff] [blame] | 205 | state.label = r.getString(R.string.quick_settings_wifi_label); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 206 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 207 | minimalContentDescription.append( |
| 208 | mContext.getString(R.string.quick_settings_wifi_label)).append(","); |
| 209 | if (state.value) { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 210 | if (wifiConnected) { |
| 211 | minimalContentDescription.append(cb.wifiSignalContentDescription).append(","); |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 212 | minimalContentDescription.append(removeDoubleQuotes(cb.ssid)); |
Fabian Kozynski | ab141ea | 2019-02-25 11:14:13 -0500 | [diff] [blame] | 213 | if (!TextUtils.isEmpty(state.secondaryLabel)) { |
| 214 | minimalContentDescription.append(",").append(state.secondaryLabel); |
| 215 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 216 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 217 | } |
Jason Monk | 90950d9 | 2017-06-20 13:16:05 -0400 | [diff] [blame] | 218 | state.contentDescription = minimalContentDescription.toString(); |
Jason Monk | 28df4ed | 2017-03-23 10:25:37 -0400 | [diff] [blame] | 219 | state.dualLabelContentDescription = r.getString( |
| 220 | R.string.accessibility_quick_settings_open_settings, getTileLabel()); |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 221 | state.expandedAccessibilityClassName = Switch.class.getName(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 224 | private CharSequence getSecondaryLabel(boolean isTransient, String statusLabel) { |
Amin Shaikh | d03a743 | 2018-03-01 15:46:55 -0500 | [diff] [blame] | 225 | return isTransient |
| 226 | ? mContext.getString(R.string.quick_settings_wifi_secondary_label_transient) |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 227 | : statusLabel; |
Amin Shaikh | d03a743 | 2018-03-01 15:46:55 -0500 | [diff] [blame] | 228 | } |
| 229 | |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 230 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 231 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 232 | return MetricsEvent.QS_WIFI; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | @Override |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 236 | protected boolean shouldAnnouncementBeDelayed() { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 237 | return mStateBeforeClick.value == mState.value; |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | protected String composeChangeAnnouncement() { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 242 | if (mState.value) { |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 243 | return mContext.getString(R.string.accessibility_quick_settings_wifi_changed_on); |
| 244 | } else { |
| 245 | return mContext.getString(R.string.accessibility_quick_settings_wifi_changed_off); |
| 246 | } |
| 247 | } |
| 248 | |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 249 | @Override |
| 250 | public boolean isAvailable() { |
| 251 | return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI); |
| 252 | } |
| 253 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 254 | private static String removeDoubleQuotes(String string) { |
| 255 | if (string == null) return null; |
| 256 | final int length = string.length(); |
| 257 | if ((length > 1) && (string.charAt(0) == '"') && (string.charAt(length - 1) == '"')) { |
| 258 | return string.substring(1, length - 1); |
| 259 | } |
| 260 | return string; |
| 261 | } |
| 262 | |
Jason Monk | f117961 | 2015-09-23 11:11:00 -0400 | [diff] [blame] | 263 | protected static final class CallbackInfo { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 264 | boolean enabled; |
John Spurlock | d5cd2fd | 2014-07-27 11:36:33 -0400 | [diff] [blame] | 265 | boolean connected; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 266 | int wifiSignalIconId; |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 267 | String ssid; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 268 | boolean activityIn; |
| 269 | boolean activityOut; |
| 270 | String wifiSignalContentDescription; |
Jason Monk | 110e5f6 | 2017-03-31 13:45:12 -0400 | [diff] [blame] | 271 | boolean isTransient; |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 272 | public String statusLabel; |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 273 | |
| 274 | @Override |
| 275 | public String toString() { |
| 276 | return new StringBuilder("CallbackInfo[") |
Jason Monk | be3235a | 2017-04-05 09:29:53 -0400 | [diff] [blame] | 277 | .append("enabled=").append(enabled) |
| 278 | .append(",connected=").append(connected) |
| 279 | .append(",wifiSignalIconId=").append(wifiSignalIconId) |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 280 | .append(",ssid=").append(ssid) |
Jason Monk | be3235a | 2017-04-05 09:29:53 -0400 | [diff] [blame] | 281 | .append(",activityIn=").append(activityIn) |
| 282 | .append(",activityOut=").append(activityOut) |
| 283 | .append(",wifiSignalContentDescription=").append(wifiSignalContentDescription) |
| 284 | .append(",isTransient=").append(isTransient) |
| 285 | .append(']').toString(); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 286 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 287 | } |
| 288 | |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 289 | protected final class WifiSignalCallback implements SignalCallback { |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 290 | final CallbackInfo mInfo = new CallbackInfo(); |
| 291 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 292 | @Override |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 293 | public void setWifiIndicators(boolean enabled, IconState statusIcon, IconState qsIcon, |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 294 | boolean activityIn, boolean activityOut, String description, boolean isTransient, |
| 295 | String statusLabel) { |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 296 | if (DEBUG) Log.d(TAG, "onWifiSignalChanged enabled=" + enabled); |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 297 | mInfo.enabled = enabled; |
| 298 | mInfo.connected = qsIcon.visible; |
| 299 | mInfo.wifiSignalIconId = qsIcon.icon; |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 300 | mInfo.ssid = description; |
Jason Monk | 878c093 | 2015-07-21 10:18:01 -0400 | [diff] [blame] | 301 | mInfo.activityIn = activityIn; |
| 302 | mInfo.activityOut = activityOut; |
| 303 | mInfo.wifiSignalContentDescription = qsIcon.contentDescription; |
Jason Monk | 110e5f6 | 2017-03-31 13:45:12 -0400 | [diff] [blame] | 304 | mInfo.isTransient = isTransient; |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 305 | mInfo.statusLabel = statusLabel; |
Jason Monk | be3235a | 2017-04-05 09:29:53 -0400 | [diff] [blame] | 306 | if (isShowingDetail()) { |
| 307 | mDetailAdapter.updateItems(); |
| 308 | } |
Amin Shaikh | a5902ea | 2018-03-29 14:23:29 -0400 | [diff] [blame] | 309 | refreshState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 310 | } |
Jason Monk | be3235a | 2017-04-05 09:29:53 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 313 | protected class WifiDetailAdapter implements DetailAdapter, |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 314 | NetworkController.AccessPointController.AccessPointCallback, QSDetailItems.Callback { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 315 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 316 | private QSDetailItems mItems; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 317 | private AccessPoint[] mAccessPoints; |
| 318 | |
| 319 | @Override |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 320 | public CharSequence getTitle() { |
| 321 | return mContext.getString(R.string.quick_settings_wifi_label); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | public Intent getSettingsIntent() { |
| 325 | return WIFI_SETTINGS; |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public Boolean getToggleState() { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 330 | return mState.value; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public void setToggleState(boolean state) { |
| 335 | if (DEBUG) Log.d(TAG, "setToggleState " + state); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 336 | MetricsLogger.action(mContext, MetricsEvent.QS_WIFI_TOGGLE, state); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 337 | mController.setWifiEnabled(state); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | @Override |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 341 | public int getMetricsCategory() { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 342 | return MetricsEvent.QS_WIFI_DETAILS; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | @Override |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 346 | public View createDetailView(Context context, View convertView, ViewGroup parent) { |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 347 | if (DEBUG) Log.d(TAG, "createDetailView convertView=" + (convertView != null)); |
| 348 | mAccessPoints = null; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 349 | mItems = QSDetailItems.convertOrInflate(context, convertView, parent); |
| 350 | mItems.setTagSuffix("Wifi"); |
| 351 | mItems.setCallback(this); |
Sundeep Ghuman | c09b7f7 | 2017-07-26 20:23:32 -0700 | [diff] [blame] | 352 | mWifiController.scanForAccessPoints(); // updates APs and items |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 353 | setItemsVisible(mState.value); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 354 | return mItems; |
| 355 | } |
| 356 | |
| 357 | @Override |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 358 | public void onAccessPointsChanged(final List<AccessPoint> accessPoints) { |
| 359 | mAccessPoints = accessPoints.toArray(new AccessPoint[accessPoints.size()]); |
Sundeep Ghuman | ce5fbd4 | 2017-07-18 15:16:01 -0700 | [diff] [blame] | 360 | filterUnreachableAPs(); |
| 361 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 362 | updateItems(); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 363 | } |
| 364 | |
Sundeep Ghuman | ce5fbd4 | 2017-07-18 15:16:01 -0700 | [diff] [blame] | 365 | /** Filter unreachable APs from mAccessPoints */ |
| 366 | private void filterUnreachableAPs() { |
| 367 | int numReachable = 0; |
| 368 | for (AccessPoint ap : mAccessPoints) { |
| 369 | if (ap.isReachable()) numReachable++; |
| 370 | } |
| 371 | if (numReachable != mAccessPoints.length) { |
| 372 | AccessPoint[] unfiltered = mAccessPoints; |
| 373 | mAccessPoints = new AccessPoint[numReachable]; |
| 374 | int i = 0; |
| 375 | for (AccessPoint ap : unfiltered) { |
| 376 | if (ap.isReachable()) mAccessPoints[i++] = ap; |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 381 | @Override |
Jason Monk | 17f3c3f | 2015-01-14 10:13:22 -0500 | [diff] [blame] | 382 | public void onSettingsActivityTriggered(Intent settingsIntent) { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 383 | mActivityStarter.postStartActivityDismissingKeyguard(settingsIntent, 0); |
Jason Monk | 17f3c3f | 2015-01-14 10:13:22 -0500 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | @Override |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 387 | public void onDetailItemClick(Item item) { |
| 388 | if (item == null || item.tag == null) return; |
| 389 | final AccessPoint ap = (AccessPoint) item.tag; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 390 | if (!ap.isActive()) { |
Jason Monk | d2263cd | 2014-11-10 14:22:56 -0500 | [diff] [blame] | 391 | if (mWifiController.connect(ap)) { |
Jason Monk | 5d32507 | 2014-10-27 11:38:47 -0400 | [diff] [blame] | 392 | mHost.collapsePanels(); |
| 393 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 394 | } |
| 395 | showDetail(false); |
| 396 | } |
| 397 | |
| 398 | @Override |
| 399 | public void onDetailItemDisconnect(Item item) { |
| 400 | // noop |
| 401 | } |
| 402 | |
| 403 | public void setItemsVisible(boolean visible) { |
| 404 | if (mItems == null) return; |
| 405 | mItems.setItemsVisible(visible); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | private void updateItems() { |
| 409 | if (mItems == null) return; |
Jason Monk | d9fcc64 | 2017-08-01 10:13:43 -0400 | [diff] [blame] | 410 | if ((mAccessPoints != null && mAccessPoints.length > 0) |
| 411 | || !mSignalCallback.mInfo.enabled) { |
| 412 | fireScanStateChanged(false); |
| 413 | } else { |
| 414 | fireScanStateChanged(true); |
| 415 | } |
Evan Laird | f6139f9 | 2017-05-24 16:25:57 -0400 | [diff] [blame] | 416 | |
| 417 | // Wi-Fi is off |
| 418 | if (!mSignalCallback.mInfo.enabled) { |
Amin Shaikh | dd73e16 | 2019-04-02 07:50:27 -0400 | [diff] [blame] | 419 | mItems.setEmptyState(WifiIcons.QS_WIFI_NO_NETWORK, |
Jason Monk | be3235a | 2017-04-05 09:29:53 -0400 | [diff] [blame] | 420 | R.string.wifi_is_off); |
Evan Laird | f6139f9 | 2017-05-24 16:25:57 -0400 | [diff] [blame] | 421 | mItems.setItems(null); |
| 422 | return; |
Jason Monk | be3235a | 2017-04-05 09:29:53 -0400 | [diff] [blame] | 423 | } |
Evan Laird | f6139f9 | 2017-05-24 16:25:57 -0400 | [diff] [blame] | 424 | |
| 425 | // No available access points |
Amin Shaikh | dd73e16 | 2019-04-02 07:50:27 -0400 | [diff] [blame] | 426 | mItems.setEmptyState(WifiIcons.QS_WIFI_NO_NETWORK, |
Evan Laird | f6139f9 | 2017-05-24 16:25:57 -0400 | [diff] [blame] | 427 | R.string.quick_settings_wifi_detail_empty_text); |
| 428 | |
| 429 | // Build the list |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 430 | Item[] items = null; |
| 431 | if (mAccessPoints != null) { |
| 432 | items = new Item[mAccessPoints.length]; |
| 433 | for (int i = 0; i < mAccessPoints.length; i++) { |
| 434 | final AccessPoint ap = mAccessPoints[i]; |
| 435 | final Item item = new Item(); |
| 436 | item.tag = ap; |
jackqdyulei | 786a490 | 2017-10-24 13:27:53 -0700 | [diff] [blame] | 437 | item.iconResId = mWifiController.getIcon(ap); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 438 | item.line1 = ap.getSsid(); |
Jason Monk | 283c8b7 | 2015-05-26 12:54:12 -0400 | [diff] [blame] | 439 | item.line2 = ap.isActive() ? ap.getSummary() : null; |
Sundeep Ghuman | ff0f108 | 2017-02-10 11:49:36 -0800 | [diff] [blame] | 440 | item.icon2 = ap.getSecurity() != AccessPoint.SECURITY_NONE |
| 441 | ? R.drawable.qs_ic_wifi_lock |
| 442 | : -1; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 443 | items[i] = item; |
| 444 | } |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 445 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 446 | mItems.setItems(items); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 447 | } |
Fan Zhang | 3bfda44 | 2016-07-15 10:39:03 -0700 | [diff] [blame] | 448 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 449 | } |