优化
This commit is contained in:
@@ -141,6 +141,7 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
|
|||||||
printWriter.close()
|
printWriter.close()
|
||||||
val result = writer.toString()
|
val result = writer.toString()
|
||||||
sb.append(result)
|
sb.append(result)
|
||||||
|
val crashLog = sb.toString()
|
||||||
val timestamp = System.currentTimeMillis()
|
val timestamp = System.currentTimeMillis()
|
||||||
val time = format.format(Date())
|
val time = format.format(Date())
|
||||||
val fileName = "crash-$time-$timestamp.log"
|
val fileName = "crash-$time-$timestamp.log"
|
||||||
@@ -150,19 +151,19 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
|
|||||||
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")
|
||||||
.writeText(sb.toString())
|
.writeText(crashLog)
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
kotlin.runCatching {
|
||||||
appCtx.externalCacheDir?.let { rootFile ->
|
appCtx.externalCacheDir?.let { rootFile ->
|
||||||
|
val exceedTimeMillis = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7)
|
||||||
rootFile.getFile("crash").listFiles()?.forEach {
|
rootFile.getFile("crash").listFiles()?.forEach {
|
||||||
if (it.lastModified() < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(
|
if (it.lastModified() < exceedTimeMillis) {
|
||||||
7
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
it.delete()
|
it.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FileUtils.createFileIfNotExist(rootFile, "crash", fileName)
|
FileUtils.createFileIfNotExist(rootFile, "crash", fileName)
|
||||||
.writeText(sb.toString())
|
.writeText(crashLog)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user