Loading packages/SystemUI/multivalentTests/src/com/android/systemui/volume/domain/interactor/AudioOutputInteractorTest.kt +25 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.systemui.kosmos.testScope import com.android.systemui.testKosmos import com.android.systemui.volume.data.repository.TestAudioDevicesFactory import com.android.systemui.volume.data.repository.audioRepository import com.android.systemui.volume.data.repository.audioSharingRepository import com.android.systemui.volume.domain.model.AudioOutputDevice import com.android.systemui.volume.localMediaController import com.android.systemui.volume.localMediaRepository Loading Loading @@ -69,6 +70,7 @@ class AudioOutputInteractorTest : SysuiTestCase() { addOverride(R.drawable.ic_smartphone, testIcon) addOverride(R.drawable.ic_media_speaker_device, testIcon) addOverride(R.drawable.ic_media_tablet, testIcon) addOverride(com.android.internal.R.drawable.ic_settings_bluetooth, testIcon) addOverride(com.android.internal.R.drawable.ic_bt_hearing_aid, testIcon) Loading Loading @@ -215,6 +217,29 @@ class AudioOutputInteractorTest : SysuiTestCase() { } } @Test fun inAudioSharing_returnsPrimaryDevice() { with(kosmos) { testScope.runTest { val cachedBluetoothDevice: CachedBluetoothDevice = mock { on { name }.thenReturn("audio_sharing_device_name") } with(audioSharingRepository) { setInAudioSharing(true) setPrimaryDevice(cachedBluetoothDevice) } val device by collectLastValue(underTest.currentAudioDevice) runCurrent() assertThat(device).isInstanceOf(AudioOutputDevice.Bluetooth::class.java) assertThat(device!!.icon).isEqualTo(testIcon) assertThat(device!!.name).isEqualTo("audio_sharing_device_name") } } } private companion object { val testIcon = TestStubDrawable() Loading packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorTest.kt +43 −9 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.media.flags.Flags import com.android.settingslib.R import com.android.settingslib.bluetooth.CachedBluetoothDevice import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.testScope Loading @@ -47,6 +48,7 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.mock import org.mockito.kotlin.whenever private const val builtInDeviceName = "This phone" Loading @@ -71,6 +73,7 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { with(context.orCreateTestableResources) { addOverride(R.drawable.ic_smartphone, testIcon) addOverride(R.drawable.ic_media_tablet, testIcon) addOverride(com.android.internal.R.drawable.ic_settings_bluetooth, testIcon) addOverride(R.string.media_transfer_this_device_name_tv, builtInDeviceName) addOverride(R.string.media_transfer_this_device_name_tablet, builtInDeviceName) Loading Loading @@ -161,10 +164,13 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { fun hasSession_stateIs_MediaSession_canOpenAudioSwitcherDuringAudioSharing() = with(kosmos) { testScope.runTest { audioSharingRepository.setInAudioSharing(true) localMediaRepository.updateCurrentConnectedDevice( TestMediaDevicesFactory.builtInMediaDevice() ) val cachedBluetoothDevice: CachedBluetoothDevice = mock { on { name }.thenReturn("audio_sharing_device_name") } with(audioSharingRepository) { setInAudioSharing(true) setPrimaryDevice(cachedBluetoothDevice) } mediaControllerRepository.setActiveSessions(listOf(localMediaController)) val model by collectLastValue(underTest.mediaOutputModel.filterData()) Loading @@ -175,7 +181,13 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { assertThat(session.packageName).isEqualTo("local.test.pkg") assertThat(session.canAdjustVolume).isTrue() assertThat(device) .isEqualTo(AudioOutputDevice.BuiltIn("built_in_media", testIcon)) .isEqualTo( AudioOutputDevice.Bluetooth( "audio_sharing_device_name", testIcon, cachedBluetoothDevice, ) ) assertThat(isInAudioSharing).isTrue() assertThat(canOpenAudioSwitcher).isTrue() } Loading @@ -187,7 +199,13 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { fun noMediaOrCall_stateIs_Idle() = with(kosmos) { testScope.runTest { audioSharingRepository.setInAudioSharing(true) val cachedBluetoothDevice: CachedBluetoothDevice = mock { on { name }.thenReturn("audio_sharing_device_name") } with(audioSharingRepository) { setInAudioSharing(true) setPrimaryDevice(cachedBluetoothDevice) } val model by collectLastValue(underTest.mediaOutputModel.filterData()) runCurrent() Loading @@ -195,7 +213,12 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { assertThat(model) .isEqualTo( MediaOutputComponentModel.Idle( device = AudioOutputDevice.BuiltIn("built_in_media", testIcon), device = AudioOutputDevice.Bluetooth( "audio_sharing_device_name", testIcon, cachedBluetoothDevice, ), isInAudioSharing = true, canOpenAudioSwitcher = false, ) Loading @@ -208,7 +231,13 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { fun noMediaOrCall_stateIs_Idle_canOpenAudioSwitcherDuringAudioSharing() = with(kosmos) { testScope.runTest { audioSharingRepository.setInAudioSharing(true) val cachedBluetoothDevice: CachedBluetoothDevice = mock { on { name }.thenReturn("audio_sharing_device_name") } with(audioSharingRepository) { setInAudioSharing(true) setPrimaryDevice(cachedBluetoothDevice) } val model by collectLastValue(underTest.mediaOutputModel.filterData()) runCurrent() Loading @@ -216,7 +245,12 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { assertThat(model) .isEqualTo( MediaOutputComponentModel.Idle( device = AudioOutputDevice.BuiltIn("built_in_media", testIcon), device = AudioOutputDevice.Bluetooth( "audio_sharing_device_name", testIcon, cachedBluetoothDevice, ), isInAudioSharing = true, canOpenAudioSwitcher = true, ) Loading packages/SystemUI/src/com/android/systemui/volume/domain/interactor/AudioOutputInteractor.kt +19 −15 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ constructor( private val bluetoothAdapter: BluetoothAdapter?, private val deviceIconInteractor: DeviceIconInteractor, private val mediaOutputInteractor: MediaOutputInteractor, private val audioSharingInteractor: AudioSharingInteractor, ) { val currentAudioDevice: StateFlow<AudioOutputDevice> = Loading @@ -65,12 +66,18 @@ constructor( audioRepository.communicationDevice.map { communicationDevice -> communicationDevice?.toAudioOutputDevice() } } else { audioSharingInteractor.isInAudioSharing.flatMapLatest { inAudioSharing -> if (inAudioSharing) { audioSharingInteractor.primaryDevice.map { it?.toAudioOutputDevice() } } else { mediaOutputInteractor.currentConnectedDevice.map { mediaDevice -> mediaDevice?.toAudioOutputDevice() } } } } } .map { it ?: AudioOutputDevice.Unknown } .flowOn(backgroundCoroutineContext) .stateIn(scope, SharingStarted.Eagerly, AudioOutputDevice.Unavailable) Loading Loading @@ -104,6 +111,13 @@ constructor( ) } private fun CachedBluetoothDevice.toAudioOutputDevice(): AudioOutputDevice = AudioOutputDevice.Bluetooth( name = name, icon = deviceIconInteractor.loadIcon(this), cachedBluetoothDevice = this, ) private fun MediaDevice.toAudioOutputDevice(): AudioOutputDevice { return when { this is BluetoothMediaDevice -> Loading @@ -114,20 +128,10 @@ constructor( ) deviceType == MediaDeviceType.TYPE_3POINT5_MM_AUDIO_DEVICE || deviceType == MediaDeviceType.TYPE_USB_C_AUDIO_DEVICE -> AudioOutputDevice.Wired( name = name, icon = icon, ) AudioOutputDevice.Wired(name = name, icon = icon) deviceType == MediaDeviceType.TYPE_CAST_DEVICE -> AudioOutputDevice.Remote( name = name, icon = icon, ) else -> AudioOutputDevice.BuiltIn( name = name, icon = icon, ) AudioOutputDevice.Remote(name = name, icon = icon) else -> AudioOutputDevice.BuiltIn(name = name, icon = icon) } } } packages/SystemUI/tests/utils/src/com/android/systemui/volume/domain/interactor/AudioOutputInteractorKosmos.kt +1 −0 Original line number Diff line number Diff line Loading @@ -36,5 +36,6 @@ val Kosmos.audioOutputInteractor by bluetoothAdapter, deviceIconInteractor, mediaOutputInteractor, audioSharingInteractor, ) } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/volume/domain/interactor/AudioOutputInteractorTest.kt +25 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.systemui.kosmos.testScope import com.android.systemui.testKosmos import com.android.systemui.volume.data.repository.TestAudioDevicesFactory import com.android.systemui.volume.data.repository.audioRepository import com.android.systemui.volume.data.repository.audioSharingRepository import com.android.systemui.volume.domain.model.AudioOutputDevice import com.android.systemui.volume.localMediaController import com.android.systemui.volume.localMediaRepository Loading Loading @@ -69,6 +70,7 @@ class AudioOutputInteractorTest : SysuiTestCase() { addOverride(R.drawable.ic_smartphone, testIcon) addOverride(R.drawable.ic_media_speaker_device, testIcon) addOverride(R.drawable.ic_media_tablet, testIcon) addOverride(com.android.internal.R.drawable.ic_settings_bluetooth, testIcon) addOverride(com.android.internal.R.drawable.ic_bt_hearing_aid, testIcon) Loading Loading @@ -215,6 +217,29 @@ class AudioOutputInteractorTest : SysuiTestCase() { } } @Test fun inAudioSharing_returnsPrimaryDevice() { with(kosmos) { testScope.runTest { val cachedBluetoothDevice: CachedBluetoothDevice = mock { on { name }.thenReturn("audio_sharing_device_name") } with(audioSharingRepository) { setInAudioSharing(true) setPrimaryDevice(cachedBluetoothDevice) } val device by collectLastValue(underTest.currentAudioDevice) runCurrent() assertThat(device).isInstanceOf(AudioOutputDevice.Bluetooth::class.java) assertThat(device!!.icon).isEqualTo(testIcon) assertThat(device!!.name).isEqualTo("audio_sharing_device_name") } } } private companion object { val testIcon = TestStubDrawable() Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/interactor/MediaOutputComponentInteractorTest.kt +43 −9 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.media.flags.Flags import com.android.settingslib.R import com.android.settingslib.bluetooth.CachedBluetoothDevice import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.testScope Loading @@ -47,6 +48,7 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.mock import org.mockito.kotlin.whenever private const val builtInDeviceName = "This phone" Loading @@ -71,6 +73,7 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { with(context.orCreateTestableResources) { addOverride(R.drawable.ic_smartphone, testIcon) addOverride(R.drawable.ic_media_tablet, testIcon) addOverride(com.android.internal.R.drawable.ic_settings_bluetooth, testIcon) addOverride(R.string.media_transfer_this_device_name_tv, builtInDeviceName) addOverride(R.string.media_transfer_this_device_name_tablet, builtInDeviceName) Loading Loading @@ -161,10 +164,13 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { fun hasSession_stateIs_MediaSession_canOpenAudioSwitcherDuringAudioSharing() = with(kosmos) { testScope.runTest { audioSharingRepository.setInAudioSharing(true) localMediaRepository.updateCurrentConnectedDevice( TestMediaDevicesFactory.builtInMediaDevice() ) val cachedBluetoothDevice: CachedBluetoothDevice = mock { on { name }.thenReturn("audio_sharing_device_name") } with(audioSharingRepository) { setInAudioSharing(true) setPrimaryDevice(cachedBluetoothDevice) } mediaControllerRepository.setActiveSessions(listOf(localMediaController)) val model by collectLastValue(underTest.mediaOutputModel.filterData()) Loading @@ -175,7 +181,13 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { assertThat(session.packageName).isEqualTo("local.test.pkg") assertThat(session.canAdjustVolume).isTrue() assertThat(device) .isEqualTo(AudioOutputDevice.BuiltIn("built_in_media", testIcon)) .isEqualTo( AudioOutputDevice.Bluetooth( "audio_sharing_device_name", testIcon, cachedBluetoothDevice, ) ) assertThat(isInAudioSharing).isTrue() assertThat(canOpenAudioSwitcher).isTrue() } Loading @@ -187,7 +199,13 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { fun noMediaOrCall_stateIs_Idle() = with(kosmos) { testScope.runTest { audioSharingRepository.setInAudioSharing(true) val cachedBluetoothDevice: CachedBluetoothDevice = mock { on { name }.thenReturn("audio_sharing_device_name") } with(audioSharingRepository) { setInAudioSharing(true) setPrimaryDevice(cachedBluetoothDevice) } val model by collectLastValue(underTest.mediaOutputModel.filterData()) runCurrent() Loading @@ -195,7 +213,12 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { assertThat(model) .isEqualTo( MediaOutputComponentModel.Idle( device = AudioOutputDevice.BuiltIn("built_in_media", testIcon), device = AudioOutputDevice.Bluetooth( "audio_sharing_device_name", testIcon, cachedBluetoothDevice, ), isInAudioSharing = true, canOpenAudioSwitcher = false, ) Loading @@ -208,7 +231,13 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { fun noMediaOrCall_stateIs_Idle_canOpenAudioSwitcherDuringAudioSharing() = with(kosmos) { testScope.runTest { audioSharingRepository.setInAudioSharing(true) val cachedBluetoothDevice: CachedBluetoothDevice = mock { on { name }.thenReturn("audio_sharing_device_name") } with(audioSharingRepository) { setInAudioSharing(true) setPrimaryDevice(cachedBluetoothDevice) } val model by collectLastValue(underTest.mediaOutputModel.filterData()) runCurrent() Loading @@ -216,7 +245,12 @@ class MediaOutputComponentInteractorTest : SysuiTestCase() { assertThat(model) .isEqualTo( MediaOutputComponentModel.Idle( device = AudioOutputDevice.BuiltIn("built_in_media", testIcon), device = AudioOutputDevice.Bluetooth( "audio_sharing_device_name", testIcon, cachedBluetoothDevice, ), isInAudioSharing = true, canOpenAudioSwitcher = true, ) Loading
packages/SystemUI/src/com/android/systemui/volume/domain/interactor/AudioOutputInteractor.kt +19 −15 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ constructor( private val bluetoothAdapter: BluetoothAdapter?, private val deviceIconInteractor: DeviceIconInteractor, private val mediaOutputInteractor: MediaOutputInteractor, private val audioSharingInteractor: AudioSharingInteractor, ) { val currentAudioDevice: StateFlow<AudioOutputDevice> = Loading @@ -65,12 +66,18 @@ constructor( audioRepository.communicationDevice.map { communicationDevice -> communicationDevice?.toAudioOutputDevice() } } else { audioSharingInteractor.isInAudioSharing.flatMapLatest { inAudioSharing -> if (inAudioSharing) { audioSharingInteractor.primaryDevice.map { it?.toAudioOutputDevice() } } else { mediaOutputInteractor.currentConnectedDevice.map { mediaDevice -> mediaDevice?.toAudioOutputDevice() } } } } } .map { it ?: AudioOutputDevice.Unknown } .flowOn(backgroundCoroutineContext) .stateIn(scope, SharingStarted.Eagerly, AudioOutputDevice.Unavailable) Loading Loading @@ -104,6 +111,13 @@ constructor( ) } private fun CachedBluetoothDevice.toAudioOutputDevice(): AudioOutputDevice = AudioOutputDevice.Bluetooth( name = name, icon = deviceIconInteractor.loadIcon(this), cachedBluetoothDevice = this, ) private fun MediaDevice.toAudioOutputDevice(): AudioOutputDevice { return when { this is BluetoothMediaDevice -> Loading @@ -114,20 +128,10 @@ constructor( ) deviceType == MediaDeviceType.TYPE_3POINT5_MM_AUDIO_DEVICE || deviceType == MediaDeviceType.TYPE_USB_C_AUDIO_DEVICE -> AudioOutputDevice.Wired( name = name, icon = icon, ) AudioOutputDevice.Wired(name = name, icon = icon) deviceType == MediaDeviceType.TYPE_CAST_DEVICE -> AudioOutputDevice.Remote( name = name, icon = icon, ) else -> AudioOutputDevice.BuiltIn( name = name, icon = icon, ) AudioOutputDevice.Remote(name = name, icon = icon) else -> AudioOutputDevice.BuiltIn(name = name, icon = icon) } } }
packages/SystemUI/tests/utils/src/com/android/systemui/volume/domain/interactor/AudioOutputInteractorKosmos.kt +1 −0 Original line number Diff line number Diff line Loading @@ -36,5 +36,6 @@ val Kosmos.audioOutputInteractor by bluetoothAdapter, deviceIconInteractor, mediaOutputInteractor, audioSharingInteractor, ) }