Hacker News new | ask | show | jobs
by MrThoughtful 1445 days ago
What I always found very confusing is that apps on Android can either read all of the SD drive or nothing. Wouldn't the normal approach to gate applications from each other be to give each one the right to access a single directory?

The way it is, all apps want to "READ_EXTERNAL_STORAGE" so they all can read all the data I save.

5 comments

This is being clamped down on, at least for apps on the Play Store. How it works now is the app has unfettered access to its own internal and external storage directory, and can prompt the user to select another one to give access for saving additional data. There are some rough edges for implementors, though; for example, getting your content to show up in media player apps requires usage of a completely separate API, you can't just save data in the Music or Pictures directory.
The basic idea is okay, but the practical implementation is terrible. There's additional overhead which slows down operations that need to touch lots of files, they've broken access via the standard file APIs while at the same time other Android APIs still only support standard files, the much touted media store mainly only caters for standard media file formats (i.e. images/audio/video), plus some standard "document" file formats, but good luck if your file type is too exotic (at least on my – admittedly somewhat older, though – phone even .EPUB files are already too exotic to be indexed by the media store), they've broken simple file sharing between multiple apps and effectively encourage apps to create their own private copy of such files, which is bonkers and for larger files unnecessarily takes up time and storage space, they've especially broken sharing multi-file file formats between apps (especially including the case of using a file manager app to browse through your storage and then directly open such a file in another app), …

I suppose the most common "regular user" scenarios sort of mostly work (except possibly for some performance overhead in some cases), but for more "power user"-like usage scenarios it's all too easy too run into all sorts of edge cases, limitations, and bugs that break your workflows.

Where is this "own external storage directory"?

The behavior you describe is not what I experience in real life. I see apps being able to read and write from all directories on my SD card.

Either you have Android <10, or you have an unofficial ROM, or the manufacturer decided to do weird things to the system for some reason.
Apps haven't needed this permission for most use cases for 5+ years now... only now is the ability to request it being taken away from the last ones (unless they have an exception based on a legit use case like file managers)
Funnily enough, that's exactly what Apple started with on iOS: each app only has access to its own sandbox. And it was derided by Android fans for being too restricted.
This is the new "security". Phone needs access to camera and storage although it cannot make video calls or record a conversation. Messages needs access to camera and microphone. Play Store needs access to everything. All the time. Working some jobs at Google, Microsoft, Facebook and Apple must be a pedophile's heaven.
Incorrect. Apps have private storage and shared storage, separate from fill disk access.

https://developer.android.com/training/data-storage

That is not what I see on the page you linked to.

It says "READ_EXTERNAL_STORAGE when accessing other apps' files on Android 11 (API level 30) or higher"

So, as I understand it, a user has no way to allow an app to read only from a single directory on their SD card.

Read further:

> To give users more control over their files and to limit file clutter, apps that target Android 10 (API level 29) and higher are given scoped access into external storage, or scoped storage, by default. Such apps have access only to the app-specific directory on external storage, as well as specific types of media that the app has created.

If you really want to get into the weeds, previously you could work around scoped content requirements with the manifest property "requestLegacyExternalStorage"

But it's not respected if your app targets the latest version of Android, and new uploads have to target a recent enough version that the loophole is closed.

Legacy apps will be unaffected though.