2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <vconf-keys.h>
20 #include <vconf-internal-radio-keys.h>
22 #include <eventsystem.h>
24 #include "bt-core-main.h"
25 #include "bt-core-adapter.h"
26 #include "bt-core-common.h"
27 #include "bt-core-dbus-handler.h"
28 #include "bt-core-noti-handler.h"
30 #define BT_CORE_IDLE_TERM_TIME 200 /* 200ms */
31 #define BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX 50
34 static bt_status_t adapter_status = BT_DEACTIVATED;
35 static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
36 static gboolean is_recovery_mode = FALSE;
38 static int bt_status_before[BT_MODE_MAX] = { VCONFKEY_BT_STATUS_OFF, };
39 static int bt_le_status_before[BT_MODE_MAX] = { VCONFKEY_BT_LE_STATUS_OFF, };
41 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value);
43 static void __bt_core_set_status(bt_status_t status)
45 adapter_status = status;
48 bt_status_t _bt_core_get_status(void)
50 return adapter_status;
53 static void __bt_core_set_le_status(bt_le_status_t status)
55 adapter_le_status = status;
58 bt_le_status_t _bt_core_get_le_status(void)
60 return adapter_le_status;
63 int _bt_core_get_bt_status(bt_mode_e mode)
65 return bt_status_before[mode];
68 int _bt_core_get_bt_le_status(bt_mode_e mode)
70 return bt_le_status_before[mode];
73 void _bt_core_set_bt_status(bt_mode_e mode, int status)
75 bt_status_before[mode] = status;
78 void _bt_core_set_bt_le_status(bt_mode_e mode, int status)
80 bt_le_status_before[mode] = status;
83 gboolean _bt_core_is_recovery_mode(void)
85 return is_recovery_mode;
88 static gboolean __bt_core_idle_terminate(gpointer data)
95 gboolean _bt_core_is_flight_mode_enabled(void)
97 #ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
101 ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &isFlightMode);
103 BT_ERR("vconf_get_bool failed");
111 static int __execute_command(const char *cmd, char *const arg_list[])
121 BT_ERR("fork failed");
127 BT_ERR("fork failed");
128 } else if (pid2 == 0) {
129 execv(cmd, arg_list);
136 BT_DBG("parent : forked[%d]", pid);
137 waitpid(pid, &status, 0);
138 BT_DBG("child is terminated : %d", status);
145 int _bt_enable_adapter(void)
150 bt_le_status_t le_status;
154 status = _bt_core_get_status();
155 if (status != BT_DEACTIVATED) {
156 BT_ERR("Invalid state %d", status);
157 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
161 #if 0 /* only the concept of private */
162 le_status = _bt_core_get_le_status();
163 if (le_status == BT_LE_ACTIVATED) {
164 /* Turn on PSCAN, (ISCAN if needed) */
165 /* Return with 0 for the Enabled response. */
166 __bt_core_set_status(BT_ACTIVATED);
167 BT_INFO("BR/EDR is enabled.");
168 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
173 __bt_core_set_status(BT_ACTIVATING);
175 char *argv_up[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "up", NULL};
176 ret = __execute_command("/usr/bin/hciconfig", argv_up);
178 ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
181 BT_ERR("running script failed");
183 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
184 ret = __execute_command("/usr/bin/hciconfig", argv_down);
186 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh", NULL);
188 __bt_core_set_status(BT_DEACTIVATED);
195 int _bt_disable_adapter(void)
199 bt_le_status_t le_status;
202 BT_INFO_C("Disable adapter");
204 #if 0 /* only the concept of private */
205 le_status = _bt_core_get_le_status();
206 BT_DBG("le_status : %d", le_status);
207 if (le_status == BT_LE_ACTIVATED) {
208 /* Turn off PSCAN, (ISCAN if needed) */
209 /* Return with 0 for the Disabled response. */
210 __bt_core_set_status(BT_DEACTIVATED);
211 BT_INFO("BR/EDR is disabled. now LE only mode");
212 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
217 status = _bt_core_get_status();
218 if (status == BT_ACTIVATING) {
219 /* Forcely terminate */
221 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
222 if (__execute_command("/usr/bin/hciconfig", argv_down) < 0)
223 BT_ERR("running script failed");
226 #ifdef TIZEN_FEATURE_RADIO
227 int radio_status = VCONFKEY_RADIO_STATUS_OFF;
229 /* Check if radio status on or off */
230 if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
231 BT_ERR("Fail to get radio status");
233 BT_DBG("Radio status: %d", radio_status);
235 if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
236 if (__execute_command("/usr/etc/bluetooth/bt-stack-down-with-radio.sh", NULL) < 0)
237 BT_ERR("running script failed");
239 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0)
240 BT_ERR("running script failed");
243 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0)
244 BT_ERR("running script failed");
247 _bt_core_terminate();
249 } else if (status != BT_ACTIVATED) {
250 BT_ERR("Invalid state %d", status);
251 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
254 __bt_core_set_status(BT_DEACTIVATING);
256 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
257 if (__execute_command("/usr/bin/hciconfig", argv_down) < 0) {
258 BT_ERR("running script failed");
259 __bt_core_set_status(BT_ACTIVATED);
263 #ifdef TIZEN_FEATURE_RADIO
264 int radio_status = VCONFKEY_RADIO_STATUS_OFF;
266 /* Check if radio status on or off */
267 if (vconf_get_int(VCONFKEY_RADIO_STATUS, &radio_status) < 0)
268 BT_ERR("Fail to get radio status");
270 BT_DBG("Radio status: %d", radio_status);
272 if (radio_status == VCONFKEY_RADIO_STATUS_ON) {
273 if (__execute_command("/usr/etc/bluetooth/bt-stack-down-with-radio.sh", NULL) < 0) {
274 BT_ERR("running script failed");
275 __bt_core_set_status(BT_ACTIVATED);
279 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
280 BT_ERR("running script failed");
281 __bt_core_set_status(BT_ACTIVATED);
286 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
287 BT_ERR("running script failed");
288 __bt_core_set_status(BT_ACTIVATED);
297 int _bt_enable_adapter_le(void)
303 bt_le_status_t le_status;
304 le_status = _bt_core_get_le_status();
305 retv_if(le_status != BT_LE_DEACTIVATED, -1);
307 status = _bt_core_get_status();
308 if (status == BT_DEACTIVATED) {
309 __bt_core_set_le_status(BT_LE_ACTIVATING);
310 BT_DBG("Activate BT");
312 char *argv_up[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "up", NULL};
313 ret = __execute_command("/usr/bin/hciconfig", argv_up);
315 ret = __execute_command("/usr/etc/bluetooth/bt-stack-up.sh", NULL);
318 BT_ERR("running script failed");
320 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
321 ret = __execute_command("/usr/bin/hciconfig", argv_down);
323 ret = __execute_command("/usr/etc/bluetooth/bt-dev-end.sh &", NULL);
325 __bt_core_set_status(BT_DEACTIVATED);
326 __bt_core_set_le_status(BT_LE_DEACTIVATED);
330 __bt_core_set_le_status(BT_LE_ACTIVATED);
331 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
334 ret = _bt_core_start_httpproxy();
336 BT_ERR("_bt_core_start_httpproxy() failed");
343 int _bt_disable_adapter_le(void)
348 bt_le_status_t le_status;
350 le_status = _bt_core_get_le_status();
351 retv_if(le_status == BT_LE_DEACTIVATED, 0);
352 retv_if(le_status == BT_LE_DEACTIVATING, -1);
355 _bt_core_stop_httpproxy();
358 status = _bt_core_get_status();
359 BT_DBG("status : %d", status);
361 if (status == BT_DEACTIVATED) {
362 __bt_core_set_le_status(BT_LE_DEACTIVATING);
364 char *argv_down[] = {"/usr/bin/hciconfig", "/usr/bin/hciconfig", "hci0", "down", NULL};
365 if (__execute_command("/usr/bin/hciconfig", argv_down) < 0) {
367 if (__execute_command("/usr/etc/bluetooth/bt-stack-down.sh", NULL) < 0) {
369 BT_ERR("running script failed");
370 __bt_core_set_le_status(BT_LE_ACTIVATED);
374 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
377 __bt_core_set_le_status(BT_LE_DEACTIVATED);
383 int _bt_core_service_request_adapter(int service_function)
387 GArray *in_param1 = NULL;
388 GArray *in_param2 = NULL;
389 GArray *in_param3 = NULL;
390 GArray *in_param4 = NULL;
391 GArray *out_param = NULL;
393 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
395 ret = _bt_core_service_request(BT_CORE_SERVICE, service_function,
396 in_param1, in_param2, in_param3, in_param4, &out_param);
398 BT_ERR("_bt_core_service_request_adapter() failed");
400 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
405 static gboolean __bt_core_check_the_adapter_path(GDBusConnection *conn)
408 GDBusProxy *manager_proxy = NULL;
409 GVariant *result = NULL;
410 char *adapter_path = NULL;
415 manager_proxy = g_dbus_proxy_new_sync(conn,
416 G_DBUS_PROXY_FLAGS_NONE, NULL,
419 "org.freedesktop.DBus.ObjectManager",
422 if (!manager_proxy) {
424 BT_ERR("Unable to create proxy: %s", err->message);
427 BT_ERR("Fail to create proxy");
432 result = g_dbus_proxy_call_sync(manager_proxy, "DefaultAdapter", NULL,
433 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
436 BT_ERR("Fail to get DefaultAdapter (Error: %s)", err->message);
439 BT_ERR("Fail to get DefaultAdapter");
444 if (g_strcmp0(g_variant_get_type_string(result), "(o)")) {
445 BT_ERR("Incorrect result\n");
449 g_variant_get(result, "(&o)", &adapter_path);
451 if (adapter_path == NULL ||
452 strlen(adapter_path) >= BT_CORE_CHECK_ADAPTER_OBJECT_PATH_MAX) {
453 BT_ERR("Adapter path is inproper\n");
457 g_variant_unref(result);
458 g_object_unref(manager_proxy);
464 g_variant_unref(result);
467 g_object_unref(manager_proxy);
472 void _bt_core_update_status(void)
474 int bt_status = VCONFKEY_BT_STATUS_OFF;
475 int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF;
476 gboolean ret = FALSE;
478 ret = __bt_core_check_the_adapter_path(_bt_core_get_gdbus_connection());
479 BT_INFO("check the real status of bt_adapter");
482 __bt_core_set_status(BT_DEACTIVATED);
483 __bt_core_set_le_status(BT_DEACTIVATED);
485 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0)
486 BT_ERR("no bluetooth device info, so BT was disabled at previous session");
487 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0)
488 BT_ERR("no bluetooth le info, so BT LE was disabled at previous session");
490 BT_INFO("bt_status = %d, bt_le_status = %d", bt_status, bt_le_status);
492 if (bt_status & VCONFKEY_BT_STATUS_ON)
493 __bt_core_set_status(BT_ACTIVATED);
494 if (bt_le_status & VCONFKEY_BT_LE_STATUS_ON)
495 __bt_core_set_le_status(BT_ACTIVATED);
499 gboolean _bt_core_enable_adapter(void)
503 _bt_set_flightmode_request(FALSE);
504 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
505 BT_ERR("Set vconf failed");
507 ret = _bt_enable_adapter();
514 gboolean _bt_core_disable_adapter(void)
518 _bt_set_flightmode_request(FALSE);
519 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
520 BT_ERR("Set vconf failed");
522 ret = _bt_disable_adapter();
529 gboolean _bt_core_recover_adapter(void)
534 BT_INFO_C("Recover bt adapter");
536 _bt_set_flightmode_request(FALSE);
537 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
538 BT_ERR("Set vconf failed");
540 is_recovery_mode = TRUE;
542 _bt_core_update_status();
544 if (_bt_core_get_status() == BT_ACTIVATED) {
545 _bt_core_set_bt_status(BT_RECOVERY_MODE, 1);
546 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
548 if (_bt_core_get_le_status() == BT_LE_ACTIVATED) {
549 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 1);
550 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
553 ret = _bt_disable_adapter();
555 BT_ERR("_bt_disable_adapter() failed");
556 ret_le = _bt_disable_adapter_le();
558 BT_ERR("_bt_disable_adapter_le() failed");
563 gboolean _bt_core_enable_adapter_le(void)
567 ret = _bt_enable_adapter_le();
574 gboolean _bt_core_disable_adapter_le(void)
580 ret = _bt_disable_adapter_le();
587 gboolean __bt_core_reset_adapter(void)
589 /* Forcely terminate */
590 if (__execute_command("/usr/etc/bluetooth/bt-reset-env.sh", NULL) < 0) {
591 BT_ERR("running script failed");
593 _bt_core_terminate();
598 static gboolean __bt_core_enable_core_timeout_cb(gpointer data)
602 _bt_core_init_vconf_value();
607 gboolean _bt_core_enable_core(void)
611 _bt_core_update_status();
613 g_timeout_add(200, (GSourceFunc)__bt_core_enable_core_timeout_cb, NULL);
619 gboolean _bt_core_set_transfer_value(gboolean value)
621 const char *event_val = NULL;
624 BT_DBG("value: %d", value);
626 event_val = value ? EVT_VAL_BT_TRANSFERING : EVT_VAL_BT_NON_TRANSFERING;
628 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_TRANSFERING_STATE,
629 event_val) != ES_R_OK) {
630 BT_ERR("Fail to set BT state value");
634 if (ret == FALSE || value == FALSE) {
635 BT_DBG("Terminate bt-core process");
636 g_timeout_add(BT_CORE_IDLE_TERM_TIME, __bt_core_idle_terminate, NULL);
643 gboolean _bt_core_factory_test_mode(const char *type, const char *arg)
647 char *arg_list[3] = { NULL, NULL, NULL };
649 BT_DBG("Test item : %s", type);
651 if (g_strcmp0(type, "Enable_RF_Test") == 0) {
652 cmd = "/usr/etc/bluetooth/bt-edutm-on.sh";
653 arg_list[0] = "bt-edutm-on.sh";
654 } else if (g_strcmp0(type, "Disable_RF_Test") == 0) {
655 cmd = "/usr/etc/bluetooth/bt-edutm-off.sh";
656 arg_list[0] = "bt-edutm-off.sh";
657 } else if (g_strcmp0(type, "Slave_Mode") == 0) {
658 cmd = "/usr/etc/bluetooth/bt-mode-slave.sh";
659 arg_list[0] = "bt-mode-slave.sh";
660 } else if (g_strcmp0(type, "Master_Mode") == 0) {
661 cmd = "/usr/etc/bluetooth/bt-mode-master.sh";
662 arg_list[0] = "bt-mode-master.sh";
663 } else if (g_strcmp0(type, "SSP_Debug_Mode") == 0) {
664 cmd = "/usr/etc/bluetooth/bt-set-ssp-debug-mode.sh";
665 arg_list[0] = "bt-set-ssp-debug-mode.sh";
666 arg_list[1] = (char *)arg;
667 } else if (g_strcmp0(type, "RF_Channel") == 0) {
668 cmd = "/usr/etc/bluetooth/bt-enable-rf-channel.sh";
669 arg_list[0] = "bt-enable-rf-channel.sh";
670 arg_list[1] = (char *)arg;
672 _bt_core_terminate();
676 BT_DBG("Run %s", cmd);
677 if (__execute_command(cmd, arg_list) < 0) {
678 BT_ERR("running script failed");
681 _bt_core_terminate();
685 static gboolean __bt_core_recovery_cb(gpointer data)
688 gboolean is_request_failed = FALSE;
689 static gboolean is_first_failure = TRUE;
693 if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
694 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
696 is_request_failed = TRUE;
699 if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
700 ret = _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
702 is_request_failed = TRUE;
705 if (is_request_failed == TRUE) {
706 BT_ERR("Recovery is failed.");
707 if (is_first_failure == TRUE) {
708 g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
709 is_first_failure = FALSE;
712 is_first_failure = TRUE;
716 is_first_failure = TRUE;
718 if (_bt_core_get_bt_status(BT_RECOVERY_MODE) == 1) {
719 _bt_core_set_bt_status(BT_RECOVERY_MODE, 0);
720 ret = _bt_enable_adapter();
722 BT_ERR("_bt_enable_adapter() failed");
724 if (_bt_core_get_bt_le_status(BT_RECOVERY_MODE) == 1) {
725 _bt_core_set_bt_le_status(BT_RECOVERY_MODE, 0);
726 ret = _bt_enable_adapter_le();
728 BT_ERR("_bt_enable_adapter_le() failed");
731 is_recovery_mode = FALSE;
738 static gboolean __bt_core_enable_timeout_cb(gpointer data)
740 bt_status_t adapter_status;
741 bt_le_status_t adapter_status_le;
745 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
746 BT_ERR("Set vconf failed");
748 adapter_status = _bt_core_get_status();
749 adapter_status_le = _bt_core_get_le_status();
751 if (adapter_status == BT_DEACTIVATED &&
752 _bt_core_get_bt_status(BT_FLIGHT_MODE) != 0) {
753 _bt_core_set_bt_status(BT_FLIGHT_MODE, 0);
754 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
755 _bt_enable_adapter();
758 if (adapter_status_le == BT_LE_DEACTIVATED &&
759 _bt_core_get_bt_le_status(BT_FLIGHT_MODE) != 0) {
760 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, 0);
761 _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
762 _bt_enable_adapter_le();
768 static gboolean __bt_core_disable_timeout_cb(gpointer data)
770 bt_status_t adapter_status;
771 bt_le_status_t adapter_status_le;
775 if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
776 BT_ERR("Set vconf failed");
778 adapter_status = _bt_core_get_status();
779 adapter_status_le = _bt_core_get_le_status();
781 if (adapter_status == BT_ACTIVATED) {
782 int bt_status_before_mode = 0;
784 if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
785 _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_status_before_mode);
787 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
788 _bt_disable_adapter();
791 if (adapter_status_le == BT_LE_ACTIVATED) {
792 int bt_le_status_before_mode = 0;
794 if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
795 _bt_core_set_bt_le_status(BT_FLIGHT_MODE, bt_le_status_before_mode);
797 _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
798 _bt_disable_adapter_le();
804 static int __bt_eventsystem_set_value(const char *event, const char *key, const char *value)
811 bundle_add_str(b, key, value);
813 ret = eventsystem_send_system_event(event, b);
815 BT_DBG("eventsystem_send_system_event result: %d", ret);
822 void _bt_core_adapter_added_cb(void)
825 bt_le_status_t le_status;
826 gboolean flight_mode_status;
830 status = _bt_core_get_status();
831 BT_DBG("status : %d", status);
832 le_status = _bt_core_get_le_status();
833 BT_DBG("le_status : %d", le_status);
835 if (status == BT_ACTIVATING)
836 __bt_core_set_status(BT_ACTIVATED);
837 if (le_status == BT_LE_ACTIVATING)
838 __bt_core_set_le_status(BT_LE_ACTIVATED);
840 flight_mode_status = _bt_core_is_flight_mode_enabled();
842 if (flight_mode_status == TRUE && _bt_is_flightmode_request() == TRUE) {
843 _bt_set_flightmode_request(FALSE);
844 g_timeout_add(2000, (GSourceFunc)__bt_core_disable_timeout_cb, NULL);
847 _bt_set_flightmode_request(FALSE);
849 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
850 EVT_VAL_BT_ON) != ES_R_OK)
851 BT_ERR("Fail to set BT state value");
853 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
854 EVT_VAL_BT_LE_ON) != ES_R_OK)
855 BT_ERR("Fail to set BT LE state value");
857 _bt_core_terminate();
860 void _bt_core_adapter_removed_cb(void)
862 int flight_mode_value = 0;
863 int power_saving_mode = 0;
864 gboolean flight_mode_status;
865 static int timer_id = -1;
869 __bt_core_set_status(BT_DEACTIVATED);
870 __bt_core_set_le_status(BT_LE_DEACTIVATED);
871 if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
872 BT_ERR("Set vconf failed");
873 if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
874 BT_ERR("Set vconf failed");
876 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
877 EVT_VAL_BT_OFF) != ES_R_OK)
878 BT_ERR("Fail to set value");
880 if (__bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
881 EVT_VAL_BT_LE_OFF) != ES_R_OK)
882 BT_ERR("Fail to set value");
884 if (is_recovery_mode == TRUE) {
886 timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_recovery_cb, NULL);
890 if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value) != 0)
891 BT_ERR("Fail to get the flight_mode_deactivated value");
893 if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &power_saving_mode) != 0)
894 BT_ERR("Fail to get the ps_mode_deactivated value");
896 flight_mode_status = _bt_core_is_flight_mode_enabled();
898 if (flight_mode_status == FALSE && _bt_is_flightmode_request() == TRUE) {
899 _bt_set_flightmode_request(FALSE);
901 timer_id = g_timeout_add(2000, (GSourceFunc)__bt_core_enable_timeout_cb, NULL);
904 _bt_set_flightmode_request(FALSE);
906 if (flight_mode_value == 1 || power_saving_mode == 1) {
907 BT_DBG("Bt Core not terminated");
911 _bt_core_terminate();