Fix wifi lock not released when monitoring
This commit is contained in:
@@ -158,7 +158,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
|
||||
receiverRegistered = false
|
||||
}
|
||||
launch {
|
||||
routingManager?.destroy()
|
||||
routingManager?.stop()
|
||||
routingManager = null
|
||||
if (exit) {
|
||||
cancel()
|
||||
|
||||
@@ -410,7 +410,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
|
||||
timeoutMonitor?.close()
|
||||
timeoutMonitor = null
|
||||
}
|
||||
routingManager?.destroy()
|
||||
routingManager?.stop()
|
||||
routingManager = null
|
||||
status = Status.IDLE
|
||||
ServiceNotification.stopForeground(this)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,8 @@ class TetheringService : IpNeighbourMonitoringService(), CoroutineScope {
|
||||
if (downstream.monitor) downstream.start()
|
||||
}
|
||||
for ((iface, downstream) in toRemove) {
|
||||
if (downstream.monitor) downstream.stop() else downstreams.remove(iface)?.destroy()
|
||||
downstream.stop()
|
||||
if (!downstream.monitor) check(downstreams.remove(iface, downstream))
|
||||
}
|
||||
onDownstreamsChangedLocked()
|
||||
}
|
||||
@@ -87,7 +88,7 @@ class TetheringService : IpNeighbourMonitoringService(), CoroutineScope {
|
||||
if (intent != null) {
|
||||
for (iface in intent.getStringArrayExtra(EXTRA_ADD_INTERFACES) ?: emptyArray()) {
|
||||
if (downstreams[iface] == null) Downstream(this@TetheringService, iface).apply {
|
||||
if (start()) check(downstreams.put(iface, this) == null) else destroy()
|
||||
if (start()) check(downstreams.put(iface, this) == null) else stop()
|
||||
}
|
||||
}
|
||||
intent.getStringExtra(EXTRA_ADD_INTERFACE_MONITOR)?.also { iface ->
|
||||
@@ -98,7 +99,7 @@ class TetheringService : IpNeighbourMonitoringService(), CoroutineScope {
|
||||
downstreams[iface] = this
|
||||
} else downstream.monitor = true
|
||||
}
|
||||
intent.getStringExtra(EXTRA_REMOVE_INTERFACE)?.also { downstreams.remove(it)?.destroy() }
|
||||
intent.getStringExtra(EXTRA_REMOVE_INTERFACE)?.also { downstreams.remove(it)?.stop() }
|
||||
updateNotification() // call this first just in case we are shutting down immediately
|
||||
onDownstreamsChangedLocked()
|
||||
} else if (downstreams.isEmpty()) stopSelf(startId)
|
||||
@@ -109,7 +110,7 @@ class TetheringService : IpNeighbourMonitoringService(), CoroutineScope {
|
||||
override fun onDestroy() {
|
||||
launch {
|
||||
unregisterReceiver()
|
||||
downstreams.values.forEach { it.destroy() } // force clean to prevent leakage
|
||||
downstreams.values.forEach { it.stop() } // force clean to prevent leakage
|
||||
cancel()
|
||||
dispatcher.close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user