blob: f8b9e6879dcf954b392c73d5fce748d9b2d387e7 [file] [log] [blame]
yoshiki iguchi4e30e762018-02-06 12:09:23 +09001/*
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
17package com.android.systemui.statusbar.phone;
18
Ned Burnsf81c4c42019-01-07 14:10:43 -050019import static junit.framework.Assert.assertFalse;
20import static junit.framework.Assert.assertTrue;
21
Dieter Hsubb0fdbc2019-03-08 20:56:28 +080022import static org.mockito.ArgumentMatchers.anyInt;
Ned Burnsf81c4c42019-01-07 14:10:43 -050023import static org.mockito.Mockito.when;
24
Dieter Hsubb0fdbc2019-03-08 20:56:28 +080025import android.content.Context;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090026import android.testing.AndroidTestingRunner;
27import android.testing.TestableLooper;
Ned Burnsf81c4c42019-01-07 14:10:43 -050028import android.view.View;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090029
Brett Chabot84151d92019-02-27 15:37:59 -080030import androidx.test.filters.SmallTest;
31
Selim Cinekc3fec682019-06-06 18:11:07 -070032import com.android.systemui.plugins.statusbar.StatusBarStateController;
Kevind4f66a42018-08-03 13:12:51 -070033import com.android.systemui.statusbar.AlertingNotificationManager;
34import com.android.systemui.statusbar.AlertingNotificationManagerTest;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090035import com.android.systemui.statusbar.notification.VisualStabilityManager;
Ned Burnsf81c4c42019-01-07 14:10:43 -050036import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Dieter Hsubb0fdbc2019-03-08 20:56:28 +080037import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090038
39import org.junit.Before;
40import org.junit.Rule;
41import org.junit.Test;
42import org.junit.runner.RunWith;
43import org.mockito.Mock;
44import org.mockito.junit.MockitoJUnit;
45import org.mockito.junit.MockitoRule;
46
yoshiki iguchi4e30e762018-02-06 12:09:23 +090047@SmallTest
48@RunWith(AndroidTestingRunner.class)
49@TestableLooper.RunWithLooper
Kevind4f66a42018-08-03 13:12:51 -070050public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
yoshiki iguchi4e30e762018-02-06 12:09:23 +090051 @Rule public MockitoRule rule = MockitoJUnit.rule();
52
yoshiki iguchi4e30e762018-02-06 12:09:23 +090053 private HeadsUpManagerPhone mHeadsUpManager;
54
yoshiki iguchi4e30e762018-02-06 12:09:23 +090055 @Mock private NotificationGroupManager mGroupManager;
56 @Mock private View mStatusBarWindowView;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090057 @Mock private VisualStabilityManager mVSManager;
Kevind4f66a42018-08-03 13:12:51 -070058 @Mock private StatusBar mBar;
Selim Cinekc3fec682019-06-06 18:11:07 -070059 @Mock private StatusBarStateController mStatusBarStateController;
Selim Cinekd21232e2019-06-20 14:15:59 -070060 @Mock private KeyguardBypassController mBypassController;
Selim Cinekc3fec682019-06-06 18:11:07 -070061 private boolean mLivesPastNormalTime;
Kevind4f66a42018-08-03 13:12:51 -070062
Dieter Hsubb0fdbc2019-03-08 20:56:28 +080063 private final class TestableHeadsUpManagerPhone extends HeadsUpManagerPhone {
64 TestableHeadsUpManagerPhone(Context context, View statusBarWindowView,
65 NotificationGroupManager groupManager, StatusBar bar,
Selim Cinekc3fec682019-06-06 18:11:07 -070066 VisualStabilityManager vsManager,
Selim Cinekd21232e2019-06-20 14:15:59 -070067 StatusBarStateController statusBarStateController,
68 KeyguardBypassController keyguardBypassController) {
69 super(context, statusBarStateController, keyguardBypassController);
Selim Cinekc3fec682019-06-06 18:11:07 -070070 setUp(statusBarWindowView, groupManager, bar, vsManager);
Dieter Hsubb0fdbc2019-03-08 20:56:28 +080071 mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME;
72 mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME;
Selim Cinekc3fec682019-06-06 18:11:07 -070073 mAutoDismissNotificationDecayDozing = TEST_AUTO_DISMISS_TIME;
Dieter Hsubb0fdbc2019-03-08 20:56:28 +080074 }
75 }
76
Kevind4f66a42018-08-03 13:12:51 -070077 protected AlertingNotificationManager createAlertingNotificationManager() {
78 return mHeadsUpManager;
79 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +090080
81 @Before
82 public void setUp() {
Selim Cinekc3fec682019-06-06 18:11:07 -070083 AccessibilityManagerWrapper accessibilityMgr =
Dieter Hsubb0fdbc2019-03-08 20:56:28 +080084 mDependency.injectMockDependency(AccessibilityManagerWrapper.class);
Selim Cinekc3fec682019-06-06 18:11:07 -070085 when(accessibilityMgr.getRecommendedTimeoutMillis(anyInt(), anyInt()))
Dieter Hsubb0fdbc2019-03-08 20:56:28 +080086 .thenReturn(TEST_AUTO_DISMISS_TIME);
yoshiki iguchi4e30e762018-02-06 12:09:23 +090087 when(mVSManager.isReorderingAllowed()).thenReturn(true);
Dieter Hsubb0fdbc2019-03-08 20:56:28 +080088 mHeadsUpManager = new TestableHeadsUpManagerPhone(mContext, mStatusBarWindowView,
Selim Cinekd21232e2019-06-20 14:15:59 -070089 mGroupManager, mBar, mVSManager, mStatusBarStateController, mBypassController);
Kevind4f66a42018-08-03 13:12:51 -070090 super.setUp();
91 mHeadsUpManager.mHandler = mTestHandler;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090092 }
93
94 @Test
Kevind4f66a42018-08-03 13:12:51 -070095 public void testSnooze() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +090096 mHeadsUpManager.showNotification(mEntry);
97
Kevind4f66a42018-08-03 13:12:51 -070098 mHeadsUpManager.snooze();
yoshiki iguchi4e30e762018-02-06 12:09:23 +090099
Kevind4f66a42018-08-03 13:12:51 -0700100 assertTrue(mHeadsUpManager.isSnoozed(mEntry.notification.getPackageName()));
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900101 }
102
103 @Test
Kevind4f66a42018-08-03 13:12:51 -0700104 public void testSwipedOutNotification() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900105 mHeadsUpManager.showNotification(mEntry);
Kevind4f66a42018-08-03 13:12:51 -0700106 mHeadsUpManager.addSwipedOutNotification(mEntry.key);
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900107
Kevind4f66a42018-08-03 13:12:51 -0700108 // Remove should succeed because the notification is swiped out
109 mHeadsUpManager.removeNotification(mEntry.key, false /* releaseImmediately */);
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900110
Kevina97ea052018-09-11 13:53:18 -0700111 assertFalse(mHeadsUpManager.isAlerting(mEntry.key));
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900112 }
Kevina5ff1fa2018-08-21 16:35:48 -0700113
114 @Test
Kevina97ea052018-09-11 13:53:18 -0700115 public void testCanRemoveImmediately_swipedOut() {
Kevina5ff1fa2018-08-21 16:35:48 -0700116 mHeadsUpManager.showNotification(mEntry);
117 mHeadsUpManager.addSwipedOutNotification(mEntry.key);
118
Kevina97ea052018-09-11 13:53:18 -0700119 // Notification is swiped so it can be immediately removed.
120 assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key));
Kevina5ff1fa2018-08-21 16:35:48 -0700121 }
122
123 @Test
Kevina97ea052018-09-11 13:53:18 -0700124 public void testCanRemoveImmediately_notTopEntry() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500125 NotificationEntry laterEntry = new NotificationEntry(createNewNotification(1));
Evan Laird94492852018-10-25 13:43:01 -0400126 laterEntry.setRow(mRow);
Kevina5ff1fa2018-08-21 16:35:48 -0700127 mHeadsUpManager.showNotification(mEntry);
128 mHeadsUpManager.showNotification(laterEntry);
129
Kevina97ea052018-09-11 13:53:18 -0700130 // Notification is "behind" a higher priority notification so we can remove it immediately.
131 assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key));
Kevina5ff1fa2018-08-21 16:35:48 -0700132 }
Selim Cinekc3fec682019-06-06 18:11:07 -0700133
134
135 @Test
136 public void testExtendHeadsUp() {
137 when(mStatusBarStateController.isDozing()).thenReturn(true);
138 mHeadsUpManager.showNotification(mEntry);
139 Runnable pastNormalTimeRunnable =
140 () -> mLivesPastNormalTime = mHeadsUpManager.isAlerting(mEntry.key);
141 mTestHandler.postDelayed(pastNormalTimeRunnable,
142 mHeadsUpManager.mAutoDismissNotificationDecayDozing +
143 mHeadsUpManager.mExtensionTime / 2);
144 mTestHandler.postDelayed(TEST_TIMEOUT_RUNNABLE, TEST_TIMEOUT_TIME);
145
146 mHeadsUpManager.extendHeadsUp();
147
148 // Wait for normal time runnable and extended remove runnable and process them on arrival.
149 TestableLooper.get(this).processMessages(2);
150
151 assertFalse("Test timed out", mTimedOut);
152 assertTrue("Pulse was not extended", mLivesPastNormalTime);
153 assertFalse(mHeadsUpManager.isAlerting(mEntry.key));
154 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900155}