diff --git a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt index 7a8f624f..ffff72f9 100644 --- a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt +++ b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt @@ -404,7 +404,7 @@ class RootServer { mainInitialized.await() CoroutineScope(Dispatchers.Main.immediate + job) } - val callbackWorker = newSingleThreadContext("callbackWorker") + val callbackWorker = Dispatchers.IO.limitedParallelism(1) // access to cancellables shall be wrapped in defaultWorker val cancellables = LongSparseArray<() -> Unit>() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index 47069135..33f847c0 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -59,7 +59,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope { /** * Writes and critical reads to routingManager should be protected with this context. */ - private val dispatcher = newSingleThreadContext("LocalOnlyHotspotService") + private val dispatcher = Dispatchers.IO.limitedParallelism(1) override val coroutineContext = dispatcher + Job() private var routingManager: RoutingManager? = null private var timeoutMonitor: TetherTimeoutMonitor? = null @@ -167,10 +167,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope { launch { routingManager?.stop() routingManager = null - if (exit) { - cancel() - dispatcher.close() - } + if (exit) cancel() } } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index aeee8468..754892f4 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -241,7 +241,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene /** * Writes and critical reads to routingManager should be protected with this context. */ - private val dispatcher = newSingleThreadContext("RepeaterService") + private val dispatcher = Dispatchers.IO.limitedParallelism(1) override val coroutineContext = dispatcher + Job() private var routingManager: RoutingManager? = null private var persistNextGroup = false @@ -529,7 +529,6 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene launch { // force clean to prevent leakage cleanLocked() cancel() - dispatcher.close() } app.pref.unregisterOnSharedPreferenceChangeListener(this) if (Build.VERSION.SDK_INT < 29) unregisterReceiver(deviceListener) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt index 7f68ed66..28951a4d 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/TetheringService.kt @@ -55,7 +55,7 @@ class TetheringService : IpNeighbourMonitoringService(), TetheringManager.Tether /** * Writes and critical reads to downstreams should be protected with this context. */ - private val dispatcher = newSingleThreadContext("TetheringService") + private val dispatcher = Dispatchers.IO.limitedParallelism(1) override val coroutineContext = dispatcher + Job() private val binder = Binder() private val downstreams = ConcurrentHashMap() @@ -144,7 +144,6 @@ class TetheringService : IpNeighbourMonitoringService(), TetheringManager.Tether unregisterReceiver() downstreams.values.forEach { it.stop() } // force clean to prevent leakage cancel() - dispatcher.close() } super.onDestroy() }