Fixed AVRCP controller reply pending request
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-adapter.c
index 569afe2..078bca7 100644 (file)
@@ -22,6 +22,9 @@
 #include <string.h>
 #include <vconf.h>
 #include <syspopup_caller.h>
+#include <aul.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus.h>
 #include <bundle.h>
 #include <eventsystem.h>
 #include <bundle_internal.h>
 #include "bt-service-network.h"
 #include "bt-service-obex-server.h"
 #include "bt-service-opp-client.h"
-#include "bt-service-map-client.h"
 #include "bt-service-agent.h"
 #include "bt-service-main.h"
 #include "bt-service-avrcp.h"
 #include "bt-service-device.h"
-#ifdef TIZEN_FEATURE_BT_DPM
+#include "bt-service-adapter-le.h"
+
+#ifdef TIZEN_DPM_ENABLE
 #include "bt-service-dpm.h"
 #endif
 
@@ -68,7 +72,6 @@ typedef struct {
 static bt_service_alarm_mgr_t alarm_mgr = {0, };
 
 static gboolean is_discovering;
-static gboolean discovery_req;
 static gboolean cancel_by_user;
 static bt_status_t adapter_status = BT_DEACTIVATED;
 static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
@@ -78,7 +81,9 @@ static GDBusProxy *core_proxy = NULL;
 static guint timer_id = 0;
 static guint le_timer_id = 0;
 static gboolean is_recovery_mode;
+static gboolean in_power_off;
 
+static guint poweroff_subscribe_id;
 static uint status_reg_id;
 
 #define BT_CORE_NAME "org.projectx.bt_core"
@@ -156,10 +161,10 @@ static gboolean __bt_timeout_handler(gpointer user_data)
                visible_timer.event_id = 0;
                visible_timer.timeout = 0;
 
-               if (!TIZEN_PROFILE_WEARABLE) {
-                       if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
-                               BT_ERR("Set vconf failed\n");
-               }
+#ifndef TIZEN_PROFILE_WEARABLE
+               if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
+                       BT_ERR("Set vconf failed\n");
+#endif
                return FALSE;
        }
 
@@ -183,10 +188,10 @@ static int __bt_visibility_alarm_cb(alarm_id_t alarm_id, void* user_param)
                visible_timer.event_id = 0;
                visible_timer.timeout = 0;
 
-               if (!TIZEN_PROFILE_WEARABLE) {
-                       if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
-                               BT_ERR("Set vconf failed\n");
-               }
+#ifndef TIZEN_PROFILE_WEARABLE
+               if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
+                       BT_ERR("Set vconf failed\n");
+#endif
        }
        /* Switch Off visibility in Bluez */
        _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
@@ -211,25 +216,21 @@ int __bt_set_visible_time(int timeout)
 {
        int result;
        alarm_id_t alarm_id;
-#ifdef TIZEN_FEATURE_BT_DPM
-       int discoverable_state = DPM_BT_ERROR;
-#endif
 
        __bt_visibility_alarm_remove();
 
        visible_timer.timeout = timeout;
 
-       if (!TIZEN_PROFILE_WEARABLE) {
-#ifdef TIZEN_FEATURE_BT_DPM
-               _bt_dpm_get_bluetooth_limited_discoverable_state(&discoverable_state);
-               if (discoverable_state != DPM_RESTRICTED) {
-#endif
-               if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0)
-                       BT_ERR("Set vconf failed");
-#ifdef TIZEN_FEATURE_BT_DPM
-               }
+#ifndef TIZEN_PROFILE_WEARABLE
+#ifdef TIZEN_DPM_ENABLE
+       if (_bt_dpm_get_bluetooth_limited_discoverable_state() != DPM_RESTRICTED) {
 #endif
+       if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0)
+               BT_ERR("Set vconf failed");
+#ifdef TIZEN_DPM_ENABLE
        }
+#endif
+#endif
 
 
        if (timeout <= 0)
