From 20e86b8998f465242fc02b73f1ea1592aca94d70 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 18 Jul 2026 14:39:03 +0000 Subject: [PATCH] fix: move BootCompletedReceiver disk read off the main thread isEnabled() reads plain SharedPreferences (a synchronous disk read, by design) and scans the accounts cache. Since onReceive runs on the main thread, this triggered a StrictMode DiskReadViolation at boot. Wrap the work in goAsync() + a background thread so it runs off the main thread while keeping the receiver alive until the check completes. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01P4tx1QSE27uoDpnxZZ7msT --- .../notifications/BootCompletedReceiver.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/BootCompletedReceiver.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/BootCompletedReceiver.kt index 40a9a2ab99..3f2d0a8374 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/BootCompletedReceiver.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/BootCompletedReceiver.kt @@ -50,11 +50,23 @@ class BootCompletedReceiver : BroadcastReceiver() { "android.intent.action.QUICKBOOT_POWERON", Intent.ACTION_MY_PACKAGE_REPLACED, -> { - Log.d(TAG) { "Received ${intent.action}, checking if notification service should start" } - if (NotificationRelayService.isEnabled(context)) { - Log.d(TAG, "Starting notification relay service") - NotificationRelayService.start(context) - } + // isEnabled() reads plain SharedPreferences (a synchronous disk read, by + // design — see LocalPreferences.globalSettingsPrefs) and scans the accounts + // cache. onReceive runs on the main thread, so hop off it via goAsync() to + // avoid a StrictMode DiskReadViolation while keeping the receiver alive until + // the work finishes. + val pending = goAsync() + Thread { + try { + Log.d(TAG) { "Received ${intent.action}, checking if notification service should start" } + if (NotificationRelayService.isEnabled(context)) { + Log.d(TAG, "Starting notification relay service") + NotificationRelayService.start(context) + } + } finally { + pending.finish() + } + }.start() } } }