Commit 137d5741 authored by Marijn Suijten's avatar Marijn Suijten 🦀

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.
parent 0447f7da
Pipeline #274976 passed with stages
in 5 minutes and 27 seconds
......@@ -471,6 +471,11 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
pa_log_info("Lost RFCOMM connection.");
// TODO: Keep track of which profile is the current battery provider,
// only deregister if it is us currently providing these levels.
// (Also helpful to fill the 'Source' property)
// We might also move this to Profile1::RequestDisconnection
goto fail;
......@@ -661,6 +661,36 @@ void pa_bluetooth_device_report_battery_level(pa_bluetooth_device *d, uint8_t le
/* Notify BlueZ that we're no longer providing battery info for this device */
void pa_bluetooth_device_deregister_battery(pa_bluetooth_device *d) {
static const char *interface_name = BLUEZ_BATTERY_PROVIDER_INTERFACE;
DBusMessage *m;
DBusMessageIter iter, array;
char *battery_path, *provider_path;
if (!d->has_battery_level || !d->adapter->battery_proider_registered)
battery_path = device_battery_provider_path(d);
provider_path = adapter_battery_provider_path(d->adapter);
pa_log_debug("Deregistering battery provider %s", battery_path);
pa_assert_se(m = dbus_message_new_signal(provider_path, DBUS_INTERFACE_OBJECT_MANAGER, "InterfacesRemoved"));
dbus_message_iter_init_append(m, &iter);
pa_assert_se(dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &battery_path));
pa_assert_se(dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array));
pa_assert_se(dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &interface_name));
pa_assert_se(dbus_message_iter_close_container(&iter, &array));
pa_assert_se(dbus_connection_send(pa_dbus_connection_get(d->discovery->connection), m, NULL));
d->has_battery_level = false;
static int transport_state_from_string(const char* value, pa_bluetooth_transport_state_t *state) {
......@@ -192,6 +192,7 @@ void pa_bluetooth_transport_free(pa_bluetooth_transport *t);
bool pa_bluetooth_device_any_transport_connected(const pa_bluetooth_device *d);
void pa_bluetooth_device_report_battery_level(pa_bluetooth_device *d, uint8_t level);
void pa_bluetooth_device_deregister_battery(pa_bluetooth_device *d);
pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_path(pa_bluetooth_discovery *y, const char *path);
pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_address(pa_bluetooth_discovery *y, const char *remote, const char *local);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment