mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-02-06 13:53:02 -05:00
prevent race condition if meshservice starts running before radiointerface
This commit is contained in:
@@ -5,6 +5,10 @@ package com.geeksville.mesh;
|
||||
|
||||
interface IRadioInterfaceService {
|
||||
|
||||
/** If the service is not currently connected to the radio, try to connect now. At boot the radio interface service will
|
||||
* not connect to a radio until this call is received. */
|
||||
void connect();
|
||||
|
||||
void sendToRadio(in byte [] a);
|
||||
|
||||
/// If a macaddress we will try to talk to our device, if null we will be idle.
|
||||
|
||||
@@ -148,7 +148,12 @@ class MeshService : Service(), Logging {
|
||||
private val clientPackages = mutableMapOf<String, String>()
|
||||
|
||||
val radio = ServiceClient {
|
||||
IRadioInterfaceService.Stub.asInterface(it)
|
||||
val stub = IRadioInterfaceService.Stub.asInterface(it)
|
||||
|
||||
// Now that we are connected to the radio service, tell it to connect to the radio
|
||||
stub.connect()
|
||||
|
||||
stub
|
||||
}
|
||||
|
||||
private val serviceJob = Job()
|
||||
|
||||
@@ -171,7 +171,6 @@ class RadioInterfaceService : Service(), Logging {
|
||||
runningService = this
|
||||
super.onCreate()
|
||||
registerReceiver(bluetoothStateReceiver, bluetoothStateReceiver.intent)
|
||||
startInterface()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
@@ -237,7 +236,7 @@ class RadioInterfaceService : Service(), Logging {
|
||||
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun setBondedDeviceAddress(addressIn: String?) {
|
||||
private fun setBondedDeviceAddress(addressIn: String?) {
|
||||
// Record that this use has configured a radio
|
||||
GeeksvilleApplication.analytics.track(
|
||||
"mesh_bond"
|
||||
@@ -272,6 +271,14 @@ class RadioInterfaceService : Service(), Logging {
|
||||
setBondedDeviceAddress(deviceAddr)
|
||||
}
|
||||
|
||||
/** If the service is not currently connected to the radio, try to connect now. At boot the radio interface service will
|
||||
* not connect to a radio until this call is received. */
|
||||
override fun connect() = toRemoteExceptions {
|
||||
// We don't start actually talking to our device until MeshService binds to us - this prevents
|
||||
// broadcasting connection events before MeshService is ready to receive them
|
||||
startInterface()
|
||||
}
|
||||
|
||||
override fun sendToRadio(a: ByteArray) {
|
||||
// Do this in the IO thread because it might take a while (and we don't care about the result code)
|
||||
serviceScope.handledLaunch { handleSendToRadio(a) }
|
||||
|
||||
Reference in New Issue
Block a user