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

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

Merge "Add system stream to isZenMuted" into main

parents 293a31cf d95fdcd1
Loading
Loading
Loading
Loading
+25 −24
Original line number Diff line number Diff line
@@ -48,6 +48,9 @@ class NotificationsSoundPolicyInteractor(
    /** Checks if [notificationPolicy] allows media. */
    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. */
    val isRingerAllowed: Flow<Boolean?> =
        notificationPolicy.map { policy ->
@@ -62,31 +65,29 @@ class NotificationsSoundPolicyInteractor(
            areAlarmsAllowed.filterNotNull(),
            isMediaAllowed.filterNotNull(),
            isRingerAllowed.filterNotNull(),
        ) { zenMode, areAlarmsAllowed, isMediaAllowed, isRingerAllowed ->
            if (zenMode.zenMode == Settings.Global.ZEN_MODE_NO_INTERRUPTIONS) {
            isSystemAllowed.filterNotNull(),
        ) { 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
            }

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

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

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

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