From: Seungyoun Ju Date: Wed, 29 Nov 2017 09:00:10 +0000 (+0900) Subject: Add the interface to start / stop visibility timer X-Git-Tag: accepted/tizen/4.0/unified/20171214.050401~4 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git;a=commitdiff_plain;h=68afc674f9dbdc80993a4bfae002530916995b61 Add the interface to start / stop visibility timer [Problem] Visibility timer is not stopped when connectable mode is turned off. [Cause & Measure] This patch adds the interface to control visibility timer in event handler module. [Checking Method] Turn on limited discoverable mode -> Turn off connectable mode -> Check discoverable timeout event Change-Id: I512d695799999573df739292f80544a179f2beef --- diff --git a/bt-service/bt-service-adapter.c b/bt-service/bt-service-adapter.c index d06b753..2962726 100644 --- a/bt-service/bt-service-adapter.c +++ b/bt-service/bt-service-adapter.c @@ -194,9 +194,11 @@ static int __bt_visibility_alarm_cb(alarm_id_t alarm_id, void* user_param) BT_ERR("Set vconf failed\n"); } } + /* Switch Off visibility in Bluez */ _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0); visible_timer.alarm_id = 0; + return 0; } @@ -213,43 +215,60 @@ static void __bt_visibility_alarm_remove() } } -int __bt_set_visible_time(int timeout) +int _bt_start_visibility_timer(int timeout) { int result; - alarm_id_t alarm_id; + alarm_id_t alarm_id = 0; #ifdef TIZEN_FEATURE_BT_DPM int discoverable_state = DPM_BT_ERROR; #endif + if (timeout <= 0) { + BT_ERR("Invalid timeout : %d", timeout); + return BLUETOOTH_ERROR_INVALID_PARAM; + } + +#ifdef TIZEN_FEATURE_BT_DPM + _bt_dpm_get_bluetooth_limited_discoverable_state(&discoverable_state); + if (discoverable_state != DPM_RESTRICTED) { + BT_ERR("Limited discoverable mode is not allowed"); + return BLUETOOTH_ERROR_ACCESS_DENIED; + } +#endif + __bt_visibility_alarm_remove(); - visible_timer.timeout = timeout; + result = _bt_service_set_alarm(timeout, __bt_visibility_alarm_cb, NULL, + &alarm_id); + if (result != BLUETOOTH_ERROR_NONE) { + BT_ERR("_bt_service_set_alarm is failed : 0x%X", result); + return BLUETOOTH_ERROR_INTERNAL; + } if (!TIZEN_PROFILE_WEARABLE) { -#ifdef TIZEN_FEATURE_BT_DPM - _bt_dpm_get_bluetooth_limited_discoverable_state(&discoverable_state); - if (discoverable_state != DPM_RESTRICTED) { -#endif if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0) BT_ERR("Set vconf failed"); -#ifdef TIZEN_FEATURE_BT_DPM - } -#endif } - - if (timeout <= 0) - return BLUETOOTH_ERROR_NONE; - - result = _bt_service_set_alarm(visible_timer.timeout, - __bt_visibility_alarm_cb, NULL, &alarm_id); - if (result != BLUETOOTH_ERROR_NONE) - return BLUETOOTH_ERROR_INTERNAL; + visible_timer.timeout = timeout; visible_timer.alarm_id = alarm_id; /* Take start time */ time(&(visible_timer.start_time)); - visible_timer.event_id = g_timeout_add_seconds(1, - __bt_timeout_handler, NULL); + visible_timer.event_id = g_timeout_add_seconds(1, __bt_timeout_handler, NULL); + + return BLUETOOTH_ERROR_NONE; +} + +int _bt_stop_visibility_timer(void) +{ + __bt_visibility_alarm_remove(); + + visible_timer.timeout = 0; + + if (!TIZEN_PROFILE_WEARABLE) { + if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0) + BT_ERR("Set vconf failed"); + } return BLUETOOTH_ERROR_NONE; } @@ -2027,14 +2046,15 @@ int _bt_set_discoverable_mode(int discoverable_mode, int timeout) #ifdef TIZEN_FEATURE_BT_DPM _bt_dpm_get_bluetooth_limited_discoverable_state(&discoverable_state); if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE && - discoverable_state == DPM_RESTRICTED) { + discoverable_state == DPM_RESTRICTED) { if (headed_plugin_info->plugin_headed_enabled) headed_plugin_info->headed_plugin->bt_launch_dpmpopup("DPM_POLICY_DISABLE_BT_HANDSFREE"); return BLUETOOTH_ERROR_ACCESS_DENIED; } - if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE && - discoverable_state == DPM_RESTRICTED) { + + if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE && + discoverable_state == DPM_RESTRICTED) { if (headed_plugin_info->plugin_headed_enabled) headed_plugin_info->headed_plugin->bt_launch_dpmpopup("DPM_POLICY_DISABLE_BT"); @@ -2118,10 +2138,17 @@ int _bt_set_discoverable_mode(int discoverable_mode, int timeout) return BLUETOOTH_ERROR_INTERNAL; } - if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) - timeout = -1; - - ret = __bt_set_visible_time(timeout); + if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) { + ret = _bt_stop_visibility_timer(); + if (!TIZEN_PROFILE_WEARABLE) { + if (vconf_set_int(BT_FILE_VISIBLE_TIME, -1) != 0) + BT_ERR("Set vconf failed"); + } + } else if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE) { + ret = _bt_start_visibility_timer(timeout); + } else { + ret = _bt_stop_visibility_timer(); + } g_variant_unref(result); diff --git a/bt-service/include/bt-service-adapter.h b/bt-service/include/bt-service-adapter.h index 1787cc5..11e55fe 100644 --- a/bt-service/include/bt-service-adapter.h +++ b/bt-service/include/bt-service-adapter.h @@ -179,6 +179,11 @@ int _bt_service_set_alarm(int timeout, bt_set_alarm_cb call_back, int _bt_service_remove_alarm(alarm_id_t alarm_id); gint compare_alarm(gconstpointer list_data, gconstpointer data); + +int _bt_start_visibility_timer(int timeout); + +int _bt_stop_visibility_timer(void); + #ifdef __cplusplus } #endif /* __cplusplus */