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

Commit 64fbf64c authored by Beth Thibodeau's avatar Beth Thibodeau Committed by Android (Google) Code Review
Browse files

Merge "Fix test issues with media3 buttons" into main

parents 896aa041 c2311d9c
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.systemui.media.controls.util.fakeMediaControllerFactory
import com.android.systemui.media.controls.util.fakeSessionTokenFactory
import com.android.systemui.media.controls.util.fakeSessionTokenFactory
import com.android.systemui.res.R
import com.android.systemui.res.R
import com.android.systemui.testKosmos
import com.android.systemui.testKosmos
import com.android.systemui.util.concurrency.execution
import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableList
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runCurrent
@@ -105,6 +106,7 @@ class Media3ActionFactoryTest : SysuiTestCase() {
                kosmos.looper,
                kosmos.looper,
                handler,
                handler,
                kosmos.testScope,
                kosmos.testScope,
                kosmos.execution,
            )
            )


        controllerFactory.setMedia3Controller(media3Controller)
        controllerFactory.setMedia3Controller(media3Controller)
+3 −2
Original line number Original line Diff line number Diff line
@@ -42,7 +42,7 @@ import com.android.systemui.media.controls.shared.model.MediaButton
import com.android.systemui.media.controls.util.MediaControllerFactory
import com.android.systemui.media.controls.util.MediaControllerFactory
import com.android.systemui.media.controls.util.SessionTokenFactory
import com.android.systemui.media.controls.util.SessionTokenFactory
import com.android.systemui.res.R
import com.android.systemui.res.R
import com.android.systemui.util.Assert
import com.android.systemui.util.concurrency.Execution
import javax.inject.Inject
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.launch
@@ -63,6 +63,7 @@ constructor(
    @Background private val looper: Looper,
    @Background private val looper: Looper,
    @Background private val handler: Handler,
    @Background private val handler: Handler,
    @Background private val bgScope: CoroutineScope,
    @Background private val bgScope: CoroutineScope,
    private val execution: Execution,
) {
) {


    /**
    /**
@@ -108,7 +109,7 @@ constructor(
        m3controller: Media3Controller,
        m3controller: Media3Controller,
        token: SessionToken,
        token: SessionToken,
    ): MediaButton? {
    ): MediaButton? {
        Assert.isNotMainThread()
        require(!execution.isMainThread())


        // First, get standard actions
        // First, get standard actions
        val playOrPause =
        val playOrPause =
+13 −0
Original line number Original line Diff line number Diff line
@@ -289,6 +289,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
            }
            }
        verify(smartspaceManager).createSmartspaceSession(capture(smartSpaceConfigBuilderCaptor))
        verify(smartspaceManager).createSmartspaceSession(capture(smartSpaceConfigBuilderCaptor))
        mediaControllerFactory.setControllerForToken(session.sessionToken, controller)
        mediaControllerFactory.setControllerForToken(session.sessionToken, controller)
        whenever(controller.sessionToken).thenReturn(session.sessionToken)
        whenever(controller.transportControls).thenReturn(transportControls)
        whenever(controller.transportControls).thenReturn(transportControls)
        whenever(controller.playbackInfo).thenReturn(playbackInfo)
        whenever(controller.playbackInfo).thenReturn(playbackInfo)
        whenever(controller.metadata).thenReturn(metadataBuilder.build())
        whenever(controller.metadata).thenReturn(metadataBuilder.build())
@@ -1599,6 +1600,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
        verify(logger, never()).logResumeMediaAdded(anyInt(), eq(PACKAGE_NAME), any())
        verify(logger, never()).logResumeMediaAdded(anyInt(), eq(PACKAGE_NAME), any())
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testTooManyCompactActions_isTruncated() {
    fun testTooManyCompactActions_isTruncated() {
        // GIVEN a notification where too many compact actions were specified
        // GIVEN a notification where too many compact actions were specified
@@ -1635,6 +1637,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
            .isEqualTo(LegacyMediaDataManagerImpl.MAX_COMPACT_ACTIONS)
            .isEqualTo(LegacyMediaDataManagerImpl.MAX_COMPACT_ACTIONS)
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testTooManyNotificationActions_isTruncated() {
    fun testTooManyNotificationActions_isTruncated() {
        // GIVEN a notification where too many notification actions are added
        // GIVEN a notification where too many notification actions are added
@@ -1670,6 +1673,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
            .isEqualTo(LegacyMediaDataManagerImpl.MAX_NOTIFICATION_ACTIONS)
            .isEqualTo(LegacyMediaDataManagerImpl.MAX_NOTIFICATION_ACTIONS)
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_noState_usesNotification() {
    fun testPlaybackActions_noState_usesNotification() {
        val desc = "Notification Action"
        val desc = "Notification Action"
@@ -1703,6 +1707,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
        assertThat(mediaDataCaptor.value!!.actions[0]!!.contentDescription).isEqualTo(desc)
        assertThat(mediaDataCaptor.value!!.actions[0]!!.contentDescription).isEqualTo(desc)
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_hasPrevNext() {
    fun testPlaybackActions_hasPrevNext() {
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4")
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4")
@@ -1746,6 +1751,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
        assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[1])
        assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[1])
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_noPrevNext_usesCustom() {
    fun testPlaybackActions_noPrevNext_usesCustom() {
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4", "custom 5")
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4", "custom 5")
@@ -1778,6 +1784,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
        assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[3])
        assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[3])
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_connecting() {
    fun testPlaybackActions_connecting() {
        val stateActions = PlaybackState.ACTION_PLAY
        val stateActions = PlaybackState.ACTION_PLAY
@@ -1797,6 +1804,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
            .isEqualTo(context.getString(R.string.controls_media_button_connecting))
            .isEqualTo(context.getString(R.string.controls_media_button_connecting))
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_reservedSpace() {
    fun testPlaybackActions_reservedSpace() {
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4")
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4")
@@ -1835,6 +1843,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
        assertThat(actions.reservePrev).isTrue()
        assertThat(actions.reservePrev).isTrue()
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_playPause_hasButton() {
    fun testPlaybackActions_playPause_hasButton() {
        val stateActions = PlaybackState.ACTION_PLAY_PAUSE
        val stateActions = PlaybackState.ACTION_PLAY_PAUSE
@@ -1998,6 +2007,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
            assertThat(mediaDataCaptor.value.semanticActions).isNotNull()
            assertThat(mediaDataCaptor.value.semanticActions).isNotNull()
        }
        }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackStateNull_Pause_keyExists_callsListener() {
    fun testPlaybackStateNull_Pause_keyExists_callsListener() {
        whenever(controller.playbackState).thenReturn(null)
        whenever(controller.playbackState).thenReturn(null)
@@ -2056,6 +2066,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
        assertThat(mediaDataCaptor.value.isClearable).isFalse()
        assertThat(mediaDataCaptor.value.isClearable).isFalse()
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testRetain_notifPlayer_notifRemoved_setToResume() {
    fun testRetain_notifPlayer_notifRemoved_setToResume() {
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
@@ -2086,6 +2097,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
            )
            )
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testRetain_notifPlayer_sessionDestroyed_doesNotChange() {
    fun testRetain_notifPlayer_sessionDestroyed_doesNotChange() {
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
@@ -2104,6 +2116,7 @@ class LegacyMediaDataManagerImplTest(flags: FlagsParameterization) : SysuiTestCa
            .onMediaDataLoaded(eq(PACKAGE_NAME), any(), any(), anyBoolean(), anyInt(), anyBoolean())
            .onMediaDataLoaded(eq(PACKAGE_NAME), any(), any(), anyBoolean(), anyInt(), anyBoolean())
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testRetain_notifPlayer_removeWhileActive_fullyRemoved() {
    fun testRetain_notifPlayer_removeWhileActive_fullyRemoved() {
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
+17 −4
Original line number Original line Diff line number Diff line
@@ -103,7 +103,6 @@ import org.mockito.ArgumentMatchers.anyInt
import org.mockito.Captor
import org.mockito.Captor
import org.mockito.Mock
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.never
import org.mockito.Mockito.reset
import org.mockito.Mockito.reset
import org.mockito.Mockito.verify
import org.mockito.Mockito.verify
@@ -113,6 +112,7 @@ import org.mockito.junit.MockitoJUnit
import org.mockito.kotlin.any
import org.mockito.kotlin.any
import org.mockito.kotlin.capture
import org.mockito.kotlin.capture
import org.mockito.kotlin.eq
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import org.mockito.kotlin.whenever
import org.mockito.quality.Strictness
import org.mockito.quality.Strictness
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
@@ -312,6 +312,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
            }
            }
        verify(smartspaceManager).createSmartspaceSession(capture(smartSpaceConfigBuilderCaptor))
        verify(smartspaceManager).createSmartspaceSession(capture(smartSpaceConfigBuilderCaptor))
        mediaControllerFactory.setControllerForToken(session.sessionToken, controller)
        mediaControllerFactory.setControllerForToken(session.sessionToken, controller)
        whenever(controller.sessionToken).thenReturn(session.sessionToken)
        whenever(controller.transportControls).thenReturn(transportControls)
        whenever(controller.transportControls).thenReturn(transportControls)
        whenever(controller.playbackInfo).thenReturn(playbackInfo)
        whenever(controller.playbackInfo).thenReturn(playbackInfo)
        whenever(controller.metadata).thenReturn(metadataBuilder.build())
        whenever(controller.metadata).thenReturn(metadataBuilder.build())
@@ -596,7 +597,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
    fun testOnNotificationAdded_emptyTitle_hasPlaceholder() {
    fun testOnNotificationAdded_emptyTitle_hasPlaceholder() {
        // When the manager has a notification with an empty title, and the app is not
        // When the manager has a notification with an empty title, and the app is not
        // required to include a non-empty title
        // required to include a non-empty title
        val mockPackageManager = mock(PackageManager::class.java)
        val mockPackageManager = mock<PackageManager>()
        context.setMockPackageManager(mockPackageManager)
        context.setMockPackageManager(mockPackageManager)
        whenever(mockPackageManager.getApplicationLabel(any())).thenReturn(APP_NAME)
        whenever(mockPackageManager.getApplicationLabel(any())).thenReturn(APP_NAME)
        whenever(controller.metadata)
        whenever(controller.metadata)
@@ -626,7 +627,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
    fun testOnNotificationAdded_blankTitle_hasPlaceholder() {
    fun testOnNotificationAdded_blankTitle_hasPlaceholder() {
        // GIVEN that the manager has a notification with a blank title, and the app is not
        // GIVEN that the manager has a notification with a blank title, and the app is not
        // required to include a non-empty title
        // required to include a non-empty title
        val mockPackageManager = mock(PackageManager::class.java)
        val mockPackageManager = mock<PackageManager>()
        context.setMockPackageManager(mockPackageManager)
        context.setMockPackageManager(mockPackageManager)
        whenever(mockPackageManager.getApplicationLabel(any())).thenReturn(APP_NAME)
        whenever(mockPackageManager.getApplicationLabel(any())).thenReturn(APP_NAME)
        whenever(controller.metadata)
        whenever(controller.metadata)
@@ -656,7 +657,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
    fun testOnNotificationAdded_emptyMetadata_usesNotificationTitle() {
    fun testOnNotificationAdded_emptyMetadata_usesNotificationTitle() {
        // When the app sets the metadata title fields to empty strings, but does include a
        // When the app sets the metadata title fields to empty strings, but does include a
        // non-blank notification title
        // non-blank notification title
        val mockPackageManager = mock(PackageManager::class.java)
        val mockPackageManager = mock<PackageManager>()
        context.setMockPackageManager(mockPackageManager)
        context.setMockPackageManager(mockPackageManager)
        whenever(mockPackageManager.getApplicationLabel(any())).thenReturn(APP_NAME)
        whenever(mockPackageManager.getApplicationLabel(any())).thenReturn(APP_NAME)
        whenever(controller.metadata)
        whenever(controller.metadata)
@@ -1610,6 +1611,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        verify(logger, never()).logResumeMediaAdded(anyInt(), eq(PACKAGE_NAME), any())
        verify(logger, never()).logResumeMediaAdded(anyInt(), eq(PACKAGE_NAME), any())
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testTooManyCompactActions_isTruncated() {
    fun testTooManyCompactActions_isTruncated() {
        // GIVEN a notification where too many compact actions were specified
        // GIVEN a notification where too many compact actions were specified
@@ -1646,6 +1648,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
            .isEqualTo(MediaDataProcessor.MAX_COMPACT_ACTIONS)
            .isEqualTo(MediaDataProcessor.MAX_COMPACT_ACTIONS)
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testTooManyNotificationActions_isTruncated() {
    fun testTooManyNotificationActions_isTruncated() {
        // GIVEN a notification where too many notification actions are added
        // GIVEN a notification where too many notification actions are added
@@ -1681,6 +1684,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
            .isEqualTo(MediaDataProcessor.MAX_NOTIFICATION_ACTIONS)
            .isEqualTo(MediaDataProcessor.MAX_NOTIFICATION_ACTIONS)
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_noState_usesNotification() {
    fun testPlaybackActions_noState_usesNotification() {
        val desc = "Notification Action"
        val desc = "Notification Action"
@@ -1714,6 +1718,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        assertThat(mediaDataCaptor.value!!.actions[0]!!.contentDescription).isEqualTo(desc)
        assertThat(mediaDataCaptor.value!!.actions[0]!!.contentDescription).isEqualTo(desc)
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_hasPrevNext() {
    fun testPlaybackActions_hasPrevNext() {
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4")
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4")
@@ -1757,6 +1762,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[1])
        assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[1])
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_noPrevNext_usesCustom() {
    fun testPlaybackActions_noPrevNext_usesCustom() {
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4", "custom 5")
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4", "custom 5")
@@ -1789,6 +1795,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[3])
        assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[3])
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_connecting() {
    fun testPlaybackActions_connecting() {
        val stateActions = PlaybackState.ACTION_PLAY
        val stateActions = PlaybackState.ACTION_PLAY
@@ -1874,6 +1881,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
            .isNotEqualTo(firstSemanticActions.prevOrCustom?.icon)
            .isNotEqualTo(firstSemanticActions.prevOrCustom?.icon)
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_reservedSpace() {
    fun testPlaybackActions_reservedSpace() {
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4")
        val customDesc = arrayOf("custom 1", "custom 2", "custom 3", "custom 4")
@@ -1912,6 +1920,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        assertThat(actions.reservePrev).isTrue()
        assertThat(actions.reservePrev).isTrue()
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackActions_playPause_hasButton() {
    fun testPlaybackActions_playPause_hasButton() {
        val stateActions = PlaybackState.ACTION_PLAY_PAUSE
        val stateActions = PlaybackState.ACTION_PLAY_PAUSE
@@ -2074,6 +2083,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        assertThat(mediaDataCaptor.value.semanticActions).isNotNull()
        assertThat(mediaDataCaptor.value.semanticActions).isNotNull()
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testPlaybackStateNull_Pause_keyExists_callsListener() {
    fun testPlaybackStateNull_Pause_keyExists_callsListener() {
        whenever(controller.playbackState).thenReturn(null)
        whenever(controller.playbackState).thenReturn(null)
@@ -2132,6 +2142,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
        assertThat(mediaDataCaptor.value.isClearable).isFalse()
        assertThat(mediaDataCaptor.value.isClearable).isFalse()
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testRetain_notifPlayer_notifRemoved_setToResume() {
    fun testRetain_notifPlayer_notifRemoved_setToResume() {
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
@@ -2162,6 +2173,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
            )
            )
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testRetain_notifPlayer_sessionDestroyed_doesNotChange() {
    fun testRetain_notifPlayer_sessionDestroyed_doesNotChange() {
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
@@ -2180,6 +2192,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
            .onMediaDataLoaded(eq(PACKAGE_NAME), any(), any(), anyBoolean(), anyInt(), anyBoolean())
            .onMediaDataLoaded(eq(PACKAGE_NAME), any(), any(), anyBoolean(), anyInt(), anyBoolean())
    }
    }


    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_BUTTON_MEDIA3)
    @Test
    @Test
    fun testRetain_notifPlayer_removeWhileActive_fullyRemoved() {
    fun testRetain_notifPlayer_removeWhileActive_fullyRemoved() {
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
        fakeFeatureFlags.set(MEDIA_RETAIN_SESSIONS, true)
+19 −1
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Handler
import android.os.looper
import android.os.looper
import androidx.media3.session.CommandButton
import androidx.media3.session.CommandButton
import androidx.media3.session.MediaController
import androidx.media3.session.MediaController
import androidx.media3.session.SessionCommand
import androidx.media3.session.SessionToken
import androidx.media3.session.SessionToken
import com.android.systemui.Flags
import com.android.systemui.Flags
import com.android.systemui.graphics.imageLoader
import com.android.systemui.graphics.imageLoader
@@ -30,7 +31,11 @@ import com.android.systemui.kosmos.testScope
import com.android.systemui.media.controls.shared.mediaLogger
import com.android.systemui.media.controls.shared.mediaLogger
import com.android.systemui.media.controls.util.fakeMediaControllerFactory
import com.android.systemui.media.controls.util.fakeMediaControllerFactory
import com.android.systemui.media.controls.util.fakeSessionTokenFactory
import com.android.systemui.media.controls.util.fakeSessionTokenFactory
import com.android.systemui.util.concurrency.execution
import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableList
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.mock
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import org.mockito.kotlin.whenever


@@ -46,10 +51,22 @@ var Kosmos.media3ActionFactory: Media3ActionFactory by
                mock<MediaController>().also {
                mock<MediaController>().also {
                    whenever(it.customLayout).thenReturn(customLayout)
                    whenever(it.customLayout).thenReturn(customLayout)
                    whenever(it.sessionExtras).thenReturn(Bundle())
                    whenever(it.sessionExtras).thenReturn(Bundle())
                    whenever(it.isCommandAvailable(any())).thenReturn(true)
                    whenever(it.isSessionCommandAvailable(any<SessionCommand>())).thenReturn(true)
                }
                }
            fakeMediaControllerFactory.setMedia3Controller(media3Controller)
            fakeMediaControllerFactory.setMedia3Controller(media3Controller)
            fakeSessionTokenFactory.setMedia3SessionToken(mock<SessionToken>())
            fakeSessionTokenFactory.setMedia3SessionToken(mock<SessionToken>())
        }
        }

        val runnableCaptor = argumentCaptor<Runnable>()
        val handler =
            mock<Handler> {
                on { post(runnableCaptor.capture()) } doAnswer
                    {
                        runnableCaptor.lastValue.run()
                        true
                    }
            }
        Media3ActionFactory(
        Media3ActionFactory(
            context = applicationContext,
            context = applicationContext,
            imageLoader = imageLoader,
            imageLoader = imageLoader,
@@ -57,7 +74,8 @@ var Kosmos.media3ActionFactory: Media3ActionFactory by
            tokenFactory = fakeSessionTokenFactory,
            tokenFactory = fakeSessionTokenFactory,
            logger = mediaLogger,
            logger = mediaLogger,
            looper = looper,
            looper = looper,
            handler = Handler(looper),
            handler = handler,
            bgScope = testScope,
            bgScope = testScope,
            execution = execution,
        )
        )
    }
    }