Android storage. A list of folders available for application.

There are two types of storages: internal and external. Internal storage is a persistent storage on the phone chip. In earlier days, its volume was pretty small. Therefore, removable SD cards were used and they presented external storage. External storage was mainly used to keep large media files. However, when a user ran out of the internal storage to install apps, she tried to install them on the external storage. However, SD card is a challenge: (1) can be removed at any moment (2) when USB mass storage is enabled on SD card, it is unmounted. So, the apps on the SD card suddenly become unknown to the system. Therefore, special considerations should be taken before installing an app on the external storage.

Nowdays, “external storage” means either one of two things: the actual removable microSD card or the virtual “SDCard” partition located in /data/media.

Note, many modern devices are not shipped with a slot for removable SD card at all, for example https://www.gsmarena.com/asus_rog_phone_6_diablo_immortal_edition-11986.php or https://www.gsmarena.com/samsung_galaxy_s22_ultra_5g-11251.php.

The application can query the system about available directories. Here is a list of API and an example of the API results. The test was done on Sumsung A53 with Android 13 (API level 33). The test application is site.dbu9.gamerec2.

Table Of Contents

Internal storage

Application cache and files directories

An application does not need any permissions to write / read internal storage folders. Cache files are removed on app uninstall or even before, by OS decision.

API Result
Context.getFilesDir() /data/user/0/site.dbu9.gamerec2/files
Context.getCacheDir() /data/user/0/site.dbu9.gamerec2/cache

External storage

Is emulated or mounted

If there is no actual SD card which serves as external storage, the external storage is emulated and not mounted, neither for read-write nor for read only.

API Result
Environment.isExternalStorageEmulated() true
Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED false
Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED_READ_ONLY false

Application cahce and files diriectories

No need to require any permission to use the storage starting from Android 4. The files are removed when the app is uninstalled.

API Result
Context.getExternalFilesDir() /storage/emulated/0/Android/data/site.dbu9.gamerec2/files
Context.getExternalCacheDir() /storage/emulated/0/Android/data/site.dbu9.gamerec2/cache

Non-application folders

API Result
Environment.getRootDirectory() /system
Environment.getDataDirectory() /data
Environment.getStorageDirectory() /storage
Environment.getExternalStorageDirectory() /storage/emulated/0

Public directories available for RW by any application

API Result
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) /storage/emulated/0/Download
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) /storage/emulated/0/Movies
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) /storage/emulated/0/DCIM
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) /storage/emulated/0/Documents

ADB shell investgation

Let’s look at directory strcuture from AD shell. After running adb shell, we’re inside the phone:

