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

Commit 9804e633 authored by Michael Mikhail's avatar Michael Mikhail Committed by Android (Google) Code Review
Browse files

Merge "Update last active timestamp when resumption added" into main

parents a85b4bea fe082363
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -583,6 +583,10 @@ class MediaDataManager(
                }
                return
            }
            // Update last active if media was still active.
            if (it.active) {
                it.lastActive = systemClock.elapsedRealtime()
            }
            it.active = !timedOut
            if (DEBUG) Log.d(TAG, "Updating $key timedOut: $timedOut")
            onMediaDataLoaded(key, key, it)
@@ -1520,6 +1524,12 @@ class MediaDataManager(
            context.packageManager.getLaunchIntentForPackage(data.packageName)?.let {
                PendingIntent.getActivity(context, 0, it, PendingIntent.FLAG_IMMUTABLE)
            }
        val lastActive =
            if (data.active) {
                systemClock.elapsedRealtime()
            } else {
                data.lastActive
            }
        val updated =
            data.copy(
                token = null,
@@ -1531,6 +1541,7 @@ class MediaDataManager(
                isPlaying = false,
                isClearable = true,
                clickIntent = launcherIntent,
                lastActive = lastActive,
            )
        val pkg = data.packageName
        val migrate = mediaEntries.put(pkg, updated) == null
+40 −4
Original line number Diff line number Diff line
@@ -1476,7 +1476,7 @@ class MediaDataManagerTest : SysuiTestCase() {
    }

    @Test
    fun testOnMediaDataTimedOut_doesNotUpdateLastActiveTime() {
    fun testOnMediaDataTimedOut_updatesLastActiveTime() {
        // GIVEN that the manager has a notification
        mediaDataManager.onNotificationAdded(KEY, mediaNotification)
        assertThat(backgroundExecutor.runAllReady()).isEqualTo(1)
@@ -1487,7 +1487,7 @@ class MediaDataManagerTest : SysuiTestCase() {
        val currentTime = clock.elapsedRealtime()
        mediaDataManager.setTimedOut(KEY, true, true)

        // THEN the last active time is not changed
        // THEN the last active time is changed
        verify(listener)
            .onMediaDataLoaded(
                eq(KEY),
@@ -1497,11 +1497,11 @@ class MediaDataManagerTest : SysuiTestCase() {
                eq(0),
                eq(false)
            )
        assertThat(mediaDataCaptor.value.lastActive).isLessThan(currentTime)
        assertThat(mediaDataCaptor.value.lastActive).isAtLeast(currentTime)
    }

    @Test
    fun testOnActiveMediaConverted_doesNotUpdateLastActiveTime() {
    fun testOnActiveMediaConverted_updatesLastActiveTime() {
        // GIVEN that the manager has a notification with a resume action
        addNotificationAndLoad()
        val data = mediaDataCaptor.value
@@ -1514,6 +1514,42 @@ class MediaDataManagerTest : SysuiTestCase() {
        val currentTime = clock.elapsedRealtime()
        mediaDataManager.onNotificationRemoved(KEY)

        // THEN the last active time is changed
        verify(listener)
            .onMediaDataLoaded(
                eq(PACKAGE_NAME),
                eq(KEY),
                capture(mediaDataCaptor),
                eq(true),
                eq(0),
                eq(false)
            )
        assertThat(mediaDataCaptor.value.resumption).isTrue()
        assertThat(mediaDataCaptor.value.lastActive).isAtLeast(currentTime)

        // Log as a conversion event, not as a new resume control
        verify(logger).logActiveConvertedToResume(anyInt(), eq(PACKAGE_NAME), eq(instanceId))
        verify(logger, never()).logResumeMediaAdded(anyInt(), eq(PACKAGE_NAME), any())
    }

    @Test
    fun testOnInactiveMediaConverted_doesNotUpdateLastActiveTime() {
        // GIVEN that the manager has a notification with a resume action
        addNotificationAndLoad()
        val data = mediaDataCaptor.value
        val instanceId = data.instanceId
        assertThat(data.resumption).isFalse()
        mediaDataManager.onMediaDataLoaded(
            KEY,
            null,
            data.copy(resumeAction = Runnable {}, active = false)
        )

        // WHEN the notification is removed
        clock.advanceTime(100)
        val currentTime = clock.elapsedRealtime()
        mediaDataManager.onNotificationRemoved(KEY)

        // THEN the last active time is not changed
        verify(listener)
            .onMediaDataLoaded(