From 84cee1fc2ca32c7f5d920faccb0772e901311598 Mon Sep 17 00:00:00 2001 From: Haijie Hong Date: Wed, 5 Feb 2025 11:18:55 +0800 Subject: Fix memory issue introduced by ag/29732078 Bug: 390438221 Test: local tested Flag: com.android.settingslib.flags.enable_le_audio_sharing Change-Id: I0062f0ce63e78974de0a61dfc4110f5a1117ff12 --- .../data/repository/AudioSharingRepository.kt | 37 ++++++++++------------ 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'packages/SettingsLib/src') diff --git a/packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioSharingRepository.kt b/packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioSharingRepository.kt index 01bf0c8335d1..8771ba05a6a8 100644 --- a/packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioSharingRepository.kt +++ b/packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioSharingRepository.kt @@ -150,27 +150,13 @@ class AudioSharingRepositoryImpl( BluetoothCsipSetCoordinator.GROUP_ID_INVALID ) - override val secondaryGroupId: StateFlow = - secondaryDevice - .map { BluetoothUtils.getGroupId(it) } - .onEach { logger.onSecondaryGroupIdChanged(it) } - .flowOn(backgroundCoroutineContext) - .stateIn( - coroutineScope, - SharingStarted.WhileSubscribed(), - BluetoothCsipSetCoordinator.GROUP_ID_INVALID - ) + override val primaryDevice: StateFlow = + primaryGroupId + .map { getCachedDeviceFromGroupId(it) } + .stateIn(coroutineScope, SharingStarted.WhileSubscribed(), null) - override val primaryDevice: StateFlow - get() = primaryGroupId.map { getCachedDeviceFromGroupId(it) } - .stateIn( - coroutineScope, - SharingStarted.WhileSubscribed(), - null - ) - - override val secondaryDevice: StateFlow - get() = merge( + override val secondaryDevice: StateFlow = + merge( isAudioSharingProfilesReady.flatMapLatest { ready -> if (ready) { btManager.profileManager.leAudioBroadcastAssistantProfile @@ -196,6 +182,17 @@ class AudioSharingRepositoryImpl( null ) + override val secondaryGroupId: StateFlow = + secondaryDevice + .map { BluetoothUtils.getGroupId(it) } + .onEach { logger.onSecondaryGroupIdChanged(it) } + .flowOn(backgroundCoroutineContext) + .stateIn( + coroutineScope, + SharingStarted.WhileSubscribed(), + BluetoothCsipSetCoordinator.GROUP_ID_INVALID + ) + override val volumeMap: StateFlow = inAudioSharing.flatMapLatest { isSharing -> if (isSharing) { -- cgit v1.2.3-59-g8ed1b