Android External Storage Permissions Analysis

Source: Internet
Author: User

I don't know if you've found anything. A history of growth from rookie: http://blog.csdn.net/zjbpku/article/details/25161131.

The version number after KitKat no longer supports user SDcard (secondary Storage) write operations. Assuming that the user wants to copy the file to the phone, it can only

stored in internal storage and cannot be stored in an external sdcard, and a new directory cannot be created. This has brought a certain inconvenience to both the user and the developer. of the

The external sdcard cannot be manipulated in the version number after KitKat. is because Google has changed the permissions for this module. Once we were able to get write_external_storage directly

and Read_external_storage permissions to operate the SDcard directly, it is not now, its purpose is to uninstall the software can be created by the software to delete all files.

According to Google

Employee Jeff SharKey, a developer of this module, has introduced a new API to secondary External Storage since KitKat Anroid, but this is not the focus of this article. This

The focus of this paper is to analyze how external storage permissions work.


The Android version number before KitKat will separate an external storage space (external storage) for the application, which may be sdcard

(pluggable external Sdcaard) may also be on the inside of the device flash, we want to get Write_external_storage permissions on the

Space for access, assuming that just reading the content does not require permission.

In the 4.4 KitKat and after the version number. Google made two changes: 1, need to read

Read_external_storage permissions. 2, access to the application belongs to the folder (such as: android/data/[package name]) stored data is not required

The right.


In KitKat, external storage (external storage) is cut into multiple parts: a "primary" section. One or more "secondary" sections.

Before the KitKat.

API can be used to manipulate primary external storage,secondary external storage is a slight change to the Write permission, as described above, in the application of the

The folder to which it belongs (for example, Android/data/[package name]) has full permissions on the file, and in addition to the folder that the app can manage, the app does not have a write

Permission, no matter what the write operation.

This brings out the focus of this article.

Ps:google Although there is no requirement for vendors to add additional privileges to sdcard operations. But

It is mandatory to require the manufacturer to restrict the secondary external storage. Assuming you have questions about internal storage and external storage, you can look at the text

Document Https://developer.android.com/guide/topics/data/data-storage.html#filesInternal


According to Jeff SharKey's introduction, the current version of the Android system, which is KitKat, uses fuse (Filesysgem in userspace) to external storage

Management of the line.

In order to obtain the necessary permissions when the file is created, to dynamically accept or deny individual requests from users/groups, an Android daemon will participate with the fuse core

Driven interactions. This is only part of the Linux-based permissions that Android uses on a removable volume formatted with the Fat File System. In the kernel, it also agrees to use out of the main

Multi-level permission control for Owner/gouper/user operation. Take a look at the following Jeff Sharkey's explanation:


Https://android.googlesource.com/platform/system/core/+/master/sdcard/sdcard.c


Before 4.4, the framework API did not change very much on storage volumes (storage volumes), and device manufacturers were able to create a single "primary" volume or multiple "secondary"

Volume. While these different volumes can be managed by the system services StorageManager and Mountservice, visiting the "PRIMARY" section in this case is like visiting a single external storage.

Very many devices have SD card, but they do not regard it as external storage, in fact this is the "secondary volume" of these devices. Samsung's Galaxy series, for example, is part of this

Category, in terms of permissions. The SD card is actually managed like an external storage volume. However, as a device "secondary external storage", there is no API to write the operation.

The following code is from AOSP device storage conf iguration Example:

On initmkdir/mnt/shell/emulated 0700 shell shellmkdir/storage/emulated 0555 root Rootmkdir/mnt/media_rw/sdcard1 0700 Me DIA_RW Media_rwmkdir/storage/sdcard1 0700 root rootexport external_storage/storage/emulated/legacyexport EMULATED_ Storage_source/mnt/shell/emulatedexport Emulated_storage_target/storage/emulatedexport Secondary_storage/storage /sdcard1
Applications within the system can access any part of the secondary storage. For third-party applications almost impossible (now es Fileexplore, Airdroid, FX, and several other file applications through

A special workaround is to enable the operation of external storage of files on certain models.

(for how to manipulate files on 4.4, you can refer to the storage Options.)

Since the beginning of 4.4, Google has introduced

SAF Framework ( Storage Access Framework). Let's say that Google will not change its operation right now for the 4.4 system external SD, for developers. Familiarity with the SAF framework may be necessary.

another. in the 4.4 system internal application. You will find an apk called Documentui, which is used to handle some of the SAF's interfaces.

)


The folder file under external storage has the same permissions as the following:

4.4 Devices:

