#include "bt-service-dpm.h"
#endif
#include "bt-service-hidhost.h"
+#include "bt-service-hiddevice.h"
#include "bt-service-socket.h"
#include "bt-service-hdp.h"
static bt_adapter_timer_t visible_timer;
-static guint timer_id = 0;
+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 gboolean a2dp_init_pending = FALSE;
+static guint timer_id = 0;
+static gboolean a2dp_init_pending = TRUE;
/* Adapter default states */
static bt_status_t adapter_state = BT_DEACTIVATED;
static void __bt_set_visible_mode(void);
static void __bt_set_local_name(void);
+static gboolean __bt_disconnect_all(void);
+
/* Initialize BT stack (Initialize OAL layer) */
int _bt_stack_init(void)
{
int _bt_enable_adapter(void)
{
+ bt_le_status_t le_status = BT_LE_DEACTIVATED;
+
+ le_status = _bt_adapter_get_le_status();
+
+ BT_INFO("Current state [%d], LE [%d]", adapter_state, le_status);
+
+ if (adapter_state == BT_ACTIVATING || le_status == BT_LE_ACTIVATING) {
+ BT_ERR("Enabling in progress");
+ return BLUETOOTH_ERROR_IN_PROGRESS;
+ }
+
+ if (adapter_state == BT_ACTIVATED) {
+ BT_ERR("Already enabled");
+ return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
+ }
+
+ if (adapter_state == BT_DEACTIVATING ||
+ adapter_state == BT_TERMINATING ||
+ le_status == BT_LE_DEACTIVATING) {
+ BT_ERR("Disabling in progress");
+ return BLUETOOTH_ERROR_DEVICE_BUSY;
+ }
+
return __bt_adapter_state_handle_request(TRUE);
}
int _bt_recover_adapter(void)
{
- /* TODO_40 : 4.0 merge */
- BT_INFO("Not Supported");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
+ int result = BLUETOOTH_ERROR_NONE;
+
+ if (_bt_adapter_get_status() == BT_DEACTIVATING) {
+ BT_ERR("Disabling in progress");
+ return BLUETOOTH_ERROR_IN_PROGRESS;
+ }
+
+ if (_bt_adapter_get_status() == BT_DEACTIVATED) {
+ BT_ERR("Already Disabled");
+ return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+ }
+
+ _bt_adapter_set_status(BT_DEACTIVATING);
+
+ result = adapter_recover();
+
+ if (result != OAL_STATUS_SUCCESS)
+ return BLUETOOTH_ERROR_INTERNAL;
+
+ __bt_disconnect_all();
+
+ return result;
}
int _bt_reset_adapter(void)
return BLUETOOTH_ERROR_NONE;
}
+#ifdef TIZEN_FEATURE_BT_PERMANENT_LOG
+void _bt_start_log_dump(const char *path)
+{
+ GDBusProxy *proxy;
+ GVariant *result;
+ GError *error = NULL;
+
+ ret_if(path == NULL);
+
+ BT_INFO("Start log_dump(path = %s)", path);
+
+ _bt_send_dump_signal(BT_DUMP_SERVICE_START_SIGNAL);
+
+ proxy = __bt_get_core_proxy();
+ ret_if(proxy == NULL);
+
+ result = g_dbus_proxy_call_sync(proxy, "LogDump",
+ g_variant_new("(s)", path),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (!result) {
+ if (error != NULL) {
+ BT_ERR("Bt core call failed(Error: %s)", error->message);
+ g_clear_error(&error);
+ } else {
+ BT_ERR("Bt core call failed");
+ }
+ } else {
+ g_variant_unref(result);
+ }
+
+ _bt_send_dump_signal(BT_DUMP_SERVICE_FINISH_SIGNAL);
+}
+#endif
+
int _bt_check_adapter(int *status)
{
BT_INFO("+");
int _bt_disable_adapter(void)
{
+ bt_le_status_t le_status = BT_LE_DEACTIVATED;
+
+ le_status = _bt_adapter_get_le_status();
+
+ BT_INFO("Current state [%d], LE [%d]", adapter_state, le_status);
+
+ if (adapter_state == BT_DEACTIVATING ||
+ adapter_state == BT_TERMINATING ||
+ le_status == BT_LE_DEACTIVATING) {
+ BT_DBG("Disabling in progress");
+ return BLUETOOTH_ERROR_IN_PROGRESS;
+ }
+
+ if (adapter_state == BT_DEACTIVATED) {
+ BT_DBG("Already disabled");
+ return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+ }
+
+ if (adapter_state == BT_ACTIVATING || le_status == BT_LE_ACTIVATING) {
+ BT_ERR("Enabling in progress");
+ return BLUETOOTH_ERROR_DEVICE_BUSY;
+ }
+
+ /* TODO: Need to add the function to disconnect all devices */
+ /* __bt_disconnect_all(); */
+
return __bt_adapter_state_handle_request(FALSE);
}
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;
return result;
}
+int _bt_get_connectable(void)
+{
+ int result;
+
+ BT_DBG("+");
+
+ result = adapter_get_connectable();
+ if (result != OAL_STATUS_SUCCESS) {
+ BT_ERR("adapter_get_connectable failed: %d", result);
+ result = BLUETOOTH_ERROR_INTERNAL;
+ } else
+ result = BLUETOOTH_ERROR_NONE;
+
+ BT_DBG("-");
+ return result;
+}
+
int _bt_is_service_used(void)
{
int result;
return BLUETOOTH_ERROR_NONE;
}
-static void __bt_handle_pending_a2dp_init(service_uuid_t *service_list, unsigned int count)
+static gboolean __bt_disconnect_all(void)
+{
+ int i;
+ gboolean ret = FALSE;
+ GArray *device_list;
+ guint size;
+ int result;
+ bluetooth_device_info_t *info;
+
+ BT_DBG("");
+ device_list = g_array_new(FALSE, FALSE, sizeof(gchar));
+
+ BT_DBG("The length of device list after the initialisation is [%d]", device_list->len);
+
+ _bt_service_get_bonded_dev_list(&device_list);
+
+ size = (device_list->len) / sizeof(bluetooth_device_info_t);
+
+ for (i = 0; i < size; i++) {
+ info = &g_array_index(device_list,
+ bluetooth_device_info_t, i);
+ if (info->connected != BLUETOOTH_CONNECTED_LINK_NONE) {
+ BT_DBG("Found Connected Device");
+ result = _bt_disconnect_device(&info->device_address);
+ if (result != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Cannot disconnect all the devices. bt_disconnect_device Failed");
+ g_array_free(device_list, TRUE);
+ return ret;
+ }
+ }
+ }
+ ret = TRUE;
+ g_array_free(device_list, TRUE);
+
+ return ret;
+}
+
+static void __bt_handle_pending_a2dp_init(unsigned int a2dp_role)
{
int ret;
- unsigned int i;
- unsigned char *uuid;
- char uuid_str[BT_UUID_STRING_SIZE];
if (!a2dp_init_pending)
return;
BT_DBG("+");
a2dp_init_pending = FALSE;
- for (i = 0; i < count; i++) {
- uuid = service_list[i].uuid;
- _bt_service_convert_uuid_type_to_string(uuid_str, uuid);
- BT_INFO("Adapter Service: [%s]", uuid_str);
- if (!strcasecmp(uuid_str, A2DP_SINK_UUID)) {
- BT_INFO("Enable A2DP Sink role");
- /* Initialize A2DP Sink */
- ret = _bt_audio_initialize(BT_A2DP_SINK_MODULE);
- if (ret != BLUETOOTH_ERROR_NONE)
- BT_ERR("_bt_audio_initialize(BT_A2DP_SINK_MODULE) Failed");
-
- /* Initialize AVRCP Controller */
- ret = _bt_audio_initialize(BT_AVRCP_CTRL_MODULE);
- if (ret != BLUETOOTH_ERROR_NONE)
- BT_ERR("_bt_audio_initialize(BT_AVRCP_CTRL_MODULE) Failed");
-
- _bt_audio_set_current_role(BLUETOOTH_A2DP_SINK);
- return;
- }
+
+ if (a2dp_role == BT_A2DP_SINK_ROLE) {
+ BT_INFO("Enable A2DP Sink role");
+ /* Initialize A2DP Sink */
+ ret = _bt_audio_initialize(BT_A2DP_SINK_MODULE);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ BT_ERR("_bt_audio_initialize(BT_A2DP_SINK_MODULE) Failed");
+
+ /* Initialize AVRCP Controller */
+ ret = _bt_audio_initialize(BT_AVRCP_CTRL_MODULE);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ BT_ERR("_bt_audio_initialize(BT_AVRCP_CTRL_MODULE) Failed");
+
+ _bt_audio_set_current_role(BLUETOOTH_A2DP_SINK);
+ return;
}
- BT_INFO("Enable A2DP Source role by default");
+ BT_INFO("Enable A2DP Source role");
/* Initialize A2DP Source */
ret = _bt_audio_initialize(BT_A2DP_SOURCE_MODULE);
if (ret != BLUETOOTH_ERROR_NONE)
BT_INFO("Adapter discoverable mode:"
" BLUETOOTH_DISCOVERABLE_MODE_NON_CONNECTABLE");
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
- g_variant_new("(b)", connectable));
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
- g_variant_new("(in)", result, mode));
+ if (__bt_is_service_request_present(BT_GET_CONNECTABLE)) {
+ __bt_adapter_handle_pending_requests(BT_GET_CONNECTABLE,
+ (void *) &connectable, sizeof(gboolean));
+
+ } else {
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
+ g_variant_new("(b)", connectable));
+
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+ g_variant_new("(in)", result, mode));
+ }
break;
}
case OAL_EVENT_ADAPTER_MODE_CONNECTABLE: {
BT_INFO("Adapter discoverable mode:"
" BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE");
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
- g_variant_new("(b)", connectable));
- mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
- g_variant_new("(in)", result, mode));
+ if (__bt_is_service_request_present(BT_GET_CONNECTABLE)) {
+ __bt_adapter_handle_pending_requests(BT_GET_CONNECTABLE,
+ (void *) &connectable, sizeof(gboolean));
+
+ } else {
+
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
+ g_variant_new("(b)", connectable));
+
+ mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+ g_variant_new("(in)", result, mode));
+ }
break;
}
case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE: {
int mode;
+ gboolean connectable = TRUE;
BT_INFO("Adapter discoverable mode:"
" BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE");
- /* Send event to application */
- mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
- g_variant_new("(in)", result, mode));
+ if (__bt_is_service_request_present(BT_GET_CONNECTABLE)) {
+ __bt_adapter_handle_pending_requests(BT_GET_CONNECTABLE,
+ (void *) &connectable, sizeof(gboolean));
+ } else {
+ /* Send event to application */
+ mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
+ _bt_send_event(BT_ADAPTER_EVENT,
+ BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+ g_variant_new("(in)", result, mode));
+ }
break;
}
case OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT: {
count = list->num;
service_list = list->service_list;
- __bt_handle_pending_a2dp_init(service_list, count);
__bt_adapter_handle_pending_requests(BT_IS_SERVICE_USED, service_list, count);
+
+ char uuids[512] = {0,};
+ char standard_prefix[2] = {0,};
+ int index = 0;
+ for (int i = 0; i < count; i++) {
+ if (i > 0)
+ g_snprintf(uuids + (index++), 2, ",");
+ if (memcmp(service_list[i].uuid, standard_prefix, 2) == 0) {
+ g_snprintf(uuids + index, 5, "%.2x%.2x",
+ service_list[i].uuid[2], service_list[i].uuid[3]);
+ index += 4;
+ } else {
+ g_snprintf(uuids + index, 9, "%.2x%.2x..%.2x,",
+ service_list[i].uuid[0], service_list[i].uuid[1], service_list[i].uuid[15]);
+ index += 8;
+ }
+ }
+ BT_PERMANENT_LOG("UUIDs %s", uuids);
break;
}
case OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST: {
g_free(addr_list);
break;
}
+ case OAL_EVENT_ADAPTER_PROPERTY_A2DP_ROLE: {
+ unsigned int *a2dp_role = event_data;
+
+ BT_INFO("a2dp role: [%u]", *a2dp_role);
+
+ __bt_handle_pending_a2dp_init(*a2dp_role);
+
+ break;
+ }
default:
BT_ERR("Unhandled event..");
break;
if (ret != BLUETOOTH_ERROR_NONE)
BT_ERR("_bt_hidhost_initialize Failed");
+ ret = _bt_hiddevice_initialize();
+ if (ret != BLUETOOTH_ERROR_NONE)
+ BT_ERR("_bt_hiddevice_initialize Failed");
+
ret = _bt_socket_init();
if (ret != BLUETOOTH_ERROR_NONE)
BT_ERR("_bt_socket_init Failed");
- /*
- * 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)
- BT_ERR("adapter_get_service_uuids failed: %d", ret);
- 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_gatt_init Failed");
+ /* Initialize HF Client */
+ ret = _bt_audio_initialize(BT_HFP_MODULE);
+ if (ret != BLUETOOTH_ERROR_NONE)
+ BT_ERR("_bt_audio_initialize(BT_HFP_MODULE) Failed");
+
return BLUETOOTH_ERROR_NONE;
}
//_bt_audio_deinitialize(BT_AG_MODULE);
//_bt_audio_deinitialize(BT_AVRCP_CTRL_MODULE);
//_bt_audio_deinitialize(BT_AUDIO_ALL_MODULE);
+
+ a2dp_init_pending = TRUE;
#endif
_bt_hdp_deinit();
_bt_gatt_deinit();
BT_INFO("+");
/* Get method invocation context */
- for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
+ for (l = _bt_get_invocation_list(); l != NULL; ) {
req_info = l->data;
+ l = g_slist_next(l);
if (req_info == NULL || req_info->service_function != service_function)
continue;
g_array_append_vals(out_param, &done, sizeof(gboolean));
break;
}
+ case BT_GET_CONNECTABLE:
case BT_GET_LOCAL_NAME:
case BT_GET_LOCAL_ADDRESS:
case BT_GET_LOCAL_VERSION:
/* Request return handlings */
static gboolean __bt_adapter_post_set_enabled(gpointer user_data)
{
- BT_INFO("__bt_adapter_post_set_enabled>>");
-
- if (!TIZEN_PROFILE_TV) {
- __bt_set_visible_mode();
+ int result = BLUETOOTH_ERROR_NONE;
- /* add the vconf noti handler */
- if (0 != vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
- (vconf_callback_fn)__bt_phone_name_changed_cb, NULL))
- BT_ERR("DEVICE_NAME key changed notification registration failed");
+ BT_INFO("__bt_adapter_post_set_enabled>>");
- __bt_set_local_name();
- } else {
+ if (TIZEN_PROFILE_TV || !headed_plugin_info->plugin_headed_enabled) {
if (BLUETOOTH_ERROR_NONE != _bt_set_discoverable_mode(
BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0))
BT_ERR("Fail to set discoverable mode");
+ } else {
+ __bt_set_visible_mode();
}
+ /* add the vconf noti handler */
+ if (0 != vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
+ (vconf_callback_fn)__bt_phone_name_changed_cb, NULL))
+ BT_ERR("DEVICE_NAME key changed notification registration failed");
+
+ __bt_set_local_name();
+
/* Get All properties */
if (OAL_STATUS_SUCCESS != adapter_get_properties())
BT_ERR("adapter_get_properties failed");
- /* Add Adapter enabled post processing codes */
+ __bt_adapter_state_set_status(BT_ACTIVATED);
+
+ /*Send BT Enabled event to application */
+ _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
+ g_variant_new("(i)", result));
+
+ BT_PERMANENT_LOG("BT Enabled");
+
return FALSE;
}
/* 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);
+ 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_update_bt_enabled(void)
{
- int result = BLUETOOTH_ERROR_NONE;
-
BT_INFO("_bt_adapter_update_bt_enabled >> Init profiles...");
if (BLUETOOTH_ERROR_NONE != _bt_init_profiles())
BT_ERR("Bluetooth profile init failed");
/* TODO:Add timer function to handle any further post processing */
g_idle_add((GSourceFunc)__bt_adapter_post_set_enabled, NULL);
-
- /*Return BT_ADAPTER_ENABLE Method invocation context */
- __bt_adapter_handle_pending_requests(BT_ENABLE_ADAPTER, NULL, 0);
- /*Send BT Enabled event to application */
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
- g_variant_new("(i)", result));
}
static void __bt_adapter_update_bt_disabled(void)
{
- int result = BLUETOOTH_ERROR_NONE;
int power_off_status = 0;
int ret;
_bt_device_handle_adapter_state(FALSE);
+#ifdef TIZEN_FEATURE_BT_AVC_TARGET
+ /* Send the information to Absolute Volume Controller */
+ _bt_audio_handle_adapter_disabled();
+#endif
+
/* Update the vconf BT status in normal Deactivation case only */
ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
BT_DBG("ret : %d, power_off_status : %d", ret, power_off_status);
/* TODO:Add timer function to handle any further post processing */
g_idle_add((GSourceFunc)__bt_adapter_post_set_disabled, NULL);
- /* Return BT_ADAPTER_DISABLE Method invocation context */
- __bt_adapter_handle_pending_requests(BT_DISABLE_ADAPTER, NULL, 0);
-
- /* Send BT Disabled event to application */
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
- g_variant_new("(i)", result));
+ /* Pending BT Disabled event before bt-service's termination */
}
static void __bt_adapter_state_set_status(bt_status_t status)
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:
- __bt_adapter_state_set_status(bt_status);
+ __bt_adapter_state_set_status(BT_TERMINATING);
/* Adapter is disabled, unregister event handlers */
_bt_service_unregister_event_handler_callback(BT_ADAPTER_MODULE);
__bt_adapter_update_bt_disabled();
break;
case BT_ACTIVATED:
- __bt_adapter_state_set_status(bt_status);
/* Add Adapter enabled post processing codes */
if (timer_id > 0) {
BT_DBG("g_source is removed");
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:
}
}
+int _bt_set_adapter_request_state(int enable)
+{
+ return oal_set_adapter_request_state(enable);
+}
+
+int _bt_set_le_request_state(int enable)
+{
+ return oal_set_le_request_state(enable);
+}
+
static int __bt_adapter_state_handle_request(gboolean enable)
{
int result = BLUETOOTH_ERROR_NONE;
- BT_DBG("");
switch (adapter_state) {
- case BT_ACTIVATING: {
- BT_INFO("Adapter is currently in activating state, state [%d]",
- adapter_state);
- if (enable) {
- return BLUETOOTH_ERROR_IN_PROGRESS;
- } else {
- if (adapter_discovery_state == ADAPTER_DISCOVERY_STARTED ||
- adapter_discovery_state == ADAPTER_DISCOVERY_STARTING) {
- /*TODO Stop Discovery*/
- __bt_adapter_update_discovery_status(FALSE);
- }
- result = adapter_disable();
- if (result != OAL_STATUS_SUCCESS) {
- BT_ERR("adapter_enable failed: [%d]", result);
- result = BLUETOOTH_ERROR_INTERNAL;
- /*TODO: perform if anything more needs to be done to handle failure */
- } else {
- /* TODO: To be handled */
- __bt_adapter_state_set_status(BT_DEACTIVATING);
- result = BLUETOOTH_ERROR_NONE;
- }
- }
+ case BT_ACTIVATING:
+ case BT_DEACTIVATING:
+ BT_INFO("Should not be callded : state [%d]", adapter_state);
+ return BLUETOOTH_ERROR_INTERNAL;
break;
- }
case BT_ACTIVATED: {
BT_INFO("Adapter is currently in activated state, state [%d]",
adapter_state);
}
break;
}
- case BT_DEACTIVATING: {
- BT_INFO("Adapter is currently in deactivating state, state [%d]",
- adapter_state);
- if (!enable) {
- return BLUETOOTH_ERROR_IN_PROGRESS;
-
- } else {
- result = adapter_enable();
- if (result != OAL_STATUS_SUCCESS && result != OAL_STATUS_PENDING) {
- BT_ERR("adapter_enable failed: [%d]", result);
- adapter_disable();
- result = BLUETOOTH_ERROR_INTERNAL;
- /*TODO: perform if anything more needs to be done to handle failure */
- } else {
- /* TODO: To be handled */
- __bt_adapter_state_set_status(BT_ACTIVATING);
- result = BLUETOOTH_ERROR_NONE;
- }
- }
- break;
- }
case BT_DEACTIVATED: {
BT_INFO("Adapter is currently in deactivated state, state [%d]",
adapter_state);
case ADAPTER_DISCOVERY_STARTING: {
BT_INFO("Adapter is currently in discovery starting state, state [%d]",
adapter_discovery_state);
- if (enable) {
- return BLUETOOTH_ERROR_IN_PROGRESS;
- } else {
- result = adapter_stop_inquiry();
- if (result != OAL_STATUS_SUCCESS) {
- BT_ERR("Discover stop failed: %d", result);
- result = BLUETOOTH_ERROR_INTERNAL;
- } else {
- BT_ERR("Stop Discovery Triggered successfully");
- __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STOPPING);
- result = BLUETOOTH_ERROR_NONE;
- }
- }
+
+ result = enable ? BLUETOOTH_ERROR_IN_PROGRESS :
+ BLUETOOTH_ERROR_DEVICE_BUSY;
+
break;
}
case ADAPTER_DISCOVERY_STOPPED: {
case ADAPTER_DISCOVERY_STOPPING: {
BT_INFO("Adapter is currently in discovery stopping state, state [%d]",
adapter_discovery_state);
- if (!enable)
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
- else {
- BT_DBG("max_resp: %u, duration: %u, cod: 0x%X", max_response, duration, mask);
- if (!is_custom)
- result = adapter_start_inquiry(duration);
- else
- result = adapter_start_custom_inquiry(role);
- if (result != OAL_STATUS_SUCCESS) {
- BT_ERR("Start Discovery failed: %d", result);
- result = BLUETOOTH_ERROR_INTERNAL;
- } else {
- BT_ERR("Start Discovery Triggered successfully");
- __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STARTING);
- result = BLUETOOTH_ERROR_NONE;
- }
- }
+
+ result = enable ? BLUETOOTH_ERROR_DEVICE_BUSY :
+ BLUETOOTH_ERROR_NOT_IN_OPERATION;
+
break;
}
default:
_bt_adapter_set_status(BT_DEACTIVATED);
__bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STOPPED);
+ /* Send BT Disabled event to application */
+ _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
+ g_variant_new("(i)", result));
+
BT_INFO("Adapter disabled");
+ BT_PERMANENT_LOG("BT Disabled");
}