KEMBAR78
Permissions (BT & WiFi): don't add AccessFineLocation to required permissions if NeverForLocation flag is present by janusw · Pull Request #20874 · dotnet/maui · GitHub
Skip to content

Conversation

janusw
Copy link
Contributor

@janusw janusw commented Feb 27, 2024

Description of Change

This fixes #20871, by making sure that AccessFineLocation is not added to the required permissions for Permissions.Bluetooth or Permissions.NearbyWifiDevices if they are declared with the NeverForLocation flag.
Otherwise the permission status will be PermissionStatus.Denied, if AccessFineLocation is in the manifest but denied at runtime (even if it is not strictly required).

Issues Fixed

Fixes #20871

@janusw janusw requested a review from a team as a code owner February 27, 2024 20:38
@janusw janusw requested review from PureWeen and rmarinho February 27, 2024 20:38
@ghost ghost added the community ✨ Community Contribution label Feb 27, 2024
@ghost
Copy link

ghost commented Feb 27, 2024

Hey there @janusw! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@jfversluis
Copy link
Member

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis jfversluis added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Feb 28, 2024
@janusw
Copy link
Contributor Author

janusw commented Oct 8, 2024

Ping! Can this be included in .NET 9, please? It has been waiting for more than half a year! @rmarinho @PureWeen

@walnut-co
Copy link

Someone, please approve this PR. It's hurting the development and new features.

@janusw @shanselman

@gauravsk1996
Copy link

gauravsk1996 commented Jun 27, 2025

Someone, please approve the PR. This should be the part of MAUI. please make it happen it would help the developers.

@bernieEV
Copy link

please get Bluetooth and Wifi independent from LOCATION permission.

…missions if NeverForLocation flag is present

* otherwise the permission-status will be 'denied' if AccessFineLocation is in the manifest, but denied at runtime
  (even if it is not strictly required)
@janusw janusw force-pushed the permissions_fix_neverforlocation branch from b315053 to 2159c41 Compare June 27, 2025 14:11
@janusw
Copy link
Contributor Author

janusw commented Jun 28, 2025

I have rebased this on the current main branch.

@jfversluis @rmarinho @PureWeen Can we please get this into MAUI v10? It's a relatively simple fix without any API changes ...

@jfversluis jfversluis requested a review from Copilot June 30, 2025 13:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that AccessFineLocation is not added to the required permissions for Bluetooth and WiFi when the NeverForLocation flag is declared, resolving issue #20871.

  • Added HasFlagInManifest to detect NeverForLocation flags in the manifest.
  • Updated the RequiredPermissions logic for Bluetooth and NearbyWifiDevices to skip AccessFineLocation if the flag is present.
  • Removed redundant manifest checks for older Android SDK versions (<= R and < Tiramisu).
Comments suppressed due to low confidence (3)

src/Essentials/src/Permissions/Permissions.android.cs:239

  • New behavior around skipping AccessFineLocation when the NeverForLocation flag is set needs automated tests. Please add cases in TestCases.Shared.Tests and TestCases.HostApp to cover both Bluetooth and WiFi scenarios.
						if (IsDeclaredInManifest(Manifest.Permission.AccessFineLocation) && !HasFlagInManifest(Manifest.Permission.BluetoothScan, RequestedPermission.NeverForLocation))

src/Essentials/src/Permissions/Permissions.android.cs:7

  • [nitpick] The docs in /docs/ should be updated to describe the new NeverForLocation flag behavior for Bluetooth and NearbyWifiDevices permissions so that public documentation matches the implementation.
using Android.Content.PM;

src/Essentials/src/Permissions/Permissions.android.cs:36

  • Using requestedPermissions.Count on an array is invalid and may throw. Switch to requestedPermissions.Length (and similarly for requestedPermissionsFlags) and guard against requestedPermissions or requestedPermissionsFlags being null before the loop.
			for (int i=0; i<requestedPermissions.Count; i++)

@jfversluis
Copy link
Member

jfversluis commented Jun 30, 2025

Hey everyone, sorry this fell between the cracks. While I absolutely agree we should take this and lets make it happen, I just wanted to note that for a lot of this stuff, especially permissions, you shouldn't be blocked on it since it is very extensible: https://learn.microsoft.com/dotnet/maui/platform-integration/appmodel/permissions?view=net-maui-9.0&tabs=android#extending-permissions sure, if we do it its easier for you, but you shouldn't be blocked on this. Just wanted to let you know! :)

Now with that, lets see if we can get this in, thanks for all the hard work @janusw!

Also if anyone here would be able to grab the artifacts from this build and test it out and let us know if it doesn't have any unexpected side-effects, that would be amazing! See instructions for that here: https://github.com/dotnet/maui/wiki/Testing-PR-Builds

@jfversluis
Copy link
Member

/azp run MAUI-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis jfversluis modified the milestones: .NET 9 SR9, .NET 9 SR10 Jun 30, 2025
@PureWeen PureWeen changed the base branch from main to inflight/current July 1, 2025 16:20
@PureWeen PureWeen merged commit c48d5a9 into dotnet:inflight/current Jul 1, 2025
17 checks passed
github-actions bot pushed a commit that referenced this pull request Jul 2, 2025
…missions if NeverForLocation flag is present (#20874)

* otherwise the permission-status will be 'denied' if AccessFineLocation is in the manifest, but denied at runtime
  (even if it is not strictly required)
github-actions bot pushed a commit that referenced this pull request Jul 8, 2025
…missions if NeverForLocation flag is present (#20874)

* otherwise the permission-status will be 'denied' if AccessFineLocation is in the manifest, but denied at runtime
  (even if it is not strictly required)
github-actions bot pushed a commit that referenced this pull request Jul 9, 2025
…missions if NeverForLocation flag is present (#20874)

* otherwise the permission-status will be 'denied' if AccessFineLocation is in the manifest, but denied at runtime
  (even if it is not strictly required)
PureWeen pushed a commit that referenced this pull request Jul 10, 2025
…missions if NeverForLocation flag is present (#20874)

* otherwise the permission-status will be 'denied' if AccessFineLocation is in the manifest, but denied at runtime
  (even if it is not strictly required)
PureWeen pushed a commit that referenced this pull request Jul 15, 2025
…missions if NeverForLocation flag is present (#20874)

* otherwise the permission-status will be 'denied' if AccessFineLocation is in the manifest, but denied at runtime
  (even if it is not strictly required)
PureWeen pushed a commit that referenced this pull request Jul 17, 2025
…missions if NeverForLocation flag is present (#20874)

* otherwise the permission-status will be 'denied' if AccessFineLocation is in the manifest, but denied at runtime
  (even if it is not strictly required)
github-actions bot pushed a commit that referenced this pull request Jul 25, 2025
…missions if NeverForLocation flag is present (#20874)

* otherwise the permission-status will be 'denied' if AccessFineLocation is in the manifest, but denied at runtime
  (even if it is not strictly required)
github-actions bot pushed a commit that referenced this pull request Jul 31, 2025
…missions if NeverForLocation flag is present (#20874)

* otherwise the permission-status will be 'denied' if AccessFineLocation is in the manifest, but denied at runtime
  (even if it is not strictly required)
@github-actions github-actions bot locked and limited conversation to collaborators Aug 1, 2025
@janusw janusw deleted the permissions_fix_neverforlocation branch August 2, 2025 07:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info community ✨ Community Contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permission bug: Bluetooth scanning without location permission on Android 12+

6 participants