Refine onAvailable handling
Do not assume interfaceName unchanging.
This commit is contained in:
@@ -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
|
||||
}
|
||||
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) }
|
||||
}
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user