OSDN Git Service

Make sure BiometricType is never null
authorLucas Dupin <dupin@google.com>
Wed, 10 Apr 2019 20:13:20 +0000 (13:13 -0700)
committerLucas Dupin <dupin@google.com>
Wed, 10 Apr 2019 20:13:20 +0000 (13:13 -0700)
Test: atest BiometricsUnlockControllerTest
Fixes: 129905024
Change-Id: Iccf8d1eb1b844c5298b780422f6fa550c083a3b4

packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java
packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java

index 2e85fea..ce8463e 100644 (file)
@@ -367,16 +367,11 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback {
     @Override
     public void onFinishedGoingToSleep(int why) {
         Trace.beginSection("BiometricUnlockController#onFinishedGoingToSleep");
-        if (mPendingAuthenticatedUserId != -1) {
-
+        BiometricSourceType pendingType = mPendingAuthenticatedBioSourceType;
+        int pendingUserId = mPendingAuthenticatedUserId;
+        if (pendingUserId != -1 && pendingType != null) {
             // Post this to make sure it's executed after the device is fully locked.
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    onBiometricAuthenticated(mPendingAuthenticatedUserId,
-                            mPendingAuthenticatedBioSourceType);
-                }
-            });
+            mHandler.post(() -> onBiometricAuthenticated(pendingUserId, pendingType));
         }
         mPendingAuthenticatedUserId = -1;
         mPendingAuthenticatedBioSourceType = null;
index 057f752..d2d294b 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.systemui.statusbar.phone;
 
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyFloat;
 import static org.mockito.ArgumentMatchers.eq;
@@ -71,6 +72,8 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
     private UnlockMethodCache mUnlockMethodCache;
     @Mock
     private TunerService mTunerService;
+    @Mock
+    private Handler mHandler;
     private BiometricUnlockController mBiometricUnlockController;
 
     @Before
@@ -172,12 +175,24 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
         verify(mStatusBarKeyguardViewManager, never()).animateCollapsePanels(anyFloat());
     }
 
+    @Test
+    public void onFinishedGoingToSleep_authenticatesWhenPending() {
+        when(mUpdateMonitor.isGoingToSleep()).thenReturn(true);
+        mBiometricUnlockController.onFinishedGoingToSleep(-1);
+        verify(mHandler, never()).post(any());
+
+        mBiometricUnlockController.onBiometricAuthenticated(1 /* userId */,
+                BiometricSourceType.FACE);
+        mBiometricUnlockController.onFinishedGoingToSleep(-1);
+        verify(mHandler).post(any());
+    }
+
     private class TestableBiometricUnlockController extends BiometricUnlockController {
 
         TestableBiometricUnlockController(boolean faceDismissesKeyguard) {
             super(mContext, mDozeScrimController,
                     mKeyguardViewMediator, mScrimController, mStatusBar, mUnlockMethodCache,
-                    new Handler(), mUpdateMonitor, mTunerService, 0 /* wakeUpDelay */,
+                    mHandler, mUpdateMonitor, mTunerService, 0 /* wakeUpDelay */,
                     faceDismissesKeyguard);
             mFaceDismissesKeyguard = faceDismissesKeyguard;
         }