summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-10-10 08:54:46 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-10-10 08:54:46 +0000
commit787bc2c69db1c25ccb15ea6a585c33d74fdb4f66 (patch)
tree931a12cb4ee4a3f9cbe5b550055fceecbf6c5a8c
parentde05b66161524bbca2ca91daeee1683329623c51 (diff)
parent5a70f5a8f967a0fbeb1165cbcd321e2a6cbc1b34 (diff)
Merge "Show the name of the mode blocking audio streams in volume panel" into main
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/notification/data/repository/FakeZenModeRepository.kt4
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractorTest.kt117
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModelTest.kt174
-rw-r--r--packages/SystemUI/res/values/strings.xml5
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractor.kt22
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt115
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModelKosmos.kt2
7 files changed, 414 insertions, 25 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/notification/data/repository/FakeZenModeRepository.kt b/packages/SettingsLib/src/com/android/settingslib/notification/data/repository/FakeZenModeRepository.kt
index 43d79466d6ca..23be7baa6496 100644
--- a/packages/SettingsLib/src/com/android/settingslib/notification/data/repository/FakeZenModeRepository.kt
+++ b/packages/SettingsLib/src/com/android/settingslib/notification/data/repository/FakeZenModeRepository.kt
@@ -78,6 +78,10 @@ class FakeZenModeRepository : ZenModeRepository {
mutableModesFlow.value = (mutableModesFlow.value.filter { it.id != modeId }) + mode
}
+ fun clearModes() {
+ mutableModesFlow.value = listOf()
+ }
+
fun getMode(id: String): ZenMode? {
return mutableModesFlow.value.find { it.id == id }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractorTest.kt
index c5ccf9e6a1d1..74d4178891b9 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractorTest.kt
@@ -18,6 +18,8 @@ package com.android.systemui.statusbar.policy.domain.interactor
import android.app.AutomaticZenRule
import android.app.Flags
+import android.app.NotificationManager.INTERRUPTION_FILTER_NONE
+import android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY
import android.app.NotificationManager.Policy
import android.platform.test.annotations.EnableFlags
import android.provider.Settings
@@ -25,6 +27,7 @@ import android.provider.Settings.Secure.ZEN_DURATION
import android.provider.Settings.Secure.ZEN_DURATION_FOREVER
import android.provider.Settings.Secure.ZEN_DURATION_PROMPT
import android.service.notification.SystemZenRules
+import android.service.notification.ZenPolicy
import android.service.notification.ZenPolicy.VISUAL_EFFECT_NOTIFICATION_LIST
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -383,6 +386,120 @@ class ZenModeInteractorTest : SysuiTestCase() {
}
@Test
+ @EnableFlags(Flags.FLAG_MODES_UI)
+ fun activeModesBlockingEverything_hasModesWithFilterNone() =
+ testScope.runTest {
+ val blockingEverything by collectLastValue(underTest.activeModesBlockingEverything)
+
+ zenModeRepository.addModes(
+ listOf(
+ TestModeBuilder()
+ .setName("Filter=None, Not active")
+ .setInterruptionFilter(INTERRUPTION_FILTER_NONE)
+ .setActive(false)
+ .build(),
+ TestModeBuilder()
+ .setName("Filter=Priority, Active")
+ .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
+ .setActive(true)
+ .build(),
+ TestModeBuilder()
+ .setName("Filter=None, Active")
+ .setInterruptionFilter(INTERRUPTION_FILTER_NONE)
+ .setActive(true)
+ .build(),
+ TestModeBuilder()
+ .setName("Filter=None, Active Too")
+ .setInterruptionFilter(INTERRUPTION_FILTER_NONE)
+ .setActive(true)
+ .build(),
+ )
+ )
+ runCurrent()
+
+ assertThat(blockingEverything!!.mainMode!!.name).isEqualTo("Filter=None, Active")
+ assertThat(blockingEverything!!.modeNames)
+ .containsExactly("Filter=None, Active", "Filter=None, Active Too")
+ .inOrder()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_UI)
+ fun activeModesBlockingMedia_hasModesWithPolicyBlockingMedia() =
+ testScope.runTest {
+ val blockingMedia by collectLastValue(underTest.activeModesBlockingMedia)
+
+ zenModeRepository.addModes(
+ listOf(
+ TestModeBuilder()
+ .setName("Blocks media, Not active")
+ .setZenPolicy(ZenPolicy.Builder().allowMedia(false).build())
+ .setActive(false)
+ .build(),
+ TestModeBuilder()
+ .setName("Allows media, Active")
+ .setZenPolicy(ZenPolicy.Builder().allowMedia(true).build())
+ .setActive(true)
+ .build(),
+ TestModeBuilder()
+ .setName("Blocks media, Active")
+ .setZenPolicy(ZenPolicy.Builder().allowMedia(false).build())
+ .setActive(true)
+ .build(),
+ TestModeBuilder()
+ .setName("Blocks media, Active Too")
+ .setZenPolicy(ZenPolicy.Builder().allowMedia(false).build())
+ .setActive(true)
+ .build(),
+ )
+ )
+ runCurrent()
+
+ assertThat(blockingMedia!!.mainMode!!.name).isEqualTo("Blocks media, Active")
+ assertThat(blockingMedia!!.modeNames)
+ .containsExactly("Blocks media, Active", "Blocks media, Active Too")
+ .inOrder()
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_UI)
+ fun activeModesBlockingAlarms_hasModesWithPolicyBlockingAlarms() =
+ testScope.runTest {
+ val blockingAlarms by collectLastValue(underTest.activeModesBlockingAlarms)
+
+ zenModeRepository.addModes(
+ listOf(
+ TestModeBuilder()
+ .setName("Blocks alarms, Not active")
+ .setZenPolicy(ZenPolicy.Builder().allowAlarms(false).build())
+ .setActive(false)
+ .build(),
+ TestModeBuilder()
+ .setName("Allows alarms, Active")
+ .setZenPolicy(ZenPolicy.Builder().allowAlarms(true).build())
+ .setActive(true)
+ .build(),
+ TestModeBuilder()
+ .setName("Blocks alarms, Active")
+ .setZenPolicy(ZenPolicy.Builder().allowAlarms(false).build())
+ .setActive(true)
+ .build(),
+ TestModeBuilder()
+ .setName("Blocks alarms, Active Too")
+ .setZenPolicy(ZenPolicy.Builder().allowAlarms(false).build())
+ .setActive(true)
+ .build(),
+ )
+ )
+ runCurrent()
+
+ assertThat(blockingAlarms!!.mainMode!!.name).isEqualTo("Blocks alarms, Active")
+ assertThat(blockingAlarms!!.modeNames)
+ .containsExactly("Blocks alarms, Active", "Blocks alarms, Active Too")
+ .inOrder()
+ }
+
+ @Test
@EnableFlags(ModesEmptyShadeFix.FLAG_NAME, Flags.FLAG_MODES_UI, Flags.FLAG_MODES_API)
fun modesHidingNotifications_onlyIncludesModesWithNotifListSuppression() =
testScope.runTest {
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModelTest.kt
new file mode 100644
index 000000000000..f80b36a10dc2
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModelTest.kt
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.volume.panel.component.volume.slider.ui.viewmodel
+
+import android.app.Flags
+import android.app.NotificationManager.INTERRUPTION_FILTER_NONE
+import android.media.AudioManager
+import android.platform.test.annotations.EnableFlags
+import android.service.notification.ZenPolicy
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.internal.logging.uiEventLogger
+import com.android.settingslib.notification.modes.TestModeBuilder
+import com.android.settingslib.volume.shared.model.AudioStream
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.statusbar.policy.data.repository.fakeZenModeRepository
+import com.android.systemui.statusbar.policy.domain.interactor.zenModeInteractor
+import com.android.systemui.testKosmos
+import com.android.systemui.volume.domain.interactor.audioVolumeInteractor
+import com.android.systemui.volume.shared.volumePanelLogger
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.runTest
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@OptIn(ExperimentalCoroutinesApi::class)
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class AudioStreamSliderViewModelTest : SysuiTestCase() {
+
+ private val kosmos = testKosmos()
+ private val testScope = kosmos.testScope
+ private val zenModeRepository = kosmos.fakeZenModeRepository
+
+ private lateinit var mediaStream: AudioStreamSliderViewModel
+ private lateinit var alarmsStream: AudioStreamSliderViewModel
+ private lateinit var notificationStream: AudioStreamSliderViewModel
+ private lateinit var otherStream: AudioStreamSliderViewModel
+
+ @Before
+ fun setUp() {
+ mediaStream = audioStreamSliderViewModel(AudioManager.STREAM_MUSIC)
+ alarmsStream = audioStreamSliderViewModel(AudioManager.STREAM_ALARM)
+ notificationStream = audioStreamSliderViewModel(AudioManager.STREAM_NOTIFICATION)
+ otherStream = audioStreamSliderViewModel(AudioManager.STREAM_VOICE_CALL)
+ }
+
+ private fun audioStreamSliderViewModel(stream: Int): AudioStreamSliderViewModel {
+ return AudioStreamSliderViewModel(
+ AudioStreamSliderViewModel.FactoryAudioStreamWrapper(AudioStream(stream)),
+ testScope.backgroundScope,
+ context,
+ kosmos.audioVolumeInteractor,
+ kosmos.zenModeInteractor,
+ kosmos.uiEventLogger,
+ kosmos.volumePanelLogger,
+ )
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_UI, Flags.FLAG_MODES_UI_ICONS)
+ fun slider_media_hasDisabledByModesText() =
+ testScope.runTest {
+ val mediaSlider by collectLastValue(mediaStream.slider)
+
+ zenModeRepository.addMode(
+ TestModeBuilder()
+ .setName("Media is ok")
+ .setZenPolicy(ZenPolicy.Builder().allowAllSounds().build())
+ .setActive(true)
+ .build()
+ )
+ zenModeRepository.addMode(
+ TestModeBuilder()
+ .setName("No media plz")
+ .setZenPolicy(ZenPolicy.Builder().allowMedia(false).build())
+ .setActive(true)
+ .build()
+ )
+ runCurrent()
+
+ assertThat(mediaSlider!!.disabledMessage)
+ .isEqualTo("Unavailable because No media plz is on")
+
+ zenModeRepository.clearModes()
+ runCurrent()
+
+ assertThat(mediaSlider!!.disabledMessage).isEqualTo("Unavailable")
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_UI, Flags.FLAG_MODES_UI_ICONS)
+ fun slider_alarms_hasDisabledByModesText() =
+ testScope.runTest {
+ val alarmsSlider by collectLastValue(alarmsStream.slider)
+
+ zenModeRepository.addMode(
+ TestModeBuilder()
+ .setName("Alarms are ok")
+ .setZenPolicy(ZenPolicy.Builder().allowAllSounds().build())
+ .setActive(true)
+ .build()
+ )
+ zenModeRepository.addMode(
+ TestModeBuilder()
+ .setName("Zzzzz")
+ .setZenPolicy(ZenPolicy.Builder().allowAlarms(false).build())
+ .setActive(true)
+ .build()
+ )
+ runCurrent()
+
+ assertThat(alarmsSlider!!.disabledMessage).isEqualTo("Unavailable because Zzzzz is on")
+
+ zenModeRepository.clearModes()
+ runCurrent()
+
+ assertThat(alarmsSlider!!.disabledMessage).isEqualTo("Unavailable")
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_UI, Flags.FLAG_MODES_UI_ICONS)
+ fun slider_other_hasDisabledByModesText() =
+ testScope.runTest {
+ val otherSlider by collectLastValue(otherStream.slider)
+
+ zenModeRepository.addMode(
+ TestModeBuilder()
+ .setName("Everything blocked")
+ .setInterruptionFilter(INTERRUPTION_FILTER_NONE)
+ .setActive(true)
+ .build()
+ )
+ runCurrent()
+
+ assertThat(otherSlider!!.disabledMessage)
+ .isEqualTo("Unavailable because Everything blocked is on")
+
+ zenModeRepository.clearModes()
+ runCurrent()
+
+ assertThat(otherSlider!!.disabledMessage).isEqualTo("Unavailable")
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_UI, Flags.FLAG_MODES_UI_ICONS)
+ fun slider_notification_hasSpecialDisabledText() =
+ testScope.runTest {
+ val notificationSlider by collectLastValue(notificationStream.slider)
+ runCurrent()
+
+ assertThat(notificationSlider!!.disabledMessage)
+ .isEqualTo("Unavailable because ring is muted")
+ }
+}
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 96a85d78e2b5..72250610d768 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1746,6 +1746,11 @@
<!-- 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>
+ <!-- A message shown when a specific volume (e.g. Alarms, Media, etc) is disabled because an active mode is muting that audio stream altogether [CHAR_LIMIT=50]-->
+ <string name="stream_unavailable_by_modes">Unavailable because <xliff:g id="mode" example="Bedtime">%s</xliff:g> is on</string>
+ <!-- A message shown when a specific volume (e.g. Alarms, Media, etc) is disabled but we don't know which mode (or anything else) is responsible. [CHAR_LIMIT=50]-->
+ <string name="stream_unavailable_by_unknown">Unavailable</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] -->
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractor.kt
index daba1099c49d..9839f9d76537 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/domain/interactor/ZenModeInteractor.kt
@@ -16,10 +16,12 @@
package com.android.systemui.statusbar.policy.domain.interactor
+import android.app.NotificationManager.INTERRUPTION_FILTER_NONE
import android.content.Context
import android.provider.Settings
import android.provider.Settings.Secure.ZEN_DURATION_FOREVER
import android.provider.Settings.Secure.ZEN_DURATION_PROMPT
+import android.service.notification.ZenPolicy.STATE_DISALLOW
import android.service.notification.ZenPolicy.VISUAL_EFFECT_NOTIFICATION_LIST
import android.util.Log
import androidx.concurrent.futures.await
@@ -115,6 +117,26 @@ constructor(
.flowOn(bgDispatcher)
.distinctUntilChanged()
+ val activeModesBlockingEverything: Flow<ActiveZenModes> = getFilteredActiveModesFlow { mode ->
+ mode.interruptionFilter == INTERRUPTION_FILTER_NONE
+ }
+
+ val activeModesBlockingMedia: Flow<ActiveZenModes> = getFilteredActiveModesFlow { mode ->
+ mode.policy.priorityCategoryMedia == STATE_DISALLOW
+ }
+
+ val activeModesBlockingAlarms: Flow<ActiveZenModes> = getFilteredActiveModesFlow { mode ->
+ mode.policy.priorityCategoryAlarms == STATE_DISALLOW
+ }
+
+ private fun getFilteredActiveModesFlow(predicate: (ZenMode) -> Boolean): Flow<ActiveZenModes> {
+ return modes
+ .map { modes -> modes.filter { mode -> predicate(mode) } }
+ .map { modes -> buildActiveZenModes(modes) }
+ .flowOn(bgDispatcher)
+ .distinctUntilChanged()
+ }
+
suspend fun getActiveModes() = buildActiveZenModes(zenModeRepository.getModes())
private suspend fun buildActiveZenModes(modes: List<ZenMode>): ActiveZenModes {
diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt
index ffb1f11c4970..2aa1ac99a400 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt
@@ -18,6 +18,9 @@ package com.android.systemui.volume.panel.component.volume.slider.ui.viewmodel
import android.content.Context
import android.media.AudioManager
+import android.media.AudioManager.STREAM_ALARM
+import android.media.AudioManager.STREAM_MUSIC
+import android.media.AudioManager.STREAM_NOTIFICATION
import android.util.Log
import com.android.internal.logging.UiEventLogger
import com.android.settingslib.volume.domain.interactor.AudioVolumeInteractor
@@ -25,7 +28,11 @@ import com.android.settingslib.volume.shared.model.AudioStream
import com.android.settingslib.volume.shared.model.AudioStreamModel
import com.android.settingslib.volume.shared.model.RingerMode
import com.android.systemui.common.shared.model.Icon
+import com.android.systemui.modes.shared.ModesUiIcons
import com.android.systemui.res.R
+import com.android.systemui.statusbar.policy.domain.interactor.ZenModeInteractor
+import com.android.systemui.statusbar.policy.domain.model.ActiveZenModes
+import com.android.systemui.util.kotlin.combine
import com.android.systemui.volume.panel.shared.VolumePanelLogger
import com.android.systemui.volume.panel.ui.VolumePanelUiEvent
import dagger.assisted.Assisted
@@ -51,16 +58,14 @@ constructor(
@Assisted private val coroutineScope: CoroutineScope,
private val context: Context,
private val audioVolumeInteractor: AudioVolumeInteractor,
+ private val zenModeInteractor: ZenModeInteractor,
private val uiEventLogger: UiEventLogger,
private val volumePanelLogger: VolumePanelLogger,
) : SliderViewModel {
private val volumeChanges = MutableStateFlow<Int?>(null)
private val streamsAffectedByRing =
- setOf(
- AudioManager.STREAM_RING,
- AudioManager.STREAM_NOTIFICATION,
- )
+ setOf(AudioManager.STREAM_RING, AudioManager.STREAM_NOTIFICATION)
private val audioStream = audioStreamWrapper.audioStream
private val iconsByStream =
mapOf(
@@ -78,11 +83,6 @@ constructor(
AudioStream(AudioManager.STREAM_NOTIFICATION) to R.string.stream_notification,
AudioStream(AudioManager.STREAM_ALARM) to R.string.stream_alarm,
)
- private val disabledTextByStream =
- mapOf(
- AudioStream(AudioManager.STREAM_NOTIFICATION) to
- R.string.stream_notification_unavailable,
- )
private val uiEventByStream =
mapOf(
AudioStream(AudioManager.STREAM_MUSIC) to
@@ -98,15 +98,48 @@ constructor(
)
override val slider: StateFlow<SliderState> =
- combine(
- audioVolumeInteractor.getAudioStream(audioStream),
- audioVolumeInteractor.canChangeVolume(audioStream),
- audioVolumeInteractor.ringerMode,
- ) { model, isEnabled, ringerMode ->
- volumePanelLogger.onVolumeUpdateReceived(audioStream, model.volume)
- model.toState(isEnabled, ringerMode)
- }
- .stateIn(coroutineScope, SharingStarted.Eagerly, SliderState.Empty)
+ if (ModesUiIcons.isEnabled) {
+ combine(
+ audioVolumeInteractor.getAudioStream(audioStream),
+ audioVolumeInteractor.canChangeVolume(audioStream),
+ audioVolumeInteractor.ringerMode,
+ zenModeInteractor.activeModesBlockingEverything,
+ zenModeInteractor.activeModesBlockingAlarms,
+ zenModeInteractor.activeModesBlockingMedia,
+ ) {
+ model,
+ isEnabled,
+ ringerMode,
+ modesBlockingEverything,
+ modesBlockingAlarms,
+ modesBlockingMedia ->
+ volumePanelLogger.onVolumeUpdateReceived(audioStream, model.volume)
+ model.toState(
+ isEnabled,
+ ringerMode,
+ getStreamDisabledMessage(
+ modesBlockingEverything,
+ modesBlockingAlarms,
+ modesBlockingMedia,
+ ),
+ )
+ }
+ .stateIn(coroutineScope, SharingStarted.Eagerly, SliderState.Empty)
+ } else {
+ combine(
+ audioVolumeInteractor.getAudioStream(audioStream),
+ audioVolumeInteractor.canChangeVolume(audioStream),
+ audioVolumeInteractor.ringerMode,
+ ) { model, isEnabled, ringerMode ->
+ volumePanelLogger.onVolumeUpdateReceived(audioStream, model.volume)
+ model.toState(
+ isEnabled,
+ ringerMode,
+ getStreamDisabledMessageWithoutModes(audioStream),
+ )
+ }
+ .stateIn(coroutineScope, SharingStarted.Eagerly, SliderState.Empty)
+ }
init {
volumeChanges
@@ -139,6 +172,7 @@ constructor(
private fun AudioStreamModel.toState(
isEnabled: Boolean,
ringerMode: RingerMode,
+ disabledMessage: String?,
): State {
val label =
labelsByStream[audioStream]?.let(context::getString)
@@ -148,13 +182,7 @@ constructor(
valueRange = volumeRange.first.toFloat()..volumeRange.last.toFloat(),
icon = getIcon(ringerMode),
label = label,
- disabledMessage =
- context.getString(
- disabledTextByStream.getOrDefault(
- audioStream,
- R.string.stream_alarm_unavailable,
- )
- ),
+ disabledMessage = disabledMessage,
isEnabled = isEnabled,
a11yStep = volumeRange.step,
a11yClickDescription =
@@ -191,6 +219,43 @@ constructor(
)
}
+ private fun getStreamDisabledMessage(
+ blockingEverything: ActiveZenModes,
+ blockingAlarms: ActiveZenModes,
+ blockingMedia: ActiveZenModes,
+ ): String {
+ // TODO: b/372213356 - Figure out the correct messages for VOICE_CALL and RING.
+ // In fact, VOICE_CALL should not be affected by interruption filtering at all.
+ return if (audioStream.value == STREAM_NOTIFICATION) {
+ context.getString(R.string.stream_notification_unavailable)
+ } else {
+ val blockingModeName =
+ when {
+ blockingEverything.mainMode != null -> blockingEverything.mainMode.name
+ audioStream.value == STREAM_ALARM -> blockingAlarms.mainMode?.name
+ audioStream.value == STREAM_MUSIC -> blockingMedia.mainMode?.name
+ else -> null
+ }
+
+ if (blockingModeName != null) {
+ context.getString(R.string.stream_unavailable_by_modes, blockingModeName)
+ } else {
+ // Should not actually be visible, but as a catch-all.
+ context.getString(R.string.stream_unavailable_by_unknown)
+ }
+ }
+ }
+
+ private fun getStreamDisabledMessageWithoutModes(audioStream: AudioStream): String {
+ // TODO: b/372213356 - Figure out the correct messages for VOICE_CALL and RING.
+ // In fact, VOICE_CALL should not be affected by interruption filtering at all.
+ return if (audioStream.value == STREAM_NOTIFICATION) {
+ context.getString(R.string.stream_notification_unavailable)
+ } else {
+ context.getString(R.string.stream_alarm_unavailable)
+ }
+ }
+
private fun AudioStreamModel.getIcon(ringerMode: RingerMode): Icon {
val iconRes =
if (isAffectedByMute && isMuted) {
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModelKosmos.kt
index e6b52f0c52e0..55f0a28d0135 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModelKosmos.kt
@@ -19,6 +19,7 @@ package com.android.systemui.volume.panel.component.volume.slider.ui.viewmodel
import android.content.applicationContext
import com.android.internal.logging.uiEventLogger
import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.statusbar.policy.domain.interactor.zenModeInteractor
import com.android.systemui.volume.domain.interactor.audioVolumeInteractor
import com.android.systemui.volume.shared.volumePanelLogger
import kotlinx.coroutines.CoroutineScope
@@ -36,6 +37,7 @@ val Kosmos.audioStreamSliderViewModelFactory by
coroutineScope,
applicationContext,
audioVolumeInteractor,
+ zenModeInteractor,
uiEventLogger,
volumePanelLogger,
)