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