From 11def06227748f3b821185b6ce68c4383da6dc46 Mon Sep 17 00:00:00 2001 From: Bill Lin Date: Thu, 17 Mar 2022 08:53:58 +0800 Subject: [PATCH] Refactor BiometricUnlockController mode/state control Some of KeyguardUpdateMonitorCallbacks were deprecated, Migrating to use WakefulnessLifecycle. - onStartedGoingToSleep() - onFinishedGoingToSleep() Test: atest SystemUITests Test: atest BiometricsUnlockControllerTest Test: manuall enable log and UDFPS unlock Bug: 222631581 Change-Id: I4eabcf80dbc614bbc446517723a9a8e97ea0e844 --- .../phone/BiometricUnlockController.java | 56 +++++++++---------- .../phone/BiometricsUnlockControllerTest.java | 4 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java index b46ed57fb866a..aab5ff8d92e6a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java @@ -537,27 +537,6 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp mPendingShowBouncer = false; } - @Override - public void onStartedGoingToSleep(int why) { - resetMode(); - mFadedAwayAfterWakeAndUnlock = false; - mPendingAuthenticated = null; - } - - @Override - public void onFinishedGoingToSleep(int why) { - Trace.beginSection("BiometricUnlockController#onFinishedGoingToSleep"); - if (mPendingAuthenticated != null) { - PendingAuthenticated pendingAuthenticated = mPendingAuthenticated; - // Post this to make sure it's executed after the device is fully locked. - mHandler.post(() -> onBiometricAuthenticated(pendingAuthenticated.userId, - pendingAuthenticated.biometricSourceType, - pendingAuthenticated.isStrongBiometric)); - mPendingAuthenticated = null; - } - Trace.endSection(); - } - public boolean hasPendingAuthentication() { return mPendingAuthenticated != null && mUpdateMonitor @@ -752,13 +731,34 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp @VisibleForTesting final WakefulnessLifecycle.Observer mWakefulnessObserver = new WakefulnessLifecycle.Observer() { - @Override - public void onFinishedWakingUp() { - if (mPendingShowBouncer) { - BiometricUnlockController.this.showBouncer(); - } - } - }; + @Override + public void onFinishedWakingUp() { + if (mPendingShowBouncer) { + BiometricUnlockController.this.showBouncer(); + } + } + + @Override + public void onStartedGoingToSleep() { + resetMode(); + mFadedAwayAfterWakeAndUnlock = false; + mPendingAuthenticated = null; + } + + @Override + public void onFinishedGoingToSleep() { + Trace.beginSection("BiometricUnlockController#onFinishedGoingToSleep"); + if (mPendingAuthenticated != null) { + PendingAuthenticated pendingAuthenticated = mPendingAuthenticated; + // Post this to make sure it's executed after the device is fully locked. + mHandler.post(() -> onBiometricAuthenticated(pendingAuthenticated.userId, + pendingAuthenticated.biometricSourceType, + pendingAuthenticated.isStrongBiometric)); + mPendingAuthenticated = null; + } + Trace.endSection(); + } + }; private final ScreenLifecycle.Observer mScreenObserver = new ScreenLifecycle.Observer() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java index ed144fa993696..142c2c1ed0178 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java @@ -408,7 +408,7 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase { @Test public void onFinishedGoingToSleep_authenticatesWhenPending() { when(mUpdateMonitor.isGoingToSleep()).thenReturn(true); - mBiometricUnlockController.onFinishedGoingToSleep(-1); + mBiometricUnlockController.mWakefulnessObserver.onFinishedGoingToSleep(); verify(mHandler, never()).post(any()); ArgumentCaptor captor = ArgumentCaptor.forClass(Runnable.class); @@ -416,7 +416,7 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase { // value of isUnlockingWithBiometricAllowed() mBiometricUnlockController.onBiometricAuthenticated(1 /* userId */, BiometricSourceType.FACE, true /* isStrongBiometric */); - mBiometricUnlockController.onFinishedGoingToSleep(-1); + mBiometricUnlockController.mWakefulnessObserver.onFinishedGoingToSleep(); verify(mHandler).post(captor.capture()); captor.getValue().run(); }