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

Commit ef980766 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move binder calls to a background thread." into main

parents 5925e116 7214f0b9
Loading
Loading
Loading
Loading
+8 −12
Original line number Diff line number Diff line
@@ -26,9 +26,8 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.android.systemui.volume.data.repository.FakeLocalMediaRepository
import com.android.systemui.volume.localMediaController
import com.android.systemui.volume.localMediaRepositoryFactory
@@ -42,7 +41,6 @@ import com.android.systemui.volume.remoteMediaController
import com.android.systemui.volume.remotePlaybackInfo
import com.android.systemui.volume.remotePlaybackStateBuilder
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
@@ -53,7 +51,7 @@ import org.junit.runner.RunWith
@TestableLooper.RunWithLooper(setAsMainLooper = true)
class MediaOutputInteractorTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    private val kosmos = testKosmos().useUnconfinedTestDispatcher()

    private lateinit var underTest: MediaOutputInteractor

@@ -64,7 +62,9 @@ class MediaOutputInteractorTest : SysuiTestCase() {
                "local.test.pkg",
                FakeLocalMediaRepository().apply {
                    updateCurrentConnectedDevice(
                        mock { whenever(name).thenReturn("local_media_device") }
                        TestMediaDevicesFactory.builtInMediaDevice(
                            deviceName = "local_media_device"
                        )
                    )
                },
            )
@@ -72,7 +72,9 @@ class MediaOutputInteractorTest : SysuiTestCase() {
                "remote.test.pkg",
                FakeLocalMediaRepository().apply {
                    updateCurrentConnectedDevice(
                        mock { whenever(name).thenReturn("remote_media_device") }
                        TestMediaDevicesFactory.remoteMediaDevice(
                            deviceName = "remote_media_device"
                        )
                    )
                },
            )
@@ -88,7 +90,6 @@ class MediaOutputInteractorTest : SysuiTestCase() {

                val activeMediaDeviceSessions by
                    collectLastValue(underTest.activeMediaDeviceSessions)
                runCurrent()

                assertThat(activeMediaDeviceSessions!!.local).isNull()
                assertThat(activeMediaDeviceSessions!!.remote).isNull()
@@ -105,7 +106,6 @@ class MediaOutputInteractorTest : SysuiTestCase() {

                val activeMediaDeviceSessions by
                    collectLastValue(underTest.activeMediaDeviceSessions)
                runCurrent()

                with(activeMediaDeviceSessions!!.local!!) {
                    assertThat(packageName).isEqualTo("local.test.pkg")
@@ -148,7 +148,6 @@ class MediaOutputInteractorTest : SysuiTestCase() {

                val activeMediaDeviceSessions by
                    collectLastValue(underTest.activeMediaDeviceSessions)
                runCurrent()

                assertThat(activeMediaDeviceSessions!!.local!!.canAdjustVolume).isFalse()
                assertThat(activeMediaDeviceSessions!!.remote!!.canAdjustVolume).isFalse()
@@ -168,7 +167,6 @@ class MediaOutputInteractorTest : SysuiTestCase() {
                val defaultActiveMediaSession by
                    collectLastValue(underTest.defaultActiveMediaSession)
                val currentDevice by collectLastValue(underTest.currentConnectedDevice)
                runCurrent()

                with((defaultActiveMediaSession as Result.Data<MediaDeviceSession?>).data!!) {
                    assertThat(packageName).isEqualTo("local.test.pkg")
@@ -192,7 +190,6 @@ class MediaOutputInteractorTest : SysuiTestCase() {
                val defaultActiveMediaSession by
                    collectLastValue(underTest.defaultActiveMediaSession)
                val currentDevice by collectLastValue(underTest.currentConnectedDevice)
                runCurrent()

                with((defaultActiveMediaSession as Result.Data<MediaDeviceSession?>).data!!) {
                    assertThat(packageName).isEqualTo("remote.test.pkg")
@@ -216,7 +213,6 @@ class MediaOutputInteractorTest : SysuiTestCase() {
                val defaultActiveMediaSession by
                    collectLastValue(underTest.defaultActiveMediaSession)
                val currentDevice by collectLastValue(underTest.currentConnectedDevice)
                runCurrent()

                with((defaultActiveMediaSession as Result.Data<MediaDeviceSession?>).data!!) {
                    assertThat(packageName).isEqualTo("local.test.pkg")
+14 −8
Original line number Diff line number Diff line
@@ -19,13 +19,16 @@ import com.android.settingslib.volume.data.repository.LocalMediaRepository
import com.android.settingslib.volume.data.repository.LocalMediaRepositoryImpl
import com.android.settingslib.volume.shared.AudioManagerEventsReceiver
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.media.controls.util.LocalMediaManagerFactory
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.withContext

interface LocalMediaRepositoryFactory {

    fun create(packageName: String?, coroutineScope: CoroutineScope): LocalMediaRepository
    suspend fun create(packageName: String?, coroutineScope: CoroutineScope): LocalMediaRepository
}

@SysUISingleton
@@ -34,15 +37,18 @@ class LocalMediaRepositoryFactoryImpl
constructor(
    private val eventsReceiver: AudioManagerEventsReceiver,
    private val localMediaManagerFactory: LocalMediaManagerFactory,
    @Background private val backgroundCoroutineContext: CoroutineContext,
) : LocalMediaRepositoryFactory {

    override fun create(
    override suspend fun create(
        packageName: String?,
        coroutineScope: CoroutineScope
        coroutineScope: CoroutineScope,
    ): LocalMediaRepository =
        withContext(backgroundCoroutineContext) {
            LocalMediaRepositoryImpl(
                eventsReceiver,
                localMediaManagerFactory.create(packageName),
                coroutineScope,
            )
        }
}
+2 −1
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ constructor(
                    .onStart { emit(activeSessions) }
            }
            .map { getMediaControllers(it) }
            .flowOn(backgroundCoroutineContext)
            .stateIn(coroutineScope, SharingStarted.WhileSubscribed(), MediaControllers(null, null))

    /** [MediaDeviceSessions] that contains currently active sessions. */
@@ -131,7 +132,7 @@ constructor(
            var remoteController: MediaController? = null
            val remoteMediaSessions: MutableSet<String> = mutableSetOf()
            for (controller in controllers) {
                val playbackInfo: MediaController.PlaybackInfo = controller.playbackInfo ?: continue
                val playbackInfo: MediaController.PlaybackInfo = controller.playbackInfo
                when (playbackInfo.playbackType) {
                    MediaController.PlaybackInfo.PLAYBACK_TYPE_REMOTE -> {
                        // MediaController can't be local if there is a remote one for the same
+2 −2
Original line number Diff line number Diff line
@@ -28,8 +28,8 @@ class FakeLocalMediaRepositoryFactory(private val defaultProvider: () -> LocalMe
        repositories[packageName] = localMediaRepository
    }

    override fun create(
    override suspend fun create(
        packageName: String?,
        coroutineScope: CoroutineScope
        coroutineScope: CoroutineScope,
    ): LocalMediaRepository = repositories[packageName] ?: defaultProvider()
}