Handle default network changes

This commit is contained in:
Mygod
2018-10-03 13:57:39 +08:00
parent 408c84f8d7
commit f7978a5a2f

View File

@@ -24,14 +24,15 @@ object DefaultNetworkMonitor : UpstreamMonitor() {
val properties = app.connectivity.getLinkProperties(network) val properties = app.connectivity.getLinkProperties(network)
val ifname = properties?.interfaceName ?: return val ifname = properties?.interfaceName ?: return
when (currentNetwork) { when (currentNetwork) {
null -> currentNetwork = network null -> { }
network -> { network -> {
val oldProperties = currentLinkProperties!! val oldProperties = currentLinkProperties!!
check(ifname == oldProperties.interfaceName) check(ifname == oldProperties.interfaceName)
if (properties.dnsServers == oldProperties.dnsServers) return if (properties.dnsServers == oldProperties.dnsServers) return
} }
else -> check(false) else -> callbacks.forEach { it.onLost() } // we are using the other default network now
} }
currentNetwork = network
currentLinkProperties = properties currentLinkProperties = properties
callbacks.forEach { it.onAvailable(ifname, properties.dnsServers) } callbacks.forEach { it.onAvailable(ifname, properties.dnsServers) }
} }