From b4b609cb1ebcb12a832511b28d3ddef8c7a57029 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 24 Oct 2016 13:15:00 +0900 Subject: [PATCH] Fix bug in relative type & once alarm - Timer is not expired when duetime is duplicated time as DST Change-Id: I6d7284a5e8cd93c8163e88d82c446c0457710931 Signed-off-by: Jiwoong Im --- alarm-manager-schedule.c | 7 ++++++ alarm-manager.c | 57 ++++++++++++++++++++++++------------------------ include/alarm-internal.h | 2 +- src/alarm-lib.c | 3 +++ 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/alarm-manager-schedule.c b/alarm-manager-schedule.c index da14495..3f5e844 100644 --- a/alarm-manager-schedule.c +++ b/alarm-manager-schedule.c @@ -149,6 +149,13 @@ static time_t __alarm_next_duetime_once(__alarm_info_t *__alarm_info) struct tm tmp_tm; int current_dst = 0; + if ((__alarm_info->alarm_info.alarm_type & ALARM_TYPE_RELATIVE) && __alarm_info->start != 0) + { + ALARM_MGR_EXCEPTION_PRINT("Final due_time = %d, %s", + __alarm_info->start, ctime(&__alarm_info->start)); + return __alarm_info->start; + } + alarm_info_t *alarm_info = &__alarm_info->alarm_info; alarm_date_t *start = &alarm_info->start; diff --git a/alarm-manager.c b/alarm-manager.c index ba6924e..9ed2047 100644 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -485,16 +485,20 @@ static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info, struct tm alarm_tm = { 0, }; if (start->year != 0) { - alarm_tm.tm_year = start->year - 1900; - alarm_tm.tm_mon = start->month - 1; - alarm_tm.tm_mday = start->day; + if ((alarm_info->alarm_type & ALARM_TYPE_RELATIVE) && alarm_info->reserved_info != 0) { + __alarm_info->start = alarm_info->reserved_info; + } else { + alarm_tm.tm_year = start->year - 1900; + alarm_tm.tm_mon = start->month - 1; + alarm_tm.tm_mday = start->day; - alarm_tm.tm_hour = start->hour; - alarm_tm.tm_min = start->min; - alarm_tm.tm_sec = start->sec; - alarm_tm.tm_isdst = -1; + alarm_tm.tm_hour = start->hour; + alarm_tm.tm_min = start->min; + alarm_tm.tm_sec = start->sec; + alarm_tm.tm_isdst = -1; - __alarm_info->start = mktime(&alarm_tm); + __alarm_info->start = mktime(&alarm_tm); + } } else { __alarm_info->start = 0; } @@ -607,7 +611,6 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time) __alarm_info_t *entry = NULL; struct tm *p_time = NULL ; struct tm due_time_result ; - struct tm fixed_time = { 0, }; is_time_changed = true; tzset(); @@ -628,26 +631,23 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time) start->hour = p_time->tm_hour; start->min = p_time->tm_min; start->sec = p_time->tm_sec; - - end->year = p_time->tm_year + 1900; - end->month = p_time->tm_mon + 1; - end->day = p_time->tm_mday; - - memset(&fixed_time, 0, sizeof(fixed_time)); - fixed_time.tm_year = p_time->tm_year; - fixed_time.tm_mon = p_time->tm_mon; - fixed_time.tm_mday = p_time->tm_mday; - fixed_time.tm_hour = 0; - fixed_time.tm_min = 0; - fixed_time.tm_sec = 0; } - entry->start = mktime(&fixed_time); - - fixed_time.tm_hour = 23; - fixed_time.tm_min = 59; - fixed_time.tm_sec = 59; + if (entry->start != 0) { + entry->start = entry->due_time; + } - entry->end = mktime(&fixed_time); + if (entry->end != 0) { + entry->end += diff_time; + p_time = localtime_r(&entry->end, &due_time_result); + if (p_time != NULL) { + end->year = p_time->tm_year + 1900; + end->month = p_time->tm_mon + 1; + end->day = p_time->tm_mday; + end->hour = p_time->tm_hour; + end->min = p_time->tm_min; + end->sec = p_time->tm_sec; + } + } } _alarm_next_duetime(entry); } @@ -2453,6 +2453,8 @@ gboolean alarm_manager_alarm_create_periodic(AlarmManager *obj, GDBusMethodInvoc time_t standard_time = _get_periodic_alarm_standard_time(); localtime_r(&standard_time, &standard_tm); + alarm_info.reserved_info = standard_time; + alarm_info.start.year = standard_tm.tm_year + 1900; alarm_info.start.month = standard_tm.tm_mon + 1; alarm_info.start.day = standard_tm.tm_mday; @@ -2468,7 +2470,6 @@ gboolean alarm_manager_alarm_create_periodic(AlarmManager *obj, GDBusMethodInvoc alarm_info.alarm_type |= ALARM_TYPE_RELATIVE; alarm_info.alarm_type |= ALARM_TYPE_WITHCB; alarm_info.alarm_type |= ALARM_TYPE_PERIOD; - alarm_info.reserved_info = 0; if (interval <= 0) { alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE; diff --git a/include/alarm-internal.h b/include/alarm-internal.h index 3928eb8..18231b3 100644 --- a/include/alarm-internal.h +++ b/include/alarm-internal.h @@ -127,7 +127,7 @@ typedef struct { alarm_date_t end; /**< end time of the alarm */ alarm_mode_t mode; /**< mode of alarm */ int alarm_type; /**< alarm type*/ - int reserved_info; + int reserved_info; /** 1st duetime(UTC epochtime) */ } alarm_info_t; bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm, diff --git a/src/alarm-lib.c b/src/alarm-lib.c index 3c81e44..a4016da 100644 --- a/src/alarm-lib.c +++ b/src/alarm-lib.c @@ -1027,6 +1027,7 @@ EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time, } else { current_time.tv_sec += trigger_at_time; } + alarm_info.reserved_info = current_time.tv_sec; tzset(); /* Processes the TZ environment variable, and Set timezone, daylight, and tzname. */ localtime_r(¤t_time.tv_sec, &duetime_tm); @@ -1109,6 +1110,7 @@ EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time, } else { current_time.tv_sec += trigger_at_time; } + alarm_info.reserved_info = current_time.tv_sec; tzset(); /* Processes the TZ environment variable, and Set timezone, daylight, and tzname. */ localtime_r(¤t_time.tv_sec, &duetime_tm); @@ -1208,6 +1210,7 @@ EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time, } else { current_time.tv_sec += trigger_at_time; } + alarm_info.reserved_info = current_time.tv_sec; tzset(); /* Processes the TZ environment variable, and Set timezone, daylight, and tzname. */ localtime_r(¤t_time.tv_sec, &duetime_tm); -- 2.7.4