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

Commit 60f42b09 authored by Yiyi Shen's avatar Yiyi Shen
Browse files

Change inAudioSharing to StateFlow

Test: atest
Bug: 336716411
Flag: com.android.settingslib.flags.volume_dialog_audio_sharing_fix
Change-Id: I3481d8bc922387f74a21b92493c7e0a2e534a68c
parent b8481144
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ typealias GroupIdToVolumes = Map<Int, Int>
/** Provides audio sharing functionality. */
interface AudioSharingRepository {
    /** Whether the device is in audio sharing. */
    val inAudioSharing: Flow<Boolean>
    val inAudioSharing: StateFlow<Boolean>

    /** The primary headset groupId in audio sharing. */
    val primaryGroupId: StateFlow<Int>
@@ -101,7 +101,7 @@ class AudioSharingRepositoryImpl(
            .flowOn(backgroundCoroutineContext)
            .stateIn(coroutineScope, SharingStarted.WhileSubscribed(), false)

    override val inAudioSharing: Flow<Boolean> =
    override val inAudioSharing: StateFlow<Boolean> =
        isAudioSharingProfilesReady.flatMapLatest { ready ->
            if (ready) {
                btManager.profileManager.leAudioBroadcastProfile.onBroadcastStartedOrStopped
@@ -113,6 +113,7 @@ class AudioSharingRepositoryImpl(
                flowOf(false)
            }
        }
            .stateIn(coroutineScope, SharingStarted.WhileSubscribed(), false)

    private val primaryChange: Flow<Unit> = callbackFlow {
        val callback =
@@ -254,7 +255,7 @@ class AudioSharingRepositoryImpl(
}

class AudioSharingRepositoryEmptyImpl : AudioSharingRepository {
    override val inAudioSharing: Flow<Boolean> = flowOf(false)
    override val inAudioSharing: StateFlow<Boolean> = MutableStateFlow(false)
    override val primaryGroupId: StateFlow<Int> =
        MutableStateFlow(BluetoothCsipSetCoordinator.GROUP_ID_INVALID)
    override val secondaryGroupId: StateFlow<Int> =
+1 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.volume.data.repository

import com.android.settingslib.volume.data.repository.AudioSharingRepository
import com.android.settingslib.volume.data.repository.GroupIdToVolumes
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

@@ -30,7 +29,7 @@ class FakeAudioSharingRepository : AudioSharingRepository {
        MutableStateFlow(TEST_GROUP_ID_INVALID)
    private val mutableVolumeMap: MutableStateFlow<GroupIdToVolumes> = MutableStateFlow(emptyMap())

    override val inAudioSharing: Flow<Boolean> = mutableInAudioSharing
    override val inAudioSharing: StateFlow<Boolean> = mutableInAudioSharing
    override val primaryGroupId: StateFlow<Int> = mutablePrimaryGroupId
    override val secondaryGroupId: StateFlow<Int> = mutableSecondaryGroupId
    override val volumeMap: StateFlow<GroupIdToVolumes> = mutableVolumeMap