mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
bd4aa95ff5
commit
8df1cb8ab6
@ -4,8 +4,10 @@ import android.annotation.SuppressLint
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Looper
|
||||||
import android.webkit.WebSettings
|
import android.webkit.WebSettings
|
||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.exception.NoStackTraceException
|
import io.legado.app.exception.NoStackTraceException
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.help.config.LocalConfig
|
import io.legado.app.help.config.LocalConfig
|
||||||
@ -37,10 +39,27 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
|
|||||||
* uncaughtException 回调函数
|
* uncaughtException 回调函数
|
||||||
*/
|
*/
|
||||||
override fun uncaughtException(thread: Thread, ex: Throwable) {
|
override fun uncaughtException(thread: Thread, ex: Throwable) {
|
||||||
|
if (shouldAbsorb(ex)) {
|
||||||
|
AppLog.put("发生未捕获的异常\n${ex.localizedMessage}", ex)
|
||||||
|
Looper.loop()
|
||||||
|
} else {
|
||||||
ReadAloud.stop(context)
|
ReadAloud.stop(context)
|
||||||
handleException(ex)
|
handleException(ex)
|
||||||
mDefaultHandler?.uncaughtException(thread, ex)
|
mDefaultHandler?.uncaughtException(thread, ex)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun shouldAbsorb(e: Throwable): Boolean {
|
||||||
|
return when {
|
||||||
|
e::class.simpleName == "CannotDeliverBroadcastException" -> true
|
||||||
|
e is SecurityException && e.message?.contains(
|
||||||
|
"nor current process has android.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS",
|
||||||
|
true
|
||||||
|
) == true -> true
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理该异常
|
* 处理该异常
|
||||||
@ -107,7 +126,8 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
|
|||||||
val time = format.format(Date())
|
val time = format.format(Date())
|
||||||
val fileName = "crash-$time-$timestamp.log"
|
val fileName = "crash-$time-$timestamp.log"
|
||||||
try {
|
try {
|
||||||
val backupPath = AppConfig.backupPath ?: throw NoStackTraceException("备份路径未配置")
|
val backupPath = AppConfig.backupPath
|
||||||
|
?: throw NoStackTraceException("备份路径未配置")
|
||||||
val uri = Uri.parse(backupPath)
|
val uri = Uri.parse(backupPath)
|
||||||
val fileDoc = FileDoc.fromUri(uri, true)
|
val fileDoc = FileDoc.fromUri(uri, true)
|
||||||
fileDoc.createFileIfNotExist(fileName, "crash")
|
fileDoc.createFileIfNotExist(fileName, "crash")
|
||||||
|
Loading…
Reference in New Issue
Block a user