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

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

Merge "Disable sliders for zen muted streams" into main

parents 1e366780 bce56563
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.settingslib.volume.shared.model.RingerMode
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
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 */
@@ -56,9 +55,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
@@ -1536,8 +1536,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
@@ -67,6 +67,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