From: Jo?o Paulo Rechi Vita <jprvita@xxxxxxxxxxxxx> --- src/modules/bluetooth/backend-ofono.c | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c index f9157e3..404a6b5 100644 --- a/src/modules/bluetooth/backend-ofono.c +++ b/src/modules/bluetooth/backend-ofono.c @@ -384,6 +384,7 @@ static void hf_audio_agent_unregister(pa_bluetooth_backend *backend) { static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *data) { const char *sender; + DBusError err; pa_bluetooth_backend *backend = data; pa_assert(bus); @@ -394,6 +395,41 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *da if (!pa_safe_streq(backend->ofono_bus_id, sender) && !pa_streq("org.freedesktop.DBus", sender)) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + dbus_error_init(&err); + + if (dbus_message_is_signal(m, "org.freedesktop.DBus", "NameOwnerChanged")) { + const char *name, *old_owner, *new_owner; + + if (!dbus_message_get_args(m, &err, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &old_owner, + DBUS_TYPE_STRING, &new_owner, + DBUS_TYPE_INVALID)) { + pa_log_error("Failed to parse org.freedesktop.DBus.NameOwnerChanged: %s", err.message); + goto fail; + } + + if (pa_streq(name, OFONO_SERVICE)) { + + if (old_owner && *old_owner) { + pa_log_debug("oFono disappeared"); + + pa_hashmap_remove_all(backend->cards); + + pa_xfree(backend->ofono_bus_id); + backend->ofono_bus_id = NULL; + } + + if (new_owner && *new_owner) { + pa_log_debug("oFono appeared"); + hf_audio_agent_register(backend); + } + } + + } + +fail: + dbus_error_free(&err); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -- 1.9.3