Prevent calling callback in synchronized
This commit is contained in:
@@ -85,7 +85,7 @@ object DefaultNetworkMonitor : UpstreamMonitor() {
|
||||
} catch (e: SecurityException) {
|
||||
// SecurityException would be thrown in requestNetwork on Android 6.0 thanks to Google's stupid bug
|
||||
if (Build.VERSION.SDK_INT != 23) throw e
|
||||
callback.onFallback()
|
||||
GlobalScope.launch { callback.onFallback() }
|
||||
return
|
||||
}
|
||||
registered = true
|
||||
|
||||
@@ -9,8 +9,11 @@ class InterfaceMonitor(val iface: String) : UpstreamMonitor() {
|
||||
val old = currentIface != null
|
||||
if (present == old) return
|
||||
currentIface = if (present) iface else null
|
||||
if (present) {
|
||||
val lp = currentLinkProperties ?: return@synchronized
|
||||
if (present) Pair(iface, currentLinkProperties) else null
|
||||
}.let { pair ->
|
||||
if (pair != null) {
|
||||
val (iface, lp) = pair
|
||||
lp ?: return
|
||||
callbacks.forEach { it.onAvailable(iface, lp) }
|
||||
} else callbacks.forEach { it.onLost() }
|
||||
}
|
||||
|
||||
@@ -15,14 +15,15 @@ class IpNeighbourMonitor private constructor() : IpMonitor() {
|
||||
var instance: IpNeighbourMonitor? = null
|
||||
|
||||
fun registerCallback(callback: Callback) = synchronized(callbacks) {
|
||||
if (!callbacks.add(callback)) return@synchronized
|
||||
if (!callbacks.add(callback)) return@synchronized null
|
||||
var monitor = instance
|
||||
if (monitor == null) {
|
||||
monitor = IpNeighbourMonitor()
|
||||
instance = monitor
|
||||
monitor.flush()
|
||||
} else callback.onIpNeighbourAvailable(monitor.neighbours.values)
|
||||
}
|
||||
null
|
||||
} else monitor.neighbours.values
|
||||
}?.let { callback.onIpNeighbourAvailable(it) }
|
||||
fun unregisterCallback(callback: Callback) = synchronized(callbacks) {
|
||||
if (!callbacks.remove(callback) || callbacks.isNotEmpty()) return@synchronized
|
||||
instance?.destroy()
|
||||
|
||||
Reference in New Issue
Block a user