Refine code style
This commit is contained in:
@@ -133,12 +133,11 @@ object WifiApManager {
|
|||||||
fun registerSoftApCallback(callback: SoftApCallbackCompat, executor: Executor): Any {
|
fun registerSoftApCallback(callback: SoftApCallbackCompat, executor: Executor): Any {
|
||||||
val proxy = Proxy.newProxyInstance(interfaceSoftApCallback.classLoader,
|
val proxy = Proxy.newProxyInstance(interfaceSoftApCallback.classLoader,
|
||||||
arrayOf(interfaceSoftApCallback), object : InvocationHandler {
|
arrayOf(interfaceSoftApCallback), object : InvocationHandler {
|
||||||
override fun invoke(proxy: Any, method: Method, args: Array<out Any?>?): Any? {
|
override fun invoke(proxy: Any, method: Method, args: Array<out Any?>?) =
|
||||||
return if (Build.VERSION.SDK_INT >= 30 || method.name !in methods29) invokeActual(proxy, method, args) else {
|
if (Build.VERSION.SDK_INT < 30 && method.name in methods29) {
|
||||||
executor.execute { invokeActual(proxy, method, args) }
|
executor.execute { invokeActual(proxy, method, args) }
|
||||||
null // no return value as of API 30
|
null // no return value as of API 30
|
||||||
}
|
} else invokeActual(proxy, method, args)
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -135,14 +135,14 @@ private val newLookup by lazy @TargetApi(26) {
|
|||||||
*
|
*
|
||||||
* See also: https://stackoverflow.com/a/49532463/2245107
|
* See also: https://stackoverflow.com/a/49532463/2245107
|
||||||
*/
|
*/
|
||||||
fun InvocationHandler.callSuper(interfaceClass: Class<*>, proxy: Any, method: Method, args: Array<out Any?>?): Any? {
|
fun InvocationHandler.callSuper(interfaceClass: Class<*>, proxy: Any, method: Method, args: Array<out Any?>?) = when {
|
||||||
return if (Build.VERSION.SDK_INT >= 26 && method.isDefault) newLookup.newInstance(interfaceClass, 0xf) // ALL_MODES
|
Build.VERSION.SDK_INT >= 26 && method.isDefault -> newLookup.newInstance(interfaceClass, 0xf) // ALL_MODES
|
||||||
.`in`(interfaceClass).unreflectSpecial(method, interfaceClass).bindTo(proxy).run {
|
.`in`(interfaceClass).unreflectSpecial(method, interfaceClass).bindTo(proxy).run {
|
||||||
if (args == null) invokeWithArguments() else invokeWithArguments(*args)
|
if (args == null) invokeWithArguments() else invokeWithArguments(*args)
|
||||||
} else if (method.declaringClass === Object::class.java) {
|
}
|
||||||
// otherwise, we just redispatch it to InvocationHandler
|
// otherwise, we just redispatch it to InvocationHandler
|
||||||
if (args == null) method(this) else method(this, *args)
|
method.declaringClass.isAssignableFrom(javaClass) -> if (args == null) method(this) else method(this, *args)
|
||||||
} else {
|
else -> {
|
||||||
Timber.w("Unhandled method: $method(${args?.contentDeepToString()})")
|
Timber.w("Unhandled method: $method(${args?.contentDeepToString()})")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user