static bt_adapter_timer_t visible_timer;
static guint timer_id = 0;
+static guint le_timer_id = 0;
static gboolean a2dp_init_pending = FALSE;
+static GDBusProxy *core_proxy = NULL;
+#define BT_CORE_NAME "org.projectx.bt_core"
+#define BT_CORE_PATH "/org/projectx/bt_core"
+#define BT_CORE_INTERFACE "org.projectx.btcore"
/* 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);
+void _bt_adapter_start_enable_timer(void);
+void _bt_adapter_start_le_enable_timer(void);
+
+GDBusProxy *_bt_init_core_proxy(void)
+{
+ GDBusProxy *proxy;
+ GDBusConnection *conn;
+
+ conn = _bt_gdbus_get_system_gconn();
+ if (!conn)
+ return NULL;
+
+ proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ BT_CORE_NAME,
+ BT_CORE_PATH,
+ BT_CORE_INTERFACE,
+ NULL, NULL);
+
+ if (!proxy)
+ return NULL;
+
+ core_proxy = proxy;
+
+ return proxy;
+}
+
+static GDBusProxy *__bt_get_core_proxy(void)
+{
+ return (core_proxy) ? core_proxy : _bt_init_core_proxy();
+}
+
/* Initialize BT stack (Initialize OAL layer) */
int _bt_stack_init(void)
int _bt_enable_core(void)
{
- /* TODO_40 : 4.0 merge */
- BT_INFO("Not Supported");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
+ BT_INFO("Implemented");
+ GDBusProxy *proxy;
+ GVariant *result;
+ GError *error = NULL;
+
+ proxy = __bt_get_core_proxy();
+ retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
+
+ /* Clean up the process */
+ result = g_dbus_proxy_call_sync(proxy,
+ "EnableCore",
+ NULL,
+ 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");
+ return BLUETOOTH_ERROR_INTERNAL;
+}
+
+g_variant_unref(result);
+return BLUETOOTH_ERROR_NONE;
}
int _bt_recover_adapter(void)
return BLUETOOTH_ERROR_NONE;
}
+void _bt_set_le_disabled(int result)
+{
+ int power_off_status;
+ int ret;
+
+ ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
+ BT_DBG("ret : %d", ret);
+ BT_DBG("power_off_status : %d", power_off_status);
+
+ /* Update Bluetooth Status to notify other modules */
+ BT_DBG("Update vconf for BT LE normal Deactivation");
+ if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
+ BT_ERR("Set vconf failed\n");
+ _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
+
+ if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
+ EVT_VAL_BT_LE_OFF) != ES_R_OK)
+ BT_ERR("Fail to set value");
+
+ /* Send disabled event */
+ _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED,
+ g_variant_new("(i)", result));
+}
+
int _bt_check_adapter(int *status)
{
BT_INFO("+");
return FALSE;
}
+static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
+{
+ gboolean flight_mode = FALSE;
+ int type;
+
+ 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) {
+ BT_ERR("Ignore the event");
+ return;
+ }
+ else {
+ BT_ERR("Flight Mode == TRUE");
+ }
+ } else {
+ BT_ERR("Invaild vconf key type : %d", type);
+ return;
+ }
+
+ _bt_enable_core();
+}
+
+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");
+ BT_DBG("Telephony is disabled");
+ 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);
+}
+
+static gboolean __bt_enable_timeout_cb(gpointer user_data)
+{
+ GDBusProxy *proxy;
+ GVariant *result;
+ GError *error = NULL;
+
+ timer_id = 0;
+
+ retv_if(_bt_adapter_get_status() == BT_ACTIVATED, FALSE);
+
+ BT_ERR("EnableAdapter is failed");
+
+ proxy = __bt_get_core_proxy();
+ if (!proxy)
+ return FALSE;
+
+ /* Clean up the process */
+ result = g_dbus_proxy_call_sync(proxy,
+ "DisableAdapter",
+ NULL,
+ 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");
+ }
+ return FALSE;
+ }
+
+ g_variant_unref(result);
+ _bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT);
+
+#ifndef USB_BLUETOOTH
+ _bt_terminate_service(NULL);
+#endif
+
+ return FALSE;
+}
+
+void _bt_adapter_start_enable_timer(void)
+{
+ if (timer_id > 0) {
+ g_source_remove(timer_id);
+ timer_id = 0;
+ }
+
+ timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
+ __bt_enable_timeout_cb, NULL);
+
+ return;
+}
+
+static gboolean __bt_enable_le_timeout_cb(gpointer user_data)
+{
+ GDBusProxy *proxy;
+ GVariant *result;
+ GError *error = NULL;
+
+ le_timer_id = 0;
+
+ retv_if(_bt_adapter_get_le_status() == BT_LE_ACTIVATED, FALSE);
+
+ BT_ERR("EnableAdapterLE is failed");
+
+ proxy = __bt_get_core_proxy();
+ if (!proxy)
+ return FALSE;
+
+ /* Clean up the process */
+ result = g_dbus_proxy_call_sync(proxy,
+ "DisableAdapterLe",
+ NULL,
+ 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");
+ return FALSE;
+ }
+
+ g_variant_unref(result);
+ _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
+
+ _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT);
+
+ if (_bt_adapter_get_status() == BT_DEACTIVATED)
+ _bt_terminate_service(NULL);
+
+ return FALSE;
+}
+
+void _bt_adapter_start_le_enable_timer(void)
+{
+ if (le_timer_id > 0) {
+ g_source_remove(le_timer_id);
+ le_timer_id = 0;
+ }
+
+ le_timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
+ __bt_enable_le_timeout_cb, NULL);
+
+ return;
+}
+
int _bt_get_local_address(void)
{
int result;