mirror of
https://github.com/gedoor/legado.git
synced 2024-07-19 01:17:25 +08:00
优化
This commit is contained in:
parent
2720898214
commit
e6d181a5fd
@ -50,6 +50,7 @@ class App : Application() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
LogUtils.d("App", "onCreate")
|
LogUtils.d("App", "onCreate")
|
||||||
|
LogUtils.logDeviceInfo()
|
||||||
oldConfig = Configuration(resources.configuration)
|
oldConfig = Configuration(resources.configuration)
|
||||||
CrashHandler(this)
|
CrashHandler(this)
|
||||||
//预下载Cronet so
|
//预下载Cronet so
|
||||||
|
@ -30,6 +30,8 @@ import io.legado.app.utils.sendMail
|
|||||||
import io.legado.app.utils.sendToClip
|
import io.legado.app.utils.sendToClip
|
||||||
import io.legado.app.utils.showDialogFragment
|
import io.legado.app.utils.showDialogFragment
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -125,31 +127,8 @@ class AboutFragment : PreferenceFragmentCompat() {
|
|||||||
return@async
|
return@async
|
||||||
}
|
}
|
||||||
val doc = FileDoc.fromUri(Uri.parse(backupPath), true)
|
val doc = FileDoc.fromUri(Uri.parse(backupPath), true)
|
||||||
val files = FileDoc.fromFile(File(appCtx.externalCacheDir, "logs")).list()
|
copyLogs(doc)
|
||||||
if (!files.isNullOrEmpty()) {
|
copyHeapDump(doc)
|
||||||
doc.find("logs")?.delete()
|
|
||||||
val logsDoc = doc.createFolderIfNotExist("logs")
|
|
||||||
files.forEach { file ->
|
|
||||||
file.openInputStream().getOrNull()?.use { input ->
|
|
||||||
logsDoc.createFileIfNotExist(file.name).openOutputStream().getOrNull()
|
|
||||||
?.use {
|
|
||||||
input.copyTo(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val heapFile = FileDoc.fromFile(File(appCtx.externalCacheDir, "heapDump")).list()
|
|
||||||
?.firstOrNull()
|
|
||||||
if (heapFile != null) {
|
|
||||||
doc.find("heapDump")?.delete()
|
|
||||||
val heapDumpDoc = doc.createFolderIfNotExist("heapDump")
|
|
||||||
heapFile.openInputStream().getOrNull()?.use { input ->
|
|
||||||
heapDumpDoc.createFileIfNotExist(heapFile.name).openOutputStream().getOrNull()
|
|
||||||
?.use {
|
|
||||||
input.copyTo(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
appCtx.toastOnUi("已保存至备份目录")
|
appCtx.toastOnUi("已保存至备份目录")
|
||||||
}.onError {
|
}.onError {
|
||||||
AppLog.put("保存日志出错\n${it.localizedMessage}", it, true)
|
AppLog.put("保存日志出错\n${it.localizedMessage}", it, true)
|
||||||
@ -165,12 +144,39 @@ class AboutFragment : PreferenceFragmentCompat() {
|
|||||||
appCtx.toastOnUi("开始创建堆转储")
|
appCtx.toastOnUi("开始创建堆转储")
|
||||||
System.gc()
|
System.gc()
|
||||||
CrashHandler.doHeapDump()
|
CrashHandler.doHeapDump()
|
||||||
val heapFile = FileDoc.fromFile(File(appCtx.externalCacheDir, "heapDump")).list()
|
|
||||||
?.firstOrNull() ?: let {
|
|
||||||
appCtx.toastOnUi("未找到堆转储文件")
|
|
||||||
return@async
|
|
||||||
}
|
|
||||||
val doc = FileDoc.fromUri(Uri.parse(backupPath), true)
|
val doc = FileDoc.fromUri(Uri.parse(backupPath), true)
|
||||||
|
if (!copyHeapDump(doc)) {
|
||||||
|
appCtx.toastOnUi("未找到堆转储文件")
|
||||||
|
} else {
|
||||||
|
appCtx.toastOnUi("已保存至备份目录")
|
||||||
|
}
|
||||||
|
}.onError {
|
||||||
|
AppLog.put("保存堆转储失败\n${it.localizedMessage}", it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun copyLogs(doc: FileDoc) = coroutineScope {
|
||||||
|
val files = FileDoc.fromFile(File(appCtx.externalCacheDir, "logs")).list()
|
||||||
|
if (files.isNullOrEmpty()) {
|
||||||
|
return@coroutineScope
|
||||||
|
}
|
||||||
|
doc.find("logs")?.delete()
|
||||||
|
val logsDoc = doc.createFolderIfNotExist("logs")
|
||||||
|
files.forEach { file ->
|
||||||
|
launch {
|
||||||
|
file.openInputStream().getOrNull()?.use { input ->
|
||||||
|
logsDoc.createFileIfNotExist(file.name).openOutputStream().getOrNull()
|
||||||
|
?.use {
|
||||||
|
input.copyTo(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun copyHeapDump(doc: FileDoc): Boolean {
|
||||||
|
val heapFile = FileDoc.fromFile(File(appCtx.externalCacheDir, "heapDump")).list()
|
||||||
|
?.firstOrNull() ?: return false
|
||||||
doc.find("heapDump")?.delete()
|
doc.find("heapDump")?.delete()
|
||||||
val heapDumpDoc = doc.createFolderIfNotExist("heapDump")
|
val heapDumpDoc = doc.createFolderIfNotExist("heapDump")
|
||||||
heapFile.openInputStream().getOrNull()?.use { input ->
|
heapFile.openInputStream().getOrNull()?.use { input ->
|
||||||
@ -179,10 +185,7 @@ class AboutFragment : PreferenceFragmentCompat() {
|
|||||||
input.copyTo(it)
|
input.copyTo(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
appCtx.toastOnUi("已保存至备份目录")
|
return true
|
||||||
}.onError {
|
|
||||||
AppLog.put("保存堆转储失败\n${it.localizedMessage}", it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -174,6 +174,7 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
|
|
||||||
PreferKey.recordLog -> {
|
PreferKey.recordLog -> {
|
||||||
LogUtils.upLevel()
|
LogUtils.upLevel()
|
||||||
|
LogUtils.logDeviceInfo()
|
||||||
LiveEventBus.config().enableLogger(AppConfig.recordLog)
|
LiveEventBus.config().enableLogger(AppConfig.recordLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,10 @@
|
|||||||
package io.legado.app.utils
|
package io.legado.app.utils
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.os.Build
|
||||||
|
import android.webkit.WebSettings
|
||||||
import io.legado.app.BuildConfig
|
import io.legado.app.BuildConfig
|
||||||
|
import io.legado.app.constant.AppConst
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@ -107,6 +110,33 @@ object LogUtils {
|
|||||||
val sdf = SimpleDateFormat(pattern)
|
val sdf = SimpleDateFormat(pattern)
|
||||||
return sdf.format(date)
|
return sdf.format(date)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun logDeviceInfo() {
|
||||||
|
d("DeviceInfo") {
|
||||||
|
buildString {
|
||||||
|
kotlin.runCatching {
|
||||||
|
//获取系统信息
|
||||||
|
append("MANUFACTURER=").append(Build.MANUFACTURER).append("\n")
|
||||||
|
append("BRAND=").append(Build.BRAND).append("\n")
|
||||||
|
append("MODEL=").append(Build.MODEL).append("\n")
|
||||||
|
append("SDK_INT=").append(Build.VERSION.SDK_INT).append("\n")
|
||||||
|
append("RELEASE=").append(Build.VERSION.RELEASE).append("\n")
|
||||||
|
val userAgent = try {
|
||||||
|
WebSettings.getDefaultUserAgent(appCtx)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
e.localizedMessage ?: "null"
|
||||||
|
}
|
||||||
|
append("WebViewUserAgent=").append(userAgent).append("\n")
|
||||||
|
//获取app版本信息
|
||||||
|
AppConst.appInfo.let {
|
||||||
|
append("versionName=").append(it.versionName).append("\n")
|
||||||
|
append("versionCode=").append(it.versionCode).append("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Throwable.printOnDebug() {
|
fun Throwable.printOnDebug() {
|
||||||
|
Loading…
Reference in New Issue
Block a user