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