Refine code style

This commit is contained in:
Mygod
2020-07-03 12:38:33 +08:00
parent 05c4ba5b81
commit 04cad4ded1
2 changed files with 11 additions and 12 deletions

View File

@@ -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

View File

@@ -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
}