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 ddf57ca..db1acec 100644 --- a/tool/src/main/java/io/netbird/client/tool/Preferences.java +++ b/tool/src/main/java/io/netbird/client/tool/Preferences.java @@ -27,7 +27,7 @@ public void disableTraceLog() { } public boolean isConnectionForceRelayed() { - return sharedPref.getBoolean(keyForceRelayConnection, true); + return sharedPref.getBoolean(keyForceRelayConnection, false); } public void enableForcedRelayConnection() { diff --git a/tool/src/main/java/io/netbird/client/tool/networks/ConcreteNetworkAvailabilityListener.java b/tool/src/main/java/io/netbird/client/tool/networks/ConcreteNetworkAvailabilityListener.java index 8c8cdbc..e15cdd3 100644 --- a/tool/src/main/java/io/netbird/client/tool/networks/ConcreteNetworkAvailabilityListener.java +++ b/tool/src/main/java/io/netbird/client/tool/networks/ConcreteNetworkAvailabilityListener.java @@ -13,26 +13,27 @@ public ConcreteNetworkAvailabilityListener() { @Override public void onNetworkAvailable(@Constants.NetworkType int networkType) { - boolean isWifiAvailable = Boolean.TRUE.equals(availableNetworkTypes.get(Constants.NetworkType.WIFI)); + boolean hadNetwork = !availableNetworkTypes.isEmpty(); + boolean hadSameType = Boolean.TRUE.equals(availableNetworkTypes.get(networkType)); availableNetworkTypes.put(networkType, true); - // if wifi is available and wasn't before, notifies listener. - // Android prioritizes wifi over mobile data network by default. - if (!isWifiAvailable && networkType == Constants.NetworkType.WIFI) { + // Notify on any network type change: + // - new WiFi connection (Mobile → WiFi switch) + // - new Mobile connection when WiFi was lost (WiFi → Mobile switch) + // - first network connection + if (!hadSameType) { notifyListener(); } } @Override public void onNetworkLost(@Constants.NetworkType int networkType) { - boolean isMobileAvailable = Boolean.TRUE.equals(availableNetworkTypes.get(Constants.NetworkType.MOBILE)); + boolean wasPresent = availableNetworkTypes.remove(networkType) != null; - availableNetworkTypes.remove(networkType); - - // if wifi is lost and mobile data is available, notifies listener. - // No use to notify it if there's no other type of network available. - if (isMobileAvailable && networkType == Constants.NetworkType.WIFI) { + // Notify when a tracked network is lost and another type is still available. + // Guards against duplicate/out-of-order onLost callbacks. + if (wasPresent && !availableNetworkTypes.isEmpty()) { notifyListener(); } }