diff --git a/app/src/main/java/com/mogo/launcher/lancet/ANRFix.kt b/app/src/main/java/com/mogo/launcher/lancet/ANRFix.kt index 878eafd753..24e9815327 100644 --- a/app/src/main/java/com/mogo/launcher/lancet/ANRFix.kt +++ b/app/src/main/java/com/mogo/launcher/lancet/ANRFix.kt @@ -1,10 +1,15 @@ 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 @@ -12,60 +17,66 @@ import kotlinx.coroutines.Runnable @Group("anr_fix") class ANRFix { - @Insert - @TargetClass("com.zhidao.cosupload.service.UploadService") - @TargetMethod(methodName = "addUploadPaths") - private fun fixAddUploadPathsANR() { - ThreadUtils.getIoPool().execute(ANRFixTask(This.get(), "addUploadPaths")) - } + companion object { - @Insert - @TargetClass("com.zhidao.cosupload.service.UploadService") - @TargetMethod(methodName = "upload") - private fun fixUploadANR(@ClassOf("com.zhidao.cosupload.model.CacheUploadIdData") data: Any?) { - ThreadUtils.getIoPool().execute(ANRFixTask2(This.get(), "upload", data)) - } - - @Insert - @TargetClass("com.zhidao.cosupload.manager.CosUploadManagerImpl") - @TargetMethod(methodName = "upload") - private fun fixCosUploadManagerImplANR(productLine: String?, paths: List?, eventId: String?, @ClassOf("com.zhidao.cosupload.DbPriorityConfig") config: Any?) { - ThreadUtils.getIoPool().execute(ANRFixTask3(This.get(), "upload", productLine, paths, eventId, config)) - } -} - -class ANRFixTask(private val delegate: Any, private val methodName: String): Runnable { - - override fun run() { - delegate.javaClass.declaredMethods.find { - it.name != methodName && it.name.contains(methodName) - }?.also { - it.isAccessible = true - it.invoke(delegate) + @JvmStatic + @TargetClass(value = "android.os.Handler", scope = ALL) + @TargetMethod(methodName = "post") + @ReplaceInvoke + fun handlerPostProxy(handler: Handler, action: Runnable): Boolean { + val what = ObjectHashCodeUtils.getHashCodeIfNeed(action) + handler.removeMessages(what) + val msg = Message.obtain(handler, action) + msg.what = what + return handler.sendMessage(msg) } - } -} -class ANRFixTask2(private val delegate: Any, private val methodName: String, private val p: Any?): Runnable { - - override fun run() { - delegate.javaClass.declaredMethods.find { - it.name != methodName && it.name.contains(methodName) - }?.also { - it.isAccessible = true - it.invoke(delegate, p) + @JvmStatic + @TargetClass(value = "android.os.Handler", scope = ALL) + @TargetMethod(methodName = "postDelayed") + @ReplaceInvoke + fun handlerPostDelayProxy(handler: Handler, action: Runnable, delayMillis: Long): Boolean { + val what = ObjectHashCodeUtils.getHashCodeIfNeed(action) + handler.removeMessages(what) + val msg = Message.obtain(handler, action) + msg.what = what + return handler.sendMessageDelayed(msg, delayMillis) } - } -} -class ANRFixTask3(private val delegate: Any, private val methodName: String,private val productLine: String?, private val paths: List?, private val eventId: String?, private val config: Any?): Runnable { + @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) + } + } - override fun run() { - delegate.javaClass.declaredMethods.find { - it.name != methodName && it.name.contains(methodName) - }?.also { - it.isAccessible = true - it.invoke(delegate, productLine, paths, eventId, config) + @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) + } } } } \ No newline at end of file diff --git a/app/src/main/java/com/mogo/launcher/lancet/MemoryLeakFix.kt b/app/src/main/java/com/mogo/launcher/lancet/MemoryLeakFix.kt index dff034aefa..6a204380c9 100644 --- a/app/src/main/java/com/mogo/launcher/lancet/MemoryLeakFix.kt +++ b/app/src/main/java/com/mogo/launcher/lancet/MemoryLeakFix.kt @@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentHashMap @Group("memory_leak") class MemoryLeakFix { - @NameRegex("(com\\.mogo|com\\.zhidao|com\\.elegant|com\\.zhidaoauto|com\\.zhjt).*") + @NameRegex("(com\\.zhidao|com\\.elegant|com\\.zhidaoauto|com\\.zhjt|com\\.mogo(?!(\\.thread\\.ext|\\.launcher\\.lancet))).*") @Insert(mayCreateSuper = true) @ImplementedInterface("java.lang.Runnable", scope = LEAF) @TargetMethod(methodName = "run") diff --git a/app/src/main/java/com/mogo/launcher/lancet/TextViewSetTextOpt.java b/app/src/main/java/com/mogo/launcher/lancet/TextViewOpt.java similarity index 97% rename from app/src/main/java/com/mogo/launcher/lancet/TextViewSetTextOpt.java rename to app/src/main/java/com/mogo/launcher/lancet/TextViewOpt.java index ad11c130cd..328132eb55 100644 --- a/app/src/main/java/com/mogo/launcher/lancet/TextViewSetTextOpt.java +++ b/app/src/main/java/com/mogo/launcher/lancet/TextViewOpt.java @@ -13,7 +13,7 @@ import com.knightboost.lancet.api.annotations.Weaver; @Weaver @Group("textview_opt") -public class TextViewSetTextOpt { +public class TextViewOpt { @NameRegex("(com\\.mogo|com\\.zhidao|com\\.elegant|com\\.zhidaoauto|com\\.zhjt).*") @TargetClass(value = "android.widget.TextView",scope = Scope.ALL) diff --git a/core/function-impl/mogo-core-function-chat/src/main/java/com/mogo/eagle/core/function/chat/facade/gme/Gme.kt b/core/function-impl/mogo-core-function-chat/src/main/java/com/mogo/eagle/core/function/chat/facade/gme/Gme.kt index 3865a31b07..f60dbf14f6 100644 --- a/core/function-impl/mogo-core-function-chat/src/main/java/com/mogo/eagle/core/function/chat/facade/gme/Gme.kt +++ b/core/function-impl/mogo-core-function-chat/src/main/java/com/mogo/eagle/core/function/chat/facade/gme/Gme.kt @@ -219,12 +219,12 @@ internal object GmePoller { if (ITMGContext.GetInstance(null) != null) { ITMGContext.GetInstance(null).Poll() } - handler.postDelayed(this, 30) + handler.postDelayed(this, 1000) } } internal fun start() { - handler.postDelayed(poll, 30) + handler.postDelayed(poll, 2000) } internal fun stop() { diff --git a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/ObjectHashCodeUtils.java b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/ObjectHashCodeUtils.java index 026c8fcef2..b860b5319e 100644 --- a/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/ObjectHashCodeUtils.java +++ b/core/mogo-core-utils/src/main/java/com/mogo/eagle/core/utilcode/util/ObjectHashCodeUtils.java @@ -21,7 +21,7 @@ public class ObjectHashCodeUtils { if (value != null) { return value; } - int hashCode = System.identityHashCode(obj); + int hashCode = - System.identityHashCode(obj); hashCodes.put(name, hashCode); return hashCode; }