zhanghai / zhanghai/MaterialFiles
[Bug] Potential Main thread blocking via synchronous ContentResolver#query in DocumentUri.kt
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 9k
- Forks
- 736
- PR merge metrics
- No merged PRs in 30d
Description
Hi Material Files Team,
I’m a PhD student researching Android performance issues. My research group recently ran a static analysis scan for thread-affinity and main-thread blocking bugs, and our prototype flagged a potential issue in Material Files.
Checked target
- APK-level caller:
me.zhanghai.android.files.file.DocumentUriKt#getDisplayName-B0AdpUI - Detected API:
android.content.ContentResolver#query - Observed context:
main/UIthread - Expected context:
worker/backgroundthread
What I found
The analyzer reported that the app call:
contentResolver.query(
from a main/UI-thread path.
Verified bug trace
me.zhanghai.android.files.file.DocumentUriKt#getDisplayName-B0AdpUI
-> source location: app/src/main/java/me/zhanghai/android/files/file/DocumentUri.kt:43
-> source call: contentResolver.query(
-> ContentResolver dispatches synchronous provider/storage work
-> backing provider may perform Binder, disk, or document-provider I/O before returning
-> analyzer/source audit observed context: main/UI thread
-> expected context: worker/background thread
-> possible UI freeze / delayed response / jank / ANR risk
Source context used for verification:
41: get() {
42: try {
> 43: contentResolver.query(
44: value, arrayOf(DocumentsContract.Document.COLUMN_DISPLAY_NAME), null, null, null
45: ).use { cursor ->
Why this matters
Running the I/O operations synchronously on the UI thread can make Material Files feel frozen or delayed on slower devices, large datasets, or slow providers.
Possible fix
A possible fix is to move the blocking I/O, database, media, or system-service operation to a worker context and post only UI updates back to the main thread.
lifecycleScope.launch {
val result = withContext(Dispatchers.IO) {
performBlockingOperation()
}
renderResult(result)
}
Reference
- Source evidence:
app/src/main/java/me/zhanghai/android/files/file/DocumentUri.kt:43 - Reference: https://developer.android.com/reference/android/content/ContentResolver#query(android.net.Uri,%20java.lang.String[],%20java.lang.String,%20java.lang.String[],%20java.lang.String)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at app/src/main/java/me/zhanghai/android/files/file/DocumentUri.kt:43 and inspect DocumentUriKt#getDisplayName-B0AdpUI plus its callers to confirm the thread context around ContentResolver#query. Determine how the existing code handles background work, then verify that the query no longer blocks the main/UI thread while display-name behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100