Support ap identifier for WifiClient
This commit is contained in:
@@ -20,28 +20,26 @@ value class SoftApInfo(val inner: Parcelable) {
|
||||
@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)
|
||||
}
|
||||
private val getApInstanceIdentifier by lazy @TargetApi(31) { UnblockCentral.getApInstanceIdentifier(clazz) }
|
||||
@get:RequiresApi(31)
|
||||
private val getAutoShutdownTimeoutMillis by lazy { clazz.getDeclaredMethod("getAutoShutdownTimeoutMillis") }
|
||||
|
||||
val channelWidthLookup = ConstantLookup("CHANNEL_WIDTH_") { clazz }
|
||||
}
|
||||
|
||||
val frequency get() = getFrequency.invoke(inner) as Int
|
||||
val bandwidth get() = getBandwidth.invoke(inner) as Int
|
||||
val frequency get() = getFrequency(inner) as Int
|
||||
val bandwidth get() = getBandwidth(inner) as Int
|
||||
@get:RequiresApi(31)
|
||||
val bssid get() = getBssid.invoke(inner) as MacAddress
|
||||
val bssid get() = getBssid(inner) as MacAddress
|
||||
@get:RequiresApi(31)
|
||||
val wifiStandard get() = getWifiStandard.invoke(inner) as Int
|
||||
val wifiStandard get() = getWifiStandard(inner) as Int
|
||||
@get:RequiresApi(31)
|
||||
val apInstanceIdentifier get() = try {
|
||||
getApInstanceIdentifier.invoke(inner) as? String
|
||||
getApInstanceIdentifier(inner) as? String
|
||||
} catch (e: ReflectiveOperationException) {
|
||||
Timber.w(e)
|
||||
null
|
||||
}
|
||||
@get:RequiresApi(31)
|
||||
val autoShutdownTimeoutMillis get() = getAutoShutdownTimeoutMillis.invoke(inner) as Long
|
||||
val autoShutdownTimeoutMillis get() = getAutoShutdownTimeoutMillis(inner) as Long
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ object WifiApManager {
|
||||
fun onNumClientsChanged(numClients: Int) { }
|
||||
|
||||
@RequiresApi(30)
|
||||
fun onConnectedClientsChanged(clients: List<MacAddress>) {
|
||||
fun onConnectedClientsChanged(clients: List<Parcelable>) {
|
||||
@Suppress("DEPRECATION")
|
||||
onNumClientsChanged(clients.size)
|
||||
}
|
||||
@@ -93,7 +93,7 @@ object WifiApManager {
|
||||
fun onCapabilityChanged(capability: Parcelable) { }
|
||||
|
||||
@RequiresApi(30)
|
||||
fun onBlockedClientConnecting(client: MacAddress, blockedReason: Int) { }
|
||||
fun onBlockedClientConnecting(client: Parcelable, blockedReason: Int) { }
|
||||
}
|
||||
@RequiresApi(28)
|
||||
val failureReasonLookup = ConstantLookup<WifiManager>("SAP_START_FAILURE_",
|
||||
@@ -112,10 +112,6 @@ object WifiApManager {
|
||||
WifiManager::class.java.getDeclaredMethod("unregisterSoftApCallback", interfaceSoftApCallback)
|
||||
}
|
||||
|
||||
private val getMacAddress by lazy {
|
||||
Class.forName("android.net.wifi.WifiClient").getDeclaredMethod("getMacAddress")
|
||||
}
|
||||
|
||||
@RequiresApi(28)
|
||||
fun registerSoftApCallback(callback: SoftApCallbackCompat, executor: Executor): Any {
|
||||
val proxy = Proxy.newProxyInstance(interfaceSoftApCallback.classLoader,
|
||||
@@ -140,18 +136,19 @@ object WifiApManager {
|
||||
}
|
||||
"onConnectedClientsChanged" -> @TargetApi(30) {
|
||||
if (Build.VERSION.SDK_INT < 30) Timber.w(Exception("Unexpected onConnectedClientsChanged"))
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
callback.onConnectedClientsChanged(when (noArgs) {
|
||||
1 -> args!![0] as? Iterable<*> ?: return null
|
||||
1 -> args!![0] as List<Parcelable>
|
||||
2 -> {
|
||||
Timber.w(Exception("Unexpected onConnectedClientsChanged API 31+"))
|
||||
// dispatchInfoChanged(args!![0])
|
||||
args!![1] as? Iterable<*> ?: return null
|
||||
args!![1] as List<Parcelable>
|
||||
}
|
||||
else -> {
|
||||
Timber.w("Unexpected args for $name: ${args?.contentToString()}")
|
||||
return null
|
||||
}
|
||||
}.map { getMacAddress(it) as MacAddress })
|
||||
})
|
||||
}
|
||||
"onInfoChanged" -> @TargetApi(30) {
|
||||
if (noArgs != 1) Timber.w("Unexpected args for $name: ${args?.contentToString()}")
|
||||
@@ -179,7 +176,7 @@ object WifiApManager {
|
||||
"onBlockedClientConnecting" -> @TargetApi(30) {
|
||||
if (Build.VERSION.SDK_INT < 30) Timber.w(Exception("Unexpected onBlockedClientConnecting"))
|
||||
if (noArgs != 2) Timber.w("Unexpected args for $name: ${args?.contentToString()}")
|
||||
callback.onBlockedClientConnecting(getMacAddress(args!![0]) as MacAddress, args[1] as Int)
|
||||
callback.onBlockedClientConnecting(args!![0] as Parcelable, args[1] as Int)
|
||||
}
|
||||
else -> callSuper(interfaceSoftApCallback, proxy, method, args)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
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.UnblockCentral
|
||||
import timber.log.Timber
|
||||
|
||||
@JvmInline
|
||||
@RequiresApi(30)
|
||||
value class WifiClient(val inner: Parcelable) {
|
||||
companion object {
|
||||
private val clazz by lazy { Class.forName("android.net.wifi.WifiClient") }
|
||||
private val getMacAddress by lazy { clazz.getDeclaredMethod("getMacAddress") }
|
||||
@get:RequiresApi(31)
|
||||
private val getApInstanceIdentifier by lazy @TargetApi(31) { UnblockCentral.getApInstanceIdentifier(clazz) }
|
||||
}
|
||||
|
||||
val macAddress get() = getMacAddress(inner) as MacAddress
|
||||
@get:RequiresApi(31)
|
||||
val apInstanceIdentifier get() = try {
|
||||
getApInstanceIdentifier(inner) as? String
|
||||
} catch (e: ReflectiveOperationException) {
|
||||
Timber.w(e)
|
||||
null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user