diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt index 08097b90..ace67d6e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/DefaultNetworkMonitor.kt @@ -4,6 +4,8 @@ import android.annotation.TargetApi import android.net.* import android.os.Build import be.mygod.vpnhotspot.App.Companion.app +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import timber.log.Timber object DefaultNetworkMonitor : UpstreamMonitor() { @@ -72,7 +74,7 @@ object DefaultNetworkMonitor : UpstreamMonitor() { override fun registerCallbackLocked(callback: Callback) { if (registered) { val currentLinkProperties = currentLinkProperties - if (currentLinkProperties != null) { + if (currentLinkProperties != null) GlobalScope.launch { callback.onAvailable(currentLinkProperties.interfaceName!!, currentLinkProperties) } } else { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/InterfaceMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/InterfaceMonitor.kt index 25a5ab17..36bc0b9b 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/InterfaceMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/InterfaceMonitor.kt @@ -1,6 +1,8 @@ package be.mygod.vpnhotspot.net.monitor import be.mygod.vpnhotspot.App.Companion.app +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch class InterfaceMonitor(val iface: String) : UpstreamMonitor() { private fun setPresent(present: Boolean) = synchronized(this) { @@ -24,7 +26,9 @@ class InterfaceMonitor(val iface: String) : UpstreamMonitor() { if (!registered) { IpLinkMonitor.registerCallback(this, iface, this::setPresent) registered = true - } else if (currentIface != null) callback.onAvailable(iface, currentLinkProperties ?: return) + } else if (currentIface != null) GlobalScope.launch { + callback.onAvailable(iface, currentLinkProperties ?: return@launch) + } } override fun destroyLocked() { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/VpnMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/VpnMonitor.kt index e50a0ab0..f1aee4eb 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/VpnMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/VpnMonitor.kt @@ -2,6 +2,8 @@ package be.mygod.vpnhotspot.net.monitor import android.net.* import be.mygod.vpnhotspot.App.Companion.app +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import timber.log.Timber object VpnMonitor : UpstreamMonitor() { @@ -72,7 +74,7 @@ object VpnMonitor : UpstreamMonitor() { override fun registerCallbackLocked(callback: Callback) { if (registered) { val currentLinkProperties = currentLinkProperties - if (currentLinkProperties != null) { + if (currentLinkProperties != null) GlobalScope.launch { callback.onAvailable(currentLinkProperties.interfaceName!!, currentLinkProperties) } } else {