fix: network monitoring bug

This commit is contained in:
Zane Schepke
2025-11-04 17:48:40 -05:00
parent 4bcd810b38
commit 4beeb4e01e
5 changed files with 335 additions and 271 deletions
@@ -61,6 +61,9 @@ class AutoTunnelService : LifecycleService() {
private val autoTunnelStateFlow = MutableStateFlow(defaultState)
private var autoTunnelJob: Job? = null
private var permissionsJob: Job? = null
class LocalBinder(service: AutoTunnelService) : Binder() {
private val serviceRef = WeakReference(service)
@@ -89,8 +92,10 @@ class AutoTunnelService : LifecycleService() {
fun start() {
launchWatcherNotification()
startAutoTunnelStateJob()
startLocationPermissionsNotificationJob()
autoTunnelJob?.cancel()
autoTunnelJob = startAutoTunnelStateJob()
permissionsJob?.cancel()
permissionsJob = startLocationPermissionsNotificationJob()
}
fun stop() {
@@ -130,7 +135,7 @@ class AutoTunnelService : LifecycleService() {
)
}
private fun startAutoTunnelStateJob() =
private fun startAutoTunnelStateJob(): Job =
lifecycleScope.launch(ioDispatcher) {
val networkFlow =
debouncedConnectivityStateFlow
@@ -59,8 +59,8 @@ data class AutoTunnelState(
return DoNothing
}
private val ethernetActive: Boolean = networkState.activeNetwork is ActiveNetwork.Cellular
private val mobileDataActive: Boolean = networkState.activeNetwork is ActiveNetwork.Ethernet
private val ethernetActive: Boolean = networkState.activeNetwork is ActiveNetwork.Ethernet
private val mobileDataActive: Boolean = networkState.activeNetwork is ActiveNetwork.Cellular
private val wifiActive: Boolean = networkState.activeNetwork is ActiveNetwork.Wifi
private fun preferredMobileDataTunnel(): TunnelConfig? {