diff options
author | Inkyun Kil <inkyun.kil@samsung.com> | 2020-06-19 13:01:19 +0900 |
---|---|---|
committer | Inkyun Kil <inkyun.kil@samsung.com> | 2020-06-25 16:57:53 +0900 |
commit | e002c23e1822572a6153626175250a44a1e46542 (patch) | |
tree | c0f66310c94a0e6c256debd3c89a847607729781 | |
parent | 4db806433570659bb7bfd316584f50fc06f81e6c (diff) | |
download | alarm-manager-tizen_5.5.tar.gz alarm-manager-tizen_5.5.tar.bz2 alarm-manager-tizen_5.5.zip |
Improve codes for rtc resettizen_5.5
Change-Id: I76b60ef568b64c0859924868a5d13d5c0d855dec
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
-rw-r--r-- | server/alarm-manager-db.c | 56 | ||||
-rw-r--r-- | server/alarm-manager-db.h | 2 | ||||
-rw-r--r-- | server/alarm-manager.c | 30 |
3 files changed, 81 insertions, 7 deletions
diff --git a/server/alarm-manager-db.c b/server/alarm-manager-db.c index 5de09b3..aed8b99 100644 --- a/server/alarm-manager-db.c +++ b/server/alarm-manager-db.c @@ -79,6 +79,7 @@ extern __alarm_server_context_t alarm_context; sqlite3 *alarmmgr_db; static bool is_db_corrupted = false; +static const int latest_settime_id = -2; static const migration_func m_func[] = { @@ -809,3 +810,58 @@ recover: return true; } + +bool _set_latest_settime(time_t settime) +{ + char *error_message = NULL; + + char *query = sqlite3_mprintf("insert or replace into alarmmgr( alarm_id, start,\ + end, uid, global, is_disabled, caller_pkgid, callee_pkgid, app_unique_name,\ + app_service_name, app_service_name_mod, bundle, noti_len, noti, year,\ + month, day, hour, min, sec, msec, day_of_week, repeat,\ + alarm_type, reserved_info, dst_service_name, dst_service_name_mod)\ + values (%d,%d,0,0,0,1,'n','n','n','n','n','n',0,\ + 'n',0,0,0,0,0,0,0,0,0,0,0,'n','n')", latest_settime_id, (gint64)settime); + + if (SQLITE_OK != sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) { + SECURE_LOGE("sqlite3_exec() is failed. query = %s, error message = %s", query, error_message); + sqlite3_free(error_message); + sqlite3_free(query); + return false; + } + + LOGD("latest_settime : %ld", settime); + sqlite3_free(query); + return true; +} + +bool _get_latest_settime(time_t *settime) +{ + sqlite3_stmt *stmt = NULL; + int ret; + + char *query = sqlite3_mprintf("select start from alarmmgr where alarm_id=%d", + latest_settime_id); + + ret = sqlite3_prepare_v2(alarmmgr_db, query, strlen(query), &stmt, NULL); + if (SQLITE_OK != ret) { + LOGE("sqlite3_prepare() is failed. [%d]", ret); + sqlite3_free(query); + return false; + } + + ret = sqlite3_step(stmt); + if (SQLITE_ROW == ret) { + *settime = (time_t)sqlite3_column_int(stmt, 0); + LOGD("latest_settime : %ld", *settime); + } else { + LOGE("latest_settime is not set"); + sqlite3_finalize(stmt); + sqlite3_free(query); + return false; + } + + sqlite3_finalize(stmt); + sqlite3_free(query); + return true; +}
\ No newline at end of file diff --git a/server/alarm-manager-db.h b/server/alarm-manager-db.h index b454ba2..02c18ba 100644 --- a/server/alarm-manager-db.h +++ b/server/alarm-manager-db.h @@ -33,6 +33,8 @@ bool _save_alarms(__alarm_info_t *__alarm_info); bool _update_alarms(__alarm_info_t *__alarm_info); gboolean _update_relative_alarms(gpointer user_data); void _update_db_for_disabled_alarm(alarm_id_t alarm_id, bool disabled_by_ups); +bool _get_latest_settime(time_t *settime); +bool _set_latest_settime(time_t settime); int migration_func_version_1(void); diff --git a/server/alarm-manager.c b/server/alarm-manager.c index f67beda..b22345e 100644 --- a/server/alarm-manager.c +++ b/server/alarm-manager.c @@ -85,6 +85,7 @@ GHashTable *caller_appid_cache_table; bool is_time_changed = false; /* for calculating next duetime */ static time_t periodic_alarm_standard_time = 0; static bool using_rtc = false; +static bool is_rtc_reset = false; struct running_info_t { pid_t pid; @@ -315,6 +316,9 @@ static bool __set_time(time_t _time) LOGD("ALARM_SET_RTC ioctl is succeed. [%d]", (int)_time); strncpy(log_tag, "SET RTC START", sizeof(log_tag) - 1); _save_module_log(log_tag, log_message); + + if (!_set_latest_settime(_time)) + LOGE("DB is failed."); return true; } } else { @@ -588,7 +592,6 @@ static void __alarm_update_due_time_of_all_items_in_list(time_t new_time, double __alarm_info_t *entry = NULL; struct tm *p_time = NULL; struct tm due_time_result; - bool is_rtc_reset = false; is_time_changed = true; if (periodic_alarm_standard_time != 0) @@ -601,8 +604,7 @@ static void __alarm_update_due_time_of_all_items_in_list(time_t new_time, double if (base_info->alarm_type & ALARM_TYPE_RELATIVE) { /* case of RTC reset */ if (entry->base_info.mode.repeat == ALARM_REPEAT_MODE_ONCE) { - if ((entry->due_time + diff_time - new_time) > - (entry->due_time - entry->base_info.reserved_info)) { + if (is_rtc_reset) { LOGE("[ RTC reset]: new time %s %ld, diff %f, id %d duetime %s %ld %ld", ctime(&new_time), new_time, diff_time, entry->alarm_id, ctime(&entry->due_time), entry->due_time, @@ -615,9 +617,7 @@ static void __alarm_update_due_time_of_all_items_in_list(time_t new_time, double } else { entry->due_time += diff_time; - is_rtc_reset = false; - if ((entry->due_time - new_time) > base_info->mode.u_interval.interval) { - is_rtc_reset = true; + if (is_rtc_reset) { entry->due_time = new_time + ((entry->due_time - new_time) % base_info->mode.u_interval.interval); LOGE("[ RTC reset]: new time %s %ld, diff %f, id %d duetime %s %ld %ld", @@ -658,6 +658,12 @@ static void __alarm_update_due_time_of_all_items_in_list(time_t new_time, double _alarm_set_next_duetime(entry); } + if (is_rtc_reset) { + is_rtc_reset = false; + LOGW("RTC RESET -> RTC Normal"); + _save_module_log("[RTC NORMAL]", "RTC RESET -> NORMAL"); + } + time(¤t_time); for (iter = alarm_context.alarms; iter != NULL;) { @@ -3121,7 +3127,7 @@ void _alarm_initialize() #if !(GLIB_CHECK_VERSION(2, 36, 0)) g_type_init(); #endif - + time_t latest_settime; //For debug int expire_mode = ALARM_EXPIRE_MODE_NORMAL; vconf_get_int(VCONFKEY_ALARM_EXPIRE_MODE, &expire_mode); @@ -3166,6 +3172,16 @@ void _alarm_initialize() LOGE("power saving mode init failed"); exit(1); } + + if (_get_latest_settime(&latest_settime)) { + time_t current_time; + time(¤t_time); + if (current_time < latest_settime) { + LOGE("[RTC_RESET] RTC goes back into the past."); + _save_module_log("FAIL: RTC_RESET", "RTC goes back into the past."); + is_rtc_reset = true; + } + } } __initialize_alarm_list(); |