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

Commit ef1e87a5 authored by Norman Bintang's avatar Norman Bintang
Browse files

Hide Media Output from Volume Panel on Desktop

Desktop is using Headless System User Mode (HSUM). And MediaRouter2 is
not compatible with HSUM, causing Media Output to be broken. We need to
hide this component, and let users select input/output devices from the
settings page.

Bug: b/390286295, b/372868909
Test: mp sysuititan
Flag: EXEMPT desktop only changes
Change-Id: Ic326362e25747fb214877ca99cf7d271e7b0ad24
parent d42f8e3d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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
@@ -39,6 +39,6 @@ interface MediaOutputModule {
    @IntoMap
    @StringKey(VolumePanelComponents.MEDIA_OUTPUT)
    fun bindComponentAvailabilityCriteria(
        criteria: AlwaysAvailableCriteria
        criteria: MediaOutputAvailabilityCriteria
    ): ComponentAvailabilityCriteria
}
+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()
        }
}
+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
}
+7 −4
Original line number Diff line number Diff line
@@ -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)
    }