yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [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 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 19 | import static junit.framework.Assert.assertFalse; |
| 20 | import static junit.framework.Assert.assertTrue; |
| 21 | |
Dieter Hsu | bb0fdbc | 2019-03-08 20:56:28 +0800 | [diff] [blame] | 22 | import static org.mockito.ArgumentMatchers.anyInt; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 23 | import static org.mockito.Mockito.when; |
| 24 | |
Dieter Hsu | bb0fdbc | 2019-03-08 20:56:28 +0800 | [diff] [blame] | 25 | import android.content.Context; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 26 | import android.testing.AndroidTestingRunner; |
| 27 | import android.testing.TestableLooper; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 28 | import android.view.View; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 29 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 30 | import androidx.test.filters.SmallTest; |
| 31 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 32 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 33 | import com.android.systemui.statusbar.AlertingNotificationManager; |
| 34 | import com.android.systemui.statusbar.AlertingNotificationManagerTest; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 35 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 36 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Dieter Hsu | bb0fdbc | 2019-03-08 20:56:28 +0800 | [diff] [blame] | 37 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 38 | |
| 39 | import org.junit.Before; |
| 40 | import org.junit.Rule; |
| 41 | import org.junit.Test; |
| 42 | import org.junit.runner.RunWith; |
| 43 | import org.mockito.Mock; |
| 44 | import org.mockito.junit.MockitoJUnit; |
| 45 | import org.mockito.junit.MockitoRule; |
| 46 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 47 | @SmallTest |
| 48 | @RunWith(AndroidTestingRunner.class) |
| 49 | @TestableLooper.RunWithLooper |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 50 | public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 51 | @Rule public MockitoRule rule = MockitoJUnit.rule(); |
| 52 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 53 | private HeadsUpManagerPhone mHeadsUpManager; |
| 54 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 55 | @Mock private NotificationGroupManager mGroupManager; |
| 56 | @Mock private View mStatusBarWindowView; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 57 | @Mock private VisualStabilityManager mVSManager; |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 58 | @Mock private StatusBar mBar; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 59 | @Mock private StatusBarStateController mStatusBarStateController; |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 60 | @Mock private KeyguardBypassController mBypassController; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 61 | private boolean mLivesPastNormalTime; |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 62 | |
Dieter Hsu | bb0fdbc | 2019-03-08 20:56:28 +0800 | [diff] [blame] | 63 | private final class TestableHeadsUpManagerPhone extends HeadsUpManagerPhone { |
| 64 | TestableHeadsUpManagerPhone(Context context, View statusBarWindowView, |
| 65 | NotificationGroupManager groupManager, StatusBar bar, |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 66 | VisualStabilityManager vsManager, |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 67 | StatusBarStateController statusBarStateController, |
| 68 | KeyguardBypassController keyguardBypassController) { |
| 69 | super(context, statusBarStateController, keyguardBypassController); |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 70 | setUp(statusBarWindowView, groupManager, bar, vsManager); |
Dieter Hsu | bb0fdbc | 2019-03-08 20:56:28 +0800 | [diff] [blame] | 71 | mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME; |
| 72 | mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 73 | mAutoDismissNotificationDecayDozing = TEST_AUTO_DISMISS_TIME; |
Dieter Hsu | bb0fdbc | 2019-03-08 20:56:28 +0800 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 77 | protected AlertingNotificationManager createAlertingNotificationManager() { |
| 78 | return mHeadsUpManager; |
| 79 | } |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 80 | |
| 81 | @Before |
| 82 | public void setUp() { |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 83 | AccessibilityManagerWrapper accessibilityMgr = |
Dieter Hsu | bb0fdbc | 2019-03-08 20:56:28 +0800 | [diff] [blame] | 84 | mDependency.injectMockDependency(AccessibilityManagerWrapper.class); |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 85 | when(accessibilityMgr.getRecommendedTimeoutMillis(anyInt(), anyInt())) |
Dieter Hsu | bb0fdbc | 2019-03-08 20:56:28 +0800 | [diff] [blame] | 86 | .thenReturn(TEST_AUTO_DISMISS_TIME); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 87 | when(mVSManager.isReorderingAllowed()).thenReturn(true); |
Dieter Hsu | bb0fdbc | 2019-03-08 20:56:28 +0800 | [diff] [blame] | 88 | mHeadsUpManager = new TestableHeadsUpManagerPhone(mContext, mStatusBarWindowView, |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 89 | mGroupManager, mBar, mVSManager, mStatusBarStateController, mBypassController); |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 90 | super.setUp(); |
| 91 | mHeadsUpManager.mHandler = mTestHandler; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | @Test |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 95 | public void testSnooze() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 96 | mHeadsUpManager.showNotification(mEntry); |
| 97 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 98 | mHeadsUpManager.snooze(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 99 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 100 | assertTrue(mHeadsUpManager.isSnoozed(mEntry.notification.getPackageName())); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Test |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 104 | public void testSwipedOutNotification() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 105 | mHeadsUpManager.showNotification(mEntry); |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 106 | mHeadsUpManager.addSwipedOutNotification(mEntry.key); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 107 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 108 | // Remove should succeed because the notification is swiped out |
| 109 | mHeadsUpManager.removeNotification(mEntry.key, false /* releaseImmediately */); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 110 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 111 | assertFalse(mHeadsUpManager.isAlerting(mEntry.key)); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 112 | } |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 113 | |
| 114 | @Test |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 115 | public void testCanRemoveImmediately_swipedOut() { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 116 | mHeadsUpManager.showNotification(mEntry); |
| 117 | mHeadsUpManager.addSwipedOutNotification(mEntry.key); |
| 118 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 119 | // Notification is swiped so it can be immediately removed. |
| 120 | assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key)); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Test |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 124 | public void testCanRemoveImmediately_notTopEntry() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 125 | NotificationEntry laterEntry = new NotificationEntry(createNewNotification(1)); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 126 | laterEntry.setRow(mRow); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 127 | mHeadsUpManager.showNotification(mEntry); |
| 128 | mHeadsUpManager.showNotification(laterEntry); |
| 129 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 130 | // Notification is "behind" a higher priority notification so we can remove it immediately. |
| 131 | assertTrue(mHeadsUpManager.canRemoveImmediately(mEntry.key)); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 132 | } |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 133 | |
| 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 iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 155 | } |