summaryrefslogtreecommitdiff
path: root/src/modules/bluetooth/module-bluez5-device.c
diff options
context:
space:
mode:
authorMarijn Suijten <marijns95@gmail.com>2021-01-19 11:45:46 +0100
committerMarijn Suijten <marijns95@gmail.com>2021-07-28 09:11:43 +0200
commit713e3f0680581022ffaec22e663451f4a999f8f3 (patch)
tree78195e396ed17151a8052452ccf8a892c4bcb45e /src/modules/bluetooth/module-bluez5-device.c
parentf7955eeb48f7e1bc0fe966ab2904832143cd754e (diff)
downloadpulseaudio-713e3f0680581022ffaec22e663451f4a999f8f3.tar.gz
bluetooth: Deregister battery provider when profile disconnects
Whenever a device disconnects the device is not removed from BlueZ, only the profiles that had an active connection are disconnected. Since we were providing this battery level based on AT commands received through HSP/HFP these services should be responsible for deregistering it again. Deregister the interface to signal BlueZ (And UPower in return) that the battery level won't be accurate/updated anymore. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/482>
Diffstat (limited to 'src/modules/bluetooth/module-bluez5-device.c')
-rw-r--r--src/modules/bluetooth/module-bluez5-device.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c
index 579c63c0f..5b656612c 100644
--- a/src/modules/bluetooth/module-bluez5-device.c
+++ b/src/modules/bluetooth/module-bluez5-device.c
@@ -2308,12 +2308,15 @@ static pa_hook_result_t device_battery_level_changed_cb(pa_bluetooth_discovery *
pa_assert(d);
pa_assert(u);
- if (d != u->device || !d->has_battery_level)
+ if (d != u->device)
return PA_HOOK_OK;
- level = d->battery_level;
-
- pa_proplist_setf(u->card->proplist, "bluetooth.battery", "%d%%", level);
+ if (d->has_battery_level) {
+ level = d->battery_level;
+ pa_proplist_setf(u->card->proplist, "bluetooth.battery", "%d%%", level);
+ } else {
+ pa_proplist_unset(u->card->proplist, "bluetooth.battery");
+ }
return PA_HOOK_OK;
}