From c5946610a8228319dc757ac505e303d3b3149eb5 Mon Sep 17 00:00:00 2001 From: renwj Date: Tue, 26 Dec 2023 15:08:59 +0800 Subject: [PATCH] =?UTF-8?q?[6.2.6][=E6=8A=80=E6=9C=AF=E4=BC=98=E5=8C=96]?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96View=20post=E5=92=8CActivity=20runOnUiThre?= =?UTF-8?q?ad=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/lancet/jank/ui/UiPostLancet.kt | 61 ++++++++++++++++--- config.gradle | 2 +- .../mogo-core-res/src/main/res/values/ids.xml | 1 + 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/app/src/block/java/com/mogo/launcher/lancet/jank/ui/UiPostLancet.kt b/app/src/block/java/com/mogo/launcher/lancet/jank/ui/UiPostLancet.kt index f45b8f5750..4b8add0333 100644 --- a/app/src/block/java/com/mogo/launcher/lancet/jank/ui/UiPostLancet.kt +++ b/app/src/block/java/com/mogo/launcher/lancet/jank/ui/UiPostLancet.kt @@ -1,6 +1,7 @@ package com.mogo.launcher.lancet.jank.ui import android.app.Activity +import android.os.SystemClock import android.view.View import com.knightboost.lancet.api.Scope import com.knightboost.lancet.api.annotations.Group @@ -10,11 +11,28 @@ import com.knightboost.lancet.api.annotations.TargetMethod import com.knightboost.lancet.api.annotations.Weaver import com.mogo.eagle.core.block.runtime.message.Message import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager +import com.mogo.launcher.R @Weaver @Group("main_block_check") class UiPostLancet { + + class ActionWrapper(private val extra:Map, private val delegate: Runnable): Runnable { + + override fun run() { + val startTime = SystemClock.uptimeMillis() + try { + delegate.run() + } finally { + val duration = SystemClock.uptimeMillis() - startTime + CallerDevaToolsManager.block()?.takeIf { + it.hasInit() + }?.recorder()?.recycle(Message.acquire(handler = null, action = delegate, duration = duration, extra = extra)) + } + } + } + companion object { @JvmStatic @@ -22,12 +40,13 @@ class UiPostLancet { @TargetMethod(methodName = "runOnUiThread") @ReplaceInvoke fun runOnUiThreadOfActivity(activity: Activity, action: Runnable) { + val extra = mapOf(activity.javaClass.name to "runOnUiThread") try { - activity.runOnUiThread(action) + activity.runOnUiThread(ActionWrapper(extra, action)) } finally { CallerDevaToolsManager.block()?.takeIf { it.hasInit() - }?.recorder()?.insert(Message.acquire(handler = null, action = action, extra = mapOf(activity.javaClass.name to "runOnUiThread"))) + }?.recorder()?.insert(Message.acquire(handler = null, action = action, extra = extra)) } } @@ -36,12 +55,20 @@ class UiPostLancet { @TargetMethod(methodName = "post") @ReplaceInvoke fun post(view: View, action: Runnable): Boolean { - return try { - view.post(action) + val extra = mapOf(view.javaClass.name to "post") + try { + var map = view.getTag(R.id.action_wrapper_tag_id) as? HashMap + if (map == null) { + map = HashMap() + view.setTag(R.id.action_wrapper_tag_id, map) + } + val wrapper = ActionWrapper(extra, action) + map[action] = wrapper + return view.post(wrapper) } finally { CallerDevaToolsManager.block()?.takeIf { it.hasInit() - }?.recorder()?.insert(Message.acquire(handler = null, action = action, extra = mapOf(view.javaClass.name to "post"))) + }?.recorder()?.insert(Message.acquire(handler = null, action = action, extra = extra)) } } @@ -50,12 +77,20 @@ class UiPostLancet { @TargetMethod(methodName = "postDelayed") @ReplaceInvoke fun postDelayed(view: View, action: Runnable, delayMillis: Long): Boolean { - return try { - view.postDelayed(action, delayMillis) + val extra = mapOf(view.javaClass.name to "postDelayed") + try { + var map = view.getTag(R.id.action_wrapper_tag_id) as? HashMap + if (map == null) { + map = HashMap() + view.setTag(R.id.action_wrapper_tag_id, map) + } + val wrapper = ActionWrapper(extra, action) + map[action] = wrapper + return view.postDelayed(wrapper, delayMillis) } finally { CallerDevaToolsManager.block()?.takeIf { it.hasInit() - }?.recorder()?.insert(Message.acquire(handler = null, action = action, delay = delayMillis, extra = mapOf(view.javaClass.name to "postDelayed"))) + }?.recorder()?.insert(Message.acquire(handler = null, action = action, delay = delayMillis, extra = extra)) } } @@ -64,8 +99,14 @@ class UiPostLancet { @TargetMethod(methodName = "removeCallbacks") @ReplaceInvoke fun removeCallbacks(view: View, action: Runnable): Boolean { - return try { - view.removeCallbacks(action) + try { + val tag = view.getTag(R.id.action_wrapper_tag_id) + if (tag != null && tag is HashMap<*, *>) { + (tag.remove(action) as? Runnable)?.also { + return view.removeCallbacks(it) + } + } + return false } finally { CallerDevaToolsManager.block()?.takeIf { it.hasInit() diff --git a/config.gradle b/config.gradle index bb0e778323..13f02464d7 100644 --- a/config.gradle +++ b/config.gradle @@ -228,7 +228,7 @@ ext { passport_secret : "com.zhidaoauto:sdk-java:1.0.5-SNAPSHOT", // 主线程卡顿监测 - block_detector : "com.mogo.eagle.core.block:runtime:10.90.50", + block_detector : "com.mogo.eagle.core.block:runtime:10.90.60", //======================== google auto-service =============== google_auto_service : "com.google.auto.service:auto-service:1.0-rc7", diff --git a/core/mogo-core-res/src/main/res/values/ids.xml b/core/mogo-core-res/src/main/res/values/ids.xml index 07e922177b..95e122fa17 100644 --- a/core/mogo-core-res/src/main/res/values/ids.xml +++ b/core/mogo-core-res/src/main/res/values/ids.xml @@ -4,4 +4,5 @@ + \ No newline at end of file