Split SetChannel command

This commit is contained in:
Mygod
2020-07-01 14:08:00 -04:00
parent 5e4cebc346
commit 600a99cd13
2 changed files with 13 additions and 3 deletions

View File

@@ -206,7 +206,10 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
override fun onFailure(reason: Int) { override fun onFailure(reason: Int) {
if (reason == WifiP2pManager.ERROR && Build.VERSION.SDK_INT >= 30) launch(start = CoroutineStart.UNDISPATCHED) { if (reason == WifiP2pManager.ERROR && Build.VERSION.SDK_INT >= 30) launch(start = CoroutineStart.UNDISPATCHED) {
val rootReason = try { 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) { } catch (e: Exception) {
Timber.w(e) Timber.w(e)
SmartSnackbar.make(e).show() SmartSnackbar.make(e).show()

View File

@@ -18,9 +18,16 @@ import java.io.File
object RepeaterCommands { object RepeaterCommands {
@Parcelize @Parcelize
class SetChannel(private val oc: Int, private val forceReinit: Boolean = false) : RootCommand<ParcelableInt?> { class Deinit : RootCommandNoResult {
override suspend fun execute(): Parcelable? {
channel = null
return null
}
}
@Parcelize
class SetChannel(private val oc: Int) : RootCommand<ParcelableInt?> {
override suspend fun execute() = Services.p2p!!.run { override suspend fun execute() = Services.p2p!!.run {
if (forceReinit) channel = null
val uninitializer = object : WifiP2pManager.ChannelListener { val uninitializer = object : WifiP2pManager.ChannelListener {
var target: WifiP2pManager.Channel? = null var target: WifiP2pManager.Channel? = null
override fun onChannelDisconnected() { override fun onChannelDisconnected() {