Network update improvements
This commit is contained in:
@@ -120,11 +120,12 @@ class BaresipService: Service() {
|
|||||||
override fun onAvailable(network: Network) {
|
override fun onAvailable(network: Network) {
|
||||||
super.onAvailable(network)
|
super.onAvailable(network)
|
||||||
Log.d(TAG, "Network $network is available")
|
Log.d(TAG, "Network $network is available")
|
||||||
if (network !in allNetworks)
|
|
||||||
allNetworks.add(network)
|
|
||||||
// If API >= 26, this will be followed by onCapabilitiesChanged
|
// If API >= 26, this will be followed by onCapabilitiesChanged
|
||||||
if (isServiceRunning && VERSION.SDK_INT < 26)
|
if (isServiceRunning && VERSION.SDK_INT < 26) {
|
||||||
|
if (network !in allNetworks)
|
||||||
|
allNetworks.add(network)
|
||||||
updateNetwork()
|
updateNetwork()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLosing(network: Network, maxMsToLive: Int) {
|
override fun onLosing(network: Network, maxMsToLive: Int) {
|
||||||
@@ -135,24 +136,31 @@ class BaresipService: Service() {
|
|||||||
override fun onLost(network: Network) {
|
override fun onLost(network: Network) {
|
||||||
super.onLost(network)
|
super.onLost(network)
|
||||||
Log.d(TAG, "Network $network is lost")
|
Log.d(TAG, "Network $network is lost")
|
||||||
if (network in allNetworks)
|
if (isServiceRunning) {
|
||||||
allNetworks.remove(network)
|
if (network in allNetworks)
|
||||||
if (isServiceRunning)
|
allNetworks.remove(network)
|
||||||
updateNetwork()
|
updateNetwork()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCapabilitiesChanged(network: Network, caps: NetworkCapabilities) {
|
override fun onCapabilitiesChanged(network: Network, caps: NetworkCapabilities) {
|
||||||
super.onCapabilitiesChanged(network, caps)
|
super.onCapabilitiesChanged(network, caps)
|
||||||
Log.d(TAG, "Network $network capabilities changed: $caps")
|
Log.d(TAG, "Network $network capabilities changed: $caps")
|
||||||
if (isServiceRunning)
|
if (isServiceRunning) {
|
||||||
|
if (network !in allNetworks)
|
||||||
|
allNetworks.add(network)
|
||||||
updateNetwork()
|
updateNetwork()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLinkPropertiesChanged(network: Network, props: LinkProperties) {
|
override fun onLinkPropertiesChanged(network: Network, props: LinkProperties) {
|
||||||
super.onLinkPropertiesChanged(network, props)
|
super.onLinkPropertiesChanged(network, props)
|
||||||
Log.d(TAG, "Network $network link properties changed: $props")
|
Log.d(TAG, "Network $network link properties changed: $props")
|
||||||
if (isServiceRunning)
|
if (isServiceRunning) {
|
||||||
|
if (network !in allNetworks)
|
||||||
|
allNetworks.add(network)
|
||||||
updateNetwork()
|
updateNetwork()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1249,12 +1257,9 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
private fun updateNetwork() {
|
private fun updateNetwork() {
|
||||||
|
|
||||||
if (!isServiceRunning)
|
/* for (n in allNetworks)
|
||||||
return
|
|
||||||
|
|
||||||
for (n in allNetworks)
|
|
||||||
Log.d(TAG, "NETWORK $n with caps ${cm.getNetworkCapabilities(n)} and props " +
|
Log.d(TAG, "NETWORK $n with caps ${cm.getNetworkCapabilities(n)} and props " +
|
||||||
"${cm.getLinkProperties(n)} is active ${isNetworkActive(n)}")
|
"${cm.getLinkProperties(n)} is active ${isNetworkActive(n)}") */
|
||||||
|
|
||||||
updateDnsServers()
|
updateDnsServers()
|
||||||
|
|
||||||
@@ -1329,14 +1334,12 @@ class BaresipService: Service() {
|
|||||||
return
|
return
|
||||||
val servers = mutableListOf<InetAddress>()
|
val servers = mutableListOf<InetAddress>()
|
||||||
// Use DNS servers first from active network (if available)
|
// Use DNS servers first from active network (if available)
|
||||||
for (n in allNetworks)
|
val activeNetwork = activeNetwork()
|
||||||
if (isNetworkActive(n)) {
|
if (activeNetwork != null) {
|
||||||
val linkProps = cm.getLinkProperties(n)
|
val linkProps = cm.getLinkProperties(activeNetwork)
|
||||||
if (linkProps != null) {
|
if (linkProps != null)
|
||||||
servers.addAll(linkProps.dnsServers)
|
servers.addAll(linkProps.dnsServers)
|
||||||
break
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
// Then add DNS servers from the other networks
|
// Then add DNS servers from the other networks
|
||||||
for (n in allNetworks) {
|
for (n in allNetworks) {
|
||||||
if (isNetworkActive(n)) continue
|
if (isNetworkActive(n)) continue
|
||||||
|
|||||||
Reference in New Issue
Block a user