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