diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 841a357d..6dbbc5d3 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -85,21 +85,21 @@ class BaresipService: Service() { override fun onAvailable(network: Network) { super.onAvailable(network) Log.i(LOG_TAG, "Network $network is available") - updateNetwork() + updateNetwork(false) } override fun onLost(network: Network) { super.onLost(network) Log.i(LOG_TAG, "Network $network is lost") if (activeNetwork == "$network") - updateNetwork() + updateNetwork(false) } override fun onLinkPropertiesChanged(network: Network, props: LinkProperties) { super.onLinkPropertiesChanged(network, props) Log.i(LOG_TAG, "Network $network link properties changed") if (activeNetwork == "$network") - updateNetwork() + updateNetwork(true) } 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() + updateNetwork(false) } if (!Utils.isVisible()) return @@ -1028,7 +1028,7 @@ class BaresipService: Service() { } } - private fun updateNetwork() { + private fun updateNetwork(change: Boolean) { // Use VPN network if available for (n in cm.allNetworks) { val caps = cm.getNetworkCapabilities(n) ?: continue @@ -1036,6 +1036,8 @@ 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") @@ -1059,6 +1061,8 @@ 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) @@ -1076,6 +1080,8 @@ 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)