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

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

Merge "Add Volume Panel sliders logs" into main

parents ed804207 803659a0
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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
@@ -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> =
@@ -170,6 +172,7 @@ class AudioRepositoryImpl(
            .conflate()
            .map { getCurrentAudioStream(audioStream) }
            .onStart { emit(getCurrentAudioStream(audioStream)) }
            .onEach { logger.onVolumeUpdateReceived(audioStream, it) }
            .flowOn(backgroundCoroutineContext)
    }

@@ -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)
        }
    }
@@ -247,4 +251,11 @@ class AudioRepositoryImpl(
            awaitClose { contentResolver.unregisterContentObserver(observer) }
        }
    }

    interface Logger {

        fun onSetVolumeRequested(audioStream: AudioStream, volume: Int)

        fun onVolumeUpdateReceived(audioStream: AudioStream, model: AudioStreamModel)
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -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
@@ -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(
+11 −0
Original line number Diff line number Diff line
@@ -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()
@@ -109,6 +110,7 @@ class AudioRepositoryTest {
                contentResolver,
                testScope.testScheduler,
                testScope.backgroundScope,
                logger,
            )
    }

@@ -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(
+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")
        }
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -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