- Do not believe if lost network becomes immediately available again.
This commit is contained in:
@@ -50,6 +50,7 @@ class BaresipService: Service() {
|
|||||||
internal var audioFocused = false
|
internal var audioFocused = false
|
||||||
internal var origCallVolume = -1
|
internal var origCallVolume = -1
|
||||||
internal val btAdapter = BluetoothAdapter.getDefaultAdapter()
|
internal val btAdapter = BluetoothAdapter.getDefaultAdapter()
|
||||||
|
internal var activeNetwork: Network? = null
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
|
|
||||||
@@ -81,17 +82,27 @@ class BaresipService: Service() {
|
|||||||
super.onAvailable(network)
|
super.onAvailable(network)
|
||||||
val linkProperties = cm.getLinkProperties(network)
|
val linkProperties = cm.getLinkProperties(network)
|
||||||
Log.i(LOG_TAG, "Network $network is available: '$linkProperties'")
|
Log.i(LOG_TAG, "Network $network is available: '$linkProperties'")
|
||||||
|
if (activeNetwork == null) {
|
||||||
|
Log.i(LOG_TAG, "Updating dnsServers and linkAddresses")
|
||||||
|
activeNetwork = network
|
||||||
dnsServers = linkProperties.dnsServers
|
dnsServers = linkProperties.dnsServers
|
||||||
linkAddresses = linkProperties.linkAddresses
|
linkAddresses = linkProperties.linkAddresses
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
override fun onLost(network: Network) {
|
||||||
super.onLost(network)
|
super.onLost(network)
|
||||||
Log.d(LOG_TAG, "Network '$network' is lost")
|
if (activeNetwork == network) {
|
||||||
val allNetworks = cm.allNetworks
|
Log.d(LOG_TAG, "Active network '$network' is lost")
|
||||||
if (allNetworks.size > 0) {
|
activeNetwork = null
|
||||||
Log.d(LOG_TAG, "Network ${allNetworks[0]} is available")
|
for (net in cm.allNetworks)
|
||||||
val linkProperties = cm.getLinkProperties(allNetworks[0])
|
if (net != network) {
|
||||||
|
Log.d(LOG_TAG, "New network $net is available")
|
||||||
|
activeNetwork = net
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (activeNetwork != null) {
|
||||||
|
val linkProperties = cm.getLinkProperties(activeNetwork)
|
||||||
if (dynDns) {
|
if (dynDns) {
|
||||||
dnsServers = linkProperties.dnsServers
|
dnsServers = linkProperties.dnsServers
|
||||||
if (Config.updateDnsServers(dnsServers) != 0)
|
if (Config.updateDnsServers(dnsServers) != 0)
|
||||||
@@ -101,13 +112,18 @@ class BaresipService: Service() {
|
|||||||
Utils.updateLinkAddresses()
|
Utils.updateLinkAddresses()
|
||||||
UserAgent.register()
|
UserAgent.register()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(LOG_TAG, "Network '$network' is lost")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) {
|
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) {
|
||||||
super.onLinkPropertiesChanged(network, linkProperties)
|
super.onLinkPropertiesChanged(network, linkProperties)
|
||||||
Log.e(LOG_TAG, "Network $network link properties changed: $linkProperties")
|
|
||||||
if (!isServiceRunning)
|
if (!isServiceRunning)
|
||||||
return
|
return
|
||||||
|
if (network == activeNetwork) {
|
||||||
|
Log.e(LOG_TAG, "Active network $network link properties changed: " +
|
||||||
|
"$linkProperties")
|
||||||
if (dynDns) {
|
if (dynDns) {
|
||||||
dnsServers = linkProperties.dnsServers
|
dnsServers = linkProperties.dnsServers
|
||||||
if (Config.updateDnsServers(dnsServers) != 0)
|
if (Config.updateDnsServers(dnsServers) != 0)
|
||||||
@@ -116,6 +132,10 @@ class BaresipService: Service() {
|
|||||||
linkAddresses = linkProperties.linkAddresses
|
linkAddresses = linkProperties.linkAddresses
|
||||||
Utils.updateLinkAddresses()
|
Utils.updateLinkAddresses()
|
||||||
// UserAgent.register()
|
// UserAgent.register()
|
||||||
|
} else {
|
||||||
|
Log.e(LOG_TAG, "Network $network link properties changed: " +
|
||||||
|
"$linkProperties")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user