Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Lucas Dupin | 71dd484 | 2018-05-29 15:41:03 -0700 | [diff] [blame] | 20 | import static org.mockito.ArgumentMatchers.anyFloat; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 21 | import static org.mockito.ArgumentMatchers.eq; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame^] | 22 | import static org.mockito.Mockito.mock; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 23 | import static org.mockito.Mockito.never; |
| 24 | import static org.mockito.Mockito.reset; |
| 25 | import static org.mockito.Mockito.verify; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 26 | import static org.mockito.Mockito.when; |
| 27 | |
| 28 | import android.content.Context; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 29 | import android.testing.AndroidTestingRunner; |
| 30 | import android.testing.TestableLooper; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame^] | 31 | import android.view.View; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 32 | import android.view.ViewGroup; |
| 33 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 34 | import androidx.test.filters.SmallTest; |
| 35 | |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 36 | import com.android.internal.widget.LockPatternUtils; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 37 | import com.android.keyguard.ViewMediatorCallback; |
| 38 | import com.android.systemui.SysuiTestCase; |
| 39 | import com.android.systemui.keyguard.DismissCallbackRegistry; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 40 | import com.android.systemui.plugins.ActivityStarter.OnDismissAction; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame^] | 41 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 42 | import com.android.systemui.statusbar.StatusBarState; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 43 | |
| 44 | import org.junit.Before; |
| 45 | import org.junit.Test; |
| 46 | import org.junit.runner.RunWith; |
| 47 | import org.mockito.Mock; |
| 48 | import org.mockito.MockitoAnnotations; |
| 49 | |
| 50 | @SmallTest |
| 51 | @RunWith(AndroidTestingRunner.class) |
| 52 | @TestableLooper.RunWithLooper |
| 53 | public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { |
| 54 | |
| 55 | @Mock |
| 56 | private ViewMediatorCallback mViewMediatorCallback; |
| 57 | @Mock |
| 58 | private LockPatternUtils mLockPatternUtils; |
| 59 | @Mock |
| 60 | private KeyguardBouncer mBouncer; |
| 61 | @Mock |
| 62 | private StatusBar mStatusBar; |
| 63 | @Mock |
| 64 | private ViewGroup mContainer; |
| 65 | @Mock |
| 66 | private NotificationPanelView mNotificationPanelView; |
| 67 | @Mock |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 68 | private BiometricUnlockController mBiometrucUnlockController; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 69 | @Mock |
| 70 | private DismissCallbackRegistry mDismissCallbackRegistry; |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame^] | 71 | @Mock |
| 72 | private ViewGroup mLockIconContainer; |
| 73 | @Mock |
| 74 | private StatusBarStateController mStatusBarStateController; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 75 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 76 | |
| 77 | @Before |
| 78 | public void setUp() { |
| 79 | MockitoAnnotations.initMocks(this); |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 80 | mDependency.injectMockDependency(StatusBarWindowController.class); |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame^] | 81 | mDependency.injectTestDependency(StatusBarStateController.class, mStatusBarStateController); |
| 82 | when(mLockIconContainer.getParent()).thenReturn(mock(ViewGroup.class)); |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 83 | mStatusBarKeyguardViewManager = new TestableStatusBarKeyguardViewManager(getContext(), |
| 84 | mViewMediatorCallback, mLockPatternUtils); |
| 85 | mStatusBarKeyguardViewManager.registerStatusBar(mStatusBar, mContainer, |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame^] | 86 | mNotificationPanelView, mBiometrucUnlockController, mDismissCallbackRegistry, |
| 87 | mLockIconContainer); |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 88 | mStatusBarKeyguardViewManager.show(null); |
| 89 | } |
| 90 | |
| 91 | @Test |
| 92 | public void dismissWithAction_AfterKeyguardGoneSetToFalse() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 93 | OnDismissAction action = () -> false; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 94 | Runnable cancelAction = () -> {}; |
| 95 | mStatusBarKeyguardViewManager.dismissWithAction(action, cancelAction, |
| 96 | false /* afterKeyguardGone */); |
| 97 | verify(mBouncer).showWithDismissAction(eq(action), eq(cancelAction)); |
| 98 | } |
| 99 | |
| 100 | @Test |
| 101 | public void showBouncer_onlyWhenShowing() { |
| 102 | mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */); |
| 103 | mStatusBar.showBouncer(true /* scrimmed */); |
| 104 | verify(mBouncer, never()).show(anyBoolean(), anyBoolean()); |
| 105 | verify(mBouncer, never()).show(anyBoolean()); |
| 106 | } |
| 107 | |
| 108 | @Test |
| 109 | public void showBouncer_notWhenBouncerAlreadyShowing() { |
| 110 | mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */); |
| 111 | when(mBouncer.isSecure()).thenReturn(true); |
| 112 | mStatusBar.showBouncer(true /* scrimmed */); |
| 113 | verify(mBouncer, never()).show(anyBoolean(), anyBoolean()); |
| 114 | verify(mBouncer, never()).show(anyBoolean()); |
| 115 | } |
| 116 | |
| 117 | @Test |
| 118 | public void showBouncer_showsTheBouncer() { |
| 119 | mStatusBarKeyguardViewManager.showBouncer(true /* scrimmed */); |
| 120 | verify(mBouncer).show(anyBoolean(), eq(true)); |
| 121 | } |
| 122 | |
| 123 | @Test |
| 124 | public void onPanelExpansionChanged_neverHidesFullscreenBouncer() { |
| 125 | // TODO: StatusBar should not be here, mBouncer.isFullscreenBouncer() should do the same. |
| 126 | when(mStatusBar.isFullScreenUserSwitcherState()).thenReturn(true); |
| 127 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 128 | true /* tracking */); |
| 129 | verify(mBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_VISIBLE)); |
| 130 | } |
| 131 | |
| 132 | @Test |
| 133 | public void onPanelExpansionChanged_neverHidesScrimmedBouncer() { |
Lucas Dupin | 93f714d | 2019-03-26 16:49:24 -0700 | [diff] [blame] | 134 | when(mBouncer.isShowing()).thenReturn(true); |
| 135 | when(mBouncer.isScrimmed()).thenReturn(true); |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 136 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 137 | true /* tracking */); |
| 138 | verify(mBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_VISIBLE)); |
| 139 | } |
| 140 | |
| 141 | @Test |
| 142 | public void onPanelExpansionChanged_neverShowsDuringHintAnimation() { |
| 143 | when(mNotificationPanelView.isUnlockHintRunning()).thenReturn(true); |
| 144 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 145 | true /* tracking */); |
| 146 | verify(mBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_HIDDEN)); |
| 147 | } |
| 148 | |
| 149 | @Test |
| 150 | public void onPanelExpansionChanged_propagatesToBouncer() { |
| 151 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 152 | true /* tracking */); |
| 153 | verify(mBouncer).setExpansion(eq(0.5f)); |
| 154 | } |
| 155 | |
| 156 | @Test |
| 157 | public void onPanelExpansionChanged_showsBouncerWhenSwiping() { |
| 158 | when(mStatusBar.isKeyguardCurrentlySecure()).thenReturn(true); |
| 159 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 160 | true /* tracking */); |
| 161 | verify(mBouncer).show(eq(false), eq(false)); |
| 162 | |
| 163 | // But not when it's already visible |
| 164 | reset(mBouncer); |
| 165 | when(mBouncer.isShowing()).thenReturn(true); |
| 166 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, true /* tracking */); |
| 167 | verify(mBouncer, never()).show(eq(false), eq(false)); |
| 168 | |
| 169 | // Or animating away |
| 170 | reset(mBouncer); |
| 171 | when(mBouncer.isAnimatingAway()).thenReturn(true); |
| 172 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, true /* tracking */); |
| 173 | verify(mBouncer, never()).show(eq(false), eq(false)); |
| 174 | } |
| 175 | |
Lucas Dupin | aece502 | 2018-05-21 16:44:28 -0700 | [diff] [blame] | 176 | @Test |
| 177 | public void onPanelExpansionChanged_neverTranslatesBouncerWhenOccluded() { |
| 178 | mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animate */); |
| 179 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 180 | true /* tracking */); |
| 181 | verify(mBouncer, never()).setExpansion(eq(0.5f)); |
| 182 | } |
| 183 | |
Lucas Dupin | 71dd484 | 2018-05-29 15:41:03 -0700 | [diff] [blame] | 184 | @Test |
| 185 | public void onPanelExpansionChanged_neverTranslatesBouncerWhenWakeAndUnlock() { |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 186 | when(mBiometrucUnlockController.getMode()) |
| 187 | .thenReturn(BiometricUnlockController.MODE_WAKE_AND_UNLOCK); |
Lucas Dupin | 71dd484 | 2018-05-29 15:41:03 -0700 | [diff] [blame] | 188 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(KeyguardBouncer.EXPANSION_VISIBLE, |
| 189 | false /* tracking */); |
| 190 | verify(mBouncer, never()).setExpansion(anyFloat()); |
| 191 | } |
| 192 | |
Lucas Dupin | aaac2cb | 2018-06-08 14:11:41 -0700 | [diff] [blame] | 193 | @Test |
| 194 | public void onPanelExpansionChanged_neverTranslatesBouncerWhenLaunchingApp() { |
| 195 | when(mStatusBar.isInLaunchTransition()).thenReturn(true); |
| 196 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(KeyguardBouncer.EXPANSION_VISIBLE, |
| 197 | false /* tracking */); |
| 198 | verify(mBouncer, never()).setExpansion(anyFloat()); |
| 199 | } |
| 200 | |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame^] | 201 | @Test |
| 202 | public void onQsExpansionChanged_lockVisibleOnlyWhenCollapsed() { |
| 203 | when(mStatusBarStateController.getState()).thenReturn(StatusBarState.KEYGUARD); |
| 204 | mStatusBarKeyguardViewManager.onQsExpansionChanged(0); |
| 205 | verify(mLockIconContainer).setVisibility(eq(View.VISIBLE)); |
| 206 | |
| 207 | reset(mNotificationPanelView); |
| 208 | when(mNotificationPanelView.isQsExpanded()).thenReturn(true); |
| 209 | mStatusBarKeyguardViewManager.onQsExpansionChanged(1f); |
| 210 | verify(mLockIconContainer).setVisibility(eq(View.INVISIBLE)); |
| 211 | } |
| 212 | |
| 213 | @Test |
| 214 | public void onQsExpansionChanged_lockInvisibleWhenAnimatingAway() { |
| 215 | when(mBouncer.isShowing()).thenReturn(true); |
| 216 | mStatusBarKeyguardViewManager.onQsExpansionChanged(0); |
| 217 | verify(mLockIconContainer).setVisibility(eq(View.VISIBLE)); |
| 218 | |
| 219 | when(mBouncer.isAnimatingAway()).thenReturn(true); |
| 220 | mStatusBarKeyguardViewManager.onQsExpansionChanged(0f); |
| 221 | verify(mLockIconContainer).setVisibility(eq(View.INVISIBLE)); |
| 222 | } |
| 223 | |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 224 | private class TestableStatusBarKeyguardViewManager extends StatusBarKeyguardViewManager { |
| 225 | |
| 226 | public TestableStatusBarKeyguardViewManager(Context context, |
| 227 | ViewMediatorCallback callback, |
| 228 | LockPatternUtils lockPatternUtils) { |
| 229 | super(context, callback, lockPatternUtils); |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public void registerStatusBar(StatusBar statusBar, ViewGroup container, |
| 234 | NotificationPanelView notificationPanelView, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 235 | BiometricUnlockController fingerprintUnlockController, |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame^] | 236 | DismissCallbackRegistry dismissCallbackRegistry, |
| 237 | ViewGroup lockIconContainer) { |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 238 | super.registerStatusBar(statusBar, container, notificationPanelView, |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame^] | 239 | fingerprintUnlockController, dismissCallbackRegistry, lockIconContainer); |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 240 | mBouncer = StatusBarKeyguardViewManagerTest.this.mBouncer; |
| 241 | } |
| 242 | } |
| 243 | } |