Release v1.1.2

This commit is contained in:
2026-11-02 16:01:22 +02:00
parent 5ff10463a3
commit 54b600b1ca
40 changed files with 1480 additions and 917 deletions
@@ -5,6 +5,8 @@ import android.content.Context
import android.os.Build
import android.os.Process
import android.os.StrictMode
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import java.io.File
import java.io.PrintWriter
import java.io.StringWriter
@@ -17,22 +19,23 @@ class SparkleApp : Application() {
Thread({
// Reads what the first screen needs before it asks, so its first frame does not wait on storage
Prefs(this).providerId
CrashLog.preload(this)
CrashLog.load(this)
StatsStore.init(this)
// Older versions cached a server list downloaded from the repository
File(filesDir, "servers.txt").delete()
AutoUpdate.apply(this)
// Lists can hold millions of entries; loading them should not take CPU from the first frames
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND)
runCatching { Blocklist.reload(this) }
runCatching { Blocklist.ensureLoaded(this) }
}, "startup-load").start()
}
// The VPN keeps the process running long after the screens are gone; decoded app icons
// (up to 10 MB) can be rendered again the next time the Apps tab opens
// (up to 10 MB) and the logo can be rendered again the next time they are shown
override fun onTrimMemory(level: Int) {
super.onTrimMemory(level)
if (level >= TRIM_MEMORY_UI_HIDDEN) clearAppIconCache()
if (level >= TRIM_MEMORY_UI_HIDDEN) {
clearAppIconCache()
AppLogo.clear()
}
}
// Debug builds only: logs disk and network access on the main thread, leaked closeables and the like
@@ -46,13 +49,18 @@ class SparkleApp : Application() {
object CrashLog {
private const val FILE_NAME = "last_crash.txt"
// Null when there is no report, and until the startup thread has read it
private val _report = MutableStateFlow<String?>(null)
val report: StateFlow<String?> = _report
fun install(context: Context) {
val file = File(context.filesDir, FILE_NAME)
val appContext = context.applicationContext
val previous = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, error ->
runCatching {
val trace = StringWriter().also { error.printStackTrace(PrintWriter(it)) }.toString()
file.writeText(
// Looked up only now: install() runs on the main thread at start-up
File(appContext.filesDir, FILE_NAME).writeText(
"Thread: ${thread.name}\n" +
"Android ${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT}), " +
"${Build.MANUFACTURER} ${Build.MODEL}\n\n$trace"
@@ -62,24 +70,14 @@ object CrashLog {
}
}
@Volatile
private var preloaded = false
@Volatile
private var report: String? = null
fun preload(context: Context) {
report = load(context)
preloaded = true
// Runs on the startup thread, so the main thread never reads the file
fun load(context: Context) {
_report.value = runCatching { File(context.filesDir, FILE_NAME).takeIf { it.exists() }?.readText() }.getOrNull()
}
fun read(context: Context): String? = if (preloaded) report else load(context)
fun clear(context: Context) {
report = null
File(context.filesDir, FILE_NAME).delete()
_report.value = null
val appContext = context.applicationContext
Thread({ File(appContext.filesDir, FILE_NAME).delete() }, "crash-clear").start()
}
private fun load(context: Context): String? =
runCatching { File(context.filesDir, FILE_NAME).takeIf { it.exists() }?.readText() }.getOrNull()
}