Hacker News new | ask | show | jobs
by iggldiggl 20 days ago
> Consider how the file picker works. If you press a button in the app, then a file picker is opened, but the app gets no access to anything until you select a file to give it. Clearly, this is way better than giving the app read access to your whole HDD.

For some values of better – e.g. I'm browsing through a folder with some (the) file explorer, and then decided to open an image with my favourite image viewer. The UX-friendly expectation is that I can then continue browsing (go to the next or previous image) from right inside the image viewer.

File system sandboxing however insists that the image viewer isn't allowed to access anything else, so instead I either have to go back all the way to the file explorer to open the next image, or at the very least invoke some kind of OS-blessed file open dialogue for the image viewer to be allowed to continue.

The latter is the official situation on Android, and it's rather suboptimal, to put it that way. (Made worse by the fact that the blessed way of opening a file with another app also tries to hide that file's location from the receiving app, so even if my image viewer e.g. already had sufficient file system permissions to access that file and its whole folder, without some hacky workarounds it still couldn't offer me to continue viewing other pictures inside the same folder because it doesn't really know which file it's currently opening.)

1 comments

The issue here is just that the permission model does not allow for all use cases. On iOS you can either give an app access to all your images, or select a subset (this interface is somewhat annoying to use, and could be improved), or just give it temporary access to a single image using the "share" dialog.

It's been a long time since i used Android, but why don't they just implement the ability to grant access to a given folder? The you could grant your preferred image viewer access to all your images, without it having access to your other documents. And apps that you might just want to give access to a select few images, like social media, could stay with the per-file permission.

The fact that the full path isn't revealed just seems like a sensible thing to do. Even if you give an app access to a full directory, why would it need to know where that directory is located?

> The issue here is just that the permission model does not allow for all use cases.

The problem is that for anything more complicated than a simple "grant access to this one file/directory" both the permission system and its associated UI also get pretty complicated pretty quickly.

Like "opening a file with a certain app will allow that app to read that file" is pretty easy to understand, but "opening a file with a certain app will allow that app to read all other files within that directory" already less so (but is precisely what would be needed for an image viewer).

Eventually you get to a point where it's easier to just fall back to a generic "all files" permissions, which then leads back to arguments whether users can be trusted with it.

> The fact that the full path isn't revealed just seems like a sensible thing to do. Even if you give an app access to a full directory, why would it need to know where that directory is located?

You wouldn't necessarily need the full path of the directory, but you need at least some kind of handle to it, and Android doesn't give you one when you're receiving a single file from another app. And since the file path is hidden from you even if the file is local and not cloud-based or something else, you can't even ask the user for directory viewing permissions yourself (or maybe you've even already been granted those permissions, but you still can't use them because you don't know where that file resides).

The technical justification was that the new file sharing API could in theory be backed by anything, not just the local file system, so they didn't want apps to rely on a local file system path and therefore made the design to force apps away from it (only semi-successfully, because at the same time the default implementation still somewhat leaks the original path, so you could try to reverse-engineer it from that, plus when I tried to research a bit, it seemed that possibly even without root there still was some way of getting a file system path back from a raw file handle, provided of course that the file really was backed by something local, and not cloud storage).

So far so fine, but it does break some stuff. E.g. it messes up LRU lists (opening the same file once via app A and once via app B creates two distinct LRU entries in app C), plus like I said, even if the receiving app already holds sufficient file system permissions itself, it cannot use them because it doesn't (officially) know which file and which directory it's dealing with.

And like I said, for the use case of an image viewer being able to browse adjacent files, it needs to know not only the specific file it's supposed to open, but also its containing folder.

> It's been a long time since i used Android, but why don't they just implement the ability to grant access to a given folder?

They did, but in combination with the new file sharing API that is precisely what broke advanced UX workflows like wanting to browse adjacent files in an image viewer. (Or being able to view local HTML files that aren't monolithic MHTML archives – if you pick such a file from a file browser to open it in your web browser, the web browser won't be able to open any associated subresources or follow any links to other local files.)