Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [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 | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 21 | import static org.mockito.ArgumentMatchers.eq; |
| 22 | import static org.mockito.Mockito.inOrder; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 23 | import static org.mockito.Mockito.mock; |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 24 | import static org.mockito.Mockito.never; |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 25 | import static org.mockito.Mockito.spy; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 26 | import static org.mockito.Mockito.verify; |
| 27 | import static org.mockito.Mockito.when; |
| 28 | |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 29 | import android.app.StatusBarManager; |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 30 | import android.hardware.biometrics.BiometricSourceType; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 31 | import android.testing.AndroidTestingRunner; |
| 32 | import android.testing.TestableLooper; |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 33 | import android.view.MotionEvent; |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 34 | import android.view.View; |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 35 | import android.view.ViewGroup; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 36 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 37 | import androidx.test.filters.SmallTest; |
| 38 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 39 | import com.android.keyguard.KeyguardStatusView; |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 40 | import com.android.keyguard.KeyguardUpdateMonitor; |
Robert Snoeberger | be35b76 | 2019-03-15 14:33:02 -0400 | [diff] [blame] | 41 | import com.android.systemui.SystemUIFactory; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 42 | import com.android.systemui.SysuiTestCase; |
Dave Mankoff | 781ef7e | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 43 | import com.android.systemui.plugins.FalsingManager; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 44 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 45 | import com.android.systemui.statusbar.KeyguardAffordanceView; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 46 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 47 | import com.android.systemui.statusbar.NotificationShelf; |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 48 | import com.android.systemui.statusbar.PulseExpansionHandler; |
| 49 | import com.android.systemui.statusbar.StatusBarStateControllerImpl; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 50 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 51 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 52 | import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 53 | import com.android.systemui.statusbar.notification.stack.NotificationRoundnessManager; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 54 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
| 55 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 56 | import com.android.systemui.statusbar.policy.ZenModeController; |
Robert Snoeberger | be35b76 | 2019-03-15 14:33:02 -0400 | [diff] [blame] | 57 | import com.android.systemui.util.InjectionInflationController; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 58 | |
| 59 | import org.junit.Before; |
| 60 | import org.junit.Test; |
| 61 | import org.junit.runner.RunWith; |
| 62 | import org.mockito.InOrder; |
| 63 | import org.mockito.Mock; |
| 64 | import org.mockito.MockitoAnnotations; |
| 65 | |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 66 | import java.util.function.Consumer; |
| 67 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 68 | @SmallTest |
| 69 | @RunWith(AndroidTestingRunner.class) |
| 70 | @TestableLooper.RunWithLooper |
| 71 | public class NotificationPanelViewTest extends SysuiTestCase { |
| 72 | |
| 73 | @Mock |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 74 | private StatusBar mStatusBar; |
| 75 | @Mock |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 76 | private SysuiStatusBarStateController mStatusBarStateController; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 77 | @Mock |
| 78 | private NotificationStackScrollLayout mNotificationStackScrollLayout; |
| 79 | @Mock |
| 80 | private KeyguardStatusView mKeyguardStatusView; |
Lucas Dupin | c97d88f | 2019-01-17 16:34:22 -0800 | [diff] [blame] | 81 | @Mock |
Lucas Dupin | 07ed3df | 2019-03-26 21:23:59 -0700 | [diff] [blame] | 82 | private KeyguardBottomAreaView mKeyguardBottomArea; |
| 83 | @Mock |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 84 | private KeyguardBottomAreaView mQsFrame; |
| 85 | @Mock |
| 86 | private ViewGroup mBigClockContainer; |
| 87 | @Mock |
| 88 | private ScrimController mScrimController; |
| 89 | @Mock |
| 90 | private NotificationIconAreaController mNotificationAreaController; |
| 91 | @Mock |
| 92 | private HeadsUpManagerPhone mHeadsUpManager; |
| 93 | @Mock |
| 94 | private NotificationShelf mNotificationShelf; |
| 95 | @Mock |
| 96 | private NotificationGroupManager mGroupManager; |
| 97 | @Mock |
Lucas Dupin | c97d88f | 2019-01-17 16:34:22 -0800 | [diff] [blame] | 98 | private KeyguardStatusBarView mKeyguardStatusBar; |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 99 | @Mock |
| 100 | private HeadsUpTouchHelper.Callback mHeadsUpCallback; |
| 101 | @Mock |
| 102 | private PanelBar mPanelBar; |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 103 | @Mock |
| 104 | private KeyguardAffordanceHelper mAffordanceHelper; |
Dave Mankoff | 781ef7e | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 105 | @Mock |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 106 | private KeyguardUpdateMonitor mUpdateMonitor; |
| 107 | @Mock |
Dave Mankoff | 781ef7e | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 108 | private FalsingManager mFalsingManager; |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 109 | @Mock |
| 110 | private KeyguardBypassController mKeyguardBypassController; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 111 | private NotificationPanelView mNotificationPanelView; |
| 112 | |
| 113 | @Before |
| 114 | public void setup() { |
| 115 | MockitoAnnotations.initMocks(this); |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 116 | when(mNotificationStackScrollLayout.getHeight()).thenReturn(1000); |
| 117 | when(mNotificationStackScrollLayout.getHeadsUpCallback()).thenReturn(mHeadsUpCallback); |
| 118 | when(mHeadsUpCallback.getContext()).thenReturn(mContext); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 119 | mDependency.injectTestDependency(StatusBarStateController.class, |
| 120 | mStatusBarStateController); |
| 121 | mDependency.injectMockDependency(ShadeController.class); |
| 122 | mDependency.injectMockDependency(NotificationLockscreenUserManager.class); |
| 123 | mDependency.injectMockDependency(ConfigurationController.class); |
| 124 | mDependency.injectMockDependency(ZenModeController.class); |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 125 | NotificationWakeUpCoordinator coordinator = |
Selim Cinek | 15af976 | 2019-03-19 18:32:37 -0700 | [diff] [blame] | 126 | new NotificationWakeUpCoordinator(mContext, |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 127 | mock(HeadsUpManagerPhone.class), |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 128 | new StatusBarStateControllerImpl(), |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 129 | mKeyguardBypassController); |
Selim Cinek | b8cc6ef | 2019-06-14 16:37:53 -0700 | [diff] [blame] | 130 | PulseExpansionHandler expansionHandler = new PulseExpansionHandler(mContext, coordinator, |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 131 | mKeyguardBypassController, mHeadsUpManager, |
Lucas Dupin | e7ff7be | 2019-09-17 11:19:53 -0400 | [diff] [blame] | 132 | mock(NotificationRoundnessManager.class), mStatusBarStateController); |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 133 | mNotificationPanelView = new TestableNotificationPanelView(coordinator, expansionHandler, |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 134 | mKeyguardBypassController); |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 135 | mNotificationPanelView.setHeadsUpManager(mHeadsUpManager); |
| 136 | mNotificationPanelView.setBar(mPanelBar); |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 137 | |
| 138 | when(mKeyguardBottomArea.getLeftView()).thenReturn(mock(KeyguardAffordanceView.class)); |
| 139 | when(mKeyguardBottomArea.getRightView()).thenReturn(mock(KeyguardAffordanceView.class)); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @Test |
| 143 | public void testSetDozing_notifiesNsslAndStateController() { |
| 144 | mNotificationPanelView.setDozing(true /* dozing */, true /* animate */, null /* touch */); |
| 145 | InOrder inOrder = inOrder(mNotificationStackScrollLayout, mStatusBarStateController); |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 146 | inOrder.verify(mNotificationStackScrollLayout).setDozing(eq(true), eq(true), eq(null)); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 147 | inOrder.verify(mStatusBarStateController).setDozeAmount(eq(1f), eq(true)); |
| 148 | } |
| 149 | |
| 150 | @Test |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 151 | public void testSetExpandedHeight() { |
| 152 | mNotificationPanelView.setExpandedHeight(200); |
| 153 | assertThat((int) mNotificationPanelView.getExpandedHeight()).isEqualTo(200); |
| 154 | } |
| 155 | |
| 156 | @Test |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 157 | public void testAffordanceLaunchingListener() { |
| 158 | Consumer<Boolean> listener = spy((showing) -> { }); |
| 159 | mNotificationPanelView.setExpandedFraction(1f); |
| 160 | mNotificationPanelView.setLaunchAffordanceListener(listener); |
| 161 | mNotificationPanelView.launchCamera(false /* animate */, |
| 162 | StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP); |
| 163 | verify(listener).accept(eq(true)); |
| 164 | |
| 165 | mNotificationPanelView.onAffordanceLaunchEnded(); |
| 166 | verify(listener).accept(eq(false)); |
| 167 | } |
| 168 | |
| 169 | @Test |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 170 | public void testOnTouchEvent_expansionCanBeBlocked() { |
| 171 | mNotificationPanelView.onTouchEvent(MotionEvent.obtain(0L /* downTime */, |
| 172 | 0L /* eventTime */, MotionEvent.ACTION_DOWN, 0f /* x */, 0f /* y */, |
| 173 | 0 /* metaState */)); |
| 174 | mNotificationPanelView.onTouchEvent(MotionEvent.obtain(0L /* downTime */, |
| 175 | 0L /* eventTime */, MotionEvent.ACTION_MOVE, 0f /* x */, 200f /* y */, |
| 176 | 0 /* metaState */)); |
| 177 | assertThat((int) mNotificationPanelView.getExpandedHeight()).isEqualTo(200); |
| 178 | assertThat(mNotificationPanelView.isTrackingBlocked()).isFalse(); |
| 179 | |
| 180 | mNotificationPanelView.blockExpansionForCurrentTouch(); |
| 181 | mNotificationPanelView.onTouchEvent(MotionEvent.obtain(0L /* downTime */, |
| 182 | 0L /* eventTime */, MotionEvent.ACTION_MOVE, 0f /* x */, 300f /* y */, |
| 183 | 0 /* metaState */)); |
| 184 | // Expansion should not have changed because it was blocked |
| 185 | assertThat((int) mNotificationPanelView.getExpandedHeight()).isEqualTo(200); |
| 186 | assertThat(mNotificationPanelView.isTrackingBlocked()).isTrue(); |
| 187 | |
| 188 | mNotificationPanelView.onTouchEvent(MotionEvent.obtain(0L /* downTime */, |
| 189 | 0L /* eventTime */, MotionEvent.ACTION_UP, 0f /* x */, 300f /* y */, |
| 190 | 0 /* metaState */)); |
| 191 | assertThat(mNotificationPanelView.isTrackingBlocked()).isFalse(); |
| 192 | } |
| 193 | |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 194 | @Test |
| 195 | public void testKeyguardStatusBarVisibility_hiddenForBypass() { |
| 196 | when(mUpdateMonitor.shouldListenForFace()).thenReturn(true); |
| 197 | mNotificationPanelView.mKeyguardUpdateCallback.onBiometricRunningStateChanged(true, |
| 198 | BiometricSourceType.FACE); |
| 199 | verify(mKeyguardStatusBar, never()).setVisibility(View.VISIBLE); |
| 200 | |
| 201 | when(mKeyguardBypassController.getBypassEnabled()).thenReturn(true); |
| 202 | mNotificationPanelView.mKeyguardUpdateCallback.onFinishedGoingToSleep(0); |
| 203 | mNotificationPanelView.mKeyguardUpdateCallback.onBiometricRunningStateChanged(true, |
| 204 | BiometricSourceType.FACE); |
| 205 | verify(mKeyguardStatusBar, never()).setVisibility(View.VISIBLE); |
| 206 | } |
| 207 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 208 | private class TestableNotificationPanelView extends NotificationPanelView { |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 209 | TestableNotificationPanelView(NotificationWakeUpCoordinator coordinator, |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 210 | PulseExpansionHandler expansionHandler, |
| 211 | KeyguardBypassController bypassController) { |
Robert Snoeberger | be35b76 | 2019-03-15 14:33:02 -0400 | [diff] [blame] | 212 | super(NotificationPanelViewTest.this.mContext, null, |
| 213 | new InjectionInflationController( |
| 214 | SystemUIFactory.getInstance().getRootComponent()), |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 215 | coordinator, expansionHandler, mock(DynamicPrivacyController.class), |
Dave Mankoff | 781ef7e | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 216 | bypassController, |
| 217 | mFalsingManager); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 218 | mNotificationStackScroller = mNotificationStackScrollLayout; |
| 219 | mKeyguardStatusView = NotificationPanelViewTest.this.mKeyguardStatusView; |
Lucas Dupin | c97d88f | 2019-01-17 16:34:22 -0800 | [diff] [blame] | 220 | mKeyguardStatusBar = NotificationPanelViewTest.this.mKeyguardStatusBar; |
Lucas Dupin | 07ed3df | 2019-03-26 21:23:59 -0700 | [diff] [blame] | 221 | mKeyguardBottomArea = NotificationPanelViewTest.this.mKeyguardBottomArea; |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 222 | mBigClockContainer = NotificationPanelViewTest.this.mBigClockContainer; |
| 223 | mQsFrame = NotificationPanelViewTest.this.mQsFrame; |
Lucas Dupin | 23964c7 | 2019-05-21 16:12:45 -0700 | [diff] [blame] | 224 | mAffordanceHelper = NotificationPanelViewTest.this.mAffordanceHelper; |
Lucas Dupin | 6262222 | 2019-08-29 14:46:29 -0700 | [diff] [blame] | 225 | mUpdateMonitor = NotificationPanelViewTest.this.mUpdateMonitor; |
Lucas Dupin | d61974d | 2019-03-29 16:09:26 -0700 | [diff] [blame] | 226 | initDependencies(NotificationPanelViewTest.this.mStatusBar, |
| 227 | NotificationPanelViewTest.this.mGroupManager, |
| 228 | NotificationPanelViewTest.this.mNotificationShelf, |
| 229 | NotificationPanelViewTest.this.mHeadsUpManager, |
| 230 | NotificationPanelViewTest.this.mNotificationAreaController, |
| 231 | NotificationPanelViewTest.this.mScrimController); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | } |