Skip to content

Add lazy connection toggle#140

Open
doromaraujo wants to merge 2 commits intomainfrom
feature/add-lazy-connection-toggle
Open

Add lazy connection toggle#140
doromaraujo wants to merge 2 commits intomainfrom
feature/add-lazy-connection-toggle

Conversation

@doromaraujo
Copy link
Contributor

@doromaraujo doromaraujo commented Feb 16, 2026

This PR adds a toggle in advanced settings for enabling lazy connection on the Android peer.

Summary by CodeRabbit

  • New Features
    • Added lazy connection toggle in Advanced settings for enhanced network management
    • Introduced inactivity threshold configuration option with 5-minute default
    • Reconnection warning displays when modifying these advanced settings
    • New preferences are automatically saved and synced

This propagates a value stored in UserPreference
similar to how Force Relay is implemented,
with true (enabled) as the default value,
exporting it to when engine starts and the VPN
connects under the
NB_ENABLE_EXPERIMENTAL_LAZY_CONN environment
variable.

It also adds a hardcoded value for the
NB_LAZY_CONN_INACTIVITY_THRESHOLD, 5 minutes
(instead of the SDK's default 15).
To commit 1024d45698c06fc9c674dfb7132c26c3b4e4fb6e
which contains the exported lazy connection
variables
@doromaraujo doromaraujo requested review from Copilot and pappz and removed request for Copilot February 16, 2026 12:18
@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

The PR introduces lazy connection functionality to the Netbird Android client by adding a new advanced preference setting that allows users to enable/disable lazy connection mode via a UI switch, with persistent storage and environment variable exposure.

Changes

Cohort / File(s) Summary
UI Layer
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
Added new lazy connection switch UI component with preference binding, reconnection warning dialog, and TV remote click support. Positioned between force relay and theme settings in the advanced options layout with localized string resources.
Preferences Storage
tool/src/main/java/io/netbird/client/tool/Preferences.java
Introduced lazy connection preference key and public API: isLazyConnectionEnabled(), enableLazyConnection(), disableLazyConnection(). Also added getInactivityThreshold() with 5-minute default.
Environment Packaging
tool/src/main/java/io/netbird/client/tool/EnvVarPackager.java
Mapped lazy connection and inactivity threshold preferences to environment variables Android.getEnvKeyNBLazyConn and Android.getEnvKeyNBInactivityThreshold for exposure to the native layer.
Dependencies
netbird
Updated submodule pointer to new commit hash.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • mlsmaycon

Poem

🐰 A lazy hop through the code we go,
New switches flip with preference's flow,
Inactivity timers and thresholds align,
Environment variables—oh how they shine!
Netbird hops faster when lazy's designed! 🌙✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 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' accurately and concisely summarizes the main change: adding a UI toggle to enable/disable lazy connections in advanced settings.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/add-lazy-connection-toggle

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
app/src/main/res/values/strings.xml (1)

144-145: Description string could be more informative for the user.

"Enables lazy connection for this peer" doesn't explain what lazy connection actually does. Other descriptions in this file explain the effect (e.g., "Forces usage of relay when connecting to peers"). Consider something like "Delays peer connections until traffic is detected, reducing resource usage" or similar to help users make an informed choice.

app/src/main/java/io/netbird/client/ui/advanced/AdvancedFragment.java (1)

47-87: Consider extracting a shared helper for switch configuration.

configureForceRelayConnectionSwitch and configureEnableLazyConnectionSwitch are structurally identical — they differ only in string resource IDs and preference enable/disable methods. If more switches follow this pattern, a generic helper taking those as parameters would reduce duplication.

♻️ Example generic helper
private void configureSwitch(
        `@NonNull` ComponentSwitchBinding binding,
        int titleResId,
        int descResId,
        boolean initialState,
        Runnable onEnable,
        Runnable onDisable) {
    binding.switchTitle.setText(titleResId);
    binding.switchDescription.setText(descResId);
    binding.switchControl.setChecked(initialState);
    binding.switchControl.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (isChecked) onEnable.run(); else onDisable.run();
        showReconnectionNeededWarningDialog();
    });
    binding.getRoot().setOnClickListener(v -> binding.switchControl.toggle());
}
tool/src/main/java/io/netbird/client/tool/Preferences.java (1)

55-60: Nit: the getInactivityThreshold() return type should be documented in the method contract.

The comment explains the value semantics (minutes, min 1, SDK default 15), but the method itself has no Javadoc. Since this value is passed through to the engine via environment variable, consider adding a brief @return annotation noting the unit is minutes.

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