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

Commit f8ddb8f2 authored by Anton Potapov's avatar Anton Potapov Committed by Android Build Coastguard Worker
Browse files

Take isAffectedByMute into account when trying to mute a stream

Flag: NONE bugfix
Bug: 349592304
Test: atest AudioVolumeInteractorTest
Test: maual on the phone
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d0f76880d65ef821d875101b28365bffb7c604d2)
Merged-In: I07cc413be0ea0d86093d5d640b2ed806f48ceb41
Change-Id: I07cc413be0ea0d86093d5d640b2ed806f48ceb41
parent caef0ac8
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
@@ -36,6 +36,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

@@ -49,6 +50,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) {
@@ -194,10 +209,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) {