facebook / facebook/fresco

I/O on main thread (android.content.ContentResolver.getType)

Open
#2,555 1 comment 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
17.2k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

### Description

It seems on one of my test devices I am running into some laggy-ness when scrolling quickly through a recyclerview. This seems to be caused by a call to `ContentResolver.getType` which further down the trace does a SQLite query.

```
2020-10-30 10:14:14.704 26966-26966/x.x.x/D/StrictMode: StrictMode policy violation; ~duration=47 ms: android.os.strictmode.DiskReadViolation
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1556)
at android.database.sqlite.SQLiteConnection.applyBlockGuardPolicy(SQLiteConnection.java:1138)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:939)
at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:838)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:153)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:140)
at com.android.providers.media.MediaProvider.queryForSingleItem(MediaProvider.java:6069)
at com.android.providers.media.MediaProvider.getType(MediaProvider.java:2259)
at android.content.ContentProvider$Transport.getType(ContentProvider.java:293)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:150)
at android.os.Binder.execTransactInternal(Binder.java:1032)
at android.os.Binder.execTransact(Binder.java:1005)
# via Binder call with stack:
at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:2274)
at android.os.Parcel.readExceptionCode(Parcel.java:2017)
at android.os.Parcel.readException(Parcel.java:1984)
at android.app.IActivityManager$Stub$Proxy.getProviderMimeType(IActivityManager.java:7171)
at android.content.ContentResolver.getType(ContentResolver.java:755)
at com.facebook.imagepipeline.core.ProducerSequenceFactory.getBasicDecodedImageSequence(ProducerSequenceFactory.java:361)
at com.facebook.imagepipeline.core.ProducerSequenceFactory.getDecodedImageProducerSequence(ProducerSequenceFactory.java:310)
at com.facebook.imagepipeline.core.ImagePipeline.fetchDecodedImage(ImagePipeline.java:327)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder.getDataSourceForRequest(PipelineDraweeControllerBuilder.java:168)
at com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder.getDataSourceForRequest(PipelineDraweeControllerBuilder.java:42)
at com.facebook.drawee.controller.AbstractDraweeControllerBuilder$2.get(AbstractDraweeControllerBuilder.java:421)
at com.facebook.drawee.controller.AbstractDraweeControllerBuilder$2.get(AbstractDraweeControllerBuilder.java:418)
at com.facebook.drawee.backends.pipeline.PipelineDraweeController.getDataSource(PipelineDraweeController.java:264)
at com.facebook.drawee.controller.AbstractDraweeController.submitRequest(AbstractDraweeController.java:544)
at com.facebook.drawee.controller.AbstractDraweeController.onAttach(AbstractDraweeController.java:440)
at com.facebook.drawee.view.DraweeHolder.attachController(DraweeHolder.java:248)
at com.facebook.drawee.view.DraweeHolder.attachOrDetachController(DraweeHolder.java:265)
at com.facebook.drawee.view.DraweeHolder.onVisibilityChange(DraweeHolder.java:134)
at com.facebook.drawee.generic.RootDrawable.setVisible(RootDrawable.java:67)
at android.widget.ImageView.onVisibilityAggregated(ImageView.java:1686)
at android.view.View.dispatchAttachedToWindow(View.java:20282)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3462)
at android.view.ViewGroup.addViewInner(ViewGroup.java:5218)
at android.view.ViewGroup.addView(ViewGroup.java:5004)
at android.view.ViewGroup.addView(ViewGroup.java:4944)
at androidx.recyclerview.widget.RecyclerView$5.addView(RecyclerView.java:856)
```

### Reproduction

Load a `local content-type` URI (e.g.: content://media/images/3383) using the library with StrictMode enabled.

### Solution

There can be 2 ways to solve this.
1) The call should be offloaded to another thread, could be tricky because it would mean asynchronously creating the `ProducerSequence`

2) Make it possible to give a hint about the `MIME type` of a certain content-uri via the `ImageRequest` for example. In my case I know the type already since the image is a result of a query to the MediaStore so that additional query is not necessary.

### Additional Information

* Fresco version: 2.3.0
* Platform version: Android 10, Device: Xiaomi Mi A2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.