diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt index 5376ec62..94559f25 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt @@ -24,16 +24,11 @@ object DefaultNetworkMonitor : UpstreamMonitor() { val properties = app.connectivity.getLinkProperties(network) val ifname = properties?.interfaceName ?: return synchronized(this@DefaultNetworkMonitor) { - when (currentNetwork) { - null -> { } - network -> { - val oldProperties = currentLinkProperties!! - check(ifname == oldProperties.interfaceName) - if (properties.dnsServers == oldProperties.dnsServers) return - } - else -> callbacks.forEach { it.onLost() } // we are using the other default network now - } - currentNetwork = network + val oldProperties = currentLinkProperties + if (currentNetwork != network || ifname != oldProperties?.interfaceName) { + callbacks.forEach { it.onLost() } // we are using the other default network now + currentNetwork = network + } else if (properties.dnsServers == oldProperties.dnsServers) return currentLinkProperties = properties callbacks.forEach { it.onAvailable(ifname, properties.dnsServers) } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/VpnMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/VpnMonitor.kt index 7ec97432..dcefa5ad 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/VpnMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/VpnMonitor.kt @@ -25,18 +25,11 @@ object VpnMonitor : UpstreamMonitor() { val properties = app.connectivity.getLinkProperties(network) val ifname = properties?.interfaceName ?: return synchronized(this@VpnMonitor) { - val old = currentNetwork val oldProperties = available.put(network, properties) - if (old != network) { - if (old != null) { - DebugHelper.log(TAG, "Assuming old VPN interface ${available[old]} is dying") - callbacks.forEach { it.onLost() } - } + if (currentNetwork != network || ifname != oldProperties?.interfaceName) { + if (currentNetwork != null) callbacks.forEach { it.onLost() } currentNetwork = network - } else { - check(ifname == oldProperties!!.interfaceName) - if (properties.dnsServers == oldProperties.dnsServers) return - } + } else if (properties.dnsServers == oldProperties.dnsServers) return callbacks.forEach { it.onAvailable(ifname, properties.dnsServers) } } }