r/android_devs • u/stereomatch • May 24 '20
Future talk This tutorial article introduces you to the complexity that awaits apps with the Scoped Storage changes in Android
This tutorial article introduces you to the complexity that awaits apps with the Scoped Storage changes in Android - first mandated in Android 10, now slipping to Android 11 (as Google realizes the enormity of this change perhaps, but is compelled by executive order to keep with the program):
https://www.raywenderlich.com/9577211-scoped-storage-in-android-10-getting-started Scoped Storage in Android 10: Getting Started - May 20, 2020
In Android 10, Google introduced the concept of scoped storage, which enhances user control and privacy while cutting back the file clutter that removed apps leave behind.
As usual with most coverage, only mentions enhancements, but not the disruption to standard file access.
Otherwise, seems like a good article.
Although it works, SAF is slow and highly unpopular among the developer community.
And also prohibited (!), if you don't have a file manager app that has already gone through the Permissions Declaration Form processfor Google approval (anyone remember the Call/SMS fiasco ?).
Scoped storage came on the scene when Android 10 officially launched on September 3, 2019. It changed things a bit. As the name suggests, it provides scoped — or limited — access to the file system. Apps that use scoped storage have access only to their app directory on external storage plus any media the app created.
Non-critical speak for (my words):
Scoped Storage provides a 'fluid API' that changes from month to month, by designers who don't fully understand, or care to understand it's ramifications, and which essentially makes the sharing of files between apps more difficult than before. Essentially neutering all persistent storage of files, in favor of reliance on the cloud model of storage perfected by iOS (but now injected surreptitiously by Google). This change reduces features - that aspect is not advertised to unsuspecting android users - but instead everybody parrots the advantages of what is a badly designed API, crippled features, breaking roadmap.
Article then discusses impact on audio recorder app as example:
Imagine you’re creating a voice recorder app. If you implement scoped storage in your app for Android 10 and above, you’ll have a limited scope for reading and writing files. Since your audio files reside in the app directory, you don’t need permission to access or modify them.
AKA nobody else will be able to read the archival files created by your audio recorder. You won't be able to see them in your other audio editor app as before. And when the audio recorder app is uninstalled, your precious archival audio recordings will magically disappear as well - a "feature" not advertised in the Google blurbs!
What will the recourse be for users after this sucker punch of a fait accompli by Google ? Will you rely on app data backup to cloud - and restore on app reinstall to recover the precious files? Google usurped what belonged to the user, and made it their own - they also added to the list of changes which break android roadmap, and the previous mantra, that old apps will always continue to work on newer android versions.
Why Do You Need Scoped Storage?
Is there a section "Why we don't need Scoped Storage" as well? No. Is it any wonder why Google has it so easy making these changes ?
If these content creator serve the users they should occasionally also discuss why we don't need a disruptive, only-serves-Google strategic shift in the Android roadmap?
It is not only Google who owns the roadmap, but also users. If the government abruptly changed which side of the road you can drive on, one would expect an explanation from them - none emerges from Google except the cover story of improved security (there are better ways to improve security - for one stop making internet an implicitly granted permission for all apps).
Why are Google storage "improvements" always designed to hinder local storage ? It started with crippling of ext SD card access, so it was no longer seamless - that did away with seamless use of cheap ext SD cards (which were always a strategic pain for Google's cloud ambitions). Google went with the "open" plan of the original android, and used that as an advantage over generally closed iOS. But has secretly harbored the same ambitions since KitKat when it killed seamless access to ext SD card with API changes.
Since then, internal storage has gotten just as big as ext SD card - phones with 128gb internal storage are common (another hindrance to cloud storage).
With Scoped Storage, Google is doing the same with local storage - killing seamless access to it. Only place where standard file io APIs (like fopen() from native NDK C code) will work is the ephemeral app-specific storage (ideally now backed up to Google servers with app-backup) - but which has the unfortunate "feature" of being inaccessible for all practical purposes by other apps, and for having the unfortunate propensity to go away if you uninstall the app. Essentially your audio recorder data is not your data anymore.
Should this "feature" not be advertised to users well in advance so they can steer clear of your new Android ? Or is Google fooling users into going from persistent storage to non-persistent storage without telling them ? It is fooling users - where is the consumer protection from EU when you need it - it does not matter if EU protection always arrives AFTER the damage is done - and Google is prosecuted for a day's worth of revenue. Google is a Leviathan whose momentum is impeded even by years of work by a EU team of lawyers as no fine is big enough when a company has gotten bigger than governments - talk about a world government - this is it with Google as far as the majority mobile OS world is concerned - developers warn of it but are ignored (as happened with KitKat), and users only find out about it 2 years later when they upgrade.
Reducing leftover app data: When a user uninstalls an app from their device, some app data still remains in the shared storage. With scoped storage, this problem disappears as all the app data resides exclusively in the app directory.
Yes, this "problem" of persistent storage disappears. Some quaint folks used to call it a feature. No more with Google Cloud and internet tethering to the rescue. Forget about using your audio recorder in the jungle. Or wait for Facebook's string-of-pearl's satellites to appear in the sky over your head. Just don't ask for that old persistent storage.
Limiting the abuse of READ_EXTERNAL_STORAGE permission: Developers have abused this permission heavily because it gave them access to the entire external storage. Using scoped storage, apps can access only their own files, folders and other media file types using storage APIs.
Yes, those developers, always abusing you. And Google will look like your friend if we can convince you to implicitly hate or mistrust developers - use the language wisely and it can be a weapon. What will happen if all apps started to show a screen to users warning them not to update to Android 11, as Google will abuse the user's right to free local persistent storage. Few users know this is what is about to happen, and these YouTubers, and article writers will not tell them.
Even though scoped storage is useful, there may be times when you don’t want to use it. Luckily, you can still opt out of using it in Android 10.
Thankfully he does mention the ability to avoid this in android 10. Again, all this keeps changing every few months - some time ago this change was due in Android 10. I have previously warned that this is not a small change, and it has potential to break or split android.
I hope you liked this tutorial. If you have any questions or comments, please join the forum discussion below.
The article is still valuable however, despite my criticism of how articles fail to provide context for Google changes.
2
May 24 '20
While I agree that the implementation most likely sucks, I never looked into it in detail, at least the user benefit seems clear to me:
Better control over file access. Let's assume I have an image editor. With those changes, I select which file it should be allowed to open, rather than having to give it access to my whole storage. This seems like a very important feature that tremendously improves security.
1
u/stereomatch May 24 '20 edited May 24 '20
Better control over file access. Let's assume I have an image editor. With those changes, I select which file it should be allowed to open, rather than having to give it access to my whole storage. This seems like a very important feature that tremendously improves security.
That is presuming something is true, without examining it's detail, and then concluding it is all for the best.
I don't know why people keep falling for this - perhaps there is such a reservoir of goodwill built up for Google that people automatically assume that the areas which are hazy are being addressed in the best possible way by Google - they "must" be doing it in the right way, or they "must" have a valid reason.
There is a presumption that they have the money and the people, so must be doing it the best way - not any longer, if the decisions make little technical sense (but do make business sense).
I select which file it should be allowed to open, rather than having to give it access to my whole storage.
You won't be able to open the audio recorder files with your audio editor app, as you will not be able to find them.
If your audio recorder app has it's own file manager interface, it will appear that audio files are in their old location - but actually won't be there but in another app-specific hidden location.
In reality you as a user have LESS power - there will be no way for you to browse the old audio recorder app's audio files using your audio editor app.
Now it may be possible to use Files app (or a file manager app that uses SAF) to browse to the audio recorder audio files and then click to open with audio editor - however the audio recorder files will not be in the same place (that the audio recorder internal file manager is showing the files to be).
So this is either moronic design or deliberate - you choose the label to assign to this very real behavior.
Yet we still hear people say "I can understand Google want to do it this way .. because (insert excuse)" - when all it is is a compulsion to not stand out against the company - one may need a job there one day - or may need to participate in their forum - wouldn't want to be blacklisted silently. These all are legitimate practical concerns, but should not cloud the technical discussion on it's merits.
But if this is the actual excuse for the defence of Google, we are living in a world of Stockholm Syndrome under Google - unwilling to blame the one entity that is in the driving seat of this train-wreck of a roadmap, while blaming all others.
Some will say we don't need to realize the problem because we cannot do anything about it - is a valid reason to stay quiet, but is it a valid reason to praise Google behavior?
3
May 24 '20
Just to make that clear, I am the last one who would come up with any excuses for Google. In fact I am regularly voicing my opinion on how Google runs the Playstore and Android. I can't wait for the day they are fined for their behaviour. And I certainly am not overly confident in the framework team and every API they put out either. But back to the topic at hand.
From my understanding, the Audio Recorder should save recordings in MediaStore. Then, with scoped storage, the user can select which audio files/folder the Audio Editor app can open. Is that not how it works? I'm having a hard time believing that.
2
u/stereomatch May 24 '20
Yes, thanks for that. My answer was partly pre-empting the types of response one usually gets, and was not particularly addressed to you - I apologize for my harshness.
From my understanding, the Audio Recorder should save recordings in MediaStore. Then, with scoped storage, the user can select which audio files/folder the Audio Editor app can open. Is that not how it works? I'm having a hard time believing that.
Yes, this should work it would seem - however, it may be slightly more complicated than that. The files your audio recorder thought are stored to Music are not visible to other apps which look in Music. Now the question is should a file manager app be able to see it. My sense is that the files the audio recorder app saves are actually mapped to another app-specific folder, and not actually in Music (please correct me if wrong).
So first thing is practically with a SAF based file manager they would have to scout around for where the file actually is - and then there is a second question if that app-specific hidden folder is visible to SAF based file managers (I dont know the answer to this second question off the top of my head).
3
May 24 '20
Ok, thanks for clearing that up. I really don't know, the API once again seems so over-engineered, MediaStore, DocumentProvider, DocumentContract.buildDocumentUriUsingTree, whatever. Without having implemented it, I have no hope to be able to see through this mess.
Something like ScopedStorage.pickFiles(Consumer<List<Path>>) would be nice, opening a system dialog where the user selects the files/folders my app should get access to. But that would be far too simple for an Android API..
1
u/stereomatch May 24 '20 edited May 24 '20
I really don't know, the API once again seems so over-engineered, MediaStore, DocumentProvider, DocumentContract.buildDocumentUriUsingTree, whatever. Without having implemented it, I have no hope to be able to see through this mess.
There are plenty of ways to do it cleanly IF that was the intent.
If you look at the KitKat playbook we know how they killed seamless ext SD card access.
This looks to be a repeat - with avoidance of easy/enabling ways, and choosing the most obfuscated of "alternative APIs".
Which supports the notion that intent is not to make your life easier but to tilt the balance in favor of app-specific folder (non-persistent) only - which is the ONLY way you can use standard file io - for example fopen() in NDK C code - which means ALL legacy apps will fall into this (non-persistent) basket.
Those devs who are overeager to keep persistence - they diminish their enthusiasm by offering these "alternate APIs" which are decidedly badly engineered/inconsistent/non-orthogonal - AND slower (we now know from dev input that SAF is 20x slower on some operations).
So you tell me what is going on ?
I have said from the start what Google's intention of the KitKat/ext SD card experience - and what articles had been saying at that time - that Google will never be able to get cloud revenue started if cheap, immediate SD cards were a readily available option.
So what did they do - they used their benchmark Nexus, then Pixel phones to drive through this whole thinking that "ext SD cards are bad" - you will find devs on reddit proud of that "fact".
Meanwhile manufacturers resisted - some held on, while others saw KitKat had reduced "need" (actually usability) of ext SD card - so why add it if former Nexus owners have forgotten it, and those who have ext SD card, for those most apps after KitKat no longer can seamlessly use them anyway.
So we are witnessing the fragmentation/dismantling of persistent local storage as an option for users before our eyes.
1
u/Tolriq May 24 '20
This means that private conversations would be public with anyone having read access. Not really the proper way.
Since SAF can't access the private data anymore, now the application needs to either create an complex document provider so that other apps can connect to it, or add buttons in the app so that the user can export the recording to something that may or not be able to read it. Or use that export function to duplicate the file to media store later.
Many simple things will now be a lot more complicated.
1
May 24 '20
Yeah, I don't doubt that it will be complicated. Looks over-engineered as hell to me.
I had another look, so MediaStore doesn't work with a picker, access is granted to the entire library as far as I understood. That seems rather pointless..
And for the the actual picker thing, one needs this DocumentProvider API, right? I was under the impression that there would be like a system document provider where a dialog is shown to the user to pick from storage. If that's not the case, then I really don't see the purpose behind that whole Scoped storage API either..
2
u/Tolriq May 24 '20
There is a system one but no access to private folders :)
+ Prevent selection of Download folder / root folder as folders to allow easy action on multiple files.
This will be a mess for users as they won't understand why random stuff are not allowed without any explanation to them.
They will only complain to the devs and bad rate :)
4
u/anemomylos 🛡️ May 24 '20 edited May 24 '20
Not exactly because the image editor app, not being a "file manager", will not be able to use SAF to read/write files to any location you choose.
EDT it seems that i'm wrong on this based on this thread: https://www.reddit.com/r/android_devs/comments/gpkofk/this_tutorial_article_introduces_you_to_the/frmw63q?utm_source=share&utm_medium=web2x
2
2
u/TotesMessenger May 24 '20
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
[/r/androiddev] This tutorial article introduces you to the complexity that awaits apps with the Scoped Storage changes in Android : android_devs
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
0
May 24 '20
[deleted]
3
u/stereomatch May 24 '20
Maybe someone can cross-post it to r/android (I am perma-banned there).
2
u/twigboy May 24 '20 edited Dec 09 '23
In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available. Wikipediaaol35zlx1ko000000000000000000000000000000000000000000000000000000000000
1
u/stereomatch May 24 '20
Thanks!
2
u/twigboy May 25 '20 edited Dec 09 '23
In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available. Wikipedia88llsgnng840000000000000000000000000000000000000000000000000000000000000
1
3
u/CuriousCursor May 24 '20
Can't the audio recorder app use SAF to let the user save it where they want?