Enable StrictMode in debug builds

This commit is contained in:
2026-10-25 12:25:23 +02:00
parent 2cb3439efd
commit 37653792fd
@@ -4,6 +4,7 @@ import android.app.Application
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import android.os.Process import android.os.Process
import android.os.StrictMode
import java.io.File import java.io.File
import java.io.PrintWriter import java.io.PrintWriter
import java.io.StringWriter import java.io.StringWriter
@@ -11,6 +12,7 @@ import java.io.StringWriter
class SparkleApp : Application() { class SparkleApp : Application() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
if (BuildConfig.DEBUG) enableStrictMode()
CrashLog.install(this) CrashLog.install(this)
Thread({ Thread({
// Reads what the first screen needs before it asks, so its first frame does not wait on storage // Reads what the first screen needs before it asks, so its first frame does not wait on storage
@@ -21,6 +23,12 @@ class SparkleApp : Application() {
runCatching { Blocklist.reload(this) } runCatching { Blocklist.reload(this) }
}, "startup-load").start() }, "startup-load").start()
} }
// Debug builds only: logs disk and network access on the main thread, leaked closeables and the like
private fun enableStrictMode() {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build())
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build())
}
} }
// Saves the last crash so it can be shown and copied on the next launch // Saves the last crash so it can be shown and copied on the next launch