From 600a99cd13eddaa108396336f7c5bd46f02e730b Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 1 Jul 2020 14:08:00 -0400 Subject: [PATCH] Split SetChannel command --- .../main/java/be/mygod/vpnhotspot/RepeaterService.kt | 5 ++++- .../java/be/mygod/vpnhotspot/root/RepeaterCommands.kt | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index 5f5b8671..70619056 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -206,7 +206,10 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene override fun onFailure(reason: Int) { if (reason == WifiP2pManager.ERROR && Build.VERSION.SDK_INT >= 30) launch(start = CoroutineStart.UNDISPATCHED) { val rootReason = try { - RootManager.use { it.execute(RepeaterCommands.SetChannel(oc, forceReinit)) } + RootManager.use { + if (forceReinit) it.execute(RepeaterCommands.Deinit()) + it.execute(RepeaterCommands.SetChannel(oc)) + } } catch (e: Exception) { Timber.w(e) SmartSnackbar.make(e).show() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/root/RepeaterCommands.kt b/mobile/src/main/java/be/mygod/vpnhotspot/root/RepeaterCommands.kt index da474f3b..e968baab 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/root/RepeaterCommands.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/root/RepeaterCommands.kt @@ -18,9 +18,16 @@ import java.io.File object RepeaterCommands { @Parcelize - class SetChannel(private val oc: Int, private val forceReinit: Boolean = false) : RootCommand { + class Deinit : RootCommandNoResult { + override suspend fun execute(): Parcelable? { + channel = null + return null + } + } + + @Parcelize + class SetChannel(private val oc: Int) : RootCommand { override suspend fun execute() = Services.p2p!!.run { - if (forceReinit) channel = null val uninitializer = object : WifiP2pManager.ChannelListener { var target: WifiP2pManager.Channel? = null override fun onChannelDisconnected() {