Loading packages/SystemUI/src/com/android/systemui/media/controls/domain/pipeline/MediaDataManager.kt +11 −0 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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, Loading @@ -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 Loading packages/SystemUI/tests/src/com/android/systemui/media/controls/domain/pipeline/MediaDataManagerTest.kt +40 −4 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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), Loading @@ -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 Loading @@ -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( Loading Loading
packages/SystemUI/src/com/android/systemui/media/controls/domain/pipeline/MediaDataManager.kt +11 −0 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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, Loading @@ -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 Loading
packages/SystemUI/tests/src/com/android/systemui/media/controls/domain/pipeline/MediaDataManagerTest.kt +40 −4 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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), Loading @@ -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 Loading @@ -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( Loading