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

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

Use setRingerModeInternal in the AudioRepository instead of setRingerMode to...

Use setRingerModeInternal in the AudioRepository instead of setRingerMode to align the behaviour with the volume sliders in the Settings app.

Flag: EXEMPT bugfix
Test: atest AudioRepositoryTest
Test: manual of foldable. Make sure that adjusting ringe volume while
DnD is ON doesn't change DnD state.
Fixes: 364168680

Change-Id: I18aaa5cd048b4415ab574e9ee8287c783c7b3450
parent 5620e115
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ interface AudioRepository {
     */
    suspend fun setMuted(audioStream: AudioStream, isMuted: Boolean): Boolean

    suspend fun setRingerMode(audioStream: AudioStream, mode: RingerMode)
    suspend fun setRingerModeInternal(audioStream: AudioStream, mode: RingerMode)

    /** Gets audio device category. */
    @AudioDeviceCategory suspend fun getBluetoothAudioDeviceCategory(bluetoothAddress: String): Int
@@ -248,8 +248,8 @@ class AudioRepositoryImpl(
        }
    }

    override suspend fun setRingerMode(audioStream: AudioStream, mode: RingerMode) {
        withContext(backgroundCoroutineContext) { audioManager.ringerMode = mode.value }
    override suspend fun setRingerModeInternal(audioStream: AudioStream, mode: RingerMode) {
        withContext(backgroundCoroutineContext) { audioManager.ringerModeInternal = mode.value }
    }

    @AudioDeviceCategory
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ class AudioVolumeInteractor(
        if (audioStream.value == AudioManager.STREAM_RING) {
            val mode =
                if (isMuted) AudioManager.RINGER_MODE_VIBRATE else AudioManager.RINGER_MODE_NORMAL
            audioRepository.setRingerMode(audioStream, RingerMode(mode))
            audioRepository.setRingerModeInternal(audioStream, RingerMode(mode))
        }
        val mutedChanged = audioRepository.setMuted(audioStream, isMuted)
        if (mutedChanged && !isMuted) {
+21 −2
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ class AudioRepositoryTest {

    private lateinit var underTest: AudioRepository

    private var ringerModeInternal: RingerMode = RingerMode(AudioManager.RINGER_MODE_NORMAL)

    @Before
    fun setup() {
        MockitoAnnotations.initMocks(this)
@@ -82,7 +84,7 @@ class AudioRepositoryTest {
        `when`(audioManager.communicationDevice).thenReturn(communicationDevice)
        `when`(audioManager.getStreamMinVolume(anyInt())).thenReturn(MIN_VOLUME)
        `when`(audioManager.getStreamMaxVolume(anyInt())).thenReturn(MAX_VOLUME)
        `when`(audioManager.ringerModeInternal).thenReturn(AudioManager.RINGER_MODE_NORMAL)
        `when`(audioManager.ringerModeInternal).then { ringerModeInternal.value }
        `when`(audioManager.setStreamVolume(anyInt(), anyInt(), anyInt())).then {
            val streamType = it.arguments[0] as Int
            volumeByStream[it.arguments[0] as Int] = it.arguments[1] as Int
@@ -103,6 +105,10 @@ class AudioRepositoryTest {
        `when`(audioManager.isStreamMute(anyInt())).thenAnswer {
            isMuteByStream.getOrDefault(it.arguments[0] as Int, false)
        }
        `when`(audioManager.setRingerModeInternal(anyInt())).then {
            ringerModeInternal = RingerMode(it.arguments[0] as Int)
            Unit
        }

        underTest =
            AudioRepositoryImpl(
@@ -137,7 +143,7 @@ class AudioRepositoryTest {
            underTest.ringerMode.onEach { modes.add(it) }.launchIn(backgroundScope)
            runCurrent()

            `when`(audioManager.ringerModeInternal).thenReturn(AudioManager.RINGER_MODE_SILENT)
            ringerModeInternal = RingerMode(AudioManager.RINGER_MODE_SILENT)
            triggerEvent(AudioManagerEvent.InternalRingerModeChanged)
            runCurrent()

@@ -149,6 +155,19 @@ class AudioRepositoryTest {
        }
    }

    @Test
    fun changingRingerMode_changesRingerModeInternal() {
        testScope.runTest {
            underTest.setRingerModeInternal(
                AudioStream(AudioManager.STREAM_SYSTEM),
                RingerMode(AudioManager.RINGER_MODE_SILENT),
            )
            runCurrent()

            assertThat(ringerModeInternal).isEqualTo(RingerMode(AudioManager.RINGER_MODE_SILENT))
        }
    }

    @Test
    fun communicationDeviceChanges_repositoryEmits() {
        testScope.runTest {
+2 −6
Original line number Diff line number Diff line
@@ -33,11 +33,7 @@ import kotlinx.coroutines.flow.update

class FakeAudioRepository : AudioRepository {

    private val unMutableStreams =
        setOf(
            AudioManager.STREAM_VOICE_CALL,
            AudioManager.STREAM_ALARM,
        )
    private val unMutableStreams = setOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_ALARM)

    private val mutableMode = MutableStateFlow(AudioManager.MODE_NORMAL)
    override val mode: StateFlow<Int> = mutableMode.asStateFlow()
@@ -126,7 +122,7 @@ class FakeAudioRepository : AudioRepository {
        lastAudibleVolumes[audioStream] = volume
    }

    override suspend fun setRingerMode(audioStream: AudioStream, mode: RingerMode) {
    override suspend fun setRingerModeInternal(audioStream: AudioStream, mode: RingerMode) {
        mutableRingerMode.value = mode
    }