KEMBAR78
Expose `usesPermissionFlags` in `UsesPermissionAttribute` for Android API 31+ Bluetooth permissions by Copilot · Pull Request #10411 · dotnet/android · GitHub
Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 13, 2025

Since Android API level 31, location permission is no longer required for using Bluetooth APIs if developers strongly assert that their app doesn't derive physical location from Bluetooth scan results. This is done by setting usesPermissionFlags="neverForLocation" in the AndroidManifest.xml:

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

However, the usesPermissionFlags attribute was not exposed in the .NET UsesPermissionAttribute, preventing developers from using this Android feature.

Changes Made

This PR exposes the usesPermissionFlags attribute by:

  1. Making the attribute visible in metadata.xml to enable auto-generation by the manifest-attribute-codegen system
  2. Adding comprehensive test to verify the attribute generates correct XML

The implementation leverages the existing auto-generation system instead of manual modifications, ensuring consistency with the codebase architecture.

Usage Examples

Developers can now use:

// Property assignment (auto-generated property)
[assembly: UsesPermission(Name = "android.permission.BLUETOOTH_SCAN", 
                         UsesPermissionFlags = "neverForLocation")]

This generates the correct AndroidManifest.xml entry as specified in Android documentation.

Fixes #10409.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Expose usesPermissionFlags in UsesPermissionAttribute Expose usesPermissionFlags in UsesPermissionAttribute for Android API 31+ Bluetooth permissions Aug 13, 2025
Copilot finished work on behalf of jonathanpeppers August 13, 2025 17:07
Copilot AI requested a review from jonathanpeppers August 13, 2025 17:07
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

@copilot a few suggestions to improve this.

…hanges and use auto-generation

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI requested a review from jonathanpeppers August 13, 2025 17:49
Copilot finished work on behalf of jonathanpeppers August 13, 2025 17:49
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

New test looks OK:

Image

@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 14, 2025 17:46
@jonathanpeppers jonathanpeppers enabled auto-merge (squash) August 14, 2025 17:51
@jonathanpeppers jonathanpeppers merged commit cfd3915 into main Aug 14, 2025
59 checks passed
@jonathanpeppers jonathanpeppers deleted the copilot/fix-10409 branch August 14, 2025 22:20
@github-actions github-actions bot locked and limited conversation to collaborators Sep 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose usesPermissionFlags in UsesPermissionAttribute

2 participants