Support new fields in SoftApInfo

This commit is contained in:
Mygod
2021-05-26 20:56:44 -04:00
parent a69d635f93
commit 50de5a269c
7 changed files with 123 additions and 25 deletions

View File

@@ -1,20 +1,47 @@
package be.mygod.vpnhotspot.net.wifi
import android.annotation.TargetApi
import android.net.MacAddress
import android.os.Parcelable
import androidx.annotation.RequiresApi
import be.mygod.vpnhotspot.util.ConstantLookup
import be.mygod.vpnhotspot.util.UnblockCentral
import timber.log.Timber
@JvmInline
@RequiresApi(30)
value class SoftApInfo(val inner: Parcelable) {
companion object {
private val classSoftApInfo by lazy { Class.forName("android.net.wifi.SoftApInfo") }
private val getFrequency by lazy { classSoftApInfo.getDeclaredMethod("getFrequency") }
private val getBandwidth by lazy { classSoftApInfo.getDeclaredMethod("getBandwidth") }
private val clazz by lazy { Class.forName("android.net.wifi.SoftApInfo") }
private val getFrequency by lazy { clazz.getDeclaredMethod("getFrequency") }
private val getBandwidth by lazy { clazz.getDeclaredMethod("getBandwidth") }
@get:RequiresApi(31)
private val getBssid by lazy { clazz.getDeclaredMethod("getBssid") }
@get:RequiresApi(31)
private val getWifiStandard by lazy { clazz.getDeclaredMethod("getWifiStandard") }
@get:RequiresApi(31)
private val getApInstanceIdentifier by lazy @TargetApi(31) {
UnblockCentral.SoftApInfo_getApInstanceIdentifier(clazz)
}
@get:RequiresApi(31)
private val getAutoShutdownTimeoutMillis by lazy { clazz.getDeclaredMethod("getAutoShutdownTimeoutMillis") }
val channelWidthLookup = ConstantLookup("CHANNEL_WIDTH_") { classSoftApInfo }
val channelWidthLookup = ConstantLookup("CHANNEL_WIDTH_") { clazz }
}
val frequency get() = getFrequency.invoke(inner) as Int
val bandwidth get() = getBandwidth.invoke(inner) as Int
@get:RequiresApi(31)
val bssid get() = getBssid.invoke(inner) as MacAddress
@get:RequiresApi(31)
val wifiStandard get() = getWifiStandard.invoke(inner) as Int
@get:RequiresApi(31)
val apInstanceIdentifier get() = try {
getApInstanceIdentifier.invoke(inner) as? String
} catch (e: ReflectiveOperationException) {
Timber.w(e)
null
}
@get:RequiresApi(31)
val autoShutdownTimeoutMillis get() = getAutoShutdownTimeoutMillis.invoke(inner) as Long
}