Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 1 | /* |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.car; |
| 18 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 20 | import android.app.ActivityTaskManager; |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 21 | import android.car.drivingstate.CarDrivingStateEvent; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 22 | import android.graphics.PixelFormat; |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 23 | import android.graphics.drawable.Drawable; |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 24 | import android.util.Log; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 25 | import android.view.GestureDetector; |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 26 | import android.view.Gravity; |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 27 | import android.view.MotionEvent; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 28 | import android.view.View; |
Anthony Chen | 0801a5c | 2017-03-22 09:54:37 -0700 | [diff] [blame] | 29 | import android.view.ViewGroup; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 30 | import android.view.ViewGroup.LayoutParams; |
| 31 | import android.view.WindowManager; |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 32 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 33 | import androidx.annotation.NonNull; |
| 34 | import androidx.recyclerview.widget.RecyclerView; |
| 35 | |
| 36 | import com.android.car.notification.CarNotificationListener; |
| 37 | import com.android.car.notification.CarNotificationView; |
| 38 | import com.android.car.notification.CarUxRestrictionManagerWrapper; |
| 39 | import com.android.car.notification.NotificationClickHandlerFactory; |
| 40 | import com.android.car.notification.NotificationViewController; |
| 41 | import com.android.car.notification.PreprocessingManager; |
Winson Chung | 2db3557 | 2017-10-09 15:08:30 -0700 | [diff] [blame] | 42 | import com.android.keyguard.KeyguardUpdateMonitor; |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 43 | import com.android.systemui.BatteryMeterView; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 44 | import com.android.systemui.CarSystemUIFactory; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 45 | import com.android.systemui.Dependency; |
Winson Chung | 2db3557 | 2017-10-09 15:08:30 -0700 | [diff] [blame] | 46 | import com.android.systemui.Prefs; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 47 | import com.android.systemui.R; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 48 | import com.android.systemui.SystemUIFactory; |
Winson Chung | 2db3557 | 2017-10-09 15:08:30 -0700 | [diff] [blame] | 49 | import com.android.systemui.classifier.FalsingLog; |
| 50 | import com.android.systemui.classifier.FalsingManager; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 51 | import com.android.systemui.fragments.FragmentHostManager; |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 52 | import com.android.systemui.plugins.qs.QS; |
| 53 | import com.android.systemui.qs.car.CarQSFragment; |
Winson Chung | b05b398 | 2017-11-01 18:02:43 -0700 | [diff] [blame] | 54 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 55 | import com.android.systemui.shared.system.TaskStackChangeListener; |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 56 | import com.android.systemui.statusbar.StatusBarState; |
Brad Stenning | 38b46f8 | 2018-03-27 13:57:29 -0700 | [diff] [blame] | 57 | import com.android.systemui.statusbar.car.hvac.HvacController; |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 58 | import com.android.systemui.statusbar.car.hvac.TemperatureView; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 59 | import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 60 | import com.android.systemui.statusbar.phone.StatusBar; |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 61 | import com.android.systemui.statusbar.policy.BatteryController; |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 62 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 63 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 64 | |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 65 | import java.io.FileDescriptor; |
| 66 | import java.io.PrintWriter; |
| 67 | import java.util.Map; |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 68 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 69 | /** |
| 70 | * A status bar (and navigation bar) tailored for the automotive use case. |
| 71 | */ |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 72 | public class CarStatusBar extends StatusBar implements |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 73 | CarBatteryController.BatteryViewHandler { |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 74 | private static final String TAG = "CarStatusBar"; |
| 75 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 76 | private TaskStackListenerImpl mTaskStackListener; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 77 | |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 78 | private FullscreenUserSwitcher mFullscreenUserSwitcher; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 79 | |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 80 | private CarBatteryController mCarBatteryController; |
| 81 | private BatteryMeterView mBatteryMeterView; |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 82 | private Drawable mNotificationPanelBackground; |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 83 | |
Scott Randolph | f408582 | 2017-06-27 15:23:01 -0700 | [diff] [blame] | 84 | private ViewGroup mNavigationBarWindow; |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 85 | private ViewGroup mLeftNavigationBarWindow; |
| 86 | private ViewGroup mRightNavigationBarWindow; |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 87 | private CarNavigationBarView mNavigationBarView; |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 88 | private CarNavigationBarView mLeftNavigationBarView; |
| 89 | private CarNavigationBarView mRightNavigationBarView; |
Anthony Chen | 1c59e9f | 2016-04-11 11:05:48 -0700 | [diff] [blame] | 90 | |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 91 | private final Object mQueueLock = new Object(); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 92 | private boolean mShowLeft; |
| 93 | private boolean mShowRight; |
| 94 | private boolean mShowBottom; |
| 95 | private CarFacetButtonController mCarFacetButtonController; |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 96 | private ActivityManagerWrapper mActivityManagerWrapper; |
| 97 | private DeviceProvisionedController mDeviceProvisionedController; |
| 98 | private boolean mDeviceIsProvisioned = true; |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 99 | private HvacController mHvacController; |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 100 | private DrivingStateHelper mDrivingStateHelper; |
| 101 | private SwitchToGuestTimer mSwitchToGuestTimer; |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 102 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 103 | // The container for the notifications. |
| 104 | private CarNotificationView mNotificationView; |
| 105 | private RecyclerView mNotificationList; |
| 106 | // The state of if the notification list is currently showing the bottom. |
| 107 | private boolean mNotificationListAtBottom; |
| 108 | // Was the notification list at the bottom when the user first touched the screen |
| 109 | private boolean mNotificationListAtBottomAtTimeOfTouch; |
| 110 | // To be attached to the navigation bars such that they can close the notification panel if |
| 111 | // it's open. |
| 112 | private View.OnTouchListener mNavBarNotificationTouchListener; |
| 113 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 114 | @Override |
| 115 | public void start() { |
Brad Stenning | eb6051c | 2019-02-27 13:46:11 -0800 | [diff] [blame] | 116 | // get the provisioned state before calling the parent class since it's that flow that |
| 117 | // builds the nav bar |
| 118 | mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); |
| 119 | mDeviceIsProvisioned = mDeviceProvisionedController.isDeviceProvisioned(); |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 120 | super.start(); |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 121 | mTaskStackListener = new TaskStackListenerImpl(); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 122 | mActivityManagerWrapper = ActivityManagerWrapper.getInstance(); |
| 123 | mActivityManagerWrapper.registerTaskStackListener(mTaskStackListener); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 124 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 125 | mNotificationPanel.setScrollingEnabled(true); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 126 | |
Rakesh Iyer | 545e47d | 2017-01-23 18:10:21 -0800 | [diff] [blame] | 127 | createBatteryController(); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 128 | mCarBatteryController.startListening(); |
Brad Stenning | 38b46f8 | 2018-03-27 13:57:29 -0700 | [diff] [blame] | 129 | |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 130 | mHvacController.connectToCarService(); |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 131 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 132 | CarSystemUIFactory factory = SystemUIFactory.getInstance(); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 133 | if (!mDeviceIsProvisioned) { |
| 134 | mDeviceProvisionedController.addCallback( |
| 135 | new DeviceProvisionedController.DeviceProvisionedListener() { |
| 136 | @Override |
| 137 | public void onDeviceProvisionedChanged() { |
Brad Stenning | a2d87d8 | 2019-01-24 12:33:10 -0800 | [diff] [blame] | 138 | mHandler.post(() -> { |
| 139 | // on initial boot we are getting a call even though the value |
| 140 | // is the same so we are confirming the reset is needed |
| 141 | boolean deviceProvisioned = |
| 142 | mDeviceProvisionedController.isDeviceProvisioned(); |
| 143 | if (mDeviceIsProvisioned != deviceProvisioned) { |
| 144 | mDeviceIsProvisioned = deviceProvisioned; |
| 145 | restartNavBars(); |
| 146 | } |
| 147 | }); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 148 | } |
| 149 | }); |
| 150 | } |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 151 | |
| 152 | // Register a listener for driving state changes. |
| 153 | mDrivingStateHelper = new DrivingStateHelper(mContext, this::onDrivingStateChanged); |
| 154 | mDrivingStateHelper.connectToCarService(); |
| 155 | |
| 156 | mSwitchToGuestTimer = new SwitchToGuestTimer(mContext); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Remove all content from navbars and rebuild them. Used to allow for different nav bars |
Guobin Zhang | eef0e0c | 2019-02-01 11:54:24 -0800 | [diff] [blame] | 161 | * before and after the device is provisioned. . Also for change of density and font size. |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 162 | */ |
| 163 | private void restartNavBars() { |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 164 | // remove and reattach all hvac components such that we don't keep a reference to unused |
| 165 | // ui elements |
| 166 | mHvacController.removeAllComponents(); |
| 167 | addTemperatureViewToController(mStatusBarWindow); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 168 | mCarFacetButtonController.removeAll(); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 169 | if (mNavigationBarWindow != null) { |
| 170 | mNavigationBarWindow.removeAllViews(); |
| 171 | mNavigationBarView = null; |
| 172 | } |
| 173 | |
| 174 | if (mLeftNavigationBarWindow != null) { |
| 175 | mLeftNavigationBarWindow.removeAllViews(); |
| 176 | mLeftNavigationBarView = null; |
| 177 | } |
| 178 | |
| 179 | if (mRightNavigationBarWindow != null) { |
| 180 | mRightNavigationBarWindow.removeAllViews(); |
| 181 | mRightNavigationBarView = null; |
| 182 | } |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 183 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 184 | buildNavBarContent(); |
Brad Stenning | 7522164 | 2019-03-13 07:33:24 -0700 | [diff] [blame] | 185 | // If the UI was rebuilt (day/night change) while the keyguard was up we need to |
| 186 | // correctly respect that state. |
| 187 | if (mIsKeyguard) { |
| 188 | updateNavBarForKeyguardContent(); |
| 189 | } |
Brad Stenning | 4534f44 | 2019-04-01 21:43:32 -0700 | [diff] [blame^] | 190 | // CarFacetButtonController was reset therefore we need to re-add the status bar elements |
| 191 | // to the controller. |
| 192 | mCarFacetButtonController.addAllFacetButtons(mStatusBarWindow); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 195 | private void addTemperatureViewToController(View v) { |
| 196 | if (v instanceof TemperatureView) { |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 197 | mHvacController.addHvacTextView((TemperatureView) v); |
| 198 | } else if (v instanceof ViewGroup) { |
| 199 | ViewGroup viewGroup = (ViewGroup) v; |
| 200 | for (int i = 0; i < viewGroup.getChildCount(); i++) { |
| 201 | addTemperatureViewToController(viewGroup.getChildAt(i)); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 206 | /** |
| 207 | * Allows for showing or hiding just the navigation bars. This is indented to be used when |
| 208 | * the full screen user selector is shown. |
| 209 | */ |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 210 | void setNavBarVisibility(@View.Visibility int visibility) { |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 211 | if (mNavigationBarWindow != null) { |
| 212 | mNavigationBarWindow.setVisibility(visibility); |
| 213 | } |
| 214 | if (mLeftNavigationBarWindow != null) { |
| 215 | mLeftNavigationBarWindow.setVisibility(visibility); |
| 216 | } |
| 217 | if (mRightNavigationBarWindow != null) { |
| 218 | mRightNavigationBarWindow.setVisibility(visibility); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | |
| 223 | @Override |
| 224 | public boolean hideKeyguard() { |
| 225 | boolean result = super.hideKeyguard(); |
| 226 | if (mNavigationBarView != null) { |
| 227 | mNavigationBarView.hideKeyguardButtons(); |
| 228 | } |
| 229 | if (mLeftNavigationBarView != null) { |
| 230 | mLeftNavigationBarView.hideKeyguardButtons(); |
| 231 | } |
| 232 | if (mRightNavigationBarView != null) { |
| 233 | mRightNavigationBarView.hideKeyguardButtons(); |
| 234 | } |
| 235 | return result; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | @Override |
| 240 | public void showKeyguard() { |
| 241 | super.showKeyguard(); |
Brad Stenning | 7522164 | 2019-03-13 07:33:24 -0700 | [diff] [blame] | 242 | updateNavBarForKeyguardContent(); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Switch to the keyguard applicable content contained in the nav bars |
| 247 | */ |
| 248 | private void updateNavBarForKeyguardContent() { |
Brad Stenning | 7e41181 | 2018-04-13 22:52:39 -0700 | [diff] [blame] | 249 | if (mNavigationBarView != null) { |
| 250 | mNavigationBarView.showKeyguardButtons(); |
| 251 | } |
| 252 | if (mLeftNavigationBarView != null) { |
| 253 | mLeftNavigationBarView.showKeyguardButtons(); |
| 254 | } |
| 255 | if (mRightNavigationBarView != null) { |
| 256 | mRightNavigationBarView.showKeyguardButtons(); |
| 257 | } |
| 258 | } |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 259 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 260 | |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 261 | @Override |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 262 | protected void makeStatusBarView() { |
| 263 | super.makeStatusBarView(); |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 264 | mHvacController = new HvacController(mContext); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 265 | |
Guobin Zhang | eef0e0c | 2019-02-01 11:54:24 -0800 | [diff] [blame] | 266 | CarSystemUIFactory factory = SystemUIFactory.getInstance(); |
| 267 | mCarFacetButtonController = factory.getCarDependencyComponent() |
| 268 | .getCarFacetButtonController(); |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 269 | mNotificationPanelBackground = getDefaultWallpaper(); |
| 270 | mScrimController.setScrimBehindDrawable(mNotificationPanelBackground); |
| 271 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 272 | FragmentHostManager manager = FragmentHostManager.get(mStatusBarWindow); |
| 273 | manager.addTagListener(CollapsedStatusBarFragment.TAG, (tag, fragment) -> { |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 274 | mBatteryMeterView = fragment.getView().findViewById(R.id.battery); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 275 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 276 | // By default, the BatteryMeterView should not be visible. It will be toggled |
| 277 | // when a device has connected by bluetooth. |
| 278 | mBatteryMeterView.setVisibility(View.GONE); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 279 | }); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 280 | |
| 281 | connectNotificationsUI(); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Attach the notification listeners and controllers to the UI as well as build all the |
| 286 | * touch listeners needed for opening and closing the notification panel |
| 287 | */ |
| 288 | private void connectNotificationsUI() { |
| 289 | // Attached to the status bar to detect pull down of the notification shade. |
| 290 | GestureDetector openGestureDetector = new GestureDetector(mContext, |
| 291 | new OpenNotificationGestureListener() { |
| 292 | @Override |
| 293 | protected void openNotification() { |
| 294 | animateExpandNotificationsPanel(); |
| 295 | } |
| 296 | }); |
| 297 | // Attached to the notification ui to detect close request of the notification shade. |
| 298 | GestureDetector closeGestureDetector = new GestureDetector(mContext, |
| 299 | new CloseNotificationGestureListener() { |
| 300 | @Override |
| 301 | protected void close() { |
| 302 | animateCollapsePanels(); |
| 303 | } |
| 304 | }); |
| 305 | // Attached to the NavBars to close the notification shade |
| 306 | GestureDetector navBarCloseNotificationGestureDetector = new GestureDetector(mContext, |
| 307 | new NavBarCloseNotificationGestureListener() { |
| 308 | @Override |
| 309 | protected void close() { |
| 310 | animateCollapsePanels(); |
| 311 | } |
| 312 | }); |
| 313 | mNavBarNotificationTouchListener = |
| 314 | (v, event) -> navBarCloseNotificationGestureDetector.onTouchEvent(event); |
| 315 | |
Brad Stenning | c622f1d | 2019-01-29 11:24:11 -0800 | [diff] [blame] | 316 | // The following are the ui elements that the user would call the status bar. |
| 317 | // This will set the status bar so it they can make call backs. |
| 318 | CarNavigationBarView topBar = mStatusBarWindow.findViewById(R.id.car_top_bar); |
| 319 | topBar.setStatusBar(this); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 320 | topBar.setStatusBarWindowTouchListener((v1, event1) -> |
| 321 | openGestureDetector.onTouchEvent(event1)); |
| 322 | |
| 323 | NotificationClickHandlerFactory clickHandlerFactory = new NotificationClickHandlerFactory( |
| 324 | mBarService, |
| 325 | launchResult -> { |
| 326 | if (launchResult == ActivityManager.START_TASK_TO_FRONT |
| 327 | || launchResult == ActivityManager.START_SUCCESS) { |
| 328 | animateCollapsePanels(); |
| 329 | } |
| 330 | }); |
| 331 | CarNotificationListener carNotificationListener = new CarNotificationListener(); |
| 332 | CarUxRestrictionManagerWrapper carUxRestrictionManagerWrapper = |
| 333 | new CarUxRestrictionManagerWrapper(); |
| 334 | carNotificationListener.registerAsSystemService(mContext, carUxRestrictionManagerWrapper, |
| 335 | clickHandlerFactory); |
| 336 | |
| 337 | mNotificationView = mStatusBarWindow.findViewById(R.id.notification_view); |
| 338 | View glassPane = mStatusBarWindow.findViewById(R.id.glass_pane); |
| 339 | mNotificationView.setClickHandlerFactory(clickHandlerFactory); |
| 340 | |
| 341 | // The glass pane is used to view touch events before passed to the notification list. |
| 342 | // This allows us to initialize gesture listeners and detect when to close the notifications |
| 343 | glassPane.setOnTouchListener((v, event) -> { |
| 344 | if (event.getActionMasked() == MotionEvent.ACTION_UP) { |
| 345 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 346 | } |
| 347 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
| 348 | mNotificationListAtBottomAtTimeOfTouch = mNotificationListAtBottom; |
| 349 | // Pass the down event to gesture detector so that it knows where the touch event |
| 350 | // started. |
| 351 | closeGestureDetector.onTouchEvent(event); |
| 352 | } |
| 353 | return false; |
| 354 | }); |
| 355 | mNotificationList = mNotificationView.findViewById(R.id.notifications); |
| 356 | mNotificationList.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| 357 | @Override |
| 358 | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { |
| 359 | super.onScrolled(recyclerView, dx, dy); |
| 360 | if (!mNotificationList.canScrollVertically(1)) { |
| 361 | mNotificationListAtBottom = true; |
| 362 | return; |
| 363 | } |
| 364 | mNotificationListAtBottom = false; |
| 365 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 366 | } |
| 367 | }); |
| 368 | mNotificationList.setOnTouchListener(new View.OnTouchListener() { |
| 369 | @Override |
| 370 | public boolean onTouch(View v, MotionEvent event) { |
| 371 | boolean handled = false; |
| 372 | if (mNotificationListAtBottomAtTimeOfTouch && mNotificationListAtBottom) { |
| 373 | handled = closeGestureDetector.onTouchEvent(event); |
| 374 | } |
| 375 | // Updating the mNotificationListAtBottomAtTimeOfTouch state has to be done after |
| 376 | // the event has been passed to the closeGestureDetector above, such that the |
| 377 | // closeGestureDetector sees the up event before the state has changed. |
| 378 | if (event.getActionMasked() == MotionEvent.ACTION_UP) { |
| 379 | mNotificationListAtBottomAtTimeOfTouch = false; |
| 380 | } |
| 381 | return handled; |
| 382 | } |
| 383 | }); |
| 384 | |
| 385 | NotificationViewController mNotificationViewController = new NotificationViewController( |
| 386 | mNotificationView, |
| 387 | PreprocessingManager.getInstance(mContext), |
| 388 | carNotificationListener, |
| 389 | carUxRestrictionManagerWrapper); |
| 390 | mNotificationViewController.enable(); |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 393 | @Override |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 394 | public void animateExpandNotificationsPanel() { |
| 395 | if (!mCommandQueue.panelsEnabled() || !mUserSetup) { |
| 396 | return; |
| 397 | } |
| 398 | // scroll to top |
| 399 | mNotificationList.scrollToPosition(0); |
| 400 | mStatusBarWindowController.setPanelVisible(true); |
| 401 | mNotificationView.setVisibility(View.VISIBLE); |
| 402 | // let the status bar know that the panel is open |
| 403 | setPanelExpanded(true); |
| 404 | } |
| 405 | |
| 406 | @Override |
| 407 | public void animateCollapsePanels(int flags, boolean force, boolean delayed, |
| 408 | float speedUpFactor) { |
| 409 | super.animateCollapsePanels(flags, force, delayed, speedUpFactor); |
| 410 | if (!mPanelExpanded || mNotificationView.getVisibility() == View.INVISIBLE) { |
| 411 | return; |
| 412 | } |
| 413 | mStatusBarWindowController.setStatusBarFocusable(false); |
| 414 | mStatusBarWindow.cancelExpandHelper(); |
| 415 | mStatusBarView.collapsePanel(true /* animate */, delayed, speedUpFactor); |
| 416 | mStatusBarWindowController.setPanelVisible(false); |
| 417 | mNotificationView.setVisibility(View.INVISIBLE); |
| 418 | // let the status bar know that the panel is cloased |
| 419 | setPanelExpanded(false); |
| 420 | } |
| 421 | |
| 422 | |
| 423 | @Override |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 424 | protected QS createDefaultQSFragment() { |
| 425 | return new CarQSFragment(); |
| 426 | } |
| 427 | |
Rakesh Iyer | 545e47d | 2017-01-23 18:10:21 -0800 | [diff] [blame] | 428 | private BatteryController createBatteryController() { |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 429 | mCarBatteryController = new CarBatteryController(mContext); |
| 430 | mCarBatteryController.addBatteryViewHandler(this); |
| 431 | return mCarBatteryController; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 434 | @Override |
Jason Monk | 49fa016 | 2017-01-11 09:21:56 -0500 | [diff] [blame] | 435 | protected void createNavigationBar() { |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 436 | mShowBottom = mContext.getResources().getBoolean(R.bool.config_enableBottomNavigationBar); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 437 | mShowLeft = mContext.getResources().getBoolean(R.bool.config_enableLeftNavigationBar); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 438 | mShowRight = mContext.getResources().getBoolean(R.bool.config_enableRightNavigationBar); |
| 439 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 440 | buildNavBarWindows(); |
| 441 | buildNavBarContent(); |
| 442 | attachNavBarWindows(); |
Andrii Kulian | 3ddd7de | 2018-10-10 00:33:19 -0700 | [diff] [blame] | 443 | |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 444 | // There has been a car customized nav bar on the default display, so just create nav bars |
| 445 | // on external displays. |
| 446 | mNavigationBarController.createNavigationBars(false /* includeDefaultDisplay */); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | private void buildNavBarContent() { |
| 450 | if (mShowBottom) { |
| 451 | buildBottomBar((mDeviceIsProvisioned) ? R.layout.car_navigation_bar : |
| 452 | R.layout.car_navigation_bar_unprovisioned); |
| 453 | } |
| 454 | |
| 455 | if (mShowLeft) { |
| 456 | buildLeft((mDeviceIsProvisioned) ? R.layout.car_left_navigation_bar : |
| 457 | R.layout.car_left_navigation_bar_unprovisioned); |
| 458 | } |
| 459 | |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 460 | if (mShowRight) { |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 461 | buildRight((mDeviceIsProvisioned) ? R.layout.car_right_navigation_bar : |
| 462 | R.layout.car_right_navigation_bar_unprovisioned); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | private void buildNavBarWindows() { |
| 467 | if (mShowBottom) { |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 468 | mNavigationBarWindow = (ViewGroup) View.inflate(mContext, |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 469 | R.layout.navigation_bar_window, null); |
| 470 | } |
| 471 | if (mShowLeft) { |
| 472 | mLeftNavigationBarWindow = (ViewGroup) View.inflate(mContext, |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 473 | R.layout.navigation_bar_window, null); |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 474 | } |
| 475 | if (mShowRight) { |
| 476 | mRightNavigationBarWindow = (ViewGroup) View.inflate(mContext, |
| 477 | R.layout.navigation_bar_window, null); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | } |
| 481 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 482 | private void attachNavBarWindows() { |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 483 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 484 | if (mShowBottom) { |
| 485 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 486 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, |
| 487 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, |
| 488 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 489 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 490 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 491 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
| 492 | PixelFormat.TRANSLUCENT); |
| 493 | lp.setTitle("CarNavigationBar"); |
| 494 | lp.windowAnimations = 0; |
| 495 | mWindowManager.addView(mNavigationBarWindow, lp); |
| 496 | } |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 497 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 498 | if (mShowLeft) { |
| 499 | int width = mContext.getResources().getDimensionPixelSize( |
| 500 | R.dimen.car_left_navigation_bar_width); |
| 501 | WindowManager.LayoutParams leftlp = new WindowManager.LayoutParams( |
| 502 | width, LayoutParams.MATCH_PARENT, |
| 503 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, |
| 504 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 505 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 506 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 507 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
| 508 | PixelFormat.TRANSLUCENT); |
| 509 | leftlp.setTitle("LeftCarNavigationBar"); |
| 510 | leftlp.windowAnimations = 0; |
| 511 | leftlp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR; |
| 512 | leftlp.gravity = Gravity.LEFT; |
| 513 | mWindowManager.addView(mLeftNavigationBarWindow, leftlp); |
| 514 | } |
| 515 | if (mShowRight) { |
| 516 | int width = mContext.getResources().getDimensionPixelSize( |
| 517 | R.dimen.car_right_navigation_bar_width); |
| 518 | WindowManager.LayoutParams rightlp = new WindowManager.LayoutParams( |
| 519 | width, LayoutParams.MATCH_PARENT, |
| 520 | WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, |
| 521 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 522 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 523 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 524 | | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, |
| 525 | PixelFormat.TRANSLUCENT); |
| 526 | rightlp.setTitle("RightCarNavigationBar"); |
| 527 | rightlp.windowAnimations = 0; |
| 528 | rightlp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR; |
| 529 | rightlp.gravity = Gravity.RIGHT; |
| 530 | mWindowManager.addView(mRightNavigationBarWindow, rightlp); |
| 531 | } |
| 532 | |
| 533 | } |
| 534 | |
| 535 | private void buildBottomBar(int layout) { |
Anthony Chen | 0801a5c | 2017-03-22 09:54:37 -0700 | [diff] [blame] | 536 | // SystemUI requires that the navigation bar view have a parent. Since the regular |
| 537 | // StatusBar inflates navigation_bar_window as this parent view, use the same view for the |
| 538 | // CarNavigationBarView. |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 539 | View.inflate(mContext, layout, mNavigationBarWindow); |
Scott Randolph | f408582 | 2017-06-27 15:23:01 -0700 | [diff] [blame] | 540 | mNavigationBarView = (CarNavigationBarView) mNavigationBarWindow.getChildAt(0); |
| 541 | if (mNavigationBarView == null) { |
| 542 | Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_navigation_bar"); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 543 | throw new RuntimeException("Unable to build botom nav bar due to missing layout"); |
Scott Randolph | f408582 | 2017-06-27 15:23:01 -0700 | [diff] [blame] | 544 | } |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 545 | mNavigationBarView.setStatusBar(this); |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 546 | addTemperatureViewToController(mNavigationBarView); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 547 | mNavigationBarView.setStatusBarWindowTouchListener(mNavBarNotificationTouchListener); |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 550 | private void buildLeft(int layout) { |
| 551 | View.inflate(mContext, layout, mLeftNavigationBarWindow); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 552 | mLeftNavigationBarView = (CarNavigationBarView) mLeftNavigationBarWindow.getChildAt(0); |
| 553 | if (mLeftNavigationBarView == null) { |
| 554 | Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_navigation_bar"); |
| 555 | throw new RuntimeException("Unable to build left nav bar due to missing layout"); |
| 556 | } |
| 557 | mLeftNavigationBarView.setStatusBar(this); |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 558 | addTemperatureViewToController(mLeftNavigationBarView); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 559 | mLeftNavigationBarView.setStatusBarWindowTouchListener(mNavBarNotificationTouchListener); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | |
Brad Stenning | 224b5b3 | 2018-03-28 21:26:57 -0700 | [diff] [blame] | 563 | private void buildRight(int layout) { |
| 564 | View.inflate(mContext, layout, mRightNavigationBarWindow); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 565 | mRightNavigationBarView = (CarNavigationBarView) mRightNavigationBarWindow.getChildAt(0); |
| 566 | if (mRightNavigationBarView == null) { |
| 567 | Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_navigation_bar"); |
| 568 | throw new RuntimeException("Unable to build right nav bar due to missing layout"); |
| 569 | } |
Brad Stenning | f084d88 | 2018-08-08 13:34:21 -0700 | [diff] [blame] | 570 | mRightNavigationBarView.setStatusBar(this); |
| 571 | addTemperatureViewToController(mRightNavigationBarView); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 572 | mRightNavigationBarView.setStatusBarWindowTouchListener(mNavBarNotificationTouchListener); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 575 | @Override |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 576 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 577 | //When executing dump() funciton simultaneously, we need to serialize them |
| 578 | //to get mStackScroller's position correctly. |
| 579 | synchronized (mQueueLock) { |
| 580 | pw.println(" mStackScroller: " + viewInfo(mStackScroller)); |
| 581 | pw.println(" mStackScroller: " + viewInfo(mStackScroller) |
| 582 | + " scroll " + mStackScroller.getScrollX() |
| 583 | + "," + mStackScroller.getScrollY()); |
| 584 | } |
| 585 | |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 586 | pw.print(" mTaskStackListener="); |
| 587 | pw.println(mTaskStackListener); |
Brad Stenning | 078235b | 2017-12-18 08:25:10 -0800 | [diff] [blame] | 588 | pw.print(" mCarFacetButtonController="); |
| 589 | pw.println(mCarFacetButtonController); |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 590 | pw.print(" mFullscreenUserSwitcher="); |
| 591 | pw.println(mFullscreenUserSwitcher); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 592 | pw.print(" mCarBatteryController="); |
| 593 | pw.println(mCarBatteryController); |
| 594 | pw.print(" mBatteryMeterView="); |
| 595 | pw.println(mBatteryMeterView); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 596 | pw.print(" mNavigationBarView="); |
| 597 | pw.println(mNavigationBarView); |
| 598 | |
| 599 | if (KeyguardUpdateMonitor.getInstance(mContext) != null) { |
| 600 | KeyguardUpdateMonitor.getInstance(mContext).dump(fd, pw, args); |
| 601 | } |
| 602 | |
| 603 | FalsingManager.getInstance(mContext).dump(pw); |
| 604 | FalsingLog.dump(pw); |
| 605 | |
| 606 | pw.println("SharedPreferences:"); |
| 607 | for (Map.Entry<String, ?> entry : Prefs.getAll(mContext).entrySet()) { |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 608 | pw.print(" "); |
| 609 | pw.print(entry.getKey()); |
| 610 | pw.print("="); |
| 611 | pw.println(entry.getValue()); |
Qiming Shi | b9dfb92 | 2017-04-13 16:23:18 +0800 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 615 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 616 | @Override |
Anthony Chen | da62fdcd5 | 2016-04-06 16:15:14 -0700 | [diff] [blame] | 617 | public void showBatteryView() { |
| 618 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 619 | Log.d(TAG, "showBatteryView(). mBatteryMeterView: " + mBatteryMeterView); |
| 620 | } |
| 621 | |
| 622 | if (mBatteryMeterView != null) { |
| 623 | mBatteryMeterView.setVisibility(View.VISIBLE); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | @Override |
| 628 | public void hideBatteryView() { |
| 629 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 630 | Log.d(TAG, "hideBatteryView(). mBatteryMeterView: " + mBatteryMeterView); |
| 631 | } |
| 632 | |
| 633 | if (mBatteryMeterView != null) { |
| 634 | mBatteryMeterView.setVisibility(View.GONE); |
| 635 | } |
| 636 | } |
| 637 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 638 | /** |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 639 | * An implementation of TaskStackChangeListener, that listens for changes in the system |
davidln | 5473915 | 2018-07-02 13:25:44 -0700 | [diff] [blame] | 640 | * task stack and notifies the navigation bar. |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 641 | */ |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 642 | private class TaskStackListenerImpl extends TaskStackChangeListener { |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 643 | @Override |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 644 | public void onTaskStackChanged() { |
Brad Stenning | a5e714c | 2018-04-12 19:23:39 -0700 | [diff] [blame] | 645 | try { |
| 646 | mCarFacetButtonController.taskChanged( |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 647 | ActivityTaskManager.getService().getAllStackInfos()); |
Brad Stenning | a5e714c | 2018-04-12 19:23:39 -0700 | [diff] [blame] | 648 | } catch (Exception e) { |
| 649 | Log.e(TAG, "Getting StackInfo from activity manager failed", e); |
| 650 | } |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 651 | } |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 652 | } |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 653 | |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 654 | private void onDrivingStateChanged(CarDrivingStateEvent notUsed) { |
| 655 | // Check if we need to start the timer every time driving state changes. |
| 656 | startSwitchToGuestTimerIfDrivingOnKeyguard(); |
| 657 | } |
| 658 | |
| 659 | private void startSwitchToGuestTimerIfDrivingOnKeyguard() { |
| 660 | if (mDrivingStateHelper.isCurrentlyDriving() && mState != StatusBarState.SHADE) { |
| 661 | // We're driving while keyguard is up. |
| 662 | mSwitchToGuestTimer.start(); |
| 663 | } else { |
| 664 | mSwitchToGuestTimer.cancel(); |
| 665 | } |
| 666 | } |
| 667 | |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 668 | @Override |
| 669 | protected void createUserSwitcher() { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 670 | UserSwitcherController userSwitcherController = |
| 671 | Dependency.get(UserSwitcherController.class); |
| 672 | if (userSwitcherController.useFullscreenUserSwitcher()) { |
| 673 | mFullscreenUserSwitcher = new FullscreenUserSwitcher(this, |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 674 | mStatusBarWindow.findViewById(R.id.fullscreen_user_switcher_stub), mContext); |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 675 | } else { |
| 676 | super.createUserSwitcher(); |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | @Override |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 681 | public void setLockscreenUser(int newUserId) { |
| 682 | super.setLockscreenUser(newUserId); |
| 683 | // Try to dismiss the keyguard after every user switch. |
| 684 | dismissKeyguardWhenUserSwitcherNotDisplayed(); |
| 685 | } |
| 686 | |
| 687 | @Override |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 688 | public void onStateChanged(int newState) { |
| 689 | super.onStateChanged(newState); |
jovanak | edba98c | 2018-09-14 15:46:24 -0700 | [diff] [blame] | 690 | |
| 691 | startSwitchToGuestTimerIfDrivingOnKeyguard(); |
| 692 | |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 693 | if (newState != StatusBarState.FULLSCREEN_USER_SWITCHER) { |
| 694 | hideUserSwitcher(); |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 695 | } else { |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 696 | dismissKeyguardWhenUserSwitcherNotDisplayed(); |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | /** Makes the full screen user switcher visible, if applicable. */ |
| 701 | public void showUserSwitcher() { |
| 702 | if (mFullscreenUserSwitcher != null && mState == StatusBarState.FULLSCREEN_USER_SWITCHER) { |
| 703 | mFullscreenUserSwitcher.show(); // Makes the switcher visible. |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | private void hideUserSwitcher() { |
| 708 | if (mFullscreenUserSwitcher != null) { |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 709 | mFullscreenUserSwitcher.hide(); |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
jovanak | 168dbdb | 2019-02-18 01:00:43 -0800 | [diff] [blame] | 713 | // We automatically dismiss keyguard unless user switcher is being shown on the keyguard. |
| 714 | private void dismissKeyguardWhenUserSwitcherNotDisplayed() { |
| 715 | if (mFullscreenUserSwitcher == null) { |
| 716 | return; // Not using the full screen user switcher. |
| 717 | } |
| 718 | |
| 719 | if (mState == StatusBarState.FULLSCREEN_USER_SWITCHER |
| 720 | && !mFullscreenUserSwitcher.isVisible()) { |
| 721 | // Current execution path continues to set state after this, thus we deffer the |
| 722 | // dismissal to the next execution cycle. |
| 723 | postDismissKeyguard(); // Dismiss the keyguard if switcher is not visible. |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 724 | } |
| 725 | } |
Rakesh Iyer | 74ebabe | 2016-03-11 10:10:43 -0800 | [diff] [blame] | 726 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 727 | public void postDismissKeyguard() { |
| 728 | mHandler.post(this::dismissKeyguard); |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Dismisses the keyguard and shows bouncer if authentication is necessary. |
| 733 | */ |
| 734 | public void dismissKeyguard() { |
| 735 | executeRunnableDismissingKeyguard(null/* runnable */, null /* cancelAction */, |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 736 | true /* dismissShade */, true /* afterKeyguardGone */, true /* deferred */); |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 739 | /** |
| 740 | * Ensures that relevant child views are appropriately recreated when the device's density |
| 741 | * changes. |
| 742 | */ |
| 743 | @Override |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 744 | public void onDensityOrFontScaleChanged() { |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 745 | super.onDensityOrFontScaleChanged(); |
Guobin Zhang | eef0e0c | 2019-02-01 11:54:24 -0800 | [diff] [blame] | 746 | restartNavBars(); |
Anthony Chen | e658cc2 | 2017-04-27 11:17:35 -0700 | [diff] [blame] | 747 | // Need to update the background on density changed in case the change was due to night |
| 748 | // mode. |
| 749 | mNotificationPanelBackground = getDefaultWallpaper(); |
| 750 | mScrimController.setScrimBehindDrawable(mNotificationPanelBackground); |
| 751 | } |
| 752 | |
| 753 | /** |
| 754 | * Returns the {@link Drawable} that represents the wallpaper that the user has currently set. |
| 755 | */ |
| 756 | private Drawable getDefaultWallpaper() { |
| 757 | return mContext.getDrawable(com.android.internal.R.drawable.default_wallpaper); |
Anthony Chen | 3cb3ad9 | 2016-12-01 10:58:47 -0800 | [diff] [blame] | 758 | } |
Brad Stenning | 19f236a | 2018-12-11 14:12:30 -0800 | [diff] [blame] | 759 | |
Priyank Singh | 63e6860 | 2019-03-04 11:57:34 -0800 | [diff] [blame] | 760 | /** Returns true if the current user makes it through the setup wizard, false otherwise. */ |
| 761 | public boolean getIsUserSetup(){ |
| 762 | return mUserSetup; |
| 763 | } |
| 764 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 765 | |
| 766 | // TODO: add settle down/up logic |
| 767 | private static final int SWIPE_UP_MIN_DISTANCE = 75; |
| 768 | private static final int SWIPE_DOWN_MIN_DISTANCE = 25; |
| 769 | private static final int SWIPE_MAX_OFF_PATH = 75; |
| 770 | private static final int SWIPE_THRESHOLD_VELOCITY = 200; |
| 771 | // Only responsible for open hooks. Since once the panel opens it covers all elements |
| 772 | // there is no need to merge with close. |
| 773 | private abstract class OpenNotificationGestureListener extends |
| 774 | GestureDetector.SimpleOnGestureListener { |
| 775 | |
| 776 | @Override |
| 777 | public boolean onFling(MotionEvent event1, MotionEvent event2, |
| 778 | float velocityX, float velocityY) { |
| 779 | if (Math.abs(event1.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH |
| 780 | || Math.abs(velocityY) < SWIPE_THRESHOLD_VELOCITY) { |
| 781 | // swipe was not vertical or was not fast enough |
| 782 | return false; |
| 783 | } |
| 784 | boolean isDown = velocityY > 0; |
| 785 | float distanceDelta = Math.abs(event1.getY() - event2.getY()); |
| 786 | if (isDown && distanceDelta > SWIPE_DOWN_MIN_DISTANCE) { |
| 787 | openNotification(); |
| 788 | return true; |
| 789 | } |
| 790 | |
| 791 | return false; |
| 792 | } |
| 793 | protected abstract void openNotification(); |
Brad Stenning | 19f236a | 2018-12-11 14:12:30 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 796 | // to be installed on the open panel notification panel |
| 797 | private abstract class CloseNotificationGestureListener extends |
| 798 | GestureDetector.SimpleOnGestureListener { |
| 799 | |
| 800 | @Override |
| 801 | public boolean onFling(MotionEvent event1, MotionEvent event2, |
| 802 | float velocityX, float velocityY) { |
| 803 | if (Math.abs(event1.getX() - event2.getX()) > SWIPE_MAX_OFF_PATH |
| 804 | || Math.abs(velocityY) < SWIPE_THRESHOLD_VELOCITY) { |
| 805 | // swipe was not vertical or was not fast enough |
| 806 | return false; |
| 807 | } |
| 808 | boolean isUp = velocityY < 0; |
| 809 | float distanceDelta = Math.abs(event1.getY() - event2.getY()); |
| 810 | if (isUp && distanceDelta > SWIPE_UP_MIN_DISTANCE) { |
| 811 | close(); |
| 812 | return true; |
| 813 | } |
| 814 | return false; |
| 815 | } |
| 816 | protected abstract void close(); |
| 817 | } |
| 818 | |
| 819 | // to be installed on the nav bars |
| 820 | private abstract class NavBarCloseNotificationGestureListener extends |
| 821 | CloseNotificationGestureListener { |
| 822 | @Override |
| 823 | public boolean onSingleTapUp(MotionEvent e) { |
| 824 | close(); |
| 825 | return super.onSingleTapUp(e); |
| 826 | } |
| 827 | |
| 828 | @Override |
| 829 | public void onLongPress(MotionEvent e) { |
| 830 | close(); |
| 831 | super.onLongPress(e); |
| 832 | } |
Adora Zhang | 0237b9c | 2019-03-08 12:27:09 -0800 | [diff] [blame] | 833 | } |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 834 | } |