Update the RFCOMM server connection information
[platform/core/connectivity/bluetooth-frwk.git] / bt-core / bt-core-noti-handler.c
index 3c5e618..9fdca7f 100644 (file)
@@ -1,11 +1,5 @@
 /*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
- *              Girishashok Joshi <girish.joshi@samsung.com>
- *              Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -46,9 +40,9 @@ static gboolean __bt_off_cause_conflict_check(void)
        int ps_mode_value = 0;
        gboolean ret = FALSE;
 
-       retv_if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE,
+       retv_if(vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE,
                                        &flight_mode_value) != 0, FALSE);
-       retv_if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE,
+       retv_if(vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE,
                                        &ps_mode_value) != 0, FALSE);
 
        if (flight_mode_value == 1 || ps_mode_value > 0) {
@@ -59,100 +53,6 @@ static gboolean __bt_off_cause_conflict_check(void)
        return ret;
 }
 
-static void __bt_core_handle_adapter_with_flight_mode(gboolean flight_mode)
-{
-       bt_status_t adapter_status;
-       bt_le_status_t adapter_status_le;
-
-       adapter_status = _bt_core_get_status();
-       adapter_status_le = _bt_core_get_le_status();
-
-       BT_INFO("bt status %d, le status %d", adapter_status, adapter_status_le);
-       if (flight_mode == TRUE) {
-               BT_INFO_C("Flight mode on. Turn off BT");
-
-               if (adapter_status == BT_ACTIVATING || adapter_status_le == BT_LE_ACTIVATING) {
-                       BT_INFO("BT adapter is activating. Turn off BT after activation");
-                       _bt_set_flightmode_request(TRUE);
-                       return;
-               }
-               if (adapter_status != BT_ACTIVATED && adapter_status_le != BT_LE_ACTIVATED) {
-                       BT_INFO("No need to control bt status");
-                       return;
-               }
-
-               if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
-                       BT_ERR("Set vconf failed");
-
-               if (adapter_status == BT_ACTIVATED) {
-                       int bt_status_before_mode = 0;
-
-                       if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
-                               _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_status_before_mode);
-
-                       _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
-#ifndef USB_BLUETOOTH
-                       _bt_disable_adapter();
-#endif
-               }
-
-               if (adapter_status_le == BT_LE_ACTIVATED) {
-                       int bt_le_status_before_mode = 0;
-
-                       if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
-                               _bt_core_set_bt_le_status(BT_FLIGHT_MODE, bt_le_status_before_mode);
-
-                       _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
-#ifndef USB_BLUETOOTH
-                       _bt_disable_adapter_le();
-#endif
-               }
-       } else {
-               int flight_mode_value = 0;
-
-               BT_INFO_C("Flight mode off. Turn on BT");
-
-               if (adapter_status == BT_DEACTIVATING || adapter_status_le == BT_LE_DEACTIVATING) {
-                       BT_INFO("BT adapter is activating. Turn off BT after activation");
-                       _bt_set_flightmode_request(TRUE);
-                       return;
-               }
-               if (adapter_status != BT_DEACTIVATED && adapter_status_le != BT_LE_DEACTIVATED) {
-                       BT_INFO("No need to control bt status");
-                       return;
-               }
-
-               if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value))
-                       BT_ERR("Fail get flight mode value");
-
-               if (flight_mode_value == 0)
-                       return;
-
-               if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
-                       BT_ERR("Set vconf failed");
-
-               ret_if(__bt_off_cause_conflict_check());
-
-               if (adapter_status == BT_DEACTIVATED &&
-                   _bt_core_get_bt_status(BT_FLIGHT_MODE) != 0) {
-                       _bt_core_set_bt_status(BT_FLIGHT_MODE, 0);
-                       _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
-#ifndef USB_BLUETOOTH
-                       _bt_enable_adapter();
-#endif
-               }
-
-               if (adapter_status_le == BT_LE_DEACTIVATED &&
-                   _bt_core_get_bt_le_status(BT_FLIGHT_MODE) != 0) {
-                       _bt_core_set_bt_le_status(BT_FLIGHT_MODE, 0);
-                       _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
-#ifndef USB_BLUETOOTH
-                       _bt_enable_adapter_le();
-#endif
-               }
-       }
-}
-
 static void __bt_core_handle_adapter_with_power_saving_mode(int power_saving_mode)
 {
        bt_status_t adapter_status;
@@ -171,10 +71,11 @@ static void __bt_core_handle_adapter_with_power_saving_mode(int power_saving_mod
                        if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status_before_mode) == 0)
                                _bt_core_set_bt_status(BT_POWER_SAVING_MODE, bt_status_before_mode);
 
+#ifdef TIZEN_FEATURE_BUSACT
                        _bt_core_service_request_adapter(BT_DISABLE_ADAPTER);
-#ifndef USB_BLUETOOTH
-                       _bt_disable_adapter();
 #endif
+                       if (!TIZEN_FEATURE_BT_USB_DONGLE)
+                               _bt_disable_adapter();
                }
                if (adapter_status_le == BT_LE_ACTIVATED) {
                        int bt_le_status_before_mode = 0;
@@ -182,11 +83,12 @@ static void __bt_core_handle_adapter_with_power_saving_mode(int power_saving_mod
                        if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status_before_mode) == 0)
                                _bt_core_set_bt_le_status(BT_POWER_SAVING_MODE, bt_le_status_before_mode);
 
+#ifdef TIZEN_FEATURE_BUSACT
                        /* Disable the BT LE */
                        _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
