try reconnecting after link properties changed

In some circumstances (like the server only being reachable over IPv6)
reconnecting when the network becomes available doesn't work. This due
to the network only being "partially" available (in the example: IPv4
working, but IPv6 not yet). By also listening for changes of the link
properties a new connection attempt is made when for example the IP
addresses of the link, or the networking routes change. Meaning that the
example issue is fixed, as a new attempt is made after the IPv6 address
is set on the link / the routes for IPv6 networking are available.
This commit is contained in:
Robert Meijers
2025-08-03 13:58:01 +02:00
parent cd7ac5595b
commit 1e4dab162c

View File

@@ -9,6 +9,7 @@ import android.content.Intent
import android.content.pm.ServiceInfo import android.content.pm.ServiceInfo
import android.graphics.Color import android.graphics.Color
import android.net.ConnectivityManager import android.net.ConnectivityManager
import android.net.LinkProperties
import android.net.Network import android.net.Network
import android.os.Build import android.os.Build
import android.os.IBinder import android.os.IBinder
@@ -57,6 +58,12 @@ internal class WebSocketService : Service() {
Logger.info("WebSocket: Network available, reconnect if needed.") Logger.info("WebSocket: Network available, reconnect if needed.")
connection?.start() connection?.start()
} }
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) {
super.onLinkPropertiesChanged(network, linkProperties)
Logger.info("WebSocket: Network properties changed, reconnect if needed.")
connection?.start()
}
} }
private val appIdToApp = ConcurrentHashMap<Long, Application>() private val appIdToApp = ConcurrentHashMap<Long, Application>()