mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix: bt notif subscription race condition (#3645)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
23db9f2443
commit
f0b9a0ff75
1 changed files with 19 additions and 31 deletions
|
|
@ -242,39 +242,27 @@ constructor(
|
|||
}
|
||||
|
||||
@OptIn(ExperimentalUuidApi::class)
|
||||
private fun setupNotifications() {
|
||||
localScope.launch {
|
||||
fromNumCharacteristic
|
||||
?.subscribe()
|
||||
?.onEach { notifyBytes ->
|
||||
try {
|
||||
Timber.d(
|
||||
"FROMNUM notify, ${notifyBytes.size} bytes: ${
|
||||
notifyBytes.joinToString(
|
||||
prefix = "[",
|
||||
postfix = "]",
|
||||
) { b -> String.format("0x%02x", b) }
|
||||
} - reading packet queue",
|
||||
)
|
||||
drainPacketQueueAndDispatch("notify")
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex, "Error handling incoming FROMNUM notify")
|
||||
}
|
||||
private suspend fun setupNotifications() {
|
||||
fromNumCharacteristic
|
||||
?.subscribe()
|
||||
?.onEach { notifyBytes ->
|
||||
try {
|
||||
Timber.d(
|
||||
"FROMNUM notify, ${notifyBytes.size} bytes: ${
|
||||
notifyBytes.joinToString(
|
||||
prefix = "[",
|
||||
postfix = "]",
|
||||
) { b -> String.format("0x%02x", b) }
|
||||
} - reading packet queue",
|
||||
)
|
||||
drainPacketQueueAndDispatch("notify")
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex, "Error handling incoming FROMNUM notify")
|
||||
}
|
||||
?.catch { e -> Timber.e(e, "Error in subscribe flow for fromNumCharacteristic") }
|
||||
?.onCompletion { cause -> Timber.d("fromNum subscribe flow completed, cause=$cause") }
|
||||
?.launchIn(scope = localScope)
|
||||
}
|
||||
|
||||
localScope.launch {
|
||||
try {
|
||||
fromNumCharacteristic?.setNotifying(true)
|
||||
drainPacketQueueAndDispatch("initial")
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Failed to enable notifications or perform initial drain")
|
||||
service.onDisconnect(false)
|
||||
}
|
||||
}
|
||||
?.catch { e -> Timber.e(e, "Error in subscribe flow for fromNumCharacteristic") }
|
||||
?.onCompletion { cause -> Timber.d("fromNum subscribe flow completed, cause=$cause") }
|
||||
?.launchIn(scope = localScope)
|
||||
service.onConnect()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue