blob: c6673095d932f8a84f2f8bba478f88be7e06f712 [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
Jorim Jaggif5304ad2017-07-17 18:31:13 +020019import static com.android.keyguard.KeyguardHostView.OnDismissAction;
20import static com.android.systemui.statusbar.phone.FingerprintUnlockController.MODE_WAKE_AND_UNLOCK;
21import static com.android.systemui.statusbar.phone.FingerprintUnlockController.MODE_WAKE_AND_UNLOCK_PULSING;
22
Jorim Jaggi786afcb2014-09-25 02:41:29 +020023import android.content.ComponentCallbacks2;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010024import android.content.Context;
25import android.os.Bundle;
Jorim Jaggie29b2db2014-05-30 23:17:03 +020026import android.os.SystemClock;
Jorim Jaggidf993512014-05-13 23:06:35 +020027import android.view.KeyEvent;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010028import android.view.View;
29import android.view.ViewGroup;
Jorim Jaggib774e552015-08-24 14:52:45 -070030import android.view.ViewRootImpl;
Jorim Jaggi786afcb2014-09-25 02:41:29 +020031import android.view.WindowManagerGlobal;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010032
Jorim Jaggi5cf17872014-03-26 18:31:48 +010033import com.android.internal.widget.LockPatternUtils;
Adrian Roosb6011622014-05-14 15:52:53 +020034import com.android.keyguard.KeyguardUpdateMonitor;
Jorim Jaggia9d7fcd2017-05-18 01:08:12 +020035import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jason Monkea03be12017-12-04 11:08:41 -050036import com.android.internal.util.LatencyTracker;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010037import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggi8adb30c2016-09-13 15:02:22 -070038import com.android.systemui.DejankUtils;
Jason Monk421a9412017-02-06 09:15:21 -080039import com.android.systemui.Dependency;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080040import com.android.systemui.SystemUIFactory;
Jorim Jaggi241ae102016-11-02 21:57:33 -070041import com.android.systemui.keyguard.DismissCallbackRegistry;
Jim Miller25d7e512015-03-03 17:12:09 -080042import com.android.systemui.statusbar.CommandQueue;
Adrian Roosd28ccd72016-01-06 15:23:14 +010043import com.android.systemui.statusbar.RemoteInputController;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010044
Jorim Jaggibcbe9482016-11-23 17:37:49 +010045import java.util.ArrayList;
46
Jorim Jaggi5cf17872014-03-26 18:31:48 +010047/**
48 * Manages creating, showing, hiding and resetting the keyguard within the status bar. Calls back
49 * via {@link ViewMediatorCallback} to poke the wake lock and report that the keyguard is done,
50 * which is in turn, reported to this class by the current
51 * {@link com.android.keyguard.KeyguardViewBase}.
52 */
Adrian Roosd28ccd72016-01-06 15:23:14 +010053public class StatusBarKeyguardViewManager implements RemoteInputController.Callback {
Jorim Jaggi76a16232014-08-08 17:00:47 +020054
55 // When hiding the Keyguard with timing supplied from WindowManager, better be early than late.
Jorim Jaggi56fd70c2016-10-27 19:57:08 -070056 private static final long HIDE_TIMING_CORRECTION_MS = - 16 * 3;
Jorim Jaggi76a16232014-08-08 17:00:47 +020057
Jorim Jaggi416493b2014-09-13 03:57:32 +020058 // Delay for showing the navigation bar when the bouncer appears. This should be kept in sync
59 // with the appear animations of the PIN/pattern/password views.
60 private static final long NAV_BAR_SHOW_DELAY_BOUNCER = 320;
61
Jorim Jaggi007f0e82015-08-14 13:56:01 -070062 private static final long WAKE_AND_UNLOCK_SCRIM_FADEOUT_DURATION_MS = 200;
63
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070064 // Duration of the Keyguard dismissal animation in case the user is currently locked. This is to
65 // make everything a bit slower to bridge a gap until the user is unlocked and home screen has
66 // dranw its first frame.
67 private static final long KEYGUARD_DISMISS_DURATION_LOCKED = 2000;
68
Jorim Jaggi5cf17872014-03-26 18:31:48 +010069 private static String TAG = "StatusBarKeyguardViewManager";
70
Xiyuan Xia1b30f792016-01-06 08:50:30 -080071 protected final Context mContext;
Jason Monk421a9412017-02-06 09:15:21 -080072 private final StatusBarWindowManager mStatusBarWindowManager;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010073
Xiyuan Xia1b30f792016-01-06 08:50:30 -080074 protected LockPatternUtils mLockPatternUtils;
75 protected ViewMediatorCallback mViewMediatorCallback;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050076 protected StatusBar mStatusBar;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070077 private FingerprintUnlockController mFingerprintUnlockController;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078
Jorim Jaggi5cf17872014-03-26 18:31:48 +010079 private ViewGroup mContainer;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010080
Xiyuan Xia1b30f792016-01-06 08:50:30 -080081 protected KeyguardBouncer mBouncer;
82 protected boolean mShowing;
83 protected boolean mOccluded;
84 protected boolean mRemoteInputActive;
Adrian Roos087826a2017-04-19 16:59:09 -070085 private boolean mDozing;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010086
Xiyuan Xia1b30f792016-01-06 08:50:30 -080087 protected boolean mFirstUpdate = true;
88 protected boolean mLastShowing;
89 protected boolean mLastOccluded;
Adrian Roosb6011622014-05-14 15:52:53 +020090 private boolean mLastBouncerShowing;
91 private boolean mLastBouncerDismissible;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080092 protected boolean mLastRemoteInputActive;
Adrian Roos087826a2017-04-19 16:59:09 -070093 private boolean mLastDozing;
Jorim Jaggif5304ad2017-07-17 18:31:13 +020094 private int mLastFpMode;
Adrian Roosd28ccd72016-01-06 15:23:14 +010095
Jorim Jaggi746f7fa2014-08-27 17:52:46 +020096 private OnDismissAction mAfterKeyguardGoneAction;
Jorim Jaggibcbe9482016-11-23 17:37:49 +010097 private final ArrayList<Runnable> mAfterKeyguardGoneRunnables = new ArrayList<>();
Adrian Roosb6011622014-05-14 15:52:53 +020098
Adrian Roosfee661c2017-08-04 17:05:45 +020099 // Dismiss action to be launched when we stop dozing or the keyguard is gone.
Adrian Roos34e65402017-08-07 19:32:45 +0200100 private DismissWithActionRequest mPendingWakeupAction;
Adrian Roosfee661c2017-08-04 17:05:45 +0200101
Jorim Jaggia9d7fcd2017-05-18 01:08:12 +0200102 private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback =
103 new KeyguardUpdateMonitorCallback() {
104 @Override
105 public void onEmergencyCallAction() {
106
107 // Since we won't get a setOccluded call we have to reset the view manually such that
108 // the bouncer goes away.
109 if (mOccluded) {
Lucas Dupin28f90292017-08-08 18:07:49 -0400110 reset(true /* hideBouncerWhenShowing */);
Jorim Jaggia9d7fcd2017-05-18 01:08:12 +0200111 }
112 }
113 };
114
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100115 public StatusBarKeyguardViewManager(Context context, ViewMediatorCallback callback,
116 LockPatternUtils lockPatternUtils) {
117 mContext = context;
118 mViewMediatorCallback = callback;
119 mLockPatternUtils = lockPatternUtils;
Jason Monk421a9412017-02-06 09:15:21 -0800120 mStatusBarWindowManager = Dependency.get(StatusBarWindowManager.class);
Jorim Jaggia9d7fcd2017-05-18 01:08:12 +0200121 KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateMonitorCallback);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100122 }
123
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500124 public void registerStatusBar(StatusBar statusBar,
Jason Monk421a9412017-02-06 09:15:21 -0800125 ViewGroup container,
Jorim Jaggi241ae102016-11-02 21:57:33 -0700126 FingerprintUnlockController fingerprintUnlockController,
127 DismissCallbackRegistry dismissCallbackRegistry) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500128 mStatusBar = statusBar;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100129 mContainer = container;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700130 mFingerprintUnlockController = fingerprintUnlockController;
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800131 mBouncer = SystemUIFactory.getInstance().createKeyguardBouncer(mContext,
Jorim Jaggi241ae102016-11-02 21:57:33 -0700132 mViewMediatorCallback, mLockPatternUtils, container, dismissCallbackRegistry);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100133 }
134
135 /**
136 * Show the keyguard. Will handle creating and attaching to the view manager
137 * lazily.
138 */
139 public void show(Bundle options) {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200140 mShowing = true;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200141 mStatusBarWindowManager.setKeyguardShowing(true);
Jorim Jaggife762342016-10-13 14:33:27 +0200142 reset(true /* hideBouncerWhenShowing */);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100143 }
144
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200145 /**
146 * Shows the notification keyguard or the bouncer depending on
147 * {@link KeyguardBouncer#needsFullscreenBouncer()}.
148 */
Jorim Jaggife762342016-10-13 14:33:27 +0200149 protected void showBouncerOrKeyguard(boolean hideBouncerWhenShowing) {
Adrian Roos41eecff2017-06-29 14:09:52 +0200150 if (mBouncer.needsFullscreenBouncer() && !mDozing) {
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200151 // The keyguard might be showing (already). So we need to hide it.
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500152 mStatusBar.hideKeyguard();
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100153 mBouncer.show(true /* resetSecuritySelection */);
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200154 } else {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500155 mStatusBar.showKeyguard();
Jorim Jaggife762342016-10-13 14:33:27 +0200156 if (hideBouncerWhenShowing) {
Adrian Roosfee661c2017-08-04 17:05:45 +0200157 hideBouncer(false /* destroyView */);
Jorim Jaggife762342016-10-13 14:33:27 +0200158 mBouncer.prepare();
159 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200160 }
Adrian Roos61676aa2017-08-03 16:24:32 +0200161 updateStates();
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200162 }
163
Adrian Roosfee661c2017-08-04 17:05:45 +0200164 private void hideBouncer(boolean destroyView) {
165 mBouncer.hide(destroyView);
Adrian Roos34e65402017-08-07 19:32:45 +0200166 cancelPendingWakeupAction();
Adrian Roosfee661c2017-08-04 17:05:45 +0200167 }
168
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200169 private void showBouncer() {
Adrian Roos0002a452014-07-03 13:46:07 +0200170 if (mShowing) {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100171 mBouncer.show(false /* resetSecuritySelection */);
Dan Sandler3806c772014-05-08 14:52:10 -0400172 }
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200173 updateStates();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100174 }
175
Jorim Jaggid9449862015-05-29 14:49:08 -0700176 public void dismissWithAction(OnDismissAction r, Runnable cancelAction,
177 boolean afterKeyguardGone) {
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800178 dismissWithAction(r, cancelAction, afterKeyguardGone, null /* message */);
179 }
180
181 public void dismissWithAction(OnDismissAction r, Runnable cancelAction,
182 boolean afterKeyguardGone, String message) {
Adrian Roos0002a452014-07-03 13:46:07 +0200183 if (mShowing) {
Adrian Roos34e65402017-08-07 19:32:45 +0200184 cancelPendingWakeupAction();
Adrian Roosfee661c2017-08-04 17:05:45 +0200185 // If we're dozing, this needs to be delayed until after we wake up - unless we're
186 // wake-and-unlocking, because there dozing will last until the end of the transition.
187 if (mDozing && !isWakeAndUnlocking()) {
Adrian Roos34e65402017-08-07 19:32:45 +0200188 mPendingWakeupAction = new DismissWithActionRequest(
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800189 r, cancelAction, afterKeyguardGone, message);
Adrian Roosfee661c2017-08-04 17:05:45 +0200190 return;
191 }
192
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200193 if (!afterKeyguardGone) {
Jorim Jaggid9449862015-05-29 14:49:08 -0700194 mBouncer.showWithDismissAction(r, cancelAction);
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200195 } else {
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200196 mAfterKeyguardGoneAction = r;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700197 mBouncer.show(false /* resetSecuritySelection */);
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200198 }
Adrian Roos7d7090d2014-05-21 13:10:23 +0200199 }
200 updateStates();
201 }
202
Adrian Roosfee661c2017-08-04 17:05:45 +0200203 private boolean isWakeAndUnlocking() {
204 int mode = mFingerprintUnlockController.getMode();
205 return mode == MODE_WAKE_AND_UNLOCK || mode == MODE_WAKE_AND_UNLOCK_PULSING;
206 }
207
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100208 /**
Jorim Jaggibcbe9482016-11-23 17:37:49 +0100209 * Adds a {@param runnable} to be executed after Keyguard is gone.
210 */
211 public void addAfterKeyguardGoneRunnable(Runnable runnable) {
212 mAfterKeyguardGoneRunnables.add(runnable);
213 }
214
215 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100216 * Reset the state of the view.
217 */
Jorim Jaggife762342016-10-13 14:33:27 +0200218 public void reset(boolean hideBouncerWhenShowing) {
Jorim Jaggi43bdbbd2014-05-09 16:05:53 +0200219 if (mShowing) {
Adrian Roos7a56d1a2017-08-04 15:04:43 +0200220 if (mOccluded && !mDozing) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500221 mStatusBar.hideKeyguard();
Adrian Roos91ffdc42017-08-04 18:14:41 +0200222 if (hideBouncerWhenShowing || mBouncer.needsFullscreenBouncer()) {
223 hideBouncer(false /* destroyView */);
224 }
Jorim Jaggi43bdbbd2014-05-09 16:05:53 +0200225 } else {
Jorim Jaggife762342016-10-13 14:33:27 +0200226 showBouncerOrKeyguard(hideBouncerWhenShowing);
Jorim Jaggi43bdbbd2014-05-09 16:05:53 +0200227 }
Selim Cinek1fcafc42015-07-20 14:39:25 -0700228 KeyguardUpdateMonitor.getInstance(mContext).sendKeyguardReset();
Jorim Jaggi43bdbbd2014-05-09 16:05:53 +0200229 updateStates();
Dan Sandler3806c772014-05-08 14:52:10 -0400230 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100231 }
232
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700233 public void onStartedGoingToSleep() {
Adrian Roos731d4df2017-07-18 15:10:39 +0200234 // TODO: remove
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700235 }
236
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700237 public void onFinishedGoingToSleep() {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200238 mBouncer.onScreenTurnedOff();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100239 }
240
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700241 public void onStartedWakingUp() {
Adrian Roos731d4df2017-07-18 15:10:39 +0200242 // TODO: remove
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100243 }
244
Jorim Jaggi93739112015-08-13 15:53:14 -0700245 public void onScreenTurningOn() {
Adrian Roos731d4df2017-07-18 15:10:39 +0200246 // TODO: remove
Selim Cinek372d1bd2015-08-14 13:19:37 -0700247 }
248
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700249 public void onScreenTurnedOn() {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800250 // TODO: remove
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700251 }
252
Adrian Roosd28ccd72016-01-06 15:23:14 +0100253 @Override
254 public void onRemoteInputActive(boolean active) {
255 mRemoteInputActive = active;
256 updateStates();
257 }
258
Adrian Roos087826a2017-04-19 16:59:09 -0700259 public void setDozing(boolean dozing) {
Adrian Roos41eecff2017-06-29 14:09:52 +0200260 if (mDozing != dozing) {
261 mDozing = dozing;
Adrian Roos61676aa2017-08-03 16:24:32 +0200262 if (dozing || mBouncer.needsFullscreenBouncer() || mOccluded) {
263 reset(dozing /* hideBouncerWhenShowing */);
264 }
Adrian Roos41eecff2017-06-29 14:09:52 +0200265 updateStates();
Adrian Roosfee661c2017-08-04 17:05:45 +0200266
267 if (!dozing) {
Adrian Roos34e65402017-08-07 19:32:45 +0200268 launchPendingWakeupAction();
Adrian Roosfee661c2017-08-04 17:05:45 +0200269 }
Adrian Roos41eecff2017-06-29 14:09:52 +0200270 }
Adrian Roos087826a2017-04-19 16:59:09 -0700271 }
272
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700273 public void onScreenTurnedOff() {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800274 // TODO: remove
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700275 }
276
277 public void notifyDeviceWakeUpRequested() {
Adrian Roos731d4df2017-07-18 15:10:39 +0200278 // TODO: remove
Selim Cinekf8fbc2a72015-06-22 16:42:07 -0400279 }
280
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100281 public void setNeedsInput(boolean needsInput) {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200282 mStatusBarWindowManager.setKeyguardNeedsInput(needsInput);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100283 }
284
Adrian Roosd5c2db62016-03-08 16:11:31 -0800285 public boolean isUnlockWithWallpaper() {
286 return mStatusBarWindowManager.isShowingWallpaper();
287 }
288
Jorim Jaggi6626f542016-08-22 13:08:44 -0700289 public void setOccluded(boolean occluded, boolean animate) {
Selim Cinek3a49ba22017-08-10 11:17:39 -0700290 mStatusBar.setOccluded(occluded);
Selim Cinekbaa23272014-07-08 18:01:07 +0200291 if (occluded && !mOccluded && mShowing) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500292 if (mStatusBar.isInLaunchTransition()) {
Selim Cinekbaa23272014-07-08 18:01:07 +0200293 mOccluded = true;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500294 mStatusBar.fadeKeyguardAfterLaunchTransition(null /* beforeFading */,
Selim Cinekbaa23272014-07-08 18:01:07 +0200295 new Runnable() {
296 @Override
297 public void run() {
Jorim Jaggi826730a2014-12-08 21:05:13 +0100298 mStatusBarWindowManager.setKeyguardOccluded(mOccluded);
Jorim Jaggife762342016-10-13 14:33:27 +0200299 reset(true /* hideBouncerWhenShowing */);
Selim Cinekbaa23272014-07-08 18:01:07 +0200300 }
301 });
302 return;
303 }
304 }
Lucas Dupin28f90292017-08-08 18:07:49 -0400305 boolean isOccluding = !mOccluded && occluded;
Jorim Jaggia6310292014-04-16 14:11:52 +0200306 mOccluded = occluded;
Adrian Roos909fe2d2016-10-12 12:03:24 -0700307 if (mShowing) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500308 mStatusBar.updateMediaMetaData(false, animate && !occluded);
Adrian Roos909fe2d2016-10-12 12:03:24 -0700309 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200310 mStatusBarWindowManager.setKeyguardOccluded(occluded);
Jorim Jaggife762342016-10-13 14:33:27 +0200311
Adrian Roos7a56d1a2017-08-04 15:04:43 +0200312 // setDozing(false) will call reset once we stop dozing.
313 if (!mDozing) {
314 // If Keyguard is reshown, don't hide the bouncer as it might just have been requested
315 // by a FLAG_DISMISS_KEYGUARD_ACTIVITY.
Lucas Dupin28f90292017-08-08 18:07:49 -0400316 reset(isOccluding /* hideBouncerWhenShowing*/);
Adrian Roos7a56d1a2017-08-04 15:04:43 +0200317 }
Adrian Roos909fe2d2016-10-12 12:03:24 -0700318 if (animate && !occluded && mShowing) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500319 mStatusBar.animateKeyguardUnoccluding();
Jorim Jaggi6626f542016-08-22 13:08:44 -0700320 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100321 }
322
Dan Sandler4b22bdf2014-06-05 00:58:02 -0400323 public boolean isOccluded() {
324 return mOccluded;
325 }
326
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100327 /**
Jorim Jaggi76a16232014-08-08 17:00:47 +0200328 * Starts the animation before we dismiss Keyguard, i.e. an disappearing animation on the
329 * security view of the bouncer.
330 *
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200331 * @param finishRunnable the runnable to be run after the animation finished, or {@code null} if
332 * no action should be run
Jorim Jaggi76a16232014-08-08 17:00:47 +0200333 */
334 public void startPreHideAnimation(Runnable finishRunnable) {
335 if (mBouncer.isShowing()) {
336 mBouncer.startPreHideAnimation(finishRunnable);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200337 } else if (finishRunnable != null) {
Jorim Jaggi76a16232014-08-08 17:00:47 +0200338 finishRunnable.run();
339 }
340 }
341
342 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100343 * Hides the keyguard view
344 */
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700345 public void hide(long startTime, long fadeoutDuration) {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200346 mShowing = false;
Adrian Roos34e65402017-08-07 19:32:45 +0200347 launchPendingWakeupAction();
Jorim Jaggi44cf9192014-06-17 19:16:00 -0700348
Jorim Jaggi031f7952016-09-01 16:39:26 -0700349 if (KeyguardUpdateMonitor.getInstance(mContext).needsSlowUnlockTransition()) {
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700350 fadeoutDuration = KEYGUARD_DISMISS_DURATION_LOCKED;
351 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200352 long uptimeMillis = SystemClock.uptimeMillis();
Jorim Jaggi76a16232014-08-08 17:00:47 +0200353 long delay = Math.max(0, startTime + HIDE_TIMING_CORRECTION_MS - uptimeMillis);
Selim Cinekbaa23272014-07-08 18:01:07 +0200354
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500355 if (mStatusBar.isInLaunchTransition() ) {
356 mStatusBar.fadeKeyguardAfterLaunchTransition(new Runnable() {
Selim Cinekbaa23272014-07-08 18:01:07 +0200357 @Override
358 public void run() {
359 mStatusBarWindowManager.setKeyguardShowing(false);
360 mStatusBarWindowManager.setKeyguardFadingAway(true);
Adrian Roosfee661c2017-08-04 17:05:45 +0200361 hideBouncer(true /* destroyView */);
Selim Cinekbaa23272014-07-08 18:01:07 +0200362 updateStates();
Selim Cinekbaa23272014-07-08 18:01:07 +0200363 }
364 }, new Runnable() {
365 @Override
366 public void run() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500367 mStatusBar.hideKeyguard();
Selim Cinekbaa23272014-07-08 18:01:07 +0200368 mStatusBarWindowManager.setKeyguardFadingAway(false);
369 mViewMediatorCallback.keyguardGone();
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200370 executeAfterKeyguardGoneAction();
Selim Cinekbaa23272014-07-08 18:01:07 +0200371 }
372 });
373 } else {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700374 executeAfterKeyguardGoneAction();
Jorim Jaggie93698b2016-11-11 18:24:38 -0800375 boolean wakeUnlockPulsing =
376 mFingerprintUnlockController.getMode() == MODE_WAKE_AND_UNLOCK_PULSING;
377 if (wakeUnlockPulsing) {
378 delay = 0;
379 fadeoutDuration = 240;
380 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500381 mStatusBar.setKeyguardFadingAway(startTime, delay, fadeoutDuration);
Jorim Jaggie93698b2016-11-11 18:24:38 -0800382 mFingerprintUnlockController.startKeyguardFadingAway();
Adrian Roosfee661c2017-08-04 17:05:45 +0200383 hideBouncer(true /* destroyView */);
Jorim Jaggie93698b2016-11-11 18:24:38 -0800384 if (wakeUnlockPulsing) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500385 mStatusBar.fadeKeyguardWhilePulsing();
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800386 wakeAndUnlockDejank();
Jorim Jaggidbc3dce2014-08-01 01:16:36 +0200387 } else {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500388 boolean staying = mStatusBar.hideKeyguard();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700389 if (!staying) {
390 mStatusBarWindowManager.setKeyguardFadingAway(true);
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800391 wakeAndUnlockDejank();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700392 } else {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500393 mStatusBar.finishKeyguardFadingAway();
Adrian Roos88e61aa2017-05-23 16:16:50 -0700394 mFingerprintUnlockController.finishKeyguardFadingAway();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700395 }
Jorim Jaggidbc3dce2014-08-01 01:16:36 +0200396 }
Jorim Jaggi67b29d52017-06-09 18:00:00 -0700397 updateStates();
Selim Cinekbaa23272014-07-08 18:01:07 +0200398 mStatusBarWindowManager.setKeyguardShowing(false);
Selim Cinekbaa23272014-07-08 18:01:07 +0200399 mViewMediatorCallback.keyguardGone();
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200400 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100401 }
402
Selim Cinekaa8bbf12016-05-04 14:13:20 -0700403 public void onDensityOrFontScaleChanged() {
Adrian Roosfee661c2017-08-04 17:05:45 +0200404 hideBouncer(true /* destroyView */);
Selim Cinekaa8bbf12016-05-04 14:13:20 -0700405 }
406
Lucas Dupin8c51ce22017-11-21 13:21:05 -0800407 public void onThemeChanged() {
Adrian Roosfee661c2017-08-04 17:05:45 +0200408 hideBouncer(true /* destroyView */);
Lucas Dupinf190a852017-07-31 17:11:26 -0700409 mBouncer.prepare();
Lucas Dupin89516d42017-07-05 13:29:18 -0700410 }
411
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800412 public void onKeyguardFadedAway() {
413 mContainer.postDelayed(() -> mStatusBarWindowManager.setKeyguardFadingAway(false),
414 100);
415 mStatusBar.finishKeyguardFadingAway();
416 mFingerprintUnlockController.finishKeyguardFadingAway();
417 WindowManagerGlobal.getInstance().trimMemory(
418 ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
419
Jorim Jaggi90978852015-08-18 19:55:53 -0700420 }
421
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800422 private void wakeAndUnlockDejank() {
Jorim Jaggi8adb30c2016-09-13 15:02:22 -0700423 if (mFingerprintUnlockController.getMode() == MODE_WAKE_AND_UNLOCK
424 && LatencyTracker.isEnabled(mContext)) {
425 DejankUtils.postAfterTraversal(() ->
426 LatencyTracker.getInstance(mContext).onActionEnd(
427 LatencyTracker.ACTION_FINGERPRINT_WAKE_AND_UNLOCK));
428 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700429 }
430
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200431 private void executeAfterKeyguardGoneAction() {
432 if (mAfterKeyguardGoneAction != null) {
433 mAfterKeyguardGoneAction.onDismiss();
434 mAfterKeyguardGoneAction = null;
435 }
Jorim Jaggibcbe9482016-11-23 17:37:49 +0100436 for (int i = 0; i < mAfterKeyguardGoneRunnables.size(); i++) {
437 mAfterKeyguardGoneRunnables.get(i).run();
438 }
439 mAfterKeyguardGoneRunnables.clear();
Jorim Jaggi746f7fa2014-08-27 17:52:46 +0200440 }
441
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100442 /**
443 * Dismisses the keyguard by going to the next screen or making it gone.
444 */
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700445 public void dismissAndCollapse() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500446 mStatusBar.executeRunnableDismissingKeyguard(null, null, true, false, true);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700447 }
448
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100449 public void dismiss() {
Jorim Jaggife762342016-10-13 14:33:27 +0200450 showBouncer();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100451 }
452
Christoph Studer2231c6e2014-12-19 12:40:13 +0100453 /**
454 * WARNING: This method might cause Binder calls.
455 */
Jorim Jaggi15682502014-04-23 12:01:36 +0200456 public boolean isSecure() {
457 return mBouncer.isSecure();
458 }
459
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100460 /**
461 * @return Whether the keyguard is showing
462 */
463 public boolean isShowing() {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200464 return mShowing;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100465 }
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200466
467 /**
468 * Notifies this manager that the back button has been pressed.
469 *
470 * @return whether the back press has been handled
471 */
472 public boolean onBackPressed() {
473 if (mBouncer.isShowing()) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500474 mStatusBar.endAffordanceLaunch();
Jorim Jaggife762342016-10-13 14:33:27 +0200475 reset(true /* hideBouncerWhenShowing */);
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200476 return true;
477 }
478 return false;
479 }
480
Jim Millerf41fc962014-06-18 16:33:51 -0700481 public boolean isBouncerShowing() {
482 return mBouncer.isShowing();
483 }
484
Jorim Jaggi416493b2014-09-13 03:57:32 +0200485 private long getNavBarShowDelay() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500486 if (mStatusBar.isKeyguardFadingAway()) {
487 return mStatusBar.getKeyguardFadingAwayDelay();
Adrian Roos087826a2017-04-19 16:59:09 -0700488 } else if (mBouncer.isShowing()) {
Jorim Jaggi416493b2014-09-13 03:57:32 +0200489 return NAV_BAR_SHOW_DELAY_BOUNCER;
Adrian Roos087826a2017-04-19 16:59:09 -0700490 } else {
491 // No longer dozing, or remote input is active. No delay.
492 return 0;
Jorim Jaggi416493b2014-09-13 03:57:32 +0200493 }
494 }
495
496 private Runnable mMakeNavigationBarVisibleRunnable = new Runnable() {
497 @Override
498 public void run() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500499 mStatusBar.getNavigationBarView().getRootView().setVisibility(View.VISIBLE);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200500 }
501 };
502
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800503 protected void updateStates() {
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200504 int vis = mContainer.getSystemUiVisibility();
Adrian Roosb6011622014-05-14 15:52:53 +0200505 boolean showing = mShowing;
506 boolean occluded = mOccluded;
507 boolean bouncerShowing = mBouncer.isShowing();
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100508 boolean bouncerDismissible = !mBouncer.isFullscreenBouncer();
Adrian Roosd28ccd72016-01-06 15:23:14 +0100509 boolean remoteInputActive = mRemoteInputActive;
Adrian Roosb6011622014-05-14 15:52:53 +0200510
Adrian Roosd28ccd72016-01-06 15:23:14 +0100511 if ((bouncerDismissible || !showing || remoteInputActive) !=
512 (mLastBouncerDismissible || !mLastShowing || mLastRemoteInputActive)
Adrian Roosb6011622014-05-14 15:52:53 +0200513 || mFirstUpdate) {
Adrian Roosd28ccd72016-01-06 15:23:14 +0100514 if (bouncerDismissible || !showing || remoteInputActive) {
Adrian Roosb6011622014-05-14 15:52:53 +0200515 mContainer.setSystemUiVisibility(vis & ~View.STATUS_BAR_DISABLE_BACK);
Jason Monk1e68fb32014-05-02 16:06:20 -0400516 } else {
Adrian Roosb6011622014-05-14 15:52:53 +0200517 mContainer.setSystemUiVisibility(vis | View.STATUS_BAR_DISABLE_BACK);
Jason Monk1e68fb32014-05-02 16:06:20 -0400518 }
Jorim Jaggia6310292014-04-16 14:11:52 +0200519 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700520
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800521 boolean navBarVisible = isNavBarVisible();
522 boolean lastNavBarVisible = getLastNavBarVisible();
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700523 if (navBarVisible != lastNavBarVisible || mFirstUpdate) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500524 if (mStatusBar.getNavigationBarView() != null) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700525 if (navBarVisible) {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700526 long delay = getNavBarShowDelay();
527 if (delay == 0) {
528 mMakeNavigationBarVisibleRunnable.run();
529 } else {
530 mContainer.postOnAnimationDelayed(mMakeNavigationBarVisibleRunnable,
531 delay);
532 }
Adrian Roosb6011622014-05-14 15:52:53 +0200533 } else {
Jorim Jaggi416493b2014-09-13 03:57:32 +0200534 mContainer.removeCallbacks(mMakeNavigationBarVisibleRunnable);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500535 mStatusBar.getNavigationBarView().getRootView().setVisibility(View.GONE);
Adrian Roosb6011622014-05-14 15:52:53 +0200536 }
537 }
538 }
539
540 if (bouncerShowing != mLastBouncerShowing || mFirstUpdate) {
541 mStatusBarWindowManager.setBouncerShowing(bouncerShowing);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500542 mStatusBar.setBouncerShowing(bouncerShowing);
Adrian Roosb6011622014-05-14 15:52:53 +0200543 }
544
545 KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
546 if ((showing && !occluded) != (mLastShowing && !mLastOccluded) || mFirstUpdate) {
Jorim Jaggi6a15d522015-09-22 15:55:33 -0700547 updateMonitor.onKeyguardVisibilityChanged(showing && !occluded);
Adrian Roosb6011622014-05-14 15:52:53 +0200548 }
549 if (bouncerShowing != mLastBouncerShowing || mFirstUpdate) {
550 updateMonitor.sendKeyguardBouncerChanged(bouncerShowing);
551 }
552
553 mFirstUpdate = false;
554 mLastShowing = showing;
555 mLastOccluded = occluded;
556 mLastBouncerShowing = bouncerShowing;
557 mLastBouncerDismissible = bouncerDismissible;
Adrian Roosd28ccd72016-01-06 15:23:14 +0100558 mLastRemoteInputActive = remoteInputActive;
Adrian Roos087826a2017-04-19 16:59:09 -0700559 mLastDozing = mDozing;
Jorim Jaggif5304ad2017-07-17 18:31:13 +0200560 mLastFpMode = mFingerprintUnlockController.getMode();
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500561 mStatusBar.onKeyguardViewManagerStatesUpdated();
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200562 }
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200563
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800564 /**
565 * @return Whether the navigation bar should be made visible based on the current state.
566 */
567 protected boolean isNavBarVisible() {
Jorim Jaggif5304ad2017-07-17 18:31:13 +0200568 int fpMode = mFingerprintUnlockController.getMode();
569 boolean keyguardShowing = mShowing && !mOccluded;
570 boolean hideWhileDozing = mDozing && fpMode != MODE_WAKE_AND_UNLOCK_PULSING;
571 return (!keyguardShowing && !hideWhileDozing || mBouncer.isShowing()
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800572 || mRemoteInputActive);
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800573 }
574
575 /**
576 * @return Whether the navigation bar was made visible based on the last known state.
577 */
578 protected boolean getLastNavBarVisible() {
Jorim Jaggif5304ad2017-07-17 18:31:13 +0200579 boolean keyguardShowing = mLastShowing && !mLastOccluded;
580 boolean hideWhileDozing = mLastDozing && mLastFpMode != MODE_WAKE_AND_UNLOCK_PULSING;
581 return (!keyguardShowing && !hideWhileDozing || mLastBouncerShowing
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800582 || mLastRemoteInputActive);
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800583 }
584
Selim Cinek28540192016-02-19 17:25:08 -0800585 public boolean shouldDismissOnMenuPressed() {
586 return mBouncer.shouldDismissOnMenuPressed();
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200587 }
Jorim Jaggidf993512014-05-13 23:06:35 +0200588
589 public boolean interceptMediaKey(KeyEvent event) {
590 return mBouncer.interceptMediaKey(event);
591 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200592
Jorim Jaggife762342016-10-13 14:33:27 +0200593 public void readyForKeyguardDone() {
594 mViewMediatorCallback.readyForKeyguardDone();
595 }
596
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +0200597 public boolean shouldDisableWindowAnimationsForUnlock() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500598 return mStatusBar.isInLaunchTransition();
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +0200599 }
600
601 public boolean isGoingToNotificationShade() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500602 return mStatusBar.isGoingToNotificationShade();
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +0200603 }
Adrian Roos31b844b2014-11-21 13:55:09 +0100604
605 public boolean isSecure(int userId) {
606 return mBouncer.isSecure() || mLockPatternUtils.isSecure(userId);
607 }
Jim Millerab954542014-10-10 18:21:49 -0700608
Jorim Jaggi33ae80e2015-02-04 16:37:11 +0100609 public void keyguardGoingAway() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500610 mStatusBar.keyguardGoingAway();
Jorim Jaggi33ae80e2015-02-04 16:37:11 +0100611 }
Jim Miller25d7e512015-03-03 17:12:09 -0800612
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700613 public void animateCollapsePanels(float speedUpFactor) {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500614 mStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE, true /* force */,
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700615 false /* delayed */, speedUpFactor);
Jim Miller25d7e512015-03-03 17:12:09 -0800616 }
Jorim Jaggi5cc86592015-06-08 14:48:28 -0700617
618 /**
619 * Notifies that the user has authenticated by other means than using the bouncer, for example,
620 * fingerprint.
621 */
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700622 public void notifyKeyguardAuthenticated(boolean strongAuth) {
623 mBouncer.notifyKeyguardAuthenticated(strongAuth);
Jorim Jaggi5cc86592015-06-08 14:48:28 -0700624 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700625
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700626 public void showBouncerMessage(String message, int color) {
627 mBouncer.showMessage(message, color);
628 }
Jorim Jaggib774e552015-08-24 14:52:45 -0700629
630 public ViewRootImpl getViewRootImpl() {
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500631 return mStatusBar.getStatusBarView().getViewRootImpl();
Jorim Jaggib774e552015-08-24 14:52:45 -0700632 }
Adrian Roosfee661c2017-08-04 17:05:45 +0200633
Adrian Roos34e65402017-08-07 19:32:45 +0200634 public void launchPendingWakeupAction() {
635 DismissWithActionRequest request = mPendingWakeupAction;
636 mPendingWakeupAction = null;
Adrian Roosfee661c2017-08-04 17:05:45 +0200637 if (request != null) {
638 if (mShowing) {
639 dismissWithAction(request.dismissAction, request.cancelAction,
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800640 request.afterKeyguardGone, request.message);
Adrian Roosfee661c2017-08-04 17:05:45 +0200641 } else if (request.dismissAction != null) {
642 request.dismissAction.onDismiss();
643 }
644 }
645 }
646
Adrian Roos34e65402017-08-07 19:32:45 +0200647 public void cancelPendingWakeupAction() {
648 DismissWithActionRequest request = mPendingWakeupAction;
649 mPendingWakeupAction = null;
Adrian Roosfee661c2017-08-04 17:05:45 +0200650 if (request != null && request.cancelAction != null) {
651 request.cancelAction.run();
652 }
653 }
654
Adrian Roos34e65402017-08-07 19:32:45 +0200655 private static class DismissWithActionRequest {
Adrian Roosfee661c2017-08-04 17:05:45 +0200656 final OnDismissAction dismissAction;
657 final Runnable cancelAction;
658 final boolean afterKeyguardGone;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800659 final String message;
Adrian Roosfee661c2017-08-04 17:05:45 +0200660
Adrian Roos34e65402017-08-07 19:32:45 +0200661 DismissWithActionRequest(OnDismissAction dismissAction, Runnable cancelAction,
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800662 boolean afterKeyguardGone, String message) {
Adrian Roosfee661c2017-08-04 17:05:45 +0200663 this.dismissAction = dismissAction;
664 this.cancelAction = cancelAction;
665 this.afterKeyguardGone = afterKeyguardGone;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800666 this.message = message;
Adrian Roosfee661c2017-08-04 17:05:45 +0200667 }
668 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100669}