Android: Detecting if writing on SdCard is possible does not work #726

Closed
Ghabry opened this Issue Jan 14, 2016 · 8 comments

Projects

None yet

3 participants

@Ghabry
Member
Ghabry commented Jan 14, 2016

I'm so pissed now of Android that I have to write a report just for your amusement.

Got some report on GooglePlay, have not verified if this is the cause but very likely is:

Last PR added redirecting of save and config when the directory is not writable. This was to work around the Android >=4.4 limitation that only system apps can write the SD card.

I use the Java-Api File.canWrite() to detect if writing works. The Api returns true, but the actual writing fails. I bet this is because .canWrite only uses stat which checks the linux access rights but Android does some other magic to prevent writing anyway.
Next time I will try to write a file instead and catch the exception.

The case for canWrite == false works, I tested that one...

@Ghabry Ghabry added the Android label Jan 14, 2016
@BlisterB
Member

Android

@Ghabry
Member
Ghabry commented Jan 15, 2016

https://code.google.com/p/android/issues/detail?id=66369

"runs into a bug on some devices when using this to test external SD access. You have permission to create the file but not to delete it, resulting in extra junk files being left."
Lol

@fdelapena
Member

This is beyond facepalm. QA and tests are not part of the Google Android team it seems.
Would be at least created files being able to be modified? Savegames and config don't need to be removed.

@fdelapena fdelapena closed this Jan 15, 2016
@fdelapena fdelapena reopened this Jan 15, 2016
@Ghabry
Member
Ghabry commented Jan 15, 2016

We don't need delete.
Well I will change the code from ".canRead()" to "try { open(); write(); close(); }". The write makes no sense because the permission check is done in open, but it is Android, so I want to be save. :D

@BlisterB
Member

Hmm damn Android, but I'm not sure to understand, this thing of not being
able to write in sdcard, does it concern a specific version or any version above 4? That doesn't make sense...
Ghabry can you put this code in a function nammed canRead in
GameBrowserHelper? It will be more clear to read and easy to
maintain/change if we find a better solution (this one call too many system
call).
Le 15 janv. 2016 9:10 AM, "Ghabry" notifications@github.com a écrit :

We don't need delete.
Well I will change the code from ".canRead()" to "try { open(); write();
close(); }". The write makes no sense because the permission check is done
in open, but it is Android, so I want to be save. :D


Reply to this email directly or view it on GitHub
#726 (comment).

@Ghabry
Member
Ghabry commented Jan 15, 2016

That read-only SD card is a feature of Android 4.4 and newer. The OEM can remove an entry from a system xml file and then only System Apps (Google+OEM bloat (Facebook, Dropbox, Samsung junk ...)) and the PC via USB-cable can write anywhere on the SD card. All other apps can only read. The reason by google for this is, that this prevents the SD card from being bloated with non-user files.
Is not enabled on all devices but when you have root permissions you can change it easily. At least if SELinux is not enabled which prevents writes in system directories even for root, in that case you must boot in a custom recovery first, Google really hates rooting it seems:

/system/etc/permissions/platform.xml

Add
<group gid=”media_rw” /> to section name=android.permission.WRITE_EXTERNAL_STORAGE

Since Android 5 they have a new Api that displays a directory picker and for the selected directory the App gets a token for write permissions. Problem: Does not work with the normale File()-Api, needs a new one. And useless for us because of Android 5 only. Well I will just fix the redirection code, is universal.
This is exactly the same Modern UI Apps for Windows do, btw to request directory write access. But Windows has it since the beginning (For Apps I mean, so Windows 8 and Phone) so you can't complain ^^.

This limitation is only for SD card, internal storage is always writable. I hate this shit. I have OpenStreetMaps offlien navigation which is >20 GB and downloaded by the app. So I'm forced to root because I need a writable sd card for this -.-

@Ghabry
Member
Ghabry commented Jan 15, 2016

Here is a nice blog article which also explains why canRead() and friends return the wrong result: https://possiblemobile.com/2014/03/android-external-storage/

@BlisterB
Member

Thanks for the papier Ghabry, interesting to know it !
Astonish : there is a complete part about Samsung hahaha.

@fdelapena fdelapena closed this in #727 Jan 17, 2016
@Ghabry Ghabry modified the milestone: 0.4.1 Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment