Skip to content

Add the ability to specify bluetooth permission#2522

Merged
freakboy3742 merged 13 commits intobeeware:mainfrom
depaolim:permissions_bluetooth
Nov 14, 2025
Merged

Add the ability to specify bluetooth permission#2522
freakboy3742 merged 13 commits intobeeware:mainfrom
depaolim:permissions_bluetooth

Conversation

@depaolim
Copy link
Copy Markdown
Contributor

@depaolim depaolim commented Oct 20, 2025

Add the ability to specify bluetooth permission for android

Allows you to specify the enabling of permissions for using Bluetooth on the Android device

Inspired by #1599

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@depaolim
Copy link
Copy Markdown
Contributor Author

Apologies, I'm not sure what's causing the build failures. If you can provide any hints or steps to reproduce the issue locally, I'd be happy to take a look and try to fix it.

@rmartin16
Copy link
Copy Markdown
Member

There was a significant AWS outage affecting Docker among many others. I re-ran the jobs for you.

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. The implementation and tests for this look perfectly good for Android; but we need to do a little more investigation before we can accept this as a change in Briefcase.

Briefcase's top level configuration for permissions is explicitly cross platform. That means we need at least a cursory investigation into whether a simple bluetooth permission will be sufficient on other platforms - iOS, macOS, Windows, and Linux.

We don't necessarily need to you implement permissions for other platforms - but we need to know that we have sufficient granularity in our cross-platform permissions to capture the necessary features.

@timrid
Copy link
Copy Markdown
Contributor

timrid commented Oct 21, 2025

A few weeks ago I investigated a little regards bleak and briefcase on macOS and added some documetation in an bleak PR.

I am also currently working on iOS support for bleak (see hbldh/bleak#1833). But it will take some time until I have tested the permissions with an iOS device. However, I think it will be very similar to macOS.

AFAIK For Windows and Linux there is no similar permissions concept for bluetooth.

@depaolim
Copy link
Copy Markdown
Contributor Author

Thanks for the PR. The implementation and tests for this look perfectly good for Android; but we need to do a little more investigation before we can accept this as a change in Briefcase.

Briefcase's top level configuration for permissions is explicitly cross platform. That means we need at least a cursory investigation into whether a simple bluetooth permission will be sufficient on other platforms - iOS, macOS, Windows, and Linux.

We don't necessarily need to you implement permissions for other platforms - but we need to know that we have sufficient granularity in our cross-platform permissions to capture the necessary features.

Your position makes perfect sense.

@depaolim
Copy link
Copy Markdown
Contributor Author

At the moment, I haven't found a straightforward way to use Bluetooth in a cross-platform manner with BeeWare, similar to how the GUI works with Toga. I've written separate experimental code snippets for Linux and Android. For Linux (and Windows), I used the python's socket implementation, while on Android I used objects from the "android.bluetooth" package. However, I haven't found a simple way to abstract this and write unified code that works across Linux, Windows, Android (and possibly iOS).
My use case is quite simple: I need to open a socket using a Bluetooth address, then perform recv/send operations. I've read several tickets discussing the use of Bleak or other solutions, but I haven't found a truly BeeWare-like approach (unlike the excellent abstractions BeeWare provides in other areas).
Do you have any suggestions or guidance on this?

@freakboy3742
Copy link
Copy Markdown
Member

At the moment, I haven't found a straightforward way to use Bluetooth in a cross-platform manner with BeeWare, similar to how the GUI works with Toga... Do you have any suggestions or guidance on this?

At present, no. You're not the first person to ask about Bluetooth support, and it's an obvious area for a mobile app (or desktop app, for that matter) to support. However, I haven't done a lot of work with Bluetooth myself, so I don't have any particular advice to give. As you've noted, Bleak is usually the suggestion that comes up; but I haven't used it myself, and I'm aware that it doesn't offer an iOS solution at present (although evidently @timrid is looking into that).

@depaolim
Copy link
Copy Markdown
Contributor Author

At the moment, I haven't found a straightforward way to use Bluetooth in a cross-platform manner with BeeWare, similar to how the GUI works with Toga... Do you have any suggestions or guidance on this?

At present, no. You're not the first person to ask about Bluetooth support, and it's an obvious area for a mobile app (or desktop app, for that matter) to support. However, I haven't done a lot of work with Bluetooth myself, so I don't have any particular advice to give. As you've noted, Bleak is usually the suggestion that comes up; but I haven't used it myself, and I'm aware that it doesn't offer an iOS solution at present (although evidently @timrid is looking into that).

Thanks for your feedback!
(I was thinking that another challenge with adding Bluetooth support to BeeWare in the future is that unit testing Bluetooth behavior in CI pipelines is difficult, since smartphone emulators, as far as I know, don’t support Bluetooth.)

Comment thread src/briefcase/platforms/android/gradle.py Outdated
@timrid
Copy link
Copy Markdown
Contributor

timrid commented Nov 5, 2025

I just verified that bluetooth is working with iOS 26.1 on an iPhone 16 by using this branch hbldh/bleak#1853. For permission handling I had to add:

[tool.briefcase.app.bleakbleexplorer.iOS]
info."NSBluetoothAlwaysUsageDescription" = "This is your description shown to the user. Explain why the app needs Bluetooth access."
image

On macOS Sequoia 15.5 I had to add the same as on iOS:

[tool.briefcase.app.bleakbleexplorer.macOS]
info."NSBluetoothAlwaysUsageDescription" = "This is your description shown to the user. Explain why the app needs Bluetooth access."
image

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

This looks good; I've flagged a couple issues related to documentation and an edge case of permissions handling.

The other detail: if we're going to fix the permission = False handling, we should also add a second changenote (2522.bugfix.md) that describes the fact that we're now handling permission disabling correctly.

Comment thread docs/en/reference/configuration.md
Comment thread src/briefcase/platforms/android/gradle.py
Comment thread src/briefcase/platforms/android/gradle.py Outdated
Comment thread changes/2522.feature.md
@depaolim
Copy link
Copy Markdown
Contributor Author

depaolim commented Nov 7, 2025

Thanks for the feedback, I'll try to get to it next week

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

One tweak to documentation, plus the update to the template, and I think we'll be good to go!

Comment thread docs/en/reference/platforms/android/gradle.md Outdated
Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

Thanks for those updates - this looks great!

@freakboy3742 freakboy3742 merged commit 1cb77f2 into beeware:main Nov 14, 2025
58 checks passed
@depaolim
Copy link
Copy Markdown
Contributor Author

Thanks for those updates - this looks great!

Happy to contribute to this fantastic project and thank you for your valuable suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants