G33K-TRICKS: [Explained] Android App directories and methods to access these directories

Sunday, January 29, 2023

[Explained] Android App directories and methods to access these directories


Android App directories and methods to be used to access these app directories 


Have you ever wonder why there are so many directories in your Android Phone and what purpose they do serve. As, Android, basically uses Linux as a base platform, it's likely to have Linux like file system structure. Let's take a quick dive into what are those different Android Application Directories in your Android mobile phone and then I've also mentioned the methods that can be used in your android application to access the data from these directories.


Android App Directory



We have 'apps' directory which is self explanatory. The data for the application that are pre-installed or the ones that you would install would sit in this folders. 

APPLICATIONS:
/data/app/* - This is for the users application Installation space 
/data/app/*/base.apk - Space for Android default or preinstalled system apps
/data/app/*/lib//*.so - Space for Shared Libraries(so = shared object similar to dll)
/data/app/*/oat//base.[art|odex|vdex] - Space of compiled executable code that we installed
/data/dalvik-cache//*.[art|dex|oat|vdex] - Space of compiled executable code only for preinstalled apps
/data/misc/profiles/cur///primary.prof - Androd RunTime Profile (refer: https://source.android.com/devices/bootloader/boot-image-profiles)
/data/misc/profiles/ref//primary.prof - Androd RunTime Profile (refer: https://source.android.com/devices/bootloader/boot-image-profiles


Next is user directory under Internal Storage

Internal Storage:
/data/user[_de]/<user_id>/<pkg> - To fetch data from this path use getDataDir()
/data/user[_de]/<user_id>/<pkg>/files - To fetch data from this path use getFilesDir()
/data/user[_de]/<user_id>/<pkg>/[code_]cache - To fetch data from this path use getCacheDir() or getCodeCacheDir()
/data/user[_de]/<user_id>/<pkg>/databases - To fetch data from this path use getDatabasePath()
/data/user[_de]/<user_id>/<pkg>/no_backup - To fetch data from this path use getNoBackupFilesDir()
/data/user[_de]/<user_id>/<pkg>/shared_prefs - To fetch data from this path use getSharedPreferences()

Next is external storage and directories present in external path like SDCard

External Storage:

/storage/emulated/obb/<pkg>/*.obb - Shared by multi-users, exposed in following view)

/storage/emulated/<user_id>/Android/obb/<pkg>/*.<pkg>.obb - To fetch data from this path use getObbDirs()

/storage/emulated/<user_id>/Android/media/<pkg> - To fetch data from this path use getExternalMediaDirs()

/storage/emulated/<user_id>/Android/data/<pkg>/ - To fetch data from this path use getExternalMediaDirs()

/storage/emulated/<user_id>/Android/data/<pkg>/files To fetch data from this path use getExternalFilesDirs()

/storage/emulated/<user_id>/Android/data/<pkg>/[code_]cache - To fetch data from this path use getExternalCacheDirs()



 TLDR, here it is in Tabular format for quick reference.

Android Apps directory and Description

No comments: