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

Commit ee9db8e9 authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge "Take isAffectedByMute into account when trying to mute a stream" into main

parents b40961f4 d0f76880
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -61,6 +61,10 @@ class AudioVolumeInteractor(
    }

    suspend fun setMuted(audioStream: AudioStream, isMuted: Boolean) {
        val streamModel = getAudioStream(audioStream).first()
        if (!streamModel.isAffectedByMute) {
            return
        }
        if (audioStream.value == AudioManager.STREAM_RING) {
            val mode =
                if (isMuted) AudioManager.RINGER_MODE_VIBRATE else AudioManager.RINGER_MODE_NORMAL
+20 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@@ -48,6 +49,20 @@ class AudioVolumeInteractorTest : SysuiTestCase() {
    private val underTest: AudioVolumeInteractor =
        with(kosmos) { AudioVolumeInteractor(audioRepository, notificationsSoundPolicyInteractor) }

    @Before
    fun setUp() =
        with(kosmos) {
            audioRepository.setAudioStreamModel(
                audioRepository.getAudioStream(audioStream).value.copy(isAffectedByMute = true)
            )
            audioRepository.setAudioStreamModel(
                audioRepository
                    .getAudioStream(AudioStream(AudioManager.STREAM_RING))
                    .value
                    .copy(isAffectedByMute = true)
            )
        }

    @Test
    fun setMuted_mutesStream() {
        with(kosmos) {
@@ -189,10 +204,14 @@ class AudioVolumeInteractorTest : SysuiTestCase() {
            testScope.runTest {
                val audioStreamModel by collectLastValue(underTest.getAudioStream(audioStream))
                audioRepository.setAudioStreamModel(
                    audioStreamModel!!.copy(isAffectedByMute = false)
                    audioStreamModel!!.copy(isAffectedByMute = false, isMuted = false)
                )

                underTest.setMuted(audioStream, true)
                runCurrent()

                assertThat(audioStreamModel!!.isAffectedByMute).isFalse()
                assertThat(audioStreamModel!!.isMuted).isFalse()
            }
        }
    }
+1 −2
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import com.android.settingslib.volume.data.repository.AudioRepository
import com.android.settingslib.volume.shared.model.AudioStream
import com.android.settingslib.volume.shared.model.AudioStreamModel
import com.android.settingslib.volume.shared.model.RingerMode
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
@@ -61,7 +60,7 @@ class FakeAudioRepository : AudioRepository {
            )
        }

    override fun getAudioStream(audioStream: AudioStream): Flow<AudioStreamModel> =
    override fun getAudioStream(audioStream: AudioStream): StateFlow<AudioStreamModel> =
        getAudioStreamModelState(audioStream).asStateFlow()

    override suspend fun setVolume(audioStream: AudioStream, volume: Int) {