Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 404375f8 authored by András Kurucz's avatar András Kurucz
Browse files

Use ActiveNotificationsInteractor in WindowRootViewVisibilityInteractor

Bug: 308623704
Test: atest SystemUITests:com.android.systemui.scene.domain.interactor.WindowRootViewVisibilityInteractorTest
Flag: ACONFIG com.android.systemui.notifications_live_data_store_refactor DEVELOPMENT
Change-Id: I35522cf6691bdad65bb1f37b8c6d486e028f9d0e
parent b738e563
Loading
Loading
Loading
Loading
+69 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.scene.domain.interactor

import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.statusbar.IStatusBarService
@@ -28,7 +30,11 @@ import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.se
import com.android.systemui.power.domain.interactor.PowerInteractorFactory
import com.android.systemui.scene.data.repository.WindowRootViewVisibilityRepository
import com.android.systemui.statusbar.NotificationPresenter
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationListRepository
import com.android.systemui.statusbar.notification.data.repository.setActiveNotifs
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.statusbar.notification.init.NotificationsController
import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor
import com.android.systemui.statusbar.policy.HeadsUpManager
import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.mockito.any
@@ -37,6 +43,7 @@ import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
@@ -50,6 +57,7 @@ import org.mockito.Mockito.verify
class WindowRootViewVisibilityInteractorTest : SysuiTestCase() {

