Conserve activity flag after notif update
When reloading the metadata or changing the stream state, let's conserve the previous activity state. Fixes: 159642373 Test: manual Test: atest MediaDataManagerTest Test: atest MediaTimeoutListenerTest Change-Id: I23cc9485c36be31c3fc2d6b3935dc829f2131afd
This commit is contained in:
@@ -432,12 +432,13 @@ class MediaDataManager(
|
||||
}
|
||||
}
|
||||
|
||||
val resumeAction: Runnable? = mediaEntries.get(key)?.resumeAction
|
||||
val hasCheckedForResume = mediaEntries.get(key)?.hasCheckedForResume == true
|
||||
foregroundExecutor.execute {
|
||||
val resumeAction: Runnable? = mediaEntries[key]?.resumeAction
|
||||
val hasCheckedForResume = mediaEntries[key]?.hasCheckedForResume == true
|
||||
val active = mediaEntries[key]?.active ?: true
|
||||
onMediaDataLoaded(key, oldKey, MediaData(true, bgColor, app, smallIconDrawable, artist,
|
||||
song, artWorkIcon, actionIcons, actionsToShowCollapsed, sbn.packageName, token,
|
||||
notif.contentIntent, null, active = true, resumeAction = resumeAction,
|
||||
notif.contentIntent, null, active, resumeAction = resumeAction,
|
||||
notificationKey = key, hasCheckedForResume = hasCheckedForResume))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ class MediaTimeoutListener @Inject constructor(
|
||||
) : MediaController.Callback() {
|
||||
|
||||
var timedOut = false
|
||||
private var playing: Boolean? = null
|
||||
|
||||
// Resume controls may have null token
|
||||
private val mediaController = if (data.token != null) {
|
||||
@@ -94,7 +95,13 @@ class MediaTimeoutListener @Inject constructor(
|
||||
Log.v(TAG, "onPlaybackStateChanged: $state")
|
||||
}
|
||||
|
||||
if (state == null || !isPlayingState(state.state)) {
|
||||
val isPlaying = state != null && isPlayingState(state.state)
|
||||
if (playing == isPlaying && playing != null) {
|
||||
return
|
||||
}
|
||||
playing = isPlaying
|
||||
|
||||
if (!isPlaying) {
|
||||
if (DEBUG) {
|
||||
Log.v(TAG, "schedule timeout for $key")
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher
|
||||
import com.android.systemui.dump.DumpManager
|
||||
import com.android.systemui.statusbar.SbnBuilder
|
||||
import com.android.systemui.util.concurrency.FakeExecutor
|
||||
import com.android.systemui.util.mockito.eq
|
||||
import com.android.systemui.util.time.FakeSystemClock
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.After
|
||||
@@ -26,8 +27,8 @@ import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when` as whenever
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.Mockito.`when` as whenever
|
||||
|
||||
private const val KEY = "KEY"
|
||||
private const val PACKAGE_NAME = "com.android.systemui"
|
||||
@@ -35,7 +36,6 @@ private const val APP_NAME = "SystemUI"
|
||||
private const val SESSION_ARTIST = "artist"
|
||||
private const val SESSION_TITLE = "title"
|
||||
|
||||
private fun <T> eq(value: T): T = Mockito.eq(value) ?: value
|
||||
private fun <T> anyObject(): T {
|
||||
return Mockito.anyObject<T>()
|
||||
}
|
||||
@@ -103,6 +103,19 @@ class MediaDataManagerTest : SysuiTestCase() {
|
||||
assertThat(mediaDataManager.hasActiveMedia()).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnSwipeToDismiss_deactivatesMedia() {
|
||||
val data = MediaData(initialized = true, backgroundColor = 0, app = null, appIcon = null,
|
||||
artist = null, song = null, artwork = null, actions = emptyList(),
|
||||
actionsToShowInCompact = emptyList(), packageName = "INVALID", token = null,
|
||||
clickIntent = null, device = null, active = true, resumeAction = null)
|
||||
mediaDataManager.onNotificationAdded(KEY, mediaNotification)
|
||||
mediaDataManager.onMediaDataLoaded(KEY, oldKey = null, data = data)
|
||||
|
||||
mediaDataManager.onSwipeToDismiss()
|
||||
assertThat(data.active).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLoadsMetadataOnBackground() {
|
||||
mediaDataManager.onNotificationAdded(KEY, mediaNotification)
|
||||
@@ -118,6 +131,30 @@ class MediaDataManagerTest : SysuiTestCase() {
|
||||
verify(listener).onMediaDataLoaded(eq(KEY), eq(null), anyObject())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnMetaDataLoaded_conservesActiveFlag() {
|
||||
val listener = TestListener()
|
||||
whenever(mediaControllerFactory.create(anyObject())).thenReturn(controller)
|
||||
whenever(controller.metadata).thenReturn(metadataBuilder.build())
|
||||
mediaDataManager.addListener(listener)
|
||||
mediaDataManager.onNotificationAdded(KEY, mediaNotification)
|
||||
assertThat(backgroundExecutor.runAllReady()).isEqualTo(1)
|
||||
assertThat(foregroundExecutor.runAllReady()).isEqualTo(1)
|
||||
assertThat(listener.data!!.active).isTrue()
|
||||
|
||||
// Swiping away makes the notification not active
|
||||
mediaDataManager.onSwipeToDismiss()
|
||||
assertThat(mediaDataManager.hasActiveMedia()).isFalse()
|
||||
|
||||
// And when a notification is updated
|
||||
mediaDataManager.onNotificationAdded(KEY, mediaNotification)
|
||||
assertThat(backgroundExecutor.runAllReady()).isEqualTo(1)
|
||||
assertThat(foregroundExecutor.runAllReady()).isEqualTo(1)
|
||||
|
||||
// MediaData should still be inactive
|
||||
assertThat(mediaDataManager.hasActiveMedia()).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHasAnyMedia_whenAddingMedia() {
|
||||
assertThat(mediaDataManager.hasAnyMedia()).isFalse()
|
||||
|
||||
Reference in New Issue
Block a user