diff options
3 files changed, 7 insertions, 1 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/anc/data/repository/AncSliceRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/anc/data/repository/AncSliceRepositoryTest.kt index dc9613904e4e..dddf582908c7 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/anc/data/repository/AncSliceRepositoryTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/volume/panel/component/anc/data/repository/AncSliceRepositoryTest.kt @@ -61,6 +61,7 @@ class AncSliceRepositoryTest : SysuiTestCase() { AncSliceRepositoryImpl( localMediaRepositoryFactory, testScope.testScheduler, + testScope.testScheduler, sliceViewManager, ) } diff --git a/packages/SystemUI/src/com/android/systemui/slice/SliceViewManagerExt.kt b/packages/SystemUI/src/com/android/systemui/slice/SliceViewManagerExt.kt index 384acc493c4a..dd7942503211 100644 --- a/packages/SystemUI/src/com/android/systemui/slice/SliceViewManagerExt.kt +++ b/packages/SystemUI/src/com/android/systemui/slice/SliceViewManagerExt.kt @@ -28,6 +28,9 @@ import kotlinx.coroutines.launch * Returns updating [Slice] for a [sliceUri]. It's null when there is no slice available for the * provided Uri. This can change overtime because of external changes (like device being * connected/disconnected). + * + * The flow should be [kotlinx.coroutines.flow.flowOn] the main thread because [SliceViewManager] + * isn't thread-safe. An exception will be thrown otherwise. */ fun SliceViewManager.sliceForUri(sliceUri: Uri): Flow<Slice?> = ConflatedCallbackFlow.conflatedCallbackFlow { diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/anc/data/repository/AncSliceRepository.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/anc/data/repository/AncSliceRepository.kt index 8ce3b1fa1e73..3117abc44111 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/anc/data/repository/AncSliceRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/anc/data/repository/AncSliceRepository.kt @@ -23,6 +23,7 @@ import androidx.slice.SliceViewManager import com.android.settingslib.bluetooth.BluetoothUtils import com.android.settingslib.media.BluetoothMediaDevice import com.android.systemui.dagger.qualifiers.Background +import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.slice.sliceForUri import com.android.systemui.volume.panel.component.mediaoutput.data.repository.LocalMediaRepositoryFactory import dagger.assisted.Assisted @@ -57,6 +58,7 @@ class AncSliceRepositoryImpl constructor( mediaRepositoryFactory: LocalMediaRepositoryFactory, @Background private val backgroundCoroutineContext: CoroutineContext, + @Main private val mainCoroutineContext: CoroutineContext, @Assisted private val sliceViewManager: SliceViewManager, ) : AncSliceRepository { @@ -73,7 +75,7 @@ constructor( .distinctUntilChanged() .flatMapLatest { sliceUri -> sliceUri ?: return@flatMapLatest flowOf(null) - sliceViewManager.sliceForUri(sliceUri) + sliceViewManager.sliceForUri(sliceUri).flowOn(mainCoroutineContext) } .flowOn(backgroundCoroutineContext) } |