Android External Secondary Storage

If you have ever put hand on coding for Android you certainly have found the API to be somewhat of a incoherent mess in certain areas.

One of the areas is that of a secondary storage inside your phone. All phones have a primary storage area, where yu can store images, videos, apps, and application data. The API to gain access to that storage has evolved over time but allows you to seamlessly integrate proper functionality into your app.



Now you may assume that the secondary storage would follow the same paradigm, and grant the same access as the primary storage to your app. However you would be wrong making this assumption. The reason you have apps like the "ES File Manager" handling this for you seamlessly is purely through tricky code in the background which circumvent googles protective scheme for secondary storage, Aka a hack.



Dont do evil ... yeah right!

Yes, google in its drive to push people into using their cloud storage is actively pressuring phone makers to get rid of that large secondary storage, or worse the insertable micro-SD card. That overarching goal of google is driving the API and the access rights to the Androids secondary storage media in a negative way.

This is a great question, and a topic which is sometimes widely misunderstood in the Android arena. To answer your question, looking at the progression of Google's open source code for Android in a historical context, the answer is yes. But, whether or not this was intentional is a matter of perspective.

Let's start with a small bit of terminology. Since the dawn of Android, nearly every type of storage has been considered “external storage,” even the non-removable flash memory that comes in every device. To distinguish, the non-removable flash memory is called “primary storage”, while a removable micro SD card is called “secondary storage.” In the early Android versions, an app merely needed permission to WRITE_EXTERNAL_STORAGE to be able to fully access both primary and secondary storage.

In March, 2011, a modification to the Android coding was made that drastically changed how secondary storage mediums (external SD cards) were mounted by the Android OS. Specifically, the commit read like this: "Mount secondary external storage writable by AID_MEDIA_RW rather than AID_SDCARD_RW.” This meant that the media would now have to belong to the “media_rw” group to modify the contents of the SD card. As a result, a new permission, called WRITE_MEDIA_STORAGE, was added to the source code. Basically, WRITE_MEDIA_STORAGE replaced the original WRITE_EXTERNAL_STORAGE. However, and perhaps unbeknownst to Google, there was a huge catch: it was not possible for regular apps to request this permission. The new permission had a protection level of storageOrSignature, which means that only system apps could request the permission. So now, the WRITE_EXTERNAL_STORAGE permission could only give apps permission to write to primary storage, but not to secondary storage (external micro SD cards). The WRITE_MEDIA_STORAGE permission could write to the external micro SD card, but regular user apps could not request the permission. This change actually took place on Android 3.2 Honeycomb, but due to the logistics of hardware and storage mediums at that time, it was barely noticed.

Starting around the time of Android 4.4 4 KitKat, and even a little earlier, the implementation of the userspace FUSE filesystem, in conjunction with changes to the open source code, resolved this problem. Yet, still to today, even with Android 8.x.x Oreo, third party apps must explicitly get the user's permission for both primary and secondary storage before the app can alter either storage medium in any way. And of course, the newer concepts of adoptible storage have alleviated problems in this regard.


Posted from my blog with SteemPress : http://www.softwaresamurai.org/2018/10/03/android-external-secondary-storage/

Sort:  

Congratulations @softwaresamurai! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

Award for the total payout received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Presentamos el Ranking de SteemitBoard

Support SteemitBoard's project! Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.029
BTC 60637.64
ETH 2405.36
USDT 1.00
SBD 2.60