mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
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:
parent
f7955eeb48
commit
713e3f0680
4 changed files with 49 additions and 4 deletions
|
|
@ -686,6 +686,11 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
|
|||
|
||||
if (events & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) {
|
||||
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
|
||||
pa_bluetooth_device_deregister_battery(t->device);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -927,6 +927,42 @@ 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)
|
||||
return;
|
||||
|
||||
d->has_battery_level = false;
|
||||
pa_hook_fire(&d->discovery->hooks[PA_BLUETOOTH_HOOK_DEVICE_BATTERY_LEVEL_CHANGED], d);
|
||||
|
||||
if (!d->adapter->battery_provider_registered)
|
||||
return;
|
||||
|
||||
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;
|
||||
|
||||
pa_xfree(battery_path);
|
||||
pa_xfree(provider_path);
|
||||
}
|
||||
|
||||
|
||||
static int transport_state_from_string(const char* value, pa_bluetooth_transport_state_t *state) {
|
||||
pa_assert(value);
|
||||
pa_assert(state);
|
||||
|
|
|
|||
|
|
@ -206,6 +206,7 @@ void pa_bluetooth_transport_load_a2dp_sink_volume(pa_bluetooth_transport *t);
|
|||
bool pa_bluetooth_device_any_transport_connected(const pa_bluetooth_device *d);
|
||||
bool pa_bluetooth_device_switch_codec(pa_bluetooth_device *device, pa_bluetooth_profile_t profile, pa_hashmap *capabilities_hashmap, const pa_a2dp_endpoint_conf *endpoint_conf, void (*codec_switch_cb)(bool, pa_bluetooth_profile_t profile, void *), void *userdata);
|
||||
void pa_bluetooth_device_report_battery_level(pa_bluetooth_device *d, uint8_t level, const char *reporting_source);
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue