mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-10-06 03:38:23 +00:00
Merge pull request #3636 from vitorpamplona/claude/strictmode-disk-read-violation-2s5q8e
Fix StrictMode DiskReadViolation in BootCompletedReceiver
This commit is contained in:
+17
-5
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user