Reverted previous commit for better reliability

This commit is contained in:
Juha Heinanen
2020-11-16 10:46:36 +02:00
parent 77f65ed1ba
commit 05a228e85d
3 changed files with 7 additions and 19 deletions
@@ -85,21 +85,21 @@ class BaresipService: Service() {
override fun onAvailable(network: Network) {
super.onAvailable(network)
Log.i(LOG_TAG, "Network $network is available")
updateNetwork(false)
updateNetwork()
}
override fun onLost(network: Network) {
super.onLost(network)
Log.i(LOG_TAG, "Network $network is lost")
if (activeNetwork == "$network")
updateNetwork(false)
updateNetwork()
}
override fun onLinkPropertiesChanged(network: Network, props: LinkProperties) {
super.onLinkPropertiesChanged(network, props)
Log.i(LOG_TAG, "Network $network link properties changed")
if (activeNetwork == "$network")
updateNetwork(true)
updateNetwork()
}
override fun onCapabilitiesChanged(network: Network, caps: NetworkCapabilities) {
@@ -483,7 +483,7 @@ class BaresipService: Service() {
}
if ((ev.size > 1) && (ev[1] == "Software caused connection abort")) {
// Perhaps due to VPN connect/disconnect
updateNetwork(false)
updateNetwork()
}
if (!Utils.isVisible())
return
@@ -1028,7 +1028,7 @@ class BaresipService: Service() {
}
}
private fun updateNetwork(change: Boolean) {
private fun updateNetwork() {
// Use VPN network if available
for (n in cm.allNetworks) {
val caps = cm.getNetworkCapabilities(n) ?: continue
@@ -1036,13 +1036,7 @@ class BaresipService: Service() {
if (isNetworkActive(n) && caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
Log.i(LOG_TAG, "Active VPN network $n is available with caps: " +
"$caps, props: $props")
if (!change && ("$n" == activeNetwork))
return
activeNetwork = "$n"
if (!isConfigInitialized)
Log.i("Baresip", "Config is NOT initialized")
else
Log.i("Baresip", "Config is initialized")
if (isConfigInitialized) {
Utils.updateLinkProperties(props)
} else {
@@ -1061,8 +1055,6 @@ class BaresipService: Service() {
if (isNetworkActive(n) && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
Log.i(LOG_TAG, "Active Internet network $n is available with caps: " +
"$caps, props: $props")
if (!change && ("$n" == activeNetwork))
return
activeNetwork = "$n"
if (isServiceRunning) {
Utils.updateLinkProperties(props)
@@ -1080,8 +1072,6 @@ class BaresipService: Service() {
if (isNetworkActive(n)) {
Log.i(LOG_TAG, "Active network $n is available with caps: " +
"$caps, props: $props")
if (!change && ("$n" == activeNetwork))
return
activeNetwork = "$n"
if (isServiceRunning) {
Utils.updateLinkProperties(props)