Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

Permissions: buffer location permission status on UWP

Open janusw opened this issue 3 years ago • 3 comments

Description of Change

This fixes a problem with location permissions on UWP. The problem is caused by a combination of several points:

  • Requesting the location permission on UWP can only be done on the main thread.
  • Querying the location automatically checks the permissions.
  • Checking the permission status on UWP does the same thing as requesting the permission, see https://github.com/xamarin/Essentials/blob/7218ab88f7fbe00ec3379bd54e6c0ce35ffc0c22/Xamarin.Essentials/Permissions/Permissions.uwp.cs#L40:L41

All of this together means that it is currently impossible to query the location outside of the main thread, because a PermissionException is triggered ("Permission request must be invoked on the main thread").

To fix it, I'm buffering the location permission status, so that it only needs to be checked/requested once (if granted), and after that we can just return the buffered value, so that querying the location outside of the main thread becomes possible.

Bugs Fixed

  • Related to issue #1771

API Changes

None.

Behavioral Changes

None.

PR Checklist

  • [ ] Has tests (if omitted, state reason in description)
  • [ ] Has samples (if omitted, state reason in description)
  • [X] Rebased on top of main at time of PR
  • [X] Changes adhere to coding standard
  • [ ] Updated documentation (see walkthrough)

janusw avatar Apr 26 '21 08:04 janusw

Docs Build status updates of commit a981f01:

:x: Validation status: errors

Please follow instructions here which may help to resolve issue.

File Status Preview URL Details
:x:Error Details

  • [Error-InsufficientPermissionOnRepo] User mimisasouvanh does not have sufficient permission on https://github.com/xamarin/Essentials repository. Hint: required permission 'Read', actual permission 'None'.

For more details, please refer to the build report.

If you see build warnings/errors with permission issues, it might be due to single sign-on (SSO) enabled on Microsoft's GitHub organizations. Please follow instructions here to re-authorize your GitHub account to Docs Build.

Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.

Note: Your PR may contain errors or warnings unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.

For any questions, please:

opbld33 avatar Apr 26 '21 08:04 opbld33

Docs Build status updates of commit 9e80679:

:x: Validation status: errors

Please follow instructions here which may help to resolve issue.

File Status Preview URL Details
:x:Error Details

  • [Error-InsufficientPermissionOnRepo] User mimisasouvanh does not have sufficient permission on https://github.com/xamarin/Essentials repository. Hint: required permission 'Read', actual permission 'None'.

For more details, please refer to the build report.

If you see build warnings/errors with permission issues, it might be due to single sign-on (SSO) enabled on Microsoft's GitHub organizations. Please follow instructions here to re-authorize your GitHub account to Docs Build.

Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.

Note: Your PR may contain errors or warnings unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.

For any questions, please:

opbld31 avatar May 01 '21 11:05 opbld31

Rebased to 1.7.0.

janusw avatar Jul 15 '21 21:07 janusw

I'm on the fence about still adding this one. It seems safe enough, on the other hand, it has been open for some time without too much traction from other people. Therefore it seems a potential risk of breaking people at this time while there are not a lot of people waiting for this change.

I guess the workaround here is to request the permission manually instead of relying on our code to do it.

Thank you for all the work and effort on this!

jfversluis avatar Dec 07 '23 14:12 jfversluis