Adds new api 36/276836/4
authorInkyun Kil <inkyun.kil@samsung.com>
Mon, 27 Jun 2022 04:08:21 +0000 (13:08 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Thu, 30 Jun 2022 05:06:08 +0000 (14:06 +0900)
- To check if system time is set

Change-Id: I64dfbe373c31d2cc89c33b32414b37c4801f7ae9
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
alarm-manager-registry.c
alarm-manager.c
alarm_mgr.xml
include/alarm-internal.h
include/alarm.h
src/alarm-lib-stub.c
src/alarm-lib.c

index 67024819e07e77f176284be90badcd839f3b6da1..e1627b82bfdc1db70ef0d1b467d33887e93a9e9d 100644 (file)
@@ -298,3 +298,54 @@ void _update_db_for_disabled_alarm(alarm_id_t alarm_id, bool disabled)
        sqlite3_free(query);
        return;
 }
+
+bool _set_is_sys_time_set(void)
+{
+       char *error_message = NULL;
+       char *query = sqlite3_mprintf("insert into alarmmgr_system(\
+                       system_time, is_set)\
+                       values (%Q,%d)",
+                       "system_time", true);
+
+       if (sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message) != SQLITE_OK) {
+               SECURE_LOGE("sqlite3_exec() is failed. error message = %s", error_message);
+               sqlite3_free(error_message);
+               sqlite3_free(query);
+               return false;
+       }
+
+       sqlite3_free(query);
+
+       return true;
+}
+
+bool _get_is_sys_time_set(gboolean *is_sys_time_set)
+{
+       sqlite3_stmt *stmt = NULL;
+       int ret;
+       char *query = sqlite3_mprintf("select * from alarmmgr_system");
+
+       if (SQLITE_OK != sqlite3_prepare_v2(alarmmgr_db, query, strlen(query), &stmt, NULL)) {
+               LOGE("sqlite3_prepare() is failed.");
+               sqlite3_free(query);
+               return false;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (SQLITE_ROW == ret) {
+               *is_sys_time_set = sqlite3_column_int(stmt, 1);
+               LOGD("is_sys_time_set : %d", (int)*is_sys_time_set);
+       } else if (SQLITE_DONE == ret) {
+               LOGE("is_sys_time_set is not set");
+               *is_sys_time_set = false;
+       } else {
+               LOGE("sqlite3_step() is failed");
+               sqlite3_finalize(stmt);
+               sqlite3_free(query);
+               return false;
+       }
+
+       sqlite3_finalize(stmt);
+       sqlite3_free(query);
+       return true;
+}
\ No newline at end of file
index 5169c0ca54c9f514959fdc72cabebbe812aafa00..48e7444a62f466fd0d7e0c4ac49c54f05e8cc72b 100644 (file)
@@ -399,6 +399,7 @@ int __set_time(time_t _time)
        int ret = 0;
        struct timeval tv;
        struct tm tm, *gmtime_res;
+       gboolean is_sys_time_set;
 
        tv.tv_sec = _time;
        tv.tv_usec = 0;
@@ -411,6 +412,9 @@ int __set_time(time_t _time)
        if (ret < 0)
                ALARM_MGR_EXCEPTION_PRINT("settimeofday is failed.[%d]", errno);
 
+       if (!_get_is_sys_time_set(&is_sys_time_set))
+               _set_is_sys_time_set();
+
        if (_APPFW_FEATURE_WAKEUP_USING_RTC) {
                /* Using /dev/alarm, this function changes both OS time and RTC. */
                const char *rtc0 = default_rtc;
@@ -4357,6 +4361,20 @@ gboolean alarm_manager_alarm_get_global(AlarmManager *pObject, GDBusMethodInvoca
        return true;
 }
 
+gboolean alarm_manager_alarm_is_sys_time_set(AlarmManager *pObject, GDBusMethodInvocation *invoc,
+                                     gpointer user_data)
+{
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       gboolean is_sys_time_set = false;
+
+       if (!_get_is_sys_time_set(&is_sys_time_set))
+               return_code = ERR_ALARM_SYSTEM_FAIL;
+
+       ALARM_MGR_LOG_PRINT("Is system time set? : %d", is_sys_time_set);
+
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(bi)", is_sys_time_set, return_code));
+       return true;
+}
 
 static void __timer_glib_finalize(GSource *src)
 {
@@ -4562,6 +4580,7 @@ static bool __initialize_dbus()
        g_signal_connect(interface, "handle_alarm_set_time_with_propagation_delay", G_CALLBACK(alarm_manager_alarm_set_time_with_propagation_delay), NULL);
        g_signal_connect(interface, "handle_alarm_set_global", G_CALLBACK(alarm_manager_alarm_set_global), NULL);
        g_signal_connect(interface, "handle_alarm_get_global", G_CALLBACK(alarm_manager_alarm_get_global), NULL);
+       g_signal_connect(interface, "handle_alarm_is_sys_time_set", G_CALLBACK(alarm_manager_alarm_is_sys_time_set), NULL);
 
        subsc_id = g_dbus_connection_signal_subscribe(connection,
                        "org.freedesktop.DBus", "org.freedesktop.DBus",
@@ -4631,6 +4650,11 @@ static bool __initialize_dbus()
                                                dst_service_name text, \
                                                dst_service_name_mod text \
                                                )"
+#define QUERY_CREATE_TABLE_ALARMMGR_SYSTEM \
+       "       CREATE TABLE IF NOT EXISTS alarmmgr_system (\n" \
+       "       system_time TEXT PRIMARY KEY, \n" \
+       "       is_set BOOL \n" \
+       ")"
 
 static int __db_busyhandler(void *pData, int count)
 {
@@ -4699,6 +4723,14 @@ static bool __initialize_db()
                }
        }
 
+       ret = sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR_SYSTEM, NULL, NULL, &error_message);
+       if (ret != SQLITE_OK) {
+               LOGE("Don't execute query = %s, error message = %s", QUERY_CREATE_TABLE_ALARMMGR_SYSTEM, error_message);
+               sqlite3_free(error_message);
+               sqlite3_close(alarmmgr_db);
+               return false;
+       }
+
        /* Check integrity of DB */
        ret = sqlite3_exec(alarmmgr_db, "PRAGMA integrity_check", check_callback, NULL, 0);
        if (ret != SQLITE_OK || is_db_corrupted) {
@@ -4736,6 +4768,14 @@ recover:
                return false;
        }
 
+       ret = sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR_SYSTEM, NULL, NULL, &error_message);
+       if (ret != SQLITE_OK) {
+               LOGE("[recover] Don't execute query = %s, error message = %s", QUERY_CREATE_TABLE_ALARMMGR_SYSTEM, error_message);
+               sqlite3_close(alarmmgr_db);
+               sqlite3_free(error_message);
+               return false;
+       }
+
        return true;
 }
 
