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 properties = app.connectivity.getLinkProperties(network)
|
||||||
val ifname = properties?.interfaceName ?: return
|
val ifname = properties?.interfaceName ?: return
|
||||||
synchronized(this@DefaultNetworkMonitor) {
|
synchronized(this@DefaultNetworkMonitor) {
|
||||||
when (currentNetwork) {
|
val oldProperties = currentLinkProperties
|
||||||
null -> { }
|
if (currentNetwork != network || ifname != oldProperties?.interfaceName) {
|
||||||
network -> {
|
callbacks.forEach { it.onLost() } // we are using the other default network now
|
||||||
val oldProperties = currentLinkProperties!!
|
currentNetwork = network
|
||||||
check(ifname == oldProperties.interfaceName)
|
} else if (properties.dnsServers == oldProperties.dnsServers) return
|
||||||
if (properties.dnsServers == oldProperties.dnsServers) return
|
|
||||||
}
|
|
||||||
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) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,18 +25,11 @@ object VpnMonitor : UpstreamMonitor() {
|
|||||||
val properties = app.connectivity.getLinkProperties(network)
|
val properties = app.connectivity.getLinkProperties(network)
|
||||||
val ifname = properties?.interfaceName ?: return
|
val ifname = properties?.interfaceName ?: return
|
||||||
synchronized(this@VpnMonitor) {
|
synchronized(this@VpnMonitor) {
|
||||||
val old = currentNetwork
|
|
||||||
val oldProperties = available.put(network, properties)
|
val oldProperties = available.put(network, properties)
|
||||||
if (old != network) {
|
if (currentNetwork != network || ifname != oldProperties?.interfaceName) {
|
||||||
if (old != null) {
|
if (currentNetwork != null) callbacks.forEach { it.onLost() }
|
||||||
DebugHelper.log(TAG, "Assuming old VPN interface ${available[old]} is dying")
|
|
||||||
callbacks.forEach { it.onLost() }
|
|
||||||
}
|
|
||||||
currentNetwork = network
|
currentNetwork = network
|
||||||
} else {
|
} else if (properties.dnsServers == oldProperties.dnsServers) return
|
||||||
check(ifname == oldProperties!!.interfaceName)
|
|
||||||
if (properties.dnsServers == oldProperties.dnsServers) return
|
|
||||||
}
|
|
||||||
callbacks.forEach { it.onAvailable(ifname, properties.dnsServers) }
|
callbacks.forEach { it.onAvailable(ifname, properties.dnsServers) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user