ChuckerTeam / chucker

🔎 An HTTP inspector for Android & OkHTTP (like Charles but on device)
Apache License 2.0
3.82k stars 330 forks source link

DiskRead and DiskWrite Violations in ChuckerCollector #737

Closed Alireza-Farahani closed 2 years ago

Alireza-Farahani commented 2 years ago

:writing_hand: Describe the bug

I'm not even sure its Chucker problem or not, but Creating ChuckerInterceptor instance (done by Hilt in out app) results in both DiskReadViolation and DiskWriteViolation.

android.os.strictmode.DiskReadViolation: null
    at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1504)
    at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:251)
    at java.io.File.exists(File.java:815)
    at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:653)
    at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:644)
    at android.app.ContextImpl.getPreferencesDir(ContextImpl.java:600)
    at android.app.ContextImpl.getSharedPreferencesPath(ContextImpl.java:809)
    at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:437)
    at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:179)
    at com.chuckerteam.chucker.api.RetentionManager.<init>(RetentionManager.kt:29)
    at com.chuckerteam.chucker.api.ChuckerCollector.<init>(ChuckerCollector.kt:28)
    at com.chuckerteam.chucker.api.ChuckerCollector.<init>(ChuckerCollector.kt:23)
    at com.chuckerteam.chucker.api.ChuckerInterceptor$Builder.build(ChuckerInterceptor.kt:366)
--------------------------
android.os.strictmode.DiskWriteViolation: null
    at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1460)
    at java.io.UnixFileSystem.delete(UnixFileSystem.java:294)
    at java.io.File.delete(File.java:1037)
    at com.chuckerteam.chucker.internal.data.room.ChuckerDatabase$Companion.create(ChuckerDatabase.kt:22)
    at com.chuckerteam.chucker.internal.data.repository.RepositoryProvider.initialize(RepositoryProvider.kt:34)
    at com.chuckerteam.chucker.api.ChuckerCollector.<init>(ChuckerCollector.kt:32)
    at com.chuckerteam.chucker.api.ChuckerCollector.<init>(ChuckerCollector.kt:23)
    at com.chuckerteam.chucker.api.ChuckerInterceptor$Builder.build(ChuckerInterceptor.kt:366)

:bomb: Steps to reproduce

StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
    .detectDiskReads()
    .detectDiskWrites()
    .penalty<whatever>
    .build()
)

:wrench: Expected behavior

Getting no violation

:camera: Screenshots

-

:iphone: Tech info

:page_facing_up: Additional context

Actually I traced those two violations and one is a simple File delete and the other a new SharedPref and I know it's not much an issue, performance wise.

vbuberen commented 2 years ago

Thanks for the report. I will try to reproduce this week and get to you.

Seems like we need to enable every single check in StrictMode to cover all use cases our users might have 🙂

vbuberen commented 2 years ago

Ok, I was able to reproduce and will work on fixing this issue.