aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt b/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt
index 82ecc9d..2bdbcca 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/common/RecentCrashHandler.kt
@@ -19,17 +19,20 @@
19package org.pacien.tincapp.activities.common 19package org.pacien.tincapp.activities.common
20 20
21import android.support.v7.app.AlertDialog 21import android.support.v7.app.AlertDialog
22import org.apache.commons.io.input.ReversedLinesFileReader
22import org.pacien.tincapp.R 23import org.pacien.tincapp.R
23import org.pacien.tincapp.activities.BaseActivity 24import org.pacien.tincapp.activities.BaseActivity
24import org.pacien.tincapp.context.App 25import org.pacien.tincapp.context.App
25import org.pacien.tincapp.context.AppPaths 26import org.pacien.tincapp.context.AppPaths
26import org.pacien.tincapp.context.CrashRecorder 27import org.pacien.tincapp.context.CrashRecorder
28import java.io.File
27 29
28/** 30/**
29 * @author pacien 31 * @author pacien
30 */ 32 */
31class RecentCrashHandler(private val parentActivity: BaseActivity) { 33class RecentCrashHandler(private val parentActivity: BaseActivity) {
32 private val resources by lazy { parentActivity.resources!! } 34 private val resources by lazy { parentActivity.resources!! }
35 private val maxLines = 1000
33 36
34 fun handleRecentCrash() { 37 fun handleRecentCrash() {
35 if (!CrashRecorder.hasPreviouslyCrashed()) return 38 if (!CrashRecorder.hasPreviouslyCrashed()) return
@@ -53,6 +56,17 @@ class RecentCrashHandler(private val parentActivity: BaseActivity) {
53 App.sendMail( 56 App.sendMail(
54 resources.getString(R.string.crash_modal_dev_email), 57 resources.getString(R.string.crash_modal_dev_email),
55 listOf(R.string.app_name, R.string.crash_modal_title).joinToString(" / ", transform = resources::getString), 58 listOf(R.string.app_name, R.string.crash_modal_title).joinToString(" / ", transform = resources::getString),
56 AppPaths.appLogFile().let { if (it.exists()) it.readText() else "" } 59 AppPaths.appLogFile().let { if (it.exists()) it.readLastLines(maxLines) else "" }
57 ) 60 )
61
62 private fun File.readLastLines(n: Int): String {
63 val reader = ReversedLinesFileReader(this, Charsets.UTF_8)
64 val lastLines = generateSequence(reader::readLine)
65 .takeWhile { line: String? -> line != null }
66 .take(n)
67 .toList()
68 .asReversed()
69
70 return lastLines.joinToString("\n")
71 }
58} 72}