Loading packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/mediaoutput/MediaOutputModule.kt +2 −2 Original line number Diff line number Diff line Loading @@ -16,9 +16,9 @@ package com.android.systemui.volume.panel.component.mediaoutput import com.android.systemui.volume.panel.component.mediaoutput.domain.MediaOutputAvailabilityCriteria import com.android.systemui.volume.panel.component.mediaoutput.ui.composable.MediaOutputComponent import com.android.systemui.volume.panel.component.shared.model.VolumePanelComponents import com.android.systemui.volume.panel.domain.AlwaysAvailableCriteria import com.android.systemui.volume.panel.domain.ComponentAvailabilityCriteria import com.android.systemui.volume.panel.shared.model.VolumePanelUiComponent import dagger.Binds Loading @@ -39,6 +39,6 @@ interface MediaOutputModule { @IntoMap @StringKey(VolumePanelComponents.MEDIA_OUTPUT) fun bindComponentAvailabilityCriteria( criteria: AlwaysAvailableCriteria criteria: MediaOutputAvailabilityCriteria ): ComponentAvailabilityCriteria } packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/MediaOutputAvailabilityCriteriaTest.kt 0 → 100644 +76 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.volume.panel.component.mediaoutput.domain import android.content.mockedContext import android.content.packageManager import android.content.pm.PackageManager.FEATURE_PC import android.testing.TestableLooper import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.testKosmos import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(AndroidJUnit4::class) @TestableLooper.RunWithLooper(setAsMainLooper = true) class MediaOutputAvailabilityCriteriaTest : SysuiTestCase() { private val kosmos = testKosmos() private val scope = kosmos.testScope private lateinit var underTest: MediaOutputAvailabilityCriteria @Before fun setup() { with(kosmos) { underTest = MediaOutputAvailabilityCriteria(kosmos.mockedContext, scope.backgroundScope) } } @Test fun isDesktop_unavailable() = kosmos.runTest { whenever(mockedContext.getPackageManager()).thenReturn(packageManager) whenever(packageManager.hasSystemFeature(FEATURE_PC)).thenReturn(true) val isAvailable by collectLastValue(underTest.isAvailable()) assertThat(isAvailable).isFalse() } @Test fun notIsDesktop_available() = kosmos.runTest { whenever(mockedContext.getPackageManager()).thenReturn(packageManager) whenever(packageManager.hasSystemFeature(FEATURE_PC)).thenReturn(false) val isAvailable by collectLastValue(underTest.isAvailable()) assertThat(isAvailable).isTrue() } } packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/MediaOutputAvailabilityCriteria.kt 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.volume.panel.component.mediaoutput.domain import android.content.Context import com.android.settingslib.media.PhoneMediaDevice.isDesktop import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope import com.android.systemui.volume.panel.domain.ComponentAvailabilityCriteria import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.stateIn @VolumePanelScope class MediaOutputAvailabilityCriteria @Inject constructor( @Application private val context: Context, @VolumePanelScope private val scope: CoroutineScope, ) : ComponentAvailabilityCriteria { private val availability = flow { emit(!isDesktop(context)) }.stateIn(scope, SharingStarted.WhileSubscribed(), false) override fun isAvailable(): Flow<Boolean> = availability } packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/mediaoutput/MediaOutputModuleKosmos.kt +7 −4 Original line number Diff line number Diff line Loading @@ -16,13 +16,16 @@ package com.android.systemui.volume.panel.component.mediaoutput import android.content.applicationContext import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testScope import com.android.systemui.volume.panel.component.mediaoutput.domain.MediaOutputAvailabilityCriteria import com.android.systemui.volume.panel.component.mediaoutput.ui.composable.MediaOutputComponent import com.android.systemui.volume.panel.component.mediaoutput.ui.viewmodel.mediaOutputViewModel import com.android.systemui.volume.panel.domain.ComponentAvailabilityCriteria import com.android.systemui.volume.panel.domain.availableCriteria var Kosmos.mediaOutputComponent: MediaOutputComponent by Kosmos.Fixture { MediaOutputComponent(mediaOutputViewModel) } var Kosmos.mediaOutputAvailabilityCriteria: ComponentAvailabilityCriteria by Kosmos.Fixture { availableCriteria } var Kosmos.mediaOutputAvailabilityCriteria by Kosmos.Fixture { MediaOutputAvailabilityCriteria(applicationContext, testScope.backgroundScope) } Loading
packages/SystemUI/compose/features/src/com/android/systemui/volume/panel/component/mediaoutput/MediaOutputModule.kt +2 −2 Original line number Diff line number Diff line Loading @@ -16,9 +16,9 @@ package com.android.systemui.volume.panel.component.mediaoutput import com.android.systemui.volume.panel.component.mediaoutput.domain.MediaOutputAvailabilityCriteria import com.android.systemui.volume.panel.component.mediaoutput.ui.composable.MediaOutputComponent import com.android.systemui.volume.panel.component.shared.model.VolumePanelComponents import com.android.systemui.volume.panel.domain.AlwaysAvailableCriteria import com.android.systemui.volume.panel.domain.ComponentAvailabilityCriteria import com.android.systemui.volume.panel.shared.model.VolumePanelUiComponent import dagger.Binds Loading @@ -39,6 +39,6 @@ interface MediaOutputModule { @IntoMap @StringKey(VolumePanelComponents.MEDIA_OUTPUT) fun bindComponentAvailabilityCriteria( criteria: AlwaysAvailableCriteria criteria: MediaOutputAvailabilityCriteria ): ComponentAvailabilityCriteria }
packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/mediaoutput/domain/MediaOutputAvailabilityCriteriaTest.kt 0 → 100644 +76 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.volume.panel.component.mediaoutput.domain import android.content.mockedContext import android.content.packageManager import android.content.pm.PackageManager.FEATURE_PC import android.testing.TestableLooper import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.testKosmos import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(AndroidJUnit4::class) @TestableLooper.RunWithLooper(setAsMainLooper = true) class MediaOutputAvailabilityCriteriaTest : SysuiTestCase() { private val kosmos = testKosmos() private val scope = kosmos.testScope private lateinit var underTest: MediaOutputAvailabilityCriteria @Before fun setup() { with(kosmos) { underTest = MediaOutputAvailabilityCriteria(kosmos.mockedContext, scope.backgroundScope) } } @Test fun isDesktop_unavailable() = kosmos.runTest { whenever(mockedContext.getPackageManager()).thenReturn(packageManager) whenever(packageManager.hasSystemFeature(FEATURE_PC)).thenReturn(true) val isAvailable by collectLastValue(underTest.isAvailable()) assertThat(isAvailable).isFalse() } @Test fun notIsDesktop_available() = kosmos.runTest { whenever(mockedContext.getPackageManager()).thenReturn(packageManager) whenever(packageManager.hasSystemFeature(FEATURE_PC)).thenReturn(false) val isAvailable by collectLastValue(underTest.isAvailable()) assertThat(isAvailable).isTrue() } }
packages/SystemUI/src/com/android/systemui/volume/panel/component/mediaoutput/domain/MediaOutputAvailabilityCriteria.kt 0 → 100644 +43 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.volume.panel.component.mediaoutput.domain import android.content.Context import com.android.settingslib.media.PhoneMediaDevice.isDesktop import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope import com.android.systemui.volume.panel.domain.ComponentAvailabilityCriteria import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.stateIn @VolumePanelScope class MediaOutputAvailabilityCriteria @Inject constructor( @Application private val context: Context, @VolumePanelScope private val scope: CoroutineScope, ) : ComponentAvailabilityCriteria { private val availability = flow { emit(!isDesktop(context)) }.stateIn(scope, SharingStarted.WhileSubscribed(), false) override fun isAvailable(): Flow<Boolean> = availability }
packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/mediaoutput/MediaOutputModuleKosmos.kt +7 −4 Original line number Diff line number Diff line Loading @@ -16,13 +16,16 @@ package com.android.systemui.volume.panel.component.mediaoutput import android.content.applicationContext import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testScope import com.android.systemui.volume.panel.component.mediaoutput.domain.MediaOutputAvailabilityCriteria import com.android.systemui.volume.panel.component.mediaoutput.ui.composable.MediaOutputComponent import com.android.systemui.volume.panel.component.mediaoutput.ui.viewmodel.mediaOutputViewModel import com.android.systemui.volume.panel.domain.ComponentAvailabilityCriteria import com.android.systemui.volume.panel.domain.availableCriteria var Kosmos.mediaOutputComponent: MediaOutputComponent by Kosmos.Fixture { MediaOutputComponent(mediaOutputViewModel) } var Kosmos.mediaOutputAvailabilityCriteria: ComponentAvailabilityCriteria by Kosmos.Fixture { availableCriteria } var Kosmos.mediaOutputAvailabilityCriteria by Kosmos.Fixture { MediaOutputAvailabilityCriteria(applicationContext, testScope.backgroundScope) }