diff options
| author | 2024-12-10 17:41:57 +0000 | |
|---|---|---|
| committer | 2024-12-10 17:41:57 +0000 | |
| commit | eaaa7eca3bff31cb648c209838c5b21a0920c3d5 (patch) | |
| tree | 5dad064dcb59929cc9e8339905fed1ee60fb2d09 | |
| parent | 1af0001d0ae581366885327252e52540e666e901 (diff) | |
| parent | 6c7d2dd2ef8650435b2c1b01eb83f846f68bf501 (diff) | |
Merge "Convert StatusBarNotificationPresenterTest to Kotlin" into main
2 files changed, 385 insertions, 379 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java deleted file mode 100644 index 41782a123f14..000000000000 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java +++ /dev/null @@ -1,379 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.systemui.statusbar.phone; - -import static android.view.Display.DEFAULT_DISPLAY; - -import static com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.BUBBLE; -import static com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.PEEK; -import static com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.PULSE; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.app.Notification; -import android.app.PendingIntent; -import android.app.StatusBarManager; -import android.platform.test.annotations.DisableFlags; -import android.platform.test.annotations.EnableFlags; -import android.testing.TestableLooper; -import android.testing.TestableLooper.RunWithLooper; - -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.SmallTest; - -import com.android.systemui.InitController; -import com.android.systemui.SysuiTestCase; -import com.android.systemui.plugins.ActivityStarter; -import com.android.systemui.plugins.statusbar.StatusBarStateController; -import com.android.systemui.power.domain.interactor.PowerInteractor; -import com.android.systemui.settings.FakeDisplayTracker; -import com.android.systemui.shade.NotificationShadeWindowView; -import com.android.systemui.shade.QuickSettingsController; -import com.android.systemui.shade.ShadeController; -import com.android.systemui.shade.ShadeViewController; -import com.android.systemui.shade.domain.interactor.PanelExpansionInteractor; -import com.android.systemui.statusbar.CommandQueue; -import com.android.systemui.statusbar.LockscreenShadeTransitionController; -import com.android.systemui.statusbar.NotificationLockscreenUserManager; -import com.android.systemui.statusbar.NotificationMediaManager; -import com.android.systemui.statusbar.NotificationRemoteInputManager; -import com.android.systemui.statusbar.NotificationShadeWindowController; -import com.android.systemui.statusbar.SysuiStatusBarStateController; -import com.android.systemui.statusbar.notification.DynamicPrivacyController; -import com.android.systemui.statusbar.notification.collection.NotificationEntry; -import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; -import com.android.systemui.statusbar.notification.collection.render.NotifShadeEventSource; -import com.android.systemui.statusbar.notification.domain.interactor.NotificationAlertsInteractor; -import com.android.systemui.statusbar.notification.interruption.NotificationInterruptSuppressor; -import com.android.systemui.statusbar.notification.interruption.VisualInterruptionCondition; -import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionProvider; -import com.android.systemui.statusbar.notification.interruption.VisualInterruptionFilter; -import com.android.systemui.statusbar.notification.interruption.VisualInterruptionRefactor; -import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType; -import com.android.systemui.statusbar.notification.row.NotificationGutsManager; -import com.android.systemui.statusbar.notification.stack.NotificationListContainer; -import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; -import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController; -import com.android.systemui.statusbar.notification.headsup.HeadsUpManager; -import com.android.systemui.statusbar.policy.KeyguardStateController; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; - -import java.util.List; -import java.util.Set; - -@SmallTest -@RunWith(AndroidJUnit4.class) -@RunWithLooper() -public class StatusBarNotificationPresenterTest extends SysuiTestCase { - private StatusBarNotificationPresenter mStatusBarNotificationPresenter; - private final VisualInterruptionDecisionProvider mVisualInterruptionDecisionProvider = - mock(VisualInterruptionDecisionProvider.class); - private NotificationInterruptSuppressor mInterruptSuppressor; - private VisualInterruptionCondition mAlertsDisabledCondition; - private VisualInterruptionCondition mVrModeCondition; - private VisualInterruptionFilter mNeedsRedactionFilter; - private VisualInterruptionCondition mPanelsDisabledCondition; - private CommandQueue mCommandQueue; - private final ShadeController mShadeController = mock(ShadeController.class); - private final NotificationAlertsInteractor mNotificationAlertsInteractor = - mock(NotificationAlertsInteractor.class); - private final KeyguardStateController mKeyguardStateController = - mock(KeyguardStateController.class); - - @Before - public void setup() { - mCommandQueue = new CommandQueue(mContext, new FakeDisplayTracker(mContext)); - mDependency.injectTestDependency(StatusBarStateController.class, - mock(SysuiStatusBarStateController.class)); - mDependency.injectTestDependency(ShadeController.class, mShadeController); - mDependency.injectMockDependency(NotificationRemoteInputManager.Callback.class); - mDependency.injectMockDependency(NotificationShadeWindowController.class); - - when(mNotificationAlertsInteractor.areNotificationAlertsEnabled()).thenReturn(true); - - createPresenter(); - if (VisualInterruptionRefactor.isEnabled()) { - verifyAndCaptureSuppressors(); - } else { - verifyAndCaptureLegacySuppressor(); - } - } - - @Test - @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testInit_refactorDisabled() { - assertFalse(VisualInterruptionRefactor.isEnabled()); - assertNull(mAlertsDisabledCondition); - assertNull(mVrModeCondition); - assertNull(mNeedsRedactionFilter); - assertNull(mPanelsDisabledCondition); - assertNotNull(mInterruptSuppressor); - } - - @Test - @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testInit_refactorEnabled() { - assertTrue(VisualInterruptionRefactor.isEnabled()); - assertNotNull(mAlertsDisabledCondition); - assertNotNull(mVrModeCondition); - assertNotNull(mNeedsRedactionFilter); - assertNotNull(mPanelsDisabledCondition); - assertNull(mInterruptSuppressor); - } - - @Test - @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testNoSuppressHeadsUp_default_refactorDisabled() { - assertFalse(mInterruptSuppressor.suppressAwakeHeadsUp(createNotificationEntry())); - } - - @Test - @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testNoSuppressHeadsUp_default_refactorEnabled() { - assertFalse(mAlertsDisabledCondition.shouldSuppress()); - assertFalse(mVrModeCondition.shouldSuppress()); - assertFalse(mNeedsRedactionFilter.shouldSuppress(createNotificationEntry())); - assertFalse(mAlertsDisabledCondition.shouldSuppress()); - } - - @Test - @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testSuppressHeadsUp_disabledStatusBar_refactorDisabled() { - mCommandQueue.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_EXPAND, 0, - false /* animate */); - TestableLooper.get(this).processAllMessages(); - - assertTrue("The panel should suppress heads up while disabled", - mInterruptSuppressor.suppressAwakeHeadsUp(createNotificationEntry())); - } - - @Test - @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testSuppressHeadsUp_disabledStatusBar_refactorEnabled() { - mCommandQueue.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_EXPAND, 0, - false /* animate */); - TestableLooper.get(this).processAllMessages(); - - assertTrue("The panel should suppress heads up while disabled", - mPanelsDisabledCondition.shouldSuppress()); - } - - @Test - @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testSuppressHeadsUp_disabledNotificationShade_refactorDisabled() { - mCommandQueue.disable(DEFAULT_DISPLAY, 0, StatusBarManager.DISABLE2_NOTIFICATION_SHADE, - false /* animate */); - TestableLooper.get(this).processAllMessages(); - - assertTrue("The panel should suppress interruptions while notification shade disabled", - mInterruptSuppressor.suppressAwakeHeadsUp(createNotificationEntry())); - } - - @Test - @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testSuppressHeadsUp_disabledNotificationShade_refactorEnabled() { - mCommandQueue.disable(DEFAULT_DISPLAY, 0, StatusBarManager.DISABLE2_NOTIFICATION_SHADE, - false /* animate */); - TestableLooper.get(this).processAllMessages(); - - assertTrue("The panel should suppress interruptions while notification shade disabled", - mPanelsDisabledCondition.shouldSuppress()); - } - - @Test - @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testPanelsDisabledConditionSuppressesPeek() { - final Set<VisualInterruptionType> types = mPanelsDisabledCondition.getTypes(); - assertTrue(types.contains(PEEK)); - assertFalse(types.contains(PULSE)); - assertFalse(types.contains(BUBBLE)); - } - - @Test - @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testNoSuppressHeadsUp_FSI_nonOccludedKeyguard_refactorDisabled() { - when(mKeyguardStateController.isShowing()).thenReturn(true); - when(mKeyguardStateController.isOccluded()).thenReturn(false); - - assertFalse(mInterruptSuppressor.suppressAwakeHeadsUp(createFsiNotificationEntry())); - } - - @Test - @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testNoSuppressHeadsUp_FSI_nonOccludedKeyguard_refactorEnabled() { - when(mKeyguardStateController.isShowing()).thenReturn(true); - when(mKeyguardStateController.isOccluded()).thenReturn(false); - - assertFalse(mNeedsRedactionFilter.shouldSuppress(createFsiNotificationEntry())); - - final Set<VisualInterruptionType> types = mNeedsRedactionFilter.getTypes(); - assertTrue(types.contains(PEEK)); - assertFalse(types.contains(PULSE)); - assertFalse(types.contains(BUBBLE)); - } - - @Test - @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testSuppressInterruptions_vrMode_refactorDisabled() { - mStatusBarNotificationPresenter.mVrMode = true; - - assertTrue("Vr mode should suppress interruptions", - mInterruptSuppressor.suppressAwakeInterruptions(createNotificationEntry())); - } - - @Test - @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testSuppressInterruptions_vrMode_refactorEnabled() { - mStatusBarNotificationPresenter.mVrMode = true; - - assertTrue("Vr mode should suppress interruptions", mVrModeCondition.shouldSuppress()); - - final Set<VisualInterruptionType> types = mVrModeCondition.getTypes(); - assertTrue(types.contains(PEEK)); - assertFalse(types.contains(PULSE)); - assertTrue(types.contains(BUBBLE)); - } - - @Test - @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testSuppressInterruptions_statusBarAlertsDisabled_refactorDisabled() { - when(mNotificationAlertsInteractor.areNotificationAlertsEnabled()).thenReturn(false); - - assertTrue("When alerts aren't enabled, interruptions are suppressed", - mInterruptSuppressor.suppressInterruptions(createNotificationEntry())); - } - - @Test - @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) - public void testSuppressInterruptions_statusBarAlertsDisabled_refactorEnabled() { - when(mNotificationAlertsInteractor.areNotificationAlertsEnabled()).thenReturn(false); - - assertTrue("When alerts aren't enabled, interruptions are suppressed", - mAlertsDisabledCondition.shouldSuppress()); - - final Set<VisualInterruptionType> types = mAlertsDisabledCondition.getTypes(); - assertTrue(types.contains(PEEK)); - assertTrue(types.contains(PULSE)); - assertTrue(types.contains(BUBBLE)); - } - - private void createPresenter() { - final ShadeViewController shadeViewController = mock(ShadeViewController.class); - - final NotificationShadeWindowView notificationShadeWindowView = - mock(NotificationShadeWindowView.class); - when(notificationShadeWindowView.getResources()).thenReturn(mContext.getResources()); - - NotificationStackScrollLayoutController stackScrollLayoutController = - mock(NotificationStackScrollLayoutController.class); - when(stackScrollLayoutController.getView()).thenReturn( - mock(NotificationStackScrollLayout.class)); - - final InitController initController = new InitController(); - - mStatusBarNotificationPresenter = new StatusBarNotificationPresenter( - mContext, - shadeViewController, - mock(PanelExpansionInteractor.class), - mock(QuickSettingsController.class), - mock(HeadsUpManager.class), - notificationShadeWindowView, - mock(ActivityStarter.class), - stackScrollLayoutController, - mock(DozeScrimController.class), - mock(NotificationShadeWindowController.class), - mock(DynamicPrivacyController.class), - mKeyguardStateController, - mNotificationAlertsInteractor, - mock(LockscreenShadeTransitionController.class), - mock(PowerInteractor.class), - mCommandQueue, - mock(NotificationLockscreenUserManager.class), - mock(SysuiStatusBarStateController.class), - mock(NotifShadeEventSource.class), - mock(NotificationMediaManager.class), - mock(NotificationGutsManager.class), - initController, - mVisualInterruptionDecisionProvider, - mock(NotificationRemoteInputManager.class), - mock(NotificationRemoteInputManager.Callback.class), - mock(NotificationListContainer.class)); - - initController.executePostInitTasks(); - } - - private void verifyAndCaptureSuppressors() { - mInterruptSuppressor = null; - - final ArgumentCaptor<VisualInterruptionCondition> conditionCaptor = - ArgumentCaptor.forClass(VisualInterruptionCondition.class); - verify(mVisualInterruptionDecisionProvider, times(3)).addCondition( - conditionCaptor.capture()); - final List<VisualInterruptionCondition> conditions = conditionCaptor.getAllValues(); - mAlertsDisabledCondition = conditions.get(0); - mVrModeCondition = conditions.get(1); - mPanelsDisabledCondition = conditions.get(2); - - final ArgumentCaptor<VisualInterruptionFilter> needsRedactionFilterCaptor = - ArgumentCaptor.forClass(VisualInterruptionFilter.class); - verify(mVisualInterruptionDecisionProvider).addFilter(needsRedactionFilterCaptor.capture()); - mNeedsRedactionFilter = needsRedactionFilterCaptor.getValue(); - } - - private void verifyAndCaptureLegacySuppressor() { - mAlertsDisabledCondition = null; - mVrModeCondition = null; - mNeedsRedactionFilter = null; - mPanelsDisabledCondition = null; - - final ArgumentCaptor<NotificationInterruptSuppressor> suppressorCaptor = - ArgumentCaptor.forClass(NotificationInterruptSuppressor.class); - verify(mVisualInterruptionDecisionProvider).addLegacySuppressor(suppressorCaptor.capture()); - mInterruptSuppressor = suppressorCaptor.getValue(); - } - - private NotificationEntry createNotificationEntry() { - return new NotificationEntryBuilder() - .setPkg("a") - .setOpPkg("a") - .setTag("a") - .setNotification(new Notification.Builder(getContext(), "a").build()) - .build(); - } - - private NotificationEntry createFsiNotificationEntry() { - final Notification notification = new Notification.Builder(getContext(), "a") - .setFullScreenIntent(mock(PendingIntent.class), true) - .build(); - - return new NotificationEntryBuilder() - .setPkg("a") - .setOpPkg("a") - .setTag("a") - .setNotification(notification) - .build(); - } -} diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.kt new file mode 100644 index 000000000000..31fbcb984105 --- /dev/null +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.kt @@ -0,0 +1,385 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.systemui.statusbar.phone + +import android.app.Notification +import android.app.Notification.Builder +import android.app.StatusBarManager +import android.platform.test.annotations.DisableFlags +import android.platform.test.annotations.EnableFlags +import android.testing.TestableLooper +import android.testing.TestableLooper.RunWithLooper +import android.view.Display.DEFAULT_DISPLAY +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.systemui.InitController +import com.android.systemui.SysuiTestCase +import com.android.systemui.plugins.activityStarter +import com.android.systemui.plugins.statusbar.StatusBarStateController +import com.android.systemui.power.domain.interactor.powerInteractor +import com.android.systemui.settings.FakeDisplayTracker +import com.android.systemui.shade.NotificationShadeWindowView +import com.android.systemui.shade.ShadeController +import com.android.systemui.shade.ShadeViewController +import com.android.systemui.shade.domain.interactor.panelExpansionInteractor +import com.android.systemui.statusbar.CommandQueue +import com.android.systemui.statusbar.NotificationRemoteInputManager +import com.android.systemui.statusbar.NotificationShadeWindowController +import com.android.systemui.statusbar.lockscreenShadeTransitionController +import com.android.systemui.statusbar.notification.collection.NotificationEntry +import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder +import com.android.systemui.statusbar.notification.domain.interactor.NotificationAlertsInteractor +import com.android.systemui.statusbar.notification.dynamicPrivacyController +import com.android.systemui.statusbar.notification.headsup.headsUpManager +import com.android.systemui.statusbar.notification.interruption.NotificationInterruptSuppressor +import com.android.systemui.statusbar.notification.interruption.VisualInterruptionCondition +import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionProvider +import com.android.systemui.statusbar.notification.interruption.VisualInterruptionFilter +import com.android.systemui.statusbar.notification.interruption.VisualInterruptionRefactor +import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType +import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController +import com.android.systemui.statusbar.notificationLockscreenUserManager +import com.android.systemui.statusbar.notificationRemoteInputManager +import com.android.systemui.statusbar.notificationShadeWindowController +import com.android.systemui.statusbar.policy.KeyguardStateController +import com.android.systemui.statusbar.sysuiStatusBarStateController +import com.android.systemui.testKosmos +import com.google.common.truth.Truth.assertThat +import com.google.common.truth.Truth.assertWithMessage +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.kotlin.argumentCaptor +import org.mockito.kotlin.mock +import org.mockito.kotlin.times +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever + +@SmallTest +@RunWith(AndroidJUnit4::class) +@RunWithLooper +class StatusBarNotificationPresenterTest : SysuiTestCase() { + private val kosmos = testKosmos() + + private val visualInterruptionDecisionProvider: VisualInterruptionDecisionProvider = mock() + + private var interruptSuppressor: NotificationInterruptSuppressor? = null + private var alertsDisabledCondition: VisualInterruptionCondition? = null + private var vrModeCondition: VisualInterruptionCondition? = null + private var needsRedactionFilter: VisualInterruptionFilter? = null + private var panelsDisabledCondition: VisualInterruptionCondition? = null + + private val commandQueue: CommandQueue = CommandQueue(mContext, FakeDisplayTracker(mContext)) + private val shadeController: ShadeController = mock() + private val notificationAlertsInteractor: NotificationAlertsInteractor = mock() + private val keyguardStateController: KeyguardStateController = mock() + + private lateinit var underTest: StatusBarNotificationPresenter + + @Before + fun setup() { + mDependency.injectTestDependency(StatusBarStateController::class.java, mock()) + mDependency.injectTestDependency(ShadeController::class.java, shadeController) + mDependency.injectMockDependency(NotificationRemoteInputManager.Callback::class.java) + mDependency.injectMockDependency(NotificationShadeWindowController::class.java) + + whenever(notificationAlertsInteractor.areNotificationAlertsEnabled()).thenReturn(true) + + underTest = createPresenter() + if (VisualInterruptionRefactor.isEnabled) { + verifyAndCaptureSuppressors() + } else { + verifyAndCaptureLegacySuppressor() + } + } + + @Test + @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testInit_refactorDisabled() { + assertThat(VisualInterruptionRefactor.isEnabled).isFalse() + assertThat(alertsDisabledCondition).isNull() + assertThat(vrModeCondition).isNull() + assertThat(needsRedactionFilter).isNull() + assertThat(panelsDisabledCondition).isNull() + assertThat(interruptSuppressor).isNotNull() + } + + @Test + @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testInit_refactorEnabled() { + assertThat(VisualInterruptionRefactor.isEnabled).isTrue() + assertThat(alertsDisabledCondition).isNotNull() + assertThat(vrModeCondition).isNotNull() + assertThat(needsRedactionFilter).isNotNull() + assertThat(panelsDisabledCondition).isNotNull() + assertThat(interruptSuppressor).isNull() + } + + @Test + @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testNoSuppressHeadsUp_default_refactorDisabled() { + assertThat(interruptSuppressor!!.suppressAwakeHeadsUp(createNotificationEntry())).isFalse() + } + + @Test + @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testNoSuppressHeadsUp_default_refactorEnabled() { + assertThat(alertsDisabledCondition!!.shouldSuppress()).isFalse() + assertThat(vrModeCondition!!.shouldSuppress()).isFalse() + assertThat(needsRedactionFilter!!.shouldSuppress(createNotificationEntry())).isFalse() + assertThat(alertsDisabledCondition!!.shouldSuppress()).isFalse() + } + + @Test + @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testSuppressHeadsUp_disabledStatusBar_refactorDisabled() { + commandQueue.disable( + DEFAULT_DISPLAY, + StatusBarManager.DISABLE_EXPAND, + 0, + false, /* animate */ + ) + TestableLooper.get(this).processAllMessages() + + assertWithMessage("The panel should suppress heads up while disabled") + .that(interruptSuppressor!!.suppressAwakeHeadsUp(createNotificationEntry())) + .isTrue() + } + + @Test + @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testSuppressHeadsUp_disabledStatusBar_refactorEnabled() { + commandQueue.disable( + DEFAULT_DISPLAY, + StatusBarManager.DISABLE_EXPAND, + 0, + false, /* animate */ + ) + TestableLooper.get(this).processAllMessages() + + assertWithMessage("The panel should suppress heads up while disabled") + .that(panelsDisabledCondition!!.shouldSuppress()) + .isTrue() + } + + @Test + @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testSuppressHeadsUp_disabledNotificationShade_refactorDisabled() { + commandQueue.disable( + DEFAULT_DISPLAY, + 0, + StatusBarManager.DISABLE2_NOTIFICATION_SHADE, + false, /* animate */ + ) + TestableLooper.get(this).processAllMessages() + + assertWithMessage( + "The panel should suppress interruptions while notification shade disabled" + ) + .that(interruptSuppressor!!.suppressAwakeHeadsUp(createNotificationEntry())) + .isTrue() + } + + @Test + @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testSuppressHeadsUp_disabledNotificationShade_refactorEnabled() { + commandQueue.disable( + DEFAULT_DISPLAY, + 0, + StatusBarManager.DISABLE2_NOTIFICATION_SHADE, + false, /* animate */ + ) + TestableLooper.get(this).processAllMessages() + + assertWithMessage( + "The panel should suppress interruptions while notification shade disabled" + ) + .that(panelsDisabledCondition!!.shouldSuppress()) + .isTrue() + } + + @Test + @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testPanelsDisabledConditionSuppressesPeek() { + val types: Set<VisualInterruptionType> = panelsDisabledCondition!!.types + assertThat(types).contains(VisualInterruptionType.PEEK) + assertThat(types) + .containsNoneOf(VisualInterruptionType.BUBBLE, VisualInterruptionType.PULSE) + } + + @Test + @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testNoSuppressHeadsUp_FSI_nonOccludedKeyguard_refactorDisabled() { + whenever(keyguardStateController.isShowing()).thenReturn(true) + whenever(keyguardStateController.isOccluded()).thenReturn(false) + + assertThat(interruptSuppressor!!.suppressAwakeHeadsUp(createFsiNotificationEntry())) + .isFalse() + } + + @Test + @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testNoSuppressHeadsUp_FSI_nonOccludedKeyguard_refactorEnabled() { + whenever(keyguardStateController.isShowing()).thenReturn(true) + whenever(keyguardStateController.isOccluded()).thenReturn(false) + + assertThat(needsRedactionFilter!!.shouldSuppress(createFsiNotificationEntry())).isFalse() + + val types: Set<VisualInterruptionType> = needsRedactionFilter!!.types + assertThat(types).contains(VisualInterruptionType.PEEK) + assertThat(types) + .containsNoneOf(VisualInterruptionType.BUBBLE, VisualInterruptionType.PULSE) + } + + @Test + @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testSuppressInterruptions_vrMode_refactorDisabled() { + underTest.mVrMode = true + + assertWithMessage("Vr mode should suppress interruptions") + .that(interruptSuppressor!!.suppressAwakeInterruptions(createNotificationEntry())) + .isTrue() + } + + @Test + @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testSuppressInterruptions_vrMode_refactorEnabled() { + underTest.mVrMode = true + + assertWithMessage("Vr mode should suppress interruptions") + .that(vrModeCondition!!.shouldSuppress()) + .isTrue() + + val types: Set<VisualInterruptionType> = vrModeCondition!!.types + assertThat(types).contains(VisualInterruptionType.PEEK) + assertThat(types).doesNotContain(VisualInterruptionType.PULSE) + assertThat(types).contains(VisualInterruptionType.BUBBLE) + } + + @Test + @DisableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testSuppressInterruptions_statusBarAlertsDisabled_refactorDisabled() { + whenever(notificationAlertsInteractor.areNotificationAlertsEnabled()).thenReturn(false) + + assertWithMessage("When alerts aren't enabled, interruptions are suppressed") + .that(interruptSuppressor!!.suppressInterruptions(createNotificationEntry())) + .isTrue() + } + + @Test + @EnableFlags(VisualInterruptionRefactor.FLAG_NAME) + fun testSuppressInterruptions_statusBarAlertsDisabled_refactorEnabled() { + whenever(notificationAlertsInteractor.areNotificationAlertsEnabled()).thenReturn(false) + + assertWithMessage("When alerts aren't enabled, interruptions are suppressed") + .that(alertsDisabledCondition!!.shouldSuppress()) + .isTrue() + + val types: Set<VisualInterruptionType> = alertsDisabledCondition!!.types + assertThat(types).contains(VisualInterruptionType.PEEK) + assertThat(types).contains(VisualInterruptionType.PULSE) + assertThat(types).contains(VisualInterruptionType.BUBBLE) + } + + private fun createPresenter(): StatusBarNotificationPresenter { + val shadeViewController: ShadeViewController = mock() + + val notificationShadeWindowView: NotificationShadeWindowView = mock() + whenever(notificationShadeWindowView.resources).thenReturn(mContext.resources) + + val stackScrollLayoutController: NotificationStackScrollLayoutController = mock() + whenever(stackScrollLayoutController.view).thenReturn(mock()) + + val initController: InitController = InitController() + + return StatusBarNotificationPresenter( + mContext, + shadeViewController, + kosmos.panelExpansionInteractor, + /* quickSettingsController = */ mock(), + kosmos.headsUpManager, + notificationShadeWindowView, + kosmos.activityStarter, + stackScrollLayoutController, + kosmos.dozeScrimController, + kosmos.notificationShadeWindowController, + kosmos.dynamicPrivacyController, + keyguardStateController, + notificationAlertsInteractor, + kosmos.lockscreenShadeTransitionController, + kosmos.powerInteractor, + commandQueue, + kosmos.notificationLockscreenUserManager, + kosmos.sysuiStatusBarStateController, + /* notifShadeEventSource = */ mock(), + /* notificationMediaManager = */ mock(), + /* notificationGutsManager = */ mock(), + initController, + visualInterruptionDecisionProvider, + kosmos.notificationRemoteInputManager, + /* remoteInputManagerCallback = */ mock(), + /* notificationListContainer = */ mock(), + ) + .also { initController.executePostInitTasks() } + } + + private fun verifyAndCaptureSuppressors() { + interruptSuppressor = null + + val conditionCaptor = argumentCaptor<VisualInterruptionCondition>() + verify(visualInterruptionDecisionProvider, times(3)).addCondition(conditionCaptor.capture()) + val conditions: List<VisualInterruptionCondition> = conditionCaptor.allValues + alertsDisabledCondition = conditions[0] + vrModeCondition = conditions[1] + panelsDisabledCondition = conditions[2] + + val needsRedactionFilterCaptor = argumentCaptor<VisualInterruptionFilter>() + verify(visualInterruptionDecisionProvider).addFilter(needsRedactionFilterCaptor.capture()) + needsRedactionFilter = needsRedactionFilterCaptor.lastValue + } + + private fun verifyAndCaptureLegacySuppressor() { + alertsDisabledCondition = null + vrModeCondition = null + needsRedactionFilter = null + panelsDisabledCondition = null + + val suppressorCaptor = argumentCaptor<NotificationInterruptSuppressor>() + verify(visualInterruptionDecisionProvider).addLegacySuppressor(suppressorCaptor.capture()) + interruptSuppressor = suppressorCaptor.lastValue + } + + private fun createNotificationEntry(): NotificationEntry { + return NotificationEntryBuilder() + .setPkg("a") + .setOpPkg("a") + .setTag("a") + .setNotification(Builder(mContext, "a").build()) + .build() + } + + private fun createFsiNotificationEntry(): NotificationEntry { + val notification: Notification = + Builder(mContext, "a").setFullScreenIntent(mock(), true).build() + + return NotificationEntryBuilder() + .setPkg("a") + .setOpPkg("a") + .setTag("a") + .setNotification(notification) + .build() + } +} |