1. Introduction

This is my first day of the August Challenge. When I first came into contact with an Android phone, I felt the chaos of the Android file system, which was filled with folders I didn’t understand. Later, after in-depth study, I know that this is caused by some Android developers’ non-standard storage methods. This article will introduce some of my own learning about The Android file storage system.

2. Divide the storage system

In early Android phones, users often added an SD card to expand their storage space due to their limited storage space. During this period, the storage space of the phone itself is called internal storage space, and the external SD card is called external storage space.

On today’s Android phones, hundreds of gigabytes of storage make it unnecessary to insert an SD card, so the internal storage space is divided into internal storage and external storage.

2.1. Internal Storage

2.1.1. Storage location

Each APP has its own internal storage space, which is stored in the /data/data/ package name folder. You can use the Device File Explore in Android Studio to view the storage space of Android devices. The Device File Explore button is usually on the right side of Android Studio.

If you cannot find this button, you can open it by clicking View-> Tool Window ->Device File Explore.

Then you can see the full picture of Android’s internal storage space. Each APP’s private internal storage space is accessible only by itself, and when the APP is deleted, the folders in it are deleted along with it.

2.1.2. Storage content and access mode

We open a folder to view its contents. Each APP has these three folders. The Cache folder is used to store the APP cache and is accessible in Kotlin via the cacheDir API. The code_cache folder is used to store the code cache, which is usually not needed, and is accessed through codeCacheDir. Databases folder is used to store database files. You do not need to access the database folder. Android will place the database files in this folder after you create the database. File is a folder for storing common files and can be accessed through filesDir. There are shared_prefs for SP files, and lib for so libraries that the APP depends on.

2.2. External storage space

2.2.1. Storage location

The external storage space is located in /storage/emulated/0. In addition to this folder, Android also has two soft links pointing to the external storage space, which are /sdcard/ and /storage/self/primary.

2.2.2. Storage content and Access mode

In the external storage space, there are not only APP private storage space but also public storage space. For example, DCIM and Picture are the public image file storage space, and Movie is the video file storage space.

/sdcard/Android/data is the external storage private directory of the APP, which can be accessed using the getExternalFilesDir API.

3. Compare the similarities and differences

Difference:

Internal storage generally stores small capacity, privacy is relatively strong files. The external storage is used to store large files.

Similarities:

An APP does not need permission to access its own private directory. You need to apply for the read/write permission only when reading/writing to the public storage area.

The resources

1.Android Storage Fundamentals – Little fish love programming