Loading packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputInteractorTest.kt +8 −12 Original line number Diff line number Diff line Loading @@ -26,9 +26,8 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.testKosmos import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.volume.data.repository.FakeLocalMediaRepository import com.android.systemui.volume.localMediaController import com.android.systemui.volume.localMediaRepositoryFactory Loading @@ -42,7 +41,6 @@ import com.android.systemui.volume.remoteMediaController import com.android.systemui.volume.remotePlaybackInfo import com.android.systemui.volume.remotePlaybackStateBuilder import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test Loading @@ -53,7 +51,7 @@ import org.junit.runner.RunWith @TestableLooper.RunWithLooper(setAsMainLooper = true) class MediaOutputInteractorTest : SysuiTestCase() { private val kosmos = testKosmos() private val kosmos = testKosmos().useUnconfinedTestDispatcher() private lateinit var underTest: MediaOutputInteractor Loading @@ -64,7 +62,9 @@ class MediaOutputInteractorTest : SysuiTestCase() { "local.test.pkg", FakeLocalMediaRepository().apply { updateCurrentConnectedDevice( mock { whenever(name).thenReturn("local_media_device") } TestMediaDevicesFactory.builtInMediaDevice( deviceName = "local_media_device" ) ) }, ) Loading @@ -72,7 +72,9 @@ class MediaOutputInteractorTest : SysuiTestCase() { "remote.test.pkg", FakeLocalMediaRepository().apply { updateCurrentConnectedDevice( mock { whenever(name).thenReturn("remote_media_device") } TestMediaDevicesFactory.remoteMediaDevice( deviceName = "remote_media_device" ) ) }, ) Loading @@ -88,7 +90,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val activeMediaDeviceSessions by collectLastValue(underTest.activeMediaDeviceSessions) runCurrent() assertThat(activeMediaDeviceSessions!!.local).isNull() assertThat(activeMediaDeviceSessions!!.remote).isNull() Loading @@ -105,7 +106,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val activeMediaDeviceSessions by collectLastValue(underTest.activeMediaDeviceSessions) runCurrent() with(activeMediaDeviceSessions!!.local!!) { assertThat(packageName).isEqualTo("local.test.pkg") Loading Loading @@ -148,7 +148,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val activeMediaDeviceSessions by collectLastValue(underTest.activeMediaDeviceSessions) runCurrent() assertThat(activeMediaDeviceSessions!!.local!!.canAdjustVolume).isFalse() assertThat(activeMediaDeviceSessions!!.remote!!.canAdjustVolume).isFalse() Loading @@ -168,7 +167,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val defaultActiveMediaSession by collectLastValue(underTest.defaultActiveMediaSession) val currentDevice by collectLastValue(underTest.currentConnectedDevice) runCurrent() with((defaultActiveMediaSession as Result.Data<MediaDeviceSession?>).data!!) { assertThat(packageName).isEqualTo("local.test.pkg") Loading @@ -192,7 +190,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val defaultActiveMediaSession by collectLastValue(underTest.defaultActiveMediaSession) val currentDevice by collectLastValue(underTest.currentConnectedDevice) runCurrent() with((defaultActiveMediaSession as Result.Data<MediaDeviceSession?>).data!!) { assertThat(packageName).isEqualTo("remote.test.pkg") Loading @@ -216,7 +213,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val defaultActiveMediaSession by collectLastValue(underTest.defaultActiveMediaSession) val currentDevice by collectLastValue(underTest.currentConnectedDevice) runCurrent() with((defaultActiveMediaSession as Result.Data<MediaDeviceSession?>).data!!) { assertThat(packageName).isEqualTo("local.test.pkg") Loading packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/data/repository/LocalMediaRepositoryFactory.kt +14 −8 Original line number Diff line number Diff line Loading @@ -19,13 +19,16 @@ import com.android.settingslib.volume.data.repository.LocalMediaRepository import com.android.settingslib.volume.data.repository.LocalMediaRepositoryImpl import com.android.settingslib.volume.shared.AudioManagerEventsReceiver import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.media.controls.util.LocalMediaManagerFactory import javax.inject.Inject import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext interface LocalMediaRepositoryFactory { fun create(packageName: String?, coroutineScope: CoroutineScope): LocalMediaRepository suspend fun create(packageName: String?, coroutineScope: CoroutineScope): LocalMediaRepository } @SysUISingleton Loading @@ -34,15 +37,18 @@ class LocalMediaRepositoryFactoryImpl constructor( private val eventsReceiver: AudioManagerEventsReceiver, private val localMediaManagerFactory: LocalMediaManagerFactory, @Background private val backgroundCoroutineContext: CoroutineContext, ) : LocalMediaRepositoryFactory { override fun create( override suspend fun create( packageName: String?, coroutineScope: CoroutineScope coroutineScope: CoroutineScope, ): LocalMediaRepository = withContext(backgroundCoroutineContext) { LocalMediaRepositoryImpl( eventsReceiver, localMediaManagerFactory.create(packageName), coroutineScope, ) } } packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputInteractor.kt +2 −1 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ constructor( .onStart { emit(activeSessions) } } .map { getMediaControllers(it) } .flowOn(backgroundCoroutineContext) .stateIn(coroutineScope, SharingStarted.WhileSubscribed(), MediaControllers(null, null)) /** [MediaDeviceSessions] that contains currently active sessions. */ Loading Loading @@ -131,7 +132,7 @@ constructor( var remoteController: MediaController? = null val remoteMediaSessions: MutableSet<String> = mutableSetOf() for (controller in controllers) { val playbackInfo: MediaController.PlaybackInfo = controller.playbackInfo ?: continue val playbackInfo: MediaController.PlaybackInfo = controller.playbackInfo when (playbackInfo.playbackType) { MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE -> { // MediaController can't be local if there is a remote one for the same Loading packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/mediaoutput/data/repository/FakeLocalMediaRepositoryFactory.kt +2 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,8 @@ class FakeLocalMediaRepositoryFactory(private val defaultProvider: () -> LocalMe repositories[packageName] = localMediaRepository } override fun create( override suspend fun create( packageName: String?, coroutineScope: CoroutineScope coroutineScope: CoroutineScope, ): LocalMediaRepository = repositories[packageName] ?: defaultProvider() } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputInteractorTest.kt +8 −12 Original line number Diff line number Diff line Loading @@ -26,9 +26,8 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.testKosmos import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.volume.data.repository.FakeLocalMediaRepository import com.android.systemui.volume.localMediaController import com.android.systemui.volume.localMediaRepositoryFactory Loading @@ -42,7 +41,6 @@ import com.android.systemui.volume.remoteMediaController import com.android.systemui.volume.remotePlaybackInfo import com.android.systemui.volume.remotePlaybackStateBuilder import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test Loading @@ -53,7 +51,7 @@ import org.junit.runner.RunWith @TestableLooper.RunWithLooper(setAsMainLooper = true) class MediaOutputInteractorTest : SysuiTestCase() { private val kosmos = testKosmos() private val kosmos = testKosmos().useUnconfinedTestDispatcher() private lateinit var underTest: MediaOutputInteractor Loading @@ -64,7 +62,9 @@ class MediaOutputInteractorTest : SysuiTestCase() { "local.test.pkg", FakeLocalMediaRepository().apply { updateCurrentConnectedDevice( mock { whenever(name).thenReturn("local_media_device") } TestMediaDevicesFactory.builtInMediaDevice( deviceName = "local_media_device" ) ) }, ) Loading @@ -72,7 +72,9 @@ class MediaOutputInteractorTest : SysuiTestCase() { "remote.test.pkg", FakeLocalMediaRepository().apply { updateCurrentConnectedDevice( mock { whenever(name).thenReturn("remote_media_device") } TestMediaDevicesFactory.remoteMediaDevice( deviceName = "remote_media_device" ) ) }, ) Loading @@ -88,7 +90,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val activeMediaDeviceSessions by collectLastValue(underTest.activeMediaDeviceSessions) runCurrent() assertThat(activeMediaDeviceSessions!!.local).isNull() assertThat(activeMediaDeviceSessions!!.remote).isNull() Loading @@ -105,7 +106,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val activeMediaDeviceSessions by collectLastValue(underTest.activeMediaDeviceSessions) runCurrent() with(activeMediaDeviceSessions!!.local!!) { assertThat(packageName).isEqualTo("local.test.pkg") Loading Loading @@ -148,7 +148,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val activeMediaDeviceSessions by collectLastValue(underTest.activeMediaDeviceSessions) runCurrent() assertThat(activeMediaDeviceSessions!!.local!!.canAdjustVolume).isFalse() assertThat(activeMediaDeviceSessions!!.remote!!.canAdjustVolume).isFalse() Loading @@ -168,7 +167,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val defaultActiveMediaSession by collectLastValue(underTest.defaultActiveMediaSession) val currentDevice by collectLastValue(underTest.currentConnectedDevice) runCurrent() with((defaultActiveMediaSession as Result.Data<MediaDeviceSession?>).data!!) { assertThat(packageName).isEqualTo("local.test.pkg") Loading @@ -192,7 +190,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val defaultActiveMediaSession by collectLastValue(underTest.defaultActiveMediaSession) val currentDevice by collectLastValue(underTest.currentConnectedDevice) runCurrent() with((defaultActiveMediaSession as Result.Data<MediaDeviceSession?>).data!!) { assertThat(packageName).isEqualTo("remote.test.pkg") Loading @@ -216,7 +213,6 @@ class MediaOutputInteractorTest : SysuiTestCase() { val defaultActiveMediaSession by collectLastValue(underTest.defaultActiveMediaSession) val currentDevice by collectLastValue(underTest.currentConnectedDevice) runCurrent() with((defaultActiveMediaSession as Result.Data<MediaDeviceSession?>).data!!) { assertThat(packageName).isEqualTo("local.test.pkg") Loading
packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/data/repository/LocalMediaRepositoryFactory.kt +14 −8 Original line number Diff line number Diff line Loading @@ -19,13 +19,16 @@ import com.android.settingslib.volume.data.repository.LocalMediaRepository import com.android.settingslib.volume.data.repository.LocalMediaRepositoryImpl import com.android.settingslib.volume.shared.AudioManagerEventsReceiver import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.media.controls.util.LocalMediaManagerFactory import javax.inject.Inject import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext interface LocalMediaRepositoryFactory { fun create(packageName: String?, coroutineScope: CoroutineScope): LocalMediaRepository suspend fun create(packageName: String?, coroutineScope: CoroutineScope): LocalMediaRepository } @SysUISingleton Loading @@ -34,15 +37,18 @@ class LocalMediaRepositoryFactoryImpl constructor( private val eventsReceiver: AudioManagerEventsReceiver, private val localMediaManagerFactory: LocalMediaManagerFactory, @Background private val backgroundCoroutineContext: CoroutineContext, ) : LocalMediaRepositoryFactory { override fun create( override suspend fun create( packageName: String?, coroutineScope: CoroutineScope coroutineScope: CoroutineScope, ): LocalMediaRepository = withContext(backgroundCoroutineContext) { LocalMediaRepositoryImpl( eventsReceiver, localMediaManagerFactory.create(packageName), coroutineScope, ) } }
packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputInteractor.kt +2 −1 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ constructor( .onStart { emit(activeSessions) } } .map { getMediaControllers(it) } .flowOn(backgroundCoroutineContext) .stateIn(coroutineScope, SharingStarted.WhileSubscribed(), MediaControllers(null, null)) /** [MediaDeviceSessions] that contains currently active sessions. */ Loading Loading @@ -131,7 +132,7 @@ constructor( var remoteController: MediaController? = null val remoteMediaSessions: MutableSet<String> = mutableSetOf() for (controller in controllers) { val playbackInfo: MediaController.PlaybackInfo = controller.playbackInfo ?: continue val playbackInfo: MediaController.PlaybackInfo = controller.playbackInfo when (playbackInfo.playbackType) { MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE -> { // MediaController can't be local if there is a remote one for the same Loading
packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/mediaoutput/data/repository/FakeLocalMediaRepositoryFactory.kt +2 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,8 @@ class FakeLocalMediaRepositoryFactory(private val defaultProvider: () -> LocalMe repositories[packageName] = localMediaRepository } override fun create( override suspend fun create( packageName: String?, coroutineScope: CoroutineScope coroutineScope: CoroutineScope, ): LocalMediaRepository = repositories[packageName] ?: defaultProvider() }