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

Commit f86b52b6 authored by Haijie Hong's avatar Haijie Hong
Browse files

Fix coroutine scope issue in DeviceSettingServiceConnection

BUG: 343317785
Test: atest DeviceSettingRepositoryTest
Flag: com.android.settings.flags.enable_bluetooth_device_details_polish
Change-Id: I6ca7ef49e57d43bde981d5ade3417d95f89af57e
parent ca251a4b
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -160,6 +160,12 @@ class DeviceSettingServiceConnection(
            }
            .shareIn(scope = coroutineScope, started = SharingStarted.WhileSubscribed(), replay = 1)

    private val services =
        ConcurrentHashMap<
            EndPoint,
            StateFlow<ServiceConnectionStatus<IDeviceSettingsProviderService>>,
        >()

    /** Gets [DeviceSettingsConfig] for the device, return null when failed. */
    suspend fun getDeviceSettingsConfig(): DeviceSettingsConfig? {
        if (!isServiceEnabled.await()) {
@@ -320,11 +326,5 @@ class DeviceSettingServiceConnection(
        const val CONFIG_SERVICE_PACKAGE_NAME = "DEVICE_SETTINGS_CONFIG_PACKAGE_NAME"
        const val CONFIG_SERVICE_CLASS_NAME = "DEVICE_SETTINGS_CONFIG_CLASS"
        const val CONFIG_SERVICE_INTENT_ACTION = "DEVICE_SETTINGS_CONFIG_ACTION"

        val services =
            ConcurrentHashMap<
                EndPoint,
                StateFlow<ServiceConnectionStatus<IDeviceSettingsProviderService>>,
            >()
    }
}
+0 −6
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -140,11 +139,6 @@ class DeviceSettingRepositoryTest {
            )
    }

    @After
    fun clean() {
        DeviceSettingServiceConnection.services.clear()
    }

    @Test
    fun getDeviceSettingsConfig_withMetadata_success() {
        testScope.runTest {