gboolean adapter_state;
_bt_set_flightmode_request(FALSE);
- if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 0) != 0)
- BT_ERR("Set vconf failed");
adapter_state = __bt_core_check_the_adapter_path();
if (adapter_state == FALSE)
#endif
} else if (bt_status == VCONFKEY_BT_STATUS_OFF &&
(flight_mode_deactivation == 1 || ps_mode_deactivation > 0)) {
- _bt_core_handle_flight_mode_noti();
+ //_bt_core_handle_flight_mode_noti();
_bt_core_handle_power_saving_mode_noti();
_bt_core_set_bt_status(BT_FLIGHT_MODE, flight_mode_deactivation);
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);
-
-#ifdef TIZEN_FEATURE_BUSACT
- _bt_core_service_request_adapter(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;
-
- 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);
-
-#ifdef TIZEN_FEATURE_BUSACT
- _bt_core_service_request_adapter(BT_DISABLE_ADAPTER_LE);
-#endif
- if (!TIZEN_FEATURE_BT_USB_DONGLE)
- _bt_disable_adapter_le();
- }
- } 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);
- if (!TIZEN_FEATURE_BT_USB_DONGLE)
- _bt_enable_adapter();
- }
-
- 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);
- if (!TIZEN_FEATURE_BT_USB_DONGLE)
- _bt_enable_adapter_le();
- }
- }
-}
-
static void __bt_core_handle_adapter_with_power_saving_mode(int power_saving_mode)
{
bt_status_t adapter_status;
}
}
-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);
-}
-
#ifdef ENABLE_TIZEN_2_4
static void __bt_core_power_saving_mode_cb(keynode_t *node, void *data)
{
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();
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);
-
- if (flight_mode == TRUE)
- __bt_core_handle_adapter_with_flight_mode(flight_mode);
#ifndef ENABLE_TIZEN_2_4
- else if (power_saving_mode > 0)
+ if (power_saving_mode > 0)
__bt_core_handle_adapter_with_power_saving_mode(power_saving_mode);
-#endif
else
BT_ERR("");
-}
-
-void _bt_core_handle_flight_mode_noti(void)
-{
- int ret;
-
- if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
- 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)
void _bt_core_unregister_vconf_handler(void)
{
- if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
- vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
- (vconf_callback_fn)__bt_core_flight_mode_cb);
- }
-
#ifdef ENABLE_TIZEN_2_4
if (!TIZEN_PROFILE_WEARABLE) {
vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
(vconf_callback_fn)__bt_core_power_saving_mode_cb);
}
#endif
-
- return;
}
void _bt_core_init_vconf_value(void);
-void _bt_core_handle_flight_mode_noti(void);
void _bt_core_handle_power_saving_mode_noti(void);
void _bt_core_unregister_vconf_handler(void);
}
}
-static void __bt_hal_flight_ps_mode_cb(keynode_t *node, void *data)
-{
- gboolean flight_mode = FALSE;
- int type;
- DBG_SECURE("HAL callback hit");
- DBG_SECURE("key=%s", vconf_keynode_get_name(node));
- type = vconf_keynode_get_type(node);
- if (type == VCONF_TYPE_BOOL) {
- flight_mode = vconf_keynode_get_bool(node);
- if (flight_mode != TRUE) {
- ERR("Ignore the event");
- return;
- } else {
- ERR("Flight Mode == TRUE");
- }
- } else {
- ERR("Invaild vconf key type : %d", type);
- return;
- }
- DBG("Enabling core now");
- _bt_hal_enable_core();
-}
-
-static void _bt_hal_register_vconf_handler(void)
-{
- DBG("+");
-
- if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
- (vconf_callback_fn)__bt_hal_flight_ps_mode_cb, NULL) < 0)
- ERR("Unable to register key handler");
- DBG("Telephony is disabled");
- if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
- (vconf_callback_fn)__bt_hal_flight_ps_mode_cb, NULL) < 0)
- ERR("Unable to register key handler");
-}
-
void _bt_hal_handle_adapter_event(GVariant *msg, const char *member)
{
if (member == NULL)
/*TODO: Initialize Obexd Event receiver */
- /* Initialize event receiver for flight mode */
- _bt_hal_register_vconf_handler();
-
event_cb = cb;
return BT_HAL_ERROR_NONE;
static bt_adapter_timer_t visible_timer;
+typedef enum {
+ BT_ADAPTER_FLIGHT_MODE_NONE = -1,
+ BT_ADAPTER_FLIGHT_MODE_OFF,
+ BT_ADAPTER_FLIGHT_MODE_ON,
+} bt_adapter_flightmode_req_e;
+
+static bt_adapter_flightmode_req_e flightmode_request = BT_ADAPTER_FLIGHT_MODE_NONE;
+
static guint timer_id = 0;
static gboolean a2dp_init_pending = TRUE;
return FALSE;
}
+static void __bt_set_flightmode_request(int value)
+{
+ BT_INFO("Setting flightmode request to %d", value);
+ flightmode_request = value;
+}
+
+static int __bt_is_flightmode_request(void)
+{
+ return flightmode_request;
+}
+
+static void __bt_service_handle_flight_mode(gboolean flight_mode, bt_status_t adapter_status)
+{
+ int flight_mode_value = 0;
+ int ps_mode_value = 0;
+
+ if (flight_mode == TRUE) {
+ BT_INFO_C("### Flight mode on. Turn off BT");
+
+ if (adapter_status != BT_ACTIVATED) {
+ BT_INFO("No need to control bt status");
+ if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_value))
+ BT_ERR("Fail get PS mode value");
+
+ BT_DBG("ps_mode_value %d", ps_mode_value);
+ if (ps_mode_value > 0) {
+ if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
+ BT_ERR("Set vconf failed");
+ }
+ return;
+ }
+
+ __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_ON);
+
+ if (vconf_set_int(BT_OFF_DUE_TO_FLIGHT_MODE, 1) != 0)
+ BT_ERR("Set vconf failed");
+
+ if (adapter_status == BT_ACTIVATED)
+ _bt_disable_adapter();
+
+ } else {
+ BT_INFO_C("### Flight mode off. Turn on BT");
+
+ if (adapter_status == BT_ACTIVATED)
+ return;
+
+ if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_value))
+ BT_ERR("Fail get flight mode value");
+
+ BT_DBG("flight_mode_value %d", 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");
+
+ if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_value))
+ BT_ERR("Fail get PS mode value");
+
+ BT_DBG("ps_mode_value %d", ps_mode_value);
+ if (ps_mode_value > 0) {
+ BT_DBG("Bt should not turn on");
+ return;
+ }
+
+ if (adapter_status == BT_DEACTIVATING) {
+ BT_INFO("BT adapter is deactivating. Turn on BT after deactivation");
+ __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_OFF);
+ return;
+ }
+
+ if (adapter_status != BT_DEACTIVATED) {
+ BT_INFO("No need to control bt status");
+ return;
+ }
+ _bt_service_initialize();
+
+ if (adapter_status == BT_DEACTIVATED)
+ _bt_enable_adapter();
+
+ }
+}
+
+static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
+{
+ int type;
+ bt_status_t adapter_status = BT_DEACTIVATED;
+ gboolean flight_mode = FALSE;
+
+ adapter_status = _bt_adapter_get_status();
+ BT_INFO("Flight mode changed. Current bt status is %d", adapter_status);
+
+ DBG_SECURE("key=%s", vconf_keynode_get_name(node));
+ type = vconf_keynode_get_type(node);
+
+ if (type == VCONF_TYPE_BOOL) {
+ flight_mode = vconf_keynode_get_bool(node);
+ __bt_service_handle_flight_mode(flight_mode, adapter_status);
+ } else {
+ BT_ERR("Invaild vconf key type : %d", type);
+ }
+}
+
+void _bt_service_register_vconf_handler(void)
+{
+ BT_DBG("+");
+
+ 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");
+ 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");
+}
+
+void _bt_service_unregister_vconf_handler(void)
+{
+ BT_DBG("+");
+
+ vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+ (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
+
+ vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
+ (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
+}
+
int _bt_get_local_address(void)
{
int result;
/* 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);
- } else {
- _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+ if (__bt_is_flightmode_request() == BT_ADAPTER_FLIGHT_MODE_ON) {
+ /* Keep bt-service to handle Flight mode OFF */
+ BT_DBG("Deactived due to flight mode. Keep bt-service");
+ _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+ __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_NONE);
+ } else if (__bt_is_flightmode_request() == BT_ADAPTER_FLIGHT_MODE_OFF) {
+ BT_DBG("Durning deactivation, receive Flight mode Off. Enable BT adapter");
+ _bt_set_disabled(BLUETOOTH_ERROR_NONE);
+ _bt_service_initialize();
+ _bt_enable_adapter();
+ __bt_set_flightmode_request(BT_ADAPTER_FLIGHT_MODE_NONE);
+ } else
+ _bt_reliable_terminate_service(NULL);
}
return FALSE;
static void __bt_adapter_state_change_callback(int bt_status)
{
- BT_INFO("__bt_adapter_state_change_callback: status [%d]", bt_status);
+ BT_INFO("BT adapter status changed [%d]", bt_status);
switch (bt_status) {
case BT_DEACTIVATED:
g_source_remove(timer_id);
timer_id = 0;
}
+
+ /*If adapter gets activated when flight mode is ON*/
+ if (__bt_is_flightmode_request() == BT_ADAPTER_FLIGHT_MODE_ON) {
+ BT_DBG("Receive Flight mode On. Disable BT adapter");
+ _bt_disable_adapter();
+ return;
+ }
+
__bt_adapter_update_bt_enabled();
break;
default:
return EXIT_FAILURE;
}
- /* Flight mode handler implemented in HAL */
+ /* Flight mode handler */
+ _bt_service_register_vconf_handler();
/* Event sender Init */
ret = _bt_init_service_event_sender();
void _bt_service_register_vconf_handler(void);
-void _bt_service_register_vconf_handler(void);
+void _bt_service_unregister_vconf_handler(void);
gboolean _bt_is_discovering(void);
gboolean _bt_reliable_terminate_service(gpointer user_data);
+int _bt_service_initialize(void);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */