From 9ea26b5eabc07a046547b6958f2ed117994a0837 Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:25:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/CrashHandler.kt | 12 +++++++----- .../java/io/legado/app/ui/about/AboutFragment.kt | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/CrashHandler.kt b/app/src/main/java/io/legado/app/help/CrashHandler.kt index 550faca6c271..9b1ab9b4f779 100644 --- a/app/src/main/java/io/legado/app/help/CrashHandler.kt +++ b/app/src/main/java/io/legado/app/help/CrashHandler.kt @@ -28,9 +28,6 @@ import java.io.StringWriter import java.text.SimpleDateFormat import java.util.Date import java.util.concurrent.TimeUnit -import kotlin.collections.component1 -import kotlin.collections.component2 -import kotlin.collections.set /** * 异常管理类 @@ -172,12 +169,17 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { /** * 进行堆转储 */ - fun doHeapDump() { + fun doHeapDump(manually: Boolean = false) { val heapDir = appCtx .externalCache .getFile("heapDump") heapDir.createFolderReplace() - val heapFile = heapDir.getFile("heap-dump-${System.currentTimeMillis()}.hprof") + val fileName = if (manually) { + "heap-dump-manually-${System.currentTimeMillis()}.hprof" + } else { + "heap-dump-${System.currentTimeMillis()}.hprof" + } + val heapFile = heapDir.getFile(fileName) val heapDumpName = heapFile.absolutePath Debug.dumpHprofData(heapDumpName) } diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index 2fafcdc197bd..d0a1917940a6 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -151,7 +151,7 @@ class AboutFragment : PreferenceFragmentCompat() { } appCtx.toastOnUi("开始创建堆转储") System.gc() - CrashHandler.doHeapDump() + CrashHandler.doHeapDump(true) val doc = FileDoc.fromUri(Uri.parse(backupPath), true) if (!copyHeapDump(doc)) { appCtx.toastOnUi("未找到堆转储文件")