From e3e0807862228203fb2fa424a8d6783eeb874ed7 Mon Sep 17 00:00:00 2001 From: MiMoHo <37556964+MiMoHo@users.noreply.github.com> Date: Fri, 3 Jul 2026 02:34:34 +0200 Subject: [PATCH] fix(widget): move single note widget database query off the main thread SingleNoteWidget.updateAppWidget() ran the blocking Room query NotesRepository.getSingleNoteWidgetData() directly in the onReceive()/onUpdate() call chain, i.e. on the main thread (this only works at all because the database is configured with allowMainThreadQueries()). Broadcast receivers should not perform disk I/O on the main thread; on slow storage this risks jank or ANRs. The per-widget query and RemoteViews update are now submitted to the provider's existing background executor, the same pattern this class already uses for removeSingleNoteWidget() in onDeleted(). AppWidgetManager is safe to call from a background thread. Fixes #2935 Assisted-by: Claude Code:claude-fable-5 AI-assistant: Claude Code 2.1.187 (Claude Fable 5) Signed-off-by: MiMoHo <37556964+MiMoHo@users.noreply.github.com> --- .../notes/widget/singlenote/SingleNoteWidget.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.kt b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.kt index 3c7c87e19..4820e4215 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/widget/singlenote/SingleNoteWidget.kt @@ -53,13 +53,15 @@ class SingleNoteWidget : AppWidgetProvider() { private fun updateAppWidget(context: Context, awm: AppWidgetManager, appWidgetIds: IntArray) { val repo = NotesRepository.getInstance(context) appWidgetIds.forEach { appWidgetId -> - repo.getSingleNoteWidgetData(appWidgetId)?.let { data -> - val pendingIntent = getPendingIntent(context, appWidgetId) - val serviceIntent = getServiceIntent(context, appWidgetId) - val views = getRemoteViews(context, pendingIntent, serviceIntent) - awm.run { - updateAppWidget(appWidgetId, views) - notifyAppWidgetViewDataChanged(appWidgetId, R.id.single_note_widget_lv) + executor.submit { + repo.getSingleNoteWidgetData(appWidgetId)?.let { + val pendingIntent = getPendingIntent(context, appWidgetId) + val serviceIntent = getServiceIntent(context, appWidgetId) + val views = getRemoteViews(context, pendingIntent, serviceIntent) + awm.run { + updateAppWidget(appWidgetId, views) + notifyAppWidgetViewDataChanged(appWidgetId, R.id.single_note_widget_lv) + } } } }