Open MitchBomcanhao opened 1 year ago
IMHO it isn't an issue - you need by design of permissions API to request explicitly them each time when you're trying to get an access to functionality which requires them
do you think it is normal for this to blow up on specific versions of android? it is essentials' job to make sure they have requested the necessary permissions in order to achieve its functionality. there's nothing in the documentation stating that you have to request this permission yourself before calling the method. Xamarin essentials does still check for permissions in other areas of the code, so why not here? from a consistency standpoint, this is broken. We shouldn't have to be checking android versions and checking specific permissions when it is the package's job to do that when necessary.
do you think it is normal for this to blow up on specific versions of android?
yes and not only for android. It's requirement of android and iOS SDK - you have to explicitly ask user about permission (if it's disabled) right before access to permission-related code
But cuz your business logic can vary depends on to specific functionality - better to call explicitly Essentials.Permissions at your own code and handle results
We shouldn't have to be checking android versions and checking specific permissions when it is the package's job to do that when necessary
What about Android-specific permissions - most of them have analogue on other platforms and common handlers at Essentials.Permissions, so you can call them)
If you don't have handler for some specific permission - you can implement it for your specific case
I know I can implement it - but that's not the point, is it? we can implement anything we want. but the essentials package is supposed to do these things for us, and indeed they do... but not on this particular case. so it is a bug because their permission checks aren't sufficient.
Description
After updating our solution to the newest Android 13 supporting packages from Essentials and Forms, and adapting the code to the new expectations regarding permissions, I've found that I could make the photo picker crash with a UnauthorizedAccessException whenever I was on Android 9 and I picked a photo in a certain way. I cannot reproduce this issue on devices running Android 10 and higher, which I assume is related to changes in permissions that also resulted in previous issues such as the following, which were identified on android 10+:
1574
1584
It is possible that the same issue already existed in older versions of essentials but as there were different expectations regarding permissions, ie we always requested Permissions.StorageRead when picking photos. Now the expectation is that you might not have to explicitly request storage permissions and it seems to still work, except on some older android versions.
Xamarin essentials actually checks for certain permissions before running some of its picking/camera tasks (and some of those checks are even api level dependent), so it is sort of implied that if essentials does not check for a permission, it is likely unnecessary? is there something in the documentation that says we have to request Permissions.StorageRead when picking photos, even though essentials doesn't check for it and it doesn't seem to be necessary for android 10+? is there an exception somewhere that says we have to still request it for android 9 and under?
Steps to Reproduce
Expected Behavior
File is accessible after picking.
Actual Behavior
App will crash with an UnauthorizedAccessException when we attempt to access it.
Basic Information
Reproduction Link
Android's AssemblyInfo.cs file declares:
I just have a plain xaml page with a button that runs this on its clicked event:
The above code will fail on
fr.OpenReadAsync()
when you're on android 9 and you haven't got StorageRead permission. It'll work fine on Android 10+.Workaround
Call
await Xamarin.Essentials.Permissions.RequestAsync<Permissions.StorageRead>();
before running this code, only if your device is running an android version lower than 10.