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 | |
Lucas Dupin | 45142ba | 2019-04-10 13:13:20 -0700 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.any; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 20 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 21 | import static org.mockito.ArgumentMatchers.anyFloat; |
| 22 | import static org.mockito.ArgumentMatchers.eq; |
| 23 | import static org.mockito.Mockito.never; |
| 24 | import static org.mockito.Mockito.reset; |
| 25 | import static org.mockito.Mockito.verify; |
| 26 | import static org.mockito.Mockito.when; |
| 27 | |
| 28 | import android.hardware.biometrics.BiometricSourceType; |
| 29 | import android.os.Handler; |
| 30 | import android.os.PowerManager; |
| 31 | import android.os.UserHandle; |
| 32 | import android.test.suitebuilder.annotation.SmallTest; |
| 33 | import android.testing.AndroidTestingRunner; |
| 34 | import android.testing.TestableLooper.RunWithLooper; |
| 35 | |
| 36 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 37 | import com.android.systemui.SysuiTestCase; |
| 38 | import com.android.systemui.keyguard.KeyguardViewMediator; |
| 39 | import com.android.systemui.statusbar.NotificationMediaManager; |
| 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 |
Lucas Dupin | 45142ba | 2019-04-10 13:13:20 -0700 | [diff] [blame] | 73 | private Handler mHandler; |
Lucas Dupin | 9bae9c2 | 2019-06-04 16:37:40 -0700 | [diff] [blame] | 74 | @Mock |
| 75 | private KeyguardBypassController mKeyguardBypassController; |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 76 | private BiometricUnlockController mBiometricUnlockController; |
| 77 | |
| 78 | @Before |
| 79 | public void setUp() { |
| 80 | MockitoAnnotations.initMocks(this); |
| 81 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 82 | when(mUpdateMonitor.isDeviceInteractive()).thenReturn(true); |
Lucas Dupin | 206fe56 | 2019-05-31 14:36:42 -0700 | [diff] [blame] | 83 | when(mUnlockMethodCache.isUnlockingWithFacePossible()).thenReturn(true); |
Selim Cinek | bd84c16 | 2019-06-11 16:23:23 -0700 | [diff] [blame] | 84 | when(mKeyguardBypassController.onBiometricAuthenticated(any())).thenReturn(true); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 85 | mContext.addMockSystemService(PowerManager.class, mPowerManager); |
| 86 | mDependency.injectTestDependency(NotificationMediaManager.class, mMediaManager); |
| 87 | mDependency.injectTestDependency(StatusBarWindowController.class, |
| 88 | mStatusBarWindowController); |
Lucas Dupin | 9bae9c2 | 2019-06-04 16:37:40 -0700 | [diff] [blame] | 89 | mBiometricUnlockController = new BiometricUnlockController(mContext, mDozeScrimController, |
| 90 | mKeyguardViewMediator, mScrimController, mStatusBar, mUnlockMethodCache, |
| 91 | mHandler, mUpdateMonitor, 0 /* wakeUpDelay */, mKeyguardBypassController); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 92 | mBiometricUnlockController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager); |
| 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void onBiometricAuthenticated_whenFingerprintAndBiometricsDisallowed_showBouncer() { |
| 97 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 98 | BiometricSourceType.FINGERPRINT); |
| 99 | verify(mStatusBarKeyguardViewManager).showBouncer(eq(false)); |
| 100 | verify(mStatusBarKeyguardViewManager).animateCollapsePanels(anyFloat()); |
| 101 | } |
| 102 | |
| 103 | @Test |
| 104 | public void onBiometricAuthenticated_whenFingerprintAndNotInteractive_wakeAndUnlock() { |
| 105 | reset(mUpdateMonitor); |
| 106 | reset(mStatusBarKeyguardViewManager); |
| 107 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 108 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 109 | when(mDozeScrimController.isPulsing()).thenReturn(true); |
| 110 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 111 | BiometricSourceType.FINGERPRINT); |
| 112 | |
| 113 | verify(mKeyguardViewMediator).onWakeAndUnlocking(); |
| 114 | } |
| 115 | |
| 116 | @Test |
| 117 | public void onBiometricAuthenticated_whenFingerprint_dismissKeyguard() { |
| 118 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 119 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 120 | BiometricSourceType.FINGERPRINT); |
| 121 | |
| 122 | verify(mStatusBarKeyguardViewManager, never()).showBouncer(anyBoolean()); |
Lucas Dupin | e78794c | 2019-06-18 11:55:37 -0700 | [diff] [blame] | 123 | verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(eq(false)); |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Test |
| 127 | public void onBiometricAuthenticated_whenFingerprintOnBouncer_dismissBouncer() { |
| 128 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 129 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 130 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 131 | BiometricSourceType.FINGERPRINT); |
| 132 | |
| 133 | verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(eq(false)); |
| 134 | } |
| 135 | |
| 136 | @Test |
| 137 | public void onBiometricAuthenticated_whenFace_dontDismissKeyguard() { |
| 138 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 139 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 140 | BiometricSourceType.FACE); |
| 141 | |
| 142 | verify(mStatusBarKeyguardViewManager, never()).animateCollapsePanels(anyFloat()); |
| 143 | } |
| 144 | |
| 145 | @Test |
Lucas Dupin | 9bae9c2 | 2019-06-04 16:37:40 -0700 | [diff] [blame] | 146 | public void onBiometricAuthenticated_whenFace_andBypass_dismissKeyguard() { |
| 147 | when(mKeyguardBypassController.getBypassEnabled()).thenReturn(true); |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 148 | mBiometricUnlockController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager); |
| 149 | |
| 150 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 151 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 152 | BiometricSourceType.FACE); |
| 153 | |
Lucas Dupin | e78794c | 2019-06-18 11:55:37 -0700 | [diff] [blame] | 154 | verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(eq(false)); |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Test |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 158 | public void onBiometricAuthenticated_whenFaceOnBouncer_dismissBouncer() { |
| 159 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 160 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 161 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 162 | BiometricSourceType.FACE); |
| 163 | |
| 164 | verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(eq(false)); |
| 165 | } |
| 166 | |
| 167 | @Test |
| 168 | public void onBiometricAuthenticated_whenFaceAndPulsing_dontDismissKeyguard() { |
| 169 | reset(mUpdateMonitor); |
| 170 | reset(mStatusBarKeyguardViewManager); |
| 171 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 172 | when(mDozeScrimController.isPulsing()).thenReturn(true); |
| 173 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 174 | BiometricSourceType.FACE); |
| 175 | |
| 176 | verify(mStatusBarKeyguardViewManager, never()).animateCollapsePanels(anyFloat()); |
| 177 | } |
Lucas Dupin | c94963f | 2019-03-07 14:54:05 -0800 | [diff] [blame] | 178 | |
Lucas Dupin | 45142ba | 2019-04-10 13:13:20 -0700 | [diff] [blame] | 179 | @Test |
| 180 | public void onFinishedGoingToSleep_authenticatesWhenPending() { |
| 181 | when(mUpdateMonitor.isGoingToSleep()).thenReturn(true); |
| 182 | mBiometricUnlockController.onFinishedGoingToSleep(-1); |
| 183 | verify(mHandler, never()).post(any()); |
| 184 | |
| 185 | mBiometricUnlockController.onBiometricAuthenticated(1 /* userId */, |
| 186 | BiometricSourceType.FACE); |
| 187 | mBiometricUnlockController.onFinishedGoingToSleep(-1); |
| 188 | verify(mHandler).post(any()); |
| 189 | } |
Lucas Dupin | 3d05353 | 2019-01-29 12:35:22 -0800 | [diff] [blame] | 190 | } |