From 1e4dab162ce2a38399376e55071f7c1781c187da Mon Sep 17 00:00:00 2001 From: Robert Meijers Date: Sun, 3 Aug 2025 13:58:01 +0200 Subject: [PATCH] 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. --- .../kotlin/com/github/gotify/service/WebSocketService.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt b/app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt index eac9ca1..30df1e0 100644 --- a/app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt +++ b/app/src/main/kotlin/com/github/gotify/service/WebSocketService.kt @@ -9,6 +9,7 @@ import android.content.Intent import android.content.pm.ServiceInfo import android.graphics.Color import android.net.ConnectivityManager +import android.net.LinkProperties import android.net.Network import android.os.Build import android.os.IBinder @@ -57,6 +58,12 @@ internal class WebSocketService : Service() { Logger.info("WebSocket: Network available, reconnect if needed.") 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()