bluetooth: try getting battery percentage from upower if missing from bluez#2967
bluetooth: try getting battery percentage from upower if missing from bluez#2967jinliu wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a UPower-based fallback to display Bluetooth device battery percentages when BlueZ doesn’t report them.
Changes:
- Pass
UPowerService*into Control Center’sBluetoothTaband the barBluetoothWidget. - Query UPower by Bluetooth address to show battery % in the device list rows and widget tooltip.
- Normalize Bluetooth addresses via
StringUtils::toLower(...)before querying UPower.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/shell/control_center/control_center_panel.cpp | Wires UPowerService* into BluetoothTab construction. |
| src/shell/control_center/bluetooth_tab.h | Extends BluetoothTab API to accept/store UPowerService*. |
| src/shell/control_center/bluetooth_tab.cpp | Uses UPower as fallback battery source for device rows. |
| src/shell/bar/widgets/bluetooth_widget.h | Extends BluetoothWidget API to accept/store UPowerService*. |
| src/shell/bar/widgets/bluetooth_widget.cpp | Uses UPower as fallback battery source in tooltip. |
| src/shell/bar/widget_factory.cpp | Passes m_upower into BluetoothWidget creation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… bluez Bluetooth widget / tab will now also query UPowerService for battery percentage if BluetoothService doesn't provide it. An example of this is the Playstation 5 controller.
1917b26 to
29d15fb
Compare
|
Thanks for this! a few things before merge: Blocker: the toLower will break the lookup. deviceForSelector → selectorMatchesField does a case-sensitive match and doesn't normalize the stored UPower fields. BlueZ reports Address in uppercase and UPower mirrors that uppercase MAC into the device serial, so a lowercased selector (aa:bb:...) won't match the uppercase serial (AA:BB:...), the lookup returns null and the feature is inert. Please pass d.address verbatim instead of StringUtils::toLower(d.address) at both call sites (and you can drop the two new util/string_utils.h includes). Verbatim matches serial exactly, and it keeps the shared selector matcher case-sensitive, making it case-insensitive would change behavior for the user-facing battery device selector too. Staleness of the fallback value. The UPower-derived percentage isn't part of any invalidation key, and luetoothService emits no signal when UPower's percentage changes, so the value can drift after it's first shown:
It'll render ok on connect (that triggers a rebuild), but won't update afterward. A complete fix needs both: subscribe to UPowerService's change callback to pump requestUpdate()/rebuild, and fold the resolved percentage into the keys so the rebuild isn't suppressed. It's fine to scope that to a follow-up if you'd rather. Minor:
|
Bluetooth widget / tab will now also query UPowerService for battery percentage if BluetoothService doesn't provide it.
An example of this is the Playstation 5 controller.