jerdog · Apr 12, 2012 at 06:30 pm

Android 3.2+ Code (Inadvertently?) Preventing Write Access to External Storage

It would seem that Google has a bug in their AOSP code that was introduced around Android 3.2, which affects how the OS handles USB Storage and can prevent write access to SD cards and USB sticks. XDA Elite Recognized Developer, Senior Moderator, and News Writer Chainfire sums up the issue in his blog post:

In the past, an app would request the “WRITE_EXTERNAL_STORAGE” permission, which would grant write access to all external storages (user/group “sdcard_rw“). This has apparently been changed to only grant write access to the primary external storage. A second permission has been introduced called “WRITE_MEDIA_STORAGE“, which would grant access to the other external storages (user/group “media_rw“).

The problem is, a third party will not actually be granted this permission, only system apps and apps provided by the device manufacturer will normally be granted this permission. There are exceptions, apparently on some devices third party apps will be granted this permission, but according to the AOSP sources, they’re certainly not supposed to.

As Chainfire investigated the issue he came across code in the /system/vold/Volume.cpp that explicitly states:

 if (primaryStorage) {
     // Special case the primary SD card.
     // For this we grant write access to the SDCARD_RW group.
     gid = AID_SDCARD_RW;
} else {
     // For secondary external storage we keep things locked up.
     gid = AID_MEDIA_RW;
}

On many devices, the internal flash is considered the “primary SD card.” The real SD card then becomes the secondary external storage, and is locked down—protected by the unattainable “WRITE_MEDIA_STORAGE” permission.

Chainfire submitted his question to the Android Developers Office Hours team, and they ended up discussing it in their live hangout on April 11. Unfortunately, the Google engineers present in the hangout were not able to provide any real answers, as this is a complicated issue and the question was only raised an hour before the show went live. They have however promised to get to the bottom of this issue, and get back to Chainfire (and us) at a later time.

Also according to Chainfire, the problem is actually present on ICS builds for the SGS2 as well, though Samsung “worked around it using a very ugly permission hack“:

<permission name=”android.permission.WRITE_EXTERNAL_STORAGE” >
     <group gid=”sdcard_rw” />
     <group gid=”media_rw” />
 </permission>

What you see here is Samsung piggybacking the WRITE_MEDIA_STORAGE permission to the WRITE_EXTERNAL_STORAGE permission, so apps do not experience the described problem.

Whether or not Google intended for connected SD Cards and USB sticks to be limited to be read-only for third-party apps remains to be seen. It does however give birth to a disturbing thought: What if the code and accompanying notes are Google’s first stages of implementing some sort of write protection for external storage, and thus further limiting our mobile freedom? We can only hope this is a genuine bug, as freedom is one of the very reasons we all avoid the Dark Side.

[Huge thanks to Chainfire for the heads up and help!]
_________
Want something on the XDA Portal? Send us a tip!

jerdog

jerdog is an editor on XDA-Developers, the largest community for Android users. Jeremy has been an XDA member since 2007, and has been involved in technology in one way or another, dating back to when he was 8 years old and was given his first PC in 1984 - which promptly got formatted. It was a match made in the stars, and he never looked back. He has owned, to date, over 60 mobile devices over the last 15 years and mobile technology just clicks with him. In addition to being a News Editor and OEM Relations Manager, he is a Senior Moderator and member of the Developer and Moderator Committees at XDA. View jerdog's posts and articles here.
Mario Tomás Serrafero · Jul 5, 2015 at 11:00 am · 2 comments

Sunday Debate: Which Factors Caused HTC’s Woes?

Join us in a fun Sunday Debate on HTC's situation. Come with your opinions and feel free to read some of our thoughts, then pick your side or play devil’s advocate to get your voice heard and engage in friendly discussion. You can read our food-for-thought or jump straight into the fray below!     HTC is underperforming, and there isn’t much of a way of denying this. In April, their revenue nearly declined 40%, plummeting after the HTC One M9 had...

XDA NEWS
Mathew Brack · Jul 4, 2015 at 05:07 pm · 4 comments

HTC’s New Ad Campaign And What It Really Means

HTC has just released three new blind test adverts comparing app loading speed, audio and selfies. Whilst you are surely astounded that HTC won every time, the tests were incredibly biased and their release shows something concerning about the company and how they are performing in the current market.     One of the many reasons companies tend to utilize blind trials is when they feel that their product is comparable or better than its competitors. This leads to the assumption...

XDA NEWS
Mario Tomás Serrafero · Jul 4, 2015 at 12:00 pm · 5 comments

XDA Picks: Best Apps of the Week (June 27 – July 4)

Apps are at the front and center of any smartphone experience, and with over a million apps on the Google Play Store and new apps being submitted to our forums every day, staying up to date on the latest apps and games can be a hassle. At XDA we don’t discriminate apps - if it’s interesting, innovative, original or useful, we mention them. The XDA Portal Team loves apps too, and here are our top picks for this week.  ...

XDA NEWS
Share This