[2.13.0]优化上传服务相关的主线程IO操作

This commit is contained in:
renwj
2022-12-29 14:42:00 +08:00
parent 44b8ff0faa
commit 17d222cf86
2 changed files with 75 additions and 0 deletions

View File

@@ -55,6 +55,10 @@ if (!isAndroidTestBuild()) {
leak_canary_crash_fix {
enable !isReleaseBuild
}
anr_fix {
enable true
}
}
}
}

View File

@@ -0,0 +1,71 @@
package com.mogo.launcher.lancet
import androidx.annotation.*
import com.knightboost.lancet.api.*
import com.knightboost.lancet.api.annotations.*
import com.knightboost.lancet.api.annotations.Weaver
import com.mogo.eagle.core.utilcode.util.*
import kotlinx.coroutines.Runnable
@Keep
@Weaver
@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"))
}
@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<String>?, 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)
}
}
}
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)
}
}
}
class ANRFixTask3(private val delegate: Any, private val methodName: String,private val productLine: String?, private val paths: List<String>?, private val eventId: String?, private val config: Any?): Runnable {
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)
}
}
}