Fix deadlocks

This commit is contained in:
Mygod
2020-02-20 09:54:34 +08:00
parent 9cb539c647
commit 7edb09ad2c
3 changed files with 11 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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() {

View File

@@ -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 {