Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 21 | import android.hardware.biometrics.BiometricSourceType; |
Steven Wu | e442acf | 2019-03-14 13:31:12 -0400 | [diff] [blame] | 22 | import android.metrics.LogMaker; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 23 | import android.os.Handler; |
| 24 | import android.os.PowerManager; |
| 25 | import android.os.SystemClock; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 26 | import android.os.Trace; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 29 | import com.android.internal.annotations.VisibleForTesting; |
Steven Wu | e442acf | 2019-03-14 13:31:12 -0400 | [diff] [blame] | 30 | import com.android.internal.logging.MetricsLogger; |
| 31 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 32 | import com.android.internal.util.LatencyTracker; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 33 | import com.android.keyguard.KeyguardConstants; |
| 34 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 35 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 36 | import com.android.systemui.Dependency; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 37 | import com.android.systemui.keyguard.KeyguardViewMediator; |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 38 | import com.android.systemui.keyguard.ScreenLifecycle; |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 39 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 40 | import com.android.systemui.statusbar.NotificationMediaManager; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 41 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 42 | |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 43 | import java.io.PrintWriter; |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 44 | import java.lang.annotation.Retention; |
| 45 | import java.lang.annotation.RetentionPolicy; |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 46 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 47 | /** |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 48 | * Controller which coordinates all the biometric unlocking actions with the UI. |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 49 | */ |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 50 | public class BiometricUnlockController extends KeyguardUpdateMonitorCallback { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 51 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 52 | private static final String TAG = "BiometricUnlockController"; |
| 53 | private static final boolean DEBUG_BIO_WAKELOCK = KeyguardConstants.DEBUG_BIOMETRIC_WAKELOCK; |
| 54 | private static final long BIOMETRIC_WAKELOCK_TIMEOUT_MS = 15 * 1000; |
| 55 | private static final String BIOMETRIC_WAKE_LOCK_NAME = "wake-and-unlock wakelock"; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 56 | |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 57 | @IntDef(prefix = { "MODE_" }, value = { |
| 58 | MODE_NONE, |
| 59 | MODE_WAKE_AND_UNLOCK, |
| 60 | MODE_WAKE_AND_UNLOCK_PULSING, |
| 61 | MODE_SHOW_BOUNCER, |
| 62 | MODE_ONLY_WAKE, |
| 63 | MODE_UNLOCK_COLLAPSING, |
| 64 | MODE_UNLOCK_FADING, |
| 65 | MODE_DISMISS_BOUNCER, |
| 66 | MODE_WAKE_AND_UNLOCK_FROM_DREAM |
| 67 | }) |
| 68 | @Retention(RetentionPolicy.SOURCE) |
| 69 | public @interface WakeAndUnlockMode {} |
| 70 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 71 | /** |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 72 | * Mode in which we don't need to wake up the device when we authenticate. |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 73 | */ |
| 74 | public static final int MODE_NONE = 0; |
| 75 | |
| 76 | /** |
| 77 | * Mode in which we wake up the device, and directly dismiss Keyguard. Active when we acquire |
| 78 | * a fingerprint while the screen is off and the device was sleeping. |
| 79 | */ |
| 80 | public static final int MODE_WAKE_AND_UNLOCK = 1; |
| 81 | |
| 82 | /** |
| 83 | * Mode in which we wake the device up, and fade out the Keyguard contents because they were |
| 84 | * already visible while pulsing in doze mode. |
| 85 | */ |
| 86 | public static final int MODE_WAKE_AND_UNLOCK_PULSING = 2; |
| 87 | |
| 88 | /** |
| 89 | * Mode in which we wake up the device, but play the normal dismiss animation. Active when we |
| 90 | * acquire a fingerprint pulsing in doze mode. |
| 91 | */ |
| 92 | public static final int MODE_SHOW_BOUNCER = 3; |
| 93 | |
| 94 | /** |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 95 | * Mode in which we only wake up the device, and keyguard was not showing when we authenticated. |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 96 | * */ |
| 97 | public static final int MODE_ONLY_WAKE = 4; |
| 98 | |
| 99 | /** |
| 100 | * Mode in which fingerprint unlocks the device. |
| 101 | */ |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 102 | public static final int MODE_UNLOCK_COLLAPSING = 5; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 105 | * Mode in which fingerprint wakes and unlocks the device from a dream. |
| 106 | */ |
Lucas Dupin | e78794c | 2019-06-18 11:55:37 -0700 | [diff] [blame] | 107 | public static final int MODE_WAKE_AND_UNLOCK_FROM_DREAM = 6; |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 110 | * Faster mode of dismissing the lock screen when we cross fade to an app |
| 111 | * (used for keyguard bypass.) |
| 112 | */ |
| 113 | public static final int MODE_UNLOCK_FADING = 7; |
| 114 | |
| 115 | /** |
| 116 | * When bouncer is visible and will be dismissed. |
| 117 | */ |
| 118 | public static final int MODE_DISMISS_BOUNCER = 8; |
| 119 | |
| 120 | /** |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 121 | * How much faster we collapse the lockscreen when authenticating with biometric. |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 122 | */ |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 123 | private static final float BIOMETRIC_COLLAPSE_SPEEDUP_FACTOR = 1.1f; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 124 | |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 125 | private final NotificationMediaManager mMediaManager; |
| 126 | private final PowerManager mPowerManager; |
| 127 | private final Handler mHandler; |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 128 | private final KeyguardBypassController mKeyguardBypassController; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 129 | private PowerManager.WakeLock mWakeLock; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 130 | private final KeyguardUpdateMonitor mUpdateMonitor; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 131 | private final KeyguardStateController mKeyguardStateController; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 132 | private final StatusBarWindowController mStatusBarWindowController; |
| 133 | private final Context mContext; |
| 134 | private final int mWakeUpDelay; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 135 | private int mMode; |
| 136 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 137 | private DozeScrimController mDozeScrimController; |
| 138 | private KeyguardViewMediator mKeyguardViewMediator; |
| 139 | private ScrimController mScrimController; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 140 | private StatusBar mStatusBar; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 141 | private int mPendingAuthenticatedUserId = -1; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 142 | private BiometricSourceType mPendingAuthenticatedBioSourceType = null; |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 143 | private boolean mPendingShowBouncer; |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 144 | private boolean mHasScreenTurnedOnSinceAuthenticating; |
Lucas Dupin | bd6c92b | 2019-07-17 09:49:52 -0700 | [diff] [blame] | 145 | private boolean mFadedAwayAfterWakeAndUnlock; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 146 | |
Steven Wu | e442acf | 2019-03-14 13:31:12 -0400 | [diff] [blame] | 147 | private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
| 148 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 149 | public BiometricUnlockController(Context context, |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 150 | DozeScrimController dozeScrimController, |
| 151 | KeyguardViewMediator keyguardViewMediator, |
| 152 | ScrimController scrimController, |
| 153 | StatusBar statusBar, |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 154 | KeyguardStateController keyguardStateController, Handler handler, |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 155 | KeyguardUpdateMonitor keyguardUpdateMonitor, |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 156 | KeyguardBypassController keyguardBypassController) { |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 157 | this(context, dozeScrimController, keyguardViewMediator, scrimController, statusBar, |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 158 | keyguardStateController, handler, keyguardUpdateMonitor, |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 159 | context.getResources() |
| 160 | .getInteger(com.android.internal.R.integer.config_wakeUpDelayDoze), |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 161 | keyguardBypassController); |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | @VisibleForTesting |
| 165 | protected BiometricUnlockController(Context context, |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 166 | DozeScrimController dozeScrimController, KeyguardViewMediator keyguardViewMediator, |
| 167 | ScrimController scrimController, StatusBar statusBar, |
| 168 | KeyguardStateController keyguardStateController, Handler handler, |
| 169 | KeyguardUpdateMonitor keyguardUpdateMonitor, int wakeUpDelay, |
| 170 | KeyguardBypassController keyguardBypassController) { |
Jorim Jaggi | 8adb30c | 2016-09-13 15:02:22 -0700 | [diff] [blame] | 171 | mContext = context; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 172 | mPowerManager = context.getSystemService(PowerManager.class); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 173 | mUpdateMonitor = keyguardUpdateMonitor; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 174 | mUpdateMonitor.registerCallback(this); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 175 | mMediaManager = Dependency.get(NotificationMediaManager.class); |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 176 | Dependency.get(WakefulnessLifecycle.class).addObserver(mWakefulnessObserver); |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 177 | Dependency.get(ScreenLifecycle.class).addObserver(mScreenObserver); |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 178 | mStatusBarWindowController = Dependency.get(StatusBarWindowController.class); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 179 | mDozeScrimController = dozeScrimController; |
| 180 | mKeyguardViewMediator = keyguardViewMediator; |
| 181 | mScrimController = scrimController; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 182 | mStatusBar = statusBar; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 183 | mKeyguardStateController = keyguardStateController; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 184 | mHandler = handler; |
| 185 | mWakeUpDelay = wakeUpDelay; |
Selim Cinek | 2c890ee | 2019-05-20 19:16:43 -0700 | [diff] [blame] | 186 | mKeyguardBypassController = keyguardBypassController; |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 187 | mKeyguardBypassController.setUnlockController(this); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | public void setStatusBarKeyguardViewManager( |
| 191 | StatusBarKeyguardViewManager statusBarKeyguardViewManager) { |
| 192 | mStatusBarKeyguardViewManager = statusBarKeyguardViewManager; |
| 193 | } |
| 194 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 195 | private final Runnable mReleaseBiometricWakeLockRunnable = new Runnable() { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 196 | @Override |
| 197 | public void run() { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 198 | if (DEBUG_BIO_WAKELOCK) { |
| 199 | Log.i(TAG, "biometric wakelock: TIMEOUT!!"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 200 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 201 | releaseBiometricWakeLock(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 202 | } |
| 203 | }; |
| 204 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 205 | private void releaseBiometricWakeLock() { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 206 | if (mWakeLock != null) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 207 | mHandler.removeCallbacks(mReleaseBiometricWakeLockRunnable); |
| 208 | if (DEBUG_BIO_WAKELOCK) { |
| 209 | Log.i(TAG, "releasing biometric wakelock"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 210 | } |
| 211 | mWakeLock.release(); |
| 212 | mWakeLock = null; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 217 | public void onBiometricAcquired(BiometricSourceType biometricSourceType) { |
| 218 | Trace.beginSection("BiometricUnlockController#onBiometricAcquired"); |
| 219 | releaseBiometricWakeLock(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 220 | if (!mUpdateMonitor.isDeviceInteractive()) { |
Jorim Jaggi | 8adb30c | 2016-09-13 15:02:22 -0700 | [diff] [blame] | 221 | if (LatencyTracker.isEnabled(mContext)) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 222 | int action = LatencyTracker.ACTION_FINGERPRINT_WAKE_AND_UNLOCK; |
| 223 | if (biometricSourceType == BiometricSourceType.FACE) { |
| 224 | action = LatencyTracker.ACTION_FACE_WAKE_AND_UNLOCK; |
| 225 | } |
| 226 | LatencyTracker.getInstance(mContext).onActionStart(action); |
Jorim Jaggi | 8adb30c | 2016-09-13 15:02:22 -0700 | [diff] [blame] | 227 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 228 | mWakeLock = mPowerManager.newWakeLock( |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 229 | PowerManager.PARTIAL_WAKE_LOCK, BIOMETRIC_WAKE_LOCK_NAME); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 230 | Trace.beginSection("acquiring wake-and-unlock"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 231 | mWakeLock.acquire(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 232 | Trace.endSection(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 233 | if (DEBUG_BIO_WAKELOCK) { |
| 234 | Log.i(TAG, "biometric acquired, grabbing biometric wakelock"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 235 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 236 | mHandler.postDelayed(mReleaseBiometricWakeLockRunnable, |
| 237 | BIOMETRIC_WAKELOCK_TIMEOUT_MS); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 238 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 239 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Adrian Roos | 3e23eb5 | 2017-07-07 15:58:57 +0200 | [diff] [blame] | 242 | private boolean pulsingOrAod() { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 243 | final ScrimState scrimState = mScrimController.getState(); |
| 244 | return scrimState == ScrimState.AOD |
| 245 | || scrimState == ScrimState.PULSING; |
Adrian Roos | 3e23eb5 | 2017-07-07 15:58:57 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 248 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 249 | public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType) { |
| 250 | Trace.beginSection("BiometricUnlockController#onBiometricAuthenticated"); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 251 | if (mUpdateMonitor.isGoingToSleep()) { |
| 252 | mPendingAuthenticatedUserId = userId; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 253 | mPendingAuthenticatedBioSourceType = biometricSourceType; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 254 | Trace.endSection(); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 255 | return; |
| 256 | } |
Steven Wu | e442acf | 2019-03-14 13:31:12 -0400 | [diff] [blame] | 257 | mMetricsLogger.write(new LogMaker(MetricsEvent.BIOMETRIC_AUTH) |
| 258 | .setType(MetricsEvent.TYPE_SUCCESS).setSubtype(toSubtype(biometricSourceType))); |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 259 | boolean unlockAllowed = mKeyguardBypassController.onBiometricAuthenticated( |
| 260 | biometricSourceType); |
| 261 | if (unlockAllowed) { |
Lucas Dupin | aad9883 | 2019-07-14 13:23:24 +0900 | [diff] [blame] | 262 | mKeyguardViewMediator.userActivity(); |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 263 | startWakeAndUnlock(biometricSourceType); |
Lucas Dupin | 5a5e0bd | 2019-07-11 14:19:11 +0900 | [diff] [blame] | 264 | } else { |
| 265 | Log.d(TAG, "onBiometricAuthenticated aborted by bypass controller"); |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 269 | public void startWakeAndUnlock(BiometricSourceType biometricSourceType) { |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 270 | startWakeAndUnlock(calculateMode(biometricSourceType)); |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 273 | public void startWakeAndUnlock(@WakeAndUnlockMode int mode) { |
Kevin Chyn | 0b508b4 | 2017-09-11 17:34:33 -0700 | [diff] [blame] | 274 | Log.v(TAG, "startWakeAndUnlock(" + mode + ")"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 275 | boolean wasDeviceInteractive = mUpdateMonitor.isDeviceInteractive(); |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 276 | mMode = mode; |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 277 | mHasScreenTurnedOnSinceAuthenticating = false; |
Adrian Roos | b880afe7 | 2017-07-25 17:02:46 +0200 | [diff] [blame] | 278 | if (mMode == MODE_WAKE_AND_UNLOCK_PULSING && pulsingOrAod()) { |
| 279 | // If we are waking the device up while we are pulsing the clock and the |
| 280 | // notifications would light up first, creating an unpleasant animation. |
| 281 | // Defer changing the screen brightness by forcing doze brightness on our window |
| 282 | // until the clock and the notifications are faded out. |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 283 | mStatusBarWindowController.setForceDozeBrightness(true); |
Adrian Roos | b880afe7 | 2017-07-25 17:02:46 +0200 | [diff] [blame] | 284 | } |
Lucas Dupin | e63abf7 | 2018-07-02 11:17:14 -0700 | [diff] [blame] | 285 | // During wake and unlock, we need to draw black before waking up to avoid abrupt |
| 286 | // brightness changes due to display state transitions. |
| 287 | boolean alwaysOnEnabled = DozeParameters.getInstance(mContext).getAlwaysOn(); |
Lucas Dupin | 2920eea | 2018-08-29 13:13:40 -0700 | [diff] [blame] | 288 | boolean delayWakeUp = mode == MODE_WAKE_AND_UNLOCK && alwaysOnEnabled && mWakeUpDelay > 0; |
Lucas Dupin | e63abf7 | 2018-07-02 11:17:14 -0700 | [diff] [blame] | 289 | Runnable wakeUp = ()-> { |
| 290 | if (!wasDeviceInteractive) { |
| 291 | if (DEBUG_BIO_WAKELOCK) { |
| 292 | Log.i(TAG, "bio wakelock: Authenticated, waking up..."); |
| 293 | } |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 294 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE, |
| 295 | "android.policy:BIOMETRIC"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 296 | } |
Lucas Dupin | e63abf7 | 2018-07-02 11:17:14 -0700 | [diff] [blame] | 297 | if (delayWakeUp) { |
| 298 | mKeyguardViewMediator.onWakeAndUnlocking(); |
| 299 | } |
| 300 | Trace.beginSection("release wake-and-unlock"); |
| 301 | releaseBiometricWakeLock(); |
| 302 | Trace.endSection(); |
| 303 | }; |
| 304 | |
Lucas Dupin | 4108a9b | 2019-05-28 20:41:51 -0700 | [diff] [blame] | 305 | if (!delayWakeUp && mMode != MODE_NONE) { |
Lucas Dupin | e63abf7 | 2018-07-02 11:17:14 -0700 | [diff] [blame] | 306 | wakeUp.run(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 307 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 308 | switch (mMode) { |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 309 | case MODE_DISMISS_BOUNCER: |
| 310 | case MODE_UNLOCK_FADING: |
| 311 | Trace.beginSection("MODE_DISMISS_BOUNCER or MODE_UNLOCK_FADING"); |
| 312 | mStatusBarKeyguardViewManager.notifyKeyguardAuthenticated( |
| 313 | false /* strongAuth */); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 314 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 315 | break; |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 316 | case MODE_UNLOCK_COLLAPSING: |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 317 | case MODE_SHOW_BOUNCER: |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 318 | Trace.beginSection("MODE_UNLOCK_COLLAPSING or MODE_SHOW_BOUNCER"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 319 | if (!wasDeviceInteractive) { |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 320 | mPendingShowBouncer = true; |
| 321 | } else { |
| 322 | showBouncer(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 323 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 324 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 325 | break; |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 326 | case MODE_WAKE_AND_UNLOCK_FROM_DREAM: |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 327 | case MODE_WAKE_AND_UNLOCK_PULSING: |
Jorim Jaggi | d94d3a2 | 2015-08-21 16:52:55 -0700 | [diff] [blame] | 328 | case MODE_WAKE_AND_UNLOCK: |
Adrian Roos | 88e61aa | 2017-05-23 16:16:50 -0700 | [diff] [blame] | 329 | if (mMode == MODE_WAKE_AND_UNLOCK_PULSING) { |
| 330 | Trace.beginSection("MODE_WAKE_AND_UNLOCK_PULSING"); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 331 | mMediaManager.updateMediaMetaData(false /* metaDataChanged */, |
Adrian Roos | 88e61aa | 2017-05-23 16:16:50 -0700 | [diff] [blame] | 332 | true /* allowEnterAnimation */); |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 333 | } else if (mMode == MODE_WAKE_AND_UNLOCK){ |
Adrian Roos | 88e61aa | 2017-05-23 16:16:50 -0700 | [diff] [blame] | 334 | Trace.beginSection("MODE_WAKE_AND_UNLOCK"); |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 335 | } else { |
| 336 | Trace.beginSection("MODE_WAKE_AND_UNLOCK_FROM_DREAM"); |
| 337 | mUpdateMonitor.awakenFromDream(); |
Adrian Roos | 88e61aa | 2017-05-23 16:16:50 -0700 | [diff] [blame] | 338 | } |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 339 | mStatusBarWindowController.setStatusBarFocusable(false); |
Lucas Dupin | e63abf7 | 2018-07-02 11:17:14 -0700 | [diff] [blame] | 340 | if (delayWakeUp) { |
Lucas Dupin | 2920eea | 2018-08-29 13:13:40 -0700 | [diff] [blame] | 341 | mHandler.postDelayed(wakeUp, mWakeUpDelay); |
Lucas Dupin | e63abf7 | 2018-07-02 11:17:14 -0700 | [diff] [blame] | 342 | } else { |
| 343 | mKeyguardViewMediator.onWakeAndUnlocking(); |
| 344 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 345 | if (mStatusBar.getNavigationBarView() != null) { |
| 346 | mStatusBar.getNavigationBarView().setWakeAndUnlocking(true); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 347 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 348 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 349 | break; |
| 350 | case MODE_ONLY_WAKE: |
| 351 | case MODE_NONE: |
| 352 | break; |
| 353 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 354 | mStatusBar.notifyBiometricAuthModeChanged(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 355 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 358 | private void showBouncer() { |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 359 | if (mMode == MODE_SHOW_BOUNCER) { |
felkachang | efebbc2f7 | 2018-05-14 12:22:40 +0800 | [diff] [blame] | 360 | mStatusBarKeyguardViewManager.showBouncer(false); |
| 361 | } |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 362 | mStatusBarKeyguardViewManager.animateCollapsePanels( |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 363 | BIOMETRIC_COLLAPSE_SPEEDUP_FACTOR); |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 364 | mPendingShowBouncer = false; |
| 365 | } |
| 366 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 367 | @Override |
| 368 | public void onStartedGoingToSleep(int why) { |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 369 | resetMode(); |
Lucas Dupin | bd6c92b | 2019-07-17 09:49:52 -0700 | [diff] [blame] | 370 | mFadedAwayAfterWakeAndUnlock = false; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 371 | mPendingAuthenticatedUserId = -1; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 372 | mPendingAuthenticatedBioSourceType = null; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public void onFinishedGoingToSleep(int why) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 377 | Trace.beginSection("BiometricUnlockController#onFinishedGoingToSleep"); |
Lucas Dupin | 45142ba | 2019-04-10 13:13:20 -0700 | [diff] [blame] | 378 | BiometricSourceType pendingType = mPendingAuthenticatedBioSourceType; |
| 379 | int pendingUserId = mPendingAuthenticatedUserId; |
| 380 | if (pendingUserId != -1 && pendingType != null) { |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 381 | // Post this to make sure it's executed after the device is fully locked. |
Lucas Dupin | 45142ba | 2019-04-10 13:13:20 -0700 | [diff] [blame] | 382 | mHandler.post(() -> onBiometricAuthenticated(pendingUserId, pendingType)); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 383 | } |
| 384 | mPendingAuthenticatedUserId = -1; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 385 | mPendingAuthenticatedBioSourceType = null; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 386 | Trace.endSection(); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Adrian Roos | 710a0b1 | 2017-07-07 19:02:34 +0200 | [diff] [blame] | 389 | public boolean hasPendingAuthentication() { |
| 390 | return mPendingAuthenticatedUserId != -1 |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 391 | && mUpdateMonitor.isUnlockingWithBiometricAllowed() |
Adrian Roos | 710a0b1 | 2017-07-07 19:02:34 +0200 | [diff] [blame] | 392 | && mPendingAuthenticatedUserId == KeyguardUpdateMonitor.getCurrentUser(); |
| 393 | } |
| 394 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 395 | public int getMode() { |
| 396 | return mMode; |
| 397 | } |
| 398 | |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 399 | private @WakeAndUnlockMode int calculateMode(BiometricSourceType biometricSourceType) { |
| 400 | if (biometricSourceType == BiometricSourceType.FACE |
| 401 | || biometricSourceType == BiometricSourceType.IRIS) { |
| 402 | return calculateModeForPassiveAuth(); |
| 403 | } else { |
| 404 | return calculateModeForFingerprint(); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | private @WakeAndUnlockMode int calculateModeForFingerprint() { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 409 | boolean unlockingAllowed = mUpdateMonitor.isUnlockingWithBiometricAllowed(); |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 410 | boolean deviceDreaming = mUpdateMonitor.isDreaming(); |
Adrian Roos | 0262666 | 2017-07-06 18:22:17 +0200 | [diff] [blame] | 411 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 412 | if (!mUpdateMonitor.isDeviceInteractive()) { |
| 413 | if (!mStatusBarKeyguardViewManager.isShowing()) { |
| 414 | return MODE_ONLY_WAKE; |
Adrian Roos | e4cb6c8a | 2017-07-19 18:08:07 +0200 | [diff] [blame] | 415 | } else if (mDozeScrimController.isPulsing() && unlockingAllowed) { |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 416 | return MODE_WAKE_AND_UNLOCK_PULSING; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 417 | } else if (unlockingAllowed || !mKeyguardStateController.isMethodSecure()) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 418 | return MODE_WAKE_AND_UNLOCK; |
| 419 | } else { |
| 420 | return MODE_SHOW_BOUNCER; |
| 421 | } |
| 422 | } |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 423 | if (unlockingAllowed && deviceDreaming) { |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 424 | return MODE_WAKE_AND_UNLOCK_FROM_DREAM; |
| 425 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 426 | if (mStatusBarKeyguardViewManager.isShowing()) { |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 427 | if (mStatusBarKeyguardViewManager.bouncerIsOrWillBeShowing() && unlockingAllowed) { |
| 428 | return MODE_DISMISS_BOUNCER; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 429 | } else if (unlockingAllowed) { |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 430 | return MODE_UNLOCK_COLLAPSING; |
Jorim Jaggi | bf04cf5 | 2015-09-02 11:53:02 -0700 | [diff] [blame] | 431 | } else if (!mStatusBarKeyguardViewManager.isBouncerShowing()) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 432 | return MODE_SHOW_BOUNCER; |
| 433 | } |
| 434 | } |
| 435 | return MODE_NONE; |
| 436 | } |
| 437 | |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 438 | private @WakeAndUnlockMode int calculateModeForPassiveAuth() { |
| 439 | boolean unlockingAllowed = mUpdateMonitor.isUnlockingWithBiometricAllowed(); |
| 440 | boolean deviceDreaming = mUpdateMonitor.isDreaming(); |
| 441 | boolean bypass = mKeyguardBypassController.getBypassEnabled(); |
| 442 | |
| 443 | if (!mUpdateMonitor.isDeviceInteractive()) { |
| 444 | if (!mStatusBarKeyguardViewManager.isShowing()) { |
| 445 | return bypass ? MODE_WAKE_AND_UNLOCK : MODE_ONLY_WAKE; |
Lucas Dupin | 81cdfa4 | 2019-07-25 20:28:28 -0700 | [diff] [blame] | 446 | } else if (!unlockingAllowed) { |
| 447 | return bypass ? MODE_SHOW_BOUNCER : MODE_NONE; |
| 448 | } else if (mDozeScrimController.isPulsing()) { |
Lucas Dupin | d5b19b7 | 2019-09-12 14:00:45 -0700 | [diff] [blame] | 449 | return bypass ? MODE_WAKE_AND_UNLOCK_PULSING : MODE_ONLY_WAKE; |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 450 | } else { |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 451 | if (bypass) { |
| 452 | // Wake-up fading out nicely |
| 453 | return MODE_WAKE_AND_UNLOCK_PULSING; |
| 454 | } else { |
| 455 | // We could theoretically return MODE_NONE, but this means that the device |
| 456 | // would be not interactive, unlocked, and the user would not see the device |
| 457 | // state. |
| 458 | return MODE_ONLY_WAKE; |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | if (unlockingAllowed && deviceDreaming) { |
| 463 | return bypass ? MODE_WAKE_AND_UNLOCK_FROM_DREAM : MODE_ONLY_WAKE; |
| 464 | } |
| 465 | if (mStatusBarKeyguardViewManager.isShowing()) { |
| 466 | if (mStatusBarKeyguardViewManager.bouncerIsOrWillBeShowing() && unlockingAllowed) { |
Lucas Dupin | a055a67 | 2019-07-16 13:46:25 -0700 | [diff] [blame] | 467 | if (bypass && mKeyguardBypassController.canPlaySubtleWindowAnimations()) { |
| 468 | return MODE_UNLOCK_FADING; |
| 469 | } else { |
| 470 | return MODE_DISMISS_BOUNCER; |
| 471 | } |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 472 | } else if (unlockingAllowed) { |
| 473 | return bypass ? MODE_UNLOCK_FADING : MODE_NONE; |
| 474 | } else { |
| 475 | return bypass ? MODE_SHOW_BOUNCER : MODE_NONE; |
| 476 | } |
| 477 | } |
| 478 | return MODE_NONE; |
| 479 | } |
| 480 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 481 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 482 | public void onBiometricAuthFailed(BiometricSourceType biometricSourceType) { |
Steven Wu | e442acf | 2019-03-14 13:31:12 -0400 | [diff] [blame] | 483 | mMetricsLogger.write(new LogMaker(MetricsEvent.BIOMETRIC_AUTH) |
| 484 | .setType(MetricsEvent.TYPE_FAILURE).setSubtype(toSubtype(biometricSourceType))); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 485 | cleanup(); |
| 486 | } |
| 487 | |
| 488 | @Override |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 489 | public void onBiometricError(int msgId, String errString, |
| 490 | BiometricSourceType biometricSourceType) { |
Steven Wu | e442acf | 2019-03-14 13:31:12 -0400 | [diff] [blame] | 491 | mMetricsLogger.write(new LogMaker(MetricsEvent.BIOMETRIC_AUTH) |
Steven Wu | 40cbada | 2019-05-16 10:56:40 -0400 | [diff] [blame] | 492 | .setType(MetricsEvent.TYPE_ERROR).setSubtype(toSubtype(biometricSourceType)) |
| 493 | .addTaggedData(MetricsEvent.FIELD_BIOMETRIC_AUTH_ERROR, msgId)); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 494 | cleanup(); |
| 495 | } |
| 496 | |
| 497 | private void cleanup() { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 498 | releaseBiometricWakeLock(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | public void startKeyguardFadingAway() { |
| 502 | |
| 503 | // Disable brightness override when the ambient contents are fully invisible. |
| 504 | mHandler.postDelayed(new Runnable() { |
| 505 | @Override |
| 506 | public void run() { |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 507 | mStatusBarWindowController.setForceDozeBrightness(false); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 508 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 509 | }, StatusBar.FADE_KEYGUARD_DURATION_PULSING); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | public void finishKeyguardFadingAway() { |
Lucas Dupin | bd6c92b | 2019-07-17 09:49:52 -0700 | [diff] [blame] | 513 | if (isWakeAndUnlock()) { |
| 514 | mFadedAwayAfterWakeAndUnlock = true; |
| 515 | } |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 516 | resetMode(); |
| 517 | } |
| 518 | |
| 519 | private void resetMode() { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 520 | mMode = MODE_NONE; |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 521 | mStatusBarWindowController.setForceDozeBrightness(false); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 522 | if (mStatusBar.getNavigationBarView() != null) { |
| 523 | mStatusBar.getNavigationBarView().setWakeAndUnlocking(false); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 524 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 525 | mStatusBar.notifyBiometricAuthModeChanged(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 526 | } |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 527 | |
Lucas Dupin | 81cdfa4 | 2019-07-25 20:28:28 -0700 | [diff] [blame] | 528 | @VisibleForTesting |
| 529 | final WakefulnessLifecycle.Observer mWakefulnessObserver = |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 530 | new WakefulnessLifecycle.Observer() { |
| 531 | @Override |
| 532 | public void onFinishedWakingUp() { |
| 533 | if (mPendingShowBouncer) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 534 | BiometricUnlockController.this.showBouncer(); |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | }; |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 538 | |
| 539 | private final ScreenLifecycle.Observer mScreenObserver = |
| 540 | new ScreenLifecycle.Observer() { |
| 541 | @Override |
| 542 | public void onScreenTurnedOn() { |
| 543 | mHasScreenTurnedOnSinceAuthenticating = true; |
| 544 | } |
| 545 | }; |
| 546 | |
| 547 | public boolean hasScreenTurnedOnSinceAuthenticating() { |
| 548 | return mHasScreenTurnedOnSinceAuthenticating; |
| 549 | } |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 550 | |
| 551 | public void dump(PrintWriter pw) { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 552 | pw.println(" BiometricUnlockController:"); |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 553 | pw.print(" mMode="); pw.println(mMode); |
| 554 | pw.print(" mWakeLock="); pw.println(mWakeLock); |
| 555 | } |
Lucas Dupin | 067136c | 2018-03-27 18:03:25 -0700 | [diff] [blame] | 556 | |
Lucas Dupin | 52c21c8 | 2018-06-04 19:03:20 -0700 | [diff] [blame] | 557 | /** |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 558 | * Successful authentication with fingerprint, face, or iris that wakes up the device. |
Lucas Dupin | 52c21c8 | 2018-06-04 19:03:20 -0700 | [diff] [blame] | 559 | */ |
Lucas Dupin | 067136c | 2018-03-27 18:03:25 -0700 | [diff] [blame] | 560 | public boolean isWakeAndUnlock() { |
Lucas Dupin | 52c21c8 | 2018-06-04 19:03:20 -0700 | [diff] [blame] | 561 | return mMode == MODE_WAKE_AND_UNLOCK |
Lucas Dupin | 067136c | 2018-03-27 18:03:25 -0700 | [diff] [blame] | 562 | || mMode == MODE_WAKE_AND_UNLOCK_PULSING |
| 563 | || mMode == MODE_WAKE_AND_UNLOCK_FROM_DREAM; |
| 564 | } |
Lucas Dupin | 52c21c8 | 2018-06-04 19:03:20 -0700 | [diff] [blame] | 565 | |
| 566 | /** |
Lucas Dupin | bd6c92b | 2019-07-17 09:49:52 -0700 | [diff] [blame] | 567 | * Successful authentication with fingerprint, face, or iris that wakes up the device. |
| 568 | * This will return {@code true} even after the keyguard fades away. |
| 569 | */ |
| 570 | public boolean unlockedByWakeAndUnlock() { |
| 571 | return isWakeAndUnlock() || mFadedAwayAfterWakeAndUnlock; |
| 572 | } |
| 573 | |
| 574 | /** |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 575 | * Successful authentication with fingerprint, face, or iris when the screen was either |
| 576 | * on or off. |
Lucas Dupin | 52c21c8 | 2018-06-04 19:03:20 -0700 | [diff] [blame] | 577 | */ |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 578 | public boolean isBiometricUnlock() { |
Lucas Dupin | fa817a0 | 2019-07-02 15:22:54 -0700 | [diff] [blame] | 579 | return isWakeAndUnlock() || mMode == MODE_UNLOCK_COLLAPSING || mMode == MODE_UNLOCK_FADING; |
Lucas Dupin | 52c21c8 | 2018-06-04 19:03:20 -0700 | [diff] [blame] | 580 | } |
Steven Wu | e442acf | 2019-03-14 13:31:12 -0400 | [diff] [blame] | 581 | |
| 582 | /** |
Selim Cinek | 84b2acc | 2019-07-07 00:40:38 -0700 | [diff] [blame] | 583 | * Successful authentication with fingerprint, face, or iris when the lockscreen fades away |
| 584 | */ |
| 585 | public boolean isUnlockFading() { |
| 586 | return mMode == MODE_UNLOCK_FADING; |
| 587 | } |
| 588 | |
| 589 | /** |
Steven Wu | e442acf | 2019-03-14 13:31:12 -0400 | [diff] [blame] | 590 | * Translates biometric source type for logging purpose. |
| 591 | */ |
| 592 | private int toSubtype(BiometricSourceType biometricSourceType) { |
| 593 | switch (biometricSourceType) { |
| 594 | case FINGERPRINT: |
| 595 | return 0; |
| 596 | case FACE: |
| 597 | return 1; |
| 598 | case IRIS: |
| 599 | return 2; |
| 600 | default: |
| 601 | return 3; |
| 602 | } |
| 603 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 604 | } |