From 3aedc953dccdaffbbd4cd378c4fcc8a3ed2943ad Mon Sep 17 00:00:00 2001 From: SeungYeup Kim Date: Wed, 17 Apr 2013 18:43:19 +0900 Subject: [PATCH] Support external time change --- alarm-manager.c | 60 ++++++++++++++++++++++++++++++++++++++++++-- packaging/alarm-manager.spec | 5 ++-- 2 files changed, 61 insertions(+), 4 deletions(-) mode change 100644 => 100755 packaging/alarm-manager.spec diff --git a/alarm-manager.c b/alarm-manager.c index f65e23c..c0d6a46 100755 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -134,6 +134,7 @@ static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext); static void __clean_registry(); static bool __alarm_manager_reset(); static void __on_system_time_changed(keynode_t *node, void *data); +static void __on_system_time_external_changed(keynode_t *node, void *data); static void __initialize_timer(); static void __initialize_alarm_list(); static void __initialize_scheduled_alarm_lsit(); @@ -1361,7 +1362,12 @@ static void __alarm_expired() current_time, interval); if (alarm_context.c_due_time > current_time) { - ALARM_MGR_LOG_PRINT("[alarm-server]: False Alarm\n"); + ALARM_MGR_LOG_PRINT("[alarm-server]: False Alarm (time changed to past)\n"); + goto done; + } + // 3 seconds is maximum permitted delay from timer expire to this function + if (alarm_context.c_due_time + 3 < current_time) { + ALARM_MGR_LOG_PRINT("[alarm-server]: False Alarm (time changed to future)\n"); goto done; } @@ -1661,6 +1667,50 @@ this value to 0(zero) return; } +static void __on_system_time_external_changed(keynode_t *node, void *data) +{ + double diff_time; + + _alarm_disable_timer(alarm_context); + + if (node) { + diff_time = vconf_keynode_get_dbl(node); + } else { + vconf_get_dbl(VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, &diff_time); + } + + tzset(); + + ALARM_MGR_ASSERT_PRINT("diff_time is %f\n", diff_time); + + ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed externally\n"); + ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n", + alarm_context.c_due_time); + + vconf_set_dbl(VCONFKEY_SYSTEM_TIMEDIFF, diff_time); + vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time); + + __alarm_update_due_time_of_all_items_in_list(diff_time); + + ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n", + alarm_context.c_due_time); + _clear_scheduled_alarm_list(); + _alarm_schedule(); + __rtc_set(); +#ifdef __ALARM_BOOT + /*alarm boot */ + if (enable_power_on_alarm) { +/* orginally first arg's value was 21(app_id, WAKEUP_ALARM_ +APP_ID) in a platform with app-server. because _alarm_power_ +on(..) fuction don't use first parameter internally, we set +this value to 0(zero) +*/ + __alarm_power_on(0, enable_power_on_alarm, NULL); + } +#endif + return; +} + static void __on_time_zone_changed(keynode_t *node, void *data) { double diff_time = 0; @@ -2471,7 +2521,13 @@ static bool __initialize_noti() if (vconf_notify_key_changed (VCONFKEY_SETAPPL_TIMEZONE_ID, __on_time_zone_changed, NULL) < 0) { ALARM_MGR_LOG_PRINT( - "Failed to add callback for time changing event\n"); + "Failed to add callback for time zone changing event\n"); + } + + if (vconf_notify_key_changed + (VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, __on_system_time_external_changed, NULL) < 0) { + ALARM_MGR_LOG_PRINT( + "Failed to add callback for time external changing event\n"); } return true; diff --git a/packaging/alarm-manager.spec b/packaging/alarm-manager.spec old mode 100644 new mode 100755 index c71ee7d..e67a1b6 --- a/packaging/alarm-manager.spec +++ b/packaging/alarm-manager.spec @@ -1,6 +1,6 @@ Name: alarm-manager Summary: Alarm library -Version: 0.4.66 +Version: 0.4.67 Release: 1 Group: System/Libraries License: Apache License, Version 2.0 @@ -105,7 +105,8 @@ fi %post -n alarm-server /sbin/ldconfig -vconftool set -t int db/system/timechange 0 -i +vconftool set -t int db/system/timechange 0 +vconftool set -t double db/system/timechange_external 0 vconftool set -t int memory/system/timechanged 0 -i -g 5000 systemctl daemon-reload -- 2.7.4