-#ifndef USB_BLUETOOTH
-                       _bt_disable_adapter_le();
 #endif
+                       if (!TIZEN_FEATURE_BT_USB_DONGLE)
+                               _bt_disable_adapter_le();
                }
        } else {
                int ps_mode_value = 0;
@@ -209,42 +111,21 @@ static void __bt_core_handle_adapter_with_power_saving_mode(int power_saving_mod
                if (adapter_status == BT_DEACTIVATED && (_bt_core_get_bt_status(BT_POWER_SAVING_MODE) != 0)) {
                        _bt_core_set_bt_status(BT_POWER_SAVING_MODE, 0);
                        _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
-#ifndef USB_BLUETOOTH
-                       _bt_enable_adapter();
-#endif
+                       if (!TIZEN_FEATURE_BT_USB_DONGLE)
+                               _bt_enable_adapter();
                }
                BT_DBG("BT LE status before Emergency mode() :%d", _bt_core_get_bt_le_status(BT_POWER_SAVING_MODE));
                if (adapter_status_le == BT_LE_DEACTIVATED &&  _bt_core_get_bt_le_status(BT_POWER_SAVING_MODE) != 0) {
                        _bt_core_set_bt_le_status(BT_POWER_SAVING_MODE, 0);
                        /* Enable the BT LE */
                        _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
-#ifndef USB_BLUETOOTH
-                       _bt_enable_adapter_le();
-#endif
+                       if (!TIZEN_FEATURE_BT_USB_DONGLE)
+                               _bt_enable_adapter_le();
                }
        }
 }
-#ifdef TIZEN_BT_FLIGHTMODE_ENABLED
-static void __bt_core_flight_mode_cb(keynode_t *node, void *data)
-{
-       gboolean flight_mode = FALSE;
-       int type;
-
-       BT_DBG("key = %s", vconf_keynode_get_name(node));
-
-       type = vconf_keynode_get_type(node);
-       if (type != VCONF_TYPE_BOOL) {
-               BT_ERR("Invaild vconf key type : %d", type);
-               return;
-       }
-
-       flight_mode = vconf_keynode_get_bool(node);
-
-       __bt_core_handle_adapter_with_flight_mode(flight_mode);
-}
-#endif
 
