kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
fix: add @Singleton annotation to RadioInterfaceService
- ensure only one RadioInterfaceService instance is created and used throughout the app - fix multiple startInterface() calls when Bluetooth is enabledpull/598/head
rodzic
af287c2e6f
commit
054d2330a4
|
@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,6 +34,7 @@ import javax.inject.Inject
|
||||||
* Note - this class intentionally dumb. It doesn't understand protobuf framing etc...
|
* Note - this class intentionally dumb. It doesn't understand protobuf framing etc...
|
||||||
* It is designed to be simple so it can be stubbed out with a simulated version as needed.
|
* It is designed to be simple so it can be stubbed out with a simulated version as needed.
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
class RadioInterfaceService @Inject constructor(
|
class RadioInterfaceService @Inject constructor(
|
||||||
private val context: Application,
|
private val context: Application,
|
||||||
private val dispatchers: CoroutineDispatchers,
|
private val dispatchers: CoroutineDispatchers,
|
||||||
|
@ -72,8 +74,8 @@ class RadioInterfaceService @Inject constructor(
|
||||||
init {
|
init {
|
||||||
processLifecycle.coroutineScope.launch {
|
processLifecycle.coroutineScope.launch {
|
||||||
bluetoothRepository.state.collect { state ->
|
bluetoothRepository.state.collect { state ->
|
||||||
if (state.enabled) {
|
if (state.enabled && !isStarted) {
|
||||||
// startInterface() FIXME no longer safe to call here, crashing SafeBluetooth.asyncConnect
|
startInterface()
|
||||||
} else if (radioIf is BluetoothInterface) {
|
} else if (radioIf is BluetoothInterface) {
|
||||||
stopInterface()
|
stopInterface()
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue