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

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

Merge "Make SliceViewManager calls from the main thread" into main

parents 295f1852 6cbe5d27
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ class AncSliceRepositoryTest : SysuiTestCase() {
                AncSliceRepositoryImpl(
                    localMediaRepositoryFactory,
                    testScope.testScheduler,
                    testScope.testScheduler,
                    sliceViewManager,
                )
        }
+3 −0
Original line number Diff line number Diff line
@@ -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 {
+3 −1
Original line number Diff line number Diff line
@@ -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)
    }