a53x:/ $ ls -ll
total 160
dr-xr-xr-x   4 root   root          0 2023-01-14 13:31:45.647999997 +0200 acct
drwxr-xr-x  78 root   root       1620 2023-01-15 09:02:02.433696803 +0200 apex
-rw-r--r--   1 root   root      49194 2022-01-01 02:00:00.000000000 +0200 audit_filter_table
lrw-r--r--   1 root   root         11 2022-01-01 02:00:00.000000000 +0200 bin -> /system/bin
lrw-r--r--   1 root   root         50 2022-01-01 02:00:00.000000000 +0200 bugreports -> /data/user_de/0/com.android.shell/files/bugreports
drwxrwx---   7 system cache      4096 2023-01-14 13:31:33.659999811 +0200 cache
drwxr-xr-x   2 root   root       4096 2022-01-01 02:00:00.000000000 +0200 carrier
drwxr-xr-x   3 root   root          0 1970-01-01 02:00:00.647999999 +0200 config
lrw-r--r--   1 root   root         17 2022-01-01 02:00:00.000000000 +0200 d -> /sys/kernel/debug
drwxrwx--x  71 system system     4096 2023-01-14 13:34:06.663999896 +0200 data
d?????????   ? ?      ?             ?                             ? data_mirror
drwxr-xr-x   2 root   root       4096 2022-01-01 02:00:00.000000000 +0200 debug_ramdisk
drwxr-xr-x  25 root   root       7920 2023-01-15 00:52:13.305707692 +0200 dev
-rw-r--r--   1 root   root       6251 2022-01-01 02:00:00.000000000 +0200 dpolicy_system
drwxrwx--x  22 system radio      4096 2022-10-27 13:20:09.495999997 +0300 efs
lrw-r--r--   1 root   root         11 2022-01-01 02:00:00.000000000 +0200 etc -> /system/etc
l?????????   ? ?      ?             ?                             ? init -> ?
-rwxr-x---   1 root   shell      3583 2022-01-01 02:00:00.000000000 +0200 init.container.rc
-rwxr-x---   1 root   shell       463 2022-01-01 02:00:00.000000000 +0200 init.environ.rc
d?????????   ? ?      ?             ?                             ? linkerconfig
d?????????   ? ?      ?             ?                             ? metadata
drwxr-xr-x  18 root   system      400 2023-01-14 13:31:47.335999996 +0200 mnt
drwxr-xr-x   3 root   root       4096 2022-12-12 03:28:52.000000000 +0200 odm
drwxr-xr-x   2 root   root       4096 2022-01-01 02:00:00.000000000 +0200 odm_dlkm
drwxr-xr-x   2 root   root       4096 2022-01-01 02:00:00.000000000 +0200 oem
drwxrwxr-x   4 radio  system     4096 2022-12-04 14:26:58.011999999 +0200 omr
drwxr-xr-x   4 root   root       4096 2008-12-31 17:00:00.000000000 +0200 optics
d?????????   ? ?      ?             ?                             ? postinstall
drwxr-xr-x   9 root   root       4096 2008-12-31 17:00:00.000000000 +0200 prism
dr-xr-xr-x 799 root   root          0 1970-01-01 02:00:00.715999999 +0200 proc
drwxr-xr-x   7 root   root       4096 2022-12-12 03:50:38.000000000 +0200 product
lrw-r--r--   1 root   root         21 2022-01-01 02:00:00.000000000 +0200 sdcard -> /storage/self/primary
drwxr-xr-x   2 root   root       4096 2022-01-01 02:00:00.000000000 +0200 second_stage_resources
-rw-r--r--   1 root   root         75 2022-01-01 02:00:00.000000000 +0200 sepolicy_version
drwxrwx--x   3 system system     4096 2008-12-31 17:00:00.000000000 +0200 spu
drwx--x--x   4 shell  everybody    80 2023-01-14 13:31:47.271999996 +0200 storage
dr-xr-xr-x  14 root   root          0 1970-01-01 02:00:00.715999999 +0200 sys
drwxr-xr-x  22 root   root       4096 2022-01-01 02:00:00.000000000 +0200 system
d?????????   ? ?      ?             ?                             ? system_dlkm
lrw-r--r--   1 root   root         18 2022-01-01 02:00:00.000000000 +0200 system_ext -> /system/system_ext
drwxr-xr-x  13 root   root       4096 2022-12-12 03:29:55.000000000 +0200 vendor
drwxr-xr-x   4 root   root       4096 2022-12-12 03:28:48.000000000 +0200 vendor_dlkm
a53x:/ $ 

So, /sdcard links to /storage/self/primary. Looking at /storage/self/primary:

a53x:/ $ ls -ll storage/self/primary/                                                                                                                                                                
total 84
drwxrws--- 2 u0_a252  media_rw   3452 2022-06-07 06:23:35.735999963 +0300 Alarms
drwxrws--x 6 media_rw media_rw   3452 2022-10-20 18:41:04.657693544 +0300 Android
drwxrws--- 2 u0_a252  media_rw   3452 2022-06-07 06:23:35.783999963 +0300 Audiobooks
drwxrws--- 5 u0_a252  media_rw   3452 2023-01-01 19:48:42.537687798 +0200 DCIM
drwxrws--- 3 u0_a252  media_rw   3452 2022-10-24 16:15:06.342341758 +0300 Documents
drwxrws--- 3 u0_a252  media_rw 118784 2023-01-12 03:10:35.224999279 +0200 Download
drwxrws--- 5 u0_a252  media_rw   3452 2023-01-01 19:48:57.745687787 +0200 Movies
drwxrwxr-x 4 media_rw media_rw   3452 2022-06-07 06:23:35.799999963 +0300 Music
drwxrws--- 2 u0_a252  media_rw   3452 2022-10-20 00:59:59.477853220 +0300 Notifications
drwxrws--- 5 u0_a252  media_rw   3452 2022-11-26 13:18:52.481699792 +0200 Pictures
drwxrws--- 2 u0_a252  media_rw   3452 2022-06-07 06:23:35.711999963 +0300 Podcasts
drwxrws--- 3 u0_a252  media_rw   3452 2022-12-08 15:50:59.997082143 +0200 Recordings
drwxrws--- 2 u0_a252  media_rw   3452 2022-06-07 06:23:35.735999963 +0300 Ringtones

Note, that /storage/self/primary/Download and /storage/emulated/0/Download is the same location.


See also