KEMBAR78
Permission bug: Bluetooth scanning without location permission on Android 12+ · Issue #20871 · dotnet/maui · GitHub
Skip to content

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

@janusw

Description

@janusw

Description

Since Android 12, it is possible to do Bluetooth scanning without location permissions. To achieve this, one has to declare the BT scanning permission in the Android manifest like this:

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />

Requesting the permissions at runtime works well for this scenario, as long as ACCESS_FINE_LOCATION is not declared in the manifest:

            PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.Bluetooth>();

            if (status != PermissionStatus.Granted)
                status = await Permissions.RequestAsync<Permissions.Bluetooth>();

However, if ACCESS_FINE_LOCATION is declared in the manifest, but is denied at runtime (while BLUETOOTH_SCAN is granted), then the snippet above reports the status as PermissionStatus.Denied.

This wrongly signals to the application that scanning is not possible, while in fact it is.

Steps to Reproduce

  1. Check out the dotnet-bluetooth-le repository (link below).
  2. Build the sample BLE.Client.MAUI and run it on a Android 12+ device.
  3. Reject the location permission, but accept the Bluetooth/Nearby devices permission at runtime.
  4. As a result, the app will not start scanning (although it could): "Permissions denied. Not scanning."

Link to public reproduction project repository

https://github.com/dotnet-bluetooth-le/dotnet-bluetooth-le

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12 and up

Did you find any workaround?

Ignore the wrong permission status.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-essentialsEssentials: Device, Display, Connectivity, Secure Storage, Sensors, App Infoplatform/androidt/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions