Support showing supported channels

This commit is contained in:
Mygod
2021-05-29 17:50:31 -04:00
parent ed4475ebb1
commit b38498071f
9 changed files with 96 additions and 12 deletions

View File

@@ -11,10 +11,23 @@ value class SoftApCapability(val inner: Parcelable) {
private val clazz by lazy { Class.forName("android.net.wifi.SoftApCapability") }
private val getMaxSupportedClients by lazy { clazz.getDeclaredMethod("getMaxSupportedClients") }
private val areFeaturesSupported by lazy { clazz.getDeclaredMethod("areFeaturesSupported", Long::class.java) }
@get:RequiresApi(31)
private val getSupportedChannelList by lazy {
clazz.getDeclaredMethod("getSupportedChannelList", Int::class.java)
}
@RequiresApi(31)
const val SOFTAP_FEATURE_BAND_24G_SUPPORTED = 32L
@RequiresApi(31)
const val SOFTAP_FEATURE_BAND_5G_SUPPORTED = 64L
@RequiresApi(31)
const val SOFTAP_FEATURE_BAND_6G_SUPPORTED = 128L
@RequiresApi(31)
const val SOFTAP_FEATURE_BAND_60G_SUPPORTED = 256L
val featureLookup by lazy { LongConstantLookup(clazz, "SOFTAP_FEATURE_") }
}
val maxSupportedClients get() = getMaxSupportedClients.invoke(inner) as Int
val maxSupportedClients get() = getMaxSupportedClients(inner) as Int
val supportedFeatures: Long get() {
var supportedFeatures = 0L
var probe = 1L
@@ -24,4 +37,5 @@ value class SoftApCapability(val inner: Parcelable) {
}
return supportedFeatures
}
fun getSupportedChannelList(band: Int) = getSupportedChannelList(inner, band) as IntArray
}

View File

@@ -12,7 +12,10 @@ import androidx.core.os.BuildCompat
import be.mygod.vpnhotspot.net.MacAddressCompat
import be.mygod.vpnhotspot.net.MacAddressCompat.Companion.toCompat
import be.mygod.vpnhotspot.net.monitor.TetherTimeoutMonitor
import be.mygod.vpnhotspot.util.ConstantLookup
import be.mygod.vpnhotspot.util.UnblockCentral
import kotlinx.parcelize.Parcelize
import timber.log.Timber
@Parcelize
data class SoftApConfigurationCompat(
@@ -40,10 +43,21 @@ data class SoftApConfigurationCompat(
companion object {
const val BAND_2GHZ = 1
const val BAND_5GHZ = 2
@TargetApi(30)
const val BAND_6GHZ = 4
@TargetApi(31)
const val BAND_60GHZ = 8
private const val BAND_LEGACY = BAND_2GHZ or BAND_5GHZ
const val BAND_ANY = BAND_LEGACY or BAND_6GHZ
val BAND_TYPES by lazy {
if (BuildCompat.isAtLeastS()) try {
return@lazy UnblockCentral.SoftApConfiguration_BAND_TYPES
} catch (e: ReflectiveOperationException) {
Timber.w(e)
}
intArrayOf(BAND_2GHZ, BAND_5GHZ, BAND_6GHZ, BAND_60GHZ)
}
val bandLookup = ConstantLookup<SoftApConfiguration>("BAND_", null, "2GHZ", "5GHZ")
fun isLegacyEitherBand(band: Int) = band and BAND_LEGACY == BAND_LEGACY

View File

@@ -122,8 +122,7 @@ object WifiApManager {
fun onBlockedClientConnecting(client: Parcelable, blockedReason: Int) { }
}
@RequiresApi(28)
val failureReasonLookup = ConstantLookup<WifiManager>("SAP_START_FAILURE_",
"SAP_START_FAILURE_GENERAL", "SAP_START_FAILURE_NO_CHANNEL")
val failureReasonLookup = ConstantLookup<WifiManager>("SAP_START_FAILURE_", "GENERAL", "NO_CHANNEL")
@get:RequiresApi(30)
val clientBlockLookup by lazy { ConstantLookup<WifiManager>("SAP_CLIENT_") }