From e973c54b9ffc8e9a6ef037b8e208601fc9b142d4 Mon Sep 17 00:00:00 2001 From: DoHyun Pyun Date: Thu, 23 Jul 2015 15:42:54 +0900 Subject: [PATCH] Fix the bug on TV profile's BT on Change-Id: I06a5ce1e466517dd31e62d45a2e7b246287e6098 Signed-off-by: DoHyun Pyun --- bt-core/bt-core-adapter.c | 103 +++++++++++++++++++++---- bt-core/bt-core-dbus-handler.c | 2 +- bt-core/include/bt-core-dbus-handler.h | 2 + bt-service/bt-service-main.c | 3 +- 4 files changed, 93 insertions(+), 17 deletions(-) diff --git a/bt-core/bt-core-adapter.c b/bt-core/bt-core-adapter.c index 4b689090..1e447fb7 100644 --- a/bt-core/bt-core-adapter.c +++ b/bt-core/bt-core-adapter.c @@ -35,6 +35,8 @@ #include "bt-core-noti-handler.h" #define BT_CORE_IDLE_TERM_TIME 200 /* 200ms */ +#define BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX 50 + static bt_status_t adapter_status = BT_DEACTIVATED; static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED; @@ -167,6 +169,7 @@ int _bt_enable_adapter(void) /* Return with 0 for the Enabled response. */ __bt_core_set_status(BT_ACTIVATED); BT_INFO("BR/EDR is enabled."); + g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL); return 0; } @@ -330,28 +333,98 @@ int _bt_core_service_request_adapter(int service_function) return ret; } -void _bt_core_update_status(void) +static gboolean __bt_core_check_the_adapter_path(GDBusConnection *conn) { - int bt_status = VCONFKEY_BT_STATUS_OFF; - int bt_le_status = 0; + GError *err = NULL; + GDBusProxy *manager_proxy = NULL; + GVariant *result = NULL; + char *adapter_path = NULL; + + if(conn == NULL) + return FALSE; + + manager_proxy = g_dbus_proxy_new_sync(conn, + G_DBUS_PROXY_FLAGS_NONE, NULL, + "org.bluez", + "/", + "org.freedesktop.DBus.ObjectManager", + NULL, &err); + + if (!manager_proxy) { + if (err != NULL) { + BT_ERR("Unable to create proxy: %s", err->message); + g_clear_error(&err); + } else { + BT_ERR("Fail to create proxy"); + } + goto fail; + } - if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) - BT_ERR("no bluetooth device info, so BT was disabled at previous session"); + result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); + if (!result) { + if (err != NULL) { + BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message); + g_clear_error(&err); + } else{ + BT_ERR("Fail to get DefaultAdapter"); + } + goto fail; + } + + if (g_strcmp0(g_variant_get_type_string(result), "(o)")) { + BT_ERR("Incorrect result\n"); + goto fail; + } - if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0) - BT_ERR("no bluetooth le info, so BT LE was disabled at previous session"); + g_variant_get(result, "(&o)", &adapter_path); - BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status); + if (adapter_path == NULL || + strlen(adapter_path) >= BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX) { + BT_ERR("Adapter path is inproper\n"); + goto fail; + } + + g_variant_unref(result); + g_object_unref(manager_proxy); + + return TRUE; - if (bt_status == VCONFKEY_BT_STATUS_OFF) +fail: + if (result) + g_variant_unref(result); + + if (manager_proxy) + g_object_unref(manager_proxy); + + return FALSE; +} + +void _bt_core_update_status(void) +{ + int bt_status = VCONFKEY_BT_STATUS_OFF; + int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF; + gboolean ret = FALSE; + + ret = __bt_core_check_the_adapter_path(_bt_core_get_gdbus_connection()); + BT_INFO("check the real status of bt_adapter"); + + if (ret != TRUE) { __bt_core_set_status(BT_DEACTIVATED); - else - __bt_core_set_status(BT_ACTIVATED); + __bt_core_set_le_status(BT_DEACTIVATED); + } else { + if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) + BT_ERR("no bluetooth device info, so BT was disabled at previous session"); + if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0) + BT_ERR("no bluetooth le info, so BT LE was disabled at previous session"); - if (bt_le_status == 0) - __bt_core_set_le_status(BT_LE_DEACTIVATED); - else - __bt_core_set_le_status(BT_LE_ACTIVATED); + BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status); + + if(bt_status == VCONFKEY_BT_STATUS_ON) + __bt_core_set_status(BT_ACTIVATED); + if(bt_le_status == VCONFKEY_BT_LE_STATUS_ON) + __bt_core_set_le_status(BT_ACTIVATED); + } } gboolean _bt_core_enable_adapter(void) diff --git a/bt-core/bt-core-dbus-handler.c b/bt-core/bt-core-dbus-handler.c index 872dd23d..292b128d 100644 --- a/bt-core/bt-core-dbus-handler.c +++ b/bt-core/bt-core-dbus-handler.c @@ -52,7 +52,7 @@ void _bt_core_fill_garray_from_variant(GVariant *var, GArray *param) } } -static GDBusConnection * _bt_core_get_gdbus_connection(void) +GDBusConnection * _bt_core_get_gdbus_connection(void) { GError *err = NULL; diff --git a/bt-core/include/bt-core-dbus-handler.h b/bt-core/include/bt-core-dbus-handler.h index 8c9b7dae..56c2406f 100644 --- a/bt-core/include/bt-core-dbus-handler.h +++ b/bt-core/include/bt-core-dbus-handler.h @@ -59,6 +59,8 @@ void _bt_core_fill_garray_from_variant(GVariant *var, GArray *param); GDBusProxy *_bt_core_gdbus_get_service_proxy(void); void _bt_core_gdbus_deinit_proxys(void); +GDBusConnection * _bt_core_get_gdbus_connection(void); + gboolean _bt_core_register_dbus(void); void _bt_core_unregister_dbus(void); diff --git a/bt-service/bt-service-main.c b/bt-service/bt-service-main.c index 7a3c939d..3f85ab94 100644 --- a/bt-service/bt-service-main.c +++ b/bt-service/bt-service-main.c @@ -73,10 +73,11 @@ static void __bt_sigterm_handler(int signo, siginfo_t *info, void *data) BT_INFO("signal [%d] is sent by [%d]", signo, info->si_pid); +#ifndef TIZEN_TV ret = _bt_recover_adapter(); if (ret != BLUETOOTH_ERROR_NONE) BT_ERR("_bt_recover_adapter is failed : %d", ret); - +#endif return; } -- 2.34.1