refactor(service): unify dual connectionState flows into single source of truth (#5077)

This commit is contained in:
James Rich 2026-04-11 19:50:52 -05:00 committed by GitHub
parent 5e44cbd3a9
commit 9468bc6ebe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 103 additions and 8 deletions

View file

@ -98,6 +98,9 @@ class MeshConnectionManagerImpl(
private var connectionRestored = false
init {
// Bridge transport-level state into the canonical app-level state.
// This is the ONLY consumer of RadioInterfaceService.connectionState — it applies
// light-sleep policy and handshake awareness before writing to ServiceRepository.
radioInterfaceService.connectionState.onEach(::onRadioConnectionState).launchIn(scope)
// Ensure notification title and content stay in sync with state changes
@ -131,6 +134,13 @@ class MeshConnectionManagerImpl(
.launchIn(scope)
}
/**
* Bridges a transport-level [ConnectionState] into the canonical app-level state.
*
* Applies light-sleep policy (power-saving / router role) to decide whether a [ConnectionState.DeviceSleep] event
* should be surfaced as sleep or as a full disconnect, then delegates to [onConnectionChanged] for the actual state
* transition.
*/
private suspend fun onRadioConnectionState(newState: ConnectionState) {
val localConfig = radioConfigRepository.localConfigFlow.first()
val isRouter = localConfig.device?.role == Config.DeviceConfig.Role.ROUTER