From a71ec87c8756f752a16d54959cb218e5673769f0 Mon Sep 17 00:00:00 2001 From: DoHyun Pyun Date: Mon, 30 Mar 2020 09:55:06 +0900 Subject: [PATCH] Invoke HAL_DISCOVERY_STATE_STOPPED event once When the user calls the cancel discovery API, the HAL_DISCOVERY_STATE_STOPPED event called twice. This patchset resolves this issue. Change-Id: Id7610da8209edf34a1205cced9fad1f18ee67c9f Signed-off-by: DoHyun Pyun --- bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c | 13 +++++++++++++ bt-oal/bluez_hal/src/bt-hal-event-receiver.c | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c b/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c index 722b0e2..7ce1f77 100644 --- a/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c +++ b/bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c @@ -508,8 +508,11 @@ int _bt_hal_dbus_stop_discovery(void) GDBusProxy *proxy; GError *error = NULL; GVariant *result; + struct hal_ev_discovery_state_changed ev; DBG("+"); + memset(&ev, 0, sizeof(ev)); + proxy = _bt_hal_get_adapter_proxy(); if (!proxy) { DBG("_bt_hal_dbus_stop_discovery: Adapter proxy get failed!!!"); @@ -533,6 +536,16 @@ int _bt_hal_dbus_stop_discovery(void) return BT_STATUS_FAIL; } + /* Stop success */ + ev.state = HAL_DISCOVERY_STATE_STOPPED; + + if (!event_cb) + event_cb = _bt_hal_get_stack_message_handler(); + if (event_cb) { + DBG("Sending HAL_EV_DISCOVERY_STATE_CHANGED event"); + event_cb(HAL_EV_DISCOVERY_STATE_CHANGED, (void*)&ev, sizeof(ev)); + } + /* discovery status will be change in event */ DBG("-"); g_variant_unref(result); diff --git a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c index 5483abf..b74a110 100644 --- a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c +++ b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c @@ -382,13 +382,17 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg) DBUS_TIMEOUT, NULL, &err); if (err) { + struct hal_ev_discovery_state_changed ev; + ERR("Dbus Error : %s", err->message); + if (g_strrstr(err->message, "No discovery started")) + continue; + /* This error is thrown by Bluez, as Discovery is already stopped. Discovery is stopped if user cancels on going discovery. In order to maintain correct state of Bluetooth Discovery state, simply send Discovery stopped event to HAL user */ - struct hal_ev_discovery_state_changed ev; ev.state = HAL_DISCOVERY_STATE_STOPPED; event_cb(HAL_EV_DISCOVERY_STATE_CHANGED, &ev, sizeof(ev)); g_clear_error(&err); -- 2.7.4