Conversation
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
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 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.
configureForceRelayConnectionSwitchandconfigureEnableLazyConnectionSwitchare 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: thegetInactivityThreshold()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
@returnannotation noting the unit is minutes.
This PR adds a toggle in advanced settings for enabling lazy connection on the Android peer.
Summary by CodeRabbit