Skip to content

SingleNoteWidget performs synchronous Room DB queries on main thread (may cause ANR/jank) #2935

@nbd-boss

Description

@nbd-boss

This issue respects the following points:

Describe the bug

Description

In SingleNoteWidget.kt, it performs synchronous Room database queries on the main thread.
This happens inside the onReceive()updateAppWidget()getSingleNoteWidgetData() call chain.

Where the issue occurs

onReceive() runs on the main/UI thread.
onReceive() calls updateAppWidget, and inside updateAppWidget it calls getSingleNoteWidgetData. getSingleNoteWidgetData() is a blocking Room query, and since it is executed directly in onReceive(), it blocks the main thread.

What Android recommends

According to official guidelines:

Disk I/O and DB queries must not run on the main thread.
BroadcastReceiver should do only lightweight work.
Heavy work should be moved to a background thread (Executor / Coroutine / WorkManager).

Expected behavior

Move the database read into a background thread.

Notes Android version

4.5.2

Notes server version

4.5.2

Nextcloud Android version

4.5.2

Nextcloud version

4.5.2

Device

Android Emulator

Android Version

Android Version: 13 (API 33)

App Store

  • Google Play Store
  • F-Droid
  • Huawei App Gallery

Stacktrace

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions