88 lines
3.1 KiB
Kotlin
88 lines
3.1 KiB
Kotlin
package com.mogo.launcher.lancet
|
|
|
|
import android.app.Activity
|
|
import android.os.*
|
|
import android.view.View
|
|
import androidx.annotation.*
|
|
import com.knightboost.lancet.api.*
|
|
import com.knightboost.lancet.api.Scope.ALL
|
|
import com.knightboost.lancet.api.annotations.*
|
|
import com.knightboost.lancet.api.annotations.Weaver
|
|
import com.mogo.eagle.core.utilcode.util.*
|
|
import kotlinx.coroutines.*
|
|
import kotlinx.coroutines.Runnable
|
|
|
|
@Keep
|
|
@Weaver
|
|
@Group("anr_fix")
|
|
class ANRFix {
|
|
|
|
companion object {
|
|
|
|
// @JvmStatic
|
|
// @TargetClass(value = "android.os.Handler", scope = ALL)
|
|
// @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)
|
|
// msg.what = what
|
|
// return handler.sendMessage(msg)
|
|
// }
|
|
//
|
|
// @JvmStatic
|
|
// @TargetClass(value = "android.os.Handler", scope = ALL)
|
|
// @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)
|
|
// msg.what = what
|
|
// return handler.sendMessageDelayed(msg, delayMillis)
|
|
// }
|
|
//
|
|
// @JvmStatic
|
|
// @TargetClass(value = "android.app.Activity", scope = ALL)
|
|
// @TargetMethod(methodName = "post")
|
|
// @ReplaceInvoke
|
|
// fun runOnUiThreadOfActivityProxy(activity: Activity, action: Runnable) {
|
|
// if (Looper.myLooper() != Looper.getMainLooper()) {
|
|
// UiThreadHandler.post(action)
|
|
// } else {
|
|
// activity.runOnUiThread(action)
|
|
// }
|
|
// }
|
|
//
|
|
// @JvmStatic
|
|
// @TargetClass(value = "android.view.View", scope = ALL)
|
|
// @TargetMethod(methodName = "post")
|
|
// @ReplaceInvoke
|
|
// fun postOfViewProxy(view: View, action: Runnable): Boolean {
|
|
// return if (Looper.myLooper() != Looper.getMainLooper()) {
|
|
// UiThreadHandler.post(action)
|
|
// } else {
|
|
// view.post(action)
|
|
// }
|
|
// }
|
|
//
|
|
// @JvmStatic
|
|
// @TargetClass(value = "android.view.View", scope = ALL)
|
|
// @TargetMethod(methodName = "postDelayed")
|
|
// @ReplaceInvoke
|
|
// fun postDelayedOfViewProxy(view: View, action: Runnable, delayMillis: Long): Boolean {
|
|
// return if (Looper.myLooper() != Looper.getMainLooper()) {
|
|
// UiThreadHandler.postDelayed(action, delayMillis)
|
|
// } else {
|
|
// view.postDelayed(action, delayMillis)
|
|
// }
|
|
// }
|
|
}
|
|
} |