From 3db216101aa94d6fe29e65cc14e57a312886773c Mon Sep 17 00:00:00 2001 From: Diego Romar <18450339+doromaraujo@users.noreply.github.com> Date: Fri, 13 Feb 2026 11:11:17 -0300 Subject: [PATCH 1/2] Add lazy connection toggle implementation 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). --- .../client/ui/advanced/AdvancedFragment.java | 22 +++++++++++++++++++ app/src/main/res/layout/fragment_advanced.xml | 13 ++++++++++- app/src/main/res/values/strings.xml | 2 ++ .../netbird/client/tool/EnvVarPackager.java | 2 ++ .../io/netbird/client/tool/Preferences.java | 21 ++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/netbird/client/ui/advanced/AdvancedFragment.java b/app/src/main/java/io/netbird/client/ui/advanced/AdvancedFragment.java index ed060c57..042f7581 100644 --- a/app/src/main/java/io/netbird/client/ui/advanced/AdvancedFragment.java +++ b/app/src/main/java/io/netbird/client/ui/advanced/AdvancedFragment.java @@ -65,6 +65,27 @@ private void configureForceRelayConnectionSwitch(@NonNull ComponentSwitchBinding }); } + private void configureEnableLazyConnectionSwitch(@NonNull ComponentSwitchBinding binding, @NonNull Preferences preferences) { + binding.switchTitle.setText(R.string.advanced_enable_lazy_conn); + binding.switchDescription.setText(R.string.advanced_enable_lazy_conn_desc); + + binding.switchControl.setChecked(preferences.isLazyConnectionEnabled()); + binding.switchControl.setOnCheckedChangeListener((buttonView, isChecked) -> { + if (isChecked) { + preferences.enableLazyConnection(); + } else { + preferences.disableLazyConnection(); + } + + showReconnectionNeededWarningDialog(); + }); + + // Make parent layout clickable to toggle switch (for TV remote) + binding.getRoot().setOnClickListener(v -> { + binding.switchControl.toggle(); + }); + } + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -182,6 +203,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, }); configureForceRelayConnectionSwitch(binding.layoutForceRelayConnection, preferences); + configureEnableLazyConnectionSwitch(binding.layoutEnableLazyConnection, preferences); // Initialize engine config switches (your settings) initializeEngineConfigSwitches(); diff --git a/app/src/main/res/layout/fragment_advanced.xml b/app/src/main/res/layout/fragment_advanced.xml index 9c74605d..83bf10f2 100644 --- a/app/src/main/res/layout/fragment_advanced.xml +++ b/app/src/main/res/layout/fragment_advanced.xml @@ -530,6 +530,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/layout_disable_firewall" /> + + + app:layout_constraintTop_toBottomOf="@id/layout_enable_lazy_connection"> Switched to profile \'%s\' Logged out from profile \'%s\' Profile \'%s\' removed successfully + Enable lazy connection + Enables lazy connection for this peer diff --git a/tool/src/main/java/io/netbird/client/tool/EnvVarPackager.java b/tool/src/main/java/io/netbird/client/tool/EnvVarPackager.java index f6413e99..dce04969 100644 --- a/tool/src/main/java/io/netbird/client/tool/EnvVarPackager.java +++ b/tool/src/main/java/io/netbird/client/tool/EnvVarPackager.java @@ -8,6 +8,8 @@ public static EnvList getEnvironmentVariables(Preferences preferences) { var envList = new EnvList(); envList.put(Android.getEnvKeyNBForceRelay(), String.valueOf(preferences.isConnectionForceRelayed())); + envList.put(Android.getEnvKeyNBLazyConn(), String.valueOf(preferences.isLazyConnectionEnabled())); + envList.put(Android.getEnvKeyNBInactivityThreshold(), String.valueOf(preferences.getInactivityThreshold())); return envList; } diff --git a/tool/src/main/java/io/netbird/client/tool/Preferences.java b/tool/src/main/java/io/netbird/client/tool/Preferences.java index ddf57ca5..fa70bb37 100644 --- a/tool/src/main/java/io/netbird/client/tool/Preferences.java +++ b/tool/src/main/java/io/netbird/client/tool/Preferences.java @@ -8,6 +8,8 @@ public class Preferences { private final String keyTraceLog = "tracelog"; private final String keyForceRelayConnection = "isConnectionForceRelayed"; + private final String keyLazyConnectionEnabled = "isLazyConnectionEnabled"; + private final String keyInactivityThreshold = "inactivityThreshold"; private final SharedPreferences sharedPref; @@ -38,6 +40,25 @@ public void disableForcedRelayConnection() { sharedPref.edit().putBoolean(keyForceRelayConnection, false).apply(); } + public boolean isLazyConnectionEnabled() { + return sharedPref.getBoolean(keyLazyConnectionEnabled, true); + } + + public void enableLazyConnection() { + sharedPref.edit().putBoolean(keyLazyConnectionEnabled, true).apply(); + } + + public void disableLazyConnection() { + sharedPref.edit().putBoolean(keyLazyConnectionEnabled, false).apply(); + } + + // This value represents for how long, in minutes, it will take for a lazy connection to be considered inactive so + // it won't attempt reconnection anymore. Currently, the user cannot change this so it's hardcoded to five minutes + // (its default value in the SDK is 15 minutes, and accepts a minimum of 1 minute). + public int getInactivityThreshold() { + return sharedPref.getInt(keyInactivityThreshold, 5); + } + public static String defaultServer() { return "https://api.netbird.io"; } From ddca255d7635a6749b2a5159d14508b4404be37b Mon Sep 17 00:00:00 2001 From: Diego Romar <18450339+doromaraujo@users.noreply.github.com> Date: Mon, 16 Feb 2026 09:16:05 -0300 Subject: [PATCH 2/2] Update netbird submodule To commit 1024d45698c06fc9c674dfb7132c26c3b4e4fb6e which contains the exported lazy connection variables --- netbird | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbird b/netbird index 67211010..1024d456 160000 --- a/netbird +++ b/netbird @@ -1 +1 @@ -Subproject commit 67211010f7240d53734abd922777c32fccb02754 +Subproject commit 1024d45698c06fc9c674dfb7132c26c3b4e4fb6e