Skip to content

StrictMode DiskReadViolation when loading image File from disk #383

@gajicm93

Description

@gajicm93

Describe the bug
I load an image "file://" Uri from disk. Coil obviously loads it on main thread, or at least does an "last modified time" check on main thread. I even tried specifying IO dispatcher with imageView.load(fileUri) { dispatcher(Dispatchers.IO) } but it doesn't help.

Expected behavior
Expected behaviour is that disk should never be touched from main thread.

To Reproduce
imageView.load(fileUri) where file Uri is a literal "file://" Uri.

Logs/Screenshots

2020-05-02 22:04:02.901 27160-27160/com.berry4u.app D/StrictMode: StrictMode policy violation; ~duration=5 ms: android.os.strictmode.DiskReadViolation
        at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1556)
        at java.io.UnixFileSystem.getLastModifiedTime(UnixFileSystem.java:289)
        at java.io.File.lastModified(File.java:939)
        at coil.fetch.FileFetcher.key(FileFetcher.kt:14)
        at coil.fetch.FileFetcher.key(FileFetcher.kt:12)
        at coil.RealImageLoader$executeInternal$2$deferred$1.invokeSuspend(RealImageLoader.kt:525)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
        at kotlinx.coroutines.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:337)
        at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:158)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
        at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
        at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
        at coil.RealImageLoader.execute(RealImageLoader.kt:143)

Version
0.10.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions