Handle default network changes
This commit is contained in:
@@ -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) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user