I am having a call to getExternalCacheDir()
function on my Android App, and this is causing an ANR for some of Android 10 users having the following devices (HUAWEI P30 lite, Galaxy A40, Xperia XZ3).
I am having the following stack trace for my ANR
The "main" (tid=1) thread is performing disk I/O.
"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 flags=1 obj=0x72dfcb58 self=0x73e23a5000
| sysTid=12158 nice=0 cgrp=default sched=0/0 handle=0x73e3913ee8
| state=D schedstat=( 378582885 304333911 539 ) utm=23 stm=14 core=7 HZ=100
| stack=0x7fc28de000-0x7fc28e0000 stackSize=8192KB
| held mutexes=
at libcore.io.Linux.access (Native method)
at libcore.io.ForwardingOs.access (ForwardingOs.java:73)
at libcore.io.BlockGuardOs.access (BlockGuardOs.java:71)
at libcore.io.ForwardingOs.access (ForwardingOs.java:73)
at android.app.ActivityThread$AndroidOs.access (ActivityThread.java:7816)
at java.io.UnixFileSystem.checkAccess (UnixFileSystem.java:281)
at java.io.File.exists (File.java:815)
at android.app.ContextImpl.ensureExternalDirsExistOrFilter (ContextImpl.java:2838)
at android.app.ContextImpl.getExternalCacheDirs (ContextImpl.java:787)
- locked <0x0614cac6> (a java.lang.Object)
at android.app.ContextImpl.getExternalCacheDir (ContextImpl.java:779)
at android.content.ContextWrapper.getExternalCacheDir (ContextWrapper.java:289)
at com.mypackage.util.file.FileManager.initialize (FileManager.java:51)
When I read the developer reference, I don't see any notice that say that we need to make the call outside the main thread: https://developer.android.com/reference/android/content/Context#getExternalCacheDir()
Should I make the call on a different thread? What's the simplest way to fix that ANR?