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 if (alarm_context.c_due_time < current_time) {
752 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
753 "(%d) is less than current time(%d)", alarm_context.c_due_time,
755 alarm_context.c_due_time = -1;
758 due_time = _alarm_next_duetime(__alarm_info);
759 if (__alarm_add_to_list(__alarm_info, alarm_id) == false) {
766 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
767 "due_time is 0, alarm(%d) \n", *alarm_id);
769 } else if (current_time == due_time) {
770 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
771 "current_time(%d) is same as due_time(%d)", current_time,
774 }else if (difftime(due_time, current_time) < 0){
775 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);
778 localtime_r(&due_time, &ts_ret);
779 strftime(due_time_r, 30, "%c", &ts_ret);
780 ALARM_MGR_LOG_PRINT("[alarm-server]:Create a new alarm: "
781 "alarm(%d) due_time(%s)", *alarm_id,
785 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
786 "due_time(%d)", alarm_context.c_due_time, due_time);
788 if (alarm_context.c_due_time == -1
789 || due_time < alarm_context.c_due_time) {
790 _clear_scheduled_alarm_list();
791 _add_to_scheduled_alarm_list(__alarm_info);
792 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
794 alarm_context.c_due_time = due_time;
796 } else if (due_time == alarm_context.c_due_time) {
797 _add_to_scheduled_alarm_list(__alarm_info);
805 if (enable_power_on_alarm) {
806 __alarm_power_on(0, enable_power_on_alarm, NULL);
814 static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
815 int pid, char *app_service_name, char *app_service_name_mod,
816 const char *dst_service_name,const char *dst_service_name_mod, int *error_code)
821 char proc_file[256] = { 0 };
822 char process_name[512] = { 0 };
823 char app_name[256] = { 0 };
825 char *proc_name_ptr = NULL;
827 __alarm_info_t *__alarm_info = NULL;
829 __alarm_info = malloc(sizeof(__alarm_info_t));
830 if (__alarm_info == NULL) {
831 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc "
832 "failed. it seems to be OOM\n", pid);
833 *error_code = -1; /* -1 means that system
834 failed internally. */
837 __alarm_info->pid = pid;
838 __alarm_info->alarm_id = -1;
840 /* we should consider to check whether pid is running or Not
842 memset(process_name, '\0', 512);
843 memset(proc_file, '\0', 256);
844 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
849 fd = open(proc_file, O_RDONLY);
851 ret = read(fd, process_name, 512);
853 while (process_name[i] != '\0') {
854 if (process_name[i] == ' ') {
855 process_name[i] = '\0';
860 /* if (readlink(proc_file, process_name, 256)!=-1) */
863 word = strtok_r(process_name, "/", &proc_name_ptr);
864 while (word != NULL) {
865 memset(app_name, 0, 256);
866 snprintf(app_name, 256, "%s", word);
867 word = strtok_r(NULL, "/", &proc_name_ptr);
869 __alarm_info->quark_app_unique_name =
870 g_quark_from_string(app_name);
871 } else { /* failure */
873 __alarm_info->quark_app_unique_name =
874 g_quark_from_string("unknown");
875 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
876 "killed, so we failed to get proc file(%s) and do not create "
877 "alarm_info\n", pid, proc_file);
878 *error_code = -1; /*-1 means that system failed
884 __alarm_info->quark_app_service_name =
885 g_quark_from_string(app_service_name);
886 __alarm_info->quark_app_service_name_mod =
887 g_quark_from_string(app_service_name_mod);
888 __alarm_info->quark_dst_service_name =
889 g_quark_from_string(dst_service_name);
890 __alarm_info->quark_dst_service_name_mod =
891 g_quark_from_string(dst_service_name_mod);
892 __alarm_info->quark_bundle = g_quark_from_string("null");
895 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
896 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
900 ALARM_MGR_LOG_PRINT("[alarm-server]:pid=%d, app_unique_name=%s, "
901 "app_service_name=%s,dst_service_name=%s, c_due_time=%d", \
902 pid, g_quark_to_string(__alarm_info->quark_app_unique_name), \
903 g_quark_to_string(__alarm_info->quark_app_service_name), \
904 g_quark_to_string(__alarm_info->quark_dst_service_name), \
905 alarm_context.c_due_time);
907 if (alarm_context.c_due_time < current_time) {
908 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
909 "(%d) is less than current time(%d)", alarm_context.c_due_time,
911 alarm_context.c_due_time = -1;
914 due_time = _alarm_next_duetime(__alarm_info);
915 if (__alarm_add_to_list(__alarm_info, alarm_id) == false) {
921 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
922 "due_time is 0, alarm(%d) \n", *alarm_id);
924 } else if (current_time == due_time) {
925 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
926 "current_time(%d) is same as due_time(%d)", current_time,
929 }else if (difftime(due_time, current_time) < 0){
930 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);
933 char due_time_r[100] = { 0 };
935 localtime_r(&due_time, &ts_ret);
936 strftime(due_time_r, 30, "%c", &ts_ret);
937 ALARM_MGR_LOG_PRINT("[alarm-server]:Create a new alarm: "
938 "alarm(%d) due_time(%s)", *alarm_id,
942 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
943 "due_time(%d)", alarm_context.c_due_time, due_time);
945 if (alarm_context.c_due_time == -1
946 || due_time < alarm_context.c_due_time) {
947 _clear_scheduled_alarm_list();
948 _add_to_scheduled_alarm_list(__alarm_info);
949 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
951 alarm_context.c_due_time = due_time;
953 } else if (due_time == alarm_context.c_due_time) {
954 _add_to_scheduled_alarm_list(__alarm_info);
962 if (enable_power_on_alarm) {
963 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
964 * platform with app-server.because __alarm_power_on(..) fuction don't
965 * use first parameter internally, we set this value to 0(zero)
967 __alarm_power_on(0, enable_power_on_alarm, NULL);
973 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
974 alarm_info_t *alarm_info, int *error_code)
979 __alarm_info_t *__alarm_info = NULL;
982 __alarm_info = malloc(sizeof(__alarm_info_t));
983 if (__alarm_info == NULL) {
984 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, "
985 "malloc failed. it seems to be OOM\n", pid);
986 *error_code = -1; /*-1 means that system failed
991 __alarm_info->pid = pid;
992 __alarm_info->alarm_id = alarm_id;
994 /* we should consider to check whether pid is running or Not
997 __alarm_info->quark_app_service_name =
998 g_quark_from_string(app_service_name);
999 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
1000 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
1002 time(¤t_time);
1004 if (alarm_context.c_due_time < current_time) {
1005 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
1006 "(%d) is less than current time(%d)", alarm_context.c_due_time,
1008 alarm_context.c_due_time = -1;
1011 due_time = _alarm_next_duetime(__alarm_info);
1012 if (!__alarm_update_in_list(pid, alarm_id, __alarm_info, error_code)) {
1014 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: requested alarm_id "
1015 "(%d) does not exist. so this value is invalid id.", alarm_id);
1018 /* ALARM_MGR_LOG_PRINT("[alarm-server]:request_pid=%d, alarm_id=%d,
1019 * app_unique_name=%s, app_service_name=%s, dst_service_name=%s,
1020 * c_due_time=%d", pid, alarm_id, g_quark_to_string
1021 * (__alarm_info->quark_app_unique_name), g_quark_to_string
1022 * (__alarm_info->quark_app_service_name), g_quark_to_string
1023 * (__alarm_info->quark_dst_service_name), alarm_context.c_due_time);
1026 result = _remove_from_scheduled_alarm_list(pid, alarm_id);
1028 if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
1029 /*there is no scheduled alarm */
1030 _alarm_disable_timer(alarm_context);
1033 ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d)\n",
1040 if (enable_power_on_alarm) {
1041 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in
1042 * a platform with app-server.because __alarm_power_on(..) fuction don't
1043 * use first parameter internally, we set this value to 0(zero)
1045 __alarm_power_on(0, enable_power_on_alarm, NULL);
1049 if (due_time == 0) {
1050 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1057 if (due_time == 0) {
1058 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1059 "due_time is 0, alarm(%d)\n", alarm_id);
1062 } else if (current_time == due_time) {
1063 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1064 "current_time(%d) is same as due_time(%d)", current_time,
1068 }else if (difftime(due_time, current_time)< 0){
1069 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);
1072 char due_time_r[100] = { 0 };
1074 localtime_r(&due_time, &ts_ret);
1075 strftime(due_time_r, 30, "%c", &ts_ret);
1076 ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d) "
1077 "due_time(%s)\n", alarm_id, due_time_r);
1080 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
1081 "due_time(%d)", alarm_context.c_due_time, due_time);
1083 if (alarm_context.c_due_time == -1
1084 || due_time < alarm_context.c_due_time) {
1085 _clear_scheduled_alarm_list();
1086 _add_to_scheduled_alarm_list(__alarm_info);
1087 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
1089 alarm_context.c_due_time = due_time;
1090 ALARM_MGR_LOG_PRINT("[alarm-server1]:alarm_context.c_due_time "
1091 "(%d), due_time(%d)", alarm_context.c_due_time, due_time);
1092 } else if (due_time == alarm_context.c_due_time) {
1093 _add_to_scheduled_alarm_list(__alarm_info);
1094 ALARM_MGR_LOG_PRINT("[alarm-server2]:alarm_context.c_due_time "
1095 "(%d), due_time(%d)", alarm_context.c_due_time, due_time);
1102 if (enable_power_on_alarm) {
1103 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
1104 * in a platform with app-server.because __alarm_power_on(..) fuction
1105 * don't use first parameter internally, we set this value to 0(zero)
1107 __alarm_power_on(0, enable_power_on_alarm, NULL);
1114 static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code)
1116 bool result = false;
1118 ALARM_MGR_LOG_PRINT("[alarm-server]:delete alarm: alarm(%d) pid(%d)\n",\
1120 result = _remove_from_scheduled_alarm_list(pid, alarm_id);
1122 if (!__alarm_remove_from_list(pid, alarm_id, error_code)) {
1124 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:delete alarm: "
1125 "alarm(%d) pid(%d) has failed with error_code(%d)\n",
1126 alarm_id, pid, *error_code);
1130 if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
1131 _alarm_disable_timer(alarm_context);
1139 if (enable_power_on_alarm) {
1140 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
1141 * platform with app-server.because __alarm_power_on(..) fuction don't
1142 * use first parameter internally, we set this value to 0(zero)
1144 __alarm_power_on(0, enable_power_on_alarm, NULL);
1151 static bool __alarm_power_on(int app_id, bool on_off, int *error_code)
1154 time_t min_time = 0;
1155 time_t current_time = 0;
1156 struct tm *temp_info;
1157 struct rtc_time rtc_tm = { 0, };
1158 struct tm min_time_r;
1162 enable_power_on_alarm = on_off;
1163 /*_update_power_on(on_off); */ /*currently its empty*/
1165 fd = open(power_rtc, O_RDONLY);
1167 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
1171 if (on_off == true) {
1172 if (_alarm_find_mintime_power_on(&min_time) == true) {
1174 ab_due_time = min_time;
1176 min_time = min_time - 60;
1178 time(¤t_time);
1180 if (min_time <= current_time)
1181 min_time = current_time + 5;
1183 temp_info = gmtime_r(&min_time, &min_time_r);
1185 ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
1187 min_time_r.tm_year,\
1189 min_time_r.tm_mday,\
1190 min_time_r.tm_hour,\
1192 ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
1194 min_time_r.tm_year,\
1196 min_time_r.tm_mday,\
1197 min_time_r.tm_hour,\
1200 rtc_tm.tm_mday = min_time_r.tm_mday;
1201 rtc_tm.tm_mon = min_time_r.tm_mon;
1202 rtc_tm.tm_year = min_time_r.tm_year;
1203 rtc_tm.tm_hour = min_time_r.tm_hour;
1204 rtc_tm.tm_min = min_time_r.tm_min;
1205 rtc_tm.tm_sec = min_time_r.tm_sec;
1206 /*set_info.time_zone = 0; */
1207 /*set_info.u_interval.day_of_week = 0; */
1209 /*ALARM_MGR_LOG_PRINT("####__alarm_power_on : %d %d
1210 %d %d %d\n",set_info.year,set_info.month,set_info.day,
1211 set_info.hour,set_info.minute); */
1213 ALARM_MGR_LOG_PRINT("due_time : %d \n", ab_due_time);
1215 ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
1216 "%d-%d-%d, %02d:%02d:%02d.\n",
1217 rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
1218 rtc_tm.tm_year + 1900, rtc_tm.tm_hour,
1219 rtc_tm.tm_min, rtc_tm.tm_sec);
1221 retval = ioctl(fd, RTC_ALM_SET, &rtc_tm);
1223 if (errno == ENOTTY) {
1224 ALARM_MGR_EXCEPTION_PRINT(
1225 "\n...Alarm IRQs not supported.\n");
1227 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
1231 ALARM_MGR_LOG_PRINT("[alarm-server]RTC "
1232 "alarm(POWER ON) is setted");
1234 /* Enable alarm interrupts */
1235 retval = ioctl(fd, RTC_AIE_ON, 0);
1237 ALARM_MGR_EXCEPTION_PRINT(
1238 "RTC_AIE_ON ioctl failed");
1242 ALARM_MGR_LOG_PRINT("[alarm-server]RTC(POWER ON) "
1246 retval = ioctl(fd, RTC_AIE_OFF, 0);
1248 ALARM_MGR_LOG_PRINT("__alarm_power_on : off\n");
1249 retval = ioctl(fd, RTC_AIE_OFF, 0);
1253 #endif /* #ifdef __ALARM_BOOT */
1258 static bool __alarm_power_off(int app_id, int *error_code)
1262 #endif /* #ifdef __ALARM_BOOT */
1266 static bool __alarm_check_next_duetime(int app_id, int *error_code)
1269 time_t current_time;
1272 time(¤t_time);
1274 interval = ab_due_time - current_time;
1276 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", ab_due_time,
1279 if (interval > 0 && interval <= 60)
1283 #else /* #ifdef __ALARM_BOOT */
1288 static void __alarm_send_noti_to_application(const char *app_service_name,
1289 alarm_id_t alarm_id)
1293 char service_name[MAX_SERVICE_NAME_LEN];
1294 char object_name[MAX_SERVICE_NAME_LEN];
1296 DBusMessage *message;
1297 DBusMessageIter iter;
1299 if (app_service_name == NULL || strlen(app_service_name) == 0) {
1300 ALARM_MGR_EXCEPTION_PRINT("This alarm destination is "
1304 memset(service_name, 0, MAX_SERVICE_NAME_LEN);
1305 memcpy(service_name, app_service_name, strlen(app_service_name));
1307 snprintf(object_name, MAX_SERVICE_NAME_LEN,
1308 "/org/tizen/alarm/client");
1310 ALARM_MGR_LOG_PRINT("[alarm server][send expired_alarm(alarm_id=%d)to"
1311 "app_service_name(%s), object_name(%s), interface_name(%s)]\n",\
1312 alarm_id, service_name, object_name, "org.tizen.alarm.client");
1314 message = dbus_message_new_method_call(service_name,
1316 "org.tizen.alarm.client",
1318 if (message == NULL) {
1319 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1320 "dbus_message_new_method_call faild. maybe OOM!.\n");
1321 ALARM_MGR_EXCEPTION_PRINT("[alarm server] so we cannot "
1322 "send expired alarm to %s\n", service_name);
1326 dbus_message_set_no_reply(message, TRUE);
1327 /* if(service_name[0]==':') */
1328 /* we don't need auto activation in a case that
1329 destination_app_service_name starts with a charactor like (:) */
1330 dbus_message_set_auto_start(message, FALSE);
1332 dbus_message_iter_init_append(message, &iter);
1333 if (!dbus_message_iter_append_basic
1334 (&iter, DBUS_TYPE_INT32, &alarm_id)) {
1335 dbus_message_unref(message);
1336 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1337 "dbus_message_iter_append_basic faild. maybe OOM!.\n");
1341 dbus_connection_send(dbus_g_connection_get_connection
1342 (alarm_context.bus), message, NULL);
1343 dbus_connection_flush(dbus_g_connection_get_connection
1344 (alarm_context.bus));
1345 dbus_message_unref(message);
1349 static void __alarm_expired()
1351 const char *destination_app_service_name = NULL;
1352 alarm_id_t alarm_id = -1;
1354 __alarm_info_t *__alarm_info = NULL;
1355 char alarm_id_val[32]={0,};
1359 ALARM_MGR_LOG_PRINT("[alarm-server]: Enter \n");
1361 time_t current_time;
1364 time(¤t_time);
1366 interval = difftime(alarm_context.c_due_time, current_time);
1367 ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), "
1368 "current_time(%d), interval(%d)\n", alarm_context.c_due_time,
1369 current_time, interval);
1371 if (alarm_context.c_due_time <= current_time - 1) {
1372 ALARM_MGR_LOG_PRINT("Wrong alarm is expired\n");
1376 GSList *iter = NULL;
1377 __scheduled_alarm_t *alarm = NULL;
1379 for (iter = g_scheduled_alarm_list; iter != NULL;
1380 iter = g_slist_next(iter)) {
1382 alarm_id = alarm->alarm_id;
1384 __alarm_info = alarm->__alarm_info;
1386 app_pid = __alarm_info->pid;
1389 (g_quark_to_string(__alarm_info->quark_bundle),
1392 b_len = strlen(g_quark_to_string(__alarm_info->quark_bundle));
1394 b = bundle_decode((bundle_raw *)g_quark_to_string(__alarm_info->quark_bundle), b_len);
1398 ALARM_MGR_EXCEPTION_PRINT("Error!!!..Unable to decode the bundle!!\n");
1402 snprintf(alarm_id_val,31,"%d",alarm_id);
1404 if (bundle_add(b,"slp.alarm.data.ID", alarm_id_val)){
1405 ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n");
1409 if ( appsvc_run_service(b, 0, NULL, NULL) < 0)
1411 ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
1415 ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
1425 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1427 ALARM_MGR_LOG_PRINT("[alarm-server]:destination is "
1428 "null, so we send expired alarm to %s(%u)\n",\
1430 __alarm_info->quark_app_service_name),
1431 __alarm_info->quark_app_service_name);
1432 destination_app_service_name = g_quark_to_string(
1433 __alarm_info->quark_app_service_name_mod);
1435 ALARM_MGR_LOG_PRINT("[alarm-server]:destination "
1438 __alarm_info->quark_dst_service_name),
1439 __alarm_info->quark_dst_service_name);
1440 destination_app_service_name = g_quark_to_string(
1441 __alarm_info->quark_dst_service_name_mod);
1445 /* orginally this code had if(__alarm_info->app_id==21) in a
1446 platform with app-server. */
1447 /*if(__alarm_info->quark_dst_service_name ==
1448 g_quark_from_string (WAKEUP_ALARM_APP_ID)) */
1450 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1451 WAKEUP_ALARM_APP_ID) == 0) {
1453 fd = open(power_rtc, O_RDONLY);
1455 ALARM_MGR_LOG_PRINT("cannot open /dev/rtc0\n");
1457 ioctl(fd, RTC_AIE_OFF, 0);
1464 * we should consider a situation that
1465 * destination_app_service_name is owner_name like (:xxxx) and
1466 * application's pid which registered this alarm was killed.In that case,
1467 * we don't need to send the expire event because the process was killed.
1468 * this causes needless message to be sent.
1470 ALARM_MGR_LOG_PRINT("[alarm-server]: "
1471 "destination_app_service_name :%s, app_pid=%d\n",
1472 destination_app_service_name, app_pid);
1473 /* the following is a code that checks the above situation.
1474 please verify this code. */
1476 if (dbus_bus_name_has_owner(
1477 dbus_g_connection_get_connection(alarm_context.bus),
1478 destination_app_service_name, NULL) == FALSE) {
1479 __expired_alarm_t *expire_info;
1480 char pkg_name[MAX_SERVICE_NAME_LEN] = { 0, };
1481 char alarm_id_str[32] = { 0, };
1483 expire_info = malloc(sizeof(__expired_alarm_t));
1484 if (G_UNLIKELY(NULL == expire_info)){
1485 ALARM_MGR_ASSERT_PRINT("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n");
1488 strncpy(expire_info->service_name,
1489 destination_app_service_name,
1490 MAX_SERVICE_NAME_LEN);
1491 expire_info->alarm_id = alarm_id;
1492 g_expired_alarm_list =
1493 g_slist_append(g_expired_alarm_list, expire_info);
1497 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1499 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);
1503 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);
1506 snprintf(alarm_id_str, 31, "%d", alarm_id);
1508 ALARM_MGR_LOG_PRINT("before aul_launch pkg_name(%s) "
1509 "alarm_id_str(%s)\n", pkg_name, alarm_id_str);
1512 kb = bundle_create();
1513 bundle_add(kb, "__ALARM_MGR_ID", alarm_id_str);
1514 aul_launch_app(pkg_name, kb);
1517 ALARM_MGR_LOG_PRINT(
1518 "before alarm_send_noti_to_application\n");
1519 __alarm_send_noti_to_application(
1520 destination_app_service_name, alarm_id);
1523 ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application\n");
1525 /* if( !(__alarm_info->alarm_info.alarm_type
1526 & ALARM_TYPE_VOLATILE) ) {
1527 __alarm_remove_from_list(__alarm_info->pid,
1531 if (__alarm_info->alarm_info.mode.repeat
1532 == ALARM_REPEAT_MODE_ONCE) {
1533 /* _alarm_next_duetime(__alarm_info);*/
1534 /* _update_alarms(__alarm_info);*/
1535 __alarm_remove_from_list(__alarm_info->pid, alarm_id,
1539 _alarm_next_duetime(__alarm_info);
1540 /* _update_alarms(__alarm_info);*/
1546 _clear_scheduled_alarm_list();
1547 alarm_context.c_due_time = -1;
1549 ALARM_MGR_LOG_PRINT("[alarm-server]: Leave \n");
1552 static gboolean __alarm_handler_idle()
1554 if (g_dummy_timer_is_set == true) {
1555 ALARM_MGR_LOG_PRINT("dummy alarm timer has expired\n");
1557 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1558 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1570 if (enable_power_on_alarm) {
1571 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
1572 *in a platform with app-server.because __alarm_power_on(..) fuction
1573 *don't use first parameter internally, we set this value to 0(zero)
1575 __alarm_power_on(0, enable_power_on_alarm, NULL);
1578 pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
1583 static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext)
1586 pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
1588 /* we moved __alarm_expired() function to __alarm_handler_idle GSource
1589 because of signal safety. */
1590 g_idle_add_full(G_PRIORITY_HIGH_IDLE, __alarm_handler_idle, NULL, NULL);
1593 static void __clean_registry()
1596 /*TODO:remove all db entries */
1599 static bool __alarm_manager_reset()
1602 _alarm_disable_timer(alarm_context);
1604 __alarm_clean_list();
1606 _clear_scheduled_alarm_list();
1612 static void __on_system_time_changed(keynode_t *node, void *data)
1618 _alarm_disable_timer(alarm_context);
1621 _time = vconf_keynode_get_int(node);
1623 vconf_get_int(VCONFKEY_SYSTEM_TIMECHANGE, (int *)&_time);
1627 diff_time = difftime(_time, before);
1631 ALARM_MGR_ASSERT_PRINT("diff_time is %f\n", diff_time);
1633 ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed\n");
1634 ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n",
1635 alarm_context.c_due_time);
1638 __alarm_update_due_time_of_all_items_in_list(diff_time);
1640 ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n",
1641 alarm_context.c_due_time);
1642 _clear_scheduled_alarm_list();
1647 if (enable_power_on_alarm) {
1648 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
1649 APP_ID) in a platform with app-server. because _alarm_power_
1650 on(..) fuction don't use first parameter internally, we set
1651 this value to 0(zero)
1653 __alarm_power_on(0, enable_power_on_alarm, NULL);
1660 gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid,
1662 int start_month, int start_day,
1663 int start_hour, int start_min,
1664 int start_sec, int end_year, int end_month,
1665 int end_day, int mode_day_of_week,
1666 int mode_repeat, int alarm_type,
1668 char *bundle_data, char *e_cookie,
1669 int *alarm_id, int *return_code)
1671 alarm_info_t alarm_info;
1672 guchar *cookie = NULL;
1676 gboolean result = true;
1678 alarm_info.start.year = start_year;
1679 alarm_info.start.month = start_month;
1680 alarm_info.start.day = start_day;
1681 alarm_info.start.hour = start_hour;
1682 alarm_info.start.min = start_min;
1683 alarm_info.start.sec = start_sec;
1685 alarm_info.end.year = end_year;
1686 alarm_info.end.month = end_month;
1687 alarm_info.end.day = end_day;
1689 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1690 alarm_info.mode.repeat = mode_repeat;
1692 alarm_info.alarm_type = alarm_type;
1693 alarm_info.reserved_info = reserved_info;
1697 cookie = g_base64_decode(e_cookie, &size);
1701 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
1705 call_gid = security_server_get_gid("alarm");
1707 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1709 retval = security_server_check_privilege((const char *)cookie, call_gid);
1711 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1712 ALARM_MGR_EXCEPTION_PRINT(
1713 "%s", "access has been denied\n");
1715 ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
1720 result = __alarm_create_appsvc(&alarm_info, alarm_id, pid,
1721 bundle_data, return_code);
1722 if (false == result)
1724 ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm!\n");
1736 gboolean alarm_manager_alarm_create(void *pObject, int pid,
1737 char *app_service_name, char *app_service_name_mod, int start_year,
1738 int start_month, int start_day,
1739 int start_hour, int start_min,
1740 int start_sec, int end_year, int end_month,
1741 int end_day, int mode_day_of_week,
1742 int mode_repeat, int alarm_type,
1744 char *reserved_service_name, char *reserved_service_name_mod, char *e_cookie,
1745 int *alarm_id, int *return_code)
1747 alarm_info_t alarm_info;
1753 alarm_info.start.year = start_year;
1754 alarm_info.start.month = start_month;
1755 alarm_info.start.day = start_day;
1756 alarm_info.start.hour = start_hour;
1757 alarm_info.start.min = start_min;
1758 alarm_info.start.sec = start_sec;
1760 alarm_info.end.year = end_year;
1761 alarm_info.end.month = end_month;
1762 alarm_info.end.day = end_day;
1764 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1765 alarm_info.mode.repeat = mode_repeat;
1767 alarm_info.alarm_type = alarm_type;
1768 alarm_info.reserved_info = reserved_info;
1772 cookie = g_base64_decode(e_cookie, &size);
1773 call_gid = security_server_get_gid("alarm");
1775 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1777 retval = security_server_check_privilege((const char *)cookie, call_gid);
1779 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1780 ALARM_MGR_EXCEPTION_PRINT(
1781 "%s", "access has been denied\n");
1783 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
1789 /* return valule and return_code should be checked */
1790 __alarm_create(&alarm_info, alarm_id, pid, app_service_name,app_service_name_mod,
1791 reserved_service_name, reserved_service_name_mod, return_code);
1799 gboolean alarm_manager_alarm_delete(void *pObject, int pid, alarm_id_t alarm_id,
1800 char *e_cookie, int *return_code)
1807 cookie = g_base64_decode(e_cookie, &size);
1808 call_gid = security_server_get_gid("alarm");
1810 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1812 retval = security_server_check_privilege((const char *)cookie, call_gid);
1814 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1815 ALARM_MGR_EXCEPTION_PRINT("%s",
1816 "access has been denied\n");
1818 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
1824 __alarm_delete(pid, alarm_id, return_code);
1832 gboolean alarm_manager_alarm_power_on(void *pObject, int pid, bool on_off,
1836 return __alarm_power_on(pid, on_off, return_code);
1839 gboolean alarm_manager_alarm_power_off(void *pObject, int pid, int *return_code)
1842 return __alarm_power_off(pid, return_code);
1845 bool alarm_manager_alarm_check_next_duetime(void *pObject, int pid,
1848 return __alarm_check_next_duetime(pid, return_code);
1851 gboolean alarm_manager_alarm_update(void *pObject, int pid,
1852 char *app_service_name, alarm_id_t alarm_id,
1853 int start_year, int start_month,
1854 int start_day, int start_hour,
1855 int start_min, int start_sec, int end_year,
1856 int end_month, int end_day,
1857 int mode_day_of_week, int mode_repeat,
1858 int alarm_type, int reserved_info,
1861 alarm_info_t alarm_info;
1862 alarm_info.start.year = start_year;
1863 alarm_info.start.month = start_month;
1864 alarm_info.start.day = start_day;
1865 alarm_info.start.hour = start_hour;
1866 alarm_info.start.min = start_min;
1867 alarm_info.start.sec = start_sec;
1869 alarm_info.end.year = end_year;
1870 alarm_info.end.month = end_month;
1871 alarm_info.end.day = end_day;
1873 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1874 alarm_info.mode.repeat = mode_repeat;
1876 alarm_info.alarm_type = alarm_type;
1877 alarm_info.reserved_info = reserved_info;
1881 __alarm_update(pid, app_service_name, alarm_id, &alarm_info,
1887 gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid,
1891 GSList *gs_iter = NULL;
1892 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is
1893 converted to quark value. */
1894 char proc_file[256] = { 0 };
1895 char process_name[512] = { 0 };
1896 char app_name[256] = { 0 };
1898 __alarm_info_t *entry = NULL;
1899 char *proc_name_ptr = NULL;
1904 /* we should consider to check whether pid is running or Not
1906 memset(process_name, '\0', 512);
1907 memset(proc_file, '\0', 256);
1908 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
1913 fd = open(proc_file, O_RDONLY);
1915 ret = read(fd, process_name, 512);
1917 while (process_name[i] != '\0') {
1918 if (process_name[i] == ' ') {
1919 process_name[i] = '\0';
1924 /*if (readlink(proc_file, process_name, 256)!=-1) */
1927 word = strtok_r(process_name, "/", &proc_name_ptr);
1928 while (word != NULL) {
1929 memset(app_name, 0, 256);
1930 snprintf(app_name, 256, "%s", word);
1931 word = strtok_r(NULL, "/", &proc_name_ptr);
1933 quark_app_unique_name = g_quark_from_string(app_name);
1934 } else { /* failure */
1936 quark_app_unique_name = g_quark_from_string("unknown");
1937 memcpy(app_name, "unknown", strlen("unknown") + 1);
1939 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
1940 "killed, so we failed to get proc file(%s) \n",
1942 *return_code = -1; /* -1 means that system
1943 failed internally. */
1947 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
1950 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
1951 gs_iter = g_slist_next(gs_iter)) {
1952 entry = gs_iter->data;
1953 ALARM_MGR_LOG_PRINT("alarm_manager_alarm_get_number_of_ids(): "
1954 "app_name=%s,quark_app_unique_name=%s\n",
1955 app_name, g_quark_to_string(entry->quark_app_unique_name));
1958 g_quark_to_string(entry->quark_app_unique_name)) == 0
1959 && strcmp(app_name, "unknown") != 0) {
1961 ALARM_MGR_LOG_PRINT("inc number of alarms of app "
1962 "(pid:%d, name:%s) is %d\n",
1963 pid, app_name, *num_of_ids);
1967 ALARM_MGR_LOG_PRINT("number of alarms of app(pid:%d, name:%s) is %d\n",
1968 pid, app_name, *num_of_ids);
1972 gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid,
1973 int max_number_of_ids,
1974 GArray **arr, int *num_of_ids,
1977 GSList *gs_iter = NULL;
1978 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is converted
1980 char proc_file[256] = { 0 };
1981 char process_name[512] = { 0 };
1982 char app_name[256] = { 0 };
1984 __alarm_info_t *entry = NULL;
1986 char *proc_name_ptr = NULL;
1990 GArray *garray = NULL;
1994 garray = g_array_new(false, true, sizeof(alarm_id_t));
1996 /* we should check that there is a resource leak.
1997 * Now we don't have free code for g_array_new().
1999 if (max_number_of_ids <= 0) {
2001 ALARM_MGR_EXCEPTION_PRINT("called for pid(%d), but "
2002 "max_number_of_ids(%d) is less than 0.\n",
2003 pid, max_number_of_ids);
2007 /* we should consider to check whether pid is running or Not
2009 memset(process_name, '\0', 512);
2010 memset(proc_file, '\0', 256);
2011 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
2013 fd = open(proc_file, O_RDONLY);
2015 ret = read(fd, process_name, 512);
2017 while (process_name[i] != '\0') {
2018 if (process_name[i] == ' ') {
2019 process_name[i] = '\0';
2024 /* if (readlink(proc_file, process_name, 256)!=-1) */
2027 word = strtok_r(process_name, "/", &proc_name_ptr);
2028 while (word != NULL) {
2029 memset(app_name, 0, 256);
2030 snprintf(app_name, 256, "%s", word);
2031 word = strtok_r(NULL, "/", &proc_name_ptr);
2033 quark_app_unique_name = g_quark_from_string(app_name);
2034 } else { /* failure */
2036 quark_app_unique_name = g_quark_from_string("unknown");
2037 memcpy(app_name, "unknown", strlen("unknown") + 1);
2039 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
2040 "killed, so we failed to get proc file(%s)\n", pid, proc_file);
2042 /* -1 means that system failed internally. */
2046 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
2049 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2050 gs_iter = g_slist_next(gs_iter)) {
2051 entry = gs_iter->data;
2054 g_quark_to_string(entry->quark_app_unique_name)) == 0
2055 && strcmp(app_name, "unknown") != 0) {
2056 g_array_append_val(garray, entry->alarm_id);
2060 *num_of_ids = index;
2067 gboolean alarm_manager_alarm_get_appsvc_info(void *pObject, int pid, alarm_id_t alarm_id,
2068 char *e_cookie, gchar **b_data, int *return_code)
2072 GSList *gs_iter = NULL;
2073 __alarm_info_t *entry = NULL;
2075 guchar *cookie = NULL;
2080 ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid,
2083 cookie = g_base64_decode(e_cookie, &size);
2087 *return_code = ERR_ALARM_SYSTEM_FAIL;
2088 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
2091 call_gid = security_server_get_gid("alarm");
2093 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
2095 retval = security_server_check_privilege((const char *)cookie, call_gid);
2097 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
2098 ALARM_MGR_EXCEPTION_PRINT(
2099 "%s", "access has been denied\n");
2101 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
2104 *return_code = ERR_ALARM_NO_PERMISSION;
2115 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2116 gs_iter = g_slist_next(gs_iter)) {
2117 entry = gs_iter->data;
2118 if (entry->alarm_id == alarm_id) {
2120 *b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
2126 if ( *b_data && strlen(*b_data) == 4 && strncmp(*b_data,"null",4) == 0){
2127 ALARM_MGR_EXCEPTION_PRINT("Regular alarm,not svc alarm");
2129 *return_code = ERR_ALARM_INVALID_TYPE;
2133 *return_code = ERR_ALARM_INVALID_ID;
2142 gboolean alarm_manager_alarm_get_info(void *pObject, int pid,
2143 alarm_id_t alarm_id, int *start_year,
2144 int *start_month, int *start_day,
2145 int *start_hour, int *start_min,
2146 int *start_sec, int *end_year,
2147 int *end_month, int *end_day,
2148 int *mode_day_of_week, int *mode_repeat,
2149 int *alarm_type, int *reserved_info,
2152 ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid,
2155 GSList *gs_iter = NULL;
2156 __alarm_info_t *entry = NULL;
2158 alarm_info_t *alarm_info = NULL;
2161 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2162 gs_iter = g_slist_next(gs_iter)) {
2163 entry = gs_iter->data;
2164 if (entry->alarm_id == alarm_id) {
2165 alarm_info = &(entry->alarm_info);
2170 if (alarm_info == NULL)
2172 ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n",
2174 *return_code = ERR_ALARM_INVALID_ID;
2176 ALARM_MGR_LOG_PRINT("alarm was found\n");
2177 *start_year = alarm_info->start.year;
2178 *start_month = alarm_info->start.month;
2179 *start_day = alarm_info->start.day;
2180 *start_hour = alarm_info->start.hour;
2181 *start_min = alarm_info->start.min;
2182 *start_sec = alarm_info->start.sec;
2184 *end_year = alarm_info->end.year;
2185 *end_year = alarm_info->end.month;
2186 *end_year = alarm_info->end.day;
2188 *mode_day_of_week = alarm_info->mode.u_interval.day_of_week;
2189 *mode_repeat = alarm_info->mode.repeat;
2191 *alarm_type = alarm_info->alarm_type;
2192 *reserved_info = alarm_info->reserved_info;
2199 #include "alarm-skeleton.h"
2201 typedef struct AlarmManagerObject AlarmManagerObject;
2202 typedef struct AlarmManagerObjectClass AlarmManagerObjectClass;
2203 GType Server_Object_get_type(void);
2204 struct AlarmManagerObject {
2207 struct AlarmManagerObjectClass {
2208 GObjectClass parent;
2211 #define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
2213 #define ALARM_MANAGER_TYPE_OBJECT (Server_Object_get_type())
2214 #define ALARM_MANAGER_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST \
2215 ((object), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObject))
2216 #define ALARM_MANAGER_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
2217 ((klass), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2218 #define ALARM_MANAGER_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE \
2219 ((object), ALARM_MANAGER_TYPE_OBJECT))
2220 #define ALARM_MANAGER_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE \
2221 ((klass), ALARM_MANAGER_TYPE_OBJECT))
2222 #define ALARM_MANAGER_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
2223 ((obj), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2224 G_DEFINE_TYPE(AlarmManagerObject, Server_Object, G_TYPE_OBJECT)
2225 static void Server_Object_init(AlarmManagerObject * obj)
2230 static void Server_Object_class_init(AlarmManagerObjectClass *klass)
2235 static void __initialize_timer()
2237 struct sigaction sig_timer;
2238 sigemptyset(&sig_timer.sa_mask);
2239 sig_timer.sa_flags = SA_SIGINFO;
2240 sig_timer.sa_sigaction = (void *)__alarm_handler;
2241 sigaction(SIG_TIMER, &sig_timer, NULL);
2243 alarm_context.timer = _alarm_create_timer();
2247 static void __initialize_alarm_list()
2250 alarm_context.alarms = NULL;
2251 alarm_context.c_due_time = -1;
2253 _load_alarms_from_registry();
2255 __rtc_set(); /*Set RTC1 Alarm with alarm due time for alarm-manager initialization*/
2260 if (enable_power_on_alarm) {
2261 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
2262 * platform with app-server. because __alarm_power_on(..) fuction don't
2263 * use first parameter internally, we set this value to 0(zero)
2265 __alarm_power_on(0, enable_power_on_alarm, NULL);
2270 static void __initialize_scheduled_alarm_lsit()
2272 _init_scheduled_alarm_list();
2276 static void __hibernation_leave_callback()
2279 __initialize_scheduled_alarm_lsit();
2281 __alarm_clean_list();
2283 __initialize_alarm_list();
2286 static bool __initialize_noti()
2289 int fd = heynoti_init();
2291 ALARM_MGR_EXCEPTION_PRINT("fail to heynoti_init\n");
2294 heynoti_subscribe(fd, "HIBERNATION_LEAVE", __hibernation_leave_callback,
2296 heynoti_attach_handler(fd);
2298 if (vconf_notify_key_changed
2299 (VCONFKEY_SYSTEM_TIMECHANGE, __on_system_time_changed, NULL) < 0) {
2300 ALARM_MGR_LOG_PRINT(
2301 "Failed to add callback for time changing event\n");
2303 /*system state change noti ó¸® */
2309 static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
2310 DBusMessage *message,
2314 if (dbus_message_is_signal
2315 (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
2320 __expired_alarm_t *expire_info;
2322 dbus_message_get_args(message,
2324 DBUS_TYPE_STRING, &service,
2325 DBUS_TYPE_STRING, &old_owner,
2326 DBUS_TYPE_STRING, &new_owner,
2329 for (entry = g_expired_alarm_list; entry; entry = entry->next) {
2331 expire_info = (__expired_alarm_t *) entry->data;
2333 if (strcmp(expire_info->service_name, service)
2335 ALARM_MGR_EXCEPTION_PRINT(
2336 "__alarm_server_filter : "
2337 "service name(%s) alarm_id (%d)\n",
2338 expire_info->service_name,\
2339 expire_info->alarm_id);
2341 __alarm_send_noti_to_application(
2342 expire_info->service_name,
2343 expire_info->alarm_id);
2344 g_expired_alarm_list =
2345 g_slist_remove(g_expired_alarm_list,
2352 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2355 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2358 static bool __initialize_dbus()
2360 GError *error = NULL;
2361 GObject *obj = NULL;
2362 DBusGConnection *connection = NULL;
2364 int request_name_result = 0;
2366 dbus_g_object_type_install_info(ALARM_MANAGER_TYPE_OBJECT,
2367 &dbus_glib_alarm_manager_object_info);
2369 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
2372 ALARM_MGR_EXCEPTION_PRINT("dbus_g_bus_get failed\n");
2376 dbus_error_init(&derror);
2378 request_name_result =
2379 dbus_bus_request_name(dbus_g_connection_get_connection(connection),
2380 "org.tizen.alarm.manager",
2381 DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &derror);
2382 if (dbus_error_is_set(&derror)) { /* failure */
2383 ALARM_MGR_EXCEPTION_PRINT("Failed to dbus_bus_request_name "
2384 "(org.tizen.alarm.manager): %s\n", derror.message);
2385 dbus_error_free(&derror);
2389 if (!(obj = g_object_new(ALARM_MANAGER_TYPE_OBJECT, NULL))) {
2390 ALARM_MGR_EXCEPTION_PRINT("Could not allocate new object\n");
2394 dbus_g_connection_register_g_object(connection,
2395 "/org/tizen/alarm/manager",
2398 /*dbus_bus_add_match (dbus_g_connection_get_connection(connection),
2399 "type='signal',member='NameOwnerChanged'",NULL); */
2401 dbus_bus_add_match(dbus_g_connection_get_connection(connection),
2402 "type='signal',sender='" DBUS_SERVICE_DBUS
2403 "',path='" DBUS_PATH_DBUS
2404 "',interface='" DBUS_INTERFACE_DBUS
2405 "',member='NameOwnerChanged'", NULL);
2407 if (!dbus_connection_add_filter
2408 (dbus_g_connection_get_connection(connection),
2409 __alarm_server_filter, NULL, NULL)) {
2410 ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
2415 alarm_context.bus = connection;
2419 #define ALARMMGR_DB_FILE "/opt/dbspace/.alarmmgr.db"
2420 sqlite3 *alarmmgr_db;
2421 #define QUERY_CREATE_TABLE_ALARMMGR "create table alarmmgr \
2422 (alarm_id integer primary key,\
2426 app_unique_name text,\
2427 app_service_name text,\
2428 app_service_name_mod text,\
2436 day_of_week integer,\
2438 alarm_type integer,\
2439 reserved_info integer,\
2440 dst_service_name text, \
2441 dst_service_name_mod text \
2444 static bool __initialize_db()
2446 char *error_message = NULL;
2449 if (access("/opt/dbspace/.alarmmgr.db", F_OK) == 0) {
2451 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2452 DB_UTIL_REGISTER_HOOK_METHOD);
2454 if (ret != SQLITE_OK) {
2455 ALARM_MGR_EXCEPTION_PRINT(
2456 "====>>>> connect menu_db [%s] failed!\n",
2465 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2466 DB_UTIL_REGISTER_HOOK_METHOD);
2468 if (ret != SQLITE_OK) {
2469 ALARM_MGR_EXCEPTION_PRINT(
2470 "====>>>> connect menu_db [%s] failed!\n",
2476 sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL,\
2478 ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, "
2479 "error message = %s\n", QUERY_CREATE_TABLE_ALARMMGR,
2487 static void __initialize()
2496 fp = fopen("/proc/alarm_boot", "r");
2501 size = fread(&temp, 1, 1, fp);
2506 alarm_boot = atoi(temp);
2514 struct rtc_time rtc_tm;
2517 fd = open(power_rtc, O_RDONLY);
2519 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
2522 retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
2525 fd2 = open(default_rtc, O_RDWR);
2527 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc1\n");
2530 retval = ioctl(fd2, RTC_SET_TIME, &rtc_tm);
2533 __initialize_timer();
2534 if (__initialize_dbus() == false) { /* because dbus's initialize
2535 failed, we cannot continue any more. */
2536 ALARM_MGR_EXCEPTION_PRINT("because __initialize_dbus failed, "
2537 "alarm-server cannot be runned.\n");
2540 __initialize_scheduled_alarm_lsit();
2542 __initialize_alarm_list();
2543 __initialize_noti();
2548 static bool __check_false_alarm()
2550 time_t current_time;
2553 time(¤t_time);
2555 interval = ab_due_time - current_time;
2557 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", \
2558 alarm_context.c_due_time, current_time);
2560 if (interval > 0 && interval <= 30) {
2562 } else if (!poweron_alarm_expired) {
2563 /* originally, first arguement's value was 121(app_id) which means
2564 * alarm_booting ui application.and this application's dbus-service
2565 * name had a org.tizen.alarmboot.ui in a platform with app-server.
2566 * so we set "org.tizen.alarmboot.ui.ALARM" instead of 121.
2568 __alarm_send_noti_to_application(
2569 WAKEUP_ALARMBOOTING_APP_ID, -1);
2579 GMainLoop *mainloop = NULL;
2581 ALARM_MGR_LOG_PRINT("Enter main loop\n");
2583 mainloop = g_main_loop_new(NULL, FALSE);
2589 __check_false_alarm();
2593 g_main_loop_run(mainloop);