From 0df5dd810c3fe4b2bde4e55313ae05931712160f Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Tue, 20 Jul 2021 19:32:40 +0900 Subject: [PATCH] Add an API for getting time update state. Change-Id: I11afee8a385517bac70599ec0268d65f421b3277 Signed-off-by: Jaehyun Kim --- include/connection_extension.h | 14 ++++++++++++++ include/net_connection_private.h | 1 + packaging/capi-network-connection.spec | 2 +- src/connection.c | 26 ++++++++++++++++++++++++++ src/libnetwork.c | 16 ++++++++++++++++ test/connection_test.c | 23 ++++++++++++++++++++++- 6 files changed, 80 insertions(+), 2 deletions(-) diff --git a/include/connection_extension.h b/include/connection_extension.h index bee17ca..8b7eb36 100755 --- a/include/connection_extension.h +++ b/include/connection_extension.h @@ -680,6 +680,20 @@ int connection_profile_save_ethernet_eap_config(connection_h connection, connection_profile_h profile); /** + * @brief Check if the time has been updated by NTP. + * @since_tizen 6.5 + * @param[in] connection The connection handle + * @param[out] updated true if the system time is updated by NTP, false otherwise + * @return 0 on success, otherwise a negative error value + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_OPERATION Invalid operation + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_PERMISSION_DENIED Permission denied + * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported + */ +int connection_clock_is_updated(connection_h connection, bool *updated); + +/** * @} */ diff --git a/include/net_connection_private.h b/include/net_connection_private.h index 48ef312..5163a73 100755 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -211,6 +211,7 @@ int _connection_libnet_start_tcpdump(connection_handle_s *conn_handle); int _connection_libnet_stop_tcpdump(connection_handle_s *conn_handle); int _connection_libnet_get_tcpdump_state(connection_handle_s *conn_handle, gboolean *tcpdump_state); +int _connection_libnet_get_clock_updated(connection_handle_s *conn_handle, bool *updated); void _connection_lock(void); void _connection_unlock(void); diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec index 3e31541..5f50351 100755 --- a/packaging/capi-network-connection.spec +++ b/packaging/capi-network-connection.spec @@ -1,6 +1,6 @@ Name: capi-network-connection Summary: Network Connection library in TIZEN C API -Version: 1.0.123 +Version: 1.0.124 Release: 2 Group: System/Network License: Apache-2.0 diff --git a/src/connection.c b/src/connection.c index 08c5a26..0048efb 100755 --- a/src/connection.c +++ b/src/connection.c @@ -1834,3 +1834,29 @@ EXPORT_API int connection_profile_save_ethernet_eap_config(connection_h connecti CONN_UNLOCK; return CONNECTION_ERROR_NONE; } + +EXPORT_API int connection_clock_is_updated(connection_h connection, bool *updated) +{ + CONN_LOCK; + + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + + if (!(_connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE + CONN_UNLOCK; //LCOV_EXCL_LINE + return CONNECTION_ERROR_INVALID_PARAMETER;//LCOV_EXCL_LINE + } + + int rv = _connection_libnet_get_clock_updated(connection, updated); + + if (rv != CONNECTION_ERROR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Fail to get clock update information[%d]", rv); //LCOV_EXCL_LINE + CONN_UNLOCK; //LCOV_EXCL_LINE + return rv; //LCOV_EXCL_LINE + } + + CONNECTION_LOG(CONNECTION_INFO, "Clock updated: %s", updated ? "true" : "false"); + CONN_UNLOCK; + + return CONNECTION_ERROR_NONE; +} diff --git a/src/libnetwork.c b/src/libnetwork.c index 4788660..81aaf10 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -1543,6 +1543,22 @@ int _connection_libnet_get_tcpdump_state(connection_handle_s *conn_handle, } //LCOV_EXCL_STOP +int _connection_libnet_get_clock_updated(connection_handle_s *conn_handle, bool *updated) +{ + int rv = 0; + + rv = net_get_clock_update_info(conn_handle->network_info_handle, updated); + if (rv == NET_ERR_ACCESS_DENIED) { + CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE + return CONNECTION_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE + } else if (rv != NET_ERR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to get clock update information[%d]", rv); //LCOV_EXCL_LINE + return CONNECTION_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + return CONNECTION_ERROR_NONE; +} + void _connection_lock(void) { if (g_conn_thread_mutex_ref == 0) diff --git a/test/connection_test.c b/test/connection_test.c index 653f4cd..9c86789 100755 --- a/test/connection_test.c +++ b/test/connection_test.c @@ -2960,6 +2960,24 @@ out: return 1; } +int test_get_clock_update_info(void) +{ + int rv = 0; + bool updated; + + rv = connection_clock_is_updated(connection, &updated); + + if (rv != CONNECTION_ERROR_NONE) { + printf("Fail to get clock update information [%s]\n", test_print_error(rv)); + return -1; + } + + printf("Retval = [%s] clock updated [%s]\n", + test_print_error(rv), updated ? "TRUE" : "FALSE"); + + return 1; +} + int main(int argc, char **argv) { GMainLoop *mainloop; @@ -3051,6 +3069,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("R - Destroy Handle(unset callbacks automatically in C# API)\n"); printf("S - Connect Ethernet EAP)\n"); printf("T - Get EAPoL info)\n"); + printf("U - Get Clock update info)\n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); } @@ -3214,7 +3233,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'T': rv = test_get_eapol_info(); break; - + case 'U': + rv = test_get_clock_update_info(); + break; } if (rv == 1) -- 2.7.4