Commit 6f04beac authored by Wim Taymans's avatar Wim Taymans
Browse files

bluez5: do NameHasOwner before using org.bluez

We should not be using org.bluez when the bluetooth service is not
running or else we might try to activate it. The activation of the
bluetooth service should be done at boot time.
parent fdf37d9a
Pipeline #448150 passed with stages
in 3 minutes and 51 seconds
......@@ -2175,6 +2175,65 @@ static void get_managed_objects(pa_bluetooth_discovery *y) {
send_and_add_to_pending(y, m, get_managed_objects_reply, NULL);
}
static void check_name_owner_reply(DBusPendingCall *pending, void *userdata) {
pa_dbus_pending *p;
pa_bluetooth_discovery *y;
DBusMessage *r;
DBusError err;
bool running;
pa_assert_se(p = userdata);
pa_assert_se(y = p->context_data);
pa_assert_se(r = dbus_pending_call_steal_reply(pending));
if (dbus_message_is_error(r, DBUS_ERROR_UNKNOWN_METHOD)) {
pa_log_warn("BlueZ D-Bus ObjectManager not available");
goto finish;
}
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
pa_log_error("NameHasOwner() failed: %s: %s", dbus_message_get_error_name(r), pa_dbus_get_error_message(r));
goto finish;
}
if (!pa_streq(dbus_message_get_signature(r), "b")) {
pa_log_error("Invalid reply signature for NameHasOwner()");
goto finish;
}
dbus_error_init(&err);
if (!dbus_message_get_args(r, &err, DBUS_TYPE_BOOLEAN, &running, DBUS_TYPE_INVALID)) {
pa_log_error("Could not check bluetooth service: %s", err.message);
dbus_error_free(&err);
goto finish;
}
pa_log_info("bluetooth service running: %s", running ? "yes" : "no");
if (running)
get_managed_objects(y);
finish:
dbus_message_unref(r);
PA_LLIST_REMOVE(pa_dbus_pending, y->pending, p);
pa_dbus_pending_free(p);
}
static void check_name_owner(pa_bluetooth_discovery *y) {
DBusMessage *m;
const char *service = BLUEZ_SERVICE;
pa_assert(y);
pa_assert_se(m = dbus_message_new_method_call("org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"NameHasOwner"));
dbus_message_append_args(m, DBUS_TYPE_STRING, &service, DBUS_TYPE_INVALID);
send_and_add_to_pending(y, m, check_name_owner_reply, NULL);
}
pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook) {
pa_assert(y);
pa_assert(PA_REFCNT_VALUE(y) > 0);
......@@ -2930,7 +2989,7 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backe
}
}
get_managed_objects(y);
check_name_owner(y);
return y;
......
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