1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 06:37:30 +00:00

Few CrashReporterHelper changes

This commit is contained in:
Ammar Githam 2021-07-12 00:30:16 +09:00
parent dc6f60e70d
commit 573ea61bb8

View File

@ -15,15 +15,18 @@ import java.time.LocalDateTime
object CrashReporterHelper { object CrashReporterHelper {
private val shortBorder = "=".repeat(14) private val shortBorder = "=".repeat(14)
private val longBorder = "=".repeat(21) private val longBorder = "=".repeat(21)
private const val prefix = "stack-"
private const val suffix = ".stacktrace"
fun startErrorReporterActivity( fun startErrorReporterActivity(
application: Application, application: Application,
exception: Throwable exception: Throwable
) { ) {
val errorContent = getReportContent(exception)
try { try {
application.openFileOutput("stack-" + System.currentTimeMillis() + ".stacktrace", Context.MODE_PRIVATE) application.openFileOutput(
.use { trace -> trace.write(errorContent.toByteArray()) } "$prefix${System.currentTimeMillis()}$suffix",
Context.MODE_PRIVATE
).use { it.write(getReportContent(exception).toByteArray()) }
} catch (ex: Exception) { } catch (ex: Exception) {
if (BuildConfig.DEBUG) Log.e(TAG, "", ex) if (BuildConfig.DEBUG) Log.e(TAG, "", ex)
} }
@ -88,7 +91,7 @@ object CrashReporterHelper {
dir.delete() dir.delete()
} }
dir.mkdirs() dir.mkdirs()
dir.list { _: File?, name: String -> name.endsWith(".stacktrace") } dir.list { _: File?, name: String -> name.endsWith(suffix) }
} catch (e: Exception) { } catch (e: Exception) {
null null
} }
@ -136,7 +139,7 @@ object CrashReporterHelper {
dir.delete() dir.delete()
} }
dir.mkdirs() dir.mkdirs()
dir.listFiles { _: File?, name: String -> name.endsWith(".stacktrace") } dir.listFiles { _: File?, name: String -> name.endsWith(suffix) }
} catch (e: Exception) { } catch (e: Exception) {
null null
} }