Rollback changes to submit TIZEN:COMMON project
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-adapter.c
index 523b266..3f510ad 100644 (file)
@@ -28,8 +28,9 @@
 #if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
 #include <syspopup_caller.h>
 #endif
+#ifdef __TIZEN_MOBILE__
 #include <aul.h>
-
+#endif
 #include "alarm.h"
 
 #include "bluetooth-api.h"
@@ -567,6 +568,7 @@ static void __bt_flight_mode_cb(keynode_t *node, void *data)
        }
 }
 
+#ifdef __TIZEN_MOBILE__
 static void __launch_bt_service(int status, int run_type)
 {
        bundle *kb;
@@ -588,8 +590,9 @@ static void __launch_bt_service(int status, int run_type)
 
        bundle_free(kb);
 }
+#endif
 
-static void __bt_adapter_set_status(bt_status_t status)
+void _bt_adapter_set_status(bt_status_t status)
 {
        adapter_status = status;
 }
@@ -655,16 +658,16 @@ static void __bt_set_local_name(void)
        free(phone_name);
 }
 
-static int __bt_set_enabled(void)
+void _bt_set_enabled(void)
 {
-       int enabled = FALSE;
        int result = BLUETOOTH_ERROR_NONE;
 
-       _bt_check_adapter(&enabled);
+       _bt_adapter_set_status(BT_ACTIVATED);
 
-       if (enabled == FALSE) {
-               BT_ERR("Bluetoothd is not running");
-               return BLUETOOTH_ERROR_INTERNAL;
+       // register agent if it was not previously done.
+       if (!adapter_agent) {
+               BT_DBG("");
+               _bt_handle_adapter_added();
        }
 
        __bt_set_visible_mode();
@@ -681,12 +684,14 @@ static int __bt_set_enabled(void)
        /* Send enabled event to API */
        _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
                                DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
-
-       return BLUETOOTH_ERROR_NONE;
 }
 
-static void __bt_set_disabled(int result)
+void _bt_set_disabled(void)
 {
+       int result = BLUETOOTH_ERROR_NONE;
+
+       _bt_adapter_set_status(BT_DEACTIVATED);
+
        /* Update Bluetooth Status to notify other modules */
        if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
                BT_ERR("Set vconf failed\n");
@@ -714,13 +719,18 @@ void _bt_handle_flight_mode_noti(void)
 
 void _bt_handle_adapter_added(void)
 {
-        adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
-        if (!adapter_agent) {
+       BT_DBG("");
+
+       adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
+       if (!adapter_agent) {
                BT_ERR("Fail to register agent");
                return;
-        }
+       }
 
 #ifdef __TIZEN_MOBILE__
+       if (!aul_app_is_running("com.samsung.bluetooth"))
+                       __launch_bt_service(0, 0);
+
        if (_bt_register_media_player() != BLUETOOTH_ERROR_NONE)
                BT_ERR("Fail to register media player");
 #endif
@@ -738,15 +748,11 @@ void _bt_handle_adapter_added(void)
 
        vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
                        __bt_flight_mode_cb, NULL);
-
-       __bt_set_enabled();
-
-       __bt_adapter_set_status(BT_ACTIVATED);
 }
 
 void _bt_handle_adapter_removed(void)
 {
-       __bt_adapter_set_status(BT_DEACTIVATED);
+       BT_DBG("");
 
        vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
                                (vconf_callback_fn)__bt_phone_name_changed_cb);
@@ -754,33 +760,31 @@ void _bt_handle_adapter_removed(void)
        _bt_destroy_agent(adapter_agent);
        adapter_agent = NULL;
 
-       __bt_set_disabled(BLUETOOTH_ERROR_NONE);
-
        _bt_terminate_service(NULL);
 }
 
 DBusGProxy *_bt_init_core_proxy(void)
 {
-       DBusGProxy *proxy;
+       DBusGProxy *proxy;
        DBusGConnection *conn;
 
        conn = _bt_get_system_gconn();
        if (!conn)
                return NULL;
 
-       proxy = dbus_g_proxy_new_for_name(conn, BT_CORE_NAME,
+       proxy = dbus_g_proxy_new_for_name(conn, BT_CORE_NAME,
                        BT_CORE_PATH, BT_CORE_INTERFACE);
        if (!proxy)
                return NULL;
 
-       core_proxy = proxy;
+       core_proxy = proxy;
 
-       return proxy;
+       return proxy;
 }
 
 static DBusGProxy *__bt_get_core_proxy(void)
 {
-       return (core_proxy) ? core_proxy : _bt_init_core_proxy();
+       return (core_proxy) ? core_proxy : _bt_init_core_proxy();
 }
 
 int _bt_enable_adapter(void)
@@ -800,7 +804,7 @@ int _bt_enable_adapter(void)
                        return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
        }
 
-       __bt_adapter_set_status(BT_ACTIVATING);
+       _bt_adapter_set_status(BT_ACTIVATING);
 
        proxy = __bt_get_core_proxy();
        if (!proxy)
@@ -811,7 +815,7 @@ int _bt_enable_adapter(void)
                                        G_TYPE_INVALID,
                                        G_TYPE_INVALID) == FALSE) {
 
-               __bt_adapter_set_status(BT_DEACTIVATED);
+               _bt_adapter_set_status(BT_DEACTIVATED);
 
                if (err != NULL) {
                        BT_ERR("Bt core call failed: [%s]", err->message);
@@ -825,7 +829,7 @@ int _bt_enable_adapter(void)
                }
 
                /* Display notification */
-               status_message_post(BT_STR_NOT_SUPPORT);
+               notification_status_message_post(BT_STR_NOT_SUPPORT);
 
                /* Terminate myself */
                g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
@@ -851,7 +855,7 @@ int _bt_disable_adapter(void)
                        return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
        }
 
-       __bt_adapter_set_status(BT_DEACTIVATING);
+       _bt_adapter_set_status(BT_DEACTIVATING);
 
        proxy = __bt_get_core_proxy();
        if (!proxy)
@@ -860,9 +864,9 @@ int _bt_disable_adapter(void)
        if (dbus_g_proxy_call(proxy, "DisableAdapter", NULL,
                                       G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
                BT_ERR("Bt core call failed");
-               __bt_adapter_set_status(BT_ACTIVATED);
+               _bt_adapter_set_status(BT_ACTIVATED);
                return BLUETOOTH_ERROR_INTERNAL;
-       }
+       }
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -893,18 +897,13 @@ int _bt_reset_adapter(void)
 
 int _bt_check_adapter(int *status)
 {
-       char *adapter_path = NULL;
-
        BT_CHECK_PARAMETER(status, return);
 
        *status = 0; /* 0: disabled */
 
-       adapter_path = _bt_get_adapter_path();
-
-       if (adapter_path != NULL)
+       if (_bt_get_adapter_power())
                *status = 1; /* 1: enabled */
 
-       g_free(adapter_path);
        return BLUETOOTH_ERROR_NONE;
 }