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>
This commit is contained in:
Marijn Suijten 2021-01-19 11:45:46 +01:00
parent f7955eeb48
commit 713e3f0680
4 changed files with 49 additions and 4 deletions

View file

@ -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;
}