    private val testScope = TestScope()
    private val testDispatcher = StandardTestDispatcher()
    private val iStatusBarService = mock<IStatusBarService>()
    private val executor = FakeExecutor(FakeSystemClock())
    private val windowRootViewVisibilityRepository =
@@ -59,6 +67,9 @@ class WindowRootViewVisibilityInteractorTest : SysuiTestCase() {
    private val notificationPresenter = mock<NotificationPresenter>()
    private val notificationsController = mock<NotificationsController>()
    private val powerInteractor = PowerInteractorFactory.create().powerInteractor
    private val activeNotificationsRepository = ActiveNotificationListRepository()
    private val activeNotificationsInteractor =
        ActiveNotificationsInteractor(activeNotificationsRepository, testDispatcher)

    private val underTest =
        WindowRootViewVisibilityInteractor(
@@ -67,6 +78,7 @@ class WindowRootViewVisibilityInteractorTest : SysuiTestCase() {
                keyguardRepository,
                headsUpManager,
                powerInteractor,
                activeNotificationsInteractor,
            )
            .apply { setUp(notificationPresenter, notificationsController) }

@@ -257,7 +269,8 @@ class WindowRootViewVisibilityInteractorTest : SysuiTestCase() {
        }

    @Test
    fun lockscreenShadeInteractive_hasHeadsUpAndNotifPresenterCollapsed_notifCountOne() =
    @DisableFlags(NotificationsLiveDataStoreRefactor.FLAG_NAME)
    fun lockscreenShadeInteractive_hasHeadsUpAndNotifPresenterCollapsed_flagOff_notifCountOne() =
        testScope.runTest {
            underTest.start()

@@ -272,6 +285,23 @@ class WindowRootViewVisibilityInteractorTest : SysuiTestCase() {
            assertThat(notifCount.value).isEqualTo(1)
        }

    @Test
    @EnableFlags(NotificationsLiveDataStoreRefactor.FLAG_NAME)
    fun lockscreenShadeInteractive_hasHeadsUpAndNotifPresenterCollapsed_flagOn_notifCountOne() =
        testScope.runTest {
            underTest.start()

            whenever(headsUpManager.hasPinnedHeadsUp()).thenReturn(true)
            whenever(notificationPresenter.isPresenterFullyCollapsed).thenReturn(true)
            activeNotificationsRepository.setActiveNotifs(4)

            makeLockscreenShadeVisible()

            val notifCount = argumentCaptor<Int>()
            verify(iStatusBarService).onPanelRevealed(any(), notifCount.capture())
            assertThat(notifCount.value).isEqualTo(1)
        }

    @Test
    fun lockscreenShadeInteractive_hasHeadsUpAndNullPresenter_notifCountOne() =
        testScope.runTest {
@@ -288,7 +318,8 @@ class WindowRootViewVisibilityInteractorTest : SysuiTestCase() {
        }

    @Test
    fun lockscreenShadeInteractive_noHeadsUp_notifCountMatchesNotifController() =
    @DisableFlags(NotificationsLiveDataStoreRefactor.FLAG_NAME)
    fun lockscreenShadeInteractive_noHeadsUp_flagOff_notifCountMatchesNotifController() =
        testScope.runTest {
            underTest.start()
            whenever(notificationPresenter.isPresenterFullyCollapsed).thenReturn(true)
@@ -304,7 +335,25 @@ class WindowRootViewVisibilityInteractorTest : SysuiTestCase() {
        }

    @Test
    fun lockscreenShadeInteractive_notifPresenterNotCollapsed_notifCountMatchesNotifController() =
    @EnableFlags(NotificationsLiveDataStoreRefactor.FLAG_NAME)
    fun lockscreenShadeInteractive_noHeadsUp_flagOn_notifCountMatchesNotifController() =
        testScope.runTest {
            underTest.start()
            whenever(notificationPresenter.isPresenterFullyCollapsed).thenReturn(true)

            whenever(headsUpManager.hasPinnedHeadsUp()).thenReturn(false)
            activeNotificationsRepository.setActiveNotifs(9)

            makeLockscreenShadeVisible()

            val notifCount = argumentCaptor<Int>()
            verify(iStatusBarService).onPanelRevealed(any(), notifCount.capture())
            assertThat(notifCount.value).isEqualTo(9)
        }

    @Test
    @DisableFlags(NotificationsLiveDataStoreRefactor.FLAG_NAME)
    fun lockscreenShadeInteractive_notifPresenterNotCollapsed_flagOff_notifCountMatchesNotifController() =
        testScope.runTest {
            underTest.start()
            whenever(headsUpManager.hasPinnedHeadsUp()).thenReturn(true)
@@ -319,6 +368,23 @@ class WindowRootViewVisibilityInteractorTest : SysuiTestCase() {
            assertThat(notifCount.value).isEqualTo(8)
        }

    @Test
    @EnableFlags(NotificationsLiveDataStoreRefactor.FLAG_NAME)
    fun lockscreenShadeInteractive_notifPresenterNotCollapsed_flagOn_notifCountMatchesNotifController() =
        testScope.runTest {
            underTest.start()
            whenever(headsUpManager.hasPinnedHeadsUp()).thenReturn(true)

            whenever(notificationPresenter.isPresenterFullyCollapsed).thenReturn(false)
            activeNotificationsRepository.setActiveNotifs(8)

            makeLockscreenShadeVisible()

            val notifCount = argumentCaptor<Int>()
            verify(iStatusBarService).onPanelRevealed(any(), notifCount.capture())
            assertThat(notifCount.value).isEqualTo(8)
        }

    @Test
    fun lockscreenShadeInteractive_noHeadsUp_noNotifController_notifCountZero() =
        testScope.runTest {
+11 −0
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@ import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.scene.data.repository.WindowRootViewVisibilityRepository
import com.android.systemui.statusbar.NotificationPresenter
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.statusbar.notification.init.NotificationsController
import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor
import com.android.systemui.statusbar.policy.HeadsUpManager
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
@@ -44,6 +46,7 @@ constructor(
    private val keyguardRepository: KeyguardRepository,
    private val headsUpManager: HeadsUpManager,
    private val powerInteractor: PowerInteractor,
    private val activeNotificationsInteractor: ActiveNotificationsInteractor,
) : CoreStartable {

    private var notificationPresenter: NotificationPresenter? = null
@@ -116,6 +119,14 @@ constructor(
    private fun getNotificationLoad(): Int {
        return if (headsUpManager.hasPinnedHeadsUp() && isNotifPresenterFullyCollapsed) {
            1
        } else {
            getActiveNotificationsCount()
        }
    }

    private fun getActiveNotificationsCount(): Int {
        return if (NotificationsLiveDataStoreRefactor.isEnabled) {
            activeNotificationsInteractor.allNotificationsCountValue
        } else {
            notificationsController?.getActiveNotificationsCount() ?: 0
        }
+2 −1
Original line number Diff line number Diff line
@@ -68,7 +68,8 @@ constructor(
    /**
     * The same as [allNotificationsCount], but without flows, for easy access in synchronous code.
     */
    val allNotificationsCountValue: Int = repository.activeNotifications.value.individuals.size
    val allNotificationsCountValue: Int
        get() = repository.activeNotifications.value.individuals.size

    /** Are any notifications being actively presented in the notification stack? */
    val areAnyNotificationsPresent: Flow<Boolean> =
+4 −3
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.notification.init

import android.service.notification.StatusBarNotification
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.people.widget.PeopleSpaceWidgetManager
import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper.SnoozeOption
import com.android.systemui.statusbar.NotificationListener
@@ -72,7 +71,6 @@ constructor(
    private val animatedImageNotificationManager: AnimatedImageNotificationManager,
    private val peopleSpaceWidgetManager: PeopleSpaceWidgetManager,
    private val bubblesOptional: Optional<Bubbles>,
    private val featureFlags: FeatureFlags
) : NotificationsController {

    override fun initialize(
@@ -136,5 +134,8 @@ constructor(
        }
    }

    override fun getActiveNotificationsCount(): Int = notifLiveDataStore.activeNotifCount.value
    override fun getActiveNotificationsCount(): Int {
        NotificationsLiveDataStoreRefactor.assertInLegacyMode()
        return notifLiveDataStore.activeNotifCount.value
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ import com.android.systemui.shade.ShadeController
import com.android.systemui.shade.ShadeViewController
import com.android.systemui.statusbar.NotificationShadeWindowController
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationListRepository
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
import com.android.systemui.statusbar.policy.HeadsUpManager
import com.android.systemui.util.concurrency.FakeExecutor
@@ -56,6 +58,7 @@ import com.google.common.truth.Truth.assertThat
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import org.junit.Before
@@ -89,6 +92,9 @@ class BackActionInteractorTest : SysuiTestCase() {
    @Mock private lateinit var onBackInvokedDispatcher: WindowOnBackInvokedDispatcher
    @Mock private lateinit var iStatusBarService: IStatusBarService
    @Mock private lateinit var headsUpManager: HeadsUpManager
    private val activeNotificationsRepository = ActiveNotificationListRepository()
    private val activeNotificationsInteractor =
        ActiveNotificationsInteractor(activeNotificationsRepository, StandardTestDispatcher())

    private val keyguardRepository = FakeKeyguardRepository()
    private val windowRootViewVisibilityInteractor: WindowRootViewVisibilityInteractor by lazy {
@@ -98,6 +104,7 @@ class BackActionInteractorTest : SysuiTestCase() {
            keyguardRepository,
            headsUpManager,
            powerInteractor,
            activeNotificationsInteractor,
        )
    }

Loading