Fix dispatcher not closed
This commit is contained in:
@@ -46,7 +46,8 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
|
|||||||
/**
|
/**
|
||||||
* Writes and critical reads to routingManager should be protected with this context.
|
* Writes and critical reads to routingManager should be protected with this context.
|
||||||
*/
|
*/
|
||||||
override val coroutineContext = newSingleThreadContext("LocalOnlyHotspotService") + Job()
|
private val dispatcher = newSingleThreadContext("LocalOnlyHotspotService")
|
||||||
|
override val coroutineContext = dispatcher + Job()
|
||||||
private var routingManager: RoutingManager? = null
|
private var routingManager: RoutingManager? = null
|
||||||
private val handler = Handler()
|
private val handler = Handler()
|
||||||
@RequiresApi(28)
|
@RequiresApi(28)
|
||||||
@@ -158,7 +159,10 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
|
|||||||
launch {
|
launch {
|
||||||
routingManager?.destroy()
|
routingManager?.destroy()
|
||||||
routingManager = null
|
routingManager = null
|
||||||
if (exit) cancel()
|
if (exit) {
|
||||||
|
cancel()
|
||||||
|
dispatcher.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
|
|||||||
/**
|
/**
|
||||||
* Writes and critical reads to routingManager should be protected with this context.
|
* Writes and critical reads to routingManager should be protected with this context.
|
||||||
*/
|
*/
|
||||||
override val coroutineContext = newSingleThreadContext("RepeaterService") + Job()
|
private val dispatcher = newSingleThreadContext("RepeaterService")
|
||||||
|
override val coroutineContext = dispatcher + Job()
|
||||||
private var routingManager: RoutingManager? = null
|
private var routingManager: RoutingManager? = null
|
||||||
private var persistNextGroup = false
|
private var persistNextGroup = false
|
||||||
|
|
||||||
@@ -419,6 +420,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
|
|||||||
launch { // force clean to prevent leakage
|
launch { // force clean to prevent leakage
|
||||||
cleanLocked()
|
cleanLocked()
|
||||||
cancel()
|
cancel()
|
||||||
|
dispatcher.close()
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT < 29) @Suppress("DEPRECATION") {
|
if (Build.VERSION.SDK_INT < 29) @Suppress("DEPRECATION") {
|
||||||
app.pref.unregisterOnSharedPreferenceChangeListener(this)
|
app.pref.unregisterOnSharedPreferenceChangeListener(this)
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ class TetheringService : IpNeighbourMonitoringService(), CoroutineScope {
|
|||||||
/**
|
/**
|
||||||
* Writes and critical reads to downstreams should be protected with this context.
|
* Writes and critical reads to downstreams should be protected with this context.
|
||||||
*/
|
*/
|
||||||
override val coroutineContext = newSingleThreadContext("TetheringService") + Job()
|
private val dispatcher = newSingleThreadContext("TetheringService")
|
||||||
|
override val coroutineContext = dispatcher + Job()
|
||||||
private val binder = Binder()
|
private val binder = Binder()
|
||||||
private val downstreams = ConcurrentHashMap<String, Downstream>()
|
private val downstreams = ConcurrentHashMap<String, Downstream>()
|
||||||
private var receiverRegistered = false
|
private var receiverRegistered = false
|
||||||
@@ -109,6 +110,7 @@ class TetheringService : IpNeighbourMonitoringService(), CoroutineScope {
|
|||||||
downstreams.values.forEach { it.destroy() } // force clean to prevent leakage
|
downstreams.values.forEach { it.destroy() } // force clean to prevent leakage
|
||||||
unregisterReceiver()
|
unregisterReceiver()
|
||||||
cancel()
|
cancel()
|
||||||
|
dispatcher.close()
|
||||||
}
|
}
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user