Support new SoftAp callback methods on Android 12 beta 1
This commit is contained in:
@@ -9,6 +9,7 @@ import android.net.wifi.WifiManager
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.core.os.BuildCompat
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat.Companion.toCompat
|
import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat.Companion.toCompat
|
||||||
import be.mygod.vpnhotspot.util.ConstantLookup
|
import be.mygod.vpnhotspot.util.ConstantLookup
|
||||||
@@ -140,6 +141,9 @@ object WifiApManager {
|
|||||||
null // no return value as of API 30
|
null // no return value as of API 30
|
||||||
} else invokeActual(proxy, method, args)
|
} else invokeActual(proxy, method, args)
|
||||||
|
|
||||||
|
@RequiresApi(30)
|
||||||
|
private fun dispatchInfoChanged(softApInfo: Any?) =
|
||||||
|
callback.onInfoChanged(getFrequency(softApInfo) as Int, getBandwidth(softApInfo) as Int)
|
||||||
private fun invokeActual(proxy: Any, method: Method, args: Array<out Any?>?): Any? {
|
private fun invokeActual(proxy: Any, method: Method, args: Array<out Any?>?): Any? {
|
||||||
val noArgs = args?.size ?: 0
|
val noArgs = args?.size ?: 0
|
||||||
return when (val name = method.name) {
|
return when (val name = method.name) {
|
||||||
@@ -154,17 +158,29 @@ object WifiApManager {
|
|||||||
}
|
}
|
||||||
"onConnectedClientsChanged" -> @TargetApi(30) {
|
"onConnectedClientsChanged" -> @TargetApi(30) {
|
||||||
if (Build.VERSION.SDK_INT < 30) Timber.w(Exception("Unexpected onConnectedClientsChanged"))
|
if (Build.VERSION.SDK_INT < 30) Timber.w(Exception("Unexpected onConnectedClientsChanged"))
|
||||||
if (noArgs != 1) Timber.w("Unexpected args for $name: ${args?.contentToString()}")
|
callback.onConnectedClientsChanged(when (noArgs) {
|
||||||
callback.onConnectedClientsChanged((args!![0] as? Iterable<*> ?: return null)
|
1 -> args!![0] as? Iterable<*> ?: return null
|
||||||
.map { getMacAddress(it) as MacAddress })
|
2 -> {
|
||||||
|
if (!BuildCompat.isAtLeastS()) Timber.w(Exception(
|
||||||
|
"Unexpected onConnectedClientsChanged API 31+"))
|
||||||
|
dispatchInfoChanged(args!![0])
|
||||||
|
args[1] as? Iterable<*> ?: return null
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Timber.w("Unexpected args for $name: ${args?.contentToString()}")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}.map { getMacAddress(it) as MacAddress })
|
||||||
}
|
}
|
||||||
"onInfoChanged" -> @TargetApi(30) {
|
"onInfoChanged" -> @TargetApi(30) {
|
||||||
if (Build.VERSION.SDK_INT < 30) Timber.w(Exception("Unexpected onInfoChanged"))
|
if (Build.VERSION.SDK_INT < 30) Timber.w(Exception("Unexpected onInfoChanged"))
|
||||||
if (noArgs != 1) Timber.w("Unexpected args for $name: ${args?.contentToString()}")
|
if (noArgs != 1) Timber.w("Unexpected args for $name: ${args?.contentToString()}")
|
||||||
val softApInfo = args!![0]
|
val arg = args!![0]
|
||||||
if (softApInfo != null && classSoftApInfo.isAssignableFrom(softApInfo.javaClass)) {
|
if (arg is List<*>) {
|
||||||
callback.onInfoChanged(getFrequency(softApInfo) as Int, getBandwidth(softApInfo) as Int)
|
if (!BuildCompat.isAtLeastS()) Timber.w(Exception("Unexpected onInfoChanged API 31+"))
|
||||||
} else null
|
if (arg.size != 1) Timber.w("Unexpected args for $name: ${args.contentToString()}")
|
||||||
|
else dispatchInfoChanged(arg[0])
|
||||||
|
} else dispatchInfoChanged(arg)
|
||||||
}
|
}
|
||||||
"onCapabilityChanged" -> @TargetApi(30) {
|
"onCapabilityChanged" -> @TargetApi(30) {
|
||||||
if (Build.VERSION.SDK_INT < 30) Timber.w(Exception("Unexpected onCapabilityChanged"))
|
if (Build.VERSION.SDK_INT < 30) Timber.w(Exception("Unexpected onCapabilityChanged"))
|
||||||
|
|||||||
Reference in New Issue
Block a user