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