blob: 93168db861be3136357de9d5ecc60ca491729642 [file] [log] [blame]
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001/*
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
17package com.android.systemui.statusbar.phone;
18
Jason Monk297c04e2018-08-23 17:16:59 -040019import static com.android.systemui.plugins.ActivityStarter.OnDismissAction;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020020import static com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_WAKE_AND_UNLOCK;
21import static com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_WAKE_AND_UNLOCK_PULSING;
Jorim Jaggif5304ad2017-07-17 18:31:13 +020022
Jorim Jaggi786afcb2014-09-25 02:41:29 +020023import android.content.ComponentCallbacks2;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010024import android.content.Context;
Jason Chang1e4a4bd2018-05-22 17:30:19 +080025import android.content.res.ColorStateList;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010026import android.os.Bundle;
Jorim Jaggie29b2db2014-05-30 23:17:03 +020027import android.os.SystemClock;
Tej Singhdd7bd352018-02-09 19:33:15 -080028import android.util.StatsLog;
Jorim Jaggidf993512014-05-13 23:06:35 +020029import android.view.KeyEvent;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010030import android.view.View;
31import android.view.ViewGroup;
Jorim Jaggib774e552015-08-24 14:52:45 -070032import android.view.ViewRootImpl;
Jorim Jaggi786afcb2014-09-25 02:41:29 +020033import android.view.WindowManagerGlobal;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010034
Lucas Dupinbc9aac12018-03-04 20:18:15 -080035import com.android.internal.util.LatencyTracker;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010036import com.android.internal.widget.LockPatternUtils;
Adrian Roosb6011622014-05-14 15:52:53 +020037import com.android.keyguard.KeyguardUpdateMonitor;
Jorim Jaggia9d7fcd2017-05-18 01:08:12 +020038import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010039import com.android.keyguard.ViewMediatorCallback;
Lucas Dupin2e838ac2019-04-17 16:50:58 -070040import com.android.settingslib.animation.AppearAnimationUtils;
Jorim Jaggi8adb30c2016-09-13 15:02:22 -070041import com.android.systemui.DejankUtils;
Jason Monk421a9412017-02-06 09:15:21 -080042import com.android.systemui.Dependency;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080043import com.android.systemui.SystemUIFactory;
Lucas Dupinafffbf92019-04-09 19:52:26 -070044import com.android.systemui.dock.DockManager;
Jorim Jaggi241ae102016-11-02 21:57:33 -070045import com.android.systemui.keyguard.DismissCallbackRegistry;
Beverly8fdb5332019-02-04 14:29:49 -050046import com.android.systemui.plugins.statusbar.StatusBarStateController;
Lucas Dupinafffbf92019-04-09 19:52:26 -070047import com.android.systemui.shared.system.QuickStepContract;
Jim Miller25d7e512015-03-03 17:12:09 -080048import com.android.systemui.statusbar.CommandQueue;
Lucas Dupin269feda2019-04-29 17:11:02 -070049import com.android.systemui.statusbar.CrossFadeHelper;
Jason Monk297c04e2018-08-23 17:16:59 -040050import com.android.systemui.statusbar.NotificationMediaManager;
Adrian Roosd28ccd72016-01-06 15:23:14 +010051import com.android.systemui.statusbar.RemoteInputController;
Lucas Dupin2e838ac2019-04-17 16:50:58 -070052import com.android.systemui.statusbar.StatusBarState;
Beverly8fdb5332019-02-04 14:29:49 -050053import com.android.systemui.statusbar.SysuiStatusBarStateController;
Lucas Dupin15a6b6c2018-04-16 14:50:20 +080054import com.android.systemui.statusbar.phone.KeyguardBouncer.BouncerExpansionCallback;
Lucas Dupinafffbf92019-04-09 19:52:26 -070055import com.android.systemui.statusbar.policy.ConfigurationController;
Jason Monk1fd3fc32018-08-14 17:20:09 -040056import com.android.systemui.statusbar.policy.KeyguardMonitor;
Evan Laird2d620fa2018-10-30 13:03:31 -040057import com.android.systemui.statusbar.policy.KeyguardMonitorImpl;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010058
Lucas Dupin15a6b6c2018-04-16 14:50:20 +080059import java.io.PrintWriter;
Jorim Jaggibcbe9482016-11-23 17:37:49 +010060import java.util.ArrayList;
61
Jorim Jaggi5cf17872014-03-26 18:31:48 +010062/**
63 * Manages creating, showing, hiding and resetting the keyguard within the status bar. Calls back
64 * via {@link ViewMediatorCallback} to poke the wake lock and report that the keyguard is done,
65 * which is in turn, reported to this class by the current
66 * {@link com.android.keyguard.KeyguardViewBase}.
67 */
Evan Laird878c8532018-10-15 15:54:29 -040068public class StatusBarKeyguardViewManager implements RemoteInputController.Callback,
Lucas Dupin2e838ac2019-04-17 16:50:58 -070069 StatusBarStateController.StateListener, ConfigurationController.ConfigurationListener,
Winson Chung1aa24b92019-04-24 15:17:33 -070070 NotificationPanelView.PanelExpansionListener, NavigationModeController.ModeChangedListener {
Jorim Jaggi76a16232014-08-08 17:00:47 +020071
72 // When hiding the Keyguard with timing supplied from WindowManager, better be early than late.
Jorim Jaggi56fd70c2016-10-27 19:57:08 -070073 private static final long HIDE_TIMING_CORRECTION_MS = - 16 * 3;
Jorim Jaggi76a16232014-08-08 17:00:47 +020074
Jorim Jaggi416493b2014-09-13 03:57:32 +020075 // Delay for showing the navigation bar when the bouncer appears. This should be kept in sync
76 // with the appear animations of the PIN/pattern/password views.
77 private static final long NAV_BAR_SHOW_DELAY_BOUNCER = 320;
78
Jorim Jaggi007f0e82015-08-14 13:56:01 -070079 private static final long WAKE_AND_UNLOCK_SCRIM_FADEOUT_DURATION_MS = 200;
80
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070081 // Duration of the Keyguard dismissal animation in case the user is currently locked. This is to
82 // make everything a bit slower to bridge a gap until the user is unlocked and home screen has
83 // dranw its first frame.
84 private static final long KEYGUARD_DISMISS_DURATION_LOCKED = 2000;
85
Jorim Jaggi5cf17872014-03-26 18:31:48 +010086 private static String TAG = "StatusBarKeyguardViewManager";
87
Xiyuan Xia1b30f792016-01-06 08:50:30 -080088 protected final Context mContext;
Lucas Dupin1a8588d2018-08-21 12:18:47 -070089 private final StatusBarWindowController mStatusBarWindowController;
Lucas Dupin15a6b6c2018-04-16 14:50:20 +080090 private final BouncerExpansionCallback mExpansionCallback = new BouncerExpansionCallback() {
91 @Override
92 public void onFullyShown() {
93 updateStates();
Lucas Dupin3cfd6882019-03-19 15:22:03 -070094 mStatusBar.wakeUpIfDozing(SystemClock.uptimeMillis(), mContainer, "BOUNCER_VISIBLE");
Lucas Dupin2e838ac2019-04-17 16:50:58 -070095 updateLockIcon();
Lucas Dupin15a6b6c2018-04-16 14:50:20 +080096 }
97
98 @Override
Lucas Dupin84993542018-10-11 19:23:45 -070099 public void onStartingToHide() {
100 updateStates();
101 }
102
103 @Override
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700104 public void onStartingToShow() {
105 updateLockIcon();
Lucas Dupin15a6b6c2018-04-16 14:50:20 +0800106 }
Lucas Dupin27321c42019-03-20 16:22:24 -0700107
108 @Override
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700109 public void onFullyHidden() {
110 updateStates();
111 updateLockIcon();
Lucas Dupin27321c42019-03-20 16:22:24 -0700112 }
Lucas Dupin15a6b6c2018-04-16 14:50:20 +0800113 };
Lucas Dupinafffbf92019-04-09 19:52:26 -0700114 private final DockManager.DockEventListener mDockEventListener =
115 new DockManager.DockEventListener() {
116 @Override
117 public void onEvent(int event) {
118 boolean isDocked = mDockManager.isDocked();
119 if (isDocked == mIsDocked) {
120 return;
121 }
122 mIsDocked = isDocked;
123 updateStates();
124 }
125 };
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100126
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800127 protected LockPatternUtils mLockPatternUtils;
128 protected ViewMediatorCallback mViewMediatorCallback;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500129 protected StatusBar mStatusBar;
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800130 private NotificationPanelView mNotificationPanelView;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200131 private BiometricUnlockController mBiometricUnlockController;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100132
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100133 private ViewGroup mContainer;
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700134 private ViewGroup mLockIconContainer;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100135
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800136 protected KeyguardBouncer mBouncer;
137 protected boolean mShowing;
138 protected boolean mOccluded;
139 protected boolean mRemoteInputActive;
Adrian Roos087826a2017-04-19 16:59:09 -0700140 private boolean mDozing;
Lucas Dupinafffbf92019-04-09 19:52:26 -0700141 private boolean mPulsing;
142 private boolean mGesturalNav;
143 private boolean mIsDocked;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100144
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800145 protected boolean mFirstUpdate = true;
146 protected boolean mLastShowing;
147 protected boolean mLastOccluded;
Adrian Roosb6011622014-05-14 15:52:53 +0200148 private boolean mLastBouncerShowing;
149 private boolean mLastBouncerDismissible;
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800150 protected boolean mLastRemoteInputActive;
Adrian Roos087826a2017-04-19 16:59:09 -0700151 private boolean mLastDozing;
Lucas Dupinafffbf92019-04-09 19:52:26 -0700152 private boolean mLastGesturalNav;
153 private boolean mLastIsDocked;
154 private boolean mLastPulsing;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200155 private int mLastBiometricMode;
Lucas Dupin16cfe452018-02-08 13:14:50 -0800156 private boolean mGoingToSleepVisibleNotOccluded;
Lucas Dupin269feda2019-04-29 17:11:02 -0700157 private boolean mLastLockVisible;
Adrian Roosd28ccd72016-01-06 15:23:14 +0100158
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200159 private OnDismissAction mAfterKeyguardGoneAction;
Jorim Jaggibcbe9482016-11-23 17:37:49 +0100160 private final ArrayList<Runnable> mAfterKeyguardGoneRunnables = new ArrayList<>();
Adrian Roosb6011622014-05-14 15:52:53 +0200161
Adrian Roosfee661c2017-08-04 17:05:45 +0200162 // Dismiss action to be launched when we stop dozing or the keyguard is gone.
Adrian Roos34e65402017-08-07 19:32:45 +0200163 private DismissWithActionRequest mPendingWakeupAction;
Evan Laird2d620fa2018-10-30 13:03:31 -0400164 private final KeyguardMonitorImpl mKeyguardMonitor =
165 (KeyguardMonitorImpl) Dependency.get(KeyguardMonitor.class);
Jason Monk297c04e2018-08-23 17:16:59 -0400166 private final NotificationMediaManager mMediaManager =
167 Dependency.get(NotificationMediaManager.class);
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700168 private final StatusBarStateController mStatusBarStateController =
169 Dependency.get(StatusBarStateController.class);
Lucas Dupinafffbf92019-04-09 19:52:26 -0700170 private final DockManager mDockManager;
Adrian Roosfee661c2017-08-04 17:05:45 +0200171
Jorim Jaggia9d7fcd2017-05-18 01:08:12 +0200172 private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback =
173 new KeyguardUpdateMonitorCallback() {
174 @Override
175 public void onEmergencyCallAction() {
176
177 // Since we won't get a setOccluded call we have to reset the view manually such that
178 // the bouncer goes away.
179 if (mOccluded) {
Lucas Dupin28f90292017-08-08 18:07:49 -0400180 reset(true /* hideBouncerWhenShowing */);
Jorim Jaggia9d7fcd2017-05-18 01:08:12 +0200181 }
182 }
183 };
184
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100185 public StatusBarKeyguardViewManager(Context context, ViewMediatorCallback callback,
186 LockPatternUtils lockPatternUtils) {
187 mContext = context;
188 mViewMediatorCallback = callback;
189 mLockPatternUtils = lockPatternUtils;
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700190 mStatusBarWindowController = Dependency.get(StatusBarWindowController.class);
Jorim Jaggia9d7fcd2017-05-18 01:08:12 +0200191 KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateMonitorCallback);
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700192 mStatusBarStateController.addCallback(this);
Lucas Dupinafffbf92019-04-09 19:52:26 -0700193 Dependency.get(ConfigurationController.class).addCallback(this);
Lucas Dupinbe050b22019-05-02 16:38:33 -0700194 mGesturalNav = QuickStepContract.isGesturalMode(
Winson Chung1aa24b92019-04-24 15:17:33 -0700195 Dependency.get(NavigationModeController.class).addListener(this));
Lucas Dupind93e95f2019-05-01 00:49:35 +0000196 mDockManager = Dependency.get(DockManager.class);
Lucas Dupinafffbf92019-04-09 19:52:26 -0700197 if (mDockManager != null) {
198 mDockManager.addListener(mDockEventListener);
199 mIsDocked = mDockManager.isDocked();
200 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100201 }
202
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500203 public void registerStatusBar(StatusBar statusBar,
Jason Monk421a9412017-02-06 09:15:21 -0800204 ViewGroup container,
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800205 NotificationPanelView notificationPanelView,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200206 BiometricUnlockController biometricUnlockController,
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700207 DismissCallbackRegistry dismissCallbackRegistry,
208 ViewGroup lockIconContainer) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500209 mStatusBar = statusBar;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100210 mContainer = container;
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700211 mLockIconContainer = lockIconContainer;
Lucas Dupin269feda2019-04-29 17:11:02 -0700212 if (mLockIconContainer != null) {
213 mLastLockVisible = mLockIconContainer.getVisibility() == View.VISIBLE;
214 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200215 mBiometricUnlockController = biometricUnlockController;
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800216 mBouncer = SystemUIFactory.getInstance().createKeyguardBouncer(mContext,
Lucas Dupin15a6b6c2018-04-16 14:50:20 +0800217 mViewMediatorCallback, mLockPatternUtils, container, dismissCallbackRegistry,
218 mExpansionCallback);
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800219 mNotificationPanelView = notificationPanelView;
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700220 notificationPanelView.setExpansionListener(this);
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800221 }
222
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700223 @Override
224 public void onPanelExpansionChanged(float expansion, boolean tracking) {
Lucas Dupin6f0d71f2018-03-23 17:26:06 -0700225 // We don't want to translate the bounce when:
226 // • Keyguard is occluded, because we're in a FLAG_SHOW_WHEN_LOCKED activity and need to
227 // conserve the original animation.
228 // • The user quickly taps on the display and we show "swipe up to unlock."
229 // • Keyguard will be dismissed by an action. a.k.a: FLAG_DISMISS_KEYGUARD_ACTIVITY
jovanak5f6dc612018-03-27 11:59:22 -0700230 // • Full-screen user switcher is displayed.
Lucas Dupind7344dc2018-04-20 12:08:52 +0800231 if (mNotificationPanelView.isUnlockHintRunning()) {
Lucas Dupinf9ca35e2018-05-16 20:41:35 -0700232 mBouncer.setExpansion(KeyguardBouncer.EXPANSION_HIDDEN);
Lucas Dupinc516bac2018-06-19 10:50:04 -0700233 } else if (bouncerNeedsScrimming()) {
Lucas Dupinf9ca35e2018-05-16 20:41:35 -0700234 mBouncer.setExpansion(KeyguardBouncer.EXPANSION_VISIBLE);
Lucas Dupin1c327432019-01-03 13:37:53 -0800235 } else if (mShowing) {
Lucas Dupinaaac2cb2018-06-08 14:11:41 -0700236 if (!isWakeAndUnlocking() && !mStatusBar.isInLaunchTransition()) {
Lucas Dupin71dd4842018-05-29 15:41:03 -0700237 mBouncer.setExpansion(expansion);
238 }
Lucas Dupinf9ca35e2018-05-16 20:41:35 -0700239 if (expansion != KeyguardBouncer.EXPANSION_HIDDEN && tracking
240 && mStatusBar.isKeyguardCurrentlySecure()
Lucas Dupin52a95872018-04-20 10:28:07 +0800241 && !mBouncer.isShowing() && !mBouncer.isAnimatingAway()) {
Lucas Dupin71dd4842018-05-29 15:41:03 -0700242 mBouncer.show(false /* resetSecuritySelection */, false /* scrimmed */);
Lucas Dupin3d565fa2018-03-20 15:40:14 -0700243 }
Lucas Dupinf6a1f172019-04-18 20:57:40 -0700244 } else if (mPulsing && expansion == KeyguardBouncer.EXPANSION_VISIBLE) {
245 // Panel expanded while pulsing but didn't translate the bouncer (because we are
246 // unlocked.) Let's simply wake-up to dismiss the lock screen.
247 mStatusBar.wakeUpIfDozing(SystemClock.uptimeMillis(), mContainer, "BOUNCER_VISIBLE");
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800248 }
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700249 }
250
251 @Override
252 public void onQsExpansionChanged(float expansion) {
253 updateLockIcon();
254 }
255
256 private void updateLockIcon() {
Brad Stenning691c2742019-04-19 11:48:00 -0700257 // Not all form factors have a lock icon
258 if (mLockIconContainer == null) {
259 return;
260 }
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700261 boolean keyguardWithoutQs = mStatusBarStateController.getState() == StatusBarState.KEYGUARD
262 && !mNotificationPanelView.isQsExpanded();
Lucas Dupin269feda2019-04-29 17:11:02 -0700263 boolean lockVisible = (mBouncer.isShowing() || keyguardWithoutQs)
264 && !mBouncer.isAnimatingAway();
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700265
Lucas Dupin269feda2019-04-29 17:11:02 -0700266 if (mLastLockVisible != lockVisible) {
267 mLastLockVisible = lockVisible;
268 if (lockVisible) {
269 CrossFadeHelper.fadeIn(mLockIconContainer,
270 AppearAnimationUtils.DEFAULT_APPEAR_DURATION /* duration */,
271 0 /* delay */);
272 } else {
273 CrossFadeHelper.fadeOut(mLockIconContainer,
274 AppearAnimationUtils.DEFAULT_APPEAR_DURATION / 2 /* duration */,
275 0 /* delay */, null /* runnable */);
276 }
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700277 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100278 }
279
280 /**
281 * Show the keyguard. Will handle creating and attaching to the view manager
282 * lazily.
283 */
284 public void show(Bundle options) {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200285 mShowing = true;
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700286 mStatusBarWindowController.setKeyguardShowing(true);
Evan Laird2d620fa2018-10-30 13:03:31 -0400287 mKeyguardMonitor.notifyKeyguardState(
288 mShowing, mKeyguardMonitor.isSecure(), mKeyguardMonitor.isOccluded());
Jorim Jaggife762342016-10-13 14:33:27 +0200289 reset(true /* hideBouncerWhenShowing */);
Tej Singhdd7bd352018-02-09 19:33:15 -0800290 StatsLog.write(StatsLog.KEYGUARD_STATE_CHANGED,
291 StatsLog.KEYGUARD_STATE_CHANGED__STATE__SHOWN);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100292 }
293
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200294 /**
295 * Shows the notification keyguard or the bouncer depending on
296 * {@link KeyguardBouncer#needsFullscreenBouncer()}.
297 */
Jorim Jaggife762342016-10-13 14:33:27 +0200298 protected void showBouncerOrKeyguard(boolean hideBouncerWhenShowing) {
Adrian Roos41eecff2017-06-29 14:09:52 +0200299 if (mBouncer.needsFullscreenBouncer() && !mDozing) {
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200300 // The keyguard might be showing (already). So we need to hide it.
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500301 mStatusBar.hideKeyguard();
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100302 mBouncer.show(true /* resetSecuritySelection */);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200303 } else {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500304 mStatusBar.showKeyguard();
Jorim Jaggife762342016-10-13 14:33:27 +0200305 if (hideBouncerWhenShowing) {
Jian Jind1b63982018-05-21 15:20:40 -0700306 hideBouncer(shouldDestroyViewOnReset() /* destroyView */);
Jorim Jaggife762342016-10-13 14:33:27 +0200307 mBouncer.prepare();
308 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200309 }
Adrian Roos61676aa2017-08-03 16:24:32 +0200310 updateStates();
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200311 }
312
Jian Jind1b63982018-05-21 15:20:40 -0700313 protected boolean shouldDestroyViewOnReset() {
314 return false;
315 }
316
Lucas Dupin3c9df5a2018-02-27 11:32:16 -0800317 private void hideBouncer(boolean destroyView) {
Lucas Dupinafffbf92019-04-09 19:52:26 -0700318 if (mBouncer == null) {
319 return;
320 }
Adrian Roosfee661c2017-08-04 17:05:45 +0200321 mBouncer.hide(destroyView);
Adrian Roos34e65402017-08-07 19:32:45 +0200322 cancelPendingWakeupAction();
Adrian Roosfee661c2017-08-04 17:05:45 +0200323 }
324
Lucas Dupinf9ca35e2018-05-16 20:41:35 -0700325 public void showBouncer(boolean scrimmed) {
326 if (mShowing && !mBouncer.isShowing()) {
327 mBouncer.show(false /* resetSecuritySelection */, scrimmed);
Dan Sandler3806c772014-05-08 14:52:10 -0400328 }
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200329 updateStates();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100330 }
331
Jorim Jaggid9449862015-05-29 14:49:08 -0700332 public void dismissWithAction(OnDismissAction r, Runnable cancelAction,
333 boolean afterKeyguardGone) {
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800334 dismissWithAction(r, cancelAction, afterKeyguardGone, null /* message */);
335 }
336
337 public void dismissWithAction(OnDismissAction r, Runnable cancelAction,
338 boolean afterKeyguardGone, String message) {
Adrian Roos0002a452014-07-03 13:46:07 +0200339 if (mShowing) {
Adrian Roos34e65402017-08-07 19:32:45 +0200340 cancelPendingWakeupAction();
Adrian Roosfee661c2017-08-04 17:05:45 +0200341 // If we're dozing, this needs to be delayed until after we wake up - unless we're
342 // wake-and-unlocking, because there dozing will last until the end of the transition.
343 if (mDozing && !isWakeAndUnlocking()) {
Adrian Roos34e65402017-08-07 19:32:45 +0200344 mPendingWakeupAction = new DismissWithActionRequest(
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800345 r, cancelAction, afterKeyguardGone, message);
Adrian Roosfee661c2017-08-04 17:05:45 +0200346 return;
347 }
348
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200349 if (!afterKeyguardGone) {
Jorim Jaggid9449862015-05-29 14:49:08 -0700350 mBouncer.showWithDismissAction(r, cancelAction);
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200351 } else {
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200352 mAfterKeyguardGoneAction = r;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700353 mBouncer.show(false /* resetSecuritySelection */);
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200354 }
Adrian Roos7d7090d2014-05-21 13:10:23 +0200355 }
356 updateStates();
357 }
358
Adrian Roosfee661c2017-08-04 17:05:45 +0200359 private boolean isWakeAndUnlocking() {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200360 int mode = mBiometricUnlockController.getMode();
Adrian Roosfee661c2017-08-04 17:05:45 +0200361 return mode == MODE_WAKE_AND_UNLOCK || mode == MODE_WAKE_AND_UNLOCK_PULSING;
362 }
363
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100364 /**
Jorim Jaggibcbe9482016-11-23 17:37:49 +0100365 * Adds a {@param runnable} to be executed after Keyguard is gone.
366 */
367 public void addAfterKeyguardGoneRunnable(Runnable runnable) {
368 mAfterKeyguardGoneRunnables.add(runnable);
369 }
370
371 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100372 * Reset the state of the view.
373 */
Jorim Jaggife762342016-10-13 14:33:27 +0200374 public void reset(boolean hideBouncerWhenShowing) {
Jorim Jaggi43bdbbd2014-05-09 16:05:53 +0200375 if (mShowing) {
Adrian Roos7a56d1a2017-08-04 15:04:43 +0200376 if (mOccluded && !mDozing) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500377 mStatusBar.hideKeyguard();
Adrian Roos91ffdc42017-08-04 18:14:41 +0200378 if (hideBouncerWhenShowing || mBouncer.needsFullscreenBouncer()) {
379 hideBouncer(false /* destroyView */);
380 }
Jorim Jaggi43bdbbd2014-05-09 16:05:53 +0200381 } else {
Jorim Jaggife762342016-10-13 14:33:27 +0200382 showBouncerOrKeyguard(hideBouncerWhenShowing);
Jorim Jaggi43bdbbd2014-05-09 16:05:53 +0200383 }
Selim Cinek1fcafc42015-07-20 14:39:25 -0700384 KeyguardUpdateMonitor.getInstance(mContext).sendKeyguardReset();
Jorim Jaggi43bdbbd2014-05-09 16:05:53 +0200385 updateStates();
Dan Sandler3806c772014-05-08 14:52:10 -0400386 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100387 }
388
Lucas Dupin16cfe452018-02-08 13:14:50 -0800389 public boolean isGoingToSleepVisibleNotOccluded() {
390 return mGoingToSleepVisibleNotOccluded;
391 }
392
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700393 public void onStartedGoingToSleep() {
Lucas Dupin16cfe452018-02-08 13:14:50 -0800394 mGoingToSleepVisibleNotOccluded = isShowing() && !isOccluded();
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700395 }
396
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700397 public void onFinishedGoingToSleep() {
Lucas Dupin16cfe452018-02-08 13:14:50 -0800398 mGoingToSleepVisibleNotOccluded = false;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200399 mBouncer.onScreenTurnedOff();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100400 }
401
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700402 public void onStartedWakingUp() {
Adrian Roos731d4df2017-07-18 15:10:39 +0200403 // TODO: remove
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100404 }
405
Jorim Jaggi93739112015-08-13 15:53:14 -0700406 public void onScreenTurningOn() {
Adrian Roos731d4df2017-07-18 15:10:39 +0200407 // TODO: remove
Selim Cinek372d1bd2015-08-14 13:19:37 -0700408 }
409
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700410 public void onScreenTurnedOn() {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800411 // TODO: remove
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700412 }
413
Adrian Roosd28ccd72016-01-06 15:23:14 +0100414 @Override
415 public void onRemoteInputActive(boolean active) {
416 mRemoteInputActive = active;
417 updateStates();
418 }
419
Evan Laird878c8532018-10-15 15:54:29 -0400420 private void setDozing(boolean dozing) {
Adrian Roos41eecff2017-06-29 14:09:52 +0200421 if (mDozing != dozing) {
422 mDozing = dozing;
Adrian Roos61676aa2017-08-03 16:24:32 +0200423 if (dozing || mBouncer.needsFullscreenBouncer() || mOccluded) {
424 reset(dozing /* hideBouncerWhenShowing */);
425 }
Adrian Roos41eecff2017-06-29 14:09:52 +0200426 updateStates();
Adrian Roosfee661c2017-08-04 17:05:45 +0200427
428 if (!dozing) {
Adrian Roos34e65402017-08-07 19:32:45 +0200429 launchPendingWakeupAction();
Adrian Roosfee661c2017-08-04 17:05:45 +0200430 }
Adrian Roos41eecff2017-06-29 14:09:52 +0200431 }
Adrian Roos087826a2017-04-19 16:59:09 -0700432 }
433
Lucas Dupinafffbf92019-04-09 19:52:26 -0700434 /**
435 * If {@link StatusBar} is pulsing.
436 */
437 public void setPulsing(boolean pulsing) {
438 if (mPulsing != pulsing) {
439 mPulsing = pulsing;
440 updateStates();
441 }
442 }
443
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100444 public void setNeedsInput(boolean needsInput) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700445 mStatusBarWindowController.setKeyguardNeedsInput(needsInput);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100446 }
447
Adrian Roosd5c2db62016-03-08 16:11:31 -0800448 public boolean isUnlockWithWallpaper() {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700449 return mStatusBarWindowController.isShowingWallpaper();
Adrian Roosd5c2db62016-03-08 16:11:31 -0800450 }
451
Jorim Jaggi6626f542016-08-22 13:08:44 -0700452 public void setOccluded(boolean occluded, boolean animate) {
Selim Cinek3a49ba22017-08-10 11:17:39 -0700453 mStatusBar.setOccluded(occluded);
Selim Cinekbaa23272014-07-08 18:01:07 +0200454 if (occluded && !mOccluded && mShowing) {
Tej Singhdd7bd352018-02-09 19:33:15 -0800455 StatsLog.write(StatsLog.KEYGUARD_STATE_CHANGED,
456 StatsLog.KEYGUARD_STATE_CHANGED__STATE__OCCLUDED);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500457 if (mStatusBar.isInLaunchTransition()) {
Selim Cinekbaa23272014-07-08 18:01:07 +0200458 mOccluded = true;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500459 mStatusBar.fadeKeyguardAfterLaunchTransition(null /* beforeFading */,
Selim Cinekbaa23272014-07-08 18:01:07 +0200460 new Runnable() {
461 @Override
462 public void run() {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700463 mStatusBarWindowController.setKeyguardOccluded(mOccluded);
Jorim Jaggife762342016-10-13 14:33:27 +0200464 reset(true /* hideBouncerWhenShowing */);
Selim Cinekbaa23272014-07-08 18:01:07 +0200465 }
466 });
467 return;
468 }
Tej Singhdd7bd352018-02-09 19:33:15 -0800469 } else if (!occluded && mOccluded && mShowing) {
470 StatsLog.write(StatsLog.KEYGUARD_STATE_CHANGED,
471 StatsLog.KEYGUARD_STATE_CHANGED__STATE__SHOWN);
Selim Cinekbaa23272014-07-08 18:01:07 +0200472 }
Lucas Dupin28f90292017-08-08 18:07:49 -0400473 boolean isOccluding = !mOccluded && occluded;
Jorim Jaggia6310292014-04-16 14:11:52 +0200474 mOccluded = occluded;
Adrian Roos909fe2d2016-10-12 12:03:24 -0700475 if (mShowing) {
Jason Monk297c04e2018-08-23 17:16:59 -0400476 mMediaManager.updateMediaMetaData(false, animate && !occluded);
Adrian Roos909fe2d2016-10-12 12:03:24 -0700477 }
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700478 mStatusBarWindowController.setKeyguardOccluded(occluded);
Jorim Jaggife762342016-10-13 14:33:27 +0200479
Adrian Roos7a56d1a2017-08-04 15:04:43 +0200480 // setDozing(false) will call reset once we stop dozing.
481 if (!mDozing) {
482 // If Keyguard is reshown, don't hide the bouncer as it might just have been requested
483 // by a FLAG_DISMISS_KEYGUARD_ACTIVITY.
Lucas Dupin28f90292017-08-08 18:07:49 -0400484 reset(isOccluding /* hideBouncerWhenShowing*/);
Adrian Roos7a56d1a2017-08-04 15:04:43 +0200485 }
Lucas Dupine9e70712019-05-01 14:41:49 -0700486 if (animate && !occluded && mShowing && !mBouncer.isShowing()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500487 mStatusBar.animateKeyguardUnoccluding();
Jorim Jaggi6626f542016-08-22 13:08:44 -0700488 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100489 }
490
Dan Sandler4b22bdf2014-06-05 00:58:02 -0400491 public boolean isOccluded() {
492 return mOccluded;
493 }
494
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100495 /**
Jorim Jaggi76a16232014-08-08 17:00:47 +0200496 * Starts the animation before we dismiss Keyguard, i.e. an disappearing animation on the
497 * security view of the bouncer.
498 *
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200499 * @param finishRunnable the runnable to be run after the animation finished, or {@code null} if
500 * no action should be run
Jorim Jaggi76a16232014-08-08 17:00:47 +0200501 */
502 public void startPreHideAnimation(Runnable finishRunnable) {
503 if (mBouncer.isShowing()) {
504 mBouncer.startPreHideAnimation(finishRunnable);
Lucas Dupin93752552018-03-19 21:32:19 -0700505 mNotificationPanelView.onBouncerPreHideAnimation();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200506 } else if (finishRunnable != null) {
Jorim Jaggi76a16232014-08-08 17:00:47 +0200507 finishRunnable.run();
508 }
Lucas Dupind61974d2019-03-29 16:09:26 -0700509 mNotificationPanelView.blockExpansionForCurrentTouch();
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700510 updateLockIcon();
Jorim Jaggi76a16232014-08-08 17:00:47 +0200511 }
512
513 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100514 * Hides the keyguard view
515 */
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700516 public void hide(long startTime, long fadeoutDuration) {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200517 mShowing = false;
Evan Laird2d620fa2018-10-30 13:03:31 -0400518 mKeyguardMonitor.notifyKeyguardState(
519 mShowing, mKeyguardMonitor.isSecure(), mKeyguardMonitor.isOccluded());
Adrian Roos34e65402017-08-07 19:32:45 +0200520 launchPendingWakeupAction();
Jorim Jaggi44cf9192014-06-17 19:16:00 -0700521
Jorim Jaggi031f7952016-09-01 16:39:26 -0700522 if (KeyguardUpdateMonitor.getInstance(mContext).needsSlowUnlockTransition()) {
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700523 fadeoutDuration = KEYGUARD_DISMISS_DURATION_LOCKED;
524 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200525 long uptimeMillis = SystemClock.uptimeMillis();
Jorim Jaggi76a16232014-08-08 17:00:47 +0200526 long delay = Math.max(0, startTime + HIDE_TIMING_CORRECTION_MS - uptimeMillis);
Selim Cinekbaa23272014-07-08 18:01:07 +0200527
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500528 if (mStatusBar.isInLaunchTransition() ) {
529 mStatusBar.fadeKeyguardAfterLaunchTransition(new Runnable() {
Selim Cinekbaa23272014-07-08 18:01:07 +0200530 @Override
531 public void run() {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700532 mStatusBarWindowController.setKeyguardShowing(false);
533 mStatusBarWindowController.setKeyguardFadingAway(true);
Adrian Roosfee661c2017-08-04 17:05:45 +0200534 hideBouncer(true /* destroyView */);
Selim Cinekbaa23272014-07-08 18:01:07 +0200535 updateStates();
Selim Cinekbaa23272014-07-08 18:01:07 +0200536 }
537 }, new Runnable() {
538 @Override
539 public void run() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500540 mStatusBar.hideKeyguard();
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700541 mStatusBarWindowController.setKeyguardFadingAway(false);
Selim Cinekbaa23272014-07-08 18:01:07 +0200542 mViewMediatorCallback.keyguardGone();
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200543 executeAfterKeyguardGoneAction();
Selim Cinekbaa23272014-07-08 18:01:07 +0200544 }
545 });
546 } else {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700547 executeAfterKeyguardGoneAction();
Jorim Jaggie93698b2016-11-11 18:24:38 -0800548 boolean wakeUnlockPulsing =
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200549 mBiometricUnlockController.getMode() == MODE_WAKE_AND_UNLOCK_PULSING;
Jorim Jaggie93698b2016-11-11 18:24:38 -0800550 if (wakeUnlockPulsing) {
551 delay = 0;
552 fadeoutDuration = 240;
553 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500554 mStatusBar.setKeyguardFadingAway(startTime, delay, fadeoutDuration);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200555 mBiometricUnlockController.startKeyguardFadingAway();
Adrian Roosfee661c2017-08-04 17:05:45 +0200556 hideBouncer(true /* destroyView */);
Jorim Jaggie93698b2016-11-11 18:24:38 -0800557 if (wakeUnlockPulsing) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500558 mStatusBar.fadeKeyguardWhilePulsing();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800559 wakeAndUnlockDejank();
Jorim Jaggidbc3dce2014-08-01 01:16:36 +0200560 } else {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500561 boolean staying = mStatusBar.hideKeyguard();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700562 if (!staying) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700563 mStatusBarWindowController.setKeyguardFadingAway(true);
Lucas Dupinf0a67e32018-09-19 15:23:54 -0700564 // hide() will happen asynchronously and might arrive after the scrims
565 // were already hidden, this means that the transition callback won't
566 // be triggered anymore and StatusBarWindowController will be forever in
567 // the fadingAway state.
568 mStatusBar.updateScrimController();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800569 wakeAndUnlockDejank();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700570 } else {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500571 mStatusBar.finishKeyguardFadingAway();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200572 mBiometricUnlockController.finishKeyguardFadingAway();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700573 }
Jorim Jaggidbc3dce2014-08-01 01:16:36 +0200574 }
Jorim Jaggi67b29d52017-06-09 18:00:00 -0700575 updateStates();
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700576 mStatusBarWindowController.setKeyguardShowing(false);
Selim Cinekbaa23272014-07-08 18:01:07 +0200577 mViewMediatorCallback.keyguardGone();
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200578 }
Tej Singhdd7bd352018-02-09 19:33:15 -0800579 StatsLog.write(StatsLog.KEYGUARD_STATE_CHANGED,
580 StatsLog.KEYGUARD_STATE_CHANGED__STATE__HIDDEN);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100581 }
582
Lucas Dupinafffbf92019-04-09 19:52:26 -0700583 @Override
Selim Cinekaa8bbf12016-05-04 14:13:20 -0700584 public void onDensityOrFontScaleChanged() {
Adrian Roosfee661c2017-08-04 17:05:45 +0200585 hideBouncer(true /* destroyView */);
Selim Cinekaa8bbf12016-05-04 14:13:20 -0700586 }
587
Lucas Dupinafffbf92019-04-09 19:52:26 -0700588 @Override
Winson Chung1aa24b92019-04-24 15:17:33 -0700589 public void onNavigationModeChanged(int mode) {
590 boolean gesturalNav = QuickStepContract.isGesturalMode(mode);
Lucas Dupinafffbf92019-04-09 19:52:26 -0700591 if (gesturalNav != mGesturalNav) {
592 mGesturalNav = gesturalNav;
593 updateStates();
594 }
595 }
596
Lucas Dupin8c51ce22017-11-21 13:21:05 -0800597 public void onThemeChanged() {
Adrian Roosfee661c2017-08-04 17:05:45 +0200598 hideBouncer(true /* destroyView */);
Lucas Dupinf190a852017-07-31 17:11:26 -0700599 mBouncer.prepare();
Lucas Dupin89516d42017-07-05 13:29:18 -0700600 }
601
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800602 public void onKeyguardFadedAway() {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700603 mContainer.postDelayed(() -> mStatusBarWindowController.setKeyguardFadingAway(false),
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800604 100);
605 mStatusBar.finishKeyguardFadingAway();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200606 mBiometricUnlockController.finishKeyguardFadingAway();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800607 WindowManagerGlobal.getInstance().trimMemory(
608 ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
609
Jorim Jaggi90978852015-08-18 19:55:53 -0700610 }
611
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800612 private void wakeAndUnlockDejank() {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200613 if (mBiometricUnlockController.getMode() == MODE_WAKE_AND_UNLOCK
Jorim Jaggi8adb30c2016-09-13 15:02:22 -0700614 && LatencyTracker.isEnabled(mContext)) {
615 DejankUtils.postAfterTraversal(() ->
616 LatencyTracker.getInstance(mContext).onActionEnd(
617 LatencyTracker.ACTION_FINGERPRINT_WAKE_AND_UNLOCK));
618 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700619 }
620
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200621 private void executeAfterKeyguardGoneAction() {
622 if (mAfterKeyguardGoneAction != null) {
623 mAfterKeyguardGoneAction.onDismiss();
624 mAfterKeyguardGoneAction = null;
625 }
Jorim Jaggibcbe9482016-11-23 17:37:49 +0100626 for (int i = 0; i < mAfterKeyguardGoneRunnables.size(); i++) {
627 mAfterKeyguardGoneRunnables.get(i).run();
628 }
629 mAfterKeyguardGoneRunnables.clear();
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200630 }
631
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100632 /**
633 * Dismisses the keyguard by going to the next screen or making it gone.
634 */
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700635 public void dismissAndCollapse() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500636 mStatusBar.executeRunnableDismissingKeyguard(null, null, true, false, true);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700637 }
638
Christoph Studer2231c6e2014-12-19 12:40:13 +0100639 /**
640 * WARNING: This method might cause Binder calls.
641 */
Jorim Jaggi15682502014-04-23 12:01:36 +0200642 public boolean isSecure() {
643 return mBouncer.isSecure();
644 }
645
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100646 /**
647 * @return Whether the keyguard is showing
648 */
649 public boolean isShowing() {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200650 return mShowing;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100651 }
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200652
653 /**
654 * Notifies this manager that the back button has been pressed.
655 *
Lucas Dupin3f54fe22018-04-08 23:17:40 -0700656 * @param hideImmediately Hide bouncer when {@code true}, keep it around otherwise.
657 * Non-scrimmed bouncers have a special animation tied to the expansion
658 * of the notification panel.
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200659 * @return whether the back press has been handled
660 */
Lucas Dupin3f54fe22018-04-08 23:17:40 -0700661 public boolean onBackPressed(boolean hideImmediately) {
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200662 if (mBouncer.isShowing()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500663 mStatusBar.endAffordanceLaunch();
Fabian Kozynskibaa47b62019-04-26 15:40:43 -0400664 // The second condition is for SIM card locked bouncer
665 if (mBouncer.isScrimmed() && !mBouncer.needsFullscreenBouncer()) {
666 hideBouncer(false);
667 updateStates();
668 } else {
669 reset(hideImmediately);
670 }
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200671 return true;
672 }
673 return false;
674 }
675
Jim Millerf41fc962014-06-18 16:33:51 -0700676 public boolean isBouncerShowing() {
677 return mBouncer.isShowing();
678 }
679
Lucas Dupind61974d2019-03-29 16:09:26 -0700680 public boolean isBouncerPartiallyVisible() {
681 return mBouncer.isPartiallyVisible();
682 }
683
Jackal Guo42cae962018-04-18 18:41:19 +0800684 public boolean isFullscreenBouncer() {
685 return mBouncer.isFullscreenBouncer();
686 }
687
Jorim Jaggi416493b2014-09-13 03:57:32 +0200688 private long getNavBarShowDelay() {
Jason Monk1fd3fc32018-08-14 17:20:09 -0400689 if (mKeyguardMonitor.isKeyguardFadingAway()) {
690 return mKeyguardMonitor.getKeyguardFadingAwayDelay();
Adrian Roos087826a2017-04-19 16:59:09 -0700691 } else if (mBouncer.isShowing()) {
Jorim Jaggi416493b2014-09-13 03:57:32 +0200692 return NAV_BAR_SHOW_DELAY_BOUNCER;
Adrian Roos087826a2017-04-19 16:59:09 -0700693 } else {
694 // No longer dozing, or remote input is active. No delay.
695 return 0;
Jorim Jaggi416493b2014-09-13 03:57:32 +0200696 }
697 }
698
699 private Runnable mMakeNavigationBarVisibleRunnable = new Runnable() {
700 @Override
701 public void run() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500702 mStatusBar.getNavigationBarView().getRootView().setVisibility(View.VISIBLE);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200703 }
704 };
705
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800706 protected void updateStates() {
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200707 int vis = mContainer.getSystemUiVisibility();
Adrian Roosb6011622014-05-14 15:52:53 +0200708 boolean showing = mShowing;
709 boolean occluded = mOccluded;
710 boolean bouncerShowing = mBouncer.isShowing();
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100711 boolean bouncerDismissible = !mBouncer.isFullscreenBouncer();
Adrian Roosd28ccd72016-01-06 15:23:14 +0100712 boolean remoteInputActive = mRemoteInputActive;
Adrian Roosb6011622014-05-14 15:52:53 +0200713
Adrian Roosd28ccd72016-01-06 15:23:14 +0100714 if ((bouncerDismissible || !showing || remoteInputActive) !=
715 (mLastBouncerDismissible || !mLastShowing || mLastRemoteInputActive)
Adrian Roosb6011622014-05-14 15:52:53 +0200716 || mFirstUpdate) {
Adrian Roosd28ccd72016-01-06 15:23:14 +0100717 if (bouncerDismissible || !showing || remoteInputActive) {
Adrian Roosb6011622014-05-14 15:52:53 +0200718 mContainer.setSystemUiVisibility(vis & ~View.STATUS_BAR_DISABLE_BACK);
Jason Monk1e68fb32014-05-02 16:06:20 -0400719 } else {
Adrian Roosb6011622014-05-14 15:52:53 +0200720 mContainer.setSystemUiVisibility(vis | View.STATUS_BAR_DISABLE_BACK);
Jason Monk1e68fb32014-05-02 16:06:20 -0400721 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200722 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700723
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800724 boolean navBarVisible = isNavBarVisible();
725 boolean lastNavBarVisible = getLastNavBarVisible();
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700726 if (navBarVisible != lastNavBarVisible || mFirstUpdate) {
Brad Stenning7e411812018-04-13 22:52:39 -0700727 updateNavigationBarVisibility(navBarVisible);
Adrian Roosb6011622014-05-14 15:52:53 +0200728 }
729
730 if (bouncerShowing != mLastBouncerShowing || mFirstUpdate) {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700731 mStatusBarWindowController.setBouncerShowing(bouncerShowing);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500732 mStatusBar.setBouncerShowing(bouncerShowing);
Adrian Roosb6011622014-05-14 15:52:53 +0200733 }
734
735 KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
736 if ((showing && !occluded) != (mLastShowing && !mLastOccluded) || mFirstUpdate) {
Jorim Jaggi6a15d522015-09-22 15:55:33 -0700737 updateMonitor.onKeyguardVisibilityChanged(showing && !occluded);
Adrian Roosb6011622014-05-14 15:52:53 +0200738 }
739 if (bouncerShowing != mLastBouncerShowing || mFirstUpdate) {
740 updateMonitor.sendKeyguardBouncerChanged(bouncerShowing);
741 }
742
743 mFirstUpdate = false;
744 mLastShowing = showing;
745 mLastOccluded = occluded;
746 mLastBouncerShowing = bouncerShowing;
747 mLastBouncerDismissible = bouncerDismissible;
Adrian Roosd28ccd72016-01-06 15:23:14 +0100748 mLastRemoteInputActive = remoteInputActive;
Adrian Roos087826a2017-04-19 16:59:09 -0700749 mLastDozing = mDozing;
Lucas Dupinafffbf92019-04-09 19:52:26 -0700750 mLastPulsing = mPulsing;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200751 mLastBiometricMode = mBiometricUnlockController.getMode();
Lucas Dupinafffbf92019-04-09 19:52:26 -0700752 mLastGesturalNav = mGesturalNav;
753 mLastIsDocked = mIsDocked;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500754 mStatusBar.onKeyguardViewManagerStatesUpdated();
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200755 }
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200756
Brad Stenning7e411812018-04-13 22:52:39 -0700757 protected void updateNavigationBarVisibility(boolean navBarVisible) {
758 if (mStatusBar.getNavigationBarView() != null) {
759 if (navBarVisible) {
760 long delay = getNavBarShowDelay();
761 if (delay == 0) {
762 mMakeNavigationBarVisibleRunnable.run();
763 } else {
764 mContainer.postOnAnimationDelayed(mMakeNavigationBarVisibleRunnable,
765 delay);
766 }
767 } else {
768 mContainer.removeCallbacks(mMakeNavigationBarVisibleRunnable);
769 mStatusBar.getNavigationBarView().getRootView().setVisibility(View.GONE);
770 }
771 }
772 }
773
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800774 /**
775 * @return Whether the navigation bar should be made visible based on the current state.
776 */
777 protected boolean isNavBarVisible() {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200778 int biometricMode = mBiometricUnlockController.getMode();
Jorim Jaggif5304ad2017-07-17 18:31:13 +0200779 boolean keyguardShowing = mShowing && !mOccluded;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200780 boolean hideWhileDozing = mDozing && biometricMode != MODE_WAKE_AND_UNLOCK_PULSING;
Lucas Dupinafffbf92019-04-09 19:52:26 -0700781 boolean keyguardWithGestureNav = (keyguardShowing && !mDozing || mPulsing && !mIsDocked)
782 && mGesturalNav;
Jorim Jaggif5304ad2017-07-17 18:31:13 +0200783 return (!keyguardShowing && !hideWhileDozing || mBouncer.isShowing()
Lucas Dupinafffbf92019-04-09 19:52:26 -0700784 || mRemoteInputActive || keyguardWithGestureNav);
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800785 }
786
787 /**
788 * @return Whether the navigation bar was made visible based on the last known state.
789 */
790 protected boolean getLastNavBarVisible() {
Jorim Jaggif5304ad2017-07-17 18:31:13 +0200791 boolean keyguardShowing = mLastShowing && !mLastOccluded;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200792 boolean hideWhileDozing = mLastDozing && mLastBiometricMode != MODE_WAKE_AND_UNLOCK_PULSING;
Lucas Dupinafffbf92019-04-09 19:52:26 -0700793 boolean keyguardWithGestureNav = (keyguardShowing && !mLastDozing
794 || mLastPulsing && !mLastIsDocked) && mLastGesturalNav;
Jorim Jaggif5304ad2017-07-17 18:31:13 +0200795 return (!keyguardShowing && !hideWhileDozing || mLastBouncerShowing
Lucas Dupinafffbf92019-04-09 19:52:26 -0700796 || mLastRemoteInputActive || keyguardWithGestureNav);
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800797 }
798
Selim Cinek28540192016-02-19 17:25:08 -0800799 public boolean shouldDismissOnMenuPressed() {
800 return mBouncer.shouldDismissOnMenuPressed();
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200801 }
Jorim Jaggidf993512014-05-13 23:06:35 +0200802
803 public boolean interceptMediaKey(KeyEvent event) {
804 return mBouncer.interceptMediaKey(event);
805 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200806
Jorim Jaggife762342016-10-13 14:33:27 +0200807 public void readyForKeyguardDone() {
808 mViewMediatorCallback.readyForKeyguardDone();
809 }
810
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +0200811 public boolean shouldDisableWindowAnimationsForUnlock() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500812 return mStatusBar.isInLaunchTransition();
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +0200813 }
814
815 public boolean isGoingToNotificationShade() {
Beverly8fdb5332019-02-04 14:29:49 -0500816 return ((SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class))
817 .leaveOpenOnKeyguardHide();
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +0200818 }
Adrian Roos31b844b2014-11-21 13:55:09 +0100819
820 public boolean isSecure(int userId) {
821 return mBouncer.isSecure() || mLockPatternUtils.isSecure(userId);
822 }
Jim Millerab954542014-10-10 18:21:49 -0700823
Jorim Jaggi33ae80e2015-02-04 16:37:11 +0100824 public void keyguardGoingAway() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500825 mStatusBar.keyguardGoingAway();
Jorim Jaggi33ae80e2015-02-04 16:37:11 +0100826 }
Jim Miller25d7e512015-03-03 17:12:09 -0800827
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700828 public void animateCollapsePanels(float speedUpFactor) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500829 mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE, true /* force */,
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700830 false /* delayed */, speedUpFactor);
Jim Miller25d7e512015-03-03 17:12:09 -0800831 }
Jorim Jaggi5cc86592015-06-08 14:48:28 -0700832
Aarthi Balachander0a427ef2018-07-13 15:00:58 -0700833
834 /**
835 * Called when cancel button in bouncer is pressed.
836 */
837 public void onCancelClicked() {
838 // No-op
839 }
840
Jorim Jaggi5cc86592015-06-08 14:48:28 -0700841 /**
842 * Notifies that the user has authenticated by other means than using the bouncer, for example,
843 * fingerprint.
844 */
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700845 public void notifyKeyguardAuthenticated(boolean strongAuth) {
846 mBouncer.notifyKeyguardAuthenticated(strongAuth);
Jorim Jaggi5cc86592015-06-08 14:48:28 -0700847 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700848
Jason Chang1e4a4bd2018-05-22 17:30:19 +0800849 public void showBouncerMessage(String message, ColorStateList colorState) {
850 mBouncer.showMessage(message, colorState);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700851 }
Jorim Jaggib774e552015-08-24 14:52:45 -0700852
853 public ViewRootImpl getViewRootImpl() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500854 return mStatusBar.getStatusBarView().getViewRootImpl();
Jorim Jaggib774e552015-08-24 14:52:45 -0700855 }
Adrian Roosfee661c2017-08-04 17:05:45 +0200856
Adrian Roos34e65402017-08-07 19:32:45 +0200857 public void launchPendingWakeupAction() {
858 DismissWithActionRequest request = mPendingWakeupAction;
859 mPendingWakeupAction = null;
Adrian Roosfee661c2017-08-04 17:05:45 +0200860 if (request != null) {
861 if (mShowing) {
862 dismissWithAction(request.dismissAction, request.cancelAction,
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800863 request.afterKeyguardGone, request.message);
Adrian Roosfee661c2017-08-04 17:05:45 +0200864 } else if (request.dismissAction != null) {
865 request.dismissAction.onDismiss();
866 }
867 }
868 }
869
Adrian Roos34e65402017-08-07 19:32:45 +0200870 public void cancelPendingWakeupAction() {
871 DismissWithActionRequest request = mPendingWakeupAction;
872 mPendingWakeupAction = null;
Adrian Roosfee661c2017-08-04 17:05:45 +0200873 if (request != null && request.cancelAction != null) {
874 request.cancelAction.run();
875 }
876 }
877
Lucas Dupinf9ca35e2018-05-16 20:41:35 -0700878 public boolean bouncerNeedsScrimming() {
Lucas Dupin300e3712019-03-27 19:33:36 -0700879 return mOccluded || mBouncer.willDismissWithAction()
Lucas Dupin93f714d2019-03-26 16:49:24 -0700880 || mStatusBar.isFullScreenUserSwitcherState()
Lucas Dupin300e3712019-03-27 19:33:36 -0700881 || (mBouncer.isShowing() && mBouncer.isScrimmed())
882 || mBouncer.isFullscreenBouncer();
Lucas Dupinf9ca35e2018-05-16 20:41:35 -0700883 }
884
Lucas Dupin15a6b6c2018-04-16 14:50:20 +0800885 public void dump(PrintWriter pw) {
886 pw.println("StatusBarKeyguardViewManager:");
887 pw.println(" mShowing: " + mShowing);
888 pw.println(" mOccluded: " + mOccluded);
889 pw.println(" mRemoteInputActive: " + mRemoteInputActive);
890 pw.println(" mDozing: " + mDozing);
891 pw.println(" mGoingToSleepVisibleNotOccluded: " + mGoingToSleepVisibleNotOccluded);
892 pw.println(" mAfterKeyguardGoneAction: " + mAfterKeyguardGoneAction);
893 pw.println(" mAfterKeyguardGoneRunnables: " + mAfterKeyguardGoneRunnables);
894 pw.println(" mPendingWakeupAction: " + mPendingWakeupAction);
895
896 if (mBouncer != null) {
897 mBouncer.dump(pw);
898 }
899 }
900
Evan Laird878c8532018-10-15 15:54:29 -0400901 @Override
902 public void onStateChanged(int newState) {
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700903 updateLockIcon();
Evan Laird878c8532018-10-15 15:54:29 -0400904 }
905
906 @Override
907 public void onDozingChanged(boolean isDozing) {
908 setDozing(isDozing);
909 }
910
Lucas Dupin407cc582019-03-11 21:04:31 -0700911 public KeyguardBouncer getBouncer() {
912 return mBouncer;
913 }
914
Adrian Roos34e65402017-08-07 19:32:45 +0200915 private static class DismissWithActionRequest {
Adrian Roosfee661c2017-08-04 17:05:45 +0200916 final OnDismissAction dismissAction;
917 final Runnable cancelAction;
918 final boolean afterKeyguardGone;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800919 final String message;
Adrian Roosfee661c2017-08-04 17:05:45 +0200920
Adrian Roos34e65402017-08-07 19:32:45 +0200921 DismissWithActionRequest(OnDismissAction dismissAction, Runnable cancelAction,
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800922 boolean afterKeyguardGone, String message) {
Adrian Roosfee661c2017-08-04 17:05:45 +0200923 this.dismissAction = dismissAction;
924 this.cancelAction = cancelAction;
925 this.afterKeyguardGone = afterKeyguardGone;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800926 this.message = message;
Adrian Roosfee661c2017-08-04 17:05:45 +0200927 }
928 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100929}