Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingServiceConnection.kt +24 −14 Original line number Diff line number Diff line Loading @@ -56,11 +56,13 @@ import kotlinx.coroutines.flow.flatMapConcat import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.shareIn import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import kotlinx.coroutines.plus import kotlinx.coroutines.withContext @OptIn(ExperimentalCoroutinesApi::class) Loading Loading @@ -101,8 +103,7 @@ class DeviceSettingServiceConnection( } else if (allStatus.all { it is ServiceConnectionStatus.Connected }) { allStatus .filterIsInstance< ServiceConnectionStatus.Connected< IDeviceSettingsProviderService> ServiceConnectionStatus.Connected<IDeviceSettingsProviderService> >() .all { it.service.serviceStatus?.enabled == true } } else { Loading Loading @@ -232,7 +233,7 @@ class DeviceSettingServiceConnection( IDeviceSettingsProviderService.Stub::asInterface, ) .stateIn( coroutineScope, coroutineScope.plus(backgroundCoroutineContext), SharingStarted.WhileSubscribed(), ServiceConnectionStatus.Connecting, ) Loading Loading @@ -273,11 +274,20 @@ class DeviceSettingServiceConnection( launch { send(ServiceConnectionStatus.Connecting) } } } if (!context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)) { if ( !context.bindService( intent, Context.BIND_AUTO_CREATE, { launch { it.run() } }, serviceConnection, ) ) { Log.w(TAG, "Fail to bind service $intent") launch { send(ServiceConnectionStatus.Failed) } } awaitClose { context.unbindService(serviceConnection) } } .flowOn(backgroundCoroutineContext) } private suspend fun tryGetEndpointFromMetadata(cachedDevice: CachedBluetoothDevice): EndPoint? = Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt +3 −3 Original line number Diff line number Diff line Loading @@ -102,9 +102,9 @@ class DeviceSettingRepositoryTest { `when`(settingProviderService2.queryLocalInterface(anyString())) .thenReturn(settingProviderService2) `when`(context.bindService(any(), any(), anyInt())).then { input -> `when`(context.bindService(any(), anyInt(), any(), any())).then { input -> val intent = input.getArgument<Intent?>(0) val connection = input.getArgument<ServiceConnection>(1) val connection = input.getArgument<ServiceConnection>(3) when (intent?.action) { CONFIG_SERVICE_INTENT_ACTION -> Loading Loading @@ -210,7 +210,7 @@ class DeviceSettingRepositoryTest { fun getDeviceSettingsConfig_bindingServiceFail_returnNull() { testScope.runTest { `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG) doReturn(false).`when`(context).bindService(any(), any(), anyInt()) doReturn(false).`when`(context).bindService(any(), anyInt(), any(), any()) val config = underTest.getDeviceSettingsConfig(cachedDevice) Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingServiceConnection.kt +24 −14 Original line number Diff line number Diff line Loading @@ -56,11 +56,13 @@ import kotlinx.coroutines.flow.flatMapConcat import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.shareIn import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import kotlinx.coroutines.plus import kotlinx.coroutines.withContext @OptIn(ExperimentalCoroutinesApi::class) Loading Loading @@ -101,8 +103,7 @@ class DeviceSettingServiceConnection( } else if (allStatus.all { it is ServiceConnectionStatus.Connected }) { allStatus .filterIsInstance< ServiceConnectionStatus.Connected< IDeviceSettingsProviderService> ServiceConnectionStatus.Connected<IDeviceSettingsProviderService> >() .all { it.service.serviceStatus?.enabled == true } } else { Loading Loading @@ -232,7 +233,7 @@ class DeviceSettingServiceConnection( IDeviceSettingsProviderService.Stub::asInterface, ) .stateIn( coroutineScope, coroutineScope.plus(backgroundCoroutineContext), SharingStarted.WhileSubscribed(), ServiceConnectionStatus.Connecting, ) Loading Loading @@ -273,11 +274,20 @@ class DeviceSettingServiceConnection( launch { send(ServiceConnectionStatus.Connecting) } } } if (!context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)) { if ( !context.bindService( intent, Context.BIND_AUTO_CREATE, { launch { it.run() } }, serviceConnection, ) ) { Log.w(TAG, "Fail to bind service $intent") launch { send(ServiceConnectionStatus.Failed) } } awaitClose { context.unbindService(serviceConnection) } } .flowOn(backgroundCoroutineContext) } private suspend fun tryGetEndpointFromMetadata(cachedDevice: CachedBluetoothDevice): EndPoint? = Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt +3 −3 Original line number Diff line number Diff line Loading @@ -102,9 +102,9 @@ class DeviceSettingRepositoryTest { `when`(settingProviderService2.queryLocalInterface(anyString())) .thenReturn(settingProviderService2) `when`(context.bindService(any(), any(), anyInt())).then { input -> `when`(context.bindService(any(), anyInt(), any(), any())).then { input -> val intent = input.getArgument<Intent?>(0) val connection = input.getArgument<ServiceConnection>(1) val connection = input.getArgument<ServiceConnection>(3) when (intent?.action) { CONFIG_SERVICE_INTENT_ACTION -> Loading Loading @@ -210,7 +210,7 @@ class DeviceSettingRepositoryTest { fun getDeviceSettingsConfig_bindingServiceFail_returnNull() { testScope.runTest { `when`(configService.getDeviceSettingsConfig(any())).thenReturn(DEVICE_SETTING_CONFIG) doReturn(false).`when`(context).bindService(any(), any(), anyInt()) doReturn(false).`when`(context).bindService(any(), anyInt(), any(), any()) val config = underTest.getDeviceSettingsConfig(cachedDevice) Loading