index bcdee0815583b20f81610983bfc2fed54f5ddd11..a4daf426788d77349920099f7cb920c10cc42cf9 100644 (file)
       <arg type="b" name="global" direction="out" />
       <arg type="i" name="return_code" direction="out" />
     </method>
+    <method name="alarm_is_sys_time_set">
+      <arg type="b" name="global" direction="out" />
+      <arg type="i" name="return_code" direction="out" />
+    </method>
     <signal name="alarm_expired">
       <arg type="i" name="alarm_id" />
       <arg type="s" name="app_service_name" />
index a0edf843c80b8c9343f8d72cf44e7066d40c067a..e326ef9d2e4c143e19670144c34882605ed0a6f6 100644 (file)
@@ -164,6 +164,7 @@ bool _send_alarm_set_time(alarm_context_t context, int new_time, int *error_code
 bool _send_alarm_set_time_async(alarm_context_t context, int new_time, alarm_set_time_cb_t result_cb, void *user_data);
 bool _send_alarm_set_global(alarm_context_t context, int alarm_id, bool global, int *error_code);
 bool _send_alarm_get_global(alarm_context_t context, int alarm_id, bool *global, int *error_code);
+bool _send_alarm_is_sys_time_set(alarm_context_t context, bool *global, int *error_code);
 
 /*  alarm manager*/
 typedef struct {
@@ -246,6 +247,8 @@ bool _init_scheduled_alarm_list();
 time_t _get_periodic_alarm_standard_time(void);
 
 void _update_db_for_disabled_alarm(alarm_id_t alarm_id, bool disabled_by_ups);
+bool _get_is_sys_time_set(gboolean *is_sys_time_set);
+bool _set_is_sys_time_set(void);
 
 #ifdef _DEBUG_MODE_
 #define ALARM_MGR_LOG_PRINT(FMT, ARG...)  do { printf("%5d", getpid()); printf
index dfde8380f9342715eb5b70ef508edcb76f58652b..ae3083ce673208a7ba4d0cac440c3a04136a9c23 100644 (file)
@@ -1683,6 +1683,8 @@ int alarmmgr_add_reference_periodic_alarm_withcb(int interval, alarm_cb_t handle
 int alarmmgr_update_alarm(alarm_id_t alarm_id,
                alarm_entry_t *alarm, int update_flag);
 
+int alarmmgr_is_sys_time_set(bool *is_sys_time_set);
+
 #ifdef __cplusplus
 }
 #endif
index ef9ff21fc206eba778f53b0807a9c5706f436db5..216e90395a9c8adc736338d53270ffd715eac5a2 100644 (file)
@@ -936,6 +936,39 @@ bool _send_alarm_get_global(alarm_context_t context, const alarm_id_t alarm_id,
        return true;
 }
 
+bool _send_alarm_is_sys_time_set(alarm_context_t context, bool *is_sys_time_set, int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       gboolean _is_sys_time_set;
+
+       if (!alarm_manager_call_alarm_is_sys_time_set_sync((AlarmManager *)context.proxy, &_is_sys_time_set, &return_code, NULL, &error)) {
+               /*g_dbus_proxy_call_sync error */
+               /*error_code should be set */
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_is_sys_time_set_sync() failed by dbus. return_code[%d]", return_code);
+               if (error_code) {
+                       if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                               *error_code = ERR_ALARM_NO_PERMISSION;
+                       else
+                               *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code);
+                       g_error_free(error);
+               }
+               return false;
+       }
+
+       if (return_code != ALARMMGR_RESULT_SUCCESS) {
+               if (error_code)
+                       *error_code = return_code;
+               return false;
+       }
+
+       *is_sys_time_set = (bool)_is_sys_time_set;
+       return true;
+}
+
 bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id,
                alarm_info_t *alarm_info, int update_flag, int *error_code)
 {
index 35b5af86287bcf182fda06cee97f5a8e0c50f895..5d513932edd11dd5ac572bbdf0fdb30627f2fd81 100755 (executable)
@@ -2013,3 +2013,21 @@ EXPORT_API int alarmmgr_update_alarm(alarm_id_t alarm_id,
 
        return ALARMMGR_RESULT_SUCCESS;
 }
+
+EXPORT_API int alarmmgr_is_sys_time_set(bool *is_sys_time_set)
+{
+       int error_code;
+
+       if (__sub_init() < 0)
+               return ERR_ALARM_SYSTEM_FAIL;
+
+       if (is_sys_time_set == NULL) {
+               LOGE("[alarm-lib]:is_sys_time_set is NULL\n");
+               return ERR_ALARM_INVALID_PARAM;
+       }
+
+       if (!_send_alarm_is_sys_time_set(alarm_context, is_sys_time_set, &error_code))
+               return error_code;
+
+       return ALARMMGR_RESULT_SUCCESS;
+}
\ No newline at end of file