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

Commit d537198f authored by Anton Potapov's avatar Anton Potapov
Browse files

Fix media output component appearance

The new media output component is always visible and displays the
current media output (either phone or a connected device)

Fixed icon colors to match MaterialTheme ones

Flag: aconfig new_volume_panel DISABLED
Test: atest MediaOutputAvailabilityCriteriaTest
Fixes: 325669613
Change-Id: Ia3039084a5b2562b9d3ae96777513882755c1bad
parent 34457980
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ constructor(
            ) {
                Icon(
                    icon = it.icon,
                    tint = it.iconColor.toColor(),
                    modifier = Modifier.padding(12.dp).fillMaxSize(),
                )
            }
+4 −36
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.systemui.volume.panel.component.mediaoutput.domain

import android.media.AudioManager
import android.media.session.MediaSession
import android.media.session.PlaybackState
import android.testing.TestableLooper.RunWithLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -26,14 +24,8 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.android.systemui.volume.audioModeInteractor
import com.android.systemui.volume.audioRepository
import com.android.systemui.volume.localMediaRepository
import com.android.systemui.volume.mediaController
import com.android.systemui.volume.mediaControllerRepository
import com.android.systemui.volume.mediaOutputInteractor
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
@@ -54,23 +46,14 @@ class MediaOutputAvailabilityCriteriaTest : SysuiTestCase() {

    @Before
    fun setup() {
        with(kosmos) {
            whenever(mediaController.packageName).thenReturn("test.pkg")
            whenever(mediaController.sessionToken).thenReturn(MediaSession.Token(0, mock {}))
            whenever(mediaController.playbackState).thenReturn(PlaybackState.Builder().build())

            mediaControllerRepository.setActiveLocalMediaController(mediaController)

            underTest = MediaOutputAvailabilityCriteria(mediaOutputInteractor, audioModeInteractor)
        }
        underTest = MediaOutputAvailabilityCriteria(kosmos.audioModeInteractor)
    }

    @Test
    fun notInCallAndHasDevices_isAvailable_true() {
    fun notInCall_isAvailable_true() {
        with(kosmos) {
            testScope.runTest {
                audioRepository.setMode(AudioManager.MODE_NORMAL)
                localMediaRepository.updateMediaDevices(listOf(mock {}))

                val isAvailable by collectLastValue(underTest.isAvailable())
                runCurrent()
@@ -79,27 +62,12 @@ class MediaOutputAvailabilityCriteriaTest : SysuiTestCase() {
            }
        }
    }
    @Test
    fun inCallAndHasDevices_isAvailable_false() {
        with(kosmos) {
            testScope.runTest {
                audioRepository.setMode(AudioManager.MODE_IN_CALL)
                localMediaRepository.updateMediaDevices(listOf(mock {}))

                val isAvailable by collectLastValue(underTest.isAvailable())
                runCurrent()

                assertThat(isAvailable).isFalse()
            }
        }
    }

    @Test
    fun notInCallAndHasDevices_isAvailable_false() {
    fun inCall_isAvailable_false() {
        with(kosmos) {
            testScope.runTest {
                audioRepository.setMode(AudioManager.MODE_NORMAL)
                localMediaRepository.updateMediaDevices(emptyList())
                audioRepository.setMode(AudioManager.MODE_IN_CALL)

                val isAvailable by collectLastValue(underTest.isAvailable())
                runCurrent()
+5 −2
Original line number Diff line number Diff line
@@ -953,8 +953,11 @@
        <item name="wallpaperTextColor">@*android:color/primary_text_material_dark</item>
    </style>

    <style name="Theme.VolumePanelActivity"
        parent="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen">
    <style name="Theme.VolumePanelActivity" parent="@android:style/Theme.DeviceDefault.DayNight">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:backgroundDimEnabled">true</item>
+2 −10
Original line number Diff line number Diff line
@@ -17,27 +17,19 @@
package com.android.systemui.volume.panel.component.mediaoutput.domain

import com.android.settingslib.volume.domain.interactor.AudioModeInteractor
import com.android.systemui.volume.panel.component.mediaoutput.domain.interactor.MediaOutputInteractor
import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope
import com.android.systemui.volume.panel.domain.ComponentAvailabilityCriteria
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map

/** Determines if the Media Output Volume Panel component is available. */
@VolumePanelScope
class MediaOutputAvailabilityCriteria
@Inject
constructor(
    private val mediaOutputInteractor: MediaOutputInteractor,
    private val audioModeInteractor: AudioModeInteractor,
) : ComponentAvailabilityCriteria {

    override fun isAvailable(): Flow<Boolean> {
        return combine(mediaOutputInteractor.mediaDevices, audioModeInteractor.isOngoingCall) {
            devices,
            isOngoingCall ->
            !isOngoingCall && devices.isNotEmpty()
        }
    }
    override fun isAvailable(): Flow<Boolean> = audioModeInteractor.isOngoingCall.map { !it }
}
+0 −4
Original line number Diff line number Diff line
@@ -95,10 +95,6 @@ constructor(
    val currentConnectedDevice: Flow<MediaDevice?> =
        localMediaRepository.flatMapLatest { it.currentConnectedDevice }

    /** A list of available [MediaDevice]s. */
    val mediaDevices: Flow<Collection<MediaDevice>> =
        localMediaRepository.flatMapLatest { it.mediaDevices }

    private suspend fun getApplicationLabel(packageName: String): CharSequence? {
        return try {
            withContext(backgroundCoroutineContext) {
Loading