Loading packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioRepository.kt +4 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterIsInstance Loading Loading @@ -161,6 +162,7 @@ class AudioRepositoryImpl( }, volumeSettingChanges(audioStream), ) .conflate() .map { getCurrentAudioStream(audioStream) } .onStart { emit(getCurrentAudioStream(audioStream)) } .flowOn(backgroundCoroutineContext) Loading @@ -184,10 +186,11 @@ class AudioRepositoryImpl( } } override suspend fun setVolume(audioStream: AudioStream, volume: Int) = override suspend fun setVolume(audioStream: AudioStream, volume: Int) { withContext(backgroundCoroutineContext) { audioManager.setStreamVolume(audioStream.value, volume, 0) } } override suspend fun setMuted(audioStream: AudioStream, isMuted: Boolean): Boolean { return withContext(backgroundCoroutineContext) { Loading packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt +13 −3 Original line number Diff line number Diff line Loading @@ -32,9 +32,13 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlin.math.roundToInt import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch Loading @@ -49,6 +53,7 @@ constructor( private val uiEventLogger: UiEventLogger, ) : SliderViewModel { private val volumeChanges = MutableStateFlow<Int?>(null) private val streamsAffectedByRing = setOf( AudioManager.STREAM_RING, Loading Loading @@ -104,12 +109,17 @@ constructor( } .stateIn(coroutineScope, SharingStarted.Eagerly, SliderState.Empty) init { volumeChanges .filterNotNull() .onEach { audioVolumeInteractor.setVolume(audioStream, it) } .launchIn(coroutineScope) } override fun onValueChanged(state: SliderState, newValue: Float) { val audioViewModel = state as? State audioViewModel ?: return coroutineScope.launch { audioVolumeInteractor.setVolume(audioStream, newValue.roundToInt()) } volumeChanges.tryEmit(newValue.roundToInt()) } override fun onValueChangeFinished() { Loading Loading
packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioRepository.kt +4 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterIsInstance Loading Loading @@ -161,6 +162,7 @@ class AudioRepositoryImpl( }, volumeSettingChanges(audioStream), ) .conflate() .map { getCurrentAudioStream(audioStream) } .onStart { emit(getCurrentAudioStream(audioStream)) } .flowOn(backgroundCoroutineContext) Loading @@ -184,10 +186,11 @@ class AudioRepositoryImpl( } } override suspend fun setVolume(audioStream: AudioStream, volume: Int) = override suspend fun setVolume(audioStream: AudioStream, volume: Int) { withContext(backgroundCoroutineContext) { audioManager.setStreamVolume(audioStream.value, volume, 0) } } override suspend fun setMuted(audioStream: AudioStream, isMuted: Boolean): Boolean { return withContext(backgroundCoroutineContext) { Loading
packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt +13 −3 Original line number Diff line number Diff line Loading @@ -32,9 +32,13 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlin.math.roundToInt import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch Loading @@ -49,6 +53,7 @@ constructor( private val uiEventLogger: UiEventLogger, ) : SliderViewModel { private val volumeChanges = MutableStateFlow<Int?>(null) private val streamsAffectedByRing = setOf( AudioManager.STREAM_RING, Loading Loading @@ -104,12 +109,17 @@ constructor( } .stateIn(coroutineScope, SharingStarted.Eagerly, SliderState.Empty) init { volumeChanges .filterNotNull() .onEach { audioVolumeInteractor.setVolume(audioStream, it) } .launchIn(coroutineScope) } override fun onValueChanged(state: SliderState, newValue: Float) { val audioViewModel = state as? State audioViewModel ?: return coroutineScope.launch { audioVolumeInteractor.setVolume(audioStream, newValue.roundToInt()) } volumeChanges.tryEmit(newValue.roundToInt()) } override fun onValueChangeFinished() { Loading