From 784d97b8db63318518cdf1eb88abf9ffb70cefc0 Mon Sep 17 00:00:00 2001 From: renwj Date: Wed, 18 Jan 2023 15:05:34 +0800 Subject: [PATCH] =?UTF-8?q?[2.13.2]=E4=BF=AE=E6=AD=A3Android8.0=E5=8F=8A?= =?UTF-8?q?=E4=BB=A5=E5=90=8E,=E5=90=8E=E5=8F=B0=E5=BC=80=E5=90=AFService?= =?UTF-8?q?=E5=BC=95=E8=B5=B7=E7=9A=84=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 7 ++-- .../com/mogo/launcher/MogoApplication.java | 30 +---------------- .../java/com/mogo/launcher/lancet/CrashFix.kt | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 app/src/main/java/com/mogo/launcher/lancet/CrashFix.kt diff --git a/app/build.gradle b/app/build.gradle index 0b5f1cb500..9470c7c56c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,13 +52,12 @@ if (!isAndroidTestBuild()) { enableInDebug true weaveGroup { - leak_canary_crash_fix { - enable !isReleaseBuild - } - anr_fix { enable true } + crash_fix { + enable true + } } } } diff --git a/app/src/main/java/com/mogo/launcher/MogoApplication.java b/app/src/main/java/com/mogo/launcher/MogoApplication.java index 8f87eca0de..c0ce3cb4d2 100644 --- a/app/src/main/java/com/mogo/launcher/MogoApplication.java +++ b/app/src/main/java/com/mogo/launcher/MogoApplication.java @@ -1,29 +1 @@ -package com.mogo.launcher; - -import com.mogo.eagle.core.function.main.MainMoGoApplication; -import com.mogo.eagle.core.utilcode.mogo.logger.LogLevel; -import com.mogo.eagle.core.utilcode.mogo.logger.Logger; -import com.mogo.launcher.crash.CrashSystem; - -/** - * @author congtaowang - * @since 2019-12-18 - *

- * Launcher application - */ -public class MogoApplication extends MainMoGoApplication { - - @Override - protected void initCrashConfig() { - CrashSystem crashSystem = CrashSystem.getInstance(this); - crashSystem.init(); - //设置debug模式,日志不上传 - crashSystem.setDebug(BuildConfig.DEBUG); - } - - @Override - protected void initLogConfig() { - super.initLogConfig(); - Logger.init(BuildConfig.DEBUG ? LogLevel.DEBUG : LogLevel.OFF); - } -} +package com.mogo.launcher; import com.mogo.eagle.core.function.main.MainMoGoApplication; import com.mogo.eagle.core.utilcode.mogo.logger.LogLevel; import com.mogo.eagle.core.utilcode.mogo.logger.Logger; import com.mogo.launcher.crash.CrashSystem; /** * @author congtaowang * @since 2019-12-18 *

* Launcher application */ public class MogoApplication extends MainMoGoApplication { @Override protected void initCrashConfig() { CrashSystem crashSystem = CrashSystem.getInstance(this); crashSystem.init(); //设置debug模式,日志不上传 crashSystem.setDebug(BuildConfig.DEBUG); } @Override protected void initLogConfig() { super.initLogConfig(); Logger.init(BuildConfig.DEBUG ? LogLevel.DEBUG : LogLevel.OFF); } } \ No newline at end of file diff --git a/app/src/main/java/com/mogo/launcher/lancet/CrashFix.kt b/app/src/main/java/com/mogo/launcher/lancet/CrashFix.kt new file mode 100644 index 0000000000..09ae7d1c42 --- /dev/null +++ b/app/src/main/java/com/mogo/launcher/lancet/CrashFix.kt @@ -0,0 +1,32 @@ +package com.mogo.launcher.lancet + +import android.content.ComponentName +import android.content.Intent +import androidx.annotation.* +import com.knightboost.lancet.api.Origin +import com.knightboost.lancet.api.Scope.ALL +import com.knightboost.lancet.api.Scope.LEAF +import com.knightboost.lancet.api.annotations.* + +@Keep +@Weaver +@Group("crash_fix") +class CrashFix { + + /** + * 修正Android8.0及之后,后台启动Service引起的崩溃 + * java.lang.IllegalStateException: Not allowed to start service Intent { + * act=com.zhidao.cosupload.service.UPLOAD_ACTION cmp=com.mogo.launcher.f/com.zhidao.cosupload.service.UploadService }: app is in background uid UidRecord{6443b7b u0a404 LAST bg:+1m15s362ms idle change:idle procs:1 seq(0,0,0)} + */ + @Insert(mayCreateSuper = true) + @TargetClass("android.content.Context", scope = LEAF) + @TargetMethod(methodName = "startService") + fun fixStartServiceCrash(intent: Intent): ComponentName? { + return try { + Origin.call() as ComponentName? + } catch (t: Throwable) { + t.printStackTrace() + null + } + } +} \ No newline at end of file