@@ -286,6 +287,7 @@ static int __bt_get_bonded_device_info(gchar *device_path,
        GDBusProxy *device_proxy;
        gchar *address = NULL;
        gchar *name = NULL;
+       gchar *alias = NULL;
        unsigned int cod = 0;
        gint rssi = 0;
        gboolean trust = FALSE;
@@ -344,10 +346,9 @@ static int __bt_get_bonded_device_info(gchar *device_path,
                } else if (!g_strcmp0(key, "Address")) {
                        g_variant_get(value, "s", &address);
                } else if (!g_strcmp0(key, "Alias")) {
-                       g_variant_get(value, "s", &name);
+                       g_variant_get(value, "s", &alias);
                } else if (!g_strcmp0(key, "Name")) {
-                       if (!name)
-                               g_variant_get(value, "s", &name);
+                       g_variant_get(value, "s", &name);
                } else if (!g_strcmp0(key, "Class")) {
                        cod = g_variant_get_uint32(value);
                } else if (!g_strcmp0(key, "Connected")) {
@@ -358,9 +359,9 @@ static int __bt_get_bonded_device_info(gchar *device_path,
                        rssi = g_variant_get_int16(value);
                } else if (!g_strcmp0(key, "UUIDs")) {
                        __bt_get_service_list(value, dev_info);
-               } else if (!g_strcmp0(key, "ManufacturerDataLen")) {
+               } else if (!g_strcmp0(key, "LegacyManufacturerDataLen")) {
                        dev_info->manufacturer_data.data_len = g_variant_get_uint16(value);
-               } else if (!g_strcmp0(key, "ManufacturerData")) {
+               } else if (!g_strcmp0(key, "LegacyManufacturerData")) {
                        manufacturer_data = g_byte_array_new();
                        g_variant_get(value, "ay", &char_value_iter);
                        while (g_variant_iter_loop(char_value_iter, "y",  &char_value))
@@ -385,6 +386,7 @@ static int __bt_get_bonded_device_info(gchar *device_path,
 
        if ((paired == FALSE) && (trust == FALSE)) {
                g_free(address);
+               g_free(alias);
                g_free(name);
                return BLUETOOTH_ERROR_NOT_PAIRED;
        }
@@ -394,7 +396,7 @@ static int __bt_get_bonded_device_info(gchar *device_path,
 
        _bt_divide_device_class(&dev_info->device_class, cod);
 
-       g_strlcpy(dev_info->device_name.name, name,
+       g_strlcpy(dev_info->device_name.name, alias ? alias : name,
                        BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
 
        dev_info->rssi = rssi;
@@ -403,6 +405,7 @@ static int __bt_get_bonded_device_info(gchar *device_path,
        dev_info->connected = connected;
        ret = BLUETOOTH_ERROR_NONE;
        g_free(address);
+       g_free(alias);
        g_free(name);
 
        return ret;
@@ -411,7 +414,6 @@ static int __bt_get_bonded_device_info(gchar *device_path,
 void _bt_set_discovery_status(gboolean mode)
 {
        is_discovering = mode;
-       discovery_req = FALSE;
 }
 
 void _bt_set_cancel_by_user(gboolean value)
@@ -452,6 +454,17 @@ void _bt_set_le_intended_status(gboolean value)
        is_le_intended = value;
 }
 
+static void __bt_set_in_poweroff(void)
+{
+       BT_INFO("Set in_power_off to TRUE");
+       in_power_off = TRUE;
+}
+
+static gboolean __bt_is_in_poweroff(void)
+{
+       return in_power_off;
+}
+
 static void __bt_phone_name_changed_cb(keynode_t *node, void *data)
 {
        char *phone_name = NULL;
@@ -468,8 +481,13 @@ static void __bt_phone_name_changed_cb(keynode_t *node, void *data)
                                                        (const char **)&ptr))
                                        *ptr = '\0';
 
+                       BT_INFO("device_name is changed to %s", phone_name);
                        _bt_set_local_name(phone_name);
+               } else {
+                       BT_ERR("phone_name is NOT valid");
                }
+       } else {
+               BT_ERR("vconf type is NOT string");
        }
 }
 
@@ -515,16 +533,18 @@ static int __bt_set_enabled(void)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       if (TIZEN_PROFILE_MOBILE || TIZEN_PROFILE_IVI) {
-               /* BT setting UI will control Mobile's visible mode. So in the FRWK...set the visible mode as off: */
-               if (_bt_set_discoverable_mode(
-                       BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0) != BLUETOOTH_ERROR_NONE)
-                               BT_ERR("Set connectable mode failed");
-       } else if (TIZEN_PROFILE_TV) {
-               if (_bt_set_discoverable_mode(
-                       BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0) != BLUETOOTH_ERROR_NONE)
-                               BT_ERR("Fail to set discoverable mode");
-       }
+#ifdef TIZEN_PROFILE_MOBILE || defined(TIZEN_PROFILE_IVI)
+       /* BT setting UI will control Mobile's visible mode. So in the FRWK...set the visible mode as off: */
+       if (_bt_set_discoverable_mode(
+               BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0) != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("Set connectable mode failed");
+#else
+#ifdef TIZEN_TV
+       if (_bt_set_discoverable_mode(
+               BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0) != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("Fail to set discoverable mode");
+#endif
+#endif
 
        /* Update Bluetooth Status to notify other modules */
        if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
@@ -589,12 +609,15 @@ void _bt_set_disabled(int result)
        _bt_adapter_set_status(BT_DEACTIVATED);
        _bt_set_discovery_status(FALSE);
 
-       if (TIZEN_FEATURE_BT_USB_DONGLE ||
-           _bt_adapter_get_le_status() != BT_LE_DEACTIVATED) {
+#ifndef USB_BLUETOOTH
+       if (_bt_adapter_get_le_status() != BT_LE_DEACTIVATED) {
+#endif
                /* Send disabled event */
                _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
                                g_variant_new("(i)", result));
+#ifndef USB_BLUETOOTH
        }
+#endif
 
        BT_INFO("Adapter disabled");
 }
@@ -607,7 +630,11 @@ static int __bt_set_le_enabled(void)
 
        /* Update Bluetooth Status to notify other modules */
        if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_ON) != 0)
-               BT_ERR("Set vconf failed\n");
+               BT_ERR("Set vconf failed");
+
+       /* set packet length to max size to enable packet length extension */
+       if (BLUETOOTH_ERROR_NONE != _bt_le_set_max_packet_len())
+               BT_ERR("Fail to set max packet length");
 
        if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
                                                EVT_VAL_BT_LE_ON) != ES_R_OK)
@@ -698,6 +725,7 @@ int _bt_enable_core(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
+#if defined(TIZEN_FEATURE_FLIGHTMODE_ENABLED) || (!defined(TIZEN_PROFILE_WEARABLE))
 static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
 {
        gboolean flight_mode = FALSE;
@@ -725,39 +753,87 @@ static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
 
        _bt_enable_core();
 }
+#endif
 
-void _bt_service_register_vconf_handler(void)
+static void __bt_poweroff_event_filter(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
 {
-       BT_DBG("+");
+       int state = 0;
 
-       if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
-               if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-                               (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
-                       BT_ERR("Unable to register key handler");
-       } else {
-               BT_DBG("Telephony is disabled");
+       g_variant_get(parameters, "(i)", &state);
+
+       if (state != BT_DEVICED_POWEROFF_SIGNAL_POWEROFF &&
+           state != BT_DEVICED_POWEROFF_SIGNAL_REBOOT) {
+               BT_DBG("Not interested event : %d", state);
+               return;
        }
 
-       if (!TIZEN_PROFILE_WEARABLE) {
-               if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
-                               (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
-                       BT_ERR("Unable to register key handler");
+       if (_bt_adapter_get_status() == BT_ACTIVATING) {
+               BT_INFO("Just update VCONFKEY_BT_STATUS in Power off");
+               if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON))
+                       BT_ERR("Set VCONFKEY_BT_STATUS failed");
+       } else {
+               __bt_set_in_poweroff();
        }
 }
 
+void _bt_service_register_poweroff_event(void)
+{
+       if (poweroff_subscribe_id)
+               return;
+
+       poweroff_subscribe_id = g_dbus_connection_signal_subscribe(
+                       _bt_gdbus_get_system_gconn(), NULL,
+                       BT_DEVICED_POWEROFF_INTERFACE,
+                       BT_DEVICED_POWEROFF_SIGNAL,
+                       BT_DEVICED_POWEROFF_OBJECT_PATH,
+                       NULL, 0, __bt_poweroff_event_filter, NULL, NULL);
+}
+
+void _bt_service_unregister_poweroff_event(void)
+{
+       if (poweroff_subscribe_id == 0)
+               return;
+
+       g_dbus_connection_signal_unsubscribe(_bt_gdbus_get_system_gconn(),
+                                            poweroff_subscribe_id);
+       poweroff_subscribe_id = 0;
+}
+
+void _bt_service_register_vconf_handler(void)
+{
+       BT_DBG("+");
+
+#ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
+       if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+                       (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
+               BT_ERR("Unable to register key handler");
+#else
+       BT_DBG("Telephony is disabled");
+#endif
+
+#ifndef TIZEN_PROFILE_WEARABLE
+       if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
+                       (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
+               BT_ERR("Unable to register key handler");
+#endif
+}
+
 void _bt_service_unregister_vconf_handler(void)
 {
        BT_DBG("+");
 
-       if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
-               vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-                               (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
-       }
+#ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
+       vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+                       (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
+#endif
 
-       if (!TIZEN_PROFILE_WEARABLE) {
-               vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
-                               (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
-       }
+#ifndef TIZEN_PROFILE_WEARABLE
+       vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
+                       (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
+#endif
 }
 
 static void __bt_state_event_handler(const char *event_name, bundle *data, void *user_data)
@@ -789,24 +865,24 @@ void _bt_handle_adapter_added(void)
 
        status = _bt_adapter_get_status();
        le_status = _bt_adapter_get_le_status();
-       BT_DBG("status : %d", status);
-       BT_DBG("le_status : %d", le_status);
+       BT_INFO("status : %d", status);
+       BT_INFO("le_status : %d", le_status);
 
-       if (!TIZEN_FEATURE_BT_USB_DONGLE) {
+#ifndef USB_BLUETOOTH
+       adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
+       if (!adapter_agent) {
+               BT_ERR("Fail to register agent");
+               return;
+       }
+#else
+       if (adapter_agent == NULL) {
                adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
                if (!adapter_agent) {
                        BT_ERR("Fail to register agent");
                        return;
                }
-       } else {
-               if (adapter_agent == NULL) {
-                       adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
-                       if (!adapter_agent) {
-                               BT_ERR("Fail to register agent");
-                               return;
-                       }
-               }
        }
+#endif
 
        if (_bt_register_media_player() != BLUETOOTH_ERROR_NONE)
                BT_ERR("Fail to register media player");
@@ -867,34 +943,23 @@ void _bt_handle_adapter_removed(void)
        if (0 != ret)
                ERR("vconf_ignore_key_changed failed\n");
 
-/* unregister all the services/servers/profiles registered on bluez-adapter
-    once adapter is removed, reinitializing of the state-varaibles becomes
-    a problem */
-       if (_bt_unregister_obex_server() != BLUETOOTH_ERROR_NONE)
-               BT_ERR("Fail to unregister obex server");
-
-       if (_bt_unregister_media_player() != BLUETOOTH_ERROR_NONE)
-               BT_ERR("Fail to unregister media player");
-
-/* Other unregister APIs should be placed here */
+#ifndef USB_BLUETOOTH
+       _bt_destroy_agent(adapter_agent);
+       adapter_agent = NULL;
 
-       if (!TIZEN_FEATURE_BT_USB_DONGLE) {
-               _bt_destroy_agent(adapter_agent);
-               adapter_agent = NULL;
-
-               if (is_recovery_mode == TRUE) {
-                       /* Send disabled event */
-                       _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+       if (is_recovery_mode == TRUE) {
+               /* Send disabled event */
+               _bt_set_disabled(BLUETOOTH_ERROR_NONE);
 
-                       /* Will recover BT by bt-core, so set the mode as activating */
-                       _bt_adapter_set_status(BT_ACTIVATING);
-                       is_recovery_mode = FALSE;
-               } else {
-                       _bt_reliable_terminate_service(NULL);
-               }
+               /* Will recover BT by bt-core, so set the mode as activating */
+               _bt_adapter_set_status(BT_ACTIVATING);
+               is_recovery_mode = FALSE;
        } else {
-               _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+               _bt_reliable_terminate_service(NULL);
        }
+#else
+       _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+#endif
 
        if (eventsystem_unregister_event(status_reg_id) != ES_R_OK)
                BT_ERR("Fail to unregister system event");
@@ -938,8 +1003,9 @@ static gboolean __bt_enable_timeout_cb(gpointer user_data)
        g_variant_unref(result);
        _bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT);
 
-       if (!TIZEN_FEATURE_BT_USB_DONGLE)
-               _bt_terminate_service(NULL);
+#ifndef USB_BLUETOOTH
+       _bt_terminate_service(NULL);
+#endif
 
        return FALSE;
 }
@@ -1015,6 +1081,7 @@ void _bt_adapter_start_enable_timer(void)
        return;
 }
 
+#ifdef TIZEN_TV
 static gboolean __bt_adapter_enabled_cb(gpointer user_data)
 {
        BT_DBG("+");
@@ -1024,6 +1091,7 @@ static gboolean __bt_adapter_enabled_cb(gpointer user_data)
 
        return FALSE;
 }
+#endif
 
 int _bt_enable_adapter_check_status(void)
 {
@@ -1078,7 +1146,8 @@ int _bt_enable_adapter(void)
 
        _bt_adapter_set_status(BT_ACTIVATING);
 
-if (TIZEN_PROFILE_TV) {
+#ifdef TIZEN_TV
+{
        int adapter_status = BT_ADAPTER_DISABLED;
 
        if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
@@ -1091,6 +1160,14 @@ if (TIZEN_PROFILE_TV) {
                return BLUETOOTH_ERROR_NONE;
        }
 }
+#endif
+
+       if (__bt_is_in_poweroff() == TRUE) {
+               BT_INFO("Just update VCONFKEY_BT_STATUS in Power off");
+               if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
+                       BT_ERR("Set VCONFKEY_BT_STATUS failed");
+               return BLUETOOTH_ERROR_NONE;
+       }
 
        proxy = __bt_get_core_proxy();
        if (!proxy)
@@ -1127,9 +1204,10 @@ if (TIZEN_PROFILE_TV) {
                                g_clear_error(&error);
                }
                g_variant_unref(result);
+#ifndef USB_BLUETOOTH
                /* Terminate myself */
-               if (!TIZEN_FEATURE_BT_USB_DONGLE)
-                       g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
+               g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
+#endif
                return BLUETOOTH_ERROR_INTERNAL;
        }
        g_variant_unref(result);
@@ -1150,7 +1228,7 @@ static gboolean __bt_disconnect_all(void)
        GVariant *result;
        GError *error = NULL;
        GArray *device_list;
-       bluetooth_device_info_t info;
+       bluetooth_device_info_t *info;
        guint size;
        char *device_path = NULL;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
@@ -1172,12 +1250,12 @@ static gboolean __bt_disconnect_all(void)
 
        for (i = 0; i < size; i++) {
 
-               info = g_array_index(device_list,
+               info = &g_array_index(device_list,
                                bluetooth_device_info_t, i);
 
-               if (info.connected != BLUETOOTH_CONNECTED_LINK_NONE) {
+               if (info->connected != BLUETOOTH_CONNECTED_LINK_NONE) {
                        BT_DBG("Found Connected device");
-                       _bt_convert_addr_type_to_string(address, info.device_address.addr);
+                       _bt_convert_addr_type_to_string(address, info->device_address.addr);
                        device_path = _bt_get_device_object_path(address);
                        if (device_path == NULL)
                                continue;
@@ -1328,16 +1406,7 @@ int _bt_disable_adapter(void)
                g_source_remove(timer_id);
                timer_id = 0;
        }
-/* unregister all the services/servers/profiles registered on bluez-adapter
-    once adapter is removed, reinitializing of the state-varaibles becomes
-    a problem */
-       if (_bt_unregister_obex_server() != BLUETOOTH_ERROR_NONE)
-               BT_ERR("Fail to unregister obex server");
-
-       if (_bt_unregister_media_player() != BLUETOOTH_ERROR_NONE)
-               BT_ERR("Fail to unregister media player");
 
-/* Other unregister APIs should be placed here */
        __bt_disconnect_all();
        ret = _bt_disable_cb();
 
@@ -1353,12 +1422,12 @@ int _bt_recover_adapter(void)
        GError *error = NULL;
 
        if (_bt_adapter_get_status() == BT_DEACTIVATING) {
-               BT_DBG("Disabling in progress");
+               BT_ERR("Disabling in progress");
                return BLUETOOTH_ERROR_IN_PROGRESS;
        }
 
        if (_bt_adapter_get_status() == BT_DEACTIVATED) {
-               BT_DBG("Already disabled");
+               BT_ERR("Already disabled");
                return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
        }
 
@@ -1430,9 +1499,10 @@ int _bt_reset_adapter(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
+#ifndef TIZEN_TV
 int _bt_check_adapter(int *status)
 {
-if (!TIZEN_PROFILE_TV) {
+
        char *adapter_path = NULL;
 
        BT_CHECK_PARAMETER(status, return);
@@ -1447,7 +1517,10 @@ if (!TIZEN_PROFILE_TV) {
 
        g_free(adapter_path);
        return BLUETOOTH_ERROR_NONE;
-} else {
+}
+#else
+int _bt_check_adapter(int *status)
+{
        GDBusProxy *proxy;
        GError *error = NULL;
        GVariant *result;
@@ -1490,7 +1563,7 @@ if (!TIZEN_PROFILE_TV) {
        g_variant_unref(temp);
        return BLUETOOTH_ERROR_NONE;
 }
-}
+#endif
 
 int _bt_enable_adapter_le(void)
 {
@@ -1930,28 +2003,20 @@ int _bt_set_discoverable_mode(int discoverable_mode, int timeout)
        GError *error = NULL;
        GDBusProxy *proxy;
        GVariant *result;
-#ifdef TIZEN_FEATURE_BT_DPM
-       int discoverable_state = DPM_BT_ERROR;
-#endif
 
        proxy = _bt_get_adapter_properties_proxy();
 
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-#ifdef TIZEN_FEATURE_BT_DPM
-       _bt_dpm_get_bluetooth_limited_discoverable_state(&discoverable_state);
+#ifdef TIZEN_DPM_ENABLE
        if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE &&
-                discoverable_state == DPM_RESTRICTED) {
-               if (headed_plugin_info->plugin_headed_enabled)
-                       headed_plugin_info->headed_plugin->bt_launch_dpmpopup("DPM_POLICY_DISABLE_BT_HANDSFREE");
-
+               _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
+               _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT_HANDSFREE");
                return BLUETOOTH_ERROR_ACCESS_DENIED;
        }
        if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE &&
-               discoverable_state == DPM_RESTRICTED) {
-               if (headed_plugin_info->plugin_headed_enabled)
-                       headed_plugin_info->headed_plugin->bt_launch_dpmpopup("DPM_POLICY_DISABLE_BT");
-
+                _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
+               _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT");
                return BLUETOOTH_ERROR_ACCESS_DENIED;
        }
 #endif
@@ -2076,7 +2141,7 @@ int _bt_start_discovery(void)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       discovery_req = TRUE;
+       is_discovering = TRUE;
        cancel_by_user = FALSE;
        /* discovery status will be change in event */
        g_variant_unref(result);
@@ -2124,7 +2189,7 @@ int _bt_start_custom_discovery(bt_discovery_role_type_t role)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       discovery_req = TRUE;
+       is_discovering = TRUE;
        cancel_by_user = FALSE;
        /* discovery status will be change in event */
        g_variant_unref(result);
@@ -2169,7 +2234,6 @@ int _bt_cancel_discovery(void)
                return ret;
        }
 
-       discovery_req = FALSE;
        cancel_by_user = TRUE;
        /* discovery status will be change in event */
        g_variant_unref(result);
@@ -2178,7 +2242,7 @@ int _bt_cancel_discovery(void)
 
 gboolean _bt_is_discovering(void)
 {
-       return (is_discovering || discovery_req);
+       return is_discovering;
 }
 
 gboolean _bt_is_connectable(void)
@@ -2420,9 +2484,9 @@ static bluetooth_device_info_t *__bt_parse_device_info(GVariantIter *item_iter)
                        }
                        dev_info->service_index = i;
                        g_variant_iter_free(iter);
-               } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
+               } else if (strcasecmp(key, "LegacyManufacturerDataLen") == 0) {
                        dev_info->manufacturer_data.data_len = g_variant_get_uint16(value);
-               } else if (strcasecmp(key, "ManufacturerData") == 0) {
+               } else if (strcasecmp(key, "LegacyManufacturerData") == 0) {
                        manufacturer_data = g_byte_array_new();
                        g_variant_get(value, "ay", &char_value_iter);
                        while (g_variant_iter_loop(char_value_iter, "y",  &char_value))
@@ -2976,11 +3040,7 @@ int _bt_service_remove_alarm(alarm_id_t alarm_id)
 
 gint compare_alarm(gconstpointer list_data, gconstpointer data)
 {
-#ifdef ARCH64
-       alarm_id_t alarm_id = (alarm_id_t)(uintptr_t)data;
-#else
        alarm_id_t alarm_id = (alarm_id_t)data;
-#endif
        bt_service_alarm_t *p_data = (bt_service_alarm_t *)list_data;
 
        if (p_data->alarm_id == alarm_id)
@@ -2999,11 +3059,7 @@ static void alarm_data_free(void *data)
 static gboolean _bt_adapter_request_delayed_cb(gpointer user_data)
 {
        int result;
-#ifdef ARCH64
-       int function = (int)(uintptr_t)user_data;
-#else
        int function = (int)user_data;
-#endif
 
        switch (function) {
        case BT_ENABLE_ADAPTER:
@@ -3058,16 +3114,14 @@ int _bt_adapter_request_delayed(int function)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-#ifdef ARCH64
-       g_idle_add((GSourceFunc)_bt_adapter_request_delayed_cb, (void *)(uintptr_t)function);
-#else
-       g_idle_add((GSourceFunc)_bt_adapter_request_delayed_cb, (void *)function);
-#endif
+       g_idle_add((GSourceFunc)_bt_adapter_request_delayed_cb, (void*)function);
 
        return BLUETOOTH_ERROR_NONE;
 }
 
+
 int _bt_get_enable_timer_id(void)
 {
        return timer_id;
 }
+