[Email Protected]:/storage/sdcard # LLD---rwxr-x system sdcard_rw 2014-05-06 13:20 ALARMSD---rwxr-x system SDCARD_RW 2014 -05-06 13:21 Androidd---rwxr-x system sdcard_rw 2014-05-06 13:20 DCIMD---rwxr-x system sdcard_rw 2014-05-06 13:20 Download D---rwxr-x system sdcard_rw 2014-05-06 13:18 LOST.  Dird---rwxr-x system sdcard_rw 2014-05-06 13:20 moviesd---rwxr-x system sdcard_rw 2014-05-06 13:20 MUSICD---rwxr-x system  SDCARD_RW 2014-05-06 13:20 NOTIFICATIONSD---rwxr-x system sdcard_rw 2014-05-06 13:20 picturesd---rwxr-x system sdcard_rw 2014-05-06 13:20 PODCASTSD---rwxr-x system sdcard_rw 2014-05-06 13:20 ringtones[email Protected]:/storage/sdcard # ll and ROID/DATA/DRWXRWX---system sdcard_rw 2014-05-06 13:21 Com.google.android.apps.maps

4.4 Devices:

[Email Protected]:/storage/sdcard # lldrwxrwx---root sdcard_r 2013-11-27 23:35 alarmsdrwxrwx--x root Sdcard_r 2013-11-27 23:36 androiddrwxrwx---Root sdcard_r 2014-05-06 01:33 dcimdrwxrwx---root sdcard_r 2013-11-27 23:35 Downloaddrwxrwx---R Oot sdcard_r 2013-11-28 04:33 LOST.  dirdrwxrwx---root sdcard_r 2013-11-27 23:35 moviesdrwxrwx---root sdcard_r 2013-11-27 23:35 musicdrwxrwx---root sdcard_r  2013-11-27 23:35 notificationsdrwxrwx---root sdcard_r 2013-11-27 23:35 picturesdrwxrwx---root sdcard_r 2013-11-27 23:35 podcastsdrwxrwx---root sdcard_r 2013-11-27 23:35 ringtones[email Protected]:/storage/sdcard # ll Android/data/ DRWXRWX---u0_a33 sdcard_r 2013-11-27 23:36 com.google.android.apps.maps[email Protected]:/storage/sdcard # ll Android/ DATA/COM.GOOGLE.ANDROID.APPS.MAPS/DRWXRWX---u0_a33 sdcard_r 2013-11-27 23:36 cachedrwxrwx---u0_a33 sdcard_r 2013-11-27 23:36 TestData


Note: In 4.3, the SDCARD_RW group has all the read and write permissions. In the KitKat. The Sdcard_r group has +rwx all permissions. In fact, this is obviously not true. Does not wait to indicate all.

Because the fuse daemon actively participates in changes to the application's permissions at execution time.

The results of the execution of file APIs canWrite (), CanRead (), and CanExecute () are very large

The values returned by these methods are recorded separately in the kernel file system. So they all return true, even if attempting to open the file with POSIX will fail. (in 4.4 of the external SD

Card, it is not possible to write files in the directory, but when you try to call the CanWrite () method to infer whether the directory is writable. It will still return a true value. So this method is not available)


Android.permission.WRITE_EXTERNAL_STORAGE permissions are granted to members of the Sdcard_r and SDCARD_RW groups. However, authentication of write permissions in KitKat requires some

The check of the state. The fuse daemon is therefore used to supplement the file system's permissions. The fuse daemon enforces each permission (that is, the number of visitors to the app) that has a specific folder

Stored folder Android/data/pack-agename ... and some public folders). The fuse daemon is also strong for all non-default users configured with the-W flag in the SDCARD_RW group

To give write-protected permission to the system.

Service sdcard/system/bin/sdcard-u 1023-g 1023-l/data/media/mnt/shell/emulated    class Late_startservice FUSE_SDC Ard1/system/bin/sdcard-u 1023-g 1023-w 1023-d/mnt/media_rw/sdcard1/storage/sdcard1    class Late_start    disabl Ed

Can be seen from the above two sentences program. The fuse daemon enforces the control of GID 1023 (MEDIA_RW. System application only) ability to write operations on Secondar storage. Re-Introduction

A problem. In 4.4 The external storage is divided into primary and secondary. The primary section (built-in sdcard) is capable of write operations. And in the secondary section

(external SDcard) is not agreeable, how does fuse daemon distinguish control? According to Jeff, "-W 2013" indicates the mandatory use of MEDIA_RW gid talent in

The secondary section has write permissions.


Let's comb this out, assuming that you have file operations on an KitKat device with an external SD card, what can and cannot be done for developers? Gives the developer an attempt to

Some of the actions and results:


Summing up, since the beginning of 4.4 Google to secondary volume has made restrictions, not only for users inconvenience. Also brings a lot of inconvenience to equipment manufacturers and developers, Huawei

To this end, the developers were issued a notice: Android4.4 on the application of external card compatibility issues and solutions. Right now. In addition to some of the OEM's own permissions to modify the ROM

Third-party apps are not restricted. Daniel also made changes to the root device user Platform.xml file to change the permissions (in detail please Baidu) to enable third-party applications to operate

External SD card, other file management tools mentioned above can also operate external SD card.

Regardless of what Google is doing to limit its intentions, we want Google to think about it from a user's perspective,

Make the better of the Android system.

Thanks for the help of the developer of the FX file management tool Tod Liebeck in g+ to answer my questions in a timely manner. At the same time, thank you for

Tod Liebeck developer of X-plore to resolve KitKat external SD file operation scheme.





Android External Storage Permissions Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.