mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-04 06:00:11 +00:00
精简:ANR异常捕获依赖(ANR-WatchDog)
This commit is contained in:
parent
f34bfa926f
commit
d57e682e89
@ -214,9 +214,6 @@ dependencies {
|
||||
implementation 'com.zzhoujay.richtext:richtext:3.0.8'
|
||||
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'
|
||||
|
||||
|
@ -27,7 +27,6 @@ import com.idormy.sms.forwarder.service.BatteryService
|
||||
import com.idormy.sms.forwarder.service.ForegroundService
|
||||
import com.idormy.sms.forwarder.service.HttpService
|
||||
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.XBasicLibInit
|
||||
import com.idormy.sms.forwarder.utils.sdkinit.XUpdateInit
|
||||
@ -223,8 +222,6 @@ class App : Application(), CactusCallback, Configuration.Provider by Core {
|
||||
XUpdateInit.init(this)
|
||||
// 运营统计数据
|
||||
UMengInit.init(this)
|
||||
// ANR监控
|
||||
ANRWatchDogInit.init()
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
|
@ -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...")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user