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; |
| 39 | |
| 40 | import org.junit.Before; |
| 41 | import org.junit.Test; |
| 42 | import org.junit.runner.RunWith; |
| 43 | import org.mockito.Mock; |
| 44 | import org.mockito.MockitoAnnotations; |
| 45 | |
| 46 | @SmallTest |
| 47 | @RunWith(AndroidTestingRunner.class) |
| 48 | @RunWithLooper |
| 49 | public class BiometricsUnlockControllerTest extends SysuiTestCase { |
| 50 | |
| 51 | @Mock |
| 52 | private NotificationMediaManager mMediaManager; |
| 53 | @Mock |
| 54 | private PowerManager mPowerManager; |
| 55 | @Mock |
| 56 | private KeyguardUpdateMonitor mUpdateMonitor; |
| 57 | @Mock |
| 58 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 59 | @Mock |
| 60 | private StatusBarWindowController mStatusBarWindowController; |
| 61 | @Mock |
| 62 | private DozeScrimController mDozeScrimController; |
| 63 | @Mock |
| 64 | private KeyguardViewMediator mKeyguardViewMediator; |
| 65 | @Mock |
| 66 | private ScrimController mScrimController; |
| 67 | @Mock |
| 68 | private StatusBar mStatusBar; |
| 69 | @Mock |
| 70 | private UnlockMethodCache mUnlockMethodCache; |
| 71 | private BiometricUnlockController mBiometricUnlockController; |
| 72 | |
| 73 | @Before |
| 74 | public void setUp() { |
| 75 | MockitoAnnotations.initMocks(this); |
| 76 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 77 | when(mUpdateMonitor.isDeviceInteractive()).thenReturn(true); |
| 78 | mContext.addMockSystemService(PowerManager.class, mPowerManager); |
| 79 | mDependency.injectTestDependency(NotificationMediaManager.class, mMediaManager); |
| 80 | mDependency.injectTestDependency(StatusBarWindowController.class, |
| 81 | mStatusBarWindowController); |
| 82 | mBiometricUnlockController = new BiometricUnlockController(mContext, mDozeScrimController, |
| 83 | mKeyguardViewMediator, mScrimController, mStatusBar, mUnlockMethodCache, |
| 84 | new Handler(), mUpdateMonitor, 0 /* wakeUpDelay */); |
| 85 | mBiometricUnlockController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager); |
| 86 | } |
| 87 | |
| 88 | @Test |
| 89 | public void onBiometricAuthenticated_whenFingerprintAndBiometricsDisallowed_showBouncer() { |
| 90 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 91 | BiometricSourceType.FINGERPRINT); |
| 92 | verify(mStatusBarKeyguardViewManager).showBouncer(eq(false)); |
| 93 | verify(mStatusBarKeyguardViewManager).animateCollapsePanels(anyFloat()); |
| 94 | } |
| 95 | |
| 96 | @Test |
| 97 | public void onBiometricAuthenticated_whenFingerprintAndNotInteractive_wakeAndUnlock() { |
| 98 | reset(mUpdateMonitor); |
| 99 | reset(mStatusBarKeyguardViewManager); |
| 100 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 101 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 102 | when(mDozeScrimController.isPulsing()).thenReturn(true); |
| 103 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 104 | BiometricSourceType.FINGERPRINT); |
| 105 | |
| 106 | verify(mKeyguardViewMediator).onWakeAndUnlocking(); |
| 107 | } |
| 108 | |
| 109 | @Test |
| 110 | public void onBiometricAuthenticated_whenFingerprint_dismissKeyguard() { |
| 111 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 112 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 113 | BiometricSourceType.FINGERPRINT); |
| 114 | |
| 115 | verify(mStatusBarKeyguardViewManager, never()).showBouncer(anyBoolean()); |
| 116 | verify(mStatusBarKeyguardViewManager).animateCollapsePanels(anyFloat()); |
| 117 | } |
| 118 | |
| 119 | @Test |
| 120 | public void onBiometricAuthenticated_whenFingerprintOnBouncer_dismissBouncer() { |
| 121 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 122 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 123 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 124 | BiometricSourceType.FINGERPRINT); |
| 125 | |
| 126 | verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(eq(false)); |
| 127 | } |
| 128 | |
| 129 | @Test |
| 130 | public void onBiometricAuthenticated_whenFace_dontDismissKeyguard() { |
| 131 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 132 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 133 | BiometricSourceType.FACE); |
| 134 | |
| 135 | verify(mStatusBarKeyguardViewManager, never()).animateCollapsePanels(anyFloat()); |
| 136 | } |
| 137 | |
| 138 | @Test |
| 139 | public void onBiometricAuthenticated_whenFaceOnBouncer_dismissBouncer() { |
| 140 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 141 | when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |
| 142 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 143 | BiometricSourceType.FACE); |
| 144 | |
| 145 | verify(mStatusBarKeyguardViewManager).notifyKeyguardAuthenticated(eq(false)); |
| 146 | } |
| 147 | |
| 148 | @Test |
| 149 | public void onBiometricAuthenticated_whenFaceAndPulsing_dontDismissKeyguard() { |
| 150 | reset(mUpdateMonitor); |
| 151 | reset(mStatusBarKeyguardViewManager); |
| 152 | when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); |
| 153 | when(mDozeScrimController.isPulsing()).thenReturn(true); |
| 154 | mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, |
| 155 | BiometricSourceType.FACE); |
| 156 | |
| 157 | verify(mStatusBarKeyguardViewManager, never()).animateCollapsePanels(anyFloat()); |
| 158 | } |
| 159 | } |