Skip to content

Add Lazy connection toggle to Advanced settings#171

Open
MichaelUray wants to merge 1 commit intonetbirdio:mainfrom
MichaelUray:feat/lazy-connection-toggle-upstream
Open

Add Lazy connection toggle to Advanced settings#171
MichaelUray wants to merge 1 commit intonetbirdio:mainfrom
MichaelUray:feat/lazy-connection-toggle-upstream

Conversation

@MichaelUray
Copy link
Copy Markdown

@MichaelUray MichaelUray commented Apr 25, 2026

Describe your changes

Adds a "Lazy connection" switch to the Advanced settings fragment (sits between Block inbound connections and Disable client routes). The toggle controls the engine's LazyConnectionEnabled setting via the gomobile Preferences bridge.

  • New layout_lazy_connection block in fragment_advanced.xml; the constraint chain is updated so layout_disable_client_routes is anchored below the new block.
  • New string resources advanced_lazy_connection / advanced_lazy_connection_desc.
  • AdvancedFragment.initializeEngineConfigSwitches() reads the current value via goPreferences.getLazyConnectionEnabled() and writes back via setLazyConnectionEnabled() + commit() on toggle, with a TV-remote layout click handler wired through layout_lazy_connection.toggle().

Default is off, so behavior on existing installs does not change until a user enables it explicitly.

Issue ticket number and link

N/A.

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible) — N/A, UI passthrough.
  • Extended the README / documentation, if necessary

Dependency

This PR consumes two new bridge methods on the gomobile Preferences type:

  • GetLazyConnectionEnabled() (bool, error)
  • SetLazyConnectionEnabled(enabled bool)

Those are added in netbirdio/netbird#5994. This PR's submodule pointer is intentionally not bumped — it should land after #5994 merges, at which point a routine submodule update will pick up the new bridge symbols and this PR will compile.

Testing

Verified end-to-end on a Galaxy S21 (SM-G991B, Android 15) with a local build that includes the bridge change:

  • aapt2 dump resources confirms id/layout_lazy_connection, id/switch_lazy_connection, string/advanced_lazy_connection are baked into the APK.
  • dexdump confirms AdvancedFragment calls Preferences.{get,set}LazyConnectionEnabled.
  • After toggling the switch on and reconnecting, GoLog logcat confirms the engine activates the lazy-connection subsystem:
    • client/internal/lazyconn/manager/manager.go: setup lazy connection service
    • client/internal/lazyconn/inactivity/manager.go: inactivity threshold configured: 15m0s
    • client/internal/conn_mgr.go: peer added to lazy conn manager (per peer)
    • client/internal/lazyconn/activity/listener_udp.go: created activity listener: 127.0.0.1:NNNNN
    • On peer activity: removing activity listeneradding peer to inactivity manager
  • With the toggle off, the same logcat shows: client/internal/conn_mgr.go: lazy connection manager is disabled.

Summary by CodeRabbit

  • New Features
    • Added "Lazy Connection" setting in advanced settings that defers per-peer connection establishment. This feature reduces background resource usage but may introduce slight latency for initial peer connections. Includes TV-remote navigation support for the new setting.

Adds a switch in the Advanced fragment that controls the
LazyConnectionEnabled engine setting. Default is OFF so existing
behavior is preserved; users opt in to per-peer connection on first
traffic for reduced background load.

The toggle wires through the new GetLazyConnectionEnabled /
SetLazyConnectionEnabled methods on the gomobile Preferences bridge.

Tested on a Galaxy S21 (Android 15): toggling the switch persists
LazyConnectionEnabled in the config; on reconnect the engine activates
the lazy connection manager (setup lazy connection service, per-peer
activity listeners on 127.0.0.1:N, 15-minute inactivity threshold) and
peers are wired up on demand instead of eagerly.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b7b56ccd-6cf7-41ba-ad14-701fa02319c2

📥 Commits

Reviewing files that changed from the base of the PR and between 950ab4c and 9ae32bc.

📒 Files selected for processing (3)
  • app/src/main/java/io/netbird/client/ui/advanced/AdvancedFragment.java
  • app/src/main/res/layout/fragment_advanced.xml
  • app/src/main/res/values/strings.xml

📝 Walkthrough

Walkthrough

A new "Lazy Connection" configuration switch is added to the advanced settings UI. The implementation includes Java logic to load and persist the setting, layout XML defining the switch component, and localized string resources for the label and description.

Changes

Cohort / File(s) Summary
Advanced Settings Logic
app/src/main/java/io/netbird/client/ui/advanced/AdvancedFragment.java
Adds initialization, persistence, and TV-remote interaction handling for the "Lazy Connection" switch via getLazyConnectionEnabled() and setLazyConnectionEnabled() methods.
Advanced Settings Layout
app/src/main/res/layout/fragment_advanced.xml
Introduces a new layout_lazy_connection container with a SwitchMaterial control and reorganizes existing layout elements to accommodate the new switch.
String Resources
app/src/main/res/values/strings.xml
Adds localized UI strings for the "Lazy connection" option label and description.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰✨ A lazy hop, a switch so neat,
Connections deferred make apps run sweet,
Less background noise, first packet may wait,
The rabbit approves of this lighter fate!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add Lazy connection toggle to Advanced settings' clearly and concisely describes the main change: introducing a new UI toggle for the lazy connection feature in the advanced settings screen.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant