Loading packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioRepository.kt +11 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch Loading Loading @@ -98,6 +99,7 @@ class AudioRepositoryImpl( private val contentResolver: ContentResolver, private val backgroundCoroutineContext: CoroutineContext, private val coroutineScope: CoroutineScope, private val logger: Logger, ) : AudioRepository { private val streamSettingNames: Map<AudioStream, String> = Loading Loading @@ -170,6 +172,7 @@ class AudioRepositoryImpl( .conflate() .map { getCurrentAudioStream(audioStream) } .onStart { emit(getCurrentAudioStream(audioStream)) } .onEach { logger.onVolumeUpdateReceived(audioStream, it) } .flowOn(backgroundCoroutineContext) } Loading @@ -193,6 +196,7 @@ class AudioRepositoryImpl( override suspend fun setVolume(audioStream: AudioStream, volume: Int) { withContext(backgroundCoroutineContext) { logger.onSetVolumeRequested(audioStream, volume) audioManager.setStreamVolume(audioStream.value, volume, 0) } } Loading Loading @@ -247,4 +251,11 @@ class AudioRepositoryImpl( awaitClose { contentResolver.unregisterContentObserver(observer) } } } interface Logger { fun onSetVolumeRequested(audioStream: AudioStream, volume: Int) fun onVolumeUpdateReceived(audioStream: AudioStream, model: AudioStreamModel) } } packages/SettingsLib/src/com/android/settingslib/volume/shared/model/AudioStream.kt +3 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settingslib.volume.shared.model import android.media.AudioManager import android.media.AudioSystem /** Type-safe wrapper for [AudioManager] audio stream. */ @JvmInline Loading @@ -25,6 +26,8 @@ value class AudioStream(val value: Int) { require(value in supportedStreamTypes) { "Unsupported stream=$value" } } override fun toString(): String = AudioSystem.streamToString(value) companion object { val supportedStreamTypes = setOf( Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/volume/data/repository/AudioRepositoryTest.kt +11 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ class AudioRepositoryTest { @Mock private lateinit var communicationDevice: AudioDeviceInfo @Mock private lateinit var contentResolver: ContentResolver private val logger = FakeAudioRepositoryLogger() private val eventsReceiver = FakeAudioManagerEventsReceiver() private val volumeByStream: MutableMap<Int, Int> = mutableMapOf() private val isAffectedByRingerModeByStream: MutableMap<Int, Boolean> = mutableMapOf() Loading Loading @@ -109,6 +110,7 @@ class AudioRepositoryTest { contentResolver, testScope.testScheduler, testScope.backgroundScope, logger, ) } Loading Loading @@ -173,6 +175,15 @@ class AudioRepositoryTest { underTest.setVolume(audioStream, 50) runCurrent() assertThat(logger.logs) .isEqualTo( listOf( "onVolumeUpdateReceived audioStream=STREAM_SYSTEM", "onSetVolumeRequested audioStream=STREAM_SYSTEM", "onVolumeUpdateReceived audioStream=STREAM_SYSTEM", "onVolumeUpdateReceived audioStream=STREAM_SYSTEM", ) ) assertThat(streamModel) .isEqualTo( AudioStreamModel( Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/volume/data/repository/FakeAudioRepositoryLogger.kt 0 → 100644 +39 −0 Original line number Diff line number Diff line /* * 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.settingslib.volume.data.repository import com.android.settingslib.volume.shared.model.AudioStream import com.android.settingslib.volume.shared.model.AudioStreamModel class FakeAudioRepositoryLogger : AudioRepositoryImpl.Logger { private val mutableLogs: MutableList<String> = mutableListOf() val logs: List<String> get() = mutableLogs override fun onSetVolumeRequested(audioStream: AudioStream, volume: Int) { synchronized(mutableLogs) { mutableLogs.add("onSetVolumeRequested audioStream=$audioStream") } } override fun onVolumeUpdateReceived(audioStream: AudioStream, model: AudioStreamModel) { synchronized(mutableLogs) { mutableLogs.add("onVolumeUpdateReceived audioStream=$audioStream") } } } packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +7 −0 Original line number Diff line number Diff line Loading @@ -674,4 +674,11 @@ public class LogModule { return factory.create("DeviceEntryIconLog", 100); } /** Provides a {@link LogBuffer} for use by the volume loggers. */ @Provides @SysUISingleton @VolumeLog public static LogBuffer provideVolumeLogBuffer(LogBufferFactory factory) { return factory.create("VolumeLog", 50); } } Loading
packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioRepository.kt +11 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch Loading Loading @@ -98,6 +99,7 @@ class AudioRepositoryImpl( private val contentResolver: ContentResolver, private val backgroundCoroutineContext: CoroutineContext, private val coroutineScope: CoroutineScope, private val logger: Logger, ) : AudioRepository { private val streamSettingNames: Map<AudioStream, String> = Loading Loading @@ -170,6 +172,7 @@ class AudioRepositoryImpl( .conflate() .map { getCurrentAudioStream(audioStream) } .onStart { emit(getCurrentAudioStream(audioStream)) } .onEach { logger.onVolumeUpdateReceived(audioStream, it) } .flowOn(backgroundCoroutineContext) } Loading @@ -193,6 +196,7 @@ class AudioRepositoryImpl( override suspend fun setVolume(audioStream: AudioStream, volume: Int) { withContext(backgroundCoroutineContext) { logger.onSetVolumeRequested(audioStream, volume) audioManager.setStreamVolume(audioStream.value, volume, 0) } } Loading Loading @@ -247,4 +251,11 @@ class AudioRepositoryImpl( awaitClose { contentResolver.unregisterContentObserver(observer) } } } interface Logger { fun onSetVolumeRequested(audioStream: AudioStream, volume: Int) fun onVolumeUpdateReceived(audioStream: AudioStream, model: AudioStreamModel) } }
packages/SettingsLib/src/com/android/settingslib/volume/shared/model/AudioStream.kt +3 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settingslib.volume.shared.model import android.media.AudioManager import android.media.AudioSystem /** Type-safe wrapper for [AudioManager] audio stream. */ @JvmInline Loading @@ -25,6 +26,8 @@ value class AudioStream(val value: Int) { require(value in supportedStreamTypes) { "Unsupported stream=$value" } } override fun toString(): String = AudioSystem.streamToString(value) companion object { val supportedStreamTypes = setOf( Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/volume/data/repository/AudioRepositoryTest.kt +11 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ class AudioRepositoryTest { @Mock private lateinit var communicationDevice: AudioDeviceInfo @Mock private lateinit var contentResolver: ContentResolver private val logger = FakeAudioRepositoryLogger() private val eventsReceiver = FakeAudioManagerEventsReceiver() private val volumeByStream: MutableMap<Int, Int> = mutableMapOf() private val isAffectedByRingerModeByStream: MutableMap<Int, Boolean> = mutableMapOf() Loading Loading @@ -109,6 +110,7 @@ class AudioRepositoryTest { contentResolver, testScope.testScheduler, testScope.backgroundScope, logger, ) } Loading Loading @@ -173,6 +175,15 @@ class AudioRepositoryTest { underTest.setVolume(audioStream, 50) runCurrent() assertThat(logger.logs) .isEqualTo( listOf( "onVolumeUpdateReceived audioStream=STREAM_SYSTEM", "onSetVolumeRequested audioStream=STREAM_SYSTEM", "onVolumeUpdateReceived audioStream=STREAM_SYSTEM", "onVolumeUpdateReceived audioStream=STREAM_SYSTEM", ) ) assertThat(streamModel) .isEqualTo( AudioStreamModel( Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/volume/data/repository/FakeAudioRepositoryLogger.kt 0 → 100644 +39 −0 Original line number Diff line number Diff line /* * 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.settingslib.volume.data.repository import com.android.settingslib.volume.shared.model.AudioStream import com.android.settingslib.volume.shared.model.AudioStreamModel class FakeAudioRepositoryLogger : AudioRepositoryImpl.Logger { private val mutableLogs: MutableList<String> = mutableListOf() val logs: List<String> get() = mutableLogs override fun onSetVolumeRequested(audioStream: AudioStream, volume: Int) { synchronized(mutableLogs) { mutableLogs.add("onSetVolumeRequested audioStream=$audioStream") } } override fun onVolumeUpdateReceived(audioStream: AudioStream, model: AudioStreamModel) { synchronized(mutableLogs) { mutableLogs.add("onVolumeUpdateReceived audioStream=$audioStream") } } }
packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +7 −0 Original line number Diff line number Diff line Loading @@ -674,4 +674,11 @@ public class LogModule { return factory.create("DeviceEntryIconLog", 100); } /** Provides a {@link LogBuffer} for use by the volume loggers. */ @Provides @SysUISingleton @VolumeLog public static LogBuffer provideVolumeLogBuffer(LogBufferFactory factory) { return factory.create("VolumeLog", 50); } }