refactor(ble): improve connection lifecycle and enhance OTA reliability (#4721)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2026-03-05 12:58:34 -06:00 committed by GitHub
parent 5a5aa1f026
commit 68b2b6d88e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 741 additions and 537 deletions

View file

@ -38,7 +38,6 @@ import no.nordicsemi.kotlin.ble.core.LegacyAdvertisingSetParameters
import no.nordicsemi.kotlin.ble.core.Permission
import org.junit.Before
import org.junit.Test
import org.meshtastic.core.ble.BleError
import org.meshtastic.core.ble.MeshtasticBleConstants.FROMNUM_CHARACTERISTIC
import org.meshtastic.core.ble.MeshtasticBleConstants.FROMRADIO_CHARACTERISTIC
import org.meshtastic.core.ble.MeshtasticBleConstants.LOGRADIO_CHARACTERISTIC
@ -169,7 +168,7 @@ class NordicBleInterfaceRetryTest {
assert(writtenValue!!.contentEquals(dataToSend))
// Verify we didn't disconnect due to the retryable error
verify(exactly = 0) { service.onDisconnect(any<BleError.BluetoothError>()) }
verify(exactly = 0) { service.onDisconnect(any(), any()) }
nordicInterface.close()
}
@ -274,7 +273,7 @@ class NordicBleInterfaceRetryTest {
// Verify onDisconnect was called after retries exhausted
// Nordic BLE wraps RuntimeException in BluetoothException
verify { service.onDisconnect(any<BleError.BluetoothError>()) }
verify { service.onDisconnect(any(), any()) }
nordicInterface.close()
}

View file

@ -40,7 +40,6 @@ import no.nordicsemi.kotlin.ble.core.and
import no.nordicsemi.kotlin.ble.environment.android.mock.MockAndroidEnvironment
import org.junit.Before
import org.junit.Test
import org.meshtastic.core.ble.BleError
import org.meshtastic.core.ble.MeshtasticBleConstants.FROMNUM_CHARACTERISTIC
import org.meshtastic.core.ble.MeshtasticBleConstants.FROMRADIOSYNC_CHARACTERISTIC
import org.meshtastic.core.ble.MeshtasticBleConstants.FROMRADIO_CHARACTERISTIC
@ -400,8 +399,7 @@ class NordicBleInterfaceTest {
advanceUntilIdle()
// Verify onDisconnect was called on the service
// NordicBleInterface calls onDisconnect(BleError.Disconnected)
verify { service.onDisconnect(any<BleError.Disconnected>()) }
verify { service.onDisconnect(any(), any()) }
nordicInterface.close()
}
@ -481,7 +479,7 @@ class NordicBleInterfaceTest {
advanceUntilIdle()
// Verify that discovery failed
verify { service.onDisconnect(any<BleError.DiscoveryFailed>()) }
verify { service.onDisconnect(false, "Required characteristic missing") }
nordicInterface.close()
}
@ -575,7 +573,7 @@ class NordicBleInterfaceTest {
advanceUntilIdle()
// Verify onDisconnect was called with error
verify { service.onDisconnect(any<BleError>()) }
verify { service.onDisconnect(any(), any()) }
nordicInterface.close()
}