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