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

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

Add system stream to isZenMuted

This CL addresses this
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/26256302/comment/c0b411c7_d034125a/
comment.

Flag: aconfig new_volume_panel TEAMFOOD
Test: atest NotificationsSoundPolicyInteractorTest
Fixes: 326440214
Change-Id: Ia64bc543601175675ded9b316d51ab50258b4296
parent 80b15219
Loading
Loading
Loading
Loading
+25 −24
Original line number Original line Diff line number Diff line
@@ -48,6 +48,9 @@ class NotificationsSoundPolicyInteractor(
    /** Checks if [notificationPolicy] allows media. */
    /** Checks if [notificationPolicy] allows media. */
    val isMediaAllowed: Flow<Boolean?> = notificationPolicy.map { it?.allowMedia() }
    val isMediaAllowed: Flow<Boolean?> = notificationPolicy.map { it?.allowMedia() }


    /** Checks if [notificationPolicy] allows system sounds. */
    val isSystemAllowed: Flow<Boolean?> = notificationPolicy.map { it?.allowSystem() }

    /** Checks if [notificationPolicy] allows ringer. */
    /** Checks if [notificationPolicy] allows ringer. */
    val isRingerAllowed: Flow<Boolean?> =
    val isRingerAllowed: Flow<Boolean?> =
        notificationPolicy.map { policy ->
        notificationPolicy.map { policy ->
@@ -62,31 +65,29 @@ class NotificationsSoundPolicyInteractor(
            areAlarmsAllowed.filterNotNull(),
            areAlarmsAllowed.filterNotNull(),
            isMediaAllowed.filterNotNull(),
            isMediaAllowed.filterNotNull(),
            isRingerAllowed.filterNotNull(),
            isRingerAllowed.filterNotNull(),
        ) { zenMode, areAlarmsAllowed, isMediaAllowed, isRingerAllowed ->
            isSystemAllowed.filterNotNull(),
            if (zenMode.zenMode == Settings.Global.ZEN_MODE_NO_INTERRUPTIONS) {
        ) { zenMode, areAlarmsAllowed, isMediaAllowed, isRingerAllowed, isSystemAllowed ->
            when (zenMode.zenMode) {
                // Everything is muted
                Settings.Global.ZEN_MODE_NO_INTERRUPTIONS -> return@combine true
                Settings.Global.ZEN_MODE_ALARMS ->
                    return@combine stream.value == AudioManager.STREAM_RING ||
                        stream.value == AudioManager.STREAM_NOTIFICATION ||
                        stream.value == AudioManager.STREAM_SYSTEM
                Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS -> {
                    when {
                        stream.value == AudioManager.STREAM_ALARM && !areAlarmsAllowed ->
                            return@combine true
                            return@combine true
            }
                        stream.value == AudioManager.STREAM_MUSIC && !isMediaAllowed ->

            val isNotificationOrRing =
                stream.value == AudioManager.STREAM_RING ||
                    stream.value == AudioManager.STREAM_NOTIFICATION
            if (isNotificationOrRing && zenMode.zenMode == Settings.Global.ZEN_MODE_ALARMS) {
                            return@combine true
                            return@combine true
            }
                        stream.value == AudioManager.STREAM_SYSTEM && !isSystemAllowed ->
            if (zenMode.zenMode != Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
                return@combine false
            }

            if (stream.value == AudioManager.STREAM_ALARM && !areAlarmsAllowed) {
                            return@combine true
                            return@combine true
            }
                        (stream.value == AudioManager.STREAM_RING ||
            if (stream.value == AudioManager.STREAM_MUSIC && !isMediaAllowed) {
                            stream.value == AudioManager.STREAM_NOTIFICATION) && !isRingerAllowed ->
                            return@combine true
                            return@combine true
                    }
                    }
            if (isNotificationOrRing && !isRingerAllowed) {
                return@combine true
                }
                }

            }
            return@combine false
            return@combine false
        }
        }
    }
    }
+6 −2
Original line number Original line Diff line number Diff line
@@ -196,10 +196,14 @@ class NotificationsSoundPolicyInteractorTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun zenModeAlarms_ringAndNotifications_muted() {
    fun zenModeAlarms_ringedStreams_muted() {
        with(kosmos) {
        with(kosmos) {
            val expectedToBeMuted =
            val expectedToBeMuted =
                setOf(AudioManager.STREAM_RING, AudioManager.STREAM_NOTIFICATION)
                setOf(
                    AudioManager.STREAM_RING,
                    AudioManager.STREAM_NOTIFICATION,
                    AudioManager.STREAM_SYSTEM,
                )
            testScope.runTest {
            testScope.runTest {
                notificationsSoundPolicyRepository.updateNotificationPolicy()
                notificationsSoundPolicyRepository.updateNotificationPolicy()
                notificationsSoundPolicyRepository.updateZenMode(ZenMode(Global.ZEN_MODE_ALARMS))
                notificationsSoundPolicyRepository.updateZenMode(ZenMode(Global.ZEN_MODE_ALARMS))