Fix the bug on TV profile's BT on 45/44545/1 accepted/tizen/mobile/20150723.090048 accepted/tizen/tv/20150723.090143 accepted/tizen/wearable/20150723.090235 submit/tizen_mobile/20150723.064429 submit/tizen_tv/20150723.064433 submit/tizen_wearable/20150723.064437
authorDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 23 Jul 2015 06:42:54 +0000 (15:42 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 23 Jul 2015 06:42:54 +0000 (15:42 +0900)
Change-Id: I06a5ce1e466517dd31e62d45a2e7b246287e6098
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-core/bt-core-adapter.c
bt-core/bt-core-dbus-handler.c
bt-core/include/bt-core-dbus-handler.h
bt-service/bt-service-main.c

index 4b68909..1e447fb 100644 (file)
@@ -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)
index 872dd23..292b128 100644 (file)
@@ -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;
 
index 8c9b7da..56c2406 100644 (file)
@@ -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);
 
index 7a3c939..3f85ab9 100644 (file)
@@ -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;
 }