mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: Improve connection state broadcast and timing (#4498)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
4303bfaac4
commit
fad26f1273
7 changed files with 127 additions and 10 deletions
|
|
@ -41,6 +41,8 @@ import org.meshtastic.core.service.ConnectionState
|
|||
import org.meshtastic.core.service.MeshServiceNotifications
|
||||
import org.meshtastic.proto.Config
|
||||
import org.meshtastic.proto.LocalConfig
|
||||
import org.meshtastic.proto.LocalModuleConfig
|
||||
import org.meshtastic.proto.ModuleConfig
|
||||
import org.meshtastic.proto.ToRadio
|
||||
|
||||
class MeshConnectionManagerTest {
|
||||
|
|
@ -61,6 +63,7 @@ class MeshConnectionManagerTest {
|
|||
private val analytics: PlatformAnalytics = mockk(relaxed = true)
|
||||
private val radioConnectionState = MutableStateFlow<ConnectionState>(ConnectionState.Disconnected)
|
||||
private val localConfigFlow = MutableStateFlow(LocalConfig())
|
||||
private val moduleConfigFlow = MutableStateFlow(LocalModuleConfig())
|
||||
|
||||
private val testDispatcher = UnconfinedTestDispatcher()
|
||||
|
||||
|
|
@ -74,6 +77,7 @@ class MeshConnectionManagerTest {
|
|||
|
||||
every { radioInterfaceService.connectionState } returns radioConnectionState
|
||||
every { radioConfigRepository.localConfigFlow } returns localConfigFlow
|
||||
every { radioConfigRepository.moduleConfigFlow } returns moduleConfigFlow
|
||||
every { nodeRepository.myNodeInfo } returns MutableStateFlow<MyNodeEntity?>(null)
|
||||
|
||||
manager =
|
||||
|
|
@ -176,4 +180,27 @@ class MeshConnectionManagerTest {
|
|||
connectionStateHolder.connectionState.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `onRadioConfigLoaded processes queued packets and sets time`() = runTest(testDispatcher) {
|
||||
manager.onRadioConfigLoaded()
|
||||
|
||||
verify { commandSender.processQueuedPackets() }
|
||||
verify { commandSender.sendAdmin(any(), initFn = any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `onNodeDbReady starts MQTT and requests history`() = runTest(testDispatcher) {
|
||||
val moduleConfig = mockk<LocalModuleConfig>(relaxed = true)
|
||||
every { moduleConfig.mqtt } returns ModuleConfig.MQTTConfig(enabled = true)
|
||||
every { moduleConfig.store_forward } returns ModuleConfig.StoreForwardConfig(enabled = true)
|
||||
moduleConfigFlow.value = moduleConfig
|
||||
|
||||
manager.start(backgroundScope)
|
||||
manager.onNodeDbReady()
|
||||
advanceUntilIdle()
|
||||
|
||||
verify { mqttManager.start(any(), true, any()) }
|
||||
verify { historyManager.requestHistoryReplay("onNodeDbReady", any(), any(), "Unknown") }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2025-2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.geeksville.mesh.service
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import io.mockk.mockk
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.meshtastic.core.service.ConnectionState
|
||||
import org.meshtastic.core.service.ServiceRepository
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class MeshServiceBroadcastsTest {
|
||||
|
||||
private lateinit var context: Context
|
||||
private val connectionStateHolder = ConnectionStateHandler()
|
||||
private val serviceRepository: ServiceRepository = mockk(relaxed = true)
|
||||
private lateinit var broadcasts: MeshServiceBroadcasts
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
context = ApplicationProvider.getApplicationContext()
|
||||
broadcasts = MeshServiceBroadcasts(context, connectionStateHolder, serviceRepository)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `broadcastConnection sends uppercase state string for ATAK`() {
|
||||
connectionStateHolder.setState(ConnectionState.Connected)
|
||||
|
||||
broadcasts.broadcastConnection()
|
||||
|
||||
val shadowApp = shadowOf(context as Application)
|
||||
val intent = shadowApp.broadcastIntents.find { it.action == ACTION_MESH_CONNECTED }
|
||||
assertEquals("CONNECTED", intent?.getStringExtra(EXTRA_CONNECTED))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `broadcastConnection sends legacy connection intent`() {
|
||||
connectionStateHolder.setState(ConnectionState.Connected)
|
||||
|
||||
broadcasts.broadcastConnection()
|
||||
|
||||
val shadowApp = shadowOf(context as Application)
|
||||
val intent = shadowApp.broadcastIntents.find { it.action == ACTION_CONNECTION_CHANGED }
|
||||
assertEquals("CONNECTED", intent?.getStringExtra(EXTRA_CONNECTED))
|
||||
assertEquals(true, intent?.getBooleanExtra("connected", false))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue