summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/volume/domain/interactor/AudioVolumeInteractor.kt4
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/volume/domain/interactor/AudioVolumeInteractorTest.kt21
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/volume/data/repository/FakeAudioRepository.kt3
3 files changed, 25 insertions, 3 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/volume/domain/interactor/AudioVolumeInteractor.kt b/packages/SettingsLib/src/com/android/settingslib/volume/domain/interactor/AudioVolumeInteractor.kt
index 202ff400782f..bdd582d5130b 100644
--- a/packages/SettingsLib/src/com/android/settingslib/volume/domain/interactor/AudioVolumeInteractor.kt
+++ b/packages/SettingsLib/src/com/android/settingslib/volume/domain/interactor/AudioVolumeInteractor.kt
@@ -61,6 +61,10 @@ class AudioVolumeInteractor(
}
suspend fun setMuted(audioStream: AudioStream, isMuted: Boolean) {
+ val streamModel = getAudioStream(audioStream).first()
+ if (!streamModel.isAffectedByMute) {
+ return
+ }
if (audioStream.value == AudioManager.STREAM_RING) {
val mode =
if (isMuted) AudioManager.RINGER_MODE_VIBRATE else AudioManager.RINGER_MODE_NORMAL
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/domain/interactor/AudioVolumeInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/domain/interactor/AudioVolumeInteractorTest.kt
index 6e49e431bd80..8a68417f0ef5 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/domain/interactor/AudioVolumeInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/domain/interactor/AudioVolumeInteractorTest.kt
@@ -35,6 +35,7 @@ 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
@@ -48,6 +49,20 @@ class AudioVolumeInteractorTest : SysuiTestCase() {
private val underTest: AudioVolumeInteractor =
with(kosmos) { AudioVolumeInteractor(audioRepository, notificationsSoundPolicyInteractor) }
+ @Before
+ fun setUp() =
+ with(kosmos) {
+ audioRepository.setAudioStreamModel(
+ audioRepository.getAudioStream(audioStream).value.copy(isAffectedByMute = true)
+ )
+ audioRepository.setAudioStreamModel(
+ audioRepository
+ .getAudioStream(AudioStream(AudioManager.STREAM_RING))
+ .value
+ .copy(isAffectedByMute = true)
+ )
+ }
+
@Test
fun setMuted_mutesStream() {
with(kosmos) {
@@ -189,10 +204,14 @@ class AudioVolumeInteractorTest : SysuiTestCase() {
testScope.runTest {
val audioStreamModel by collectLastValue(underTest.getAudioStream(audioStream))
audioRepository.setAudioStreamModel(
- audioStreamModel!!.copy(isAffectedByMute = false)
+ audioStreamModel!!.copy(isAffectedByMute = false, isMuted = false)
)
+ underTest.setMuted(audioStream, true)
+ runCurrent()
+
assertThat(audioStreamModel!!.isAffectedByMute).isFalse()
+ assertThat(audioStreamModel!!.isMuted).isFalse()
}
}
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/data/repository/FakeAudioRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/data/repository/FakeAudioRepository.kt
index fcea9e7b2a3f..135cb14a3497 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/volume/data/repository/FakeAudioRepository.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/volume/data/repository/FakeAudioRepository.kt
@@ -22,7 +22,6 @@ import com.android.settingslib.volume.data.repository.AudioRepository
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 kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
@@ -61,7 +60,7 @@ class FakeAudioRepository : AudioRepository {
)
}
- override fun getAudioStream(audioStream: AudioStream): Flow<AudioStreamModel> =
+ override fun getAudioStream(audioStream: AudioStream): StateFlow<AudioStreamModel> =
getAudioStreamModelState(audioStream).asStateFlow()
override suspend fun setVolume(audioStream: AudioStream, volume: Int) {