Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

[Bug] Android 12: "Approximate" Location Permissions Returns Denied #1912

Closed
SharpMobileCode opened this issue Oct 28, 2021 · 10 comments · Fixed by #1937
Closed

[Bug] Android 12: "Approximate" Location Permissions Returns Denied #1912

SharpMobileCode opened this issue Oct 28, 2021 · 10 comments · Fixed by #1937
Labels
bug Something isn't working

Comments

@SharpMobileCode
Copy link

Description

On an Android 12 device or emulator, the Permissions.RequestAsync<Permissions.LocationWhenInUse>() call returns PermissionStatus.Denied when user selects "Approximate" location. It should return PermissionStatus.Granted

Steps to Reproduce

  1. Clone or download this repo: https://github.com/SharpMobileCode/Android12XamEssentialsBug
  2. Run the Android application on an Android 12 device or emulator.
  3. Tap the "Request Location Permission" button.
  4. Select "Approximate".
  5. Select "While using the app" or "Only this time".

Expected Behavior

Returns PermissionStatus.Granted

Actual Behavior

Returns PermissionStatus.Denied

Basic Information

  • Version with issue: 1.7.0
  • Last known good version:
  • IDE: Visual Studio 2019 for Mac
  • Platform Target Frameworks: API Level 30
    • Android: API Level 30
  • Android Support Library Version:
  • Nuget Packages: Xamarin.Essentials, Xamarin.Forms
  • Affected Devices: All devices running Android 12

Reproduction Link

https://github.com/SharpMobileCode/Android12XamEssentialsBug

@SharpMobileCode SharpMobileCode added the bug Something isn't working label Oct 28, 2021
@SharpMobileCode
Copy link
Author

This seems to be the problem:

if (grantResults.Any(g => g == Permission.Denied))

When the Permission request is being made for Android.Permission.COARSE and Android.Permission.FINE, they are now individual permissions. When the user selects "Approximate", then COARSE returns Granted and FINE returns Denied. Since that piece of code is looking for ANY denied permission, it is failing the entire request.

I'm not sure what the thought process behind denying the entire request was, so I'm not sure what the next step is. @jfversluis, any idea? Oh, and sorry this boomeranged back to you :)

@jfversluis
Copy link
Member

Hey @SharpMobileCode! Thanks for the report and helping with the investigation. Don't worry about getting this on my plate 😄

I'm looking into this now, hoping to have something soon. So my thinking is that in the case of the locations we should add a different path here then that check if either of those is Granted?

@aritchie pinging you as well as you had some input on this?

@aritchie
Copy link
Contributor

aritchie commented Nov 2, 2021

@jfversluis I'm looking into sending a PR. There are a few issues with permissions around this. The LocationAlways is even more bugged FYI ;)

Android 12 introduced the ability for the user to deny fine location, but instead grant coarse in its place.

@jfversluis
Copy link
Member

Awesome! Appreciate it! I'll be waiting for that PR or let me know if you can't do it so I can take over :)

@SharpMobileCode
Copy link
Author

Thank you both! I think this may also fix #1871 if I'm following the code path correctly.

@aritchie
Copy link
Contributor

aritchie commented Nov 2, 2021

In the meantime, people can just set their targets as android 10. You don't need to be on the latest target for Xamarin Forms and most xamarin libs right now.

@SharpMobileCode
Copy link
Author

That's good to know! Just one thing to be aware of. Google Play is now requiring targeting API Level 30 (Android 11) for existing apps starting this month for app updates.

@jfversluis
Copy link
Member

@aritchie let me know if you're still looking into this. Else I will be in the near future :)

@aritchie
Copy link
Contributor

aritchie commented Dec 2, 2021

@jfversluis Sorry about that, I forgot all about this. I've got this fixed up in Shiny, so I can bring it here. There is a couple of things to discuss here as the issue is bigger as it includes issues with LocationAlways as well. The current architecture is limiting and requires a number of changes to support the way android does batches of permissions now.

Let me know if you agree with the following:

  1. Even when you request precise location, you have to request coarse. If the user denies precise location, essentials should return restricted - not denied. Denied should only be returned when coarse & precise are both denied because you aren't getting ANY GPS at that point.
  2. For LocationAlways, background location is now requested separately from coarse/precise because it opens a settings popup from Android. If background is denied, but coarse/precise is granted - essentials should return restricted, not denied otherwise only denied if coarse & precise are again denied.
  3. The architecture of all the permissions on Android need to be updated to be able to support groups of requests.

@KirylAkulich1
Copy link

As I see you use Restricted state for LocationWhenInUse. An you also fix comments for enum https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/Permissions/Permissions.shared.enums.cs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
4 participants