#include <E_DBus.h>
#include <aul.h>
#include <bluetooth.h>
+#include <bluetooth_internal.h>
#include <feedback.h>
#include <device/display.h>
#include <efl_extension.h>
elm_popup_dismiss(obj);
}
+static void __bluetooth_adapter_state_changed_cb(int result, bt_adapter_state_e state, void *user_data)
+{
+ BT_DBG("bluetooth state changed callback");
+ int ret;
+ int timeout;
+ struct bt_popup_appdata *ad = (struct bt_popup_appdata *)user_data;
+
+ if (state == BT_ADAPTER_ENABLED) {
+ BT_DBG("bt enabled");
+
+ if (ad->event_type != BT_EVENT_VISIBILITY_REQUEST) {
+ __bluetooth_win_del(ad);
+ return;
+ }
+
+ if (ad->visibility_timeout) {
+ timeout = atoi(ad->visibility_timeout);
+
+ if (timeout <= BT_VISIBILITY_TIMEOUT_MIN) {
+ ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, BT_VISIBILITY_TIMEOUT_MIN);
+ BT_DBG("set visibility, returns:%d", ret);
+ } else if (timeout >= BT_VISIBILITY_TIMEOUT_MAX) {
+ ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, BT_VISIBILITY_TIMEOUT_MAX);
+ BT_DBG("set visibility, returns:%d", ret);
+ } else {
+ ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, timeout);
+ BT_DBG("set visibility, returns:%d", ret);
+ }
+
+ free(ad->visibility_timeout);
+ ad->visibility_timeout = NULL;
+ } else {
+ /* default timeout value */
+ ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, BT_VISIBILITY_TIMEOUT_DEFAULT);
+ BT_DBG("set visibility, returns:%d", ret);
+ }
+
+ __bluetooth_win_del(ad);
+ } else {
+ BT_DBG("bt disabled");
+ }
+}
+
+static void __bluetooth_visibility_confirm_cb(void *data,
+ Evas_Object *obj, void *event_info)
+{
+ BT_DBG("visibility confirm cb called");
+
+ if (obj == NULL || data == NULL)
+ return;
+
+ int ret = BT_ERROR_NONE;
+ bt_adapter_state_e state = BT_ADAPTER_DISABLED;
+ const char *style = elm_object_style_get(obj);
+
+ struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
+
+ if (!g_strcmp0(style, "popup/circle/right")) {
+ /* check state */
+ ret = bt_initialize();
+ if (ret) {
+ BT_DBG("bt initialize, returns:%d", ret);
+ return;
+ }
+
+ ret = bt_adapter_set_state_changed_cb(__bluetooth_adapter_state_changed_cb, ad);
+ if (ret) {
+ BT_DBG("bt enable, returns:%d", ret);
+ return;
+ }
+
+ ret = bt_adapter_get_state(&state);
+ if (ret) {
+ BT_DBG("bt get state, returns:%d", ret);
+ return;
+ }
+
+ if (state == BT_ADAPTER_DISABLED) {
+ ret = bt_adapter_enable();
+ BT_DBG("bt enable, returns:%d", ret);
+ } else {
+ if (ad->event_type != BT_EVENT_VISIBILITY_REQUEST) {
+ BT_DBG("Already enabled, and not visiblity mode");
+ __bluetooth_win_del(ad);
+ return;
+ }
+
+ if (ad->visibility_timeout) {
+ ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, atoi(ad->visibility_timeout));
+ BT_DBG("set visibility, returns:%d", ret);
+ } else {
+ ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, 120);
+ BT_DBG("set visibility, returns:%d", ret);
+ }
+ __bluetooth_win_del(ad);
+ }
+ } else {
+ __bluetooth_win_del(ad);
+ }
+}
+
+static char *format_string(const char *format, ...)
+{
+ va_list arg;
+ char* chTemp = NULL;
+ chTemp = (char*)malloc(1024 * sizeof(char));
+ if (!chTemp) {
+ BT_DBG("memory alloc failed");
+ return NULL;
+ }
+
+ va_start(arg, format);
+ vsnprintf(chTemp, 1024, format, arg);
+ va_end(arg);
+ return chTemp;
+}
+
static void __lock_display()
{
#if 0
}
break;
+ case BT_EVENT_ENABLE_REQUEST: {
+ int ret = BT_ERROR_NONE;
+ bt_adapter_state_e state = BT_ADAPTER_DISABLED;
+ char *popup_text = NULL;
+
+ BT_INFO("Enable request popup");
+
+ ret = bt_initialize();
+ if (ret) {
+ BT_DBG("Fail to bt initialize, returns:%d", ret);
+ break;
+ }
+
+ ret = bt_adapter_get_state(&state);
+ if (ret) {
+ BT_DBG("Fail to bt get state, returns:%d", ret);
+ break;
+ }
+
+ if (state == BT_ADAPTER_ENABLED) {
+ BT_DBG("Already enabled!");
+ timeout = BT_ERROR_TIMEOUT;
+ __bluetooth_draw_toast_popup(ad, "Bluetooth is already enabled");
+ break;
+ }
+
+ popup_text = format_string("Requesting permission to turn on Bluetooth. Do you want to do this?");
+
+ __bluetooth_draw_text_popup(ad, popup_text, __bluetooth_visibility_confirm_cb);
+
+ g_free(popup_text);
+
+ break;
+ }
+ case BT_EVENT_VISIBILITY_REQUEST: {
+ char *tmp_timeout = NULL;
+ char *popup_text = NULL;
+
+ BT_INFO("Enable request popup");
+
+ if (ad->visibility_timeout) {
+ timeout = atoi(ad->visibility_timeout);
+
+ if (timeout <= BT_VISIBILITY_TIMEOUT_MIN)
+ tmp_timeout = BT_VISIBILITY_TIMEOUT_MIN_STR;
+ else if (timeout >= BT_VISIBILITY_TIMEOUT_MAX)
+ tmp_timeout = BT_VISIBILITY_TIMEOUT_MAX_STR;
+ else
+ tmp_timeout = ad->visibility_timeout;
+ } else {
+ /* default timeout value */
+ tmp_timeout = BT_VISIBILITY_TIMEOUT_DEFAULT_STR;
+ }
+
+ popup_text = format_string("Requesting permission to turn on Bluetooth and to set Visibility during %s seconds. Do you want to do this?",
+ tmp_timeout);
+
+ __bluetooth_draw_text_popup(ad, popup_text, __bluetooth_visibility_confirm_cb);
+
+ g_free(popup_text);
+ break;
+ }
+
default:
BT_ERR("Unknown event_type : %s", ad->event_type);
return -1;
/* Start Main UI */
event_type = bundle_get_val(b, "event-type");
if (event_type == NULL) {
+ char *operation = NULL;
+
BT_ERR("event type is NULL");
- return;
- }
- BT_INFO("event_type : %s", event_type);
- __bluetooth_parse_event(ad, event_type);
+ /* Get app control operation */
+ if (app_control_get_operation(app_control, &operation) < 0) {
+ BT_ERR("Get operation error");
+ return;
+ }
- if (!strcasecmp(event_type, "terminate")) {
- BT_ERR("get terminate event");
- __bluetooth_win_del(ad);
- return;
+ if (operation)
+ BT_INFO("operation: %s", operation);
+
+ if (g_strcmp0(operation, APP_CONTROL_OPERATION_SETTING_BT_VISIBILITY) == 0) {
+ char *timeout = NULL;
+
+ ad->visibility_timeout = NULL;
+ ret = app_control_get_extra_data(app_control, "timeout", &timeout);
+ if (ret < 0) {
+ BT_ERR("Get data error");
+ } else {
+ BT_INFO("Get visibility timeout : %s", timeout);
+ if (timeout)
+ ad->visibility_timeout = timeout;
+ }
+
+ ad->event_type = BT_EVENT_VISIBILITY_REQUEST;
+ } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_SETTING_BT_ENABLE) == 0) {
+ ad->event_type = BT_EVENT_ENABLE_REQUEST;
+ } else {
+ BT_ERR("Abnormal app control operation!");
+ return;
+ }
+ } else {
+ BT_INFO("event_type : %s", event_type);
+
+ __bluetooth_parse_event(ad, event_type);
+
+ if (!strcasecmp(event_type, "terminate")) {
+ BT_ERR("get terminate event");
+ __bluetooth_win_del(ad);
+ return;
+ }
}
if (syspopup_has_popup(b)) {
}
ret = syspopup_create(b, &handler, ad->win_main, ad);
- if (ret == -1) {
- BT_ERR("syspopup_create err");
- __bluetooth_remove_all_event(ad);
- return;
- }
-
-
+ if (ret == -1)
+ BT_ERR("No syspopup call - Just AUL operation");
DONE:
ret = __bluetooth_launch_handler(ad, b);
if (ret != 0) {