Fix inconsistent behavior in onLost

This commit is contained in:
Mygod
2018-12-14 00:46:46 +08:00
parent 50925935e6
commit c3cb26ce35

View File

@@ -71,15 +71,13 @@ object VpnMonitor : UpstreamMonitor() {
override fun onLost(network: Network) = synchronized(this@VpnMonitor) {
if (available.remove(network) == null || currentNetwork != network) return
callbacks.forEach { it.onLost() }
if (available.isNotEmpty()) {
val next = available.entries.first()
currentNetwork = next.key
debugLog(TAG, "Switching to ${next.value.interfaceName} as VPN interface")
callbacks.forEach { it.onAvailable(next.value.interfaceName!!, next.value.dnsServers) }
} else {
callbacks.forEach { it.onLost() }
currentNetwork = null
}
} else currentNetwork = null
}
}