Fix requestPersistentGroupInfo and deletePersistentGroup permissions

This commit is contained in:
Mygod
2020-07-01 15:37:21 -04:00
parent 600a99cd13
commit febf7f1c61
8 changed files with 170 additions and 84 deletions

View File

@@ -7,13 +7,15 @@ import android.system.Os
import android.system.OsConstants
import android.text.TextUtils
import be.mygod.librootkotlinx.ParcelableInt
import be.mygod.librootkotlinx.ParcelableList
import be.mygod.librootkotlinx.RootCommand
import be.mygod.librootkotlinx.RootCommandNoResult
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.deletePersistentGroup
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.requestPersistentGroupInfo
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.setWifiP2pChannels
import be.mygod.vpnhotspot.util.Services
import eu.chainfire.librootjava.RootJava
import kotlinx.android.parcel.Parcelize
import kotlinx.coroutines.CompletableDeferred
import java.io.File
object RepeaterCommands {
@@ -25,30 +27,24 @@ object RepeaterCommands {
}
}
@Parcelize
data class DeletePersistentGroup(val netId: Int) : RootCommand<ParcelableInt?> {
override suspend fun execute() = Services.p2p!!.run {
deletePersistentGroup(obtainChannel(), netId)?.let { ParcelableInt(it) }
}
}
@Parcelize
class RequestPersistentGroupInfo : RootCommand<ParcelableList> {
override suspend fun execute() = Services.p2p!!.run {
ParcelableList(requestPersistentGroupInfo(obtainChannel()).toList())
}
}
@Parcelize
class SetChannel(private val oc: Int) : RootCommand<ParcelableInt?> {
override suspend fun execute() = Services.p2p!!.run {
val uninitializer = object : WifiP2pManager.ChannelListener {
var target: WifiP2pManager.Channel? = null
override fun onChannelDisconnected() {
if (target == channel) channel = null
}
}
val channel = channel ?: initialize(RootJava.getSystemContext(),
Looper.getMainLooper(), uninitializer)
uninitializer.target = channel
RepeaterCommands.channel = channel // cache the instance until invalidated
val future = CompletableDeferred<Int?>()
setWifiP2pChannels(channel, 0, oc, object : WifiP2pManager.ActionListener {
override fun onSuccess() {
future.complete(null)
}
override fun onFailure(reason: Int) {
future.complete(reason)
}
})
future.await()?.let { ParcelableInt(it) }
setWifiP2pChannels(obtainChannel(), 0, oc)?.let { ParcelableInt(it) }
}
}
@@ -82,4 +78,18 @@ object RepeaterCommands {
private const val CONF_PATH_TREBLE = "/data/vendor/wifi/wpa/p2p_supplicant.conf"
private const val CONF_PATH_LEGACY = "/data/misc/wifi/p2p_supplicant.conf"
private var channel: WifiP2pManager.Channel? = null
private fun WifiP2pManager.obtainChannel(): WifiP2pManager.Channel {
channel?.let { return it }
val uninitializer = object : WifiP2pManager.ChannelListener {
var target: WifiP2pManager.Channel? = null
override fun onChannelDisconnected() {
if (target == channel) channel = null
}
}
return initialize(RootJava.getSystemContext(), Looper.getMainLooper(), uninitializer).also {
uninitializer.target = it
channel = it // cache the instance until invalidated
}
}
}