Skip to content

feat: Improve connection state broadcast and timing#4498

Merged
jamesarich merged 3 commits into
mainfrom
fix/connection-broadcasts
Feb 7, 2026
Merged

feat: Improve connection state broadcast and timing#4498
jamesarich merged 3 commits into
mainfrom
fix/connection-broadcasts

Conversation

@jamesarich

@jamesarich jamesarich commented Feb 7, 2026

Copy link
Copy Markdown
Collaborator

This pull request introduces several improvements to connection state handling and broadcasting, adds new tests, and updates dependencies to support enhanced testing. The main changes include refactoring connection state management and broadcasts for better compatibility, updating method responsibilities, and increasing test coverage for these behaviors.

Connection State Handling and Broadcasting:

  • Added a new broadcast action, ACTION_CONNECTION_CHANGED, to Constants.kt for legacy compatibility and updated broadcastConnection in MeshServiceBroadcasts to send both the new and legacy intents with uppercase state strings for better integration with consumers like ATAK and older clients. [1] [2]
  • Modified broadcastConnection to ensure the connection state string is always uppercase and to include both the new and legacy broadcast formats, including a boolean extra for legacy consumers.

Connection Manager Refactoring:

  • Refactored MeshConfigFlowManager and MeshConnectionManager to separate responsibilities: moved setting the connection state and broadcasting out of node DB readiness and into radio config loading, and split the onHasSettings method into onRadioConfigLoaded and onNodeDbReady for clearer lifecycle management. [1] [2] [3] [4]

Testing Enhancements:

  • Added a new test suite MeshServiceBroadcastsTest.kt using Robolectric to verify correct broadcast behavior for connection state changes, including both new and legacy intent formats.
  • Expanded MeshConnectionManagerTest to cover the new onRadioConfigLoaded and onNodeDbReady behaviors, and updated test setup to mock new flows. [1] [2] [3] [4]

Dependency Updates:

  • Added robolectric and androidx.test.core to the test dependencies in build.gradle.kts to support the new and updated tests.

Copilot AI review requested due to automatic review settings February 7, 2026 18:06
@github-actions github-actions Bot added the bugfix PR tag label Feb 7, 2026
This commit refactors the connection state broadcasting logic.

- A new `ACTION_CONNECTION_CHANGED` broadcast is introduced for legacy consumers.
- The existing `ACTION_MESH_CONNECTED` broadcast now sends the connection state as an uppercase string for improved compatibility (e.g., with ATAK).
- The `Connected` state is now set and broadcasted immediately after `myNodeInfo` is successfully committed, rather than waiting for the full node DB update. This provides a more accurate and timely reflection of the connection status.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@jamesarich jamesarich force-pushed the fix/connection-broadcasts branch from 316d869 to 650f5ba Compare February 7, 2026 18:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors mesh connection state signaling from the Android service to improve broadcast compatibility (e.g., ATAK) and to reflect “Connected” sooner in the config flow.

Changes:

  • Broadcast connection state as an uppercase string on ACTION_MESH_CONNECTED and reintroduce a legacy ACTION_CONNECTION_CHANGED broadcast for older consumers.
  • Move the “Connected” state transition + broadcast to immediately after myNodeInfo commit (instead of waiting for the full node DB update).
  • Add the new broadcast action constant.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
app/src/main/java/com/geeksville/mesh/service/MeshServiceBroadcasts.kt Uppercases connection state extra; adds legacy ACTION_CONNECTION_CHANGED broadcast and legacy boolean extra.
app/src/main/java/com/geeksville/mesh/service/MeshConfigFlowManager.kt Sets/broadcasts Connected earlier in the config-only completion path; reorders downstream hooks.
app/src/main/java/com/geeksville/mesh/service/Constants.kt Introduces ACTION_CONNECTION_CHANGED constant.

Comment thread app/src/main/java/com/geeksville/mesh/service/MeshConfigFlowManager.kt Outdated
Comment thread app/src/main/java/com/geeksville/mesh/service/MeshConfigFlowManager.kt Outdated
@codecov

codecov Bot commented Feb 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 10.89%. Comparing base (6ec2ed7) to head (56f2e73).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...m/geeksville/mesh/service/MeshConfigFlowManager.kt 0.00% 4 Missing ⚠️
...m/geeksville/mesh/service/MeshConnectionManager.kt 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4498      +/-   ##
==========================================
+ Coverage   10.64%   10.89%   +0.25%     
==========================================
  Files         427      427              
  Lines       14387    14395       +8     
  Branches     2387     2388       +1     
==========================================
+ Hits         1531     1568      +37     
+ Misses      12561    12526      -35     
- Partials      295      301       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This commit refactors the connection logic to better separate the "radio config loaded" and "node database ready" states.

Key changes:
- Introduces `onRadioConfigLoaded()` to handle actions that only require the radio configuration, such as setting the time on the device and processing the initial packet queue.
- Introduces `onNodeDbReady()` to handle actions that depend on the node database being initialized, such as starting MQTT and requesting message history.
- The previous `onHasSettings()` method is removed and its logic is split between the two new, more specific functions.
- Fixes a lint warning by explicitly using `Locale.ROOT` for an `uppercase()` string conversion.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
…erviceBroadcasts

Adds and improves unit tests for core service components.

- Implements Robolectric tests for `MeshServiceBroadcasts` to verify that connection state change intents are correctly broadcast for ATAK and legacy consumers.
- Adds test coverage for `MeshConnectionManager` to ensure queued packets are processed and time is set after radio config is loaded.
- Verifies that `MeshConnectionManager` correctly starts MQTT and requests message history when the node database is ready.
- Includes `Robolectric` and `androidx.test.core` as test dependencies.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@jamesarich jamesarich added this pull request to the merge queue Feb 7, 2026
Merged via the queue into main with commit fad26f1 Feb 7, 2026
9 checks passed
@jamesarich jamesarich deleted the fix/connection-broadcasts branch February 7, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants