Fix deadlocks
This commit is contained in:
@@ -4,6 +4,8 @@ import android.annotation.TargetApi
|
|||||||
import android.net.*
|
import android.net.*
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
object DefaultNetworkMonitor : UpstreamMonitor() {
|
object DefaultNetworkMonitor : UpstreamMonitor() {
|
||||||
@@ -72,7 +74,7 @@ object DefaultNetworkMonitor : UpstreamMonitor() {
|
|||||||
override fun registerCallbackLocked(callback: Callback) {
|
override fun registerCallbackLocked(callback: Callback) {
|
||||||
if (registered) {
|
if (registered) {
|
||||||
val currentLinkProperties = currentLinkProperties
|
val currentLinkProperties = currentLinkProperties
|
||||||
if (currentLinkProperties != null) {
|
if (currentLinkProperties != null) GlobalScope.launch {
|
||||||
callback.onAvailable(currentLinkProperties.interfaceName!!, currentLinkProperties)
|
callback.onAvailable(currentLinkProperties.interfaceName!!, currentLinkProperties)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package be.mygod.vpnhotspot.net.monitor
|
package be.mygod.vpnhotspot.net.monitor
|
||||||
|
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class InterfaceMonitor(val iface: String) : UpstreamMonitor() {
|
class InterfaceMonitor(val iface: String) : UpstreamMonitor() {
|
||||||
private fun setPresent(present: Boolean) = synchronized(this) {
|
private fun setPresent(present: Boolean) = synchronized(this) {
|
||||||
@@ -24,7 +26,9 @@ class InterfaceMonitor(val iface: String) : UpstreamMonitor() {
|
|||||||
if (!registered) {
|
if (!registered) {
|
||||||
IpLinkMonitor.registerCallback(this, iface, this::setPresent)
|
IpLinkMonitor.registerCallback(this, iface, this::setPresent)
|
||||||
registered = true
|
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() {
|
override fun destroyLocked() {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package be.mygod.vpnhotspot.net.monitor
|
|||||||
|
|
||||||
import android.net.*
|
import android.net.*
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
object VpnMonitor : UpstreamMonitor() {
|
object VpnMonitor : UpstreamMonitor() {
|
||||||
@@ -72,7 +74,7 @@ object VpnMonitor : UpstreamMonitor() {
|
|||||||
override fun registerCallbackLocked(callback: Callback) {
|
override fun registerCallbackLocked(callback: Callback) {
|
||||||
if (registered) {
|
if (registered) {
|
||||||
val currentLinkProperties = currentLinkProperties
|
val currentLinkProperties = currentLinkProperties
|
||||||
if (currentLinkProperties != null) {
|
if (currentLinkProperties != null) GlobalScope.launch {
|
||||||
callback.onAvailable(currentLinkProperties.interfaceName!!, currentLinkProperties)
|
callback.onAvailable(currentLinkProperties.interfaceName!!, currentLinkProperties)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user