blob: 2162ea70fe84f6215d949d3b8578f8e52c4129ca [file] [log] [blame]
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07001/*
2 * Copyright (C) 2015 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
19import android.content.Context;
Gus Prevasab336792018-11-14 13:52:20 -050020import android.hardware.biometrics.BiometricSourceType;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070021import android.os.Handler;
22import android.os.PowerManager;
23import android.os.SystemClock;
Nick Desaulniers1d396752016-07-25 15:05:33 -070024import android.os.Trace;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070025import android.util.Log;
26
Gus Prevasab336792018-11-14 13:52:20 -050027import com.android.internal.util.LatencyTracker;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070028import com.android.keyguard.KeyguardConstants;
29import com.android.keyguard.KeyguardUpdateMonitor;
30import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jason Monk421a9412017-02-06 09:15:21 -080031import com.android.systemui.Dependency;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070032import com.android.systemui.keyguard.KeyguardViewMediator;
Adrian Roos7a5e4c92017-07-31 16:40:19 +020033import com.android.systemui.keyguard.ScreenLifecycle;
Adrian Roos58ba6852017-07-18 17:10:29 +020034import com.android.systemui.keyguard.WakefulnessLifecycle;
Jason Monk297c04e2018-08-23 17:16:59 -040035import com.android.systemui.statusbar.NotificationMediaManager;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070036
Adrian Roosba7ca592017-08-15 17:48:05 +020037import java.io.PrintWriter;
38
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070039/**
Gilad Brettercb51b8b2018-03-22 17:04:51 +020040 * Controller which coordinates all the biometric unlocking actions with the UI.
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070041 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +020042public class BiometricUnlockController extends KeyguardUpdateMonitorCallback {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070043
Gilad Brettercb51b8b2018-03-22 17:04:51 +020044 private static final String TAG = "BiometricUnlockController";
45 private static final boolean DEBUG_BIO_WAKELOCK = KeyguardConstants.DEBUG_BIOMETRIC_WAKELOCK;
46 private static final long BIOMETRIC_WAKELOCK_TIMEOUT_MS = 15 * 1000;
47 private static final String BIOMETRIC_WAKE_LOCK_NAME = "wake-and-unlock wakelock";
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070048
49 /**
Lucas Dupin3d053532019-01-29 12:35:22 -080050 * Mode in which we don't need to wake up the device when we authenticate.
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070051 */
52 public static final int MODE_NONE = 0;
53
54 /**
55 * Mode in which we wake up the device, and directly dismiss Keyguard. Active when we acquire
56 * a fingerprint while the screen is off and the device was sleeping.
57 */
58 public static final int MODE_WAKE_AND_UNLOCK = 1;
59
60 /**
61 * Mode in which we wake the device up, and fade out the Keyguard contents because they were
62 * already visible while pulsing in doze mode.
63 */
64 public static final int MODE_WAKE_AND_UNLOCK_PULSING = 2;
65
66 /**
67 * Mode in which we wake up the device, but play the normal dismiss animation. Active when we
68 * acquire a fingerprint pulsing in doze mode.
69 */
70 public static final int MODE_SHOW_BOUNCER = 3;
71
72 /**
Lucas Dupin3d053532019-01-29 12:35:22 -080073 * Mode in which we only wake up the device, and keyguard was not showing when we authenticated.
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070074 * */
75 public static final int MODE_ONLY_WAKE = 4;
76
77 /**
78 * Mode in which fingerprint unlocks the device.
79 */
80 public static final int MODE_UNLOCK = 5;
81
82 /**
83 * Mode in which fingerprint brings up the bouncer because fingerprint unlocking is currently
84 * not allowed.
85 */
86 public static final int MODE_DISMISS_BOUNCER = 6;
87
88 /**
Kevin Chyn36778ff2017-09-07 19:55:38 -070089 * Mode in which fingerprint wakes and unlocks the device from a dream.
90 */
91 public static final int MODE_WAKE_AND_UNLOCK_FROM_DREAM = 7;
92
93 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +020094 * How much faster we collapse the lockscreen when authenticating with biometric.
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070095 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +020096 private static final float BIOMETRIC_COLLAPSE_SPEEDUP_FACTOR = 1.1f;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070097
Lucas Dupin3d053532019-01-29 12:35:22 -080098 private final NotificationMediaManager mMediaManager;
99 private final PowerManager mPowerManager;
100 private final Handler mHandler;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700101 private PowerManager.WakeLock mWakeLock;
Lucas Dupin3d053532019-01-29 12:35:22 -0800102 private final KeyguardUpdateMonitor mUpdateMonitor;
103 private final UnlockMethodCache mUnlockMethodCache;
104 private final StatusBarWindowController mStatusBarWindowController;
105 private final Context mContext;
106 private final int mWakeUpDelay;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700107 private int mMode;
108 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700109 private DozeScrimController mDozeScrimController;
110 private KeyguardViewMediator mKeyguardViewMediator;
111 private ScrimController mScrimController;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500112 private StatusBar mStatusBar;
Jorim Jaggi95e40382015-09-16 15:53:42 -0700113 private int mPendingAuthenticatedUserId = -1;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200114 private BiometricSourceType mPendingAuthenticatedBioSourceType = null;
Adrian Roos58ba6852017-07-18 17:10:29 +0200115 private boolean mPendingShowBouncer;
Adrian Roos7a5e4c92017-07-31 16:40:19 +0200116 private boolean mHasScreenTurnedOnSinceAuthenticating;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700117
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200118 public BiometricUnlockController(Context context,
119 DozeScrimController dozeScrimController,
120 KeyguardViewMediator keyguardViewMediator,
121 ScrimController scrimController,
122 StatusBar statusBar,
Lucas Dupin3d053532019-01-29 12:35:22 -0800123 UnlockMethodCache unlockMethodCache, Handler handler,
124 KeyguardUpdateMonitor keyguardUpdateMonitor,
125 int wakeUpDelay) {
Jorim Jaggi8adb30c2016-09-13 15:02:22 -0700126 mContext = context;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700127 mPowerManager = context.getSystemService(PowerManager.class);
Lucas Dupin3d053532019-01-29 12:35:22 -0800128 mUpdateMonitor = keyguardUpdateMonitor;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700129 mUpdateMonitor.registerCallback(this);
Lucas Dupin3d053532019-01-29 12:35:22 -0800130 mMediaManager = Dependency.get(NotificationMediaManager.class);
Adrian Roos58ba6852017-07-18 17:10:29 +0200131 Dependency.get(WakefulnessLifecycle.class).addObserver(mWakefulnessObserver);
Adrian Roos7a5e4c92017-07-31 16:40:19 +0200132 Dependency.get(ScreenLifecycle.class).addObserver(mScreenObserver);
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700133 mStatusBarWindowController = Dependency.get(StatusBarWindowController.class);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700134 mDozeScrimController = dozeScrimController;
135 mKeyguardViewMediator = keyguardViewMediator;
136 mScrimController = scrimController;
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500137 mStatusBar = statusBar;
Jorim Jaggi8adb30c2016-09-13 15:02:22 -0700138 mUnlockMethodCache = unlockMethodCache;
Lucas Dupin3d053532019-01-29 12:35:22 -0800139 mHandler = handler;
140 mWakeUpDelay = wakeUpDelay;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700141 }
142
143 public void setStatusBarKeyguardViewManager(
144 StatusBarKeyguardViewManager statusBarKeyguardViewManager) {
145 mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
146 }
147
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200148 private final Runnable mReleaseBiometricWakeLockRunnable = new Runnable() {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700149 @Override
150 public void run() {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200151 if (DEBUG_BIO_WAKELOCK) {
152 Log.i(TAG, "biometric wakelock: TIMEOUT!!");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700153 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200154 releaseBiometricWakeLock();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700155 }
156 };
157
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200158 private void releaseBiometricWakeLock() {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700159 if (mWakeLock != null) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200160 mHandler.removeCallbacks(mReleaseBiometricWakeLockRunnable);
161 if (DEBUG_BIO_WAKELOCK) {
162 Log.i(TAG, "releasing biometric wakelock");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700163 }
164 mWakeLock.release();
165 mWakeLock = null;
166 }
167 }
168
169 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200170 public void onBiometricAcquired(BiometricSourceType biometricSourceType) {
171 Trace.beginSection("BiometricUnlockController#onBiometricAcquired");
172 releaseBiometricWakeLock();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700173 if (!mUpdateMonitor.isDeviceInteractive()) {
Jorim Jaggi8adb30c2016-09-13 15:02:22 -0700174 if (LatencyTracker.isEnabled(mContext)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200175 int action = LatencyTracker.ACTION_FINGERPRINT_WAKE_AND_UNLOCK;
176 if (biometricSourceType == BiometricSourceType.FACE) {
177 action = LatencyTracker.ACTION_FACE_WAKE_AND_UNLOCK;
178 }
179 LatencyTracker.getInstance(mContext).onActionStart(action);
Jorim Jaggi8adb30c2016-09-13 15:02:22 -0700180 }
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700181 mWakeLock = mPowerManager.newWakeLock(
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200182 PowerManager.PARTIAL_WAKE_LOCK, BIOMETRIC_WAKE_LOCK_NAME);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700183 Trace.beginSection("acquiring wake-and-unlock");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700184 mWakeLock.acquire();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700185 Trace.endSection();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200186 if (DEBUG_BIO_WAKELOCK) {
187 Log.i(TAG, "biometric acquired, grabbing biometric wakelock");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700188 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200189 mHandler.postDelayed(mReleaseBiometricWakeLockRunnable,
190 BIOMETRIC_WAKELOCK_TIMEOUT_MS);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700191 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700192 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700193 }
194
Adrian Roos3e23eb52017-07-07 15:58:57 +0200195 private boolean pulsingOrAod() {
Lucas Dupin9e3fa102017-11-08 17:16:55 -0800196 final ScrimState scrimState = mScrimController.getState();
197 return scrimState == ScrimState.AOD
198 || scrimState == ScrimState.PULSING;
Adrian Roos3e23eb52017-07-07 15:58:57 +0200199 }
200
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700201 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200202 public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType) {
203 Trace.beginSection("BiometricUnlockController#onBiometricAuthenticated");
Jorim Jaggi95e40382015-09-16 15:53:42 -0700204 if (mUpdateMonitor.isGoingToSleep()) {
205 mPendingAuthenticatedUserId = userId;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200206 mPendingAuthenticatedBioSourceType = biometricSourceType;
Nick Desaulniers1d396752016-07-25 15:05:33 -0700207 Trace.endSection();
Jorim Jaggi95e40382015-09-16 15:53:42 -0700208 return;
209 }
Lucas Dupin3d053532019-01-29 12:35:22 -0800210 startWakeAndUnlock(calculateMode(biometricSourceType));
Adrian Roos6d5ebb72017-08-03 15:10:22 +0200211 }
212
213 public void startWakeAndUnlock(int mode) {
Kevin Chyn0b508b42017-09-11 17:34:33 -0700214 // TODO(b/62444020): remove when this bug is fixed
215 Log.v(TAG, "startWakeAndUnlock(" + mode + ")");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700216 boolean wasDeviceInteractive = mUpdateMonitor.isDeviceInteractive();
Adrian Roos6d5ebb72017-08-03 15:10:22 +0200217 mMode = mode;
Adrian Roos7a5e4c92017-07-31 16:40:19 +0200218 mHasScreenTurnedOnSinceAuthenticating = false;
Adrian Roosb880afe72017-07-25 17:02:46 +0200219 if (mMode == MODE_WAKE_AND_UNLOCK_PULSING && pulsingOrAod()) {
220 // If we are waking the device up while we are pulsing the clock and the
221 // notifications would light up first, creating an unpleasant animation.
222 // Defer changing the screen brightness by forcing doze brightness on our window
223 // until the clock and the notifications are faded out.
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700224 mStatusBarWindowController.setForceDozeBrightness(true);
Adrian Roosb880afe72017-07-25 17:02:46 +0200225 }
Lucas Dupine63abf72018-07-02 11:17:14 -0700226 // During wake and unlock, we need to draw black before waking up to avoid abrupt
227 // brightness changes due to display state transitions.
228 boolean alwaysOnEnabled = DozeParameters.getInstance(mContext).getAlwaysOn();
Lucas Dupin2920eea2018-08-29 13:13:40 -0700229 boolean delayWakeUp = mode == MODE_WAKE_AND_UNLOCK && alwaysOnEnabled && mWakeUpDelay > 0;
Lucas Dupine63abf72018-07-02 11:17:14 -0700230 Runnable wakeUp = ()-> {
231 if (!wasDeviceInteractive) {
232 if (DEBUG_BIO_WAKELOCK) {
233 Log.i(TAG, "bio wakelock: Authenticated, waking up...");
234 }
Michael Wrighte3001042019-02-05 00:13:14 +0000235 mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
236 "android.policy:BIOMETRIC");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700237 }
Lucas Dupine63abf72018-07-02 11:17:14 -0700238 if (delayWakeUp) {
239 mKeyguardViewMediator.onWakeAndUnlocking();
240 }
241 Trace.beginSection("release wake-and-unlock");
242 releaseBiometricWakeLock();
243 Trace.endSection();
244 };
245
246 if (!delayWakeUp) {
247 wakeUp.run();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700248 }
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700249 switch (mMode) {
250 case MODE_DISMISS_BOUNCER:
Nick Desaulniers1d396752016-07-25 15:05:33 -0700251 Trace.beginSection("MODE_DISMISS");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700252 mStatusBarKeyguardViewManager.notifyKeyguardAuthenticated(
253 false /* strongAuth */);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700254 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700255 break;
256 case MODE_UNLOCK:
257 case MODE_SHOW_BOUNCER:
Nick Desaulniers1d396752016-07-25 15:05:33 -0700258 Trace.beginSection("MODE_UNLOCK or MODE_SHOW_BOUNCER");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700259 if (!wasDeviceInteractive) {
260 mStatusBarKeyguardViewManager.notifyDeviceWakeUpRequested();
Adrian Roos58ba6852017-07-18 17:10:29 +0200261 mPendingShowBouncer = true;
262 } else {
263 showBouncer();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700264 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700265 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700266 break;
Kevin Chyn36778ff2017-09-07 19:55:38 -0700267 case MODE_WAKE_AND_UNLOCK_FROM_DREAM:
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700268 case MODE_WAKE_AND_UNLOCK_PULSING:
Jorim Jaggid94d3a22015-08-21 16:52:55 -0700269 case MODE_WAKE_AND_UNLOCK:
Adrian Roos88e61aa2017-05-23 16:16:50 -0700270 if (mMode == MODE_WAKE_AND_UNLOCK_PULSING) {
271 Trace.beginSection("MODE_WAKE_AND_UNLOCK_PULSING");
Jason Monk297c04e2018-08-23 17:16:59 -0400272 mMediaManager.updateMediaMetaData(false /* metaDataChanged */,
Adrian Roos88e61aa2017-05-23 16:16:50 -0700273 true /* allowEnterAnimation */);
Kevin Chyn36778ff2017-09-07 19:55:38 -0700274 } else if (mMode == MODE_WAKE_AND_UNLOCK){
Adrian Roos88e61aa2017-05-23 16:16:50 -0700275 Trace.beginSection("MODE_WAKE_AND_UNLOCK");
Kevin Chyn36778ff2017-09-07 19:55:38 -0700276 } else {
277 Trace.beginSection("MODE_WAKE_AND_UNLOCK_FROM_DREAM");
278 mUpdateMonitor.awakenFromDream();
Adrian Roos88e61aa2017-05-23 16:16:50 -0700279 }
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700280 mStatusBarWindowController.setStatusBarFocusable(false);
Lucas Dupine63abf72018-07-02 11:17:14 -0700281 if (delayWakeUp) {
Lucas Dupin2920eea2018-08-29 13:13:40 -0700282 mHandler.postDelayed(wakeUp, mWakeUpDelay);
Lucas Dupine63abf72018-07-02 11:17:14 -0700283 } else {
284 mKeyguardViewMediator.onWakeAndUnlocking();
285 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500286 if (mStatusBar.getNavigationBarView() != null) {
287 mStatusBar.getNavigationBarView().setWakeAndUnlocking(true);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700288 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700289 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700290 break;
291 case MODE_ONLY_WAKE:
292 case MODE_NONE:
293 break;
294 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200295 mStatusBar.notifyBiometricAuthModeChanged();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700296 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700297 }
298
Adrian Roos58ba6852017-07-18 17:10:29 +0200299 private void showBouncer() {
Lucas Dupin3d053532019-01-29 12:35:22 -0800300 if (mMode == MODE_SHOW_BOUNCER) {
felkachangefebbc2f72018-05-14 12:22:40 +0800301 mStatusBarKeyguardViewManager.showBouncer(false);
302 }
Adrian Roos58ba6852017-07-18 17:10:29 +0200303 mStatusBarKeyguardViewManager.animateCollapsePanels(
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200304 BIOMETRIC_COLLAPSE_SPEEDUP_FACTOR);
Adrian Roos58ba6852017-07-18 17:10:29 +0200305 mPendingShowBouncer = false;
306 }
307
Jorim Jaggi95e40382015-09-16 15:53:42 -0700308 @Override
309 public void onStartedGoingToSleep(int why) {
Adrian Roosba7ca592017-08-15 17:48:05 +0200310 resetMode();
Jorim Jaggi95e40382015-09-16 15:53:42 -0700311 mPendingAuthenticatedUserId = -1;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200312 mPendingAuthenticatedBioSourceType = null;
Jorim Jaggi95e40382015-09-16 15:53:42 -0700313 }
314
315 @Override
316 public void onFinishedGoingToSleep(int why) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200317 Trace.beginSection("BiometricUnlockController#onFinishedGoingToSleep");
Jorim Jaggi95e40382015-09-16 15:53:42 -0700318 if (mPendingAuthenticatedUserId != -1) {
319
320 // Post this to make sure it's executed after the device is fully locked.
321 mHandler.post(new Runnable() {
322 @Override
323 public void run() {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200324 onBiometricAuthenticated(mPendingAuthenticatedUserId,
325 mPendingAuthenticatedBioSourceType);
Jorim Jaggi95e40382015-09-16 15:53:42 -0700326 }
327 });
328 }
329 mPendingAuthenticatedUserId = -1;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200330 mPendingAuthenticatedBioSourceType = null;
Nick Desaulniers1d396752016-07-25 15:05:33 -0700331 Trace.endSection();
Jorim Jaggi95e40382015-09-16 15:53:42 -0700332 }
333
Adrian Roos710a0b12017-07-07 19:02:34 +0200334 public boolean hasPendingAuthentication() {
335 return mPendingAuthenticatedUserId != -1
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200336 && mUpdateMonitor.isUnlockingWithBiometricAllowed()
Adrian Roos710a0b12017-07-07 19:02:34 +0200337 && mPendingAuthenticatedUserId == KeyguardUpdateMonitor.getCurrentUser();
338 }
339
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700340 public int getMode() {
341 return mMode;
342 }
343
Lucas Dupin3d053532019-01-29 12:35:22 -0800344 private int calculateMode(BiometricSourceType biometricSourceType) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200345 boolean unlockingAllowed = mUpdateMonitor.isUnlockingWithBiometricAllowed();
Kevin Chyn36778ff2017-09-07 19:55:38 -0700346 boolean deviceDreaming = mUpdateMonitor.isDreaming();
Lucas Dupin3d053532019-01-29 12:35:22 -0800347 boolean isFace = biometricSourceType == BiometricSourceType.FACE;
Adrian Roos02626662017-07-06 18:22:17 +0200348
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700349 if (!mUpdateMonitor.isDeviceInteractive()) {
350 if (!mStatusBarKeyguardViewManager.isShowing()) {
351 return MODE_ONLY_WAKE;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200352 } else if (mDozeScrimController.isPulsing() && unlockingAllowed) {
Lucas Dupin3d053532019-01-29 12:35:22 -0800353 return isFace ? MODE_NONE : MODE_WAKE_AND_UNLOCK_PULSING;
Jorim Jaggi8adb30c2016-09-13 15:02:22 -0700354 } else if (unlockingAllowed || !mUnlockMethodCache.isMethodSecure()) {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700355 return MODE_WAKE_AND_UNLOCK;
356 } else {
357 return MODE_SHOW_BOUNCER;
358 }
359 }
Lucas Dupin3d053532019-01-29 12:35:22 -0800360 if (unlockingAllowed && deviceDreaming && !isFace) {
Kevin Chyn36778ff2017-09-07 19:55:38 -0700361 return MODE_WAKE_AND_UNLOCK_FROM_DREAM;
362 }
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700363 if (mStatusBarKeyguardViewManager.isShowing()) {
364 if (mStatusBarKeyguardViewManager.isBouncerShowing() && unlockingAllowed) {
365 return MODE_DISMISS_BOUNCER;
366 } else if (unlockingAllowed) {
Lucas Dupin3d053532019-01-29 12:35:22 -0800367 return isFace ? MODE_ONLY_WAKE : MODE_UNLOCK;
Jorim Jaggibf04cf52015-09-02 11:53:02 -0700368 } else if (!mStatusBarKeyguardViewManager.isBouncerShowing()) {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700369 return MODE_SHOW_BOUNCER;
370 }
371 }
372 return MODE_NONE;
373 }
374
375 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200376 public void onBiometricAuthFailed(BiometricSourceType biometricSourceType) {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700377 cleanup();
378 }
379
380 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200381 public void onBiometricError(int msgId, String errString,
382 BiometricSourceType biometricSourceType) {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700383 cleanup();
384 }
385
386 private void cleanup() {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200387 releaseBiometricWakeLock();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700388 }
389
390 public void startKeyguardFadingAway() {
391
392 // Disable brightness override when the ambient contents are fully invisible.
393 mHandler.postDelayed(new Runnable() {
394 @Override
395 public void run() {
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700396 mStatusBarWindowController.setForceDozeBrightness(false);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700397 }
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500398 }, StatusBar.FADE_KEYGUARD_DURATION_PULSING);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700399 }
400
401 public void finishKeyguardFadingAway() {
Adrian Roosba7ca592017-08-15 17:48:05 +0200402 resetMode();
403 }
404
405 private void resetMode() {
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700406 mMode = MODE_NONE;
Lucas Dupin1a8588d2018-08-21 12:18:47 -0700407 mStatusBarWindowController.setForceDozeBrightness(false);
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500408 if (mStatusBar.getNavigationBarView() != null) {
409 mStatusBar.getNavigationBarView().setWakeAndUnlocking(false);
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700410 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200411 mStatusBar.notifyBiometricAuthModeChanged();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700412 }
Adrian Roos58ba6852017-07-18 17:10:29 +0200413
414 private final WakefulnessLifecycle.Observer mWakefulnessObserver =
415 new WakefulnessLifecycle.Observer() {
416 @Override
417 public void onFinishedWakingUp() {
418 if (mPendingShowBouncer) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200419 BiometricUnlockController.this.showBouncer();
Adrian Roos58ba6852017-07-18 17:10:29 +0200420 }
421 }
422 };
Adrian Roos7a5e4c92017-07-31 16:40:19 +0200423
424 private final ScreenLifecycle.Observer mScreenObserver =
425 new ScreenLifecycle.Observer() {
426 @Override
427 public void onScreenTurnedOn() {
428 mHasScreenTurnedOnSinceAuthenticating = true;
429 }
430 };
431
432 public boolean hasScreenTurnedOnSinceAuthenticating() {
433 return mHasScreenTurnedOnSinceAuthenticating;
434 }
Adrian Roosba7ca592017-08-15 17:48:05 +0200435
436 public void dump(PrintWriter pw) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200437 pw.println(" BiometricUnlockController:");
Adrian Roosba7ca592017-08-15 17:48:05 +0200438 pw.print(" mMode="); pw.println(mMode);
439 pw.print(" mWakeLock="); pw.println(mWakeLock);
440 }
Lucas Dupin067136c2018-03-27 18:03:25 -0700441
Lucas Dupin52c21c82018-06-04 19:03:20 -0700442 /**
Lucas Dupin3d053532019-01-29 12:35:22 -0800443 * Successful authentication with fingerprint, face, or iris that wakes up the device.
Lucas Dupin52c21c82018-06-04 19:03:20 -0700444 */
Lucas Dupin067136c2018-03-27 18:03:25 -0700445 public boolean isWakeAndUnlock() {
Lucas Dupin52c21c82018-06-04 19:03:20 -0700446 return mMode == MODE_WAKE_AND_UNLOCK
Lucas Dupin067136c2018-03-27 18:03:25 -0700447 || mMode == MODE_WAKE_AND_UNLOCK_PULSING
448 || mMode == MODE_WAKE_AND_UNLOCK_FROM_DREAM;
449 }
Lucas Dupin52c21c82018-06-04 19:03:20 -0700450
451 /**
Lucas Dupin3d053532019-01-29 12:35:22 -0800452 * Successful authentication with fingerprint, face, or iris when the screen was either
453 * on or off.
Lucas Dupin52c21c82018-06-04 19:03:20 -0700454 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200455 public boolean isBiometricUnlock() {
Lucas Dupin52c21c82018-06-04 19:03:20 -0700456 return isWakeAndUnlock() || mMode == MODE_UNLOCK;
457 }
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -0700458}