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
This commit is contained in:
Bill Lin
2022-03-17 08:53:58 +08:00
parent 4cbf4dd3f8
commit 11def06227
2 changed files with 30 additions and 30 deletions

View File

@@ -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() {

View File

@@ -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<Runnable> 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();
}