mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-09 16:17:44 +00:00
try saving crash logs when device is locked
This commit is contained in:
parent
e6ec1c7bca
commit
b5837c3380
2 changed files with 14 additions and 5 deletions
|
@ -11,6 +11,7 @@ import android.os.Build
|
|||
import helium314.keyboard.latin.BuildConfig
|
||||
import helium314.keyboard.latin.settings.DebugSettings
|
||||
import helium314.keyboard.latin.settings.Defaults
|
||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.latin.utils.prefs
|
||||
import java.io.File
|
||||
|
@ -64,11 +65,17 @@ ${Log.getLog(100).joinToString("\n")}
|
|||
|
||||
private fun writeCrashReportToFile(text: String) {
|
||||
try {
|
||||
val dir = appContext.getExternalFilesDir(null) ?: return
|
||||
val dir = appContext.getExternalFilesDir(null)
|
||||
val date = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(Calendar.getInstance().time)
|
||||
val crashReportFile = File(dir, "crash_report_$date.txt")
|
||||
crashReportFile.writeText(text)
|
||||
} catch (ignored: IOException) {
|
||||
crashReportFile.appendText(text)
|
||||
} catch (_: Exception) {
|
||||
// can't write in external files dir, maybe device just booted and is still locked
|
||||
// in this case there shouldn't be any sensitive data and we can put crash logs in unprotected files dir
|
||||
val dir = DeviceProtectedUtils.getFilesDir(appContext) ?: return
|
||||
val date = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(Calendar.getInstance().time)
|
||||
val crashReportFile = File(dir, "crash_report_unprotected_$date.txt")
|
||||
crashReportFile.appendText(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import helium314.keyboard.latin.R
|
|||
import helium314.keyboard.latin.common.FileUtils
|
||||
import helium314.keyboard.latin.define.DebugFlags
|
||||
import helium314.keyboard.latin.settings.Settings
|
||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import helium314.keyboard.latin.utils.ExecutorUtils
|
||||
import helium314.keyboard.latin.utils.UncachedInputMethodManagerUtils
|
||||
import helium314.keyboard.latin.utils.cleanUnusedMainDicts
|
||||
|
@ -191,8 +192,9 @@ class SettingsActivity : ComponentActivity(), SharedPreferences.OnSharedPreferen
|
|||
|
||||
private fun findCrashReports(): List<File> {
|
||||
// find crash report files
|
||||
val dir: File = getExternalFilesDir(null) ?: return emptyList()
|
||||
val allFiles = dir.listFiles() ?: return emptyList()
|
||||
val dir = getExternalFilesDir(null)
|
||||
val unprotectedDir = DeviceProtectedUtils.getFilesDir(this)
|
||||
val allFiles = dir?.listFiles()?.toList().orEmpty() + unprotectedDir?.listFiles().orEmpty()
|
||||
return allFiles.filter { it.name.startsWith("crash_report") }
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue