Question Asker Question Asker - 1 month ago 10
Android Question

How secure is the Android app cache?

That is, the locations returned by

getExternalCacheDir()
and
getCacheDir()
.

Can other apps of a certain privilege level access these directories? Does the phone need to be rooted to access these?

What can I store there safely, and what should I avoid storing there?

Answer

Can other apps of a certain privilege level access these directories?

getExternalCacheDir() is accessible by any app that holds the READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE permission.

getCacheDir() is accessible only by your app, with the exception being on rooted devices where the user explicitly uses an app that leverages superuser capabilities to access the entire filesystem. However, any app can trigger the system to clear out the cache, so to some extent, any app can have delete privileges for getCacheDir(). If that concerns you, use getFilesDir().

Does the phone need to be rooted to access these?

For getCacheDir(), yes (excluding the clear-cache scenario described above). For getExternalCacheDir(), no.