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

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

Disable sliders for zen muted streams

Flag: aconfig new_volume_panel TEAMFOOD
Test: manual on the phone
Test: atest AudioVolumeInteractorTest
Fixes: 327596875
Change-Id: I601419074dddd8fcdfc9ca225d53321907c36d1f
parent 80b15219
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ 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.combine
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map

/** Provides audio stream state and an ability to change it */
@@ -52,9 +51,14 @@ class AudioVolumeInteractor(
    /** Checks if the volume can be changed via the UI. */
    fun canChangeVolume(audioStream: AudioStream): Flow<Boolean> {
        return if (audioStream.value == AudioManager.STREAM_NOTIFICATION) {
            getAudioStream(AudioStream(AudioManager.STREAM_RING)).map { !it.isMuted }
            combine(
                notificationsSoundPolicyInteractor.isZenMuted(audioStream),
                getAudioStream(AudioStream(AudioManager.STREAM_RING)).map { it.isMuted },
            ) { isZenMuted, isRingMuted ->
                !isZenMuted && !isRingMuted
            }
        } else {
            flowOf(true)
            notificationsSoundPolicyInteractor.isZenMuted(audioStream).map { !it }
        }
    }

+22 −0
Original line number Diff line number Diff line
@@ -112,6 +112,28 @@ class AudioVolumeInteractorTest : SysuiTestCase() {
        }
    }

    @Test
    fun zenMuted_cantChange() {
        with(kosmos) {
            testScope.runTest {
                notificationsSoundPolicyRepository.updateNotificationPolicy()
                notificationsSoundPolicyRepository.updateZenMode(
                    ZenMode(Settings.Global.ZEN_MODE_NO_INTERRUPTIONS)
                )

                val canChangeVolume by
                    collectLastValue(
                        underTest.canChangeVolume(AudioStream(AudioManager.STREAM_NOTIFICATION))
                    )

                underTest.setMuted(AudioStream(AudioManager.STREAM_RING), true)
                runCurrent()

                assertThat(canChangeVolume).isFalse()
            }
        }
    }

    @Test
    fun streamIsMuted_getStream_volumeZero() {
        with(kosmos) {
+5 −1
Original line number Diff line number Diff line
@@ -1521,8 +1521,12 @@

    <!-- Media device casting volume slider label [CHAR_LIMIT=20] -->
    <string name="media_device_cast">Cast</string>
    <!-- A message shown when the notification volume changing is disabled because of the muted ring stream [CHAR_LIMIT=40]-->
    <!-- A message shown when the notification volume changing is disabled because of the muted ring stream [CHAR_LIMIT=50]-->
    <string name="stream_notification_unavailable">Unavailable because ring is muted</string>
    <!-- A message shown when the alarm volume changing is disabled because of the don't disturb mode [CHAR_LIMIT=50]-->
    <string name="stream_alarm_unavailable">Unavailable because Do Not Disturb is on</string>
    <!-- A message shown when the media volume changing is disabled because of the don't disturb mode [CHAR_LIMIT=50]-->
    <string name="stream_media_unavailable">Unavailable because Do Not Disturb is on</string>

    <!-- Shown in the header of quick settings to indicate to the user that their phone ringer is on vibrate. [CHAR_LIMIT=NONE] -->
    <!-- Shown in the header of quick settings to indicate to the user that their phone ringer is on silent (muted). [CHAR_LIMIT=NONE] -->
+2 −0
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ constructor(
        mapOf(
            AudioStream(AudioManager.STREAM_NOTIFICATION) to
                R.string.stream_notification_unavailable,
            AudioStream(AudioManager.STREAM_ALARM) to R.string.stream_alarm_unavailable,
            AudioStream(AudioManager.STREAM_MUSIC) to R.string.stream_media_unavailable,
        )

    private var value = 0f