Skip to content

Commit 1726fd4

Browse files
Collect more info for crash report
1 parent b7cc97a commit 1726fd4

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

app/src/main/kotlin/eu/fliegendewurst/triliumdroid/util/CrashReport.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package eu.fliegendewurst.triliumdroid.util
22

3+
import android.app.ActivityManager
34
import android.content.Context
45
import android.content.Intent
56
import android.net.Uri
@@ -14,6 +15,7 @@ import java.io.File
1415
import java.io.FileOutputStream
1516
import java.io.IOException
1617
import java.io.InputStreamReader
18+
import java.util.*
1719

1820

1921
object CrashReport {
@@ -31,7 +33,9 @@ object CrashReport {
3133
var bytes = "\n\n"
3234
bytes += "Thread: ${thread.name} (ID = ${thread.id})\n"
3335
bytes += "Error: ${throwable}\n"
34-
bytes += "API Level: ${Build.VERSION.SDK_INT} (${Build.VERSION.RELEASE})\n"
36+
bytes += "API Level: ${Build.VERSION.SDK_INT} (Android ${Build.VERSION.RELEASE})\n"
37+
bytes += "RAM: ${getMemorySize(context) / 1024 / 1024}MB\n"
38+
bytes += "Locale: ${Locale.getDefault().language}\n"
3539
bytes += "Stacktrace:\n"
3640
bytes += throwable.stackTraceToString()
3741
fos.write(bytes.encodeToByteArray())
@@ -121,4 +125,15 @@ object CrashReport {
121125
.show()
122126
}
123127
}
128+
129+
private fun getMemorySize(context: Context): Long {
130+
try {
131+
val actManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
132+
val memInfo = ActivityManager.MemoryInfo()
133+
actManager.getMemoryInfo(memInfo)
134+
return memInfo.totalMem
135+
} catch (_: Exception) {
136+
return 0
137+
}
138+
}
124139
}

0 commit comments

Comments
 (0)