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 | |
| 19 | import android.content.Context; |
| 20 | import android.os.Handler; |
| 21 | import android.os.PowerManager; |
| 22 | import android.os.SystemClock; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 23 | import android.os.Trace; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 24 | import android.util.Log; |
| 25 | |
| 26 | import com.android.keyguard.KeyguardConstants; |
| 27 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 28 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Jason Monk | 453e7c1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 29 | import com.android.internal.util.LatencyTracker; |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 30 | import com.android.systemui.Dependency; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 31 | import com.android.systemui.keyguard.KeyguardViewMediator; |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 32 | import com.android.systemui.keyguard.ScreenLifecycle; |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 33 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 34 | |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 35 | import java.io.PrintWriter; |
| 36 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Controller which coordinates all the fingerprint unlocking actions with the UI. |
| 39 | */ |
| 40 | public class FingerprintUnlockController extends KeyguardUpdateMonitorCallback { |
| 41 | |
| 42 | private static final String TAG = "FingerprintController"; |
| 43 | private static final boolean DEBUG_FP_WAKELOCK = KeyguardConstants.DEBUG_FP_WAKELOCK; |
| 44 | private static final long FINGERPRINT_WAKELOCK_TIMEOUT_MS = 15 * 1000; |
| 45 | private static final String FINGERPRINT_WAKE_LOCK_NAME = "wake-and-unlock wakelock"; |
| 46 | |
| 47 | /** |
| 48 | * Mode in which we don't need to wake up the device when we get a fingerprint. |
| 49 | */ |
| 50 | public static final int MODE_NONE = 0; |
| 51 | |
| 52 | /** |
| 53 | * Mode in which we wake up the device, and directly dismiss Keyguard. Active when we acquire |
| 54 | * a fingerprint while the screen is off and the device was sleeping. |
| 55 | */ |
| 56 | public static final int MODE_WAKE_AND_UNLOCK = 1; |
| 57 | |
| 58 | /** |
| 59 | * Mode in which we wake the device up, and fade out the Keyguard contents because they were |
| 60 | * already visible while pulsing in doze mode. |
| 61 | */ |
| 62 | public static final int MODE_WAKE_AND_UNLOCK_PULSING = 2; |
| 63 | |
| 64 | /** |
| 65 | * Mode in which we wake up the device, but play the normal dismiss animation. Active when we |
| 66 | * acquire a fingerprint pulsing in doze mode. |
| 67 | */ |
| 68 | public static final int MODE_SHOW_BOUNCER = 3; |
| 69 | |
| 70 | /** |
| 71 | * Mode in which we only wake up the device, and keyguard was not showing when we acquired a |
| 72 | * fingerprint. |
| 73 | * */ |
| 74 | public static final int MODE_ONLY_WAKE = 4; |
| 75 | |
| 76 | /** |
| 77 | * Mode in which fingerprint unlocks the device. |
| 78 | */ |
| 79 | public static final int MODE_UNLOCK = 5; |
| 80 | |
| 81 | /** |
| 82 | * Mode in which fingerprint brings up the bouncer because fingerprint unlocking is currently |
| 83 | * not allowed. |
| 84 | */ |
| 85 | public static final int MODE_DISMISS_BOUNCER = 6; |
| 86 | |
| 87 | /** |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 88 | * Mode in which fingerprint wakes and unlocks the device from a dream. |
| 89 | */ |
| 90 | public static final int MODE_WAKE_AND_UNLOCK_FROM_DREAM = 7; |
| 91 | |
| 92 | /** |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 93 | * How much faster we collapse the lockscreen when authenticating with fingerprint. |
| 94 | */ |
Selim Cinek | df5501b | 2017-04-14 20:01:27 -0700 | [diff] [blame] | 95 | private static final float FINGERPRINT_COLLAPSE_SPEEDUP_FACTOR = 1.1f; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 96 | |
| 97 | private PowerManager mPowerManager; |
| 98 | private Handler mHandler = new Handler(); |
| 99 | private PowerManager.WakeLock mWakeLock; |
| 100 | private KeyguardUpdateMonitor mUpdateMonitor; |
| 101 | private int mMode; |
| 102 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 103 | private StatusBarWindowManager mStatusBarWindowManager; |
| 104 | private DozeScrimController mDozeScrimController; |
| 105 | private KeyguardViewMediator mKeyguardViewMediator; |
| 106 | private ScrimController mScrimController; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 107 | private StatusBar mStatusBar; |
Jorim Jaggi | 8adb30c | 2016-09-13 15:02:22 -0700 | [diff] [blame] | 108 | private final UnlockMethodCache mUnlockMethodCache; |
| 109 | private final Context mContext; |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 110 | private int mPendingAuthenticatedUserId = -1; |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 111 | private boolean mPendingShowBouncer; |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 112 | private boolean mHasScreenTurnedOnSinceAuthenticating; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 113 | |
| 114 | public FingerprintUnlockController(Context context, |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 115 | DozeScrimController dozeScrimController, |
| 116 | KeyguardViewMediator keyguardViewMediator, |
| 117 | ScrimController scrimController, |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 118 | StatusBar statusBar, |
Jorim Jaggi | 8adb30c | 2016-09-13 15:02:22 -0700 | [diff] [blame] | 119 | UnlockMethodCache unlockMethodCache) { |
| 120 | mContext = context; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 121 | mPowerManager = context.getSystemService(PowerManager.class); |
| 122 | mUpdateMonitor = KeyguardUpdateMonitor.getInstance(context); |
| 123 | mUpdateMonitor.registerCallback(this); |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 124 | Dependency.get(WakefulnessLifecycle.class).addObserver(mWakefulnessObserver); |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 125 | Dependency.get(ScreenLifecycle.class).addObserver(mScreenObserver); |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 126 | mStatusBarWindowManager = Dependency.get(StatusBarWindowManager.class); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 127 | mDozeScrimController = dozeScrimController; |
| 128 | mKeyguardViewMediator = keyguardViewMediator; |
| 129 | mScrimController = scrimController; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 130 | mStatusBar = statusBar; |
Jorim Jaggi | 8adb30c | 2016-09-13 15:02:22 -0700 | [diff] [blame] | 131 | mUnlockMethodCache = unlockMethodCache; |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | public void setStatusBarKeyguardViewManager( |
| 135 | StatusBarKeyguardViewManager statusBarKeyguardViewManager) { |
| 136 | mStatusBarKeyguardViewManager = statusBarKeyguardViewManager; |
| 137 | } |
| 138 | |
| 139 | private final Runnable mReleaseFingerprintWakeLockRunnable = new Runnable() { |
| 140 | @Override |
| 141 | public void run() { |
| 142 | if (DEBUG_FP_WAKELOCK) { |
| 143 | Log.i(TAG, "fp wakelock: TIMEOUT!!"); |
| 144 | } |
| 145 | releaseFingerprintWakeLock(); |
| 146 | } |
| 147 | }; |
| 148 | |
| 149 | private void releaseFingerprintWakeLock() { |
| 150 | if (mWakeLock != null) { |
| 151 | mHandler.removeCallbacks(mReleaseFingerprintWakeLockRunnable); |
| 152 | if (DEBUG_FP_WAKELOCK) { |
| 153 | Log.i(TAG, "releasing fp wakelock"); |
| 154 | } |
| 155 | mWakeLock.release(); |
| 156 | mWakeLock = null; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public void onFingerprintAcquired() { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 162 | Trace.beginSection("FingerprintUnlockController#onFingerprintAcquired"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 163 | releaseFingerprintWakeLock(); |
| 164 | if (!mUpdateMonitor.isDeviceInteractive()) { |
Jorim Jaggi | 8adb30c | 2016-09-13 15:02:22 -0700 | [diff] [blame] | 165 | if (LatencyTracker.isEnabled(mContext)) { |
| 166 | LatencyTracker.getInstance(mContext).onActionStart( |
| 167 | LatencyTracker.ACTION_FINGERPRINT_WAKE_AND_UNLOCK); |
| 168 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 169 | mWakeLock = mPowerManager.newWakeLock( |
| 170 | PowerManager.PARTIAL_WAKE_LOCK, FINGERPRINT_WAKE_LOCK_NAME); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 171 | Trace.beginSection("acquiring wake-and-unlock"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 172 | mWakeLock.acquire(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 173 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 174 | if (DEBUG_FP_WAKELOCK) { |
| 175 | Log.i(TAG, "fingerprint acquired, grabbing fp wakelock"); |
| 176 | } |
| 177 | mHandler.postDelayed(mReleaseFingerprintWakeLockRunnable, |
| 178 | FINGERPRINT_WAKELOCK_TIMEOUT_MS); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 179 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 180 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Adrian Roos | 3e23eb5 | 2017-07-07 15:58:57 +0200 | [diff] [blame] | 183 | private boolean pulsingOrAod() { |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 184 | final ScrimState scrimState = mScrimController.getState(); |
| 185 | return scrimState == ScrimState.AOD |
| 186 | || scrimState == ScrimState.PULSING; |
Adrian Roos | 3e23eb5 | 2017-07-07 15:58:57 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 189 | @Override |
| 190 | public void onFingerprintAuthenticated(int userId) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 191 | Trace.beginSection("FingerprintUnlockController#onFingerprintAuthenticated"); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 192 | if (mUpdateMonitor.isGoingToSleep()) { |
| 193 | mPendingAuthenticatedUserId = userId; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 194 | Trace.endSection(); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 195 | return; |
| 196 | } |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 197 | startWakeAndUnlock(calculateMode()); |
| 198 | } |
| 199 | |
| 200 | public void startWakeAndUnlock(int mode) { |
Kevin Chyn | 0b508b4 | 2017-09-11 17:34:33 -0700 | [diff] [blame] | 201 | // TODO(b/62444020): remove when this bug is fixed |
| 202 | Log.v(TAG, "startWakeAndUnlock(" + mode + ")"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 203 | boolean wasDeviceInteractive = mUpdateMonitor.isDeviceInteractive(); |
Adrian Roos | 6d5ebb7 | 2017-08-03 15:10:22 +0200 | [diff] [blame] | 204 | mMode = mode; |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 205 | mHasScreenTurnedOnSinceAuthenticating = false; |
Adrian Roos | b880afe7 | 2017-07-25 17:02:46 +0200 | [diff] [blame] | 206 | if (mMode == MODE_WAKE_AND_UNLOCK_PULSING && pulsingOrAod()) { |
| 207 | // If we are waking the device up while we are pulsing the clock and the |
| 208 | // notifications would light up first, creating an unpleasant animation. |
| 209 | // Defer changing the screen brightness by forcing doze brightness on our window |
| 210 | // until the clock and the notifications are faded out. |
| 211 | mStatusBarWindowManager.setForceDozeBrightness(true); |
| 212 | } |
Lucas Dupin | 614b9ce | 2018-07-02 11:17:14 -0700 | [diff] [blame] | 213 | // During wake and unlock, we need to draw black before waking up to avoid abrupt |
| 214 | // brightness changes due to display state transitions. |
| 215 | boolean alwaysOnEnabled = DozeParameters.getInstance(mContext).getAlwaysOn(); |
| 216 | boolean delayWakeUp = mode == MODE_WAKE_AND_UNLOCK && alwaysOnEnabled; |
| 217 | Runnable wakeUp = ()-> { |
| 218 | if (!wasDeviceInteractive) { |
| 219 | if (DEBUG_FP_WAKELOCK) { |
| 220 | Log.i(TAG, "fp wakelock: Authenticated, waking up..."); |
| 221 | } |
| 222 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.policy:FINGERPRINT"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 223 | } |
Lucas Dupin | 614b9ce | 2018-07-02 11:17:14 -0700 | [diff] [blame] | 224 | if (delayWakeUp) { |
| 225 | mKeyguardViewMediator.onWakeAndUnlocking(); |
| 226 | } |
| 227 | Trace.beginSection("release wake-and-unlock"); |
| 228 | releaseFingerprintWakeLock(); |
| 229 | Trace.endSection(); |
| 230 | }; |
| 231 | |
| 232 | if (!delayWakeUp) { |
| 233 | wakeUp.run(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 234 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 235 | switch (mMode) { |
| 236 | case MODE_DISMISS_BOUNCER: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 237 | Trace.beginSection("MODE_DISMISS"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 238 | mStatusBarKeyguardViewManager.notifyKeyguardAuthenticated( |
| 239 | false /* strongAuth */); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 240 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 241 | break; |
| 242 | case MODE_UNLOCK: |
| 243 | case MODE_SHOW_BOUNCER: |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 244 | Trace.beginSection("MODE_UNLOCK or MODE_SHOW_BOUNCER"); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 245 | if (!wasDeviceInteractive) { |
| 246 | mStatusBarKeyguardViewManager.notifyDeviceWakeUpRequested(); |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 247 | mPendingShowBouncer = true; |
| 248 | } else { |
| 249 | showBouncer(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 250 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 251 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 252 | break; |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 253 | case MODE_WAKE_AND_UNLOCK_FROM_DREAM: |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 254 | case MODE_WAKE_AND_UNLOCK_PULSING: |
Jorim Jaggi | d94d3a2 | 2015-08-21 16:52:55 -0700 | [diff] [blame] | 255 | case MODE_WAKE_AND_UNLOCK: |
Adrian Roos | 88e61aa | 2017-05-23 16:16:50 -0700 | [diff] [blame] | 256 | if (mMode == MODE_WAKE_AND_UNLOCK_PULSING) { |
| 257 | Trace.beginSection("MODE_WAKE_AND_UNLOCK_PULSING"); |
| 258 | mStatusBar.updateMediaMetaData(false /* metaDataChanged */, |
| 259 | true /* allowEnterAnimation */); |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 260 | } else if (mMode == MODE_WAKE_AND_UNLOCK){ |
Adrian Roos | 88e61aa | 2017-05-23 16:16:50 -0700 | [diff] [blame] | 261 | Trace.beginSection("MODE_WAKE_AND_UNLOCK"); |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 262 | } else { |
| 263 | Trace.beginSection("MODE_WAKE_AND_UNLOCK_FROM_DREAM"); |
| 264 | mUpdateMonitor.awakenFromDream(); |
Adrian Roos | 88e61aa | 2017-05-23 16:16:50 -0700 | [diff] [blame] | 265 | } |
Jorim Jaggi | d94d3a2 | 2015-08-21 16:52:55 -0700 | [diff] [blame] | 266 | mStatusBarWindowManager.setStatusBarFocusable(false); |
Lucas Dupin | 614b9ce | 2018-07-02 11:17:14 -0700 | [diff] [blame] | 267 | if (delayWakeUp) { |
| 268 | mHandler.postDelayed(wakeUp, 50); |
| 269 | } else { |
| 270 | mKeyguardViewMediator.onWakeAndUnlocking(); |
| 271 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 272 | if (mStatusBar.getNavigationBarView() != null) { |
| 273 | mStatusBar.getNavigationBarView().setWakeAndUnlocking(true); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 274 | } |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 275 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 276 | break; |
| 277 | case MODE_ONLY_WAKE: |
| 278 | case MODE_NONE: |
| 279 | break; |
| 280 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 281 | mStatusBar.notifyFpAuthModeChanged(); |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 282 | Trace.endSection(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 285 | private void showBouncer() { |
felkachang | efebbc2f7 | 2018-05-14 12:22:40 +0800 | [diff] [blame] | 286 | if (calculateMode() == MODE_SHOW_BOUNCER) { |
| 287 | mStatusBarKeyguardViewManager.showBouncer(false); |
| 288 | } |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 289 | mStatusBarKeyguardViewManager.animateCollapsePanels( |
| 290 | FINGERPRINT_COLLAPSE_SPEEDUP_FACTOR); |
| 291 | mPendingShowBouncer = false; |
| 292 | } |
| 293 | |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 294 | @Override |
| 295 | public void onStartedGoingToSleep(int why) { |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 296 | resetMode(); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 297 | mPendingAuthenticatedUserId = -1; |
| 298 | } |
| 299 | |
| 300 | @Override |
| 301 | public void onFinishedGoingToSleep(int why) { |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 302 | Trace.beginSection("FingerprintUnlockController#onFinishedGoingToSleep"); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 303 | if (mPendingAuthenticatedUserId != -1) { |
| 304 | |
| 305 | // Post this to make sure it's executed after the device is fully locked. |
| 306 | mHandler.post(new Runnable() { |
| 307 | @Override |
| 308 | public void run() { |
| 309 | onFingerprintAuthenticated(mPendingAuthenticatedUserId); |
| 310 | } |
| 311 | }); |
| 312 | } |
| 313 | mPendingAuthenticatedUserId = -1; |
Nick Desaulniers | 1d39675 | 2016-07-25 15:05:33 -0700 | [diff] [blame] | 314 | Trace.endSection(); |
Jorim Jaggi | 95e4038 | 2015-09-16 15:53:42 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Adrian Roos | 710a0b1 | 2017-07-07 19:02:34 +0200 | [diff] [blame] | 317 | public boolean hasPendingAuthentication() { |
| 318 | return mPendingAuthenticatedUserId != -1 |
| 319 | && mUpdateMonitor.isUnlockingWithFingerprintAllowed() |
| 320 | && mPendingAuthenticatedUserId == KeyguardUpdateMonitor.getCurrentUser(); |
| 321 | } |
| 322 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 323 | public int getMode() { |
| 324 | return mMode; |
| 325 | } |
| 326 | |
| 327 | private int calculateMode() { |
| 328 | boolean unlockingAllowed = mUpdateMonitor.isUnlockingWithFingerprintAllowed(); |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 329 | boolean deviceDreaming = mUpdateMonitor.isDreaming(); |
Adrian Roos | 0262666 | 2017-07-06 18:22:17 +0200 | [diff] [blame] | 330 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 331 | if (!mUpdateMonitor.isDeviceInteractive()) { |
| 332 | if (!mStatusBarKeyguardViewManager.isShowing()) { |
| 333 | return MODE_ONLY_WAKE; |
Adrian Roos | e4cb6c8a | 2017-07-19 18:08:07 +0200 | [diff] [blame] | 334 | } else if (mDozeScrimController.isPulsing() && unlockingAllowed) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 335 | return MODE_WAKE_AND_UNLOCK_PULSING; |
Jorim Jaggi | 8adb30c | 2016-09-13 15:02:22 -0700 | [diff] [blame] | 336 | } else if (unlockingAllowed || !mUnlockMethodCache.isMethodSecure()) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 337 | return MODE_WAKE_AND_UNLOCK; |
| 338 | } else { |
| 339 | return MODE_SHOW_BOUNCER; |
| 340 | } |
| 341 | } |
Kevin Chyn | 36778ff | 2017-09-07 19:55:38 -0700 | [diff] [blame] | 342 | if (unlockingAllowed && deviceDreaming) { |
| 343 | return MODE_WAKE_AND_UNLOCK_FROM_DREAM; |
| 344 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 345 | if (mStatusBarKeyguardViewManager.isShowing()) { |
| 346 | if (mStatusBarKeyguardViewManager.isBouncerShowing() && unlockingAllowed) { |
| 347 | return MODE_DISMISS_BOUNCER; |
| 348 | } else if (unlockingAllowed) { |
| 349 | return MODE_UNLOCK; |
Jorim Jaggi | bf04cf5 | 2015-09-02 11:53:02 -0700 | [diff] [blame] | 350 | } else if (!mStatusBarKeyguardViewManager.isBouncerShowing()) { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 351 | return MODE_SHOW_BOUNCER; |
| 352 | } |
| 353 | } |
| 354 | return MODE_NONE; |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public void onFingerprintAuthFailed() { |
| 359 | cleanup(); |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void onFingerprintError(int msgId, String errString) { |
| 364 | cleanup(); |
| 365 | } |
| 366 | |
| 367 | private void cleanup() { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 368 | releaseFingerprintWakeLock(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | public void startKeyguardFadingAway() { |
| 372 | |
| 373 | // Disable brightness override when the ambient contents are fully invisible. |
| 374 | mHandler.postDelayed(new Runnable() { |
| 375 | @Override |
| 376 | public void run() { |
| 377 | mStatusBarWindowManager.setForceDozeBrightness(false); |
| 378 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 379 | }, StatusBar.FADE_KEYGUARD_DURATION_PULSING); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | public void finishKeyguardFadingAway() { |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 383 | resetMode(); |
| 384 | } |
| 385 | |
| 386 | private void resetMode() { |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 387 | mMode = MODE_NONE; |
Adrian Roos | 88e61aa | 2017-05-23 16:16:50 -0700 | [diff] [blame] | 388 | mStatusBarWindowManager.setForceDozeBrightness(false); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 389 | if (mStatusBar.getNavigationBarView() != null) { |
| 390 | mStatusBar.getNavigationBarView().setWakeAndUnlocking(false); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 391 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 392 | mStatusBar.notifyFpAuthModeChanged(); |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 393 | } |
Adrian Roos | 58ba685 | 2017-07-18 17:10:29 +0200 | [diff] [blame] | 394 | |
| 395 | private final WakefulnessLifecycle.Observer mWakefulnessObserver = |
| 396 | new WakefulnessLifecycle.Observer() { |
| 397 | @Override |
| 398 | public void onFinishedWakingUp() { |
| 399 | if (mPendingShowBouncer) { |
| 400 | FingerprintUnlockController.this.showBouncer(); |
| 401 | } |
| 402 | } |
| 403 | }; |
Adrian Roos | 7a5e4c9 | 2017-07-31 16:40:19 +0200 | [diff] [blame] | 404 | |
| 405 | private final ScreenLifecycle.Observer mScreenObserver = |
| 406 | new ScreenLifecycle.Observer() { |
| 407 | @Override |
| 408 | public void onScreenTurnedOn() { |
| 409 | mHasScreenTurnedOnSinceAuthenticating = true; |
| 410 | } |
| 411 | }; |
| 412 | |
| 413 | public boolean hasScreenTurnedOnSinceAuthenticating() { |
| 414 | return mHasScreenTurnedOnSinceAuthenticating; |
| 415 | } |
Adrian Roos | ba7ca59 | 2017-08-15 17:48:05 +0200 | [diff] [blame] | 416 | |
| 417 | public void dump(PrintWriter pw) { |
| 418 | pw.println(" FingerprintUnlockController:"); |
| 419 | pw.print(" mMode="); pw.println(mMode); |
| 420 | pw.print(" mWakeLock="); pw.println(mWakeLock); |
| 421 | } |
Lucas Dupin | 067136c | 2018-03-27 18:03:25 -0700 | [diff] [blame] | 422 | |
Lucas Dupin | 52c21c8 | 2018-06-04 19:03:20 -0700 | [diff] [blame] | 423 | /** |
| 424 | * Successful authentication with fingerprint that wakes up the device. |
| 425 | */ |
Lucas Dupin | 067136c | 2018-03-27 18:03:25 -0700 | [diff] [blame] | 426 | public boolean isWakeAndUnlock() { |
Lucas Dupin | 52c21c8 | 2018-06-04 19:03:20 -0700 | [diff] [blame] | 427 | return mMode == MODE_WAKE_AND_UNLOCK |
Lucas Dupin | 067136c | 2018-03-27 18:03:25 -0700 | [diff] [blame] | 428 | || mMode == MODE_WAKE_AND_UNLOCK_PULSING |
| 429 | || mMode == MODE_WAKE_AND_UNLOCK_FROM_DREAM; |
| 430 | } |
Lucas Dupin | 52c21c8 | 2018-06-04 19:03:20 -0700 | [diff] [blame] | 431 | |
| 432 | /** |
| 433 | * Successful authentication with fingerprint when the screen was either on or off. |
| 434 | */ |
| 435 | public boolean isFingerprintUnlock() { |
| 436 | return isWakeAndUnlock() || mMode == MODE_UNLOCK; |
| 437 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 438 | } |