GList *g_alarm_list;
} bt_service_alarm_mgr_t;
+#define BT_RECOVERY_MAX_COUNT 3
+
static bt_service_alarm_mgr_t alarm_mgr = {0, };
static gboolean is_discovering;
static GDBusProxy *core_proxy = NULL;
static guint timer_id = 0;
static guint le_timer_id = 0;
-static gboolean is_recovery_mode;
+static int recovery_cnt = -1;
+static guint recovery_timer = 0;
static uint status_reg_id;
#define BT_CORE_INTERFACE "org.projectx.btcore"
#define BT_DISABLE_TIME 500 /* 500 ms */
+#ifdef TIZEN_PROFILE_WEARABLE
+#define BT_RECOVERY_TIME 2000 /*2 sec*/
+#else
+#define BT_RECOVERY_TIME 5000 /*5 sec*/
+#endif
static int alarm_cb(alarm_id_t alarm_id, void* user_param);
static void alarm_data_free(void *data);
_bt_adapter_set_status(BT_DEACTIVATED);
_bt_set_discovery_status(FALSE);
-#ifndef TIZEN_FEATURE_BT_USB_DONGLE
- if (_bt_adapter_get_le_status() != BT_LE_DEACTIVATED) {
-#endif
- /* Send disabled event */
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
- g_variant_new("(i)", result));
-#ifndef TIZEN_FEATURE_BT_USB_DONGLE
- }
-#endif
-
BT_INFO("Adapter disabled");
}
BT_DBG("bt_state: (%s)", bt_le_status);
}
+static gboolean __bt_adapter_recovery_cb(gpointer data)
+{
+ int ret = 0;
+
+ BT_DBG("+");
+
+ recovery_timer = 0;
+
+ _bt_service_initialize();
+
+ ret = _bt_enable_adapter_check_status();
+ if (ret == BLUETOOTH_ERROR_NONE) {
+ ret = _bt_enable_adapter();
+ if (ret < 0)
+ BT_ERR("_bt_enable_adapter() failed");
+
+ ret = _bt_enable_adapter_le();
+ if (ret < 0)
+ BT_ERR("_bt_enable_adapter_le() failed");
+ }
+
+ recovery_cnt--;
+
+ BT_DBG("-");
+
+ return FALSE;
+}
+
void _bt_handle_adapter_added(void)
{
BT_DBG("+");
}
*/
+ recovery_cnt = -1;
+
status = _bt_adapter_get_status();
le_status = _bt_adapter_get_le_status();
BT_DBG("status : %d", status);
/* Other unregister APIs should be placed here */
-
#ifndef TIZEN_FEATURE_BT_USB_DONGLE
_bt_destroy_agent(adapter_agent);
adapter_agent = NULL;
- if (is_recovery_mode == TRUE) {
+ if (recovery_cnt > 0) {
/* Send disabled event */
_bt_set_disabled(BLUETOOTH_ERROR_NONE);
+ _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
+ g_variant_new("(i)", BLUETOOTH_ERROR_NONE));
- /* Will recover BT by bt-core, so set the mode as activating */
- _bt_adapter_set_status(BT_ACTIVATING);
- is_recovery_mode = FALSE;
- } else {
- _bt_reliable_terminate_service(NULL);
+ if (recovery_timer > 0)
+ g_source_remove(recovery_timer);
+ recovery_timer = g_timeout_add(BT_RECOVERY_TIME,
+ (GSourceFunc)__bt_adapter_recovery_cb, NULL);
+
+ if (eventsystem_unregister_event(status_reg_id) != ES_R_OK)
+ BT_ERR("Fail to unregister system event");
+ return;
}
+
+ _bt_reliable_terminate_service(NULL);
+
#else
_bt_set_disabled(BLUETOOTH_ERROR_NONE);
+ _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
+ g_variant_new("(i)", BLUETOOTH_ERROR_NONE));
#endif
if (eventsystem_unregister_event(status_reg_id) != ES_R_OK)
g_variant_unref(result);
_bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT);
+ if (recovery_cnt > 0) {
+ BT_ERR("Try recovery again(remain:%d)", recovery_cnt);
+ if (recovery_timer > 0)
+ g_source_remove(recovery_timer);
+ recovery_timer = g_timeout_add(BT_RECOVERY_TIME,
+ (GSourceFunc)__bt_adapter_recovery_cb, NULL);
+
+ return FALSE;
+ }
+
#ifndef TIZEN_FEATURE_BT_USB_DONGLE
_bt_terminate_service(NULL);
#endif
}
g_variant_unref(result);
- _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
- _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT);
+ if (_bt_adapter_get_le_status() != BT_LE_DEACTIVATED)
+ _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT);
if (_bt_adapter_get_status() == BT_DEACTIVATED)
_bt_terminate_service(NULL);
{
BT_DBG("");
_bt_set_disabled(BLUETOOTH_ERROR_NONE);
+ _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
+ g_variant_new("(i)", BLUETOOTH_ERROR_NONE));
return FALSE;
}
int _bt_recover_adapter(void)
{
BT_DBG("+");
- GDBusProxy *proxy;
- GVariant *result;
- GError *error = NULL;
if (_bt_adapter_get_status() == BT_DEACTIVATING) {
BT_DBG("Disabling in progress");
return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
}
- _bt_adapter_set_status(BT_DEACTIVATING);
-
- proxy = __bt_get_core_proxy();
- retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "RecoverAdapter",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to RecoverAdapter (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to RecoverAdapter");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- is_recovery_mode = TRUE;
+ recovery_cnt = BT_RECOVERY_MAX_COUNT;
- g_variant_unref(result);
- __bt_disconnect_all();
+ _bt_disable_adapter();
+ _bt_disable_adapter_le();
BT_DBG("-");
return BLUETOOTH_ERROR_NONE;