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 __on_system_time_external_changed(keynode_t *node, void *data);
138 static void __initialize_timer();
139 static void __initialize_alarm_list();
140 static void __initialize_scheduled_alarm_lsit();
141 static void __hibernation_leave_callback();
142 static bool __initialize_noti();
144 static bool __initialize_dbus();
145 static bool __initialize_db();
146 static void __initialize();
147 static bool __check_false_alarm();
148 static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
149 DBusMessage *message,
152 static void __rtc_set()
154 #ifdef __WAKEUP_USING_RTC__
156 const char *rtc = default_rtc;
158 struct rtc_time rtc_tm;
159 struct rtc_wkalrm rtc_wk;
162 #ifdef _SIMUL /*if build is simulator, we don't need to set
163 RTC because RTC does not work in simulator.*/
164 ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, "
165 "we don't set RTC.\n");
169 fd = open(rtc, O_RDONLY);
171 ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
175 /* Read the RTC time/date */
176 int retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
178 ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed");
183 ALARM_MGR_LOG_PRINT("\n\nCurrent RTC date/time is %d-%d-%d, "
184 "%02d:%02d:%02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
185 rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min,
188 ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d\n", \
189 alarm_context.c_due_time);
191 if (alarm_context.c_due_time != -1) {
192 time_t due_time = alarm_context.c_due_time - 1;
193 gmtime_r(&due_time, &due_tm);
195 rtc_tm.tm_mday = due_tm.tm_mday;
196 rtc_tm.tm_mon = due_tm.tm_mon;
197 rtc_tm.tm_year = due_tm.tm_year;
198 rtc_tm.tm_hour = due_tm.tm_hour;
199 rtc_tm.tm_min = due_tm.tm_min;
200 rtc_tm.tm_sec = due_tm.tm_sec;
201 memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm));
205 ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
206 "%d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_mday,
207 rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,
208 rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
210 retval = ioctl(fd, RTC_WKALM_SET, &rtc_wk);
212 if (errno == ENOTTY) {
213 ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
216 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
220 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
222 /* Enable alarm interrupts */
223 retval = ioctl(fd, RTC_AIE_ON, 0);
225 ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed");
229 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is on");
231 ALARM_MGR_LOG_PRINT("[alarm-server]alarm_context.c_due_time is"
232 "less than 10 sec. RTC alarm does not need to be set\n");
236 #endif /* __WAKEUP_USING_RTC__ */
239 int _set_rtc_time(time_t _time)
245 struct rtc_time rtc_tm = { 0, };
246 const char *rtc0 = power_rtc;
247 const char *rtc1 = default_rtc;
248 struct tm *_tm = NULL;
249 struct tm time_r = { 0, };
251 fd0 = open(rtc0, O_RDONLY);
252 fd1 = open(rtc1, O_RDONLY);
255 ALARM_MGR_LOG_PRINT("error to open /dev/rtc0.");
260 ALARM_MGR_LOG_PRINT("error to open /dev/rtc1.");
264 memset(&rtc_tm, 0, sizeof(struct rtc_time));
267 (void) gmtime_r(&_time, &time_r);
269 /* Write the RTC time/date 2008:05:21 19:20:00 */
272 rtc_tm.tm_mday = time_r.tm_mday;
273 rtc_tm.tm_mon = time_r.tm_mon;
274 rtc_tm.tm_year = time_r.tm_year;
275 rtc_tm.tm_hour = time_r.tm_hour;
276 rtc_tm.tm_min = time_r.tm_min;
280 retval0 = ioctl(fd0, RTC_SET_TIME, &rtc_tm);
285 ALARM_MGR_LOG_PRINT("error to ioctl fd0.");
291 retval1 = ioctl(fd1, RTC_SET_TIME, &rtc_tm);
296 ALARM_MGR_LOG_PRINT("error to ioctl fd1.");
305 bool __alarm_clean_list()
309 for (iter = alarm_context.alarms; iter != NULL;
310 iter = g_slist_next(iter)) {
314 g_slist_free(alarm_context.alarms);
318 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info,
319 alarm_id_t *alarm_id)
322 bool unique_id = false;
323 alarm_info_t *alarm_info = &__alarm_info->alarm_info;
324 __alarm_info_t *entry = NULL;
328 /* FIXME: alarm id must be unique. */
329 __alarm_info->alarm_id = (int)(void *)__alarm_info;
330 ALARM_MGR_LOG_PRINT("__alarm_info->alarm_id is %d", \
331 __alarm_info->alarm_id);
333 while (unique_id == false) {
336 for (iter = alarm_context.alarms; iter != NULL;
337 iter = g_slist_next(iter)) {
339 if (entry->alarm_id == __alarm_info->alarm_id) {
340 __alarm_info->alarm_id++;
348 ALARM_MGR_LOG_PRINT("[alarm-server]: before add\n");
349 for (iter = alarm_context.alarms; iter != NULL;
350 iter = g_slist_next(iter)) {
352 /*ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
356 alarm_context.alarms =
357 g_slist_append(alarm_context.alarms, __alarm_info);
359 ALARM_MGR_LOG_PRINT("[alarm-server]: after add\n");
360 for (iter = alarm_context.alarms; iter != NULL;
361 iter = g_slist_next(iter)) {
363 ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
367 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
368 _save_alarms(__alarm_info);
371 *alarm_id = __alarm_info->alarm_id;
376 static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
377 __alarm_info_t *__alarm_info,
381 alarm_info_t *alarm_info = &__alarm_info->alarm_info;
383 __alarm_info_t *entry = NULL;
385 for (iter = alarm_context.alarms; iter != NULL;
386 iter = g_slist_next(iter)) {
388 if (entry->alarm_id == alarm_id) {
391 __alarm_info->quark_app_unique_name =
392 entry->quark_app_unique_name;
393 __alarm_info->quark_dst_service_name =
394 entry->quark_dst_service_name;
395 memcpy(entry, __alarm_info, sizeof(__alarm_info_t));
403 *error_code = ERR_ALARM_INVALID_ID;
407 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
408 _update_alarms(__alarm_info);
414 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
419 alarm_info_t *alarm_info = NULL;
422 __alarm_info_t *entry = NULL;
425 ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)\n",
428 for (iter = alarm_context.alarms; iter != NULL;
429 iter = g_slist_next(iter)) {
431 if (entry->alarm_id == alarm_id) {
432 alarm_info = &entry->alarm_info;
434 ALARM_MGR_LOG_PRINT("[alarm-server]: "
435 "__alarm_remove_from_list : alarm id(%d)\n",
438 if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
439 _delete_alarms(alarm_id);
442 alarm_context.alarms =
443 g_slist_remove(alarm_context.alarms, iter->data);
450 ALARM_MGR_LOG_PRINT("[alarm-server]: after del\n");
454 *error_code = ERR_ALARM_INVALID_ID;
461 static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
462 __alarm_info_t *__alarm_info)
464 alarm_date_t *start = &alarm_info->start;
465 alarm_date_t *end = &alarm_info->end;
467 struct tm alarm_tm = { 0, };
469 if (start->year != 0) {
470 alarm_tm.tm_year = start->year - 1900;
471 alarm_tm.tm_mon = start->month - 1;
472 alarm_tm.tm_mday = start->day;
474 alarm_tm.tm_hour = 0;
478 __alarm_info->start = mktime(&alarm_tm);
480 __alarm_info->start = 0;
483 if (end->year != 0) {
484 alarm_tm.tm_year = end->year - 1900;
485 alarm_tm.tm_mon = end->month - 1;
486 alarm_tm.tm_mday = end->day;
488 alarm_tm.tm_hour = 23;
489 alarm_tm.tm_min = 59;
490 alarm_tm.tm_sec = 59;
492 __alarm_info->end = mktime(&alarm_tm);
494 __alarm_info->end = 0;
501 static bool alarm_get_tz_info(int *gmt_idx, int *dst)
503 GConfValue *value1 = NULL;
504 GConfValue *value2 = NULL;
505 GConfClient* gConfClient = NULL;
508 gConfClient = gconf_client_get_default();
511 value1 = gconf_client_get(gConfClient, SETTINGS_CLOCKTIMEZONE,
514 ALARM_MGR_LOG_PRINT("__on_system_time_changed:
515 gconf_client_get() failed:
516 error:[%s]\n", err->message);
520 *gmt_idx = gconf_value_get_int(value1);
521 ALARM_MGR_LOG_PRINT("gconf return gmt_idx =%d\n ", *gmt_idx);
523 value2 = gconf_client_get(gConfClient,
524 SETTINGS_DAYLIGHTSTATUS, &err);
526 ALARM_MGR_LOG_PRINT("__on_system_time_changed:
527 gconf_client_get() failed: error:[%s]\n", err->message);
532 *dst = gconf_value_get_int(value2);
533 ALARM_MGR_LOG_PRINT("gconf return dst =%d\n ", *dst);
535 if(gConfClient != NULL) {
536 g_object_unref(gConfClient);
541 ALARM_MGR_LOG_PRINT("check the gconf setting failed!!!!! \n ");
544 gconf_value_free(value1);
548 gconf_value_free(value2);
556 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
559 time_t min_time = -1;
562 __alarm_info_t *entry = NULL;
563 struct tm *p_time = NULL ;
564 struct tm due_time_result ;
565 struct tm fixed_time = { 0, };
567 for (iter = alarm_context.alarms; iter != NULL;
568 iter = g_slist_next(iter)) {
570 alarm_info_t *alarm_info = &(entry->alarm_info);
571 if (alarm_info->alarm_type & ALARM_TYPE_RELATIVE) {
572 /*diff_time ó¸® */
574 entry->due_time += diff_time;
576 alarm_date_t *start = &alarm_info->start; /**< start
578 alarm_date_t *end = &alarm_info->end;;
579 /**< end time of the alarm */
582 p_time = localtime_r(&entry->due_time, &due_time_result);
583 if (p_time != NULL) {
584 start->year = p_time->tm_year + 1900;
585 start->month = p_time->tm_mon + 1;
586 start->day = p_time->tm_mday;
587 start->hour = p_time->tm_hour;
588 start->min = p_time->tm_min;
589 start->sec = p_time->tm_sec;
591 end->year = p_time->tm_year + 1900;
592 end->month = p_time->tm_mon + 1;
593 end->day = p_time->tm_mday;
596 memset(&fixed_time, 0, sizeof(fixed_time));
597 fixed_time.tm_year = p_time->tm_year;
598 fixed_time.tm_mon = p_time->tm_mon;
599 fixed_time.tm_mday = p_time->tm_mday;
600 fixed_time.tm_hour = 0;
601 fixed_time.tm_min = 0;
602 fixed_time.tm_sec = 0;
604 entry->start = mktime(&fixed_time);
606 fixed_time.tm_hour = 23;
607 fixed_time.tm_min = 59;
608 fixed_time.tm_sec = 59;
610 entry->end = mktime(&fixed_time);
612 ALARM_MGR_LOG_PRINT("alarm_info->alarm_type is "
613 "ALARM_TYPE_RELATIVE\n");
615 _update_alarms(entry);
618 _alarm_next_duetime(entry);
619 ALARM_MGR_LOG_PRINT("entry->due_time is %d\n", entry->due_time);
624 for (iter = alarm_context.alarms; iter != NULL;
625 iter = g_slist_next(iter)) {
627 due_time = entry->due_time;
631 ALARM_MGR_LOG_PRINT("alarm[%d] with duetime(%u) at "
632 "current(%u)\n", entry->alarm_id, due_time, current_time);
633 if (due_time == 0) { /* 0 means this alarm has been
638 interval = difftime(due_time, current_time);
641 ALARM_MGR_LOG_PRINT("this may be error.. alarm[%d]\n", \
646 interval = difftime(due_time, min_time);
648 if ((interval < 0) || min_time == -1) {
654 alarm_context.c_due_time = min_time;
659 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
660 int pid,char *bundle_data, int *error_code){
665 char due_time_r[100] = { 0 };
666 char proc_file[512] = { 0 };
667 char process_name[512] = { 0 };
668 char app_name[512] = { 0 };
670 char *proc_name_ptr = NULL;
675 __alarm_info_t *__alarm_info = NULL;
677 __alarm_info = malloc(sizeof(__alarm_info_t));
678 if (__alarm_info == NULL) {
679 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc "
680 "failed. it seems to be OOM\n", pid);
681 *error_code = -1; /* -1 means that system
682 failed internally. */
685 __alarm_info->pid = pid;
686 __alarm_info->alarm_id = -1;
689 /* we should consider to check whether pid is running or Not
691 memset(process_name, '\0', 512);
692 memset(proc_file, '\0', 512);
693 snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
695 fd = open(proc_file, O_RDONLY);
696 if (fd < 0) { /* failure */
697 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
698 "killed, so we failed to get proc file(%s) and do not create "
699 "alarm_info\n", pid, proc_file);
700 *error_code = -1; /*-1 means that system failed
705 ret = read(fd, process_name, 512);
709 ALARM_MGR_EXCEPTION_PRINT("Unable to get application name\n");
714 while (process_name[i] != '\0') {
715 if (process_name[i] == ' ') {
716 process_name[i] = '\0';
722 word = strtok_r(process_name, "/", &proc_name_ptr);
723 while (word != NULL) {
724 memset(app_name, 0, 512);
725 snprintf(app_name, 512, "%s", word);
726 word = strtok_r(NULL, "/", &proc_name_ptr);
728 __alarm_info->quark_app_unique_name =
729 g_quark_from_string(app_name);
732 __alarm_info->quark_bundle=g_quark_from_string(bundle_data);
733 __alarm_info->quark_app_service_name = g_quark_from_string("null");
734 __alarm_info->quark_dst_service_name = g_quark_from_string("null");
735 __alarm_info->quark_app_service_name_mod = g_quark_from_string("null");
736 __alarm_info->quark_dst_service_name_mod = g_quark_from_string("null");
738 __alarm_set_start_and_end_time(alarm_info, __alarm_info);
739 memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
743 if (alarm_context.c_due_time < current_time) {
744 ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
745 "(%d) is less than current time(%d)", alarm_context.c_due_time,
747 alarm_context.c_due_time = -1;
750 due_time = _alarm_next_duetime(__alarm_info);
751 if (__alarm_add_to_list(__alarm_info, alarm_id) == false) {
758 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
759 "due_time is 0, alarm(%d) \n", *alarm_id);
761 } else if (current_time == due_time) {
762 ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
763 "current_time(%d) is same as due_time(%d)", current_time,
766 }else if (difftime(due_time, current_time) < 0){
767 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);
770 localtime_r(&due_time, &ts_ret);
771 strftime(due_time_r, 30, "%c", &ts_ret);
772 ALARM_MGR_LOG_PRINT("[alarm-server]:Create a new alarm: "
773 "alarm(%d) due_time(%s)", *alarm_id,
777 ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
778 "due_time(%d)", alarm_context.c_due_time, due_time);
780 if (alarm_context.c_due_time == -1
781 || due_time < alarm_context.c_due_time) {
782 _clear_scheduled_alarm_list();
783 _add_to_scheduled_alarm_list(__alarm_info);
784 _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
786 alarm_context.c_due_time = due_time;
788 } else if (due_time == alarm_context.c_due_time) {
789 _add_to_scheduled_alarm_list(__alarm_info);
797 if (enable_power_on_alarm) {
798 __alarm_power_on(0, enable_power_on_alarm, NULL);
806 static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
807 int pid, char *app_service_name, char *app_service_name_mod,
808 const char *dst_service_name,const char *dst_service_name_mod, int *error_code)
813 char proc_file[256] = { 0 };
814 char process_name[512] = { 0 };
815 char app_name[256] = { 0 };
817 char *proc_name_ptr = NULL;
819 __alarm_info_t *__alarm_info = NULL;
821 __alarm_info = malloc(sizeof(__alarm_info_t));
822 if (__alarm_info == NULL) {
823 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid=%d, malloc "
824 "failed. it seems to be OOM\n", pid);
825 *error_code = -1; /* -1 means that system
826 failed internally. */
829 __alarm_info->pid = pid;
830 __alarm_info->alarm_id = -1;
832 /* we should consider to check whether pid is running or Not
834 memset(process_name, '\0', 512);
835 memset(proc_file, '\0', 256);
836 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
841 fd = open(proc_file, O_RDONLY);
842 if (fd < 0) { /* failure */
843 __alarm_info->quark_app_unique_name =
844 g_quark_from_string("unknown");
845 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
846 "killed, so we failed to get proc file(%s) and do not create "
847 "alarm_info\n", pid, proc_file);
848 *error_code = -1; /*-1 means that system failed
853 ret = read(fd, process_name, 512);
855 while (process_name[i] != '\0') {
856 if (process_name[i] == ' ') {
857 process_name[i] = '\0';
862 /* if (readlink(proc_file, process_name, 256)!=-1) */
865 word = strtok_r(process_name, "/", &proc_name_ptr);
866 while (word != NULL) {
867 memset(app_name, 0, 256);
868 snprintf(app_name, 256, "%s", word);
869 word = strtok_r(NULL, "/", &proc_name_ptr);
871 __alarm_info->quark_app_unique_name =
872 g_quark_from_string(app_name);
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 rtc_time rtc_tm = { 0, };
1150 struct tm min_time_r = { 0, };
1154 enable_power_on_alarm = on_off;
1155 /*_update_power_on(on_off); */ /*currently its empty*/
1157 fd = open(power_rtc, O_RDONLY);
1159 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
1163 if (on_off == true) {
1164 if (_alarm_find_mintime_power_on(&min_time) == true) {
1166 ab_due_time = min_time;
1168 min_time = min_time - 60;
1170 time(¤t_time);
1172 if (min_time <= current_time)
1173 min_time = current_time + 5;
1175 gmtime_r(&min_time, &min_time_r);
1177 ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
1179 min_time_r.tm_year,\
1181 min_time_r.tm_mday,\
1182 min_time_r.tm_hour,\
1184 ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
1186 min_time_r.tm_year,\
1188 min_time_r.tm_mday,\
1189 min_time_r.tm_hour,\
1192 rtc_tm.tm_mday = min_time_r.tm_mday;
1193 rtc_tm.tm_mon = min_time_r.tm_mon;
1194 rtc_tm.tm_year = min_time_r.tm_year;
1195 rtc_tm.tm_hour = min_time_r.tm_hour;
1196 rtc_tm.tm_min = min_time_r.tm_min;
1197 rtc_tm.tm_sec = min_time_r.tm_sec;
1198 /*set_info.time_zone = 0; */
1199 /*set_info.u_interval.day_of_week = 0; */
1201 /*ALARM_MGR_LOG_PRINT("####__alarm_power_on : %d %d
1202 %d %d %d\n",set_info.year,set_info.month,set_info.day,
1203 set_info.hour,set_info.minute); */
1205 ALARM_MGR_LOG_PRINT("due_time : %d \n", ab_due_time);
1207 ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
1208 "%d-%d-%d, %02d:%02d:%02d.\n",
1209 rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
1210 rtc_tm.tm_year + 1900, rtc_tm.tm_hour,
1211 rtc_tm.tm_min, rtc_tm.tm_sec);
1213 retval = ioctl(fd, RTC_ALM_SET, &rtc_tm);
1215 if (errno == ENOTTY) {
1216 ALARM_MGR_EXCEPTION_PRINT(
1217 "\n...Alarm IRQs not supported.\n");
1219 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
1223 ALARM_MGR_LOG_PRINT("[alarm-server]RTC "
1224 "alarm(POWER ON) is setted");
1226 /* Enable alarm interrupts */
1227 retval = ioctl(fd, RTC_AIE_ON, 0);
1229 ALARM_MGR_EXCEPTION_PRINT(
1230 "RTC_AIE_ON ioctl failed");
1234 ALARM_MGR_LOG_PRINT("[alarm-server]RTC(POWER ON) "
1238 retval = ioctl(fd, RTC_AIE_OFF, 0);
1240 ALARM_MGR_LOG_PRINT("__alarm_power_on : off\n");
1241 retval = ioctl(fd, RTC_AIE_OFF, 0);
1245 #endif /* #ifdef __ALARM_BOOT */
1250 static bool __alarm_power_off(int app_id, int *error_code)
1254 #endif /* #ifdef __ALARM_BOOT */
1258 static bool __alarm_check_next_duetime(int app_id, int *error_code)
1261 time_t current_time;
1264 time(¤t_time);
1266 interval = ab_due_time - current_time;
1268 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", ab_due_time,
1271 if (interval > 0 && interval <= 60)
1275 #else /* #ifdef __ALARM_BOOT */
1280 static void __alarm_send_noti_to_application(const char *app_service_name,
1281 alarm_id_t alarm_id)
1285 char service_name[MAX_SERVICE_NAME_LEN];
1286 char object_name[MAX_SERVICE_NAME_LEN];
1288 DBusMessage *message;
1289 DBusMessageIter iter;
1291 if (app_service_name == NULL || strlen(app_service_name) == 0) {
1292 ALARM_MGR_EXCEPTION_PRINT("This alarm destination is "
1296 memset(service_name, 0, MAX_SERVICE_NAME_LEN);
1297 memcpy(service_name, app_service_name, strlen(app_service_name));
1299 snprintf(object_name, MAX_SERVICE_NAME_LEN,
1300 "/org/tizen/alarm/client");
1302 ALARM_MGR_LOG_PRINT("[alarm server][send expired_alarm(alarm_id=%d)to"
1303 "app_service_name(%s), object_name(%s), interface_name(%s)]\n",\
1304 alarm_id, service_name, object_name, "org.tizen.alarm.client");
1306 message = dbus_message_new_method_call(service_name,
1308 "org.tizen.alarm.client",
1310 if (message == NULL) {
1311 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1312 "dbus_message_new_method_call faild. maybe OOM!.\n");
1313 ALARM_MGR_EXCEPTION_PRINT("[alarm server] so we cannot "
1314 "send expired alarm to %s\n", service_name);
1318 dbus_message_set_no_reply(message, TRUE);
1319 /* if(service_name[0]==':') */
1320 /* we don't need auto activation in a case that
1321 destination_app_service_name starts with a charactor like (:) */
1322 dbus_message_set_auto_start(message, FALSE);
1324 dbus_message_iter_init_append(message, &iter);
1325 if (!dbus_message_iter_append_basic
1326 (&iter, DBUS_TYPE_INT32, &alarm_id)) {
1327 dbus_message_unref(message);
1328 ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
1329 "dbus_message_iter_append_basic faild. maybe OOM!.\n");
1333 dbus_connection_send(dbus_g_connection_get_connection
1334 (alarm_context.bus), message, NULL);
1335 dbus_connection_flush(dbus_g_connection_get_connection
1336 (alarm_context.bus));
1337 dbus_message_unref(message);
1341 static void __alarm_expired()
1343 const char *destination_app_service_name = NULL;
1344 alarm_id_t alarm_id = -1;
1346 __alarm_info_t *__alarm_info = NULL;
1347 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 (time changed to past)\n");
1368 // 3 seconds is maximum permitted delay from timer expire to this function
1369 if (alarm_context.c_due_time + 3 < current_time) {
1370 ALARM_MGR_LOG_PRINT("[alarm-server]: False Alarm (time changed to future)\n");
1374 GSList *iter = NULL;
1375 __scheduled_alarm_t *alarm = NULL;
1377 for (iter = g_scheduled_alarm_list; iter != NULL;
1378 iter = g_slist_next(iter)) {
1380 alarm_id = alarm->alarm_id;
1382 __alarm_info = alarm->__alarm_info;
1384 app_pid = __alarm_info->pid;
1387 (g_quark_to_string(__alarm_info->quark_bundle),
1390 b_len = strlen(g_quark_to_string(__alarm_info->quark_bundle));
1392 b = bundle_decode((bundle_raw *)g_quark_to_string(__alarm_info->quark_bundle), b_len);
1396 ALARM_MGR_EXCEPTION_PRINT("Error!!!..Unable to decode the bundle!!\n");
1400 snprintf(alarm_id_val,31,"%d",alarm_id);
1402 if (bundle_add(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){
1403 ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n");
1407 appid = appsvc_get_appid(b);
1408 if( (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_NOLAUNCH) && !aul_app_is_running(appid))
1410 ALARM_MGR_EXCEPTION_PRINT("This alarm is ignored\n");
1414 if ( appsvc_run_service(b, 0, NULL, NULL) < 0)
1416 ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
1420 ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
1431 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1433 ALARM_MGR_LOG_PRINT("[alarm-server]:destination is "
1434 "null, so we send expired alarm to %s(%u)\n",\
1436 __alarm_info->quark_app_service_name),
1437 __alarm_info->quark_app_service_name);
1438 destination_app_service_name = g_quark_to_string(
1439 __alarm_info->quark_app_service_name_mod);
1441 ALARM_MGR_LOG_PRINT("[alarm-server]:destination "
1444 __alarm_info->quark_dst_service_name),
1445 __alarm_info->quark_dst_service_name);
1446 destination_app_service_name = g_quark_to_string(
1447 __alarm_info->quark_dst_service_name_mod);
1451 /* orginally this code had if(__alarm_info->app_id==21) in a
1452 platform with app-server. */
1453 /*if(__alarm_info->quark_dst_service_name ==
1454 g_quark_from_string (WAKEUP_ALARM_APP_ID)) */
1456 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1457 WAKEUP_ALARM_APP_ID) == 0) {
1459 fd = open(power_rtc, O_RDONLY);
1461 ALARM_MGR_LOG_PRINT("cannot open /dev/rtc0\n");
1463 ioctl(fd, RTC_AIE_OFF, 0);
1470 * we should consider a situation that
1471 * destination_app_service_name is owner_name like (:xxxx) and
1472 * application's pid which registered this alarm was killed.In that case,
1473 * we don't need to send the expire event because the process was killed.
1474 * this causes needless message to be sent.
1476 ALARM_MGR_LOG_PRINT("[alarm-server]: "
1477 "destination_app_service_name :%s, app_pid=%d\n",
1478 destination_app_service_name, app_pid);
1479 /* the following is a code that checks the above situation.
1480 please verify this code. */
1482 if (dbus_bus_name_has_owner(
1483 dbus_g_connection_get_connection(alarm_context.bus),
1484 destination_app_service_name, NULL) == FALSE) {
1485 __expired_alarm_t *expire_info;
1486 char appid[MAX_SERVICE_NAME_LEN] = { 0, };
1487 char alarm_id_str[32] = { 0, };
1489 expire_info = malloc(sizeof(__expired_alarm_t));
1490 if (G_UNLIKELY(NULL == expire_info)){
1491 ALARM_MGR_ASSERT_PRINT("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n");
1494 memset(expire_info, '\0', MAX_SERVICE_NAME_LEN);
1495 strncpy(expire_info->service_name,
1496 destination_app_service_name,
1497 MAX_SERVICE_NAME_LEN-1);
1498 expire_info->alarm_id = alarm_id;
1499 g_expired_alarm_list =
1500 g_slist_append(g_expired_alarm_list, expire_info);
1504 (g_quark_to_string(__alarm_info->quark_dst_service_name),
1506 strncpy(appid,g_quark_to_string(__alarm_info->quark_app_service_name),strlen(g_quark_to_string(__alarm_info->quark_app_service_name))-6);
1510 strncpy(appid,g_quark_to_string(__alarm_info->quark_dst_service_name),strlen(g_quark_to_string(__alarm_info->quark_dst_service_name))-6);
1513 snprintf(alarm_id_str, 31, "%d", alarm_id);
1515 ALARM_MGR_LOG_PRINT("before aul_launch appid(%s) "
1516 "alarm_id_str(%s)\n", appid, alarm_id_str);
1519 kb = bundle_create();
1520 bundle_add(kb, "__ALARM_MGR_ID", alarm_id_str);
1521 aul_launch_app(appid, kb);
1524 ALARM_MGR_LOG_PRINT(
1525 "before alarm_send_noti_to_application\n");
1526 __alarm_send_noti_to_application(
1527 destination_app_service_name, alarm_id);
1530 ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application\n");
1532 /* if( !(__alarm_info->alarm_info.alarm_type
1533 & ALARM_TYPE_VOLATILE) ) {
1534 __alarm_remove_from_list(__alarm_info->pid,
1538 if (__alarm_info->alarm_info.mode.repeat
1539 == ALARM_REPEAT_MODE_ONCE) {
1540 /* _alarm_next_duetime(__alarm_info);*/
1541 /* _update_alarms(__alarm_info);*/
1542 __alarm_remove_from_list(__alarm_info->pid, alarm_id,
1546 _alarm_next_duetime(__alarm_info);
1547 /* _update_alarms(__alarm_info);*/
1553 _clear_scheduled_alarm_list();
1554 alarm_context.c_due_time = -1;
1556 ALARM_MGR_LOG_PRINT("[alarm-server]: Leave \n");
1559 static gboolean __alarm_handler_idle()
1561 if (g_dummy_timer_is_set == true) {
1562 ALARM_MGR_LOG_PRINT("dummy alarm timer has expired\n");
1564 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1565 ALARM_MGR_LOG_PRINT("__alarm_handler \n");
1577 if (enable_power_on_alarm) {
1578 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
1579 *in a platform with app-server.because __alarm_power_on(..) fuction
1580 *don't use first parameter internally, we set this value to 0(zero)
1582 __alarm_power_on(0, enable_power_on_alarm, NULL);
1585 pm_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
1590 static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext)
1593 pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
1595 /* we moved __alarm_expired() function to __alarm_handler_idle GSource
1596 because of signal safety. */
1597 g_idle_add_full(G_PRIORITY_HIGH_IDLE, __alarm_handler_idle, NULL, NULL);
1600 static void __clean_registry()
1603 /*TODO:remove all db entries */
1606 static bool __alarm_manager_reset()
1609 _alarm_disable_timer(alarm_context);
1611 __alarm_clean_list();
1613 _clear_scheduled_alarm_list();
1619 static void __on_system_time_changed(keynode_t *node, void *data)
1625 _alarm_disable_timer(alarm_context);
1628 _time = vconf_keynode_get_int(node);
1630 vconf_get_int(VCONFKEY_SYSTEM_TIMECHANGE, (int *)&_time);
1634 diff_time = difftime(_time, before);
1638 ALARM_MGR_ASSERT_PRINT("diff_time is %f\n", diff_time);
1640 ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed\n");
1641 ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n",
1642 alarm_context.c_due_time);
1646 vconf_set_dbl(VCONFKEY_SYSTEM_TIMEDIFF, diff_time);
1647 vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
1649 __alarm_update_due_time_of_all_items_in_list(diff_time);
1651 ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n",
1652 alarm_context.c_due_time);
1653 _clear_scheduled_alarm_list();
1658 if (enable_power_on_alarm) {
1659 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
1660 APP_ID) in a platform with app-server. because _alarm_power_
1661 on(..) fuction don't use first parameter internally, we set
1662 this value to 0(zero)
1664 __alarm_power_on(0, enable_power_on_alarm, NULL);
1670 static void __on_system_time_external_changed(keynode_t *node, void *data)
1673 time_t cur_time = 0;
1675 _alarm_disable_timer(alarm_context);
1678 diff_time = vconf_keynode_get_dbl(node);
1680 vconf_get_dbl(VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, &diff_time);
1685 ALARM_MGR_ASSERT_PRINT("diff_time is %f\n", diff_time);
1687 ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed externally\n");
1688 ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n",
1689 alarm_context.c_due_time);
1691 // set rtc time only because the linux time is set externally
1693 _set_rtc_time(cur_time);
1695 vconf_set_dbl(VCONFKEY_SYSTEM_TIMEDIFF, diff_time);
1696 vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
1698 __alarm_update_due_time_of_all_items_in_list(diff_time);
1700 ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n",
1701 alarm_context.c_due_time);
1702 _clear_scheduled_alarm_list();
1707 if (enable_power_on_alarm) {
1708 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
1709 APP_ID) in a platform with app-server. because _alarm_power_
1710 on(..) fuction don't use first parameter internally, we set
1711 this value to 0(zero)
1713 __alarm_power_on(0, enable_power_on_alarm, NULL);
1719 static void __on_time_zone_changed(keynode_t *node, void *data)
1721 double diff_time = 0;
1723 _alarm_disable_timer(alarm_context);
1727 ALARM_MGR_LOG_PRINT("[alarm-server] time zone has been changed\n");
1728 ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n", alarm_context.c_due_time);
1730 __alarm_update_due_time_of_all_items_in_list(diff_time);
1732 ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n", alarm_context.c_due_time);
1733 _clear_scheduled_alarm_list();
1738 if (enable_power_on_alarm) {
1739 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
1740 APP_ID) in a platform with app-server. because _alarm_power_
1741 on(..) fuction don't use first parameter internally, we set
1742 this value to 0(zero)
1744 __alarm_power_on(0, enable_power_on_alarm, NULL);
1751 gboolean alarm_manager_alarm_set_rtc_time(void *pObject, int pid,
1752 int year, int mon, int day,
1753 int hour, int min, int sec, char *e_cookie,
1755 guchar *cookie = NULL;
1758 gboolean result = true;
1761 const char *rtc = power_rtc;
1763 struct rtc_time rtc_tm = {0,};
1764 struct rtc_wkalrm rtc_wk;
1765 struct tm *alarm_tm = NULL;
1766 struct tm due_tm = {0,};
1770 *return_code = ALARMMGR_RESULT_SUCCESS;
1773 cookie = g_base64_decode(e_cookie, &size);
1777 *return_code = ERR_ALARM_NO_PERMISSION;
1778 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
1782 call_gid = security_server_get_gid("alarm");
1784 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1786 retval = security_server_check_privilege((const char *)cookie, call_gid);
1788 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1789 ALARM_MGR_EXCEPTION_PRINT(
1790 "%s", "access has been denied\n");
1792 ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
1794 *return_code = ERR_ALARM_NO_PERMISSION;
1798 /*extract day of the week, day in the year &
1799 daylight saving time from system*/
1802 alarm_tm = localtime(&ctime);
1804 alarm_tm->tm_year = year;
1805 alarm_tm->tm_mon = mon;
1806 alarm_tm->tm_mday = day;
1807 alarm_tm->tm_hour = hour;
1808 alarm_tm->tm_min = min;
1809 alarm_tm->tm_sec = sec;
1811 /*convert to calendar time representation*/
1812 time_t rtc_time = mktime(alarm_tm);
1814 /*convert to Coordinated Universal Time (UTC)*/
1815 gmtime_r(&rtc_time, &due_tm);
1817 fd = open(rtc, O_RDONLY);
1819 ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
1821 *return_code = ERR_ALARM_SYSTEM_FAIL;
1825 /* Read the RTC time/date */
1826 retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
1828 ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed");
1831 *return_code = ERR_ALARM_SYSTEM_FAIL;
1835 rtc_tm.tm_mday = due_tm.tm_mday;
1836 rtc_tm.tm_mon = due_tm.tm_mon;
1837 rtc_tm.tm_year = due_tm.tm_year;
1838 rtc_tm.tm_hour = due_tm.tm_hour;
1839 rtc_tm.tm_min = due_tm.tm_min;
1840 rtc_tm.tm_sec = due_tm.tm_sec;
1842 memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm));
1847 retval = ioctl(fd, RTC_WKALM_BOOT_SET, &rtc_wk);
1849 if (errno == ENOTTY) {
1850 ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
1853 ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
1856 *return_code = ERR_ALARM_SYSTEM_FAIL;
1859 ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
1860 /* Enable alarm interrupts */
1861 retval = ioctl(fd, RTC_AIE_ON, 0);
1863 ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed");
1865 *return_code = ERR_ALARM_SYSTEM_FAIL;
1880 gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid,
1882 int start_month, int start_day,
1883 int start_hour, int start_min,
1884 int start_sec, int end_year, int end_month,
1885 int end_day, int mode_day_of_week,
1886 int mode_repeat, int alarm_type,
1888 char *bundle_data, char *e_cookie,
1889 int *alarm_id, int *return_code)
1891 alarm_info_t alarm_info;
1892 guchar *cookie = NULL;
1896 gboolean result = true;
1898 alarm_info.start.year = start_year;
1899 alarm_info.start.month = start_month;
1900 alarm_info.start.day = start_day;
1901 alarm_info.start.hour = start_hour;
1902 alarm_info.start.min = start_min;
1903 alarm_info.start.sec = start_sec;
1905 alarm_info.end.year = end_year;
1906 alarm_info.end.month = end_month;
1907 alarm_info.end.day = end_day;
1909 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1910 alarm_info.mode.repeat = mode_repeat;
1912 alarm_info.alarm_type = alarm_type;
1913 alarm_info.reserved_info = reserved_info;
1917 cookie = g_base64_decode(e_cookie, &size);
1921 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
1925 call_gid = security_server_get_gid("alarm");
1927 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1929 retval = security_server_check_privilege((const char *)cookie, call_gid);
1931 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1932 ALARM_MGR_EXCEPTION_PRINT(
1933 "%s", "access has been denied\n");
1935 ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
1940 result = __alarm_create_appsvc(&alarm_info, alarm_id, pid,
1941 bundle_data, return_code);
1942 if (false == result)
1944 ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm!\n");
1956 gboolean alarm_manager_alarm_create(void *pObject, int pid,
1957 char *app_service_name, char *app_service_name_mod, int start_year,
1958 int start_month, int start_day,
1959 int start_hour, int start_min,
1960 int start_sec, int end_year, int end_month,
1961 int end_day, int mode_day_of_week,
1962 int mode_repeat, int alarm_type,
1964 char *reserved_service_name, char *reserved_service_name_mod, char *e_cookie,
1965 int *alarm_id, int *return_code)
1967 alarm_info_t alarm_info;
1973 alarm_info.start.year = start_year;
1974 alarm_info.start.month = start_month;
1975 alarm_info.start.day = start_day;
1976 alarm_info.start.hour = start_hour;
1977 alarm_info.start.min = start_min;
1978 alarm_info.start.sec = start_sec;
1980 alarm_info.end.year = end_year;
1981 alarm_info.end.month = end_month;
1982 alarm_info.end.day = end_day;
1984 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
1985 alarm_info.mode.repeat = mode_repeat;
1987 alarm_info.alarm_type = alarm_type;
1988 alarm_info.reserved_info = reserved_info;
1992 cookie = g_base64_decode(e_cookie, &size);
1993 call_gid = security_server_get_gid("alarm");
1995 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
1997 retval = security_server_check_privilege((const char *)cookie, call_gid);
1999 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
2000 ALARM_MGR_EXCEPTION_PRINT(
2001 "%s", "access has been denied\n");
2003 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
2009 /* return valule and return_code should be checked */
2010 __alarm_create(&alarm_info, alarm_id, pid, app_service_name,app_service_name_mod,
2011 reserved_service_name, reserved_service_name_mod, return_code);
2019 gboolean alarm_manager_alarm_delete(void *pObject, int pid, alarm_id_t alarm_id,
2020 char *e_cookie, int *return_code)
2027 cookie = g_base64_decode(e_cookie, &size);
2028 call_gid = security_server_get_gid("alarm");
2030 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
2032 retval = security_server_check_privilege((const char *)cookie, call_gid);
2034 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
2035 ALARM_MGR_EXCEPTION_PRINT("%s",
2036 "access has been denied\n");
2038 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
2044 __alarm_delete(pid, alarm_id, return_code);
2052 gboolean alarm_manager_alarm_power_on(void *pObject, int pid, bool on_off,
2056 return __alarm_power_on(pid, on_off, return_code);
2059 gboolean alarm_manager_alarm_power_off(void *pObject, int pid, int *return_code)
2062 return __alarm_power_off(pid, return_code);
2065 bool alarm_manager_alarm_check_next_duetime(void *pObject, int pid,
2068 return __alarm_check_next_duetime(pid, return_code);
2071 gboolean alarm_manager_alarm_update(void *pObject, int pid,
2072 char *app_service_name, alarm_id_t alarm_id,
2073 int start_year, int start_month,
2074 int start_day, int start_hour,
2075 int start_min, int start_sec, int end_year,
2076 int end_month, int end_day,
2077 int mode_day_of_week, int mode_repeat,
2078 int alarm_type, int reserved_info,
2081 alarm_info_t alarm_info;
2082 alarm_info.start.year = start_year;
2083 alarm_info.start.month = start_month;
2084 alarm_info.start.day = start_day;
2085 alarm_info.start.hour = start_hour;
2086 alarm_info.start.min = start_min;
2087 alarm_info.start.sec = start_sec;
2089 alarm_info.end.year = end_year;
2090 alarm_info.end.month = end_month;
2091 alarm_info.end.day = end_day;
2093 alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
2094 alarm_info.mode.repeat = mode_repeat;
2096 alarm_info.alarm_type = alarm_type;
2097 alarm_info.reserved_info = reserved_info;
2101 __alarm_update(pid, app_service_name, alarm_id, &alarm_info,
2107 gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid,
2111 GSList *gs_iter = NULL;
2112 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is
2113 converted to quark value. */
2114 char proc_file[256] = { 0 };
2115 char process_name[512] = { 0 };
2116 char app_name[256] = { 0 };
2118 __alarm_info_t *entry = NULL;
2119 char *proc_name_ptr = NULL;
2124 /* we should consider to check whether pid is running or Not
2126 memset(process_name, '\0', 512);
2127 memset(proc_file, '\0', 256);
2128 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
2133 fd = open(proc_file, O_RDONLY);
2134 if (fd < 0) { /* failure */
2135 quark_app_unique_name = g_quark_from_string("unknown");
2136 memcpy(app_name, "unknown", strlen("unknown") + 1);
2138 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
2139 "killed, so we failed to get proc file(%s) \n",
2141 *return_code = -1; /* -1 means that system
2142 failed internally. */
2145 ret = read(fd, process_name, 512);
2147 while (process_name[i] != '\0') {
2148 if (process_name[i] == ' ') {
2149 process_name[i] = '\0';
2154 /*if (readlink(proc_file, process_name, 256)!=-1) */
2157 word = strtok_r(process_name, "/", &proc_name_ptr);
2158 while (word != NULL) {
2159 memset(app_name, 0, 256);
2160 snprintf(app_name, 256, "%s", word);
2161 word = strtok_r(NULL, "/", &proc_name_ptr);
2163 quark_app_unique_name = g_quark_from_string(app_name);
2166 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
2169 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2170 gs_iter = g_slist_next(gs_iter)) {
2171 entry = gs_iter->data;
2172 ALARM_MGR_LOG_PRINT("alarm_manager_alarm_get_number_of_ids(): "
2173 "app_name=%s,quark_app_unique_name=%s\n",
2174 app_name, g_quark_to_string(entry->quark_app_unique_name));
2177 g_quark_to_string(entry->quark_app_unique_name)) == 0
2178 && strcmp(app_name, "unknown") != 0) {
2180 ALARM_MGR_LOG_PRINT("inc number of alarms of app "
2181 "(pid:%d, name:%s) is %d\n",
2182 pid, app_name, *num_of_ids);
2186 ALARM_MGR_LOG_PRINT("number of alarms of app(pid:%d, name:%s) is %d\n",
2187 pid, app_name, *num_of_ids);
2191 gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid,
2192 int max_number_of_ids,
2193 GArray **arr, int *num_of_ids,
2196 GSList *gs_iter = NULL;
2197 GQuark quark_app_unique_name; /* the fullpath of pid(pid) is converted
2199 char proc_file[256] = { 0 };
2200 char process_name[512] = { 0 };
2201 char app_name[256] = { 0 };
2203 __alarm_info_t *entry = NULL;
2205 char *proc_name_ptr = NULL;
2209 GArray *garray = NULL;
2213 garray = g_array_new(false, true, sizeof(alarm_id_t));
2215 /* we should check that there is a resource leak.
2216 * Now we don't have free code for g_array_new().
2218 if (max_number_of_ids <= 0) {
2220 ALARM_MGR_EXCEPTION_PRINT("called for pid(%d), but "
2221 "max_number_of_ids(%d) is less than 0.\n",
2222 pid, max_number_of_ids);
2226 /* we should consider to check whether pid is running or Not
2228 memset(process_name, '\0', 512);
2229 memset(proc_file, '\0', 256);
2230 snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
2232 fd = open(proc_file, O_RDONLY);
2233 if (fd < 0) { /* failure */
2234 quark_app_unique_name = g_quark_from_string("unknown");
2235 memcpy(app_name, "unknown", strlen("unknown") + 1);
2237 ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
2238 "killed, so we failed to get proc file(%s)\n", pid, proc_file);
2240 /* -1 means that system failed internally. */
2243 ret = read(fd, process_name, 512);
2245 while (process_name[i] != '\0') {
2246 if (process_name[i] == ' ') {
2247 process_name[i] = '\0';
2252 /* if (readlink(proc_file, process_name, 256)!=-1) */
2255 word = strtok_r(process_name, "/", &proc_name_ptr);
2256 while (word != NULL) {
2257 memset(app_name, 0, 256);
2258 snprintf(app_name, 256, "%s", word);
2259 word = strtok_r(NULL, "/", &proc_name_ptr);
2261 quark_app_unique_name = g_quark_from_string(app_name);
2264 ALARM_MGR_LOG_PRINT("called for app(pid:%d, name=%s)\n",
2267 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2268 gs_iter = g_slist_next(gs_iter)) {
2269 entry = gs_iter->data;
2272 g_quark_to_string(entry->quark_app_unique_name)) == 0
2273 && strcmp(app_name, "unknown") != 0) {
2274 g_array_append_val(garray, entry->alarm_id);
2278 *num_of_ids = index;
2285 gboolean alarm_manager_alarm_get_appsvc_info(void *pObject, int pid, alarm_id_t alarm_id,
2286 char *e_cookie, gchar **b_data, int *return_code)
2290 GSList *gs_iter = NULL;
2291 __alarm_info_t *entry = NULL;
2293 guchar *cookie = NULL;
2298 ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid,
2301 cookie = g_base64_decode(e_cookie, &size);
2305 *return_code = ERR_ALARM_SYSTEM_FAIL;
2306 ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
2309 call_gid = security_server_get_gid("alarm");
2311 ALARM_MGR_LOG_PRINT("call_gid : %d\n", call_gid);
2313 retval = security_server_check_privilege((const char *)cookie, call_gid);
2315 if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
2316 ALARM_MGR_EXCEPTION_PRINT(
2317 "%s", "access has been denied\n");
2319 ALARM_MGR_EXCEPTION_PRINT("%s", "Error has occurred\n");
2322 *return_code = ERR_ALARM_NO_PERMISSION;
2333 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2334 gs_iter = g_slist_next(gs_iter)) {
2335 entry = gs_iter->data;
2336 if (entry->alarm_id == alarm_id) {
2338 *b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
2344 if ( *b_data && strlen(*b_data) == 4 && strncmp(*b_data,"null",4) == 0){
2345 ALARM_MGR_EXCEPTION_PRINT("Regular alarm,not svc alarm");
2347 *return_code = ERR_ALARM_INVALID_TYPE;
2351 *return_code = ERR_ALARM_INVALID_ID;
2360 gboolean alarm_manager_alarm_get_info(void *pObject, int pid,
2361 alarm_id_t alarm_id, int *start_year,
2362 int *start_month, int *start_day,
2363 int *start_hour, int *start_min,
2364 int *start_sec, int *end_year,
2365 int *end_month, int *end_day,
2366 int *mode_day_of_week, int *mode_repeat,
2367 int *alarm_type, int *reserved_info,
2370 ALARM_MGR_LOG_PRINT("called for pid(%d) and alarm_id(%d)\n", pid,
2373 GSList *gs_iter = NULL;
2374 __alarm_info_t *entry = NULL;
2376 alarm_info_t *alarm_info = NULL;
2379 for (gs_iter = alarm_context.alarms; gs_iter != NULL;
2380 gs_iter = g_slist_next(gs_iter)) {
2381 entry = gs_iter->data;
2382 if (entry->alarm_id == alarm_id) {
2383 alarm_info = &(entry->alarm_info);
2388 if (alarm_info == NULL)
2390 ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n",
2392 *return_code = ERR_ALARM_INVALID_ID;
2394 ALARM_MGR_LOG_PRINT("alarm was found\n");
2395 *start_year = alarm_info->start.year;
2396 *start_month = alarm_info->start.month;
2397 *start_day = alarm_info->start.day;
2398 *start_hour = alarm_info->start.hour;
2399 *start_min = alarm_info->start.min;
2400 *start_sec = alarm_info->start.sec;
2402 *end_year = alarm_info->end.year;
2403 *end_year = alarm_info->end.month;
2404 *end_year = alarm_info->end.day;
2406 *mode_day_of_week = alarm_info->mode.u_interval.day_of_week;
2407 *mode_repeat = alarm_info->mode.repeat;
2409 *alarm_type = alarm_info->alarm_type;
2410 *reserved_info = alarm_info->reserved_info;
2417 #include "alarm-skeleton.h"
2419 typedef struct AlarmManagerObject AlarmManagerObject;
2420 typedef struct AlarmManagerObjectClass AlarmManagerObjectClass;
2421 GType Server_Object_get_type(void);
2422 struct AlarmManagerObject {
2425 struct AlarmManagerObjectClass {
2426 GObjectClass parent;
2429 #define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
2431 #define ALARM_MANAGER_TYPE_OBJECT (Server_Object_get_type())
2432 #define ALARM_MANAGER_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST \
2433 ((object), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObject))
2434 #define ALARM_MANAGER_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
2435 ((klass), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2436 #define ALARM_MANAGER_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE \
2437 ((object), ALARM_MANAGER_TYPE_OBJECT))
2438 #define ALARM_MANAGER_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE \
2439 ((klass), ALARM_MANAGER_TYPE_OBJECT))
2440 #define ALARM_MANAGER_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
2441 ((obj), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
2442 G_DEFINE_TYPE(AlarmManagerObject, Server_Object, G_TYPE_OBJECT)
2443 static void Server_Object_init(AlarmManagerObject * obj)
2448 static void Server_Object_class_init(AlarmManagerObjectClass *klass)
2453 static void __initialize_timer()
2455 struct sigaction sig_timer;
2456 sigemptyset(&sig_timer.sa_mask);
2457 sig_timer.sa_flags = SA_SIGINFO;
2458 sig_timer.sa_sigaction = (void *)__alarm_handler;
2459 sigaction(SIG_TIMER, &sig_timer, NULL);
2461 alarm_context.timer = _alarm_create_timer();
2465 static void __initialize_alarm_list()
2468 alarm_context.alarms = NULL;
2469 alarm_context.c_due_time = -1;
2471 _load_alarms_from_registry();
2473 __rtc_set(); /*Set RTC1 Alarm with alarm due time for alarm-manager initialization*/
2478 if (enable_power_on_alarm) {
2479 /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
2480 * platform with app-server. because __alarm_power_on(..) fuction don't
2481 * use first parameter internally, we set this value to 0(zero)
2483 __alarm_power_on(0, enable_power_on_alarm, NULL);
2488 static void __initialize_scheduled_alarm_lsit()
2490 _init_scheduled_alarm_list();
2494 static void __hibernation_leave_callback()
2497 __initialize_scheduled_alarm_lsit();
2499 __alarm_clean_list();
2501 __initialize_alarm_list();
2504 static bool __initialize_noti()
2507 int fd = heynoti_init();
2509 ALARM_MGR_EXCEPTION_PRINT("fail to heynoti_init\n");
2512 heynoti_subscribe(fd, "HIBERNATION_LEAVE", __hibernation_leave_callback,
2514 ret = heynoti_attach_handler(fd);
2516 ALARM_MGR_EXCEPTION_PRINT("heynoti_attach_handler fail");
2519 if (vconf_notify_key_changed
2520 (VCONFKEY_SYSTEM_TIMECHANGE, __on_system_time_changed, NULL) < 0) {
2521 ALARM_MGR_LOG_PRINT(
2522 "Failed to add callback for time changing event\n");
2524 /*system state change noti ó¸® */
2526 if (vconf_notify_key_changed
2527 (VCONFKEY_SETAPPL_TIMEZONE_ID, __on_time_zone_changed, NULL) < 0) {
2528 ALARM_MGR_LOG_PRINT(
2529 "Failed to add callback for time zone changing event\n");
2532 if (vconf_notify_key_changed
2533 (VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, __on_system_time_external_changed, NULL) < 0) {
2534 ALARM_MGR_LOG_PRINT(
2535 "Failed to add callback for time external changing event\n");
2542 static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
2543 DBusMessage *message,
2547 if (dbus_message_is_signal
2548 (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
2553 __expired_alarm_t *expire_info;
2555 dbus_message_get_args(message,
2557 DBUS_TYPE_STRING, &service,
2558 DBUS_TYPE_STRING, &old_owner,
2559 DBUS_TYPE_STRING, &new_owner,
2562 for (entry = g_expired_alarm_list; entry; entry = entry->next) {
2564 expire_info = (__expired_alarm_t *) entry->data;
2566 if (strcmp(expire_info->service_name, service)
2568 ALARM_MGR_EXCEPTION_PRINT(
2569 "__alarm_server_filter : "
2570 "service name(%s) alarm_id (%d)\n",
2571 expire_info->service_name,\
2572 expire_info->alarm_id);
2574 __alarm_send_noti_to_application(
2575 expire_info->service_name,
2576 expire_info->alarm_id);
2577 g_expired_alarm_list =
2578 g_slist_remove(g_expired_alarm_list,
2585 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2588 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2591 static bool __initialize_dbus()
2593 GError *error = NULL;
2594 GObject *obj = NULL;
2595 DBusGConnection *connection = NULL;
2597 int request_name_result = 0;
2599 dbus_g_object_type_install_info(ALARM_MANAGER_TYPE_OBJECT,
2600 &dbus_glib_alarm_manager_object_info);
2602 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
2605 ALARM_MGR_EXCEPTION_PRINT("dbus_g_bus_get failed\n");
2609 dbus_error_init(&derror);
2611 request_name_result =
2612 dbus_bus_request_name(dbus_g_connection_get_connection(connection),
2613 "org.tizen.alarm.manager",
2614 DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &derror);
2615 if (dbus_error_is_set(&derror)) { /* failure */
2616 ALARM_MGR_EXCEPTION_PRINT("Failed to dbus_bus_request_name "
2617 "(org.tizen.alarm.manager): %s\n", derror.message);
2618 dbus_error_free(&derror);
2622 if (!(obj = g_object_new(ALARM_MANAGER_TYPE_OBJECT, NULL))) {
2623 ALARM_MGR_EXCEPTION_PRINT("Could not allocate new object\n");
2627 dbus_g_connection_register_g_object(connection,
2628 "/org/tizen/alarm/manager",
2631 /*dbus_bus_add_match (dbus_g_connection_get_connection(connection),
2632 "type='signal',member='NameOwnerChanged'",NULL); */
2634 dbus_bus_add_match(dbus_g_connection_get_connection(connection),
2635 "type='signal',sender='" DBUS_SERVICE_DBUS
2636 "',path='" DBUS_PATH_DBUS
2637 "',interface='" DBUS_INTERFACE_DBUS
2638 "',member='NameOwnerChanged'", NULL);
2640 if (!dbus_connection_add_filter
2641 (dbus_g_connection_get_connection(connection),
2642 __alarm_server_filter, NULL, NULL)) {
2643 ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
2648 alarm_context.bus = connection;
2652 #define ALARMMGR_DB_FILE "/opt/dbspace/.alarmmgr.db"
2653 sqlite3 *alarmmgr_db;
2654 #define QUERY_CREATE_TABLE_ALARMMGR "create table alarmmgr \
2655 (alarm_id integer primary key,\
2659 app_unique_name text,\
2660 app_service_name text,\
2661 app_service_name_mod text,\
2669 day_of_week integer,\
2671 alarm_type integer,\
2672 reserved_info integer,\
2673 dst_service_name text, \
2674 dst_service_name_mod text \
2677 static bool __initialize_db()
2679 char *error_message = NULL;
2682 if (access("/opt/dbspace/.alarmmgr.db", F_OK) == 0) {
2684 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2685 DB_UTIL_REGISTER_HOOK_METHOD);
2687 if (ret != SQLITE_OK) {
2688 ALARM_MGR_EXCEPTION_PRINT(
2689 "====>>>> connect menu_db [%s] failed!\n",
2698 db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
2699 DB_UTIL_REGISTER_HOOK_METHOD);
2701 if (ret != SQLITE_OK) {
2702 ALARM_MGR_EXCEPTION_PRINT(
2703 "====>>>> connect menu_db [%s] failed!\n",
2709 sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL,\
2711 ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, "
2712 "error message = %s\n", QUERY_CREATE_TABLE_ALARMMGR,
2720 static void __initialize()
2729 fp = fopen("/proc/alarm_boot", "r");
2734 size = fread(&temp, 1, 1, fp);
2739 alarm_boot = atoi(temp);
2747 struct rtc_time rtc_tm;
2750 fd = open(power_rtc, O_RDONLY);
2752 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
2755 retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
2758 fd2 = open(default_rtc, O_RDWR);
2760 ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc1\n");
2763 retval = ioctl(fd2, RTC_SET_TIME, &rtc_tm);
2766 __initialize_timer();
2767 if (__initialize_dbus() == false) { /* because dbus's initialize
2768 failed, we cannot continue any more. */
2769 ALARM_MGR_EXCEPTION_PRINT("because __initialize_dbus failed, "
2770 "alarm-server cannot be runned.\n");
2773 __initialize_scheduled_alarm_lsit();
2775 __initialize_alarm_list();
2776 __initialize_noti();
2781 static bool __check_false_alarm()
2783 time_t current_time;
2786 time(¤t_time);
2788 interval = ab_due_time - current_time;
2790 ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", \
2791 alarm_context.c_due_time, current_time);
2793 if (interval > 0 && interval <= 30) {
2795 } else if (!poweron_alarm_expired) {
2796 /* originally, first arguement's value was 121(app_id) which means
2797 * alarm_booting ui application.and this application's dbus-service
2798 * name had a org.tizen.alarmboot.ui in a platform with app-server.
2799 * so we set "org.tizen.alarmboot.ui.ALARM" instead of 121.
2801 __alarm_send_noti_to_application(
2802 WAKEUP_ALARMBOOTING_APP_ID, -1);
2812 GMainLoop *mainloop = NULL;
2814 ALARM_MGR_LOG_PRINT("Enter main loop\n");
2816 mainloop = g_main_loop_new(NULL, FALSE);
2822 __check_false_alarm();
2826 g_main_loop_run(mainloop);