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

Commit 57c9897f authored by ggranatiero's avatar ggranatiero Committed by Giuseppe Granatiero
Browse files

Populates the notificationCount field in DisplaySwitchLatencyEvent.

The change injects ActiveNotificationsInteractor into DisplaySwitchLatencyTracker and uses its allNotificationsCountValue to capture the number of notifications when the switch event begins.

Added a unit test to DisplaySwitchLatencyTrackTest that mocks ActiveNotificationsInteractor. The test verifies that the notification count provided by the mock is correctly recorded in the final logged event.

Test: atest DisplaySwitchLatencyTrackerTest
Bug: 304491690
Flag: EXEMPT minimal changes
Change-Id: I9288900d12c90804d933ca401de38915e46b8fb4
parent 21492f3d
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.se
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
import com.android.systemui.power.domain.interactor.PowerInteractorFactory
import com.android.systemui.shared.system.SysUiStatsLog
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.testKosmos
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.Companion.FOLDABLE_DEVICE_STATE_CLOSED
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.Companion.FOLDABLE_DEVICE_STATE_HALF_OPEN
@@ -83,6 +84,7 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    private val displaySwitchLatencyLogger = mock<DisplaySwitchLatencyLogger>()
    private val screenTimeoutPolicyRepository = mock<ScreenTimeoutPolicyRepository>()
    private val latencyTracker = mock<LatencyTracker>()
    private val activeNotificationsInteractor = mock<ActiveNotificationsInteractor>()

    private val isAodAvailable = MutableStateFlow(false)
    private val screenTimeoutActive = MutableStateFlow(true)
@@ -110,6 +112,7 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
                powerInteractor,
                screenTimeoutPolicyRepository,
                keyguardInteractor,
                activeNotificationsInteractor,
                testScope.backgroundScope,
                displaySwitchLatencyLogger,
                systemClock,
@@ -489,6 +492,24 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
        }
    }

    @Test
    fun displaySwitch_withNotifications_logsNotificationCount() {
        testScope.runTest {
            // Arrange: Set a specific notification count
            val expectedCount = 5
            whenever(activeNotificationsInteractor.allNotificationsCountValue)
                .thenReturn(expectedCount)

            // Act: Perform a display switch
            setDisplaySwitchState(Switching(HALF_FOLDED))
            setDisplaySwitchState(Idle(UNFOLDED))

            // Assert: Check that the logged event contains the correct count
            val event = capturedLogEvent()
            assertThat(event.notificationCount).isEqualTo(expectedCount)
        }
    }

    private fun capturedLogEvent(): DisplaySwitchLatencyEvent {
        verify(displaySwitchLatencyLogger).log(capture(loggerArgumentCaptor))
        return loggerArgumentCaptor.value
@@ -499,12 +520,14 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
        fromFoldableDeviceState: Int,
        toFoldableDeviceState: Int,
        toState: Int = SysUiStatsLog.DISPLAY_SWITCH_LATENCY_TRACKED__FROM_STATE__UNKNOWN,
        notificationCount: Int = 0,
    ): DisplaySwitchLatencyEvent {
        return DisplaySwitchLatencyEvent(
            latencyMs = latencyMs,
            fromFoldableDeviceState = fromFoldableDeviceState,
            toFoldableDeviceState = toFoldableDeviceState,
            toState = toState,
            notificationCount = notificationCount,
            screenWakelockStatus =
                SysUiStatsLog
                    .DISPLAY_SWITCH_LATENCY_TRACKED__SCREEN_WAKELOCK_STATUS__SCREEN_WAKELOCK_STATUS_NO_WAKELOCKS,
+7 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.display.data.repository.DeviceStateRepository.Device
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.shared.system.SysUiStatsLog
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.DisplaySwitchLatencyEvent
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.TrackingResult.CORRUPTED
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.TrackingResult.SUCCESS
@@ -61,6 +62,7 @@ constructor(
    private val powerInteractor: PowerInteractor,
    private val screenTimeoutPolicyRepository: ScreenTimeoutPolicyRepository,
    private val keyguardInteractor: KeyguardInteractor,
    private val activeNotificationsInteractor: ActiveNotificationsInteractor,
    @UnfoldTracking private val scope: CoroutineScope,
    private val displaySwitchLatencyLogger: DisplaySwitchLatencyLogger,
    private val systemClock: SystemClock,
@@ -277,7 +279,11 @@ constructor(
            } else {
                HAS_SCREEN_WAKELOCKS
            }
        return copy(screenWakelockStatus = screenWakelockStatus, fromState = getFromState())
        return copy(
            screenWakelockStatus = screenWakelockStatus,
            fromState = getFromState(),
            notificationCount = activeNotificationsInteractor.allNotificationsCountValue,
        )
    }

    /**