-#ifndef TIZEN_WEARABLE
+#ifdef ENABLE_TIZEN_2_4
 static void __bt_core_power_saving_mode_cb(keynode_t *node, void *data)
 {
        int power_saving_mode = 0;
@@ -267,55 +148,52 @@ static void __bt_core_power_saving_mode_cb(keynode_t *node, void *data)
 void _bt_core_init_vconf_value(void)
 {
        gboolean flight_mode = FALSE;
+#ifndef ENABLE_TIZEN_2_4
        int power_saving_mode = 0;
+#endif
+       int bt_flight_mode = 0;
+       int bt_ps_mode = 0;
 
-       _bt_core_handle_flight_mode_noti();
+       //_bt_core_handle_flight_mode_noti();
        _bt_core_handle_power_saving_mode_noti();
 
        flight_mode = _bt_core_is_flight_mode_enabled();
 
-#ifndef TIZEN_WEARABLE
-#ifdef ENABLE_TIZEN_2_4
-       if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_saving_mode) != 0)
-               BT_ERR("Fail to get the power_saving_mode status value");
-#endif
+#ifndef ENABLE_TIZEN_2_4
+       if (!TIZEN_PROFILE_WEARABLE) {
+               if (vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &power_saving_mode) != 0)
+                       BT_ERR("Fail to get the power_saving_mode status value");
+               BT_DBG("flight_mode = %d, power_saving_mode = %d", flight_mode, power_saving_mode);
+       }
 #endif
        BT_DBG("flight_mode = %d, power_saving_mode = %d", flight_mode, power_saving_mode);
 
-       if (flight_mode == TRUE)
-               __bt_core_handle_adapter_with_flight_mode(flight_mode);
-       else if (power_saving_mode > 0)
+       if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &bt_flight_mode))
+               BT_ERR("Fail get flight mode value");
+       _bt_core_set_bt_status(BT_FLIGHT_MODE, bt_flight_mode);
+
+       if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &bt_ps_mode))
+               BT_ERR("Fail get power saving mode value");
+       _bt_core_set_bt_status(BT_POWER_SAVING_MODE, bt_ps_mode);
+#ifndef ENABLE_TIZEN_2_4
+       if (power_saving_mode > 0)
                __bt_core_handle_adapter_with_power_saving_mode(power_saving_mode);
        else
                BT_ERR("");
-}
-
-void _bt_core_handle_flight_mode_noti(void)
-{
-#ifdef TIZEN_BT_FLIGHTMODE_ENABLED
-       int ret;
-
-       BT_DBG("+");
-
-       ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-                       (vconf_callback_fn)__bt_core_flight_mode_cb, NULL);
-       if (ret < 0)
-               BT_ERR("Unable to register key handler");
-#else
-       BT_DBG("Telephony is disabled");
 #endif
 }
 
 void _bt_core_handle_power_saving_mode_noti(void)
 {
-#ifndef TIZEN_WEARABLE
-       int ret = 0;
+       if (TIZEN_PROFILE_WEARABLE)
+               return;
 
        BT_DBG("+");
 #ifdef ENABLE_TIZEN_2_4
+       int ret = 0;
+
        ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
                        (vconf_callback_fn)__bt_core_power_saving_mode_cb, NULL);
-#endif
        if (ret < 0)
                BT_ERR("Unable to register key handler");
 #endif
@@ -323,18 +201,11 @@ void _bt_core_handle_power_saving_mode_noti(void)
 
 void _bt_core_unregister_vconf_handler(void)
 {
-#ifdef TIZEN_BT_FLIGHTMODE_ENABLED
-       vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-                       (vconf_callback_fn)__bt_core_flight_mode_cb);
-#endif
-
-#ifndef TIZEN_WEARABLE
 #ifdef ENABLE_TIZEN_2_4
-       vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
-                       (vconf_callback_fn)__bt_core_power_saving_mode_cb);
-#endif
+       if (!TIZEN_PROFILE_WEARABLE) {
+               vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
+                               (vconf_callback_fn)__bt_core_power_saving_mode_cb);
+       }
 #endif
-
-       return;
 }