From 9ae32bc56b02f7141b5f0de7dabf16cf81f54263 Mon Sep 17 00:00:00 2001 From: Michael Uray <25169478+MichaelUray@users.noreply.github.com> Date: Sat, 25 Apr 2026 22:30:37 +0000 Subject: [PATCH] Add Lazy connection toggle to Advanced settings 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. --- .../client/ui/advanced/AdvancedFragment.java | 18 ++++++- app/src/main/res/layout/fragment_advanced.xml | 51 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 + 3 files changed, 68 insertions(+), 3 deletions(-) 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 3f1e2a7c..ba968d38 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 @@ -197,6 +197,7 @@ private void initializeEngineConfigSwitches() { binding.switchDisableFirewall.setChecked(goPreferences.getDisableFirewall()); binding.switchAllowSsh.setChecked(goPreferences.getServerSSHAllowed()); binding.switchBlockInbound.setChecked(goPreferences.getBlockInbound()); + binding.switchLazyConnection.setChecked(goPreferences.getLazyConnectionEnabled()); // Set up change listeners binding.switchDisableClientRoutes.setOnCheckedChangeListener((buttonView, isChecked) -> { @@ -252,15 +253,28 @@ private void initializeEngineConfigSwitches() { Log.e(LOGTAG, "Failed to set block inbound", e); } }); - + + binding.switchLazyConnection.setOnCheckedChangeListener((buttonView, isChecked) -> { + try { + goPreferences.setLazyConnectionEnabled(isChecked); + goPreferences.commit(); + } catch (Exception e) { + Log.e(LOGTAG, "Failed to set lazy connection", e); + } + }); + // Make parent layouts clickable to toggle switches (for TV remote) binding.layoutAllowSsh.setOnClickListener(v -> { binding.switchAllowSsh.toggle(); }); - + binding.layoutBlockInbound.setOnClickListener(v -> { binding.switchBlockInbound.toggle(); }); + + binding.layoutLazyConnection.setOnClickListener(v -> { + binding.switchLazyConnection.toggle(); + }); binding.layoutDisableClientRoutes.setOnClickListener(v -> { binding.switchDisableClientRoutes.toggle(); diff --git a/app/src/main/res/layout/fragment_advanced.xml b/app/src/main/res/layout/fragment_advanced.xml index ad46aea4..082f918e 100644 --- a/app/src/main/res/layout/fragment_advanced.xml +++ b/app/src/main/res/layout/fragment_advanced.xml @@ -268,7 +268,7 @@ + + + + + + + + + + + + + + Allows SSH connections to this device Block inbound connections Blocks all inbound connections to this device and routed networks. This overrides any policies received from the management service + Lazy connection + Defer per-peer connection setup until first actual traffic. Reduces background load but adds latency to the first packet to a peer NetBird logo