Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 static org.mockito.ArgumentMatchers.anyBoolean; |
| 20 | import static org.mockito.ArgumentMatchers.anyFloat; |
| 21 | import static org.mockito.ArgumentMatchers.eq; |
| 22 | import static org.mockito.Mockito.never; |
| 23 | import static org.mockito.Mockito.reset; |
| 24 | import static org.mockito.Mockito.verify; |
| 25 | import static org.mockito.Mockito.when; |
| 26 | |
| 27 | import android.hardware.biometrics.BiometricSourceType; |
| 28 | import android.os.Handler; |
| 29 | import android.os.PowerManager; |
| 30 | import android.os.UserHandle; |
| 31 | import android.test.suitebuilder.annotation.SmallTest; |
| 32 | import android.testing.AndroidTestingRunner; |
| 33 | import android.testing.TestableLooper.RunWithLooper; |
| 34 | |
| 35 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 36 | import com.android.systemui.SysuiTestCase; |
| 37 | import com.android.systemui.keyguard.KeyguardViewMediator; |
| 38 | import com.android.systemui.statusbar.NotificationMediaManager; |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 39 | import com.android.systemui.tuner.TunerService; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 40 | |
| 41 | import org.junit.Before; |
| 42 | import org.junit.Test; |
| 43 | import org.junit.runner.RunWith; |
| 44 | import org.mockito.Mock; |
| 45 | import org.mockito.MockitoAnnotations; |
| 46 | |
| 47 | @SmallTest |
| 48 | @RunWith(AndroidTestingRunner.class) |
| 49 | @RunWithLooper |
| 50 | public class BiometricsUnlockControllerTest extends SysuiTestCase { |
| 51 | |
| 52 | @Mock |
| 53 | private NotificationMediaManager mMediaManager; |
| 54 | @Mock |
| 55 | private PowerManager mPowerManager; |
| 56 | @Mock |
| 57 | private KeyguardUpdateMonitor mUpdateMonitor; |
| 58 | @Mock |
| 59 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 60 | @Mock |
| 61 | private StatusBarWindowController mStatusBarWindowController; |
| 62 | @Mock |
| 63 | private DozeScrimController mDozeScrimController; |
| 64 | @Mock |
| 65 | private KeyguardViewMediator mKeyguardViewMediator; |
| 66 | @Mock |
| 67 | private ScrimController mScrimController; |
| 68 | @Mock |
| 69 | private StatusBar mStatusBar; |
| 70 | @Mock |
| 71 | private UnlockMethodCache mUnlockMethodCache; |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 72 | @Mock |
| 73 | private TunerService mTunerService; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 74 | private BiometricUnlockController mBiometricUnlockController; |
| 75 | |
| 76 | @Before |
| 77 | public void setUp() { |
| 78 | MockitoAnnotations.initMocks(this); |
| 79 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 80 | when(mUpdateMonitor.isDeviceInteractive()).thenReturn(true); |
| 81 | mContext.addMockSystemService(PowerManager.class, mPowerManager); |
| 82 | mDependency.injectTestDependency(NotificationMediaManager.class, mMediaManager); |
| 83 | mDependency.injectTestDependency(StatusBarWindowController.class, |
| 84 | mStatusBarWindowController); |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 85 | mBiometricUnlockController = new TestableBiometricUnlockController( |
| 86 | false /* faceDismissesKeyguard */); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 87 | mBiometricUnlockController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager); |
| 88 | } |
| 89 | |
| 90 | @Test |
| 91 | public void onBiometricAuthenticated_whenFingerprintAndBiometricsDisallowed_showBouncer() { |
| 92 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 93 | BiometricSourceType.FINGERPRINT); |
| 94 | verify(mStatusBarKeyguardViewManager).showBouncer(eq(false)); |
| 95 | verify(mStatusBarKeyguardViewManager).animateCollapsePanels(anyFloat()); |
| 96 | } |
| 97 | |
| 98 | @Test |
| 99 | public void onBiometricAuthenticated_whenFingerprintAndNotInteractive_wakeAndUnlock() { |
| 100 | reset(mUpdateMonitor); |
| 101 | reset(mStatusBarKeyguardViewManager); |
| 102 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 103 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 104 | when(mDozeScrimController.isPulsing()).thenReturn(true); |
| 105 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 106 | BiometricSourceType.FINGERPRINT); |
| 107 | |
| 108 | verify(mKeyguardViewMediator).onWakeAndUnlocking(); |
| 109 | } |
| 110 | |
| 111 | @Test |
| 112 | public void onBiometricAuthenticated_whenFingerprint_dismissKeyguard() { |
| 113 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 114 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 115 | BiometricSourceType.FINGERPRINT); |
| 116 | |
| 117 | verify(mStatusBarKeyguardViewManager, never()).showBouncer(anyBoolean()); |
| 118 | verify(mStatusBarKeyguardViewManager).animateCollapsePanels(anyFloat()); |
| 119 | } |
| 120 | |
| 121 | @Test |
| 122 | public void onBiometricAuthenticated_whenFingerprintOnBouncer_dismissBouncer() { |
| 123 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 124 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 125 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 126 | BiometricSourceType.FINGERPRINT); |
| 127 | |
| 128 | verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(eq(false)); |
| 129 | } |
| 130 | |
| 131 | @Test |
| 132 | public void onBiometricAuthenticated_whenFace_dontDismissKeyguard() { |
| 133 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 134 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 135 | BiometricSourceType.FACE); |
| 136 | |
| 137 | verify(mStatusBarKeyguardViewManager, never()).animateCollapsePanels(anyFloat()); |
| 138 | } |
| 139 | |
| 140 | @Test |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 141 | public void onBiometricAuthenticated_whenFace_dismissingKeyguard() { |
| 142 | mBiometricUnlockController = new TestableBiometricUnlockController( |
| 143 | true /* faceDismissesKeyguard */); |
| 144 | mBiometricUnlockController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager); |
| 145 | |
| 146 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 147 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 148 | BiometricSourceType.FACE); |
| 149 | |
| 150 | verify(mStatusBarKeyguardViewManager).animateCollapsePanels(anyFloat()); |
| 151 | } |
| 152 | |
| 153 | @Test |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 154 | public void onBiometricAuthenticated_whenFaceOnBouncer_dismissBouncer() { |
| 155 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 156 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 157 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 158 | BiometricSourceType.FACE); |
| 159 | |
| 160 | verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(eq(false)); |
| 161 | } |
| 162 | |
| 163 | @Test |
| 164 | public void onBiometricAuthenticated_whenFaceAndPulsing_dontDismissKeyguard() { |
| 165 | reset(mUpdateMonitor); |
| 166 | reset(mStatusBarKeyguardViewManager); |
| 167 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 168 | when(mDozeScrimController.isPulsing()).thenReturn(true); |
| 169 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 170 | BiometricSourceType.FACE); |
| 171 | |
| 172 | verify(mStatusBarKeyguardViewManager, never()).animateCollapsePanels(anyFloat()); |
| 173 | } |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 174 | |
| 175 | private class TestableBiometricUnlockController extends BiometricUnlockController { |
| 176 | |
| 177 | TestableBiometricUnlockController(boolean faceDismissesKeyguard) { |
| 178 | super(mContext, mDozeScrimController, |
| 179 | mKeyguardViewMediator, mScrimController, mStatusBar, mUnlockMethodCache, |
| 180 | new Handler(), mUpdateMonitor, mTunerService, 0 /* wakeUpDelay */, |
| 181 | faceDismissesKeyguard); |
| 182 | mFaceDismissesKeyguard = faceDismissesKeyguard; |
| 183 | } |
| 184 | } |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 185 | } |