Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bluez5: Clean up static default properties, re-drop PairDevice class_ parameter #192

Merged
merged 1 commit into from Dec 23, 2023

Conversation

martinpitt
Copy link
Owner

@martinpitt martinpitt commented Dec 21, 2023

Over the years, this template has accumulated some hacks and bad API which made PairDevice()'s handling of the Modalias/Class/Icon properties buggy and hard to understand:

  • These are static device properties, they are not supposed to change during pairing.
  • Commit ee29a44 added these as some kind of "dynamic fallback default" when they were not initialized by the caller after AddDevice().
  • Commit 59d6af0 silently broke that fallback default by changing AddDevice() to set these device properties to empty strings.
  • Commit fae4be7 added another really bad API for setting Class in PairDevice()(). That API didn't fit into D-Bus (see commit 8968284 which had to make it a non-default parameter) and also broke the API, and moreover it is totally unintuitive -- the device class has nothing to do with pairing.

Clean up all of these: Set the static property defaults in AddDevice() right away, so that the caller can adjust them afterwards. Re-drop the class_ argument in PairDevice(). Adjust the documentation of AddDevice() to point out that properties should be changed after calling that.

Consequently, PairDevice() will stop claiming that the static properties changed. This also gets rid of some redundant code.


@z3ntu, this is meant to fix and Closes #190 .

@pwithnall @hadess @bjoernh I admittedly don't understand the use cases/current callers of this code. I think some API change is inevitable here to clean up, but it should at least make sense. I'd appreciate if you could check my reasoning and do some sanity testing on this with your existing tests. Cheers!

… parameter

Over the years, this template has accumulated some hacks and bad API
which made PairDevice()'s handling of the Modalias/Class/Icon properties
buggy and hard to understand:

 * These are *static* device properties, they are not supposed to change
   during pairing.
 * Commit ee29a44 added these as some kind of "dynamic fallback
   default" when they were not initialized by the caller after
   AddDevice().
 * Commit 59d6af0 silently broke that fallback default by changing
   AddDevice() to set these device properties to empty strings.
 * Commit fae4be7 added another really bad API for setting Class
   in PairDevice()(). That API didn't fit into D-Bus (see commit
   8968284 which had to make it a non-default parameter) and also
   broke the API, and moreover it is totally unintuitive -- the device
   class has nothing to do with pairing.

Clean up all of these: Set the static property defaults in AddDevice()
right away, so that the caller can adjust them afterwards. Re-drop the
`class_` argument in PairDevice(). Adjust the documentation of
AddDevice() to point out that properties should be changed after calling
that.

Consequently, PairDevice() will stop claiming that the static properties
changed. This also gets rid of some redundant code.
@pwithnall
Copy link
Contributor

I admittedly don't understand the use cases/current callers of this code. I think some API change is inevitable here to clean up, but it should at least make sense. I'd appreciate if you could check my reasoning and do some sanity testing on this with your existing tests. Cheers!

IIRC, I was using BlueZ in python-dbusmock to test part of libfolks, which is something I haven’t worked on for a long time now. I’m afraid I’m not going to resurrect my involvement in it to test this PR, sorry! If (in the unlikely case that) this PR breaks things in libfolks, I’m sure libfolks can be reworked to use the new approach here.

@martinpitt
Copy link
Owner Author

Thanks @pwithnall. @ricotz and @nielsdg you seem to have worked on libfolks recently -- does this change work for/make sense to you?

@nielsdg
Copy link

nielsdg commented Dec 23, 2023

I think it's fine to land this since it seems to fix a couple of issues and we can fix this in a reactive manner once it breaks CI (and honestly, i had to fix our CI for something similar a while ago already, see https://gitlab.gnome.org/GNOME/folks/-/commit/b6b7d41aad9e36e0). The bluez backend is barely used, and this would only affect testing at this point in any case.

@martinpitt
Copy link
Owner Author

Thanks @nielsdg for checking! Let's go with this then, even if it causes some noise I think it'll make the whole thing a lot easier to understand and adjust at least.

@martinpitt martinpitt merged commit 63264e1 into main Dec 23, 2023
26 checks passed
@martinpitt martinpitt deleted the bluez-cleanup branch December 23, 2023 21:10
@martinpitt
Copy link
Owner Author

@nielsdg And right, https://gitlab.gnome.org/GNOME/folks/-/commit/b6b7d41aad9e36e0 would have to be reverted again.

@z3ntu
Copy link

z3ntu commented Dec 24, 2023

Sorry for the delay, I tested with lomiri-system-settings tests and they do work also with this PR :) Thanks for fixing this!

But also similarly we need to revert this commit there https://gitlab.com/ubports/development/core/lomiri-system-settings/-/commit/b9aacd88e3789dbb7578f32b31ad5b239db227a2

gnomesysadmins pushed a commit to GNOME/folks that referenced this pull request Jan 12, 2024
erikinkinen pushed a commit to droidian/upower that referenced this pull request Feb 15, 2024
dbusmock 0.30.1 changed the BlueZ template to set the default "Class"
property to `MOCK_PHONE_CLASS` right away instead of in PairDevice() [1].

test_bluetooth_le_device() relied on the previous implicit default of a
"0" Class value. Set this explicitly to expect a "generic" device. This
makes the test work with old and current dbusmock versions.

https://bugs.debian.org/1059467

[1] martinpitt/python-dbusmock#192
erikinkinen pushed a commit to droidian/upower that referenced this pull request Feb 15, 2024
dbusmock 0.30.1 changed the BlueZ template to set the default "Class"
property to `MOCK_PHONE_CLASS` right away instead of in PairDevice() [1].

test_bluetooth_le_device() relied on the previous implicit default of a
"0" Class value. Set this explicitly to expect a "generic" device. This
makes the test work with old and current dbusmock versions.

https://bugs.debian.org/1059467

[1] martinpitt/python-dbusmock#192
erikinkinen pushed a commit to droidian/upower that referenced this pull request Feb 15, 2024
dbusmock 0.30.1 changed the BlueZ template to set the default "Class"
property to `MOCK_PHONE_CLASS` right away instead of in PairDevice() [1].

test_bluetooth_le_device() relied on the previous implicit default of a
"0" Class value. Set this explicitly to expect a "generic" device. This
makes the test work with old and current dbusmock versions.

https://bugs.debian.org/1059467

[1] martinpitt/python-dbusmock#192
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.

None yet

4 participants