Fix deadlocks
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user