Update link properties only when there is change
This commit is contained in:
@@ -85,21 +85,21 @@ class BaresipService: Service() {
|
|||||||
override fun onAvailable(network: Network) {
|
override fun onAvailable(network: Network) {
|
||||||
super.onAvailable(network)
|
super.onAvailable(network)
|
||||||
Log.i(LOG_TAG, "Network $network is available")
|
Log.i(LOG_TAG, "Network $network is available")
|
||||||
updateNetwork()
|
updateNetwork(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
override fun onLost(network: Network) {
|
||||||
super.onLost(network)
|
super.onLost(network)
|
||||||
Log.i(LOG_TAG, "Network $network is lost")
|
Log.i(LOG_TAG, "Network $network is lost")
|
||||||
if (activeNetwork == "$network")
|
if (activeNetwork == "$network")
|
||||||
updateNetwork()
|
updateNetwork(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLinkPropertiesChanged(network: Network, props: LinkProperties) {
|
override fun onLinkPropertiesChanged(network: Network, props: LinkProperties) {
|
||||||
super.onLinkPropertiesChanged(network, props)
|
super.onLinkPropertiesChanged(network, props)
|
||||||
Log.i(LOG_TAG, "Network $network link properties changed")
|
Log.i(LOG_TAG, "Network $network link properties changed")
|
||||||
if (activeNetwork == "$network")
|
if (activeNetwork == "$network")
|
||||||
updateNetwork()
|
updateNetwork(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCapabilitiesChanged(network: Network, caps: NetworkCapabilities) {
|
override fun onCapabilitiesChanged(network: Network, caps: NetworkCapabilities) {
|
||||||
@@ -483,7 +483,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
if ((ev.size > 1) && (ev[1] == "Software caused connection abort")) {
|
if ((ev.size > 1) && (ev[1] == "Software caused connection abort")) {
|
||||||
// Perhaps due to VPN connect/disconnect
|
// Perhaps due to VPN connect/disconnect
|
||||||
updateNetwork()
|
updateNetwork(false)
|
||||||
}
|
}
|
||||||
if (!Utils.isVisible())
|
if (!Utils.isVisible())
|
||||||
return
|
return
|
||||||
@@ -1028,7 +1028,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateNetwork() {
|
private fun updateNetwork(change: Boolean) {
|
||||||
// Use VPN network if available
|
// Use VPN network if available
|
||||||
for (n in cm.allNetworks) {
|
for (n in cm.allNetworks) {
|
||||||
val caps = cm.getNetworkCapabilities(n) ?: continue
|
val caps = cm.getNetworkCapabilities(n) ?: continue
|
||||||
@@ -1036,6 +1036,8 @@ class BaresipService: Service() {
|
|||||||
if (isNetworkActive(n) && caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
|
if (isNetworkActive(n) && caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
|
||||||
Log.i(LOG_TAG, "Active VPN network $n is available with caps: " +
|
Log.i(LOG_TAG, "Active VPN network $n is available with caps: " +
|
||||||
"$caps, props: $props")
|
"$caps, props: $props")
|
||||||
|
if (!change && ("$n" == activeNetwork))
|
||||||
|
return
|
||||||
activeNetwork = "$n"
|
activeNetwork = "$n"
|
||||||
if (!isConfigInitialized)
|
if (!isConfigInitialized)
|
||||||
Log.i("Baresip", "Config is NOT initialized")
|
Log.i("Baresip", "Config is NOT initialized")
|
||||||
@@ -1059,6 +1061,8 @@ class BaresipService: Service() {
|
|||||||
if (isNetworkActive(n) && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
|
if (isNetworkActive(n) && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
|
||||||
Log.i(LOG_TAG, "Active Internet network $n is available with caps: " +
|
Log.i(LOG_TAG, "Active Internet network $n is available with caps: " +
|
||||||
"$caps, props: $props")
|
"$caps, props: $props")
|
||||||
|
if (!change && ("$n" == activeNetwork))
|
||||||
|
return
|
||||||
activeNetwork = "$n"
|
activeNetwork = "$n"
|
||||||
if (isServiceRunning) {
|
if (isServiceRunning) {
|
||||||
Utils.updateLinkProperties(props)
|
Utils.updateLinkProperties(props)
|
||||||
@@ -1076,6 +1080,8 @@ class BaresipService: Service() {
|
|||||||
if (isNetworkActive(n)) {
|
if (isNetworkActive(n)) {
|
||||||
Log.i(LOG_TAG, "Active network $n is available with caps: " +
|
Log.i(LOG_TAG, "Active network $n is available with caps: " +
|
||||||
"$caps, props: $props")
|
"$caps, props: $props")
|
||||||
|
if (!change && ("$n" == activeNetwork))
|
||||||
|
return
|
||||||
activeNetwork = "$n"
|
activeNetwork = "$n"
|
||||||
if (isServiceRunning) {
|
if (isServiceRunning) {
|
||||||
Utils.updateLinkProperties(props)
|
Utils.updateLinkProperties(props)
|
||||||
|
|||||||
Reference in New Issue
Block a user