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 #if !GLIB_CHECK_VERSION (2, 31, 0)
39 #include <glib/gmacros.h>
43 /*#include "global-gconf.h"*/
45 #include"alarm-internal.h"
47 /*#include"limo-event-delivery.h"*/
52 #include <security-server.h>
55 #include <vconf-keys.h>
57 #define SIG_TIMER 0x32
58 #define WAKEUP_ALARM_APP_ID "org.tizen.alarm.ALARM"
59 /* alarm ui application's alarm's dbus_service name instead of 21
60 (alarm application's app_id) value */
61 #define WAKEUP_ALARMBOOTING_APP_ID "org.tizen.alarmboot.ui.ALARM"
62 /*alrmbooting ui application's dbus_service name instead of 121(alarmbooting
63 application's app_id) value */
65 #include "tapi_misc_ext.h"
67 #include "tapi_misc_data.h"
68 #include "tapi_power.h"
73 __alarm_server_context_t alarm_context;
74 bool g_dummy_timer_is_set = FALSE;
76 GSList *g_scheduled_alarm_list = NULL;
78 GSList *g_expired_alarm_list = NULL;
80 #ifndef RTC_WKALM_BOOT_SET
81 #define RTC_WKALM_BOOT_SET _IOW('p', 0x80, struct rtc_wkalrm)
85 bool enable_power_on_alarm;
87 time_t ab_due_time = -1;
88 bool poweron_alarm_expired = false;
91 /* 2008. 6. 3 sewook7.park
92 When the alarm becoms sleeping mode, alarm timer is not expired.
93 So using RTC, phone is awaken before alarm rings.
95 #define __WAKEUP_USING_RTC__
96 #ifdef __WAKEUP_USING_RTC__
98 #include <linux/rtc.h>
99 #include <sys/ioctl.h>
102 static const char default_rtc[] = "/dev/rtc1";
103 static const char power_rtc[] = "/dev/rtc0";
105 #endif /*__WAKEUP_USING_RTC__*/
107 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info,
108 alarm_id_t *alarm_id);
109 static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
110 __alarm_info_t *__alarm_info,
112 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
114 static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
115 __alarm_info_t *__alarm_info);
116 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time);
117 static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
118 int pid, char *app_service_name, char *app_service_name_mod,
119 const char *dst_service_name, const char *dst_service_name_mod, int *error_code);
120 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
121 int pid, char *bundle_data, int *error_code);
123 static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code);
124 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
125 alarm_info_t *alarm_info, int *error_code);
126 static bool __alarm_power_on(int app_id, bool on_off, int *error_code);
127 static bool __alarm_power_off(int app_id, int *error_code);
128 static bool __alarm_check_next_duetime(int app_id, int *error_code);
129 static void __alarm_send_noti_to_application(const char *app_service_name,
130 alarm_id_t alarm_id);
131 static void __alarm_expired();
132 static gboolean __alarm_handler_idle();
133 static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext);
134 static void __clean_registry();
135 static bool __alarm_manager_reset();
136 static void __on_system_time_changed(keynode_t *node, void *data);
137 static void __initialize_timer();
138 static void __initialize_alarm_list();
139 static void __initialize_scheduled_alarm_lsit();
140 static void __hibernation_leave_callback();
141 static bool __initialize_noti();
143 static bool __initialize_dbus();
144 static bool __initialize_db();
145 static void __initialize();
146 static bool __check_false_alarm();
147 static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
148 DBusMessage *message,
151 static void __rtc_set()
153 #ifdef __WAKEUP_USING_RTC__
155 const char *rtc = default_rtc;
157 struct rtc_time rtc_tm;
158 struct rtc_wkalrm rtc_wk;
161 #ifdef _SIMUL /*if build is simulator, we don't need to set
162 RTC because RTC does not work in simulator.*/
163 ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, "
164 "we don't set RTC.\n");
168 fd = open(rtc, O_RDONLY);
170 ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
174 /* Read the RTC time/date */
175 int retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
177 ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed");
182 ALARM_MGR_LOG_PRINT("\n\nCurrent RTC date/time is %d-%d-%d, "
183 "%02d:%02d:%02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
184 rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min,
187 ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d\n", \
188 alarm_context.c_due_time);
190 if (alarm_context.c_due_time != -1) {
191 time_t due_time = alarm_context.c_due_time - 1;
192 gmtime_r(&due_time, &due_tm);
194 rtc_tm.tm_mday = due_tm.tm_mday;
195 rtc_tm.tm_mon = due_tm.tm_mon;
196 rtc_tm.tm_year = due_tm.tm_year;
197 rtc_tm.tm_hour = due_tm.tm_hour;
198 rtc_tm.tm_min = due_tm.tm_min;
199 rtc_tm.tm_sec = due_tm.tm_sec;
200 memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm));
204 ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
205 "%d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_mday,
206 rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,
207 rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
209 retval = ioctl(fd, RTC_WKALM_SET, &rtc_wk);
211 if (errno == ENOTTY) {
212 ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
215 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
219 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
221 /* Enable alarm interrupts */
222 retval = ioctl(fd, RTC_AIE_ON, 0);
224 ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed");
228 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is on");
230 ALARM_MGR_LOG_PRINT("[alarm-server]alarm_context.c_due_time is"
231 "less than 10 sec. RTC alarm does not need to be set\n");
235 #endif /* __WAKEUP_USING_RTC__ */
238 int _set_rtc_time(time_t _time)
244 struct rtc_time rtc_tm = { 0, };
245 const char *rtc0 = power_rtc;
246 const char *rtc1 = default_rtc;
247 struct tm *_tm = NULL;
248 struct tm time_r = { 0, };
250 fd0 = open(rtc0, O_RDONLY);
251 fd1 = open(rtc1, O_RDONLY);
254 ALARM_MGR_LOG_PRINT("error to open /dev/rtc0.");
259 ALARM_MGR_LOG_PRINT("error to open /dev/rtc1.");
263 memset(&rtc_tm, 0, sizeof(struct rtc_time));
266 (void) gmtime_r(&_time, &time_r);
268 /* Write the RTC time/date 2008:05:21 19:20:00 */
271 rtc_tm.tm_mday = time_r.tm_mday;
272 rtc_tm.tm_mon = time_r.tm_mon;
273 rtc_tm.tm_year = time_r.tm_year;
274 rtc_tm.tm_hour = time_r.tm_hour;
275 rtc_tm.tm_min = time_r.tm_min;
279 retval0 = ioctl(fd0, RTC_SET_TIME, &rtc_tm);
284 ALARM_MGR_LOG_PRINT("error to ioctl fd0.");
290 retval1 = ioctl(fd1, RTC_SET_TIME, &rtc_tm);
295 ALARM_MGR_LOG_PRINT("error to ioctl fd1.");
304 bool __alarm_clean_list()
308 for (iter = alarm_context.alarms; iter != NULL;
309 iter = g_slist_next(iter)) {
313 g_slist_free(alarm_context.alarms);
317 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info,
318 alarm_id_t *alarm_id)
321 bool unique_id = false;
322 alarm_info_t *alarm_info = &__alarm_info->alarm_info;
323 __alarm_info_t *entry = NULL;
327 /* FIXME: alarm id must be unique. */
328 __alarm_info->alarm_id = (int)(void *)__alarm_info;
329 ALARM_MGR_LOG_PRINT("__alarm_info->alarm_id is %d", \
330 __alarm_info->alarm_id);
332 while (unique_id == false) {
335 for (iter = alarm_context.alarms; iter != NULL;
336 iter = g_slist_next(iter)) {
338 if (entry->alarm_id == __alarm_info->alarm_id) {
339 __alarm_info->alarm_id++;
347 ALARM_MGR_LOG_PRINT("[alarm-server]: before add\n");
348 for (iter = alarm_context.alarms; iter != NULL;
349 iter = g_slist_next(iter)) {
351 /*ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
355 alarm_context.alarms =
356 g_slist_append(alarm_context.alarms, __alarm_info);
358 ALARM_MGR_LOG_PRINT("[alarm-server]: after 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 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
367 _save_alarms(__alarm_info);
370 *alarm_id = __alarm_info->alarm_id;
375 static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
376 __alarm_info_t *__alarm_info,
380 alarm_info_t *alarm_info = &__alarm_info->alarm_info;
382 __alarm_info_t *entry = NULL;
384 for (iter = alarm_context.alarms; iter != NULL;
385 iter = g_slist_next(iter)) {
387 if (entry->alarm_id == alarm_id) {
390 __alarm_info->quark_app_unique_name =
391 entry->quark_app_unique_name;
392 __alarm_info->quark_dst_service_name =
393 entry->quark_dst_service_name;
394 memcpy(entry, __alarm_info, sizeof(__alarm_info_t));
402 *error_code = ERR_ALARM_INVALID_ID;
406 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
407 _update_alarms(__alarm_info);
413 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
418 alarm_info_t *alarm_info = NULL;
421 __alarm_info_t *entry = NULL;
424 ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)\n",
427 for (iter = alarm_context.alarms; iter != NULL;
428 iter = g_slist_next(iter)) {
430 if (entry->alarm_id == alarm_id) {
431 alarm_info = &entry->alarm_info;
433 ALARM_MGR_LOG_PRINT("[alarm-server]: "
434 "__alarm_remove_from_list : alarm id(%d)\n",
437 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
438 _delete_alarms(alarm_id);
441 alarm_context.alarms =
442 g_slist_remove(alarm_context.alarms, iter->data);
449 ALARM_MGR_LOG_PRINT("[alarm-server]: after del\n");
453 *error_code = ERR_ALARM_INVALID_ID;
460 static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
461 __alarm_info_t *__alarm_info)
463 alarm_date_t *start = &alarm_info->start;
464 alarm_date_t *end = &alarm_info->end;
466 struct tm alarm_tm = { 0, };
468 if (start->year != 0) {
469 alarm_tm.tm_year = start->year - 1900;
470 alarm_tm.tm_mon = start->month - 1;
471 alarm_tm.tm_mday = start->day;
473 alarm_tm.tm_hour = 0;
477 __alarm_info->start = mktime(&alarm_tm);
479 __alarm_info->start = 0;
482 if (end->year != 0) {
483 alarm_tm.tm_year = end->year - 1900;
484 alarm_tm.tm_mon = end->month - 1;
485 alarm_tm.tm_mday = end->day;
487 alarm_tm.tm_hour = 23;
488 alarm_tm.tm_min = 59;
489 alarm_tm.tm_sec = 59;
491 __alarm_info->end = mktime(&alarm_tm);
493 __alarm_info->end = 0;
500 static bool alarm_get_tz_info(int *gmt_idx, int *dst)
502 GConfValue *value1 = NULL;
503 GConfValue *value2 = NULL;
504 GConfClient* gConfClient = NULL;
507 gConfClient = gconf_client_get_default();
510 value1 = gconf_client_get(gConfClient, SETTINGS_CLOCKTIMEZONE,
513 ALARM_MGR_LOG_PRINT("__on_system_time_changed:
514 gconf_client_get() failed:
515 error:[%s]\n", err->message);
519 *gmt_idx = gconf_value_get_int(value1);
520 ALARM_MGR_LOG_PRINT("gconf return gmt_idx =%d\n ", *gmt_idx);
522 value2 = gconf_client_get(gConfClient,
523 SETTINGS_DAYLIGHTSTATUS, &err);
525 ALARM_MGR_LOG_PRINT("__on_system_time_changed:
526 gconf_client_get() failed: error:[%s]\n", err->message);
531 *dst = gconf_value_get_int(value2);
532 ALARM_MGR_LOG_PRINT("gconf return dst =%d\n ", *dst);
534 if(gConfClient != NULL) {
535 g_object_unref(gConfClient);
540 ALARM_MGR_LOG_PRINT("check the gconf setting failed!!!!! \n ");
543 gconf_value_free(value1);
547 gconf_value_free(value2);
555 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
558 time_t min_time = -1;
561 __alarm_info_t *entry = NULL;
562 struct tm *p_time = NULL ;
563 struct tm due_time_result ;
564 struct tm fixed_time = { 0, };
566 for (iter = alarm_context.alarms; iter != NULL;
567 iter = g_slist_next(iter)) {
569 alarm_info_t *alarm_info = &(entry->alarm_info);
570 if (alarm_info->alarm_type & ALARM_TYPE_RELATIVE) {
571 /*diff_time ó¸® */
573 entry->due_time += diff_time;
575 alarm_date_t *start = &alarm_info->start; /**< start
577 alarm_date_t *end = &alarm_info->end;;
578 /**< end time of the alarm */
581 p_time = localtime_r(&entry->due_time, &due_time_result);
582 if (p_time != NULL) {
583 start->year = p_time->tm_year + 1900;
584 start->month = p_time->tm_mon + 1;
585 start->day = p_time->tm_mday;
586 start->hour = p_time->tm_hour;
587 start->min = p_time->tm_min;
588 start->sec = p_time->tm_sec;
590 end->year = p_time->tm_year + 1900;
591 end->month = p_time->tm_mon + 1;
592 end->day = p_time->tm_mday;
595 memset(&fixed_time, 0, sizeof(fixed_time));
596 fixed_time.tm_year = p_time->tm_year;
597 fixed_time.tm_mon = p_time->tm_mon;
598 fixed_time.tm_mday = p_time->tm_mday;
599 fixed_time.tm_hour = 0;
600 fixed_time.tm_min = 0;
601 fixed_time.tm_sec = 0;
603 entry->start = mktime(&fixed_time);
605 fixed_time.tm_hour = 23;
606 fixed_time.tm_min = 59;
607 fixed_time.tm_sec = 59;
609 entry->end = mktime(&fixed_time);
611 ALARM_MGR_LOG_PRINT("alarm_info->alarm_type is "
612 "ALARM_TYPE_RELATIVE\n");
614 _update_alarms(entry);
617 _alarm_next_duetime(entry);
618 ALARM_MGR_LOG_PRINT("entry->due_time is %d\n", entry->due_time);
623 for (iter = alarm_context.alarms; iter != NULL;
624 iter = g_slist_next(iter)) {
626 due_time = entry->due_time;
630 ALARM_MGR_LOG_PRINT("alarm[%d] with duetime(%u) at "
631 "current(%u)\n", entry->alarm_id, due_time, current_time);
632 if (due_time == 0) { /* 0 means this alarm has been
637 interval = difftime(due_time, current_time);
640 ALARM_MGR_LOG_PRINT("this may be error.. alarm[%d]\n", \
645 interval = difftime(due_time, min_time);
647 if ((interval < 0) || min_time == -1) {
653 alarm_context.c_due_time = min_time;
658 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
659 int pid,char *bundle_data, int *error_code){
664 char due_time_r[100] = { 0 };
665 char proc_file[512] = { 0 };
666 char process_name[512] = { 0 };
667 char app_name[512] = { 0 };
669 char *proc_name_ptr = NULL;
674 __alarm_info_t *__alarm_info = NULL;
676 __alarm_info = malloc(sizeof(__alarm_info_t));
677 if (__alarm_info == NULL) {
678 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc "
679 "failed. it seems to be OOM\n", pid);
680 *error_code = -1; /* -1 means that system
681 failed internally. */
684 __alarm_info->pid = pid;
685 __alarm_info->alarm_id = -1;
688 /* we should consider to check whether pid is running or Not
690 memset(process_name, '\0', 512);
691 memset(proc_file, '\0', 512);
692 snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
694 fd = open(proc_file, O_RDONLY);
696 ret = read(fd, process_name, 512);
700 ALARM_MGR_EXCEPTION_PRINT("Unable to get application name\n");
705 while (process_name[i] != '\0') {
706 if (process_name[i] == ' ') {
707 process_name[i] = '\0';
713 word = strtok_r(process_name, "/", &proc_name_ptr);
714 while (word != NULL) {
715 memset(app_name, 0, 512);
716 snprintf(app_name, 512, "%s", word);
717 word = strtok_r(NULL, "/", &proc_name_ptr);
719 __alarm_info->quark_app_unique_name =
720 g_quark_from_string(app_name);
721 } else { /* failure */
722 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
723 "killed, so we failed to get proc file(%s) and do not create "
724 "alarm_info\n", pid, proc_file);
725 *error_code = -1; /*-1 means that system failed
731 __alarm_info->quark_bundle=g_quark_from_string(bundle_data);
732 __alarm_info->quark_app_service_name = g_quark_from_string("null");
733 __alarm_info->quark_dst_service_name = g_quark_from_string("null");
734 __alarm_info->quark_app_service_name_mod = g_quark_from_string("null");
735 __alarm_info->quark_dst_service_name_mod = g_quark_from_string("null");
737 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
738 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
742 if (alarm_context.c_due_time < current_time) {
743 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
744 "(%d) is less than current time(%d)", alarm_context.c_due_time,
746 alarm_context.c_due_time = -1;
749 due_time = _alarm_next_duetime(__alarm_info);
750 if (__alarm_add_to_list(__alarm_info, alarm_id) == false) {
757 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
758 "due_time is 0, alarm(%d) \n", *alarm_id);
760 } else if (current_time == due_time) {
761 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
762 "current_time(%d) is same as due_time(%d)", current_time,
765 }else if (difftime(due_time, current_time) < 0){
766 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);
769 localtime_r(&due_time, &ts_ret);
770 strftime(due_time_r, 30, "%c", &ts_ret);
771 ALARM_MGR_LOG_PRINT("[alarm-server]:Create a new alarm: "
772 "alarm(%d) due_time(%s)", *alarm_id,
776 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
777 "due_time(%d)", alarm_context.c_due_time, due_time);
779 if (alarm_context.c_due_time == -1
780 || due_time < alarm_context.c_due_time) {
781 _clear_scheduled_alarm_list();
782 _add_to_scheduled_alarm_list(__alarm_info);
783 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
785 alarm_context.c_due_time = due_time;
787 } else if (due_time == alarm_context.c_due_time) {
788 _add_to_scheduled_alarm_list(__alarm_info);
796 if (enable_power_on_alarm) {
797 __alarm_power_on(0, enable_power_on_alarm, NULL);
805 static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
806 int pid, char *app_service_name, char *app_service_name_mod,
807 const char *dst_service_name,const char *dst_service_name_mod, int *error_code)
812 char proc_file[256] = { 0 };
813 char process_name[512] = { 0 };
814 char app_name[256] = { 0 };
816 char *proc_name_ptr = NULL;
818 __alarm_info_t *__alarm_info = NULL;
820 __alarm_info = malloc(sizeof(__alarm_info_t));
821 if (__alarm_info == NULL) {
822 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc "
823 "failed. it seems to be OOM\n", pid);
824 *error_code = -1; /* -1 means that system
825 failed internally. */
828 __alarm_info->pid = pid;
829 __alarm_info->alarm_id = -1;
831 /* we should consider to check whether pid is running or Not
833 memset(process_name, '\0', 512);
834 memset(proc_file, '\0', 256);
835 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
840 fd = open(proc_file, O_RDONLY);
842 ret = read(fd, process_name, 512);
844 while (process_name[i] != '\0') {
845 if (process_name[i] == ' ') {
846 process_name[i] = '\0';
851 /* if (readlink(proc_file, process_name, 256)!=-1) */
854 word = strtok_r(process_name, "/", &proc_name_ptr);
855 while (word != NULL) {
856 memset(app_name, 0, 256);
857 snprintf(app_name, 256, "%s", word);
858 word = strtok_r(NULL, "/", &proc_name_ptr);
860 __alarm_info->quark_app_unique_name =
861 g_quark_from_string(app_name);
862 } else { /* failure */
864 __alarm_info->quark_app_unique_name =
865 g_quark_from_string("unknown");
866 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
867 "killed, so we failed to get proc file(%s) and do not create "
868 "alarm_info\n", pid, proc_file);
869 *error_code = -1; /*-1 means that system failed
875 __alarm_info->quark_app_service_name =
876 g_quark_from_string(app_service_name);
877 __alarm_info->quark_app_service_name_mod =
878 g_quark_from_string(app_service_name_mod);
879 __alarm_info->quark_dst_service_name =
880 g_quark_from_string(dst_service_name);
881 __alarm_info->quark_dst_service_name_mod =
882 g_quark_from_string(dst_service_name_mod);
883 __alarm_info->quark_bundle = g_quark_from_string("null");
886 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
887 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
891 ALARM_MGR_LOG_PRINT("[alarm-server]:pid=%d, app_unique_name=%s, "
892 "app_service_name=%s,dst_service_name=%s, c_due_time=%d", \
893 pid, g_quark_to_string(__alarm_info->quark_app_unique_name), \
894 g_quark_to_string(__alarm_info->quark_app_service_name), \
895 g_quark_to_string(__alarm_info->quark_dst_service_name), \
896 alarm_context.c_due_time);
898 if (alarm_context.c_due_time < current_time) {
899 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
900 "(%d) is less than current time(%d)", alarm_context.c_due_time,
902 alarm_context.c_due_time = -1;
905 due_time = _alarm_next_duetime(__alarm_info);
906 if (__alarm_add_to_list(__alarm_info, alarm_id) == false) {
912 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
913 "due_time is 0, alarm(%d) \n", *alarm_id);
915 } else if (current_time == due_time) {
916 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
917 "current_time(%d) is same as due_time(%d)", current_time,
920 }else if (difftime(due_time, current_time) < 0){
921 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);
924 char due_time_r[100] = { 0 };
926 localtime_r(&due_time, &ts_ret);
927 strftime(due_time_r, 30, "%c", &ts_ret);
928 ALARM_MGR_LOG_PRINT("[alarm-server]:Create a new alarm: "
929 "alarm(%d) due_time(%s)", *alarm_id,
933 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
934 "due_time(%d)", alarm_context.c_due_time, due_time);
936 if (alarm_context.c_due_time == -1
937 || due_time < alarm_context.c_due_time) {
938 _clear_scheduled_alarm_list();
939 _add_to_scheduled_alarm_list(__alarm_info);
940 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
942 alarm_context.c_due_time = due_time;
944 } else if (due_time == alarm_context.c_due_time) {
945 _add_to_scheduled_alarm_list(__alarm_info);
953 if (enable_power_on_alarm) {
954 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
955 * platform with app-server.because __alarm_power_on(..) fuction don't
956 * use first parameter internally, we set this value to 0(zero)
958 __alarm_power_on(0, enable_power_on_alarm, NULL);
964 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
965 alarm_info_t *alarm_info, int *error_code)
970 __alarm_info_t *__alarm_info = NULL;
973 __alarm_info = malloc(sizeof(__alarm_info_t));
974 if (__alarm_info == NULL) {
975 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, "
976 "malloc failed. it seems to be OOM\n", pid);
977 *error_code = -1; /*-1 means that system failed
982 __alarm_info->pid = pid;
983 __alarm_info->alarm_id = alarm_id;
985 /* we should consider to check whether pid is running or Not
988 __alarm_info->quark_app_service_name =
989 g_quark_from_string(app_service_name);
990 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
991 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
995 if (alarm_context.c_due_time < current_time) {
996 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
997 "(%d) is less than current time(%d)", alarm_context.c_due_time,
999 alarm_context.c_due_time = -1;
1002 due_time = _alarm_next_duetime(__alarm_info);
1003 if (!__alarm_update_in_list(pid, alarm_id, __alarm_info, error_code)) {
1005 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: requested alarm_id "
1006 "(%d) does not exist. so this value is invalid id.", alarm_id);
1009 /* ALARM_MGR_LOG_PRINT("[alarm-server]:request_pid=%d, alarm_id=%d,
1010 * app_unique_name=%s, app_service_name=%s, dst_service_name=%s,
1011 * c_due_time=%d", pid, alarm_id, g_quark_to_string
1012 * (__alarm_info->quark_app_unique_name), g_quark_to_string
1013 * (__alarm_info->quark_app_service_name), g_quark_to_string
1014 * (__alarm_info->quark_dst_service_name), alarm_context.c_due_time);
1017 result = _remove_from_scheduled_alarm_list(pid, alarm_id);
1019 if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
1020 /*there is no scheduled alarm */
1021 _alarm_disable_timer(alarm_context);
1024 ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d)\n",
1031 if (enable_power_on_alarm) {
1032 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in
1033 * a platform with app-server.because __alarm_power_on(..) fuction don't
1034 * use first parameter internally, we set this value to 0(zero)
1036 __alarm_power_on(0, enable_power_on_alarm, NULL);
1040 if (due_time == 0) {
1041 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1048 if (due_time == 0) {
1049 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1050 "due_time is 0, alarm(%d)\n", alarm_id);
1053 } else if (current_time == due_time) {
1054 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
1055 "current_time(%d) is same as due_time(%d)", current_time,
1059 }else if (difftime(due_time, current_time)< 0){
1060 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);
1064 char due_time_r[100] = { 0 };
1066 localtime_r(&due_time, &ts_ret);
1067 strftime(due_time_r, 30, "%c", &ts_ret);
1068 ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d) "
1069 "due_time(%s)\n", alarm_id, due_time_r);
1072 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
1073 "due_time(%d)", alarm_context.c_due_time, due_time);
1075 if (alarm_context.c_due_time == -1
1076 || due_time < alarm_context.c_due_time) {
1077 _clear_scheduled_alarm_list();
1078 _add_to_scheduled_alarm_list(__alarm_info);
1079 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
1081 alarm_context.c_due_time = due_time;
1082 ALARM_MGR_LOG_PRINT("[alarm-server1]:alarm_context.c_due_time "
1083 "(%d), due_time(%d)", alarm_context.c_due_time, due_time);
1084 } else if (due_time == alarm_context.c_due_time) {
1085 _add_to_scheduled_alarm_list(__alarm_info);
1086 ALARM_MGR_LOG_PRINT("[alarm-server2]:alarm_context.c_due_time "
1087 "(%d), due_time(%d)", alarm_context.c_due_time, due_time);
1094 if (enable_power_on_alarm) {
1095 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
1096 * in a platform with app-server.because __alarm_power_on(..) fuction
1097 * don't use first parameter internally, we set this value to 0(zero)
1099 __alarm_power_on(0, enable_power_on_alarm, NULL);
1107 static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code)
1109 bool result = false;
1111 ALARM_MGR_LOG_PRINT("[alarm-server]:delete alarm: alarm(%d) pid(%d)\n",\
1113 result = _remove_from_scheduled_alarm_list(pid, alarm_id);
1115 if (!__alarm_remove_from_list(pid, alarm_id, error_code)) {
1117 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:delete alarm: "
1118 "alarm(%d) pid(%d) has failed with error_code(%d)\n",
1119 alarm_id, pid, *error_code);
1123 if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
1124 _alarm_disable_timer(alarm_context);
1132 if (enable_power_on_alarm) {
1133 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
1134 * platform with app-server.because __alarm_power_on(..) fuction don't
1135 * use first parameter internally, we set this value to 0(zero)
1137 __alarm_power_on(0, enable_power_on_alarm, NULL);
1144 static bool __alarm_power_on(int app_id, bool on_off, int *error_code)
1147 time_t min_time = 0;
1148 time_t current_time = 0;
1149 struct tm *temp_info = NULL;
1150 struct rtc_time rtc_tm = { 0, };
1151 struct tm min_time_r = { 0, };
1155 enable_power_on_alarm = on_off;
1156 /*_update_power_on(on_off); */ /*currently its empty*/
1158 fd = open(power_rtc, O_RDONLY);
1160 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
1164 if (on_off == true) {
1165 if (_alarm_find_mintime_power_on(&min_time) == true) {
1167 ab_due_time = min_time;
1169 min_time = min_time - 60;
1171 time(¤t_time);
1173 if (min_time <= current_time)
1174 min_time = current_time + 5;
1176 temp_info = gmtime_r(&min_time, &min_time_r);
1178 ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
1180 min_time_r.tm_year,\
1182 min_time_r.tm_mday,\
1183 min_time_r.tm_hour,\
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,\
1193 rtc_tm.tm_mday = min_time_r.tm_mday;
1194 rtc_tm.tm_mon = min_time_r.tm_mon;
1195 rtc_tm.tm_year = min_time_r.tm_year;
1196 rtc_tm.tm_hour = min_time_r.tm_hour;
1197 rtc_tm.tm_min = min_time_r.tm_min;
1198 rtc_tm.tm_sec = min_time_r.tm_sec;
1199 /*set_info.time_zone = 0; */
1200 /*set_info.u_interval.day_of_week = 0; */
1202 /*ALARM_MGR_LOG_PRINT("####__alarm_power_on : %d %d
1203 %d %d %d\n",set_info.year,set_info.month,set_info.day,
1204 set_info.hour,set_info.minute); */
1206 ALARM_MGR_LOG_PRINT("due_time : %d \n", ab_due_time);
1208 ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
1209 "%d-%d-%d, %02d:%02d:%02d.\n",
1210 rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
1211 rtc_tm.tm_year + 1900, rtc_tm.tm_hour,
1212 rtc_tm.tm_min, rtc_tm.tm_sec);
1214 retval = ioctl(fd, RTC_ALM_SET, &rtc_tm);
1216 if (errno == ENOTTY) {
1217 ALARM_MGR_EXCEPTION_PRINT(
1218 "\n...Alarm IRQs not supported.\n");
1220 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
1224 ALARM_MGR_LOG_PRINT("[alarm-server]RTC "
1225 "alarm(POWER ON) is setted");
1227 /* Enable alarm interrupts */
1228 retval = ioctl(fd, RTC_AIE_ON, 0);
1230 ALARM_MGR_EXCEPTION_PRINT(
1231 "RTC_AIE_ON ioctl failed");
1235 ALARM_MGR_LOG_PRINT("[alarm-server]RTC(POWER ON) "
1239 retval = ioctl(fd, RTC_AIE_OFF, 0);
1241 ALARM_MGR_LOG_PRINT("__alarm_power_on : off\n");
1242 retval = ioctl(fd, RTC_AIE_OFF, 0);
1246 #endif /* #ifdef __ALARM_BOOT */
1251 static bool __alarm_power_off(int app_id, int *error_code)
1255 #endif /* #ifdef __ALARM_BOOT */
1259 static bool __alarm_check_next_duetime(int app_id, int *error_code)
1262 time_t current_time;
1265 time(¤t_time);
1267 interval = ab_due_time - current_time;
1269 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", ab_due_time,
1272 if (interval > 0 && interval <= 60)
1276 #else /* #ifdef __ALARM_BOOT */
1281 static void __alarm_send_noti_to_application(const char *app_service_name,
1282 alarm_id_t alarm_id)
1286 char service_name[MAX_SERVICE_NAME_LEN];
1287 char object_name[MAX_SERVICE_NAME_LEN];
1289 DBusMessage *message;
1290 DBusMessageIter iter;
1292 if (app_service_name == NULL || strlen(app_service_name) == 0) {
1293 ALARM_MGR_EXCEPTION_PRINT("This alarm destination is "
1297 memset(service_name, 0, MAX_SERVICE_NAME_LEN);
1298 memcpy(service_name, app_service_name, strlen(app_service_name));
1300 snprintf(object_name, MAX_SERVICE_NAME_LEN,
1301 "/org/tizen/alarm/client");
1303 ALARM_MGR_LOG_PRINT("[alarm server][send expired_alarm(alarm_id=%d)to"
1304 "app_service_name(%s), object_name(%s), interface_name(%s)]\n",\
1305 alarm_id, service_name, object_name, "org.tizen.alarm.client");
1307 message = dbus_message_new_method_call(service_name,
1309 "org.tizen.alarm.client",
1311 if (message == NULL) {
1312 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1313 "dbus_message_new_method_call faild. maybe OOM!.\n");
1314 ALARM_MGR_EXCEPTION_PRINT("[alarm server] so we cannot "
1315 "send expired alarm to %s\n", service_name);
1319 dbus_message_set_no_reply(message, TRUE);
1320 /* if(service_name[0]==':') */
1321 /* we don't need auto activation in a case that
1322 destination_app_service_name starts with a charactor like (:) */
1323 dbus_message_set_auto_start(message, FALSE);
1325 dbus_message_iter_init_append(message, &iter);
1326 if (!dbus_message_iter_append_basic
1327 (&iter, DBUS_TYPE_INT32, &alarm_id)) {
1328 dbus_message_unref(message);
1329 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1330 "dbus_message_iter_append_basic faild. maybe OOM!.\n");
1334 dbus_connection_send(dbus_g_connection_get_connection
1335 (alarm_context.bus), message, NULL);
1336 dbus_connection_flush(dbus_g_connection_get_connection
1337 (alarm_context.bus));
1338 dbus_message_unref(message);
1342 static void __alarm_expired()
1344 const char *destination_app_service_name = NULL;
1345 alarm_id_t alarm_id = -1;
1347 __alarm_info_t *__alarm_info = NULL;
1348 char alarm_id_val[32]={0,};
1352 ALARM_MGR_LOG_PRINT("[alarm-server]: Enter \n");
1354 time_t current_time;
1357 time(¤t_time);
1359 interval = difftime(alarm_context.c_due_time, current_time);
1360 ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), "
1361 "current_time(%d), interval(%d)\n", alarm_context.c_due_time,
1362 current_time, interval);
1364 if (alarm_context.c_due_time > current_time) {
1365 ALARM_MGR_LOG_PRINT("[alarm-server]: False Alarm\n");
1369 GSList *iter = NULL;
1370 __scheduled_alarm_t *alarm = NULL;
1372 for (iter = g_scheduled_alarm_list; iter != NULL;
1373 iter = g_slist_next(iter)) {
1375 alarm_id = alarm->alarm_id;
1377 __alarm_info = alarm->__alarm_info;
1379 app_pid = __alarm_info->pid;
1382 (g_quark_to_string(__alarm_info->quark_bundle),
1385 b_len = strlen(g_quark_to_string(__alarm_info->quark_bundle));
1387 b = bundle_decode((bundle_raw *)g_quark_to_string(__alarm_info->quark_bundle), b_len);
1391 ALARM_MGR_EXCEPTION_PRINT("Error!!!..Unable to decode the bundle!!\n");
1395 snprintf(alarm_id_val,31,"%d",alarm_id);
1397 if (bundle_add(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){
1398 ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n");
1402 if ( appsvc_run_service(b, 0, NULL, NULL) < 0)
1404 ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
1408 ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
1418 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1420 ALARM_MGR_LOG_PRINT("[alarm-server]:destination is "
1421 "null, so we send expired alarm to %s(%u)\n",\
1423 __alarm_info->quark_app_service_name),
1424 __alarm_info->quark_app_service_name);
1425 destination_app_service_name = g_quark_to_string(
1426 __alarm_info->quark_app_service_name_mod);
1428 ALARM_MGR_LOG_PRINT("[alarm-server]:destination "
1431 __alarm_info->quark_dst_service_name),
1432 __alarm_info->quark_dst_service_name);
1433 destination_app_service_name = g_quark_to_string(
1434 __alarm_info->quark_dst_service_name_mod);
1438 /* orginally this code had if(__alarm_info->app_id==21) in a
1439 platform with app-server. */
1440 /*if(__alarm_info->quark_dst_service_name ==
1441 g_quark_from_string (WAKEUP_ALARM_APP_ID)) */
1443 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1444 WAKEUP_ALARM_APP_ID) == 0) {
1446 fd = open(power_rtc, O_RDONLY);
1448 ALARM_MGR_LOG_PRINT("cannot open /dev/rtc0\n");
1450 ioctl(fd, RTC_AIE_OFF, 0);
1457 * we should consider a situation that
1458 * destination_app_service_name is owner_name like (:xxxx) and
1459 * application's pid which registered this alarm was killed.In that case,
1460 * we don't need to send the expire event because the process was killed.
1461 * this causes needless message to be sent.
1463 ALARM_MGR_LOG_PRINT("[alarm-server]: "
1464 "destination_app_service_name :%s, app_pid=%d\n",
1465 destination_app_service_name, app_pid);
1466 /* the following is a code that checks the above situation.
1467 please verify this code. */
1469 if (dbus_bus_name_has_owner(
1470 dbus_g_connection_get_connection(alarm_context.bus),
1471 destination_app_service_name, NULL) == FALSE) {
1472 __expired_alarm_t *expire_info;
1473 char appid[MAX_SERVICE_NAME_LEN] = { 0, };
1474 char alarm_id_str[32] = { 0, };
1476 expire_info = malloc(sizeof(__expired_alarm_t));
1477 if (G_UNLIKELY(NULL == expire_info)){
1478 ALARM_MGR_ASSERT_PRINT("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n");
1481 bzero(expire_info, sizeof (expire_info));
1482 strncpy(expire_info->service_name,
1483 destination_app_service_name,
1484 MAX_SERVICE_NAME_LEN-1);
1485 expire_info->alarm_id = alarm_id;
1486 g_expired_alarm_list =
1487 g_slist_append(g_expired_alarm_list, expire_info);
1491 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1493 strncpy(appid,g_quark_to_string(__alarm_info->quark_app_service_name),strlen(g_quark_to_string(__alarm_info->quark_app_service_name))-6);
1497 strncpy(appid,g_quark_to_string(__alarm_info->quark_dst_service_name),strlen(g_quark_to_string(__alarm_info->quark_dst_service_name))-6);
1500 snprintf(alarm_id_str, 31, "%d", alarm_id);
1502 ALARM_MGR_LOG_PRINT("before aul_launch appid(%s) "
1503 "alarm_id_str(%s)\n", appid, alarm_id_str);
1506 kb = bundle_create();
1507 bundle_add(kb, "__ALARM_MGR_ID", alarm_id_str);
1508 aul_launch_app(appid, kb);
1511 ALARM_MGR_LOG_PRINT(
1512 "before alarm_send_noti_to_application\n");
1513 __alarm_send_noti_to_application(
1514 destination_app_service_name, alarm_id);
1517 ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application\n");
1519 /* if( !(__alarm_info->alarm_info.alarm_type
1520 & ALARM_TYPE_VOLATILE) ) {
1521 __alarm_remove_from_list(__alarm_info->pid,
1525 if (__alarm_info->alarm_info.mode.repeat
1526 == ALARM_REPEAT_MODE_ONCE) {
1527 /* _alarm_next_duetime(__alarm_info);*/
1528 /* _update_alarms(__alarm_info);*/
1529 __alarm_remove_from_list(__alarm_info->pid, alarm_id,
1533 _alarm_next_duetime(__alarm_info);
1534 /* _update_alarms(__alarm_info);*/
1540 _clear_scheduled_alarm_list();
1541 alarm_context.c_due_time = -1;
1543 ALARM_MGR_LOG_PRINT("[alarm-server]: Leave \n");
1546 static gboolean __alarm_handler_idle()
1548 if (g_dummy_timer_is_set == true) {
1549 ALARM_MGR_LOG_PRINT("dummy alarm timer has expired\n");
1551 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1552 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1564 if (enable_power_on_alarm) {
1565 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
1566 *in a platform with app-server.because __alarm_power_on(..) fuction
1567 *don't use first parameter internally, we set this value to 0(zero)
1569 __alarm_power_on(0, enable_power_on_alarm, NULL);
1572 pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
1577 static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext)
1580 pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
1582 /* we moved __alarm_expired() function to __alarm_handler_idle GSource
1583 because of signal safety. */
1584 g_idle_add_full(G_PRIORITY_HIGH_IDLE, __alarm_handler_idle, NULL, NULL);
1587 static void __clean_registry()
1590 /*TODO:remove all db entries */
1593 static bool __alarm_manager_reset()
1596 _alarm_disable_timer(alarm_context);
1598 __alarm_clean_list();
1600 _clear_scheduled_alarm_list();
1606 static void __on_system_time_changed(keynode_t *node, void *data)
1612 _alarm_disable_timer(alarm_context);
1615 _time = vconf_keynode_get_int(node);
1617 vconf_get_int(VCONFKEY_SYSTEM_TIMECHANGE, (int *)&_time);
1621 diff_time = difftime(_time, before);
1625 ALARM_MGR_ASSERT_PRINT("diff_time is %f\n", diff_time);
1627 ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed\n");
1628 ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n",
1629 alarm_context.c_due_time);
1633 vconf_set_dbl(VCONFKEY_SYSTEM_TIMEDIFF, diff_time);
1634 vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
1636 __alarm_update_due_time_of_all_items_in_list(diff_time);
1638 ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n",
1639 alarm_context.c_due_time);
1640 _clear_scheduled_alarm_list();
1645 if (enable_power_on_alarm) {
1646 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
1647 APP_ID) in a platform with app-server. because _alarm_power_
1648 on(..) fuction don't use first parameter internally, we set
1649 this value to 0(zero)
1651 __alarm_power_on(0, enable_power_on_alarm, NULL);
1657 gboolean alarm_manager_alarm_set_rtc_time(void *pObject, int pid,
1658 int year, int mon, int day,
1659 int hour, int min, int sec, char *e_cookie,
1661 guchar *cookie = NULL;
1664 gboolean result = true;
1667 const char *rtc = power_rtc;
1669 struct rtc_time rtc_tm = {0,};
1670 struct rtc_wkalrm rtc_wk;
1671 struct tm *alarm_tm = NULL;
1672 struct tm due_tm = {0,};
1676 *return_code = ALARMMGR_RESULT_SUCCESS;
1679 cookie = g_base64_decode(e_cookie, &size);
1683 *return_code = ERR_ALARM_NO_PERMISSION;
1684 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
1688 call_gid = security_server_get_gid("alarm");
1690 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1692 retval = security_server_check_privilege((const char *)cookie, call_gid);
1694 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1695 ALARM_MGR_EXCEPTION_PRINT(
1696 "%s", "access has been denied\n");
1698 ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
1700 *return_code = ERR_ALARM_NO_PERMISSION;
1704 /*extract day of the week, day in the year &
1705 daylight saving time from system*/
1708 alarm_tm = localtime(&ctime);
1710 alarm_tm->tm_year = year;
1711 alarm_tm->tm_mon = mon;
1712 alarm_tm->tm_mday = day;
1713 alarm_tm->tm_hour = hour;
1714 alarm_tm->tm_min = min;
1715 alarm_tm->tm_sec = sec;
1717 /*convert to calendar time representation*/
1718 time_t rtc_time = mktime(alarm_tm);
1720 /*convert to Coordinated Universal Time (UTC)*/
1721 gmtime_r(&rtc_time, &due_tm);
1723 fd = open(rtc, O_RDONLY);
1725 ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
1727 *return_code = ERR_ALARM_SYSTEM_FAIL;
1731 /* Read the RTC time/date */
1732 retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
1734 ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed");
1737 *return_code = ERR_ALARM_SYSTEM_FAIL;
1741 rtc_tm.tm_mday = due_tm.tm_mday;
1742 rtc_tm.tm_mon = due_tm.tm_mon;
1743 rtc_tm.tm_year = due_tm.tm_year;
1744 rtc_tm.tm_hour = due_tm.tm_hour;
1745 rtc_tm.tm_min = due_tm.tm_min;
1746 rtc_tm.tm_sec = due_tm.tm_sec;
1748 memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm));
1753 retval = ioctl(fd, RTC_WKALM_BOOT_SET, &rtc_wk);
1755 if (errno == ENOTTY) {
1756 ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
1759 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
1762 *return_code = ERR_ALARM_SYSTEM_FAIL;
1765 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
1766 /* Enable alarm interrupts */
1767 retval = ioctl(fd, RTC_AIE_ON, 0);
1769 ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed");
1771 *return_code = ERR_ALARM_SYSTEM_FAIL;
1786 gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid,
1788 int start_month, int start_day,
1789 int start_hour, int start_min,
1790 int start_sec, int end_year, int end_month,
1791 int end_day, int mode_day_of_week,
1792 int mode_repeat, int alarm_type,
1794 char *bundle_data, char *e_cookie,
1795 int *alarm_id, int *return_code)
1797 alarm_info_t alarm_info;
1798 guchar *cookie = NULL;
1802 gboolean result = true;
1804 alarm_info.start.year = start_year;
1805 alarm_info.start.month = start_month;
1806 alarm_info.start.day = start_day;
1807 alarm_info.start.hour = start_hour;
1808 alarm_info.start.min = start_min;
1809 alarm_info.start.sec = start_sec;
1811 alarm_info.end.year = end_year;
1812 alarm_info.end.month = end_month;
1813 alarm_info.end.day = end_day;
1815 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1816 alarm_info.mode.repeat = mode_repeat;
1818 alarm_info.alarm_type = alarm_type;
1819 alarm_info.reserved_info = reserved_info;
1823 cookie = g_base64_decode(e_cookie, &size);
1827 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
1831 call_gid = security_server_get_gid("alarm");
1833 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1835 retval = security_server_check_privilege((const char *)cookie, call_gid);
1837 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1838 ALARM_MGR_EXCEPTION_PRINT(
1839 "%s", "access has been denied\n");
1841 ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
1846 result = __alarm_create_appsvc(&alarm_info, alarm_id, pid,
1847 bundle_data, return_code);
1848 if (false == result)
1850 ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm!\n");
1862 gboolean alarm_manager_alarm_create(void *pObject, int pid,
1863 char *app_service_name, char *app_service_name_mod, int start_year,
1864 int start_month, int start_day,
1865 int start_hour, int start_min,
1866 int start_sec, int end_year, int end_month,
1867 int end_day, int mode_day_of_week,
1868 int mode_repeat, int alarm_type,
1870 char *reserved_service_name, char *reserved_service_name_mod, char *e_cookie,
1871 int *alarm_id, int *return_code)
1873 alarm_info_t alarm_info;
1879 alarm_info.start.year = start_year;
1880 alarm_info.start.month = start_month;
1881 alarm_info.start.day = start_day;
1882 alarm_info.start.hour = start_hour;
1883 alarm_info.start.min = start_min;
1884 alarm_info.start.sec = start_sec;
1886 alarm_info.end.year = end_year;
1887 alarm_info.end.month = end_month;
1888 alarm_info.end.day = end_day;
1890 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1891 alarm_info.mode.repeat = mode_repeat;
1893 alarm_info.alarm_type = alarm_type;
1894 alarm_info.reserved_info = reserved_info;
1898 cookie = g_base64_decode(e_cookie, &size);
1899 call_gid = security_server_get_gid("alarm");
1901 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1903 retval = security_server_check_privilege((const char *)cookie, call_gid);
1905 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1906 ALARM_MGR_EXCEPTION_PRINT(
1907 "%s", "access has been denied\n");
1909 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
1915 /* return valule and return_code should be checked */
1916 __alarm_create(&alarm_info, alarm_id, pid, app_service_name,app_service_name_mod,
1917 reserved_service_name, reserved_service_name_mod, return_code);
1925 gboolean alarm_manager_alarm_delete(void *pObject, int pid, alarm_id_t alarm_id,
1926 char *e_cookie, int *return_code)
1933 cookie = g_base64_decode(e_cookie, &size);
1934 call_gid = security_server_get_gid("alarm");
1936 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1938 retval = security_server_check_privilege((const char *)cookie, call_gid);
1940 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1941 ALARM_MGR_EXCEPTION_PRINT("%s",
1942 "access has been denied\n");
1944 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
1950 __alarm_delete(pid, alarm_id, return_code);
1958 gboolean alarm_manager_alarm_power_on(void *pObject, int pid, bool on_off,
1962 return __alarm_power_on(pid, on_off, return_code);
1965 gboolean alarm_manager_alarm_power_off(void *pObject, int pid, int *return_code)
1968 return __alarm_power_off(pid, return_code);
1971 bool alarm_manager_alarm_check_next_duetime(void *pObject, int pid,
1974 return __alarm_check_next_duetime(pid, return_code);
1977 gboolean alarm_manager_alarm_update(void *pObject, int pid,
1978 char *app_service_name, alarm_id_t alarm_id,
1979 int start_year, int start_month,
1980 int start_day, int start_hour,
1981 int start_min, int start_sec, int end_year,
1982 int end_month, int end_day,
1983 int mode_day_of_week, int mode_repeat,
1984 int alarm_type, int reserved_info,
1987 alarm_info_t alarm_info;
1988 alarm_info.start.year = start_year;
1989 alarm_info.start.month = start_month;
1990 alarm_info.start.day = start_day;
1991 alarm_info.start.hour = start_hour;
1992 alarm_info.start.min = start_min;
1993 alarm_info.start.sec = start_sec;
1995 alarm_info.end.year = end_year;
1996 alarm_info.end.month = end_month;
1997 alarm_info.end.day = end_day;
1999 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
2000 alarm_info.mode.repeat = mode_repeat;
2002 alarm_info.alarm_type = alarm_type;
2003 alarm_info.reserved_info = reserved_info;
2007 __alarm_update(pid, app_service_name, alarm_id, &alarm_info,
2013 gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid,
2017 GSList *gs_iter = NULL;
2018 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is
2019 converted to quark value. */
2020 char proc_file[256] = { 0 };
2021 char process_name[512] = { 0 };
2022 char app_name[256] = { 0 };
2024 __alarm_info_t *entry = NULL;
2025 char *proc_name_ptr = NULL;
2030 /* we should consider to check whether pid is running or Not
2032 memset(process_name, '\0', 512);
2033 memset(proc_file, '\0', 256);
2034 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
2039 fd = open(proc_file, O_RDONLY);
2041 ret = read(fd, process_name, 512);
2043 while (process_name[i] != '\0') {
2044 if (process_name[i] == ' ') {
2045 process_name[i] = '\0';
2050 /*if (readlink(proc_file, process_name, 256)!=-1) */
2053 word = strtok_r(process_name, "/", &proc_name_ptr);
2054 while (word != NULL) {
2055 memset(app_name, 0, 256);
2056 snprintf(app_name, 256, "%s", word);
2057 word = strtok_r(NULL, "/", &proc_name_ptr);
2059 quark_app_unique_name = g_quark_from_string(app_name);
2060 } else { /* failure */
2062 quark_app_unique_name = g_quark_from_string("unknown");
2063 memcpy(app_name, "unknown", strlen("unknown") + 1);
2065 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
2066 "killed, so we failed to get proc file(%s) \n",
2068 *return_code = -1; /* -1 means that system
2069 failed internally. */
2073 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
2076 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2077 gs_iter = g_slist_next(gs_iter)) {
2078 entry = gs_iter->data;
2079 ALARM_MGR_LOG_PRINT("alarm_manager_alarm_get_number_of_ids(): "
2080 "app_name=%s,quark_app_unique_name=%s\n",
2081 app_name, g_quark_to_string(entry->quark_app_unique_name));
2084 g_quark_to_string(entry->quark_app_unique_name)) == 0
2085 && strcmp(app_name, "unknown") != 0) {
2087 ALARM_MGR_LOG_PRINT("inc number of alarms of app "
2088 "(pid:%d, name:%s) is %d\n",
2089 pid, app_name, *num_of_ids);
2093 ALARM_MGR_LOG_PRINT("number of alarms of app(pid:%d, name:%s) is %d\n",
2094 pid, app_name, *num_of_ids);
2098 gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid,
2099 int max_number_of_ids,
2100 GArray **arr, int *num_of_ids,
2103 GSList *gs_iter = NULL;
2104 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is converted
2106 char proc_file[256] = { 0 };
2107 char process_name[512] = { 0 };
2108 char app_name[256] = { 0 };
2110 __alarm_info_t *entry = NULL;
2112 char *proc_name_ptr = NULL;
2116 GArray *garray = NULL;
2120 garray = g_array_new(false, true, sizeof(alarm_id_t));
2122 /* we should check that there is a resource leak.
2123 * Now we don't have free code for g_array_new().
2125 if (max_number_of_ids <= 0) {
2127 ALARM_MGR_EXCEPTION_PRINT("called for pid(%d), but "
2128 "max_number_of_ids(%d) is less than 0.\n",
2129 pid, max_number_of_ids);
2133 /* we should consider to check whether pid is running or Not
2135 memset(process_name, '\0', 512);
2136 memset(proc_file, '\0', 256);
2137 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
2139 fd = open(proc_file, O_RDONLY);
2141 ret = read(fd, process_name, 512);
2143 while (process_name[i] != '\0') {
2144 if (process_name[i] == ' ') {
2145 process_name[i] = '\0';
2150 /* if (readlink(proc_file, process_name, 256)!=-1) */
2153 word = strtok_r(process_name, "/", &proc_name_ptr);
2154 while (word != NULL) {
2155 memset(app_name, 0, 256);
2156 snprintf(app_name, 256, "%s", word);
2157 word = strtok_r(NULL, "/", &proc_name_ptr);
2159 quark_app_unique_name = g_quark_from_string(app_name);
2160 } else { /* failure */
2162 quark_app_unique_name = g_quark_from_string("unknown");
2163 memcpy(app_name, "unknown", strlen("unknown") + 1);
2165 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
2166 "killed, so we failed to get proc file(%s)\n", pid, proc_file);
2168 /* -1 means that system failed internally. */
2172 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
2175 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2176 gs_iter = g_slist_next(gs_iter)) {
2177 entry = gs_iter->data;
2180 g_quark_to_string(entry->quark_app_unique_name)) == 0
2181 && strcmp(app_name, "unknown") != 0) {
2182 g_array_append_val(garray, entry->alarm_id);
2186 *num_of_ids = index;
2193 gboolean alarm_manager_alarm_get_appsvc_info(void *pObject, int pid, alarm_id_t alarm_id,
2194 char *e_cookie, gchar **b_data, int *return_code)
2198 GSList *gs_iter = NULL;
2199 __alarm_info_t *entry = NULL;
2201 guchar *cookie = NULL;
2206 ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid,
2209 cookie = g_base64_decode(e_cookie, &size);
2213 *return_code = ERR_ALARM_SYSTEM_FAIL;
2214 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
2217 call_gid = security_server_get_gid("alarm");
2219 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
2221 retval = security_server_check_privilege((const char *)cookie, call_gid);
2223 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
2224 ALARM_MGR_EXCEPTION_PRINT(
2225 "%s", "access has been denied\n");
2227 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
2230 *return_code = ERR_ALARM_NO_PERMISSION;
2241 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2242 gs_iter = g_slist_next(gs_iter)) {
2243 entry = gs_iter->data;
2244 if (entry->alarm_id == alarm_id) {
2246 *b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
2252 if ( *b_data && strlen(*b_data) == 4 && strncmp(*b_data,"null",4) == 0){
2253 ALARM_MGR_EXCEPTION_PRINT("Regular alarm,not svc alarm");
2255 *return_code = ERR_ALARM_INVALID_TYPE;
2259 *return_code = ERR_ALARM_INVALID_ID;
2268 gboolean alarm_manager_alarm_get_info(void *pObject, int pid,
2269 alarm_id_t alarm_id, int *start_year,
2270 int *start_month, int *start_day,
2271 int *start_hour, int *start_min,
2272 int *start_sec, int *end_year,
2273 int *end_month, int *end_day,
2274 int *mode_day_of_week, int *mode_repeat,
2275 int *alarm_type, int *reserved_info,
2278 ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid,
2281 GSList *gs_iter = NULL;
2282 __alarm_info_t *entry = NULL;
2284 alarm_info_t *alarm_info = NULL;
2287 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2288 gs_iter = g_slist_next(gs_iter)) {
2289 entry = gs_iter->data;
2290 if (entry->alarm_id == alarm_id) {
2291 alarm_info = &(entry->alarm_info);
2296 if (alarm_info == NULL)
2298 ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n",
2300 *return_code = ERR_ALARM_INVALID_ID;
2302 ALARM_MGR_LOG_PRINT("alarm was found\n");
2303 *start_year = alarm_info->start.year;
2304 *start_month = alarm_info->start.month;
2305 *start_day = alarm_info->start.day;
2306 *start_hour = alarm_info->start.hour;
2307 *start_min = alarm_info->start.min;
2308 *start_sec = alarm_info->start.sec;
2310 *end_year = alarm_info->end.year;
2311 *end_year = alarm_info->end.month;
2312 *end_year = alarm_info->end.day;
2314 *mode_day_of_week = alarm_info->mode.u_interval.day_of_week;
2315 *mode_repeat = alarm_info->mode.repeat;
2317 *alarm_type = alarm_info->alarm_type;
2318 *reserved_info = alarm_info->reserved_info;
2325 #include "alarm-skeleton.h"
2327 typedef struct AlarmManagerObject AlarmManagerObject;
2328 typedef struct AlarmManagerObjectClass AlarmManagerObjectClass;
2329 GType Server_Object_get_type(void);
2330 struct AlarmManagerObject {
2333 struct AlarmManagerObjectClass {
2334 GObjectClass parent;
2337 #define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
2339 #define ALARM_MANAGER_TYPE_OBJECT (Server_Object_get_type())
2340 #define ALARM_MANAGER_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST \
2341 ((object), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObject))
2342 #define ALARM_MANAGER_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
2343 ((klass), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2344 #define ALARM_MANAGER_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE \
2345 ((object), ALARM_MANAGER_TYPE_OBJECT))
2346 #define ALARM_MANAGER_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE \
2347 ((klass), ALARM_MANAGER_TYPE_OBJECT))
2348 #define ALARM_MANAGER_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
2349 ((obj), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2350 G_DEFINE_TYPE(AlarmManagerObject, Server_Object, G_TYPE_OBJECT)
2351 static void Server_Object_init(AlarmManagerObject * obj)
2356 static void Server_Object_class_init(AlarmManagerObjectClass *klass)
2361 static void __initialize_timer()
2363 struct sigaction sig_timer;
2364 sigemptyset(&sig_timer.sa_mask);
2365 sig_timer.sa_flags = SA_SIGINFO;
2366 sig_timer.sa_sigaction = (void *)__alarm_handler;
2367 sigaction(SIG_TIMER, &sig_timer, NULL);
2369 alarm_context.timer = _alarm_create_timer();
2373 static void __initialize_alarm_list()
2376 alarm_context.alarms = NULL;
2377 alarm_context.c_due_time = -1;
2379 _load_alarms_from_registry();
2381 __rtc_set(); /*Set RTC1 Alarm with alarm due time for alarm-manager initialization*/
2386 if (enable_power_on_alarm) {
2387 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
2388 * platform with app-server. because __alarm_power_on(..) fuction don't
2389 * use first parameter internally, we set this value to 0(zero)
2391 __alarm_power_on(0, enable_power_on_alarm, NULL);
2396 static void __initialize_scheduled_alarm_lsit()
2398 _init_scheduled_alarm_list();
2402 static void __hibernation_leave_callback()
2405 __initialize_scheduled_alarm_lsit();
2407 __alarm_clean_list();
2409 __initialize_alarm_list();
2412 static bool __initialize_noti()
2415 int fd = heynoti_init();
2417 ALARM_MGR_EXCEPTION_PRINT("fail to heynoti_init\n");
2420 heynoti_subscribe(fd, "HIBERNATION_LEAVE", __hibernation_leave_callback,
2422 heynoti_attach_handler(fd);
2424 if (vconf_notify_key_changed
2425 (VCONFKEY_SYSTEM_TIMECHANGE, __on_system_time_changed, NULL) < 0) {
2426 ALARM_MGR_LOG_PRINT(
2427 "Failed to add callback for time changing event\n");
2429 /*system state change noti ó¸® */
2435 static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
2436 DBusMessage *message,
2440 if (dbus_message_is_signal
2441 (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
2446 __expired_alarm_t *expire_info;
2448 dbus_message_get_args(message,
2450 DBUS_TYPE_STRING, &service,
2451 DBUS_TYPE_STRING, &old_owner,
2452 DBUS_TYPE_STRING, &new_owner,
2455 for (entry = g_expired_alarm_list; entry; entry = entry->next) {
2457 expire_info = (__expired_alarm_t *) entry->data;
2459 if (strcmp(expire_info->service_name, service)
2461 ALARM_MGR_EXCEPTION_PRINT(
2462 "__alarm_server_filter : "
2463 "service name(%s) alarm_id (%d)\n",
2464 expire_info->service_name,\
2465 expire_info->alarm_id);
2467 __alarm_send_noti_to_application(
2468 expire_info->service_name,
2469 expire_info->alarm_id);
2470 g_expired_alarm_list =
2471 g_slist_remove(g_expired_alarm_list,
2478 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2481 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2484 static bool __initialize_dbus()
2486 GError *error = NULL;
2487 GObject *obj = NULL;
2488 DBusGConnection *connection = NULL;
2490 int request_name_result = 0;
2492 dbus_g_object_type_install_info(ALARM_MANAGER_TYPE_OBJECT,
2493 &dbus_glib_alarm_manager_object_info);
2495 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
2498 ALARM_MGR_EXCEPTION_PRINT("dbus_g_bus_get failed\n");
2502 dbus_error_init(&derror);
2504 request_name_result =
2505 dbus_bus_request_name(dbus_g_connection_get_connection(connection),
2506 "org.tizen.alarm.manager",
2507 DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &derror);
2508 if (dbus_error_is_set(&derror)) { /* failure */
2509 ALARM_MGR_EXCEPTION_PRINT("Failed to dbus_bus_request_name "
2510 "(org.tizen.alarm.manager): %s\n", derror.message);
2511 dbus_error_free(&derror);
2515 if (!(obj = g_object_new(ALARM_MANAGER_TYPE_OBJECT, NULL))) {
2516 ALARM_MGR_EXCEPTION_PRINT("Could not allocate new object\n");
2520 dbus_g_connection_register_g_object(connection,
2521 "/org/tizen/alarm/manager",
2524 /*dbus_bus_add_match (dbus_g_connection_get_connection(connection),
2525 "type='signal',member='NameOwnerChanged'",NULL); */
2527 dbus_bus_add_match(dbus_g_connection_get_connection(connection),
2528 "type='signal',sender='" DBUS_SERVICE_DBUS
2529 "',path='" DBUS_PATH_DBUS
2530 "',interface='" DBUS_INTERFACE_DBUS
2531 "',member='NameOwnerChanged'", NULL);
2533 if (!dbus_connection_add_filter
2534 (dbus_g_connection_get_connection(connection),
2535 __alarm_server_filter, NULL, NULL)) {
2536 ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
2541 alarm_context.bus = connection;
2545 #define ALARMMGR_DB_FILE "/opt/dbspace/.alarmmgr.db"
2546 sqlite3 *alarmmgr_db;
2547 #define QUERY_CREATE_TABLE_ALARMMGR "create table alarmmgr \
2548 (alarm_id integer primary key,\
2552 app_unique_name text,\
2553 app_service_name text,\
2554 app_service_name_mod text,\
2562 day_of_week integer,\
2564 alarm_type integer,\
2565 reserved_info integer,\
2566 dst_service_name text, \
2567 dst_service_name_mod text \
2570 static bool __initialize_db()
2572 char *error_message = NULL;
2575 if (access("/opt/dbspace/.alarmmgr.db", F_OK) == 0) {
2577 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2578 DB_UTIL_REGISTER_HOOK_METHOD);
2580 if (ret != SQLITE_OK) {
2581 ALARM_MGR_EXCEPTION_PRINT(
2582 "====>>>> connect menu_db [%s] failed!\n",
2591 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2592 DB_UTIL_REGISTER_HOOK_METHOD);
2594 if (ret != SQLITE_OK) {
2595 ALARM_MGR_EXCEPTION_PRINT(
2596 "====>>>> connect menu_db [%s] failed!\n",
2602 sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL,\
2604 ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, "
2605 "error message = %s\n", QUERY_CREATE_TABLE_ALARMMGR,
2613 static void __initialize()
2622 fp = fopen("/proc/alarm_boot", "r");
2627 size = fread(&temp, 1, 1, fp);
2632 alarm_boot = atoi(temp);
2640 struct rtc_time rtc_tm;
2643 fd = open(power_rtc, O_RDONLY);
2645 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
2648 retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
2651 fd2 = open(default_rtc, O_RDWR);
2653 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc1\n");
2656 retval = ioctl(fd2, RTC_SET_TIME, &rtc_tm);
2659 __initialize_timer();
2660 if (__initialize_dbus() == false) { /* because dbus's initialize
2661 failed, we cannot continue any more. */
2662 ALARM_MGR_EXCEPTION_PRINT("because __initialize_dbus failed, "
2663 "alarm-server cannot be runned.\n");
2666 __initialize_scheduled_alarm_lsit();
2668 __initialize_alarm_list();
2669 __initialize_noti();
2674 static bool __check_false_alarm()
2676 time_t current_time;
2679 time(¤t_time);
2681 interval = ab_due_time - current_time;
2683 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", \
2684 alarm_context.c_due_time, current_time);
2686 if (interval > 0 && interval <= 30) {
2688 } else if (!poweron_alarm_expired) {
2689 /* originally, first arguement's value was 121(app_id) which means
2690 * alarm_booting ui application.and this application's dbus-service
2691 * name had a org.tizen.alarmboot.ui in a platform with app-server.
2692 * so we set "org.tizen.alarmboot.ui.ALARM" instead of 121.
2694 __alarm_send_noti_to_application(
2695 WAKEUP_ALARMBOOTING_APP_ID, -1);
2705 GMainLoop *mainloop = NULL;
2707 ALARM_MGR_LOG_PRINT("Enter main loop\n");
2709 mainloop = g_main_loop_new(NULL, FALSE);
2715 __check_false_alarm();
2719 g_main_loop_run(mainloop);