From: Sudipto Date: Thu, 29 Aug 2019 10:37:56 +0000 (+0530) Subject: Providing bluetooth data to battery monitor framework X-Git-Tag: submit/tizen/20190916.233704~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b70da3a34aae31246c8047ecc204caa0e31e53f;p=platform%2Fcore%2Fapi%2Fbluetooth.git Providing bluetooth data to battery monitor framework Data provided: Session start time Session end time Session scan time Session connected time Change-Id: I33243d08333d74559cd32143202b7a287af28748 Signed-off-by: Sudipto --- diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index 697addb..4ec0dd2 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -66,6 +66,32 @@ extern "C" */ int bt_adapter_enable(void); +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Synchronously provides details about bluetooth usage + * @since_tizen 5.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function provides details such as session start time, session end time as well as total scan time and total connected time in a session + * + * @remarks An pointer of type bt_battery_info_s must be passed as argument which will contain the relevant information as the function returns. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @post + * + */ +int bt_adapter_read_battery_info(bt_battery_info_s *data); + /** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE diff --git a/include/bluetooth_type_internal.h b/include/bluetooth_type_internal.h index f2fe5dc..333414d 100644 --- a/include/bluetooth_type_internal.h +++ b/include/bluetooth_type_internal.h @@ -22,6 +22,7 @@ extern "C" { #endif /* __cplusplus */ +#include #include /* This variable will be added into bt_service_class_t in tizen 4.0 */ @@ -281,6 +282,14 @@ typedef struct { // int is_protected; } bt_map_client_message_s; +typedef struct { + time_t session_start_time; + time_t session_end_time; + uint16_t session_connected_time; + uint16_t session_scan_time; + GSList *atm_list; +} bt_battery_info_s; + typedef bt_map_client_list_folders_filter_s *bt_map_client_list_folders_filter_h; typedef bt_map_client_list_messages_filter_s *bt_map_client_list_messages_filter_h; diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index 8d12f69..b314830 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -61,6 +61,33 @@ int bt_adapter_enable(void) return error_code; } +int bt_adapter_read_battery_info(bt_battery_info_s *battery_data) +{ + bt_battery_data data; + int error_code = BT_ERROR_NONE; + + BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(battery_data); + error_code = _bt_get_error_code(bluetooth_read_battery_data(&data)); + + if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */ + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); /* LCOV_EXCL_LINE */ + return error_code; + } /* LCOV_EXCL_LINE */ + + battery_data->session_start_time = data.session_start_time; + battery_data->session_end_time = data.session_end_time; + battery_data->session_scan_time = data.session_scan_time; + battery_data->session_connected_time = data.session_connected_time; + + BT_DBG("Battery Data in application layer: %ld %ld %d %d", + battery_data->session_start_time, battery_data->session_end_time, + battery_data->session_scan_time, battery_data->session_connected_time); + return error_code; +} + int bt_adapter_disable(void) { int error_code = BT_ERROR_NONE; diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index fe85217..1676782 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -237,6 +237,8 @@ tc_table_t tc_adapter[] = { , BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_OOB_EXT_DATA}, {"bt_adapter_set_remote_oob_ext_data" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_REMOTE_OOB_EXT_DATA}, + {"bt_adapter_read_battery_info" + , BT_UNIT_TEST_FUNCTION_ADAPTER_READ_BATTERY_INFO}, {"bt_adapter_set_visibility_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_MODE_CHANGED_CB}, {"bt_adapter_unset_visibility_mode_changed_cb" @@ -4183,6 +4185,16 @@ int test_input_callback(void *data) } break; } + case BT_UNIT_TEST_FUNCTION_ADAPTER_READ_BATTERY_INFO: { + bt_battery_info_s data; + ret = bt_adapter_read_battery_info(&data); + if (ret < 0) + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + else + TC_PRT("Battery data: %ld %ld %d %d", data.session_start_time, + data.session_end_time, data.session_scan_time, data.session_connected_time); + break; + } case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_REMOTE_OOB_EXT_DATA: { char remote_addr[18]; unsigned char *param_data[4]; diff --git a/test/bt_unit_test.h b/test/bt_unit_test.h index 1d1dbef..f56169e 100644 --- a/test/bt_unit_test.h +++ b/test/bt_unit_test.h @@ -84,6 +84,7 @@ typedef enum { BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_OOB_EXT_DATA, BT_UNIT_TEST_FUNCTION_ADAPTER_SET_REMOTE_OOB_EXT_DATA, BT_UNIT_TEST_FUNCTION_ADAPTER_REMOVE_REMOTE_OOB_DATA, + BT_UNIT_TEST_FUNCTION_ADAPTER_READ_BATTERY_INFO, BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_MODE_CHANGED_CB, BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_VISIBILITY_MODE_CHANGED_CB, BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_DURATION_CHANGED_CB,