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

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

Merge "Move binder calls to the background threads" into main

parents 538a83b3 11093e4e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.media.AudioManager
import android.util.Log
import com.android.settingslib.volume.shared.model.AudioManagerEvent
import com.android.settingslib.volume.shared.model.AudioStream
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.SharedFlow
@@ -31,6 +32,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.launch
@@ -44,6 +46,7 @@ interface AudioManagerEventsReceiver {
class AudioManagerEventsReceiverImpl(
    private val context: Context,
    coroutineScope: CoroutineScope,
    backgroundCoroutineContext: CoroutineContext,
) : AudioManagerEventsReceiver {

    private val allActions: Collection<String>
@@ -79,6 +82,7 @@ class AudioManagerEventsReceiverImpl(
            .filterNotNull()
            .filter { intent -> allActions.contains(intent.action) }
            .mapNotNull { it.toAudioManagerEvent() }
            .flowOn(backgroundCoroutineContext)
            .shareIn(coroutineScope, SharingStarted.WhileSubscribed())

    private fun Intent.toAudioManagerEvent(): AudioManagerEvent? {
+6 −1
Original line number Diff line number Diff line
@@ -60,7 +60,12 @@ class AudioManagerEventsReceiverTest {
    fun setup() {
        MockitoAnnotations.initMocks(this)

        underTest = AudioManagerEventsReceiverImpl(context, testScope.backgroundScope)
        underTest =
            AudioManagerEventsReceiverImpl(
                context,
                testScope.backgroundScope,
                testScope.testScheduler,
            )
    }

    @Test
+1 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ constructor(
    private val captioningManager: StateFlow<CaptioningManager?> =
        userRepository.selectedUser
            .map { userScopedCaptioningManagerProvider.forUser(it.userInfo.userHandle) }
            .flowOn(backgroundCoroutineContext)
            .stateIn(coroutineScope, SharingStarted.WhileSubscribed(), null)

    override val captioningModel: StateFlow<CaptioningModel?> =
+7 −6
Original line number Diff line number Diff line
@@ -53,7 +53,9 @@ interface AudioModule {
        fun provideAudioManagerIntentsReceiver(
            @Application context: Context,
            @Application coroutineScope: CoroutineScope,
        ): AudioManagerEventsReceiver = AudioManagerEventsReceiverImpl(context, coroutineScope)
            @Background coroutineContext: CoroutineContext,
        ): AudioManagerEventsReceiver =
            AudioManagerEventsReceiverImpl(context, coroutineScope, coroutineContext)

        @Provides
        @SysUISingleton
@@ -82,7 +84,7 @@ interface AudioModule {
            localBluetoothManager: LocalBluetoothManager?,
            @Application coroutineScope: CoroutineScope,
            @Background coroutineContext: CoroutineContext,
            volumeLogger: VolumeLogger
            volumeLogger: VolumeLogger,
        ): AudioSharingRepository =
            if (Flags.enableLeAudioSharing() && localBluetoothManager != null) {
                AudioSharingRepositoryImpl(
@@ -90,7 +92,7 @@ interface AudioModule {
                    localBluetoothManager,
                    coroutineScope,
                    coroutineContext,
                    volumeLogger
                    volumeLogger,
                )
            } else {
                AudioSharingRepositoryEmptyImpl()
@@ -111,8 +113,7 @@ interface AudioModule {

        @Provides
        @SysUISingleton
        fun provideAudioSystemRepository(
            @Application context: Context,
        ): AudioSystemRepository = AudioSystemRepositoryImpl(context)
        fun provideAudioSystemRepository(@Application context: Context): AudioSystemRepository =
            AudioSystemRepositoryImpl(context)
    }
}
+9 −5
Original line number Diff line number Diff line
@@ -22,15 +22,17 @@ import android.media.session.MediaSession
import android.media.session.PlaybackState
import android.os.Bundle
import android.os.Handler
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import com.android.systemui.volume.panel.component.mediaoutput.domain.model.MediaControllerChangeModel
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.channels.ProducerScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import com.android.app.tracing.coroutines.launchTraced as launch
import kotlinx.coroutines.flow.flowOn

interface MediaControllerInteractor {

@@ -43,6 +45,7 @@ class MediaControllerInteractorImpl
@Inject
constructor(
    @Background private val backgroundHandler: Handler,
    @Background private val backgroundCoroutineContext: CoroutineContext,
) : MediaControllerInteractor {

    override fun stateChanges(mediaController: MediaController): Flow<MediaControllerChangeModel> {
@@ -51,6 +54,7 @@ constructor(
                mediaController.registerCallback(callback, backgroundHandler)
                awaitClose { mediaController.unregisterCallback(callback) }
            }
            .flowOn(backgroundCoroutineContext)
    }
}

Loading