4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
7 * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
25 #define _BSD_SOURCE /*for localtime_r*/
36 #include<dbus/dbus-glib-lowlevel.h>
38 #include <glib/gmacros.h>
40 /*#include "global-gconf.h"*/
42 #include"alarm-internal.h"
44 /*#include"limo-event-delivery.h"*/
49 #include <security-server.h>
52 #include <vconf-keys.h>
54 #include <ITapiMisc.h>
56 #define SIG_TIMER 0x32
57 #define WAKEUP_ALARM_APP_ID "org.tizen.alarm.ALARM"
58 /* alarm ui application's alarm's dbus_service name instead of 21
59 (alarm application's app_id) value */
60 #define WAKEUP_ALARMBOOTING_APP_ID "org.tizen.alarmboot.ui.ALARM"
61 /*alrmbooting ui application's dbus_service name instead of 121(alarmbooting
62 application's app_id) value */
64 #include "tapi_misc_ext.h"
66 #include "tapi_misc_data.h"
67 #include "tapi_power.h"
72 __alarm_server_context_t alarm_context;
73 bool g_dummy_timer_is_set = FALSE;
75 GSList *g_scheduled_alarm_list = NULL;
77 GSList *g_expired_alarm_list = NULL;
80 bool enable_power_on_alarm;
82 time_t ab_due_time = -1;
83 bool poweron_alarm_expired = false;
86 /* 2008. 6. 3 sewook7.park
87 When the alarm becoms sleeping mode, alarm timer is not expired.
88 So using RTC, phone is awaken before alarm rings.
90 #define __WAKEUP_USING_RTC__
91 #ifdef __WAKEUP_USING_RTC__
93 #include <linux/rtc.h>
94 #include <sys/ioctl.h>
97 static const char default_rtc[] = "/dev/rtc1";
98 static const char power_rtc[] = "/dev/rtc0";
100 #endif /*__WAKEUP_USING_RTC__*/
102 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info,
103 alarm_id_t *alarm_id);
104 static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
105 __alarm_info_t *__alarm_info,
107 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
109 static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
110 __alarm_info_t *__alarm_info);
111 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time);
112 static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
113 int pid, char *app_service_name, char *app_service_name_mod,
114 const char *dst_service_name, const char *dst_service_name_mod, int *error_code);
115 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
116 int pid, char *bundle_data, int *error_code);
118 static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code);
119 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
120 alarm_info_t *alarm_info, int *error_code);
121 static bool __alarm_power_on(int app_id, bool on_off, int *error_code);
122 static bool __alarm_power_off(int app_id, int *error_code);
123 static bool __alarm_check_next_duetime(int app_id, int *error_code);
124 static void __alarm_send_noti_to_application(const char *app_service_name,
125 alarm_id_t alarm_id);
126 static void __alarm_expired();
127 static gboolean __alarm_handler_idle();
128 static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext);
129 static void __clean_registry();
130 static bool __alarm_manager_reset();
131 static void __on_system_time_changed(keynode_t *node, void *data);
132 static void __initialize_timer();
133 static void __initialize_alarm_list();
134 static void __initialize_scheduled_alarm_lsit();
135 static void __hibernation_leave_callback();
136 static bool __initialize_noti();
138 static bool __initialize_dbus();
139 static bool __initialize_db();
140 static void __initialize();
141 static bool __check_false_alarm();
142 static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
143 DBusMessage *message,
146 static void __rtc_set()
148 #ifdef __WAKEUP_USING_RTC__
150 const char *rtc = default_rtc;
152 struct rtc_time rtc_tm;
153 struct rtc_wkalrm rtc_wk;
156 #ifdef _SIMUL /*if build is simulator, we don't need to set
157 RTC because RTC does not work in simulator.*/
158 ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, "
159 "we don't set RTC.\n");
163 fd = open(rtc, O_RDONLY);
165 ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
169 /* Read the RTC time/date */
170 int retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
172 ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed");
177 ALARM_MGR_LOG_PRINT("\n\nCurrent RTC date/time is %d-%d-%d, "
178 "%02d:%02d:%02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
179 rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min,
182 ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d\n", \
183 alarm_context.c_due_time);
185 if (alarm_context.c_due_time != -1) {
186 time_t due_time = alarm_context.c_due_time - 1;
187 gmtime_r(&due_time, &due_tm);
189 rtc_tm.tm_mday = due_tm.tm_mday;
190 rtc_tm.tm_mon = due_tm.tm_mon;
191 rtc_tm.tm_year = due_tm.tm_year;
192 rtc_tm.tm_hour = due_tm.tm_hour;
193 rtc_tm.tm_min = due_tm.tm_min;
194 rtc_tm.tm_sec = due_tm.tm_sec;
195 memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm));
199 ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
200 "%d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_mday,
201 rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,
202 rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
204 retval = ioctl(fd, RTC_WKALM_SET, &rtc_wk);
206 if (errno == ENOTTY) {
207 ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
210 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
214 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
216 /* Enable alarm interrupts */
217 retval = ioctl(fd, RTC_AIE_ON, 0);
219 ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed");
223 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is on");
225 ALARM_MGR_LOG_PRINT("[alarm-server]alarm_context.c_due_time is"
226 "less than 10 sec. RTC alarm does not need to be set\n");
230 #endif /* __WAKEUP_USING_RTC__ */
233 int _set_rtc_time(time_t _time)
239 struct rtc_time rtc_tm;
240 const char *rtc0 = power_rtc;
241 const char *rtc1 = default_rtc;
245 tapi_misc_time_zone_info_type info = { 0, };
247 fd0 = open(rtc0, O_RDONLY);
248 fd1 = open(rtc1, O_RDONLY);
251 ALARM_MGR_LOG_PRINT("error to open /dev/rtc0.");
256 ALARM_MGR_LOG_PRINT("error to open /dev/rtc1.");
260 memset(&rtc_tm, 0, sizeof(struct rtc_time));
263 _tm = gmtime_r(&_time, &time_r);
265 /* Write the RTC time/date 2008:05:21 19:20:00 */
268 rtc_tm.tm_mday = time_r.tm_mday;
269 rtc_tm.tm_mon = time_r.tm_mon;
270 rtc_tm.tm_year = time_r.tm_year;
271 rtc_tm.tm_hour = time_r.tm_hour;
272 rtc_tm.tm_min = time_r.tm_min;
276 retval0 = ioctl(fd0, RTC_SET_TIME, &rtc_tm);
280 ALARM_MGR_LOG_PRINT("error to ioctl fd0.");
285 retval1 = ioctl(fd1, RTC_SET_TIME, &rtc_tm);
289 ALARM_MGR_LOG_PRINT("error to ioctl fd1.");
295 info.time_zone_valid = TAPI_MISC_NITZ_RTC_BKUP_PHONE;
296 info.year = time_r.tm_year;
297 info.month = time_r.tm_mon;
298 info.day = time_r.tm_mday;
299 info.hour = time_r.tm_hour;
300 info.minute = time_r.tm_min;
302 ALARM_MGR_LOG_PRINT("***********Set timezone info*********\n");
303 ALARM_MGR_LOG_PRINT("***********info.year:%d\t*********\n", info.year);
304 ALARM_MGR_LOG_PRINT("***********info.month:%d\t*********\n",
306 ALARM_MGR_LOG_PRINT("***********info.day:%d\t*********\n", info.day);
307 ALARM_MGR_LOG_PRINT("***********info.hour:%d\t*********\n", info.hour);
308 ALARM_MGR_LOG_PRINT("***********info.minute:%d\t*********\n",
310 tapi_ret = tel_set_misc_timezone_info(&info);
315 bool __alarm_clean_list()
319 for (iter = alarm_context.alarms; iter != NULL;
320 iter = g_slist_next(iter)) {
324 g_slist_free(alarm_context.alarms);
328 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info,
329 alarm_id_t *alarm_id)
332 bool unique_id = false;
333 alarm_info_t *alarm_info = &__alarm_info->alarm_info;
334 __alarm_info_t *entry = NULL;
338 /* FIXME: alarm id must be unique. */
339 __alarm_info->alarm_id = (int)(void *)__alarm_info;
340 ALARM_MGR_LOG_PRINT("__alarm_info->alarm_id is %d", \
341 __alarm_info->alarm_id);
343 while (unique_id == false) {
346 for (iter = alarm_context.alarms; iter != NULL;
347 iter = g_slist_next(iter)) {
349 if (entry->alarm_id == __alarm_info->alarm_id) {
350 __alarm_info->alarm_id++;
358 ALARM_MGR_LOG_PRINT("[alarm-server]: before add\n");
359 for (iter = alarm_context.alarms; iter != NULL;
360 iter = g_slist_next(iter)) {
362 /*ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
366 alarm_context.alarms =
367 g_slist_append(alarm_context.alarms, __alarm_info);
369 ALARM_MGR_LOG_PRINT("[alarm-server]: after add\n");
370 for (iter = alarm_context.alarms; iter != NULL;
371 iter = g_slist_next(iter)) {
373 ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
377 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
378 _save_alarms(__alarm_info);
381 *alarm_id = __alarm_info->alarm_id;
386 static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
387 __alarm_info_t *__alarm_info,
391 alarm_info_t *alarm_info = &__alarm_info->alarm_info;
393 __alarm_info_t *entry = NULL;
395 for (iter = alarm_context.alarms; iter != NULL;
396 iter = g_slist_next(iter)) {
398 if (entry->alarm_id == alarm_id) {
401 __alarm_info->quark_app_unique_name =
402 entry->quark_app_unique_name;
403 __alarm_info->quark_dst_service_name =
404 entry->quark_dst_service_name;
405 memcpy(entry, __alarm_info, sizeof(__alarm_info_t));
413 *error_code = ERR_ALARM_INVALID_ID;
417 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
418 _update_alarms(__alarm_info);
424 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
429 alarm_info_t *alarm_info = NULL;
432 __alarm_info_t *entry = NULL;
435 ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)\n",
438 for (iter = alarm_context.alarms; iter != NULL;
439 iter = g_slist_next(iter)) {
441 if (entry->alarm_id == alarm_id) {
442 alarm_info = &entry->alarm_info;
444 ALARM_MGR_LOG_PRINT("[alarm-server]: "
445 "__alarm_remove_from_list : alarm id(%d)\n",
448 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
449 _delete_alarms(alarm_id);
452 alarm_context.alarms =
453 g_slist_remove(alarm_context.alarms, iter->data);
460 ALARM_MGR_LOG_PRINT("[alarm-server]: after del\n");
464 *error_code = ERR_ALARM_INVALID_ID;
471 static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
472 __alarm_info_t *__alarm_info)
474 alarm_date_t *start = &alarm_info->start;
475 alarm_date_t *end = &alarm_info->end;
477 struct tm alarm_tm = { 0, };
479 if (start->year != 0) {
480 alarm_tm.tm_year = start->year - 1900;
481 alarm_tm.tm_mon = start->month - 1;
482 alarm_tm.tm_mday = start->day;
484 alarm_tm.tm_hour = 0;
488 __alarm_info->start = mktime(&alarm_tm);
490 __alarm_info->start = 0;
493 if (end->year != 0) {
494 alarm_tm.tm_year = end->year - 1900;
495 alarm_tm.tm_mon = end->month - 1;
496 alarm_tm.tm_mday = end->day;
498 alarm_tm.tm_hour = 23;
499 alarm_tm.tm_min = 59;
500 alarm_tm.tm_sec = 59;
502 __alarm_info->end = mktime(&alarm_tm);
504 __alarm_info->end = 0;
511 static bool alarm_get_tz_info(int *gmt_idx, int *dst)
513 GConfValue *value1 = NULL;
514 GConfValue *value2 = NULL;
515 GConfClient* gConfClient = NULL;
518 gConfClient = gconf_client_get_default();
521 value1 = gconf_client_get(gConfClient, SETTINGS_CLOCKTIMEZONE,
524 ALARM_MGR_LOG_PRINT("__on_system_time_changed:
525 gconf_client_get() failed:
526 error:[%s]\n", err->message);
530 *gmt_idx = gconf_value_get_int(value1);
531 ALARM_MGR_LOG_PRINT("gconf return gmt_idx =%d\n ", *gmt_idx);
533 value2 = gconf_client_get(gConfClient,
534 SETTINGS_DAYLIGHTSTATUS, &err);
536 ALARM_MGR_LOG_PRINT("__on_system_time_changed:
537 gconf_client_get() failed: error:[%s]\n", err->message);
542 *dst = gconf_value_get_int(value2);
543 ALARM_MGR_LOG_PRINT("gconf return dst =%d\n ", *dst);
545 if(gConfClient != NULL) {
546 g_object_unref(gConfClient);
551 ALARM_MGR_LOG_PRINT("check the gconf setting failed!!!!! \n ");
554 gconf_value_free(value1);
558 gconf_value_free(value2);
566 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
569 time_t min_time = -1;
572 __alarm_info_t *entry = NULL;
573 struct tm *p_time = NULL ;
574 struct tm due_time_result ;
575 struct tm fixed_time ;
577 for (iter = alarm_context.alarms; iter != NULL;
578 iter = g_slist_next(iter)) {
580 alarm_info_t *alarm_info = &(entry->alarm_info);
581 if (alarm_info->alarm_type & ALARM_TYPE_RELATIVE) {
582 /*diff_time ó¸® */
584 entry->due_time += diff_time;
586 alarm_date_t *start = &alarm_info->start; /**< start
588 alarm_date_t *end = &alarm_info->end;;
589 /**< end time of the alarm */
592 p_time = localtime_r(&entry->due_time, &due_time_result);
593 if (p_time != NULL) {
594 start->year = p_time->tm_year + 1900;
595 start->month = p_time->tm_mon + 1;
596 start->day = p_time->tm_mday;
597 start->hour = p_time->tm_hour;
598 start->min = p_time->tm_min;
599 start->sec = p_time->tm_sec;
601 end->year = p_time->tm_year + 1900;
602 end->month = p_time->tm_mon + 1;
603 end->day = p_time->tm_mday;
606 memset(&fixed_time, 0, sizeof(fixed_time));
607 fixed_time.tm_year = p_time->tm_year;
608 fixed_time.tm_mon = p_time->tm_mon;
609 fixed_time.tm_mday = p_time->tm_mday;
610 fixed_time.tm_hour = 0;
611 fixed_time.tm_min = 0;
612 fixed_time.tm_sec = 0;
614 entry->start = mktime(&fixed_time);
616 fixed_time.tm_hour = 23;
617 fixed_time.tm_min = 59;
618 fixed_time.tm_sec = 59;
620 entry->end = mktime(&fixed_time);
622 ALARM_MGR_LOG_PRINT("alarm_info->alarm_type is "
623 "ALARM_TYPE_RELATIVE\n");
625 _update_alarms(entry);
628 _alarm_next_duetime(entry);
629 ALARM_MGR_LOG_PRINT("entry->due_time is %d\n", entry->due_time);
634 for (iter = alarm_context.alarms; iter != NULL;
635 iter = g_slist_next(iter)) {
637 due_time = entry->due_time;
641 ALARM_MGR_LOG_PRINT("alarm[%d] with duetime(%u) at "
642 "current(%u)\n", entry->alarm_id, due_time, current_time);
643 if (due_time == 0) { /* 0 means this alarm has been
648 interval = difftime(due_time, current_time);
651 ALARM_MGR_LOG_PRINT("this may be error.. alarm[%d]\n", \
656 interval = difftime(due_time, min_time);
658 if ((interval < 0) || min_time == -1) {
664 alarm_context.c_due_time = min_time;
669 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
670 int pid,char *bundle_data, int *error_code){
675 char due_time_r[100] = { 0 };
676 char proc_file[512] = { 0 };
677 char process_name[512] = { 0 };
678 char app_name[512] = { 0 };
680 char *proc_name_ptr = NULL;
685 __alarm_info_t *__alarm_info = NULL;
687 __alarm_info = malloc(sizeof(__alarm_info_t));
688 if (__alarm_info == NULL) {
689 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc "
690 "failed. it seems to be OOM\n", pid);
691 *error_code = -1; /* -1 means that system
692 failed internally. */
695 __alarm_info->pid = pid;
696 __alarm_info->alarm_id = -1;
699 /* we should consider to check whether pid is running or Not
701 memset(process_name, '\0', 512);
702 memset(proc_file, '\0', 512);
703 snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
705 fd = open(proc_file, O_RDONLY);
707 ret = read(fd, process_name, 512);
711 ALARM_MGR_EXCEPTION_PRINT("Unable to get application name\n");
716 while (process_name[i] != '\0') {
717 if (process_name[i] == ' ') {
718 process_name[i] = '\0';
724 word = strtok_r(process_name, "/", &proc_name_ptr);
725 while (word != NULL) {
726 memset(app_name, 0, 512);
727 snprintf(app_name, 512, "%s", word);
728 word = strtok_r(NULL, "/", &proc_name_ptr);
730 __alarm_info->quark_app_unique_name =
731 g_quark_from_string(app_name);
732 } else { /* failure */
733 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
734 "killed, so we failed to get proc file(%s) and do not create "
735 "alarm_info\n", pid, proc_file);
736 *error_code = -1; /*-1 means that system failed
742 __alarm_info->quark_bundle=g_quark_from_string(bundle_data);
743 __alarm_info->quark_app_service_name = g_quark_from_string("null");
744 __alarm_info->quark_dst_service_name = g_quark_from_string("null");
746 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
747 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
751 ALARM_MGR_LOG_PRINT("[alarm-server]:pid=%d, app_unique_name=%s, "
752 "app_bundle_encoded_val=%s,c_due_time=%d", \
753 pid, g_quark_to_string(__alarm_info->quark_app_unique_name), \
754 g_quark_to_string(__alarm_info->quark_bundle), \
755 alarm_context.c_due_time);
757 if (alarm_context.c_due_time < current_time) {
758 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
759 "(%d) is less than current time(%d)", alarm_context.c_due_time,
761 alarm_context.c_due_time = -1;
764 due_time = _alarm_next_duetime(__alarm_info);
765 if (__alarm_add_to_list(__alarm_info, alarm_id) == false) {
772 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
773 "due_time is 0, alarm(%d) \n", *alarm_id);
775 } else if (current_time == due_time) {
776 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
777 "current_time(%d) is same as due_time(%d)", current_time,
780 }else if (difftime(due_time, current_time) < 0){
781 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);
784 localtime_r(&due_time, &ts_ret);
785 strftime(due_time_r, 30, "%c", &ts_ret);
786 ALARM_MGR_LOG_PRINT("[alarm-server]:Create a new alarm: "
787 "alarm(%d) due_time(%s)", *alarm_id,
791 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
792 "due_time(%d)", alarm_context.c_due_time, due_time);
794 if (alarm_context.c_due_time == -1
795 || due_time < alarm_context.c_due_time) {
796 _clear_scheduled_alarm_list();
797 _add_to_scheduled_alarm_list(__alarm_info);
798 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
800 alarm_context.c_due_time = due_time;
802 } else if (due_time == alarm_context.c_due_time) {
803 _add_to_scheduled_alarm_list(__alarm_info);
811 if (enable_power_on_alarm) {
812 __alarm_power_on(0, enable_power_on_alarm, NULL);
820 static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
821 int pid, char *app_service_name, char *app_service_name_mod,
822 const char *dst_service_name,const char *dst_service_name_mod, int *error_code)
827 char proc_file[256] = { 0 };
828 char process_name[512] = { 0 };
829 char app_name[256] = { 0 };
831 char *proc_name_ptr = NULL;
833 __alarm_info_t *__alarm_info = NULL;
835 __alarm_info = malloc(sizeof(__alarm_info_t));
836 if (__alarm_info == NULL) {
837 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc "
838 "failed. it seems to be OOM\n", pid);
839 *error_code = -1; /* -1 means that system
840 failed internally. */
843 __alarm_info->pid = pid;
844 __alarm_info->alarm_id = -1;
846 /* we should consider to check whether pid is running or Not
848 memset(process_name, '\0', 512);
849 memset(proc_file, '\0', 256);
850 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
855 fd = open(proc_file, O_RDONLY);
857 ret = read(fd, process_name, 512);
859 while (process_name[i] != '\0') {
860 if (process_name[i] == ' ') {
861 process_name[i] = '\0';
866 /* if (readlink(proc_file, process_name, 256)!=-1) */
869 word = strtok_r(process_name, "/", &proc_name_ptr);
870 while (word != NULL) {
871 memset(app_name, 0, 256);
872 snprintf(app_name, 256, "%s", word);
873 word = strtok_r(NULL, "/", &proc_name_ptr);
875 __alarm_info->quark_app_unique_name =
876 g_quark_from_string(app_name);
877 } else { /* failure */
879 __alarm_info->quark_app_unique_name =
880 g_quark_from_string("unknown");
881 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
882 "killed, so we failed to get proc file(%s) and do not create "
883 "alarm_info\n", pid, proc_file);
884 *error_code = -1; /*-1 means that system failed
890 __alarm_info->quark_app_service_name =
891 g_quark_from_string(app_service_name);
892 __alarm_info->quark_app_service_name_mod =
893 g_quark_from_string(app_service_name_mod);
894 __alarm_info->quark_dst_service_name =
895 g_quark_from_string(dst_service_name);
896 __alarm_info->quark_dst_service_name_mod =
897 g_quark_from_string(dst_service_name_mod);
898 __alarm_info->quark_bundle = g_quark_from_string("null");
901 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
902 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
906 ALARM_MGR_LOG_PRINT("[alarm-server]:pid=%d, app_unique_name=%s, "
907 "app_service_name=%s,dst_service_name=%s, c_due_time=%d", \
908 pid, g_quark_to_string(__alarm_info->quark_app_unique_name), \
909 g_quark_to_string(__alarm_info->quark_app_service_name), \
910 g_quark_to_string(__alarm_info->quark_dst_service_name), \
911 alarm_context.c_due_time);
913 if (alarm_context.c_due_time < current_time) {
914 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
915 "(%d) is less than current time(%d)", alarm_context.c_due_time,
917 alarm_context.c_due_time = -1;
920 due_time = _alarm_next_duetime(__alarm_info);
921 if (__alarm_add_to_list(__alarm_info, alarm_id) == false) {
927 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
928 "due_time is 0, alarm(%d) \n", *alarm_id);
930 } else if (current_time == due_time) {
931 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
932 "current_time(%d) is same as due_time(%d)", current_time,
935 }else if (difftime(due_time, current_time) < 0){
936 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);
939 char due_time_r[100] = { 0 };
941 localtime_r(&due_time, &ts_ret);
942 strftime(due_time_r, 30, "%c", &ts_ret);
943 ALARM_MGR_LOG_PRINT("[alarm-server]:Create a new alarm: "
944 "alarm(%d) due_time(%s)", *alarm_id,
948 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
949 "due_time(%d)", alarm_context.c_due_time, due_time);
951 if (alarm_context.c_due_time == -1
952 || due_time < alarm_context.c_due_time) {
953 _clear_scheduled_alarm_list();
954 _add_to_scheduled_alarm_list(__alarm_info);
955 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
957 alarm_context.c_due_time = due_time;
959 } else if (due_time == alarm_context.c_due_time) {
960 _add_to_scheduled_alarm_list(__alarm_info);
968 if (enable_power_on_alarm) {
969 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
970 * platform with app-server.because __alarm_power_on(..) fuction don't
971 * use first parameter internally, we set this value to 0(zero)
973 __alarm_power_on(0, enable_power_on_alarm, NULL);
979 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
980 alarm_info_t *alarm_info, int *error_code)
985 __alarm_info_t *__alarm_info = NULL;
988 __alarm_info = malloc(sizeof(__alarm_info_t));
989 if (__alarm_info == NULL) {
990 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, "
991 "malloc failed. it seems to be OOM\n", pid);
992 *error_code = -1; /*-1 means that system failed
997 __alarm_info->pid = pid;
998 __alarm_info->alarm_id = alarm_id;
1000 /* we should consider to check whether pid is running or Not
1003 __alarm_info->quark_app_service_name =
1004 g_quark_from_string(app_service_name);
1005 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
1006 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
1008 time(¤t_time);
1010 if (alarm_context.c_due_time < current_time) {
1011 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
1012 "(%d) is less than current time(%d)", alarm_context.c_due_time,
1014 alarm_context.c_due_time = -1;
1017 due_time = _alarm_next_duetime(__alarm_info);
1018 if (!__alarm_update_in_list(pid, alarm_id, __alarm_info, error_code)) {
1020 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: requested alarm_id "
1021 "(%d) does not exist. so this value is invalid id.", alarm_id);
1024 /* ALARM_MGR_LOG_PRINT("[alarm-server]:request_pid=%d, alarm_id=%d,
1025 * app_unique_name=%s, app_service_name=%s, dst_service_name=%s,
1026 * c_due_time=%d", pid, alarm_id, g_quark_to_string
1027 * (__alarm_info->quark_app_unique_name), g_quark_to_string
1028 * (__alarm_info->quark_app_service_name), g_quark_to_string
1029 * (__alarm_info->quark_dst_service_name), alarm_context.c_due_time);
1032 result = _remove_from_scheduled_alarm_list(pid, alarm_id);
1034 if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
1035 /*there is no scheduled alarm */
1036 _alarm_disable_timer(alarm_context);
1039 ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d)\n",
1046 if (enable_power_on_alarm) {
1047 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in
1048 * a platform with app-server.because __alarm_power_on(..) fuction don't
1049 * use first parameter internally, we set this value to 0(zero)
1051 __alarm_power_on(0, enable_power_on_alarm, NULL);
1055 if (due_time == 0) {
1056 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1063 if (due_time == 0) {
1064 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1065 "due_time is 0, alarm(%d)\n", alarm_id);
1068 } else if (current_time == due_time) {
1069 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1070 "current_time(%d) is same as due_time(%d)", current_time,
1074 }else if (difftime(due_time, current_time)< 0){
1075 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);
1078 char due_time_r[100] = { 0 };
1080 localtime_r(&due_time, &ts_ret);
1081 strftime(due_time_r, 30, "%c", &ts_ret);
1082 ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d) "
1083 "due_time(%s)\n", alarm_id, due_time_r);
1086 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
1087 "due_time(%d)", alarm_context.c_due_time, due_time);
1089 if (alarm_context.c_due_time == -1
1090 || due_time < alarm_context.c_due_time) {
1091 _clear_scheduled_alarm_list();
1092 _add_to_scheduled_alarm_list(__alarm_info);
1093 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
1095 alarm_context.c_due_time = due_time;
1096 ALARM_MGR_LOG_PRINT("[alarm-server1]:alarm_context.c_due_time "
1097 "(%d), due_time(%d)", alarm_context.c_due_time, due_time);
1098 } else if (due_time == alarm_context.c_due_time) {
1099 _add_to_scheduled_alarm_list(__alarm_info);
1100 ALARM_MGR_LOG_PRINT("[alarm-server2]:alarm_context.c_due_time "
1101 "(%d), due_time(%d)", alarm_context.c_due_time, due_time);
1108 if (enable_power_on_alarm) {
1109 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
1110 * in a platform with app-server.because __alarm_power_on(..) fuction
1111 * don't use first parameter internally, we set this value to 0(zero)
1113 __alarm_power_on(0, enable_power_on_alarm, NULL);
1120 static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code)
1122 bool result = false;
1124 ALARM_MGR_LOG_PRINT("[alarm-server]:delete alarm: alarm(%d) pid(%d)\n",\
1126 result = _remove_from_scheduled_alarm_list(pid, alarm_id);
1128 if (!__alarm_remove_from_list(pid, alarm_id, error_code)) {
1130 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:delete alarm: "
1131 "alarm(%d) pid(%d) has failed with error_code(%d)\n",
1132 alarm_id, pid, *error_code);
1136 if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
1137 _alarm_disable_timer(alarm_context);
1145 if (enable_power_on_alarm) {
1146 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
1147 * platform with app-server.because __alarm_power_on(..) fuction don't
1148 * use first parameter internally, we set this value to 0(zero)
1150 __alarm_power_on(0, enable_power_on_alarm, NULL);
1157 static bool __alarm_power_on(int app_id, bool on_off, int *error_code)
1160 time_t min_time = 0;
1161 time_t current_time = 0;
1162 struct tm *temp_info;
1163 struct rtc_time rtc_tm = { 0, };
1164 struct tm min_time_r;
1168 enable_power_on_alarm = on_off;
1169 /*_update_power_on(on_off); */ /*currently its empty*/
1171 fd = open(power_rtc, O_RDONLY);
1173 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
1177 if (on_off == true) {
1178 if (_alarm_find_mintime_power_on(&min_time) == true) {
1180 ab_due_time = min_time;
1182 min_time = min_time - 60;
1184 time(¤t_time);
1186 if (min_time <= current_time)
1187 min_time = current_time + 5;
1189 temp_info = gmtime_r(&min_time, &min_time_r);
1191 ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
1193 min_time_r.tm_year,\
1195 min_time_r.tm_mday,\
1196 min_time_r.tm_hour,\
1198 ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
1200 min_time_r.tm_year,\
1202 min_time_r.tm_mday,\
1203 min_time_r.tm_hour,\
1206 rtc_tm.tm_mday = min_time_r.tm_mday;
1207 rtc_tm.tm_mon = min_time_r.tm_mon;
1208 rtc_tm.tm_year = min_time_r.tm_year;
1209 rtc_tm.tm_hour = min_time_r.tm_hour;
1210 rtc_tm.tm_min = min_time_r.tm_min;
1211 rtc_tm.tm_sec = min_time_r.tm_sec;
1212 /*set_info.time_zone = 0; */
1213 /*set_info.u_interval.day_of_week = 0; */
1215 /*ALARM_MGR_LOG_PRINT("####__alarm_power_on : %d %d
1216 %d %d %d\n",set_info.year,set_info.month,set_info.day,
1217 set_info.hour,set_info.minute); */
1219 ALARM_MGR_LOG_PRINT("due_time : %d \n", ab_due_time);
1221 ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
1222 "%d-%d-%d, %02d:%02d:%02d.\n",
1223 rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
1224 rtc_tm.tm_year + 1900, rtc_tm.tm_hour,
1225 rtc_tm.tm_min, rtc_tm.tm_sec);
1227 retval = ioctl(fd, RTC_ALM_SET, &rtc_tm);
1229 if (errno == ENOTTY) {
1230 ALARM_MGR_EXCEPTION_PRINT(
1231 "\n...Alarm IRQs not supported.\n");
1233 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
1237 ALARM_MGR_LOG_PRINT("[alarm-server]RTC "
1238 "alarm(POWER ON) is setted");
1240 /* Enable alarm interrupts */
1241 retval = ioctl(fd, RTC_AIE_ON, 0);
1243 ALARM_MGR_EXCEPTION_PRINT(
1244 "RTC_AIE_ON ioctl failed");
1248 ALARM_MGR_LOG_PRINT("[alarm-server]RTC(POWER ON) "
1252 retval = ioctl(fd, RTC_AIE_OFF, 0);
1254 ALARM_MGR_LOG_PRINT("__alarm_power_on : off\n");
1255 retval = ioctl(fd, RTC_AIE_OFF, 0);
1259 #endif /* #ifdef __ALARM_BOOT */
1264 static bool __alarm_power_off(int app_id, int *error_code)
1268 #endif /* #ifdef __ALARM_BOOT */
1272 static bool __alarm_check_next_duetime(int app_id, int *error_code)
1275 time_t current_time;
1278 time(¤t_time);
1280 interval = ab_due_time - current_time;
1282 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", ab_due_time,
1285 if (interval > 0 && interval <= 60)
1289 #else /* #ifdef __ALARM_BOOT */
1294 static void __alarm_send_noti_to_application(const char *app_service_name,
1295 alarm_id_t alarm_id)
1299 char service_name[MAX_SERVICE_NAME_LEN];
1300 char object_name[MAX_SERVICE_NAME_LEN];
1302 DBusMessage *message;
1303 DBusMessageIter iter;
1305 if (app_service_name == NULL || strlen(app_service_name) == 0) {
1306 ALARM_MGR_EXCEPTION_PRINT("This alarm destination is "
1310 memset(service_name, 0, MAX_SERVICE_NAME_LEN);
1311 memcpy(service_name, app_service_name, strlen(app_service_name));
1313 snprintf(object_name, MAX_SERVICE_NAME_LEN,
1314 "/org/tizen/alarm/client");
1316 ALARM_MGR_LOG_PRINT("[alarm server][send expired_alarm(alarm_id=%d)to"
1317 "app_service_name(%s), object_name(%s), interface_name(%s)]\n",\
1318 alarm_id, service_name, object_name, "org.tizen.alarm.client");
1320 message = dbus_message_new_method_call(service_name,
1322 "org.tizen.alarm.client",
1324 if (message == NULL) {
1325 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1326 "dbus_message_new_method_call faild. maybe OOM!.\n");
1327 ALARM_MGR_EXCEPTION_PRINT("[alarm server] so we cannot "
1328 "send expired alarm to %s\n", service_name);
1332 dbus_message_set_no_reply(message, TRUE);
1333 /* if(service_name[0]==':') */
1334 /* we don't need auto activation in a case that
1335 destination_app_service_name starts with a charactor like (:) */
1336 dbus_message_set_auto_start(message, FALSE);
1338 dbus_message_iter_init_append(message, &iter);
1339 if (!dbus_message_iter_append_basic
1340 (&iter, DBUS_TYPE_INT32, &alarm_id)) {
1341 dbus_message_unref(message);
1342 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1343 "dbus_message_iter_append_basic faild. maybe OOM!.\n");
1347 dbus_connection_send(dbus_g_connection_get_connection
1348 (alarm_context.bus), message, NULL);
1349 dbus_connection_flush(dbus_g_connection_get_connection
1350 (alarm_context.bus));
1351 dbus_message_unref(message);
1355 static void __alarm_expired()
1357 const char *destination_app_service_name = NULL;
1358 alarm_id_t alarm_id = -1;
1360 __alarm_info_t *__alarm_info = NULL;
1361 char alarm_id_val[32]={0,};
1365 ALARM_MGR_LOG_PRINT("[alarm-server]: Enter \n");
1367 time_t current_time;
1370 time(¤t_time);
1372 interval = difftime(alarm_context.c_due_time, current_time);
1373 ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), "
1374 "current_time(%d), interval(%d)\n", alarm_context.c_due_time,
1375 current_time, interval);
1377 if (alarm_context.c_due_time <= current_time - 1) {
1378 ALARM_MGR_LOG_PRINT("Wrong alarm is expired\n");
1382 GSList *iter = NULL;
1383 __scheduled_alarm_t *alarm = NULL;
1385 for (iter = g_scheduled_alarm_list; iter != NULL;
1386 iter = g_slist_next(iter)) {
1388 alarm_id = alarm->alarm_id;
1390 __alarm_info = alarm->__alarm_info;
1392 app_pid = __alarm_info->pid;
1395 (g_quark_to_string(__alarm_info->quark_bundle),
1398 b_len = strlen(g_quark_to_string(__alarm_info->quark_bundle));
1400 b = bundle_decode((bundle_raw *)g_quark_to_string(__alarm_info->quark_bundle), b_len);
1404 ALARM_MGR_EXCEPTION_PRINT("Error!!!..Unable to decode the bundle!!\n");
1408 snprintf(alarm_id_val,31,"%d",alarm_id);
1410 if (bundle_add(b,"slp.alarm.data.ID", alarm_id_val)){
1411 ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n");
1415 if ( appsvc_run_service(b, 0, NULL, NULL) < 0)
1417 ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
1421 ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
1431 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1433 ALARM_MGR_LOG_PRINT("[alarm-server]:destination is "
1434 "null, so we send expired alarm to %s(%u)\n",\
1436 __alarm_info->quark_app_service_name),
1437 __alarm_info->quark_app_service_name);
1438 destination_app_service_name = g_quark_to_string(
1439 __alarm_info->quark_app_service_name_mod);
1441 ALARM_MGR_LOG_PRINT("[alarm-server]:destination "
1444 __alarm_info->quark_dst_service_name),
1445 __alarm_info->quark_dst_service_name);
1446 destination_app_service_name = g_quark_to_string(
1447 __alarm_info->quark_dst_service_name_mod);
1451 /* orginally this code had if(__alarm_info->app_id==21) in a
1452 platform with app-server. */
1453 /*if(__alarm_info->quark_dst_service_name ==
1454 g_quark_from_string (WAKEUP_ALARM_APP_ID)) */
1456 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1457 WAKEUP_ALARM_APP_ID) == 0) {
1459 fd = open(power_rtc, O_RDONLY);
1461 ALARM_MGR_LOG_PRINT("cannot open /dev/rtc0\n");
1463 ioctl(fd, RTC_AIE_OFF, 0);
1470 * we should consider a situation that
1471 * destination_app_service_name is owner_name like (:xxxx) and
1472 * application's pid which registered this alarm was killed.In that case,
1473 * we don't need to send the expire event because the process was killed.
1474 * this causes needless message to be sent.
1476 ALARM_MGR_LOG_PRINT("[alarm-server]: "
1477 "destination_app_service_name :%s, app_pid=%d\n",
1478 destination_app_service_name, app_pid);
1479 /* the following is a code that checks the above situation.
1480 please verify this code. */
1482 if (dbus_bus_name_has_owner(
1483 dbus_g_connection_get_connection(alarm_context.bus),
1484 destination_app_service_name, NULL) == FALSE) {
1485 __expired_alarm_t *expire_info;
1486 char pkg_name[MAX_SERVICE_NAME_LEN] = { 0, };
1487 char alarm_id_str[32] = { 0, };
1489 expire_info = malloc(sizeof(__expired_alarm_t));
1490 if (G_UNLIKELY(NULL == expire_info)){
1491 ALARM_MGR_ASSERT_PRINT("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n");
1494 strncpy(expire_info->service_name,
1495 destination_app_service_name,
1496 MAX_SERVICE_NAME_LEN);
1497 expire_info->alarm_id = alarm_id;
1498 g_expired_alarm_list =
1499 g_slist_append(g_expired_alarm_list, expire_info);
1503 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1505 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);
1509 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);
1512 snprintf(alarm_id_str, 31, "%d", alarm_id);
1514 ALARM_MGR_LOG_PRINT("before aul_launch pkg_name(%s) "
1515 "alarm_id_str(%s)\n", pkg_name, alarm_id_str);
1518 kb = bundle_create();
1519 bundle_add(kb, "__ALARM_MGR_ID", alarm_id_str);
1520 aul_launch_app(pkg_name, kb);
1523 ALARM_MGR_LOG_PRINT(
1524 "before alarm_send_noti_to_application\n");
1525 __alarm_send_noti_to_application(
1526 destination_app_service_name, alarm_id);
1529 ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application\n");
1531 /* if( !(__alarm_info->alarm_info.alarm_type
1532 & ALARM_TYPE_VOLATILE) ) {
1533 __alarm_remove_from_list(__alarm_info->pid,
1537 if (__alarm_info->alarm_info.mode.repeat
1538 == ALARM_REPEAT_MODE_ONCE) {
1539 /* _alarm_next_duetime(__alarm_info);*/
1540 /* _update_alarms(__alarm_info);*/
1541 __alarm_remove_from_list(__alarm_info->pid, alarm_id,
1545 _alarm_next_duetime(__alarm_info);
1546 /* _update_alarms(__alarm_info);*/
1552 _clear_scheduled_alarm_list();
1553 alarm_context.c_due_time = -1;
1555 ALARM_MGR_LOG_PRINT("[alarm-server]: Leave \n");
1558 static gboolean __alarm_handler_idle()
1560 if (g_dummy_timer_is_set == true) {
1561 ALARM_MGR_LOG_PRINT("dummy alarm timer has expired\n");
1563 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1564 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1576 if (enable_power_on_alarm) {
1577 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
1578 *in a platform with app-server.because __alarm_power_on(..) fuction
1579 *don't use first parameter internally, we set this value to 0(zero)
1581 __alarm_power_on(0, enable_power_on_alarm, NULL);
1584 pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
1589 static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext)
1592 pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
1594 /* we moved __alarm_expired() function to __alarm_handler_idle GSource
1595 because of signal safety. */
1596 g_idle_add_full(G_PRIORITY_HIGH_IDLE, __alarm_handler_idle, NULL, NULL);
1599 static void __clean_registry()
1602 /*TODO:remove all db entries */
1605 static bool __alarm_manager_reset()
1608 _alarm_disable_timer(alarm_context);
1610 __alarm_clean_list();
1612 _clear_scheduled_alarm_list();
1618 static void __on_system_time_changed(keynode_t *node, void *data)
1624 _alarm_disable_timer(alarm_context);
1627 _time = vconf_keynode_get_int(node);
1629 vconf_get_int(VCONFKEY_SYSTEM_TIMECHANGE, (int *)&_time);
1633 diff_time = difftime(_time, before);
1637 ALARM_MGR_ASSERT_PRINT("diff_time is %f\n", diff_time);
1639 ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed\n");
1640 ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n",
1641 alarm_context.c_due_time);
1644 __alarm_update_due_time_of_all_items_in_list(diff_time);
1646 ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n",
1647 alarm_context.c_due_time);
1648 _clear_scheduled_alarm_list();
1653 if (enable_power_on_alarm) {
1654 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
1655 APP_ID) in a platform with app-server. because _alarm_power_
1656 on(..) fuction don't use first parameter internally, we set
1657 this value to 0(zero)
1659 __alarm_power_on(0, enable_power_on_alarm, NULL);
1666 gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid,
1668 int start_month, int start_day,
1669 int start_hour, int start_min,
1670 int start_sec, int end_year, int end_month,
1671 int end_day, int mode_day_of_week,
1672 int mode_repeat, int alarm_type,
1674 char *bundle_data, char *e_cookie,
1675 int *alarm_id, int *return_code)
1677 alarm_info_t alarm_info;
1678 guchar *cookie = NULL;
1682 gboolean result = true;
1684 alarm_info.start.year = start_year;
1685 alarm_info.start.month = start_month;
1686 alarm_info.start.day = start_day;
1687 alarm_info.start.hour = start_hour;
1688 alarm_info.start.min = start_min;
1689 alarm_info.start.sec = start_sec;
1691 alarm_info.end.year = end_year;
1692 alarm_info.end.month = end_month;
1693 alarm_info.end.day = end_day;
1695 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1696 alarm_info.mode.repeat = mode_repeat;
1698 alarm_info.alarm_type = alarm_type;
1699 alarm_info.reserved_info = reserved_info;
1703 cookie = g_base64_decode(e_cookie, &size);
1707 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
1711 call_gid = security_server_get_gid("alarm");
1713 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1715 retval = security_server_check_privilege((const char *)cookie, call_gid);
1717 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1718 ALARM_MGR_EXCEPTION_PRINT(
1719 "%s", "access has been denied\n");
1721 ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
1726 result = __alarm_create_appsvc(&alarm_info, alarm_id, pid,
1727 bundle_data, return_code);
1728 if (false == result)
1730 ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm!\n");
1742 gboolean alarm_manager_alarm_create(void *pObject, int pid,
1743 char *app_service_name, char *app_service_name_mod, int start_year,
1744 int start_month, int start_day,
1745 int start_hour, int start_min,
1746 int start_sec, int end_year, int end_month,
1747 int end_day, int mode_day_of_week,
1748 int mode_repeat, int alarm_type,
1750 char *reserved_service_name, char *reserved_service_name_mod, char *e_cookie,
1751 int *alarm_id, int *return_code)
1753 alarm_info_t alarm_info;
1759 alarm_info.start.year = start_year;
1760 alarm_info.start.month = start_month;
1761 alarm_info.start.day = start_day;
1762 alarm_info.start.hour = start_hour;
1763 alarm_info.start.min = start_min;
1764 alarm_info.start.sec = start_sec;
1766 alarm_info.end.year = end_year;
1767 alarm_info.end.month = end_month;
1768 alarm_info.end.day = end_day;
1770 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1771 alarm_info.mode.repeat = mode_repeat;
1773 alarm_info.alarm_type = alarm_type;
1774 alarm_info.reserved_info = reserved_info;
1778 cookie = g_base64_decode(e_cookie, &size);
1779 call_gid = security_server_get_gid("alarm");
1781 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1783 retval = security_server_check_privilege((const char *)cookie, call_gid);
1785 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1786 ALARM_MGR_EXCEPTION_PRINT(
1787 "%s", "access has been denied\n");
1789 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
1795 /* return valule and return_code should be checked */
1796 __alarm_create(&alarm_info, alarm_id, pid, app_service_name,app_service_name_mod,
1797 reserved_service_name, reserved_service_name_mod, return_code);
1805 gboolean alarm_manager_alarm_delete(void *pObject, int pid, alarm_id_t alarm_id,
1806 char *e_cookie, int *return_code)
1813 cookie = g_base64_decode(e_cookie, &size);
1814 call_gid = security_server_get_gid("alarm");
1816 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1818 retval = security_server_check_privilege((const char *)cookie, call_gid);
1820 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1821 ALARM_MGR_EXCEPTION_PRINT("%s",
1822 "access has been denied\n");
1824 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
1830 __alarm_delete(pid, alarm_id, return_code);
1838 gboolean alarm_manager_alarm_power_on(void *pObject, int pid, bool on_off,
1842 return __alarm_power_on(pid, on_off, return_code);
1845 gboolean alarm_manager_alarm_power_off(void *pObject, int pid, int *return_code)
1848 return __alarm_power_off(pid, return_code);
1851 bool alarm_manager_alarm_check_next_duetime(void *pObject, int pid,
1854 return __alarm_check_next_duetime(pid, return_code);
1857 gboolean alarm_manager_alarm_update(void *pObject, int pid,
1858 char *app_service_name, alarm_id_t alarm_id,
1859 int start_year, int start_month,
1860 int start_day, int start_hour,
1861 int start_min, int start_sec, int end_year,
1862 int end_month, int end_day,
1863 int mode_day_of_week, int mode_repeat,
1864 int alarm_type, int reserved_info,
1867 alarm_info_t alarm_info;
1868 alarm_info.start.year = start_year;
1869 alarm_info.start.month = start_month;
1870 alarm_info.start.day = start_day;
1871 alarm_info.start.hour = start_hour;
1872 alarm_info.start.min = start_min;
1873 alarm_info.start.sec = start_sec;
1875 alarm_info.end.year = end_year;
1876 alarm_info.end.month = end_month;
1877 alarm_info.end.day = end_day;
1879 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1880 alarm_info.mode.repeat = mode_repeat;
1882 alarm_info.alarm_type = alarm_type;
1883 alarm_info.reserved_info = reserved_info;
1887 __alarm_update(pid, app_service_name, alarm_id, &alarm_info,
1893 gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid,
1897 GSList *gs_iter = NULL;
1898 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is
1899 converted to quark value. */
1900 char proc_file[256] = { 0 };
1901 char process_name[512] = { 0 };
1902 char app_name[256] = { 0 };
1904 __alarm_info_t *entry = NULL;
1905 char *proc_name_ptr = NULL;
1910 /* we should consider to check whether pid is running or Not
1912 memset(process_name, '\0', 512);
1913 memset(proc_file, '\0', 256);
1914 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
1919 fd = open(proc_file, O_RDONLY);
1921 ret = read(fd, process_name, 512);
1923 while (process_name[i] != '\0') {
1924 if (process_name[i] == ' ') {
1925 process_name[i] = '\0';
1930 /*if (readlink(proc_file, process_name, 256)!=-1) */
1933 word = strtok_r(process_name, "/", &proc_name_ptr);
1934 while (word != NULL) {
1935 memset(app_name, 0, 256);
1936 snprintf(app_name, 256, "%s", word);
1937 word = strtok_r(NULL, "/", &proc_name_ptr);
1939 quark_app_unique_name = g_quark_from_string(app_name);
1940 } else { /* failure */
1942 quark_app_unique_name = g_quark_from_string("unknown");
1943 memcpy(app_name, "unknown", strlen("unknown") + 1);
1945 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
1946 "killed, so we failed to get proc file(%s) \n",
1948 *return_code = -1; /* -1 means that system
1949 failed internally. */
1953 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
1956 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
1957 gs_iter = g_slist_next(gs_iter)) {
1958 entry = gs_iter->data;
1959 ALARM_MGR_LOG_PRINT("alarm_manager_alarm_get_number_of_ids(): "
1960 "app_name=%s,quark_app_unique_name=%s\n",
1961 app_name, g_quark_to_string(entry->quark_app_unique_name));
1964 g_quark_to_string(entry->quark_app_unique_name)) == 0
1965 && strcmp(app_name, "unknown") != 0) {
1967 ALARM_MGR_LOG_PRINT("inc number of alarms of app "
1968 "(pid:%d, name:%s) is %d\n",
1969 pid, app_name, *num_of_ids);
1973 ALARM_MGR_LOG_PRINT("number of alarms of app(pid:%d, name:%s) is %d\n",
1974 pid, app_name, *num_of_ids);
1978 gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid,
1979 int max_number_of_ids,
1980 GArray **arr, int *num_of_ids,
1983 GSList *gs_iter = NULL;
1984 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is converted
1986 char proc_file[256] = { 0 };
1987 char process_name[512] = { 0 };
1988 char app_name[256] = { 0 };
1990 __alarm_info_t *entry = NULL;
1992 char *proc_name_ptr = NULL;
1996 GArray *garray = NULL;
2000 garray = g_array_new(false, true, sizeof(alarm_id_t));
2002 /* we should check that there is a resource leak.
2003 * Now we don't have free code for g_array_new().
2005 if (max_number_of_ids <= 0) {
2007 ALARM_MGR_EXCEPTION_PRINT("called for pid(%d), but "
2008 "max_number_of_ids(%d) is less than 0.\n",
2009 pid, max_number_of_ids);
2013 /* we should consider to check whether pid is running or Not
2015 memset(process_name, '\0', 512);
2016 memset(proc_file, '\0', 256);
2017 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
2019 fd = open(proc_file, O_RDONLY);
2021 ret = read(fd, process_name, 512);
2023 while (process_name[i] != '\0') {
2024 if (process_name[i] == ' ') {
2025 process_name[i] = '\0';
2030 /* if (readlink(proc_file, process_name, 256)!=-1) */
2033 word = strtok_r(process_name, "/", &proc_name_ptr);
2034 while (word != NULL) {
2035 memset(app_name, 0, 256);
2036 snprintf(app_name, 256, "%s", word);
2037 word = strtok_r(NULL, "/", &proc_name_ptr);
2039 quark_app_unique_name = g_quark_from_string(app_name);
2040 } else { /* failure */
2042 quark_app_unique_name = g_quark_from_string("unknown");
2043 memcpy(app_name, "unknown", strlen("unknown") + 1);
2045 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
2046 "killed, so we failed to get proc file(%s)\n", pid, proc_file);
2048 /* -1 means that system failed internally. */
2052 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
2055 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2056 gs_iter = g_slist_next(gs_iter)) {
2057 entry = gs_iter->data;
2060 g_quark_to_string(entry->quark_app_unique_name)) == 0
2061 && strcmp(app_name, "unknown") != 0) {
2062 g_array_append_val(garray, entry->alarm_id);
2066 *num_of_ids = index;
2073 gboolean alarm_manager_alarm_get_info(void *pObject, int pid,
2074 alarm_id_t alarm_id, int *start_year,
2075 int *start_month, int *start_day,
2076 int *start_hour, int *start_min,
2077 int *start_sec, int *end_year,
2078 int *end_month, int *end_day,
2079 int *mode_day_of_week, int *mode_repeat,
2080 int *alarm_type, int *reserved_info,
2083 ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid,
2086 GSList *gs_iter = NULL;
2087 __alarm_info_t *entry = NULL;
2089 alarm_info_t *alarm_info = NULL;
2092 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2093 gs_iter = g_slist_next(gs_iter)) {
2094 entry = gs_iter->data;
2095 if (entry->alarm_id == alarm_id) {
2096 alarm_info = &(entry->alarm_info);
2101 if (alarm_info == NULL)
2103 ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n",
2105 *return_code = ERR_ALARM_INVALID_PARAM; /*TODO: ERR_ALARM_INVALID_ID?*/
2107 ALARM_MGR_LOG_PRINT("alarm was found\n");
2108 *start_year = alarm_info->start.year;
2109 *start_month = alarm_info->start.month;
2110 *start_day = alarm_info->start.day;
2111 *start_hour = alarm_info->start.hour;
2112 *start_min = alarm_info->start.min;
2113 *start_sec = alarm_info->start.sec;
2115 *end_year = alarm_info->end.year;
2116 *end_year = alarm_info->end.month;
2117 *end_year = alarm_info->end.day;
2119 *mode_day_of_week = alarm_info->mode.u_interval.day_of_week;
2120 *mode_repeat = alarm_info->mode.repeat;
2122 *alarm_type = alarm_info->alarm_type;
2123 *reserved_info = alarm_info->reserved_info;
2130 #include "alarm-skeleton.h"
2132 typedef struct AlarmManagerObject AlarmManagerObject;
2133 typedef struct AlarmManagerObjectClass AlarmManagerObjectClass;
2134 GType Server_Object_get_type(void);
2135 struct AlarmManagerObject {
2138 struct AlarmManagerObjectClass {
2139 GObjectClass parent;
2142 #define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
2144 #define ALARM_MANAGER_TYPE_OBJECT (Server_Object_get_type())
2145 #define ALARM_MANAGER_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST \
2146 ((object), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObject))
2147 #define ALARM_MANAGER_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
2148 ((klass), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2149 #define ALARM_MANAGER_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE \
2150 ((object), ALARM_MANAGER_TYPE_OBJECT))
2151 #define ALARM_MANAGER_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE \
2152 ((klass), ALARM_MANAGER_TYPE_OBJECT))
2153 #define ALARM_MANAGER_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
2154 ((obj), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2155 G_DEFINE_TYPE(AlarmManagerObject, Server_Object, G_TYPE_OBJECT)
2156 static void Server_Object_init(AlarmManagerObject * obj)
2161 static void Server_Object_class_init(AlarmManagerObjectClass *klass)
2166 static void __initialize_timer()
2168 struct sigaction sig_timer;
2169 sigemptyset(&sig_timer.sa_mask);
2170 sig_timer.sa_flags = SA_SIGINFO;
2171 sig_timer.sa_sigaction = (void *)__alarm_handler;
2172 sigaction(SIG_TIMER, &sig_timer, NULL);
2174 alarm_context.timer = _alarm_create_timer();
2178 static void __initialize_alarm_list()
2181 alarm_context.alarms = NULL;
2182 alarm_context.c_due_time = -1;
2184 _load_alarms_from_registry();
2186 __rtc_set(); /*Set RTC1 Alarm with alarm due time for alarm-manager initialization*/
2191 if (enable_power_on_alarm) {
2192 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
2193 * platform with app-server. because __alarm_power_on(..) fuction don't
2194 * use first parameter internally, we set this value to 0(zero)
2196 __alarm_power_on(0, enable_power_on_alarm, NULL);
2201 static void __initialize_scheduled_alarm_lsit()
2203 _init_scheduled_alarm_list();
2207 static void __hibernation_leave_callback()
2210 __initialize_scheduled_alarm_lsit();
2212 __alarm_clean_list();
2214 __initialize_alarm_list();
2217 static bool __initialize_noti()
2220 int fd = heynoti_init();
2222 ALARM_MGR_EXCEPTION_PRINT("fail to heynoti_init\n");
2225 heynoti_subscribe(fd, "HIBERNATION_LEAVE", __hibernation_leave_callback,
2227 heynoti_attach_handler(fd);
2229 if (vconf_notify_key_changed
2230 (VCONFKEY_SYSTEM_TIMECHANGE, __on_system_time_changed, NULL) < 0) {
2231 ALARM_MGR_LOG_PRINT(
2232 "Failed to add callback for time changing event\n");
2234 /*system state change noti ó¸® */
2240 static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
2241 DBusMessage *message,
2245 if (dbus_message_is_signal
2246 (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
2251 __expired_alarm_t *expire_info;
2253 dbus_message_get_args(message,
2255 DBUS_TYPE_STRING, &service,
2256 DBUS_TYPE_STRING, &old_owner,
2257 DBUS_TYPE_STRING, &new_owner,
2260 for (entry = g_expired_alarm_list; entry; entry = entry->next) {
2262 expire_info = (__expired_alarm_t *) entry->data;
2264 if (strcmp(expire_info->service_name, service)
2266 ALARM_MGR_EXCEPTION_PRINT(
2267 "__alarm_server_filter : "
2268 "service name(%s) alarm_id (%d)\n",
2269 expire_info->service_name,\
2270 expire_info->alarm_id);
2272 __alarm_send_noti_to_application(
2273 expire_info->service_name,
2274 expire_info->alarm_id);
2275 g_expired_alarm_list =
2276 g_slist_remove(g_expired_alarm_list,
2283 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2286 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2289 static bool __initialize_dbus()
2291 GError *error = NULL;
2292 GObject *obj = NULL;
2293 DBusGConnection *connection = NULL;
2295 int request_name_result = 0;
2297 dbus_g_object_type_install_info(ALARM_MANAGER_TYPE_OBJECT,
2298 &dbus_glib_alarm_manager_object_info);
2300 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
2303 ALARM_MGR_EXCEPTION_PRINT("dbus_g_bus_get failed\n");
2307 dbus_error_init(&derror);
2309 request_name_result =
2310 dbus_bus_request_name(dbus_g_connection_get_connection(connection),
2311 "org.tizen.alarm.manager",
2312 DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &derror);
2313 if (dbus_error_is_set(&derror)) { /* failure */
2314 ALARM_MGR_EXCEPTION_PRINT("Failed to dbus_bus_request_name "
2315 "(org.tizen.alarm.manager): %s\n", derror.message);
2316 dbus_error_free(&derror);
2320 if (!(obj = g_object_new(ALARM_MANAGER_TYPE_OBJECT, NULL))) {
2321 ALARM_MGR_EXCEPTION_PRINT("Could not allocate new object\n");
2325 dbus_g_connection_register_g_object(connection,
2326 "/org/tizen/alarm/manager",
2329 /*dbus_bus_add_match (dbus_g_connection_get_connection(connection),
2330 "type='signal',member='NameOwnerChanged'",NULL); */
2332 dbus_bus_add_match(dbus_g_connection_get_connection(connection),
2333 "type='signal',sender='" DBUS_SERVICE_DBUS
2334 "',path='" DBUS_PATH_DBUS
2335 "',interface='" DBUS_INTERFACE_DBUS
2336 "',member='NameOwnerChanged'", NULL);
2338 if (!dbus_connection_add_filter
2339 (dbus_g_connection_get_connection(connection),
2340 __alarm_server_filter, NULL, NULL)) {
2341 ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
2346 alarm_context.bus = connection;
2350 #define ALARMMGR_DB_FILE "/opt/dbspace/.alarmmgr.db"
2351 sqlite3 *alarmmgr_db;
2352 #define QUERY_CREATE_TABLE_ALARMMGR "create table alarmmgr \
2353 (alarm_id integer primary key,\
2357 app_unique_name text,\
2358 app_service_name text,\
2359 app_service_name_mod text,\
2367 day_of_week integer,\
2369 alarm_type integer,\
2370 reserved_info integer,\
2371 dst_service_name text, \
2372 dst_service_name_mod text \
2375 static bool __initialize_db()
2377 char *error_message = NULL;
2380 if (access("/opt/dbspace/.alarmmgr.db", F_OK) == 0) {
2382 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2383 DB_UTIL_REGISTER_HOOK_METHOD);
2385 if (ret != SQLITE_OK) {
2386 ALARM_MGR_EXCEPTION_PRINT(
2387 "====>>>> connect menu_db [%s] failed!\n",
2396 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2397 DB_UTIL_REGISTER_HOOK_METHOD);
2399 if (ret != SQLITE_OK) {
2400 ALARM_MGR_EXCEPTION_PRINT(
2401 "====>>>> connect menu_db [%s] failed!\n",
2407 sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL,\
2409 ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, "
2410 "error message = %s\n", QUERY_CREATE_TABLE_ALARMMGR,
2418 static void __initialize()
2427 fp = fopen("/proc/alarm_boot", "r");
2432 size = fread(&temp, 1, 1, fp);
2437 alarm_boot = atoi(temp);
2445 struct rtc_time rtc_tm;
2448 fd = open(power_rtc, O_RDONLY);
2450 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
2453 retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
2456 fd2 = open(default_rtc, O_RDWR);
2458 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc1\n");
2461 retval = ioctl(fd2, RTC_SET_TIME, &rtc_tm);
2464 __initialize_timer();
2465 if (__initialize_dbus() == false) { /* because dbus's initialize
2466 failed, we cannot continue any more. */
2467 ALARM_MGR_EXCEPTION_PRINT("because __initialize_dbus failed, "
2468 "alarm-server cannot be runned.\n");
2471 __initialize_scheduled_alarm_lsit();
2473 __initialize_alarm_list();
2474 __initialize_noti();
2479 static bool __check_false_alarm()
2481 time_t current_time;
2484 time(¤t_time);
2486 interval = ab_due_time - current_time;
2488 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", \
2489 alarm_context.c_due_time, current_time);
2491 if (interval > 0 && interval <= 30) {
2493 } else if (!poweron_alarm_expired) {
2494 /* originally, first arguement's value was 121(app_id) which means
2495 * alarm_booting ui application.and this application's dbus-service
2496 * name had a org.tizen.alarmboot.ui in a platform with app-server.
2497 * so we set "org.tizen.alarmboot.ui.ALARM" instead of 121.
2499 __alarm_send_noti_to_application(
2500 WAKEUP_ALARMBOOTING_APP_ID, -1);
2510 GMainLoop *mainloop = NULL;
2512 ALARM_MGR_LOG_PRINT("Enter main loop\n");
2514 mainloop = g_main_loop_new(NULL, FALSE);
2520 __check_false_alarm();
2524 g_main_loop_run(mainloop);