mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
chore: review-cleanup fleet (audit + fix + hardening) (#5158)
This commit is contained in:
parent
872c566ef1
commit
17e69c6d4c
68 changed files with 784 additions and 459 deletions
|
|
@ -213,10 +213,6 @@ interface MeshPrefs {
|
|||
|
||||
fun setDeviceAddress(address: String?)
|
||||
|
||||
fun shouldProvideNodeLocation(nodeNum: Int?): StateFlow<Boolean>
|
||||
|
||||
fun setShouldProvideNodeLocation(nodeNum: Int?, provide: Boolean)
|
||||
|
||||
fun getStoreForwardLastRequest(address: String?): StateFlow<Int>
|
||||
|
||||
fun setStoreForwardLastRequest(address: String?, timestamp: Int)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.meshtastic.core.repository
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import org.meshtastic.core.model.ConnectionState
|
||||
|
|
@ -68,12 +69,26 @@ interface RadioInterfaceService : RadioTransportCallback {
|
|||
/** Whether we are currently using a mock transport. */
|
||||
fun isMockTransport(): Boolean
|
||||
|
||||
/** Flow of raw data received from the radio. */
|
||||
val receivedData: SharedFlow<ByteArray>
|
||||
/**
|
||||
* Flow of raw data received from the radio.
|
||||
*
|
||||
* Emissions preserve the order in which bytes arrived from the hardware — this is required because the firmware
|
||||
* handshake (initial config packet ordering) depends on strict FIFO delivery. Implementations MUST guarantee
|
||||
* ordering; do not swap in a [SharedFlow] without preserving order.
|
||||
*/
|
||||
val receivedData: Flow<ByteArray>
|
||||
|
||||
/** Flow of radio activity events. */
|
||||
val meshActivity: SharedFlow<MeshActivity>
|
||||
|
||||
/**
|
||||
* Drains any bytes currently buffered in [receivedData] without emitting them to collectors.
|
||||
*
|
||||
* Callers invoke this before attaching a fresh collector after a stop/start cycle so stale bytes buffered while no
|
||||
* collector was attached do not get replayed ahead of the next session's handshake.
|
||||
*/
|
||||
fun resetReceivedBuffer()
|
||||
|
||||
/** Sends a raw byte array to the radio. */
|
||||
fun sendToRadio(bytes: ByteArray)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,13 +16,11 @@
|
|||
*/
|
||||
package org.meshtastic.core.repository
|
||||
|
||||
import okio.Closeable
|
||||
|
||||
/**
|
||||
* Interface for hardware transports (BLE, Serial, TCP, etc.) that handles raw byte communication. This is the
|
||||
* KMP-compatible replacement for the legacy Android-specific IRadioInterface.
|
||||
*/
|
||||
interface RadioTransport : Closeable {
|
||||
interface RadioTransport {
|
||||
/** Sends a raw byte array to the radio hardware. */
|
||||
fun handleSendToRadio(p: ByteArray)
|
||||
|
||||
|
|
@ -39,4 +37,13 @@ interface RadioTransport : Closeable {
|
|||
* function can be implemented by transports to see if we are really connected.
|
||||
*/
|
||||
fun keepAlive() {}
|
||||
|
||||
/**
|
||||
* Closes the connection to the device.
|
||||
*
|
||||
* Implementations that perform potentially-blocking teardown (e.g. BLE GATT disconnect) MUST run that work inside
|
||||
* `withContext(NonCancellable)` so a cancelled caller cannot skip cleanup, leaving the underlying resource leaked.
|
||||
* Callers must invoke this from a coroutine — it must never be called from a blocking context (no `runBlocking`).
|
||||
*/
|
||||
suspend fun close()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,14 @@
|
|||
*/
|
||||
package org.meshtastic.core.repository
|
||||
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class RadioTransportTest {
|
||||
|
||||
@Test
|
||||
fun `RadioTransport can be implemented`() {
|
||||
fun `RadioTransport can be implemented`() = runTest {
|
||||
var sentData: ByteArray? = null
|
||||
var closed = false
|
||||
var keepAliveCalled = false
|
||||
|
|
@ -37,7 +38,7 @@ class RadioTransportTest {
|
|||
keepAliveCalled = true
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
override suspend fun close() {
|
||||
closed = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue