Fix wifi lock not released when monitoring

This commit is contained in:
Mygod
2019-11-06 08:35:41 +08:00
parent ef48fe5ec4
commit 4689c9a975
4 changed files with 12 additions and 15 deletions

View File

@@ -55,9 +55,6 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
val started get() = active[downstream] === this
private var routing: Routing? = null
init {
if (isWifi) WifiDoubleLock.acquire(this)
}
fun start() = when (val other = active.putIfAbsentCompat(downstream, this)) {
null -> initRouting()
@@ -66,6 +63,7 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
}
private fun initRouting() = try {
if (isWifi) WifiDoubleLock.acquire(this)
routing = Routing(caller, downstream).apply {
try {
configure()
@@ -85,11 +83,9 @@ abstract class RoutingManager(private val caller: Any, val downstream: String, p
protected abstract fun Routing.configure()
fun stop() {
if (active.removeCompat(downstream, this)) routing?.revert()
}
fun destroy() {
if (isWifi) WifiDoubleLock.release(this)
stop()
if (active.removeCompat(downstream, this)) {
if (isWifi) WifiDoubleLock.release(this)
routing?.revert()
}
}
}