Remove duplicated logic
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / adapter / bt-service-core-adapter.c
index b82c333..98c5ec4 100644 (file)
@@ -548,15 +548,21 @@ int _bt_set_discoverable_mode(int discoverable_mode, int timeout)
 
        if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
                ret = _bt_stop_visibility_timer();
+               if (BLUETOOTH_ERROR_NONE != ret)
+                       BT_ERR("_bt_stop_visibility_timer failed");
                if (!TIZEN_PROFILE_WEARABLE) {
                        if (vconf_set_int(BT_FILE_VISIBLE_TIME, -1) != 0)
                                 BT_ERR("Set vconf failed");
                }
        } else if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE) {
                ret = _bt_start_visibility_timer(timeout);
+               if (BLUETOOTH_ERROR_NONE != ret)
+                       BT_ERR("_bt_start_visibility_timer failed");
 
        } else {
                ret = _bt_stop_visibility_timer();
+               if (BLUETOOTH_ERROR_NONE != ret)
+                       BT_ERR("_bt_stop_visibility_timer failed");
        }
 
        BT_DBG("-");
@@ -957,56 +963,45 @@ static void __bt_adapter_event_handler(int event_type, gpointer event_data)
 int _bt_init_profiles()
 {
        int ret;
+       BT_INFO("+");
 
        /*TODO: Init bluetooth profiles */
        ret = _bt_hidhost_initialize();
-       if (ret != BLUETOOTH_ERROR_NONE) {
+       if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("_bt_hidhost_initialize Failed");
-               return ret;
-       }
 
        ret = _bt_socket_init();
-       if (ret != BLUETOOTH_ERROR_NONE) {
+       if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("_bt_socket_init Failed");
-               return ret;
-       }
 
        /*
         * Query local adapter services and based on a2dp service uuids initialized
         * in bluetooth stack, enable A2DP sourec or A2DP sink role.
         */
        ret =  adapter_get_service_uuids();
-       if (ret != OAL_STATUS_SUCCESS) {
+       if (ret != OAL_STATUS_SUCCESS)
                BT_ERR("adapter_get_service_uuids failed: %d", ret);
-               return BLUETOOTH_ERROR_INTERNAL;
-       } else {
+       else
                a2dp_init_pending = TRUE;
-       }
+
 
        /* Initialize HFP Audio Gateway */
        ret = _bt_audio_initialize(BT_AG_MODULE);
-       if (ret != BLUETOOTH_ERROR_NONE) {
+       if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("_bt_audio_initialize(BT_AG_MODULE) Failed");
-               return ret;
-       }
+
        /* Registering callback for receiving audio services searched */
        ret = _bt_audio_initialize(BT_AUDIO_ALL_MODULE);
-       if (ret != BLUETOOTH_ERROR_NONE) {
+       if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("_bt_audio_initialize(BT_AUDIO_ALL_MODULE) Failed");
-               return ret;
-       }
 
        ret = _bt_hdp_init();
-       if (ret != BLUETOOTH_ERROR_NONE) {
+       if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("_bt_hdp_init Failed");
-               return ret;
-       }
 
        ret = _bt_gatt_init();
-       if (ret != BLUETOOTH_ERROR_NONE) {
+       if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("_bt_gatt_init Failed");
-               return ret;
-       }
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -1214,6 +1209,12 @@ static gboolean __bt_adapter_post_set_disabled(gpointer user_data)
                        BT_ERR("vconf_ignore_key_changed failed");
        }
 
+       /* bt-service should be terminated when BT is off */
+       if (!TIZEN_FEATURE_BT_USB_DONGLE) {
+               /* TODO: Implement to check if it is the recovery mode or not */
+               _bt_reliable_terminate_service(NULL);
+       }
+
        return FALSE;
 }
 
@@ -1231,6 +1232,9 @@ static void __bt_adapter_update_bt_enabled(void)
        if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
                BT_ERR("Set vconf failed\n");
 
+       if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
+               BT_ERR("Set vconf failed\n");
+
        /* TODO:Add timer function to handle any further post processing */
        g_idle_add((GSourceFunc)__bt_adapter_post_set_enabled, NULL);
 
@@ -1260,6 +1264,9 @@ static void __bt_adapter_update_bt_disabled(void)
        if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
                BT_ERR("Set vconf failed");
 
+       if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
+               BT_ERR("Set vconf failed\n");
+
        /* TODO:Add timer function to handle any further post processing */
        g_idle_add((GSourceFunc)__bt_adapter_post_set_disabled, NULL);
 
@@ -1329,8 +1336,6 @@ static int __bt_adapter_state_handle_request(gboolean enable)
                        if (adapter_discovery_state == ADAPTER_DISCOVERY_STARTED ||
                                        adapter_discovery_state == ADAPTER_DISCOVERY_STARTING) {
                                /*TODO Stop Discovery*/
-                               if (result != OAL_STATUS_SUCCESS)
-                                       BT_ERR("Discover stop failed: %d", result);
                                __bt_adapter_update_discovery_status(FALSE);
                        }
                        result = adapter_disable();
@@ -1355,8 +1360,6 @@ static int __bt_adapter_state_handle_request(gboolean enable)
                        if (adapter_discovery_state == ADAPTER_DISCOVERY_STARTED ||
                                        adapter_discovery_state == ADAPTER_DISCOVERY_STARTING) {
                                /*TODO Stop Discovery*/
-                               if (result != OAL_STATUS_SUCCESS)
-                                       BT_ERR("Discover stop failed: %d", result);
                                __bt_adapter_update_discovery_status(FALSE);
                        }
                        result = adapter_disable();
@@ -1665,7 +1668,6 @@ void _bt_set_disabled(int result)
        if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
                BT_ERR("Set vconf failed\n");
 
-       _bt_cancel_queued_transfers();
        _bt_adapter_set_status(BT_DEACTIVATED);
        __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STOPPED);