Providing bluetooth data to battery monitor framework 34/213034/6
authorSudipto <sudipto.bal@samsung.com>
Thu, 29 Aug 2019 10:37:56 +0000 (16:07 +0530)
committerSudipto <sudipto.bal@samsung.com>
Mon, 16 Sep 2019 05:46:25 +0000 (11:16 +0530)
Data provided:
Session start time
Session end time
Session scan time
Session connected time

Change-Id: I33243d08333d74559cd32143202b7a287af28748
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
include/bluetooth_internal.h
include/bluetooth_type_internal.h
src/bluetooth-adapter.c
test/bt_unit_test.c
test/bt_unit_test.h

index 697addb..4ec0dd2 100644 (file)
@@ -69,6 +69,32 @@ 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
  * @brief Disables the local Bluetooth adapter, asynchronously.
  * @since_tizen @if WEARABLE 2.3.1 @else 2.3 @endif
  * @privlevel platform
index f2fe5dc..333414d 100644 (file)
@@ -22,6 +22,7 @@ extern "C"
 {
 #endif /* __cplusplus */
 
+#include <stdint.h>
 #include <glib.h>
 
 /* 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;
index 8d12f69..b314830 100644 (file)
@@ -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;
index fe85217..1676782 100644 (file)
@@ -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];
index 1d1dbef..f56169e 100644 (file)
@@ -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,