[2.15.0] 优化代码逻辑

This commit is contained in:
renwj
2023-03-28 10:38:17 +08:00
parent 00c423a4b2
commit 69d25f0bad

View File

@@ -24,6 +24,9 @@ class ANRFix {
@TargetMethod(methodName = "post")
@ReplaceInvoke
fun handlerPostProxy(handler: Handler, action: Runnable): Boolean {
if (Looper.getMainLooper() != handler.looper) {
return handler.post(action)
}
val what = ObjectHashCodeUtils.getHashCodeIfNeed(action)
handler.removeMessages(what)
val msg = Message.obtain(handler, action)
@@ -36,6 +39,9 @@ class ANRFix {
@TargetMethod(methodName = "postDelayed")
@ReplaceInvoke
fun handlerPostDelayProxy(handler: Handler, action: Runnable, delayMillis: Long): Boolean {
if (Looper.getMainLooper() != handler.looper) {
return handler.postDelayed(action, delayMillis)
}
val what = ObjectHashCodeUtils.getHashCodeIfNeed(action)
handler.removeMessages(what)
val msg = Message.obtain(handler, action)