精简:ANR异常捕获依赖(ANR-WatchDog)

This commit is contained in:
pppscn 2022-06-13 17:17:32 +08:00
parent f34bfa926f
commit d57e682e89
3 changed files with 0 additions and 70 deletions

View File

@ -214,9 +214,6 @@ dependencies {
implementation 'com.zzhoujay.richtext:richtext:3.0.8' implementation 'com.zzhoujay.richtext:richtext:3.0.8'
implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:retrofit:2.9.0'
//ANR异常捕获
implementation 'com.github.anrwatchdog:anrwatchdog:1.4.0'
// //
implementation 'com.meituan.android.walle:library:1.1.6' implementation 'com.meituan.android.walle:library:1.1.6'

View File

@ -27,7 +27,6 @@ import com.idormy.sms.forwarder.service.BatteryService
import com.idormy.sms.forwarder.service.ForegroundService import com.idormy.sms.forwarder.service.ForegroundService
import com.idormy.sms.forwarder.service.HttpService import com.idormy.sms.forwarder.service.HttpService
import com.idormy.sms.forwarder.utils.* import com.idormy.sms.forwarder.utils.*
import com.idormy.sms.forwarder.utils.sdkinit.ANRWatchDogInit
import com.idormy.sms.forwarder.utils.sdkinit.UMengInit import com.idormy.sms.forwarder.utils.sdkinit.UMengInit
import com.idormy.sms.forwarder.utils.sdkinit.XBasicLibInit import com.idormy.sms.forwarder.utils.sdkinit.XBasicLibInit
import com.idormy.sms.forwarder.utils.sdkinit.XUpdateInit import com.idormy.sms.forwarder.utils.sdkinit.XUpdateInit
@ -223,8 +222,6 @@ class App : Application(), CactusCallback, Configuration.Provider by Core {
XUpdateInit.init(this) XUpdateInit.init(this)
// 运营统计数据 // 运营统计数据
UMengInit.init(this) UMengInit.init(this)
// ANR监控
ANRWatchDogInit.init()
} }
@SuppressLint("CheckResult") @SuppressLint("CheckResult")

View File

@ -1,64 +0,0 @@
@file:Suppress("MemberVisibilityCanBePrivate")
package com.idormy.sms.forwarder.utils.sdkinit
import com.github.anrwatchdog.ANRError
import com.github.anrwatchdog.ANRWatchDog
import com.github.anrwatchdog.ANRWatchDog.ANRListener
import com.xuexiang.xutil.common.logger.Logger
/**
* ANR看门狗监听器初始化
*
* @author xuexiang
* @since 2020-02-18 15:08
*/
@Suppress("unused", "MemberVisibilityCanBePrivate")
class ANRWatchDogInit private constructor() {
companion object {
private const val TAG = "ANRWatchDog"
/**
* ANR看门狗
*/
var aNRWatchDog: ANRWatchDog? = null
private set
/**
* ANR监听触发的时间
*/
private const val ANR_DURATION = 4000
/**
* ANR静默处理就是不处理直接记录一下日志
*/
private val SILENT_LISTENER = ANRListener { error: ANRError? -> Logger.eTag(TAG, error) }
/**
* ANR自定义处理可以是记录日志用于上传
*/
private val CUSTOM_LISTENER = ANRListener { error: ANRError? ->
Logger.eTag(TAG, "Detected Application Not Responding!", error)
throw error!!
}
fun init() {
//这里设置监听的间隔为2秒
aNRWatchDog = ANRWatchDog(2000)
aNRWatchDog!!.setANRInterceptor { duration: Long ->
val ret = ANR_DURATION - duration
if (ret > 0) {
Logger.wTag(
TAG,
"Intercepted ANR that is too short ($duration ms), postponing for $ret ms."
)
}
ret
}.setANRListener(SILENT_LISTENER).start()
}
}
init {
throw UnsupportedOperationException("u can't instantiate me...")
}
}