X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=alarm-manager.c;h=951b96baf31308d858ea66dc117a4e709f60b917;hb=refs%2Fheads%2Ftizen_2.1;hp=70cfe46740ccc304d96c3bfa47a800ca56dcce4e;hpb=6bbd514a7c41a2b3613e573dba99c5893e1c4aa3;p=framework%2Fappfw%2Falarm-manager.git diff --git a/alarm-manager.c b/alarm-manager.c index 70cfe46..951b96b 100755 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -35,7 +35,10 @@ #include #include #include +#if !GLIB_CHECK_VERSION (2, 31, 0) #include +#else +#endif /*#include "global-gconf.h"*/ #include"alarm.h" @@ -51,8 +54,6 @@ #include #include -#include - #define SIG_TIMER 0x32 #define WAKEUP_ALARM_APP_ID "org.tizen.alarm.ALARM" /* alarm ui application's alarm's dbus_service name instead of 21 @@ -76,6 +77,10 @@ GSList *g_scheduled_alarm_list = NULL; GSList *g_expired_alarm_list = NULL; +#ifndef RTC_WKALM_BOOT_SET +#define RTC_WKALM_BOOT_SET _IOW('p', 0x80, struct rtc_wkalrm) +#endif + #ifdef __ALARM_BOOT bool enable_power_on_alarm; bool alarm_boot; @@ -129,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(); @@ -175,8 +181,8 @@ static void __rtc_set() } ALARM_MGR_LOG_PRINT("\n\nCurrent RTC date/time is %d-%d-%d, " - "%02d:%02d:%02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1, - rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min, + "%02d:%02d:%02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1, + rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec); ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d\n", \ @@ -197,8 +203,8 @@ static void __rtc_set() rtc_wk.pending = 0; ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is " - "%d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_mday, - rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900, + "%d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_mday, + rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec); retval = ioctl(fd, RTC_WKALM_SET, &rtc_wk); @@ -236,13 +242,11 @@ int _set_rtc_time(time_t _time) int fd1 = 0; int retval0 = 0; int retval1 = 0; - struct rtc_time rtc_tm; + struct rtc_time rtc_tm = { 0, }; const char *rtc0 = power_rtc; const char *rtc1 = default_rtc; - struct tm *_tm; - struct tm time_r; - int tapi_ret; - tapi_misc_time_zone_info_type info = { 0, }; + struct tm *_tm = NULL; + struct tm time_r = { 0, }; fd0 = open(rtc0, O_RDONLY); fd1 = open(rtc1, O_RDONLY); @@ -260,7 +264,7 @@ int _set_rtc_time(time_t _time) memset(&rtc_tm, 0, sizeof(struct rtc_time)); - _tm = gmtime_r(&_time, &time_r); + (void) gmtime_r(&_time, &time_r); /* Write the RTC time/date 2008:05:21 19:20:00 */ @@ -270,44 +274,30 @@ int _set_rtc_time(time_t _time) rtc_tm.tm_year = time_r.tm_year; rtc_tm.tm_hour = time_r.tm_hour; rtc_tm.tm_min = time_r.tm_min; - rtc_tm.tm_sec = 0; - + rtc_tm.tm_sec = time_r.tm_sec; + retval0 = ioctl(fd0, RTC_SET_TIME, &rtc_tm); if (retval0 == -1) { - close(fd0); + if (fd0 != -1) + close(fd0); ALARM_MGR_LOG_PRINT("error to ioctl fd0."); perror("\t"); } - close(fd0); + if (fd0 != -1) + close(fd0); retval1 = ioctl(fd1, RTC_SET_TIME, &rtc_tm); if (retval1 == -1) { - close(fd1); + if (fd1 != -1) + close(fd1); ALARM_MGR_LOG_PRINT("error to ioctl fd1."); perror("\t"); } - close(fd1); - - /* set modem */ - info.time_zone_valid = TAPI_MISC_NITZ_RTC_BKUP_PHONE; - info.year = time_r.tm_year; - info.month = time_r.tm_mon; - info.day = time_r.tm_mday; - info.hour = time_r.tm_hour; - info.minute = time_r.tm_min; - info.second = 0; - ALARM_MGR_LOG_PRINT("***********Set timezone info*********\n"); - ALARM_MGR_LOG_PRINT("***********info.year:%d\t*********\n", info.year); - ALARM_MGR_LOG_PRINT("***********info.month:%d\t*********\n", - info.month); - ALARM_MGR_LOG_PRINT("***********info.day:%d\t*********\n", info.day); - ALARM_MGR_LOG_PRINT("***********info.hour:%d\t*********\n", info.hour); - ALARM_MGR_LOG_PRINT("***********info.minute:%d\t*********\n", - info.minute); - tapi_ret = tel_set_misc_timezone_info(&info); + if (fd1 != -1) + close(fd1); return 1; } @@ -359,7 +349,7 @@ static bool __alarm_add_to_list(__alarm_info_t *__alarm_info, for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) { entry = iter->data; - /*ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n", + /*ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n", entry->alarm_id); */ } @@ -513,12 +503,12 @@ static bool alarm_get_tz_info(int *gmt_idx, int *dst) GConfValue *value1 = NULL; GConfValue *value2 = NULL; GConfClient* gConfClient = NULL; - GError* err = NULL; - + GError* err = NULL; + gConfClient = gconf_client_get_default(); if(gConfClient) { - value1 = gconf_client_get(gConfClient, SETTINGS_CLOCKTIMEZONE, + value1 = gconf_client_get(gConfClient, SETTINGS_CLOCKTIMEZONE, &err); if (err) { ALARM_MGR_LOG_PRINT("__on_system_time_changed: @@ -529,8 +519,8 @@ static bool alarm_get_tz_info(int *gmt_idx, int *dst) } *gmt_idx = gconf_value_get_int(value1); ALARM_MGR_LOG_PRINT("gconf return gmt_idx =%d\n ", *gmt_idx); - - value2 = gconf_client_get(gConfClient, + + value2 = gconf_client_get(gConfClient, SETTINGS_DAYLIGHTSTATUS, &err); if (err) { ALARM_MGR_LOG_PRINT("__on_system_time_changed: @@ -538,10 +528,10 @@ static bool alarm_get_tz_info(int *gmt_idx, int *dst) g_error_free(err); err = NULL; } - + *dst = gconf_value_get_int(value2); ALARM_MGR_LOG_PRINT("gconf return dst =%d\n ", *dst); - + if(gConfClient != NULL) { g_object_unref(gConfClient); gConfClient = NULL; @@ -549,7 +539,7 @@ static bool alarm_get_tz_info(int *gmt_idx, int *dst) } else ALARM_MGR_LOG_PRINT("check the gconf setting failed!!!!! \n "); - + if(value1) { gconf_value_free(value1); value1 = NULL; @@ -572,7 +562,7 @@ 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 ; + struct tm fixed_time = { 0, }; for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) { @@ -583,7 +573,7 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time) entry->due_time += diff_time; - alarm_date_t *start = &alarm_info->start; /**< start + alarm_date_t *start = &alarm_info->start; /**< start time of the alarm */ alarm_date_t *end = &alarm_info->end;; /**< end time of the alarm */ @@ -602,7 +592,7 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time) 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; @@ -640,7 +630,7 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time) ALARM_MGR_LOG_PRINT("alarm[%d] with duetime(%u) at " "current(%u)\n", entry->alarm_id, due_time, current_time); - if (due_time == 0) { /* 0 means this alarm has been + if (due_time == 0) { /* 0 means this alarm has been disabled */ continue; } @@ -688,7 +678,7 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id if (__alarm_info == NULL) { ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc " "failed. it seems to be OOM\n", pid); - *error_code = -1; /* -1 means that system + *error_code = -1; /* -1 means that system failed internally. */ return false; } @@ -703,7 +693,15 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id snprintf(proc_file, 512, "/proc/%d/cmdline", pid); fd = open(proc_file, O_RDONLY); - if (fd > 0) { + if (fd < 0) { /* failure */ + ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " + "killed, so we failed to get proc file(%s) and do not create " + "alarm_info\n", pid, proc_file); + *error_code = -1; /*-1 means that system failed + internally.*/ + free(__alarm_info); + return false; + } else { ret = read(fd, process_name, 512); close(fd); if (ret <=0) @@ -729,31 +727,19 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id } __alarm_info->quark_app_unique_name = g_quark_from_string(app_name); - } else { /* failure */ - ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " - "killed, so we failed to get proc file(%s) and do not create " - "alarm_info\n", pid, proc_file); - *error_code = -1; /*-1 means that system failed - internally.*/ - free(__alarm_info); - return false; } __alarm_info->quark_bundle=g_quark_from_string(bundle_data); __alarm_info->quark_app_service_name = g_quark_from_string("null"); __alarm_info->quark_dst_service_name = g_quark_from_string("null"); + __alarm_info->quark_app_service_name_mod = g_quark_from_string("null"); + __alarm_info->quark_dst_service_name_mod = g_quark_from_string("null"); __alarm_set_start_and_end_time(alarm_info, __alarm_info); memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t)); time(¤t_time); - ALARM_MGR_LOG_PRINT("[alarm-server]:pid=%d, app_unique_name=%s, " - "app_bundle_encoded_val=%s,c_due_time=%d", \ - pid, g_quark_to_string(__alarm_info->quark_app_unique_name), \ - g_quark_to_string(__alarm_info->quark_bundle), \ - alarm_context.c_due_time); - if (alarm_context.c_due_time < current_time) { ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time " "(%d) is less than current time(%d)", alarm_context.c_due_time, @@ -836,7 +822,7 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, if (__alarm_info == NULL) { ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc " "failed. it seems to be OOM\n", pid); - *error_code = -1; /* -1 means that system + *error_code = -1; /* -1 means that system failed internally. */ return false; } @@ -853,7 +839,17 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, int ret; int i = 0; fd = open(proc_file, O_RDONLY); - if (fd > 0) { + if (fd < 0) { /* failure */ + __alarm_info->quark_app_unique_name = + g_quark_from_string("unknown"); + ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " + "killed, so we failed to get proc file(%s) and do not create " + "alarm_info\n", pid, proc_file); + *error_code = -1; /*-1 means that system failed + internally.*/ + free(__alarm_info); + return false; + } else { ret = read(fd, process_name, 512); close(fd); while (process_name[i] != '\0') { @@ -874,17 +870,6 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, } __alarm_info->quark_app_unique_name = g_quark_from_string(app_name); - } else { /* failure */ - - __alarm_info->quark_app_unique_name = - g_quark_from_string("unknown"); - ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " - "killed, so we failed to get proc file(%s) and do not create " - "alarm_info\n", pid, proc_file); - *error_code = -1; /*-1 means that system failed - internally.*/ - free(__alarm_info); - return false; } __alarm_info->quark_app_service_name = @@ -967,7 +952,7 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, /*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 + * 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); @@ -989,7 +974,7 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id, if (__alarm_info == NULL) { ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, " "malloc failed. it seems to be OOM\n", pid); - *error_code = -1; /*-1 means that system failed + *error_code = -1; /*-1 means that system failed internally.*/ return false; } @@ -1021,8 +1006,8 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id, "(%d) does not exist. so this value is invalid id.", alarm_id); return false; } - /* ALARM_MGR_LOG_PRINT("[alarm-server]:request_pid=%d, alarm_id=%d, - * app_unique_name=%s, app_service_name=%s, dst_service_name=%s, + /* ALARM_MGR_LOG_PRINT("[alarm-server]:request_pid=%d, alarm_id=%d, + * app_unique_name=%s, app_service_name=%s, dst_service_name=%s, * c_due_time=%d", pid, alarm_id, g_quark_to_string * (__alarm_info->quark_app_unique_name), g_quark_to_string * (__alarm_info->quark_app_service_name), g_quark_to_string @@ -1044,7 +1029,7 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id, #ifdef __ALARM_BOOT /*alarm boot */ if (enable_power_on_alarm) { - /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in + /* 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) */ @@ -1073,6 +1058,7 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id, return true; }else if (difftime(due_time, current_time)< 0){ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time); + free(__alarm_info); return true; } else { char due_time_r[100] = { 0 }; @@ -1106,13 +1092,14 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id, #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 + /* 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 + free(__alarm_info); return true; } @@ -1143,8 +1130,8 @@ static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code) #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 + /* 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); @@ -1159,9 +1146,8 @@ static bool __alarm_power_on(int app_id, bool on_off, int *error_code) #ifdef __ALARM_BOOT time_t min_time = 0; time_t current_time = 0; - struct tm *temp_info; struct rtc_time rtc_tm = { 0, }; - struct tm min_time_r; + struct tm min_time_r = { 0, }; int fd = 0; int retval; @@ -1186,7 +1172,7 @@ static bool __alarm_power_on(int app_id, bool on_off, int *error_code) if (min_time <= current_time) min_time = current_time + 5; - temp_info = gmtime_r(&min_time, &min_time_r); + gmtime_r(&min_time, &min_time_r); ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d " "%d\n", \ @@ -1212,7 +1198,7 @@ static bool __alarm_power_on(int app_id, bool on_off, int *error_code) /*set_info.time_zone = 0; */ /*set_info.u_interval.day_of_week = 0; */ - /*ALARM_MGR_LOG_PRINT("####__alarm_power_on : %d %d + /*ALARM_MGR_LOG_PRINT("####__alarm_power_on : %d %d %d %d %d\n",set_info.year,set_info.month,set_info.day, set_info.hour,set_info.minute); */ @@ -1221,7 +1207,7 @@ static bool __alarm_power_on(int app_id, bool on_off, int *error_code) ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is " "%d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1, - rtc_tm.tm_year + 1900, rtc_tm.tm_hour, + rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec); retval = ioctl(fd, RTC_ALM_SET, &rtc_tm); @@ -1331,12 +1317,12 @@ static void __alarm_send_noti_to_application(const char *app_service_name, dbus_message_set_no_reply(message, TRUE); /* if(service_name[0]==':') */ - /* we don't need auto activation in a case that + /* we don't need auto activation in a case that destination_app_service_name starts with a charactor like (:) */ dbus_message_set_auto_start(message, FALSE); dbus_message_iter_init_append(message, &iter); - if (!dbus_message_iter_append_basic + if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &alarm_id)) { dbus_message_unref(message); ALARM_MGR_EXCEPTION_PRINT("[alarm server] " @@ -1361,6 +1347,7 @@ static void __alarm_expired() char alarm_id_val[32]={0,}; int b_len = 0; bundle *b = NULL; + char *appid = NULL; ALARM_MGR_LOG_PRINT("[alarm-server]: Enter \n"); @@ -1371,11 +1358,16 @@ static void __alarm_expired() interval = difftime(alarm_context.c_due_time, current_time); ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), " - "current_time(%d), interval(%d)\n", alarm_context.c_due_time, + "current_time(%d), interval(%d)\n", alarm_context.c_due_time, current_time, interval); - if (alarm_context.c_due_time <= current_time - 1) { - ALARM_MGR_LOG_PRINT("Wrong alarm is expired\n"); + if (alarm_context.c_due_time > current_time) { + 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; } @@ -1407,21 +1399,29 @@ static void __alarm_expired() { snprintf(alarm_id_val,31,"%d",alarm_id); - if (bundle_add(b,"slp.alarm.data.ID", alarm_id_val)){ + if (bundle_add(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){ ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n"); } else { - if ( appsvc_run_service(b, 0, NULL, NULL) < 0) + appid = appsvc_get_appid(b); + if( (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_NOLAUNCH) && !aul_app_is_running(appid)) { - ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n"); + ALARM_MGR_EXCEPTION_PRINT("This alarm is ignored\n"); } else { - ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n"); - bundle_free(b); + if ( appsvc_run_service(b, 0, NULL, NULL) < 0) + { + ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n"); + } + else + { + ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n"); + } } } + bundle_free(b); } } @@ -1434,23 +1434,23 @@ static void __alarm_expired() "null, so we send expired alarm to %s(%u)\n",\ g_quark_to_string( __alarm_info->quark_app_service_name), - __alarm_info->quark_app_service_name); + __alarm_info->quark_app_service_name); destination_app_service_name = g_quark_to_string( __alarm_info->quark_app_service_name_mod); } else { ALARM_MGR_LOG_PRINT("[alarm-server]:destination " ":%s(%u)\n", g_quark_to_string( - __alarm_info->quark_dst_service_name), + __alarm_info->quark_dst_service_name), __alarm_info->quark_dst_service_name); destination_app_service_name = g_quark_to_string( __alarm_info->quark_dst_service_name_mod); } #ifdef __ALARM_BOOT - /* orginally this code had if(__alarm_info->app_id==21) in a + /* orginally this code had if(__alarm_info->app_id==21) in a platform with app-server. */ - /*if(__alarm_info->quark_dst_service_name == + /*if(__alarm_info->quark_dst_service_name == g_quark_from_string (WAKEUP_ALARM_APP_ID)) */ if (strcmp (g_quark_to_string(__alarm_info->quark_dst_service_name), @@ -1466,8 +1466,8 @@ static void __alarm_expired() } #endif - /* - * we should consider a situation that + /* + * we should consider a situation that * destination_app_service_name is owner_name like (:xxxx) and * application's pid which registered this alarm was killed.In that case, * we don't need to send the expire event because the process was killed. @@ -1476,24 +1476,30 @@ static void __alarm_expired() ALARM_MGR_LOG_PRINT("[alarm-server]: " "destination_app_service_name :%s, app_pid=%d\n", destination_app_service_name, app_pid); - /* the following is a code that checks the above situation. + /* the following is a code that checks the above situation. please verify this code. */ if (dbus_bus_name_has_owner( dbus_g_connection_get_connection(alarm_context.bus), destination_app_service_name, NULL) == FALSE) { __expired_alarm_t *expire_info; - char pkg_name[MAX_SERVICE_NAME_LEN] = { 0, }; + char appid[MAX_SERVICE_NAME_LEN] = { 0, }; char alarm_id_str[32] = { 0, }; + if (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_WITHCB) { + __alarm_remove_from_list(__alarm_info->pid, alarm_id, NULL); + goto done; + } + expire_info = malloc(sizeof(__expired_alarm_t)); if (G_UNLIKELY(NULL == expire_info)){ ALARM_MGR_ASSERT_PRINT("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n"); goto done; } + memset(expire_info, '\0', MAX_SERVICE_NAME_LEN); strncpy(expire_info->service_name, destination_app_service_name, - MAX_SERVICE_NAME_LEN); + MAX_SERVICE_NAME_LEN-1); expire_info->alarm_id = alarm_id; g_expired_alarm_list = g_slist_append(g_expired_alarm_list, expire_info); @@ -1502,22 +1508,22 @@ static void __alarm_expired() if (strncmp (g_quark_to_string(__alarm_info->quark_dst_service_name), "null",4) == 0) { - strncpy(pkg_name,g_quark_to_string(__alarm_info->quark_app_service_name),strlen(g_quark_to_string(__alarm_info->quark_app_service_name))-6); + strncpy(appid,g_quark_to_string(__alarm_info->quark_app_service_name),strlen(g_quark_to_string(__alarm_info->quark_app_service_name))-6); } else { - strncpy(pkg_name,g_quark_to_string(__alarm_info->quark_dst_service_name),strlen(g_quark_to_string(__alarm_info->quark_dst_service_name))-6); + strncpy(appid,g_quark_to_string(__alarm_info->quark_dst_service_name),strlen(g_quark_to_string(__alarm_info->quark_dst_service_name))-6); } snprintf(alarm_id_str, 31, "%d", alarm_id); - ALARM_MGR_LOG_PRINT("before aul_launch pkg_name(%s) " - "alarm_id_str(%s)\n", pkg_name, alarm_id_str); + ALARM_MGR_LOG_PRINT("before aul_launch appid(%s) " + "alarm_id_str(%s)\n", appid, alarm_id_str); bundle *kb; kb = bundle_create(); bundle_add(kb, "__ALARM_MGR_ID", alarm_id_str); - aul_launch_app(pkg_name, kb); + aul_launch_app(appid, kb); bundle_free(kb); } else { ALARM_MGR_LOG_PRINT( @@ -1528,9 +1534,9 @@ static void __alarm_expired() } ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application\n"); -/* if( !(__alarm_info->alarm_info.alarm_type +/* if( !(__alarm_info->alarm_info.alarm_type & ALARM_TYPE_VOLATILE) ) { - __alarm_remove_from_list(__alarm_info->pid, + __alarm_remove_from_list(__alarm_info->pid, alarm_id, NULL); } else */ @@ -1574,8 +1580,8 @@ static gboolean __alarm_handler_idle() #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 + /* 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); @@ -1641,6 +1647,59 @@ static void __on_system_time_changed(keynode_t *node, void *data) alarm_context.c_due_time); _set_time(_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_system_time_external_changed(keynode_t *node, void *data) +{ + double diff_time; + time_t cur_time = 0; + + _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); + + // set rtc time only because the linux time is set externally + time(&cur_time); + _set_rtc_time(cur_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", @@ -1653,7 +1712,38 @@ static void __on_system_time_changed(keynode_t *node, void *data) 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 +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; + + _alarm_disable_timer(alarm_context); + + tzset(); + + ALARM_MGR_LOG_PRINT("[alarm-server] time zone has been changed\n"); + ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n", alarm_context.c_due_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); @@ -1663,6 +1753,135 @@ this value to 0(zero) } +gboolean alarm_manager_alarm_set_rtc_time(void *pObject, int pid, + int year, int mon, int day, + int hour, int min, int sec, char *e_cookie, + int *return_code){ + guchar *cookie = NULL; + gsize size; + int retval = 0; + gboolean result = true; + gid_t call_gid; + + const char *rtc = power_rtc; + int fd = 0; + struct rtc_time rtc_tm = {0,}; + struct rtc_wkalrm rtc_wk; + struct tm *alarm_tm = NULL; + struct tm due_tm = {0,}; + + + if (return_code){ + *return_code = ALARMMGR_RESULT_SUCCESS; + } + + cookie = g_base64_decode(e_cookie, &size); + if (NULL == cookie) + { + if (return_code) + *return_code = ERR_ALARM_NO_PERMISSION; + ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n"); + return true; + } + + call_gid = security_server_get_gid("alarm"); + + ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid); + + retval = security_server_check_privilege((const char *)cookie, call_gid); + if (retval < 0) { + if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { + ALARM_MGR_EXCEPTION_PRINT( + "%s", "access has been denied\n"); + } + ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n"); + if (return_code) + *return_code = ERR_ALARM_NO_PERMISSION; + } + else { + + /*extract day of the week, day in the year & + daylight saving time from system*/ + time_t ctime; + ctime = time(NULL); + alarm_tm = localtime(&ctime); + + alarm_tm->tm_year = year; + alarm_tm->tm_mon = mon; + alarm_tm->tm_mday = day; + alarm_tm->tm_hour = hour; + alarm_tm->tm_min = min; + alarm_tm->tm_sec = sec; + + /*convert to calendar time representation*/ + time_t rtc_time = mktime(alarm_tm); + + /*convert to Coordinated Universal Time (UTC)*/ + gmtime_r(&rtc_time, &due_tm); + + fd = open(rtc, O_RDONLY); + if (fd == -1) { + ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n"); + if (return_code) + *return_code = ERR_ALARM_SYSTEM_FAIL; + return result; + } + + /* Read the RTC time/date */ + retval = ioctl(fd, RTC_RD_TIME, &rtc_tm); + if (retval == -1) { + ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed"); + close(fd); + if (return_code) + *return_code = ERR_ALARM_SYSTEM_FAIL; + return result; + } + + rtc_tm.tm_mday = due_tm.tm_mday; + rtc_tm.tm_mon = due_tm.tm_mon; + rtc_tm.tm_year = due_tm.tm_year; + rtc_tm.tm_hour = due_tm.tm_hour; + rtc_tm.tm_min = due_tm.tm_min; + rtc_tm.tm_sec = due_tm.tm_sec; + + memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm)); + + rtc_wk.enabled = 1; + rtc_wk.pending = 0; + + retval = ioctl(fd, RTC_WKALM_BOOT_SET, &rtc_wk); + if (retval == -1) { + if (errno == ENOTTY) { + ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not" + "supported.\n"); + } + ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl"); + close(fd); + if (return_code) + *return_code = ERR_ALARM_SYSTEM_FAIL; + } + else{ + ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted"); + /* Enable alarm interrupts */ + retval = ioctl(fd, RTC_AIE_ON, 0); + if (retval == -1) { + ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed"); + if (return_code) + *return_code = ERR_ALARM_SYSTEM_FAIL; + } + close(fd); + } + } + + if (cookie){ + g_free(cookie); + cookie = NULL; + } + + return result; + +} + gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid, int start_year, int start_month, int start_day, @@ -1707,7 +1926,7 @@ gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid, ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n"); return false; } - + call_gid = security_server_get_gid("alarm"); ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid); @@ -1895,7 +2114,7 @@ gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid, int *return_code) { GSList *gs_iter = NULL; - GQuark quark_app_unique_name; /* the fullpath of pid(pid) is + GQuark quark_app_unique_name; /* the fullpath of pid(pid) is converted to quark value. */ char proc_file[256] = { 0 }; char process_name[512] = { 0 }; @@ -1917,7 +2136,17 @@ gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid, int ret; int i = 0; fd = open(proc_file, O_RDONLY); - if (fd > 0) { + if (fd < 0) { /* failure */ + quark_app_unique_name = g_quark_from_string("unknown"); + memcpy(app_name, "unknown", strlen("unknown") + 1); + + ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " + "killed, so we failed to get proc file(%s) \n", + pid, proc_file); + *return_code = -1; /* -1 means that system + failed internally. */ + return true; + } else { ret = read(fd, process_name, 512); close(fd); while (process_name[i] != '\0') { @@ -1937,17 +2166,6 @@ gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid, word = strtok_r(NULL, "/", &proc_name_ptr); } quark_app_unique_name = g_quark_from_string(app_name); - } else { /* failure */ - - quark_app_unique_name = g_quark_from_string("unknown"); - memcpy(app_name, "unknown", strlen("unknown") + 1); - - ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " - "killed, so we failed to get proc file(%s) \n", - pid, proc_file); - *return_code = -1; /* -1 means that system - failed internally. */ - return true; } ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n", @@ -2017,7 +2235,16 @@ gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid, snprintf(proc_file, 256, "/proc/%d/cmdline", pid); fd = open(proc_file, O_RDONLY); - if (fd > 0) { + if (fd < 0) { /* failure */ + quark_app_unique_name = g_quark_from_string("unknown"); + memcpy(app_name, "unknown", strlen("unknown") + 1); + + ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " + "killed, so we failed to get proc file(%s)\n", pid, proc_file); + *return_code = -1; + /* -1 means that system failed internally. */ + return true; + } else { ret = read(fd, process_name, 512); close(fd); while (process_name[i] != '\0') { @@ -2037,16 +2264,6 @@ gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid, word = strtok_r(NULL, "/", &proc_name_ptr); } quark_app_unique_name = g_quark_from_string(app_name); - } else { /* failure */ - - quark_app_unique_name = g_quark_from_string("unknown"); - memcpy(app_name, "unknown", strlen("unknown") + 1); - - ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be " - "killed, so we failed to get proc file(%s)\n", pid, proc_file); - *return_code = -1; - /* -1 means that system failed internally. */ - return true; } ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n", @@ -2070,6 +2287,81 @@ gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid, return true; } +gboolean alarm_manager_alarm_get_appsvc_info(void *pObject, int pid, alarm_id_t alarm_id, + char *e_cookie, gchar **b_data, int *return_code) +{ + bool found = false; + + GSList *gs_iter = NULL; + __alarm_info_t *entry = NULL; + + guchar *cookie = NULL; + gsize size; + int retval = 0; + gid_t call_gid; + + ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid, + alarm_id); + + cookie = g_base64_decode(e_cookie, &size); + if (NULL == cookie) + { + if (return_code) + *return_code = ERR_ALARM_SYSTEM_FAIL; + ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n"); + return true; + } + call_gid = security_server_get_gid("alarm"); + + ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid); + + retval = security_server_check_privilege((const char *)cookie, call_gid); + if (retval < 0) { + if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) { + ALARM_MGR_EXCEPTION_PRINT( + "%s", "access has been denied\n"); + } + ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n"); + + if (return_code) + *return_code = ERR_ALARM_NO_PERMISSION; + + if (cookie) + g_free(cookie); + + return true; + } + + if (return_code) + *return_code = 0; + + for (gs_iter = alarm_context.alarms; gs_iter != NULL; + gs_iter = g_slist_next(gs_iter)) { + entry = gs_iter->data; + if (entry->alarm_id == alarm_id) { + found = true; + *b_data = g_strdup(g_quark_to_string(entry->quark_bundle)); + break; + } + } + + if (found) { + if ( *b_data && strlen(*b_data) == 4 && strncmp(*b_data,"null",4) == 0){ + ALARM_MGR_EXCEPTION_PRINT("Regular alarm,not svc alarm"); + if (return_code) + *return_code = ERR_ALARM_INVALID_TYPE; + } + } else { + if (return_code) + *return_code = ERR_ALARM_INVALID_ID; + } + + if (cookie) + g_free(cookie); + + return true; +} + gboolean alarm_manager_alarm_get_info(void *pObject, int pid, alarm_id_t alarm_id, int *start_year, int *start_month, int *start_day, @@ -2102,7 +2394,7 @@ gboolean alarm_manager_alarm_get_info(void *pObject, int pid, { ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n", alarm_id); - *return_code = ERR_ALARM_INVALID_PARAM; /*TODO: ERR_ALARM_INVALID_ID?*/ + *return_code = ERR_ALARM_INVALID_ID; } else { ALARM_MGR_LOG_PRINT("alarm was found\n"); *start_year = alarm_info->start.year; @@ -2190,7 +2482,7 @@ static void __initialize_alarm_list() /*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 + * 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); @@ -2216,7 +2508,7 @@ static void __hibernation_leave_callback() static bool __initialize_noti() { - + int ret = -1; int fd = heynoti_init(); if (fd < 0) { ALARM_MGR_EXCEPTION_PRINT("fail to heynoti_init\n"); @@ -2224,7 +2516,10 @@ static bool __initialize_noti() } heynoti_subscribe(fd, "HIBERNATION_LEAVE", __hibernation_leave_callback, NULL); - heynoti_attach_handler(fd); + ret = heynoti_attach_handler(fd); + if(ret<0) { + ALARM_MGR_EXCEPTION_PRINT("heynoti_attach_handler fail"); + } if (vconf_notify_key_changed (VCONFKEY_SYSTEM_TIMECHANGE, __on_system_time_changed, NULL) < 0) { @@ -2233,6 +2528,18 @@ static bool __initialize_noti() } /*system state change 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 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; } @@ -2407,7 +2714,7 @@ static bool __initialize_db() sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL,\ &error_message)) { ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, " - "error message = %s\n", QUERY_CREATE_TABLE_ALARMMGR, + "error message = %s\n", QUERY_CREATE_TABLE_ALARMMGR, error_message); return false; } @@ -2462,7 +2769,7 @@ static void __initialize() close(fd2); __initialize_timer(); - if (__initialize_dbus() == false) { /* because dbus's initialize + if (__initialize_dbus() == false) { /* because dbus's initialize failed, we cannot continue any more. */ ALARM_MGR_EXCEPTION_PRINT("because __initialize_dbus failed, " "alarm-server cannot be runned.\n");