From: DoHyun Pyun Date: Wed, 2 Aug 2017 06:43:16 +0000 (+0900) Subject: Support the app control operation for bt enable and visiblity X-Git-Tag: submit/tizen/20180319.053649~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9afe4c88a79696bd3d0fb522d0f4c30f94862f36;p=platform%2Fcore%2Fconnectivity%2Fbt-syspopup.git Support the app control operation for bt enable and visiblity Change-Id: I9040e1128e4de1124b09a4b316430277e9075bb1 Signed-off-by: DoHyun Pyun --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7444338..5b1c93b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,6 +140,7 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${TZ_SYS_RO_APP}/org.tizen.bt-syspop # install desktop file & icon SET(PREFIX ${CMAKE_INSTALL_PREFIX}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/org.tizen.bt-syspopup.xml DESTINATION /usr/share/packages/) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/org.tizen.bt-syspopup_w.xml DESTINATION /usr/share/packages/) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/org.tizen.bt-syspopup.png DESTINATION ${TZ_SYS_SHARE}/icons/default/small) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/custom_popup.edj DESTINATION ${TZ_SYS_RO_APP}/org.tizen.bt-syspopup/res/edje) IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_PROFILE_WEARABLE") diff --git a/data/org.tizen.bt-syspopup_w.xml b/data/org.tizen.bt-syspopup_w.xml new file mode 100644 index 0000000..f1ac529 --- /dev/null +++ b/data/org.tizen.bt-syspopup_w.xml @@ -0,0 +1,23 @@ + + + + DoHyun Pyun + Bluetooth System Popup + + + org.tizen.bt-syspopup.png + + + + + + + + + http://tizen.org/privilege/window.priority.set + http://tizen.org/privilege/display + http://tizen.org/privilege/bluetooth + http://tizen.org/privilege/bluetooth.admin + http://tizen.org/privilege/haptic + + diff --git a/packaging/org.tizen.bt-syspopup.spec b/packaging/org.tizen.bt-syspopup.spec index 7cf3934..02ee786 100644 --- a/packaging/org.tizen.bt-syspopup.spec +++ b/packaging/org.tizen.bt-syspopup.spec @@ -166,7 +166,6 @@ popd %manifest org.tizen.bt-syspopup.manifest %license LICENSE %defattr(-,root,root,-) -%{TZ_SYS_RO_PACKAGES}/org.tizen.bt-syspopup.xml %{TZ_SYS_SHARE}/icons/default/small/org.tizen.bt-syspopup.png # For backward-compatibility and GBM build optimization @@ -176,12 +175,14 @@ popd %license LICENSE %{TZ_SYS_RO_APP}/org.tizen.bt-syspopup/bin/bt-syspopup %{TZ_SYS_RO_APP}/org.tizen.bt-syspopup/res/edje/custom_popup.edj +%{TZ_SYS_RO_PACKAGES}/org.tizen.bt-syspopup.xml %endif # For backward-compatibility and GBM build optimization # if wearable, "unified". common may be added after efl-ext is unified/refactored. %if "%{?profile}" != "mobile" && "%{?profile}" != "tv" && "%{?profile}" != "ivi" && "%{?profile}" != "common" %post profile_wearable +mv %{TZ_SYS_RO_PACKAGES}/org.tizen.bt-syspopup_w.xml %{TZ_SYS_RO_PACKAGES}/org.tizen.bt-syspopup.xml pushd %{TZ_SYS_RO_APP}/org.tizen.bt-syspopup/bin mv bt-syspopup.wearable bt-syspopup popd @@ -202,4 +203,5 @@ popd %{TZ_SYS_RO_APP}/org.tizen.bt-syspopup/shared/res/tables/org.tizen.bt-syspopup_ChangeableColorTable.xml %{TZ_SYS_RO_APP}/org.tizen.bt-syspopup/shared/res/tables/org.tizen.bt-syspopup_FontInfoTable.xml %{TZ_SYS_RO_APP}/org.tizen.bt-syspopup/res/images/* +%{TZ_SYS_RO_PACKAGES}/org.tizen.bt-syspopup_w.xml %endif diff --git a/src/bt-syspopup-w.c b/src/bt-syspopup-w.c index 0738ff9..380b9bd 100644 --- a/src/bt-syspopup-w.c +++ b/src/bt-syspopup-w.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,123 @@ static void __bluetooth_popup_block_clicked_cb(void *data, Evas_Object *obj, voi 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 @@ -1830,6 +1948,69 @@ static int __bluetooth_launch_handler(struct bt_popup_appdata *ad, } 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; @@ -2032,17 +2213,49 @@ static void __bluetooth_reset(app_control_h app_control, void *user_data) /* 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)) { @@ -2067,13 +2280,8 @@ static void __bluetooth_reset(app_control_h app_control, void *user_data) } 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) { diff --git a/src/bt-syspopup-w.h b/src/bt-syspopup-w.h index 53efd07..dcc021c 100644 --- a/src/bt-syspopup-w.h +++ b/src/bt-syspopup-w.h @@ -173,6 +173,14 @@ dgettext(BT_COMMON_PKG, "WDS_ST_HEADER_ENTER_PIN_ABB") +#define BT_VISIBILITY_TIMEOUT_DEFAULT 120 +#define BT_VISIBILITY_TIMEOUT_MIN 1 +#define BT_VISIBILITY_TIMEOUT_MAX 600 + +#define BT_VISIBILITY_TIMEOUT_DEFAULT_STR "120" +#define BT_VISIBILITY_TIMEOUT_MIN_STR "1" +#define BT_VISIBILITY_TIMEOUT_MAX_STR "600" + typedef enum { BT_CHANGED_MODE_ENABLE, BT_CHANGED_MODE_DISABLE, @@ -198,6 +206,8 @@ typedef enum { BT_EVENT_HANDSFREE_AUTO_CONNECT_REQUEST = 0x1600, BT_EVENT_SYSTEM_RESET_REQUEST = 0x10000, BT_EVENT_PASSKEY_AUTO_ACCEPTED = 0x20000, + BT_EVENT_ENABLE_REQUEST = 0x40000, + BT_EVENT_VISIBILITY_REQUEST = 0x80000, } bt_popup_event_type_t; typedef enum { @@ -257,6 +267,8 @@ struct bt_popup_appdata { bt_popup_event_type_t event_type; Evas_Object *popup_check; bt_pincode_input_object *po; + + char *visibility_timeout; }; #endif /* __DEF_BT_SYSPOPUP_H_ */