tizen 2.4 release accepted/tizen_2.4_mobile tizen_2.4 accepted/tizen/2.4/mobile/20151029.034224 submit/tizen_2.4/20151028.063752 tizen_2.4_mobile_release
authorjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:28:35 +0000 (16:28 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Sat, 24 Oct 2015 07:28:35 +0000 (16:28 +0900)
14 files changed:
CMakeLists.txt
alarm-manager-registry.c [changed mode: 0644->0755]
alarm-manager-schedule.c
alarm-manager-timer.c
alarm-manager.c
alarm-server.manifest
alarm_mgr.xml
alarmmgr_log_dump.sh.in [moved from alarmmgr_log_dump.sh with 61% similarity, mode: 0755]
include/alarm-internal.h [changed mode: 0644->0755]
include/alarm.h [changed mode: 0755->0644]
packaging/alarm-manager.spec
packaging/alarm-server.service
src/alarm-lib-stub.c
src/alarm-lib.c [changed mode: 0755->0644]

index 15f407c..9ba03e3 100755 (executable)
@@ -12,7 +12,12 @@ INCLUDE_DIRECTORIES(
        include
 )
 
        include
 )
 
-SET(DEPS_PKGS "glib-2.0 dlog aul bundle security-server db-util appsvc pkgmgr-info vconf gio-2.0 gio-unix-2.0 capi-system-device")
+SET(DEPS_PKGS "glib-2.0 dlog aul bundle security-server db-util appsvc pkgmgr-info vconf gio-2.0 gio-unix-2.0 capi-system-device vasum eventsystem")
+
+IF(_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG)
+ADD_DEFINITIONS("-D_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG")
+ADD_DEFINITIONS("-DALARMMGR_LOG_FILE_PATH=\"${_APPFW_ALARM_MANAGER_MODULE_LOG_PATH}\"")
+ENDIF(_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG)
 
 message("${DEPS_PKGS}")
 
 
 message("${DEPS_PKGS}")
 
@@ -55,7 +60,9 @@ TARGET_LINK_LIBRARIES(${this_target} "-lrt -lm -pie")
 TARGET_LINK_LIBRARIES(${this_target} alarm)
 
 ADD_SUBDIRECTORY(src)
 TARGET_LINK_LIBRARIES(${this_target} alarm)
 
 ADD_SUBDIRECTORY(src)
-ADD_SUBDIRECTORY(tool)
 
 INSTALL(TARGETS ${this_target} DESTINATION bin)
 
 INSTALL(TARGETS ${this_target} DESTINATION bin)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/alarmmgr_log_dump.sh DESTINATION /opt/etc/dump.d/module.d)
+IF(_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG)
+       CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/alarmmgr_log_dump.sh.in ${CMAKE_CURRENT_SOURCE_DIR}/alarmmgr_log_dump.sh @ONLY)
+       INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/alarmmgr_log_dump.sh DESTINATION /opt/etc/dump.d/module.d)
+ENDIF(_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG)
old mode 100644 (file)
new mode 100755 (executable)
index 21c4c12..9b67232
 #define MAX_QUERY_LEN 4096
 
 extern __alarm_server_context_t alarm_context;
 #define MAX_QUERY_LEN 4096
 
 extern __alarm_server_context_t alarm_context;
-extern sqlite3 *alarmmgr_db;
-
+extern GSList *alarmmgr_db_list;
 bool _save_alarms(__alarm_info_t *__alarm_info);
 bool _update_alarms(__alarm_info_t *__alarm_info);
 bool _save_alarms(__alarm_info_t *__alarm_info);
 bool _update_alarms(__alarm_info_t *__alarm_info);
-bool _delete_alarms(alarm_id_t alarm_id);
+bool _delete_alarms(alarm_id_t alarm_id, const char *zone);
 bool _load_alarms_from_registry(void);
 
 bool _load_alarms_from_registry(void);
 
+static gint _find_zone_alarmmgr_db(void *db_info, void *data)
+{
+       _zone_alarm_db_list_t *db_struct = (_zone_alarm_db_list_t *)db_info;
+       return strcmp(db_struct->zone, (char *)data);
+}
+
+static sqlite3 *_find_db(const char *zone)
+{
+       sqlite3 *alarmmgr_db = NULL;
+       GSList *iter = g_slist_find_custom(alarmmgr_db_list, zone, (GCompareFunc)_find_zone_alarmmgr_db);
+       if (iter == NULL) {
+               SECURE_LOGE("failed to find db for zone[%s]", zone);
+               return NULL;
+       }
+       alarmmgr_db = ((_zone_alarm_db_list_t *)iter->data)->alarmmgr_db;
+
+       return alarmmgr_db;
+}
+
 bool _save_alarms(__alarm_info_t *__alarm_info)
 {
        char *error_message = NULL;
 bool _save_alarms(__alarm_info_t *__alarm_info)
 {
        char *error_message = NULL;
@@ -56,6 +74,13 @@ bool _save_alarms(__alarm_info_t *__alarm_info)
        alarm_date_t *start = &alarm_info->start;
        alarm_mode_t *mode = &alarm_info->mode;
 
        alarm_date_t *start = &alarm_info->start;
        alarm_mode_t *mode = &alarm_info->mode;
 
+       SECURE_LOGE("__zone %s", g_quark_to_string(__alarm_info->zone));
+       sqlite3 *alarmmgr_db = _find_db((const char *)g_quark_to_string(__alarm_info->zone));
+       if (alarmmgr_db == NULL) {
+               SECURE_LOGE("failed to retrieve db");
+               return false;
+       }
+
        char *query = sqlite3_mprintf("insert into alarmmgr( alarm_id, start,\
                        end, pid, caller_pkgid, callee_pkgid, app_unique_name, app_service_name, app_service_name_mod, bundle, year,\
                        month, day, hour, min, sec, day_of_week, repeat,\
        char *query = sqlite3_mprintf("insert into alarmmgr( alarm_id, start,\
                        end, pid, caller_pkgid, callee_pkgid, app_unique_name, app_service_name, app_service_name_mod, bundle, year,\
                        month, day, hour, min, sec, day_of_week, repeat,\
@@ -109,6 +134,12 @@ bool _update_alarms(__alarm_info_t *__alarm_info)
        alarm_date_t *start = &alarm_info->start;
        alarm_mode_t *mode = &alarm_info->mode;
 
        alarm_date_t *start = &alarm_info->start;
        alarm_mode_t *mode = &alarm_info->mode;
 
+       sqlite3 *alarmmgr_db = _find_db((const char *)g_quark_to_string(__alarm_info->zone));
+       if (alarmmgr_db == NULL) {
+               SECURE_LOGE("failed to retrieve db");
+               return false;
+       }
+
        char *query = sqlite3_mprintf("update alarmmgr set start=%d, end=%d,\
                        pid=%d, caller_pkgid=%Q, callee_pkgid=%Q, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\
                        bundle=%Q, year=%d, month=%d, day=%d, hour=%d, min=%d, sec=%d,\
        char *query = sqlite3_mprintf("update alarmmgr set start=%d, end=%d,\
                        pid=%d, caller_pkgid=%Q, callee_pkgid=%Q, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\
                        bundle=%Q, year=%d, month=%d, day=%d, hour=%d, min=%d, sec=%d,\
@@ -154,11 +185,17 @@ bool _update_alarms(__alarm_info_t *__alarm_info)
        return true;
 }
 
        return true;
 }
 
-bool _delete_alarms(alarm_id_t alarm_id)
+bool _delete_alarms(alarm_id_t alarm_id, const char *zone)
 {
        char *error_message = NULL;
        char *query = sqlite3_mprintf("delete from alarmmgr where alarm_id=%d", alarm_id);
 
 {
        char *error_message = NULL;
        char *query = sqlite3_mprintf("delete from alarmmgr where alarm_id=%d", alarm_id);
 
+       sqlite3 *alarmmgr_db = _find_db(zone);
+       if (alarmmgr_db == NULL) {
+               SECURE_LOGE("failed to retrieve db");
+               return false;
+       }
+
        if (SQLITE_OK != sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
                SECURE_LOGE("sqlite3_exec() is failed. query = %s, error message = %s", query, error_message);
                sqlite3_free(query);
        if (SQLITE_OK != sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
                SECURE_LOGE("sqlite3_exec() is failed. query = %s, error message = %s", query, error_message);
                sqlite3_free(query);
@@ -190,78 +227,92 @@ bool _load_alarms_from_registry()
 
        snprintf(query, MAX_QUERY_LEN, "select * from alarmmgr");
 
 
        snprintf(query, MAX_QUERY_LEN, "select * from alarmmgr");
 
-       if (SQLITE_OK != sqlite3_prepare(alarmmgr_db, query, strlen(query), &stmt, &tail)) {
-               ALARM_MGR_EXCEPTION_PRINT("sqlite3_prepare() is failed.");
-               return false;
-       }
+       GSList *iter;
+       sqlite3 *alarmmgr_db = NULL;
+       char *zone = NULL;
+       for (iter = alarmmgr_db_list; iter != NULL; iter = g_slist_next(iter)) {
+               alarmmgr_db = ((_zone_alarm_db_list_t *)iter->data)->alarmmgr_db;
+               zone = ((_zone_alarm_db_list_t *)iter->data)->zone;
+
+               if (SQLITE_OK != sqlite3_prepare(alarmmgr_db, query, strlen(query), &stmt, &tail)) {
+                       ALARM_MGR_EXCEPTION_PRINT("sqlite3_prepare() is failed.");
+                       return false;
+               }
+               for (i = 0; SQLITE_ROW == sqlite3_step(stmt); i++) {
+                       __alarm_info = malloc(sizeof(__alarm_info_t));
+
+                       if (G_UNLIKELY(__alarm_info == NULL)) {
+                               ALARM_MGR_EXCEPTION_PRINT("Memory allocation failed.");
+                               return false;
+                       }
+                       alarm_info = (alarm_info_t *) &(__alarm_info->alarm_info);
+                       start = &alarm_info->start;
+                       mode = &alarm_info->mode;
+
+                       __alarm_info->alarm_id = sqlite3_column_int(stmt, 0);
+                       __alarm_info->start = sqlite3_column_int(stmt, 1);
+                       __alarm_info->end = sqlite3_column_int(stmt, 2);
+                       __alarm_info->pid = sqlite3_column_int(stmt, 3);
+
+                       strncpy(caller_pkgid, (const char *)sqlite3_column_text(stmt, 4),
+                                       MAX_PKG_ID_LEN - 1);
+                       strncpy(callee_pkgid, (const char *)sqlite3_column_text(stmt, 5),
+                                       MAX_PKG_ID_LEN - 1);
+                       strncpy(app_unique_name, (const char *)sqlite3_column_text(stmt, 6),
+                                       MAX_SERVICE_NAME_LEN - 1);
+                       strncpy(app_service_name, (const char *)sqlite3_column_text(stmt, 7),
+                                       MAX_SERVICE_NAME_LEN - 1);
+                       strncpy(app_service_name_mod, (const char *)sqlite3_column_text(stmt, 8),
+                                       MAX_SERVICE_NAME_LEN - 1);
+                       strncpy(bundle, (const char *)sqlite3_column_text(stmt, 9),
+                                       MAX_BUNDLE_NAME_LEN - 1);
+                       start->year = sqlite3_column_int(stmt, 10);
+                       start->month = sqlite3_column_int(stmt, 11);
+                       start->day = sqlite3_column_int(stmt, 12);
+                       start->hour = sqlite3_column_int(stmt, 13);
+                       start->min = sqlite3_column_int(stmt, 14);
+                       start->sec = sqlite3_column_int(stmt, 15);
+                       mode->u_interval.day_of_week = sqlite3_column_int(stmt, 16);
+                       mode->repeat = sqlite3_column_int(stmt, 17);
+                       alarm_info->alarm_type = sqlite3_column_int(stmt, 18);
+                       alarm_info->reserved_info = sqlite3_column_int(stmt, 19);
+                       strncpy(dst_service_name, (const char *)sqlite3_column_text(stmt, 20),
+                                       MAX_SERVICE_NAME_LEN - 1);
+                       strncpy(dst_service_name_mod, (const char *)sqlite3_column_text(stmt, 21),
+                                       MAX_SERVICE_NAME_LEN - 1);
 
 
-       for (i = 0; SQLITE_ROW == sqlite3_step(stmt); i++) {
-               __alarm_info = malloc(sizeof(__alarm_info_t));
+                       __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+                       __alarm_info->quark_callee_pkgid = g_quark_from_string(callee_pkgid);
+                       __alarm_info->quark_app_unique_name =
+                               g_quark_from_string(app_unique_name);
+                       __alarm_info->quark_app_service_name =
+                               g_quark_from_string(app_service_name);
+                       __alarm_info->quark_app_service_name_mod=
+                               g_quark_from_string(app_service_name_mod);
+                       __alarm_info->quark_dst_service_name =
+                               g_quark_from_string(dst_service_name);
+                       __alarm_info->quark_dst_service_name_mod=
+                               g_quark_from_string(dst_service_name_mod);
+                       __alarm_info->quark_bundle = g_quark_from_string(bundle);
+                       __alarm_info->zone = g_quark_from_string(zone);
 
 
-               if (G_UNLIKELY(__alarm_info == NULL)) {
-                       ALARM_MGR_EXCEPTION_PRINT("Memory allocation failed.");
+                       _alarm_next_duetime(__alarm_info);
+                       alarm_context.alarms = g_slist_append(alarm_context.alarms, __alarm_info);
+               }
+
+               if (SQLITE_OK != sqlite3_finalize(stmt)) {
+                       ALARM_MGR_EXCEPTION_PRINT("sqlite3_finalize() is failed.");
                        return false;
                }
                        return false;
                }
-               alarm_info = (alarm_info_t *) &(__alarm_info->alarm_info);
-               start = &alarm_info->start;
-               mode = &alarm_info->mode;
-
-               __alarm_info->alarm_id = sqlite3_column_int(stmt, 0);
-               __alarm_info->start = sqlite3_column_int(stmt, 1);
-               __alarm_info->end = sqlite3_column_int(stmt, 2);
-               __alarm_info->pid = sqlite3_column_int(stmt, 3);
-
-               strncpy(caller_pkgid, (const char *)sqlite3_column_text(stmt, 4),
-                       MAX_PKG_ID_LEN - 1);
-               strncpy(callee_pkgid, (const char *)sqlite3_column_text(stmt, 5),
-                       MAX_PKG_ID_LEN - 1);
-               strncpy(app_unique_name, (const char *)sqlite3_column_text(stmt, 6),
-                       MAX_SERVICE_NAME_LEN - 1);
-               strncpy(app_service_name, (const char *)sqlite3_column_text(stmt, 7),
-                       MAX_SERVICE_NAME_LEN - 1);
-               strncpy(app_service_name_mod, (const char *)sqlite3_column_text(stmt, 8),
-                       MAX_SERVICE_NAME_LEN - 1);
-               strncpy(bundle, (const char *)sqlite3_column_text(stmt, 9),
-                       MAX_BUNDLE_NAME_LEN - 1);
-               start->year = sqlite3_column_int(stmt, 10);
-               start->month = sqlite3_column_int(stmt, 11);
-               start->day = sqlite3_column_int(stmt, 12);
-               start->hour = sqlite3_column_int(stmt, 13);
-               start->min = sqlite3_column_int(stmt, 14);
-               start->sec = sqlite3_column_int(stmt, 15);
-               mode->u_interval.day_of_week = sqlite3_column_int(stmt, 16);
-               mode->repeat = sqlite3_column_int(stmt, 17);
-               alarm_info->alarm_type = sqlite3_column_int(stmt, 18);
-               alarm_info->reserved_info = sqlite3_column_int(stmt, 19);
-               strncpy(dst_service_name, (const char *)sqlite3_column_text(stmt, 20),
-                       MAX_SERVICE_NAME_LEN - 1);
-               strncpy(dst_service_name_mod, (const char *)sqlite3_column_text(stmt, 21),
-                       MAX_SERVICE_NAME_LEN - 1);
-
-               __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
-               __alarm_info->quark_callee_pkgid = g_quark_from_string(callee_pkgid);
-               __alarm_info->quark_app_unique_name =
-                   g_quark_from_string(app_unique_name);
-               __alarm_info->quark_app_service_name =
-                   g_quark_from_string(app_service_name);
-               __alarm_info->quark_app_service_name_mod=
-                   g_quark_from_string(app_service_name_mod);
-               __alarm_info->quark_dst_service_name =
-                   g_quark_from_string(dst_service_name);
-               __alarm_info->quark_dst_service_name_mod=
-                   g_quark_from_string(dst_service_name_mod);
-               __alarm_info->quark_bundle = g_quark_from_string(bundle);
-
-               _alarm_next_duetime(__alarm_info);
-               alarm_context.alarms = g_slist_append(alarm_context.alarms, __alarm_info);
+               stmt = NULL;
        }
 
        }
 
-
        _alarm_schedule();
        if (SQLITE_OK != sqlite3_finalize(stmt)) {
                ALARM_MGR_EXCEPTION_PRINT("sqlite3_finalize() is failed.");
                return false;
        }
        _alarm_schedule();
        if (SQLITE_OK != sqlite3_finalize(stmt)) {
                ALARM_MGR_EXCEPTION_PRINT("sqlite3_finalize() is failed.");
                return false;
        }
+       stmt = NULL;
 
        return true;
 }
 
        return true;
 }
index 2f22f30..e5fc70a 100755 (executable)
 
 #include"alarm.h"
 #include"alarm-internal.h"
 
 #include"alarm.h"
 #include"alarm-internal.h"
-#define WAKEUP_ALARM_APP_ID "org.tizen.alarm.ALARM"    /*alarm ui
-                                                          application's alarm's dbus_service name instead of 21 value */
 #define DST_TIME_DIFF 1
 
 extern __alarm_server_context_t alarm_context;
 extern GSList *g_scheduled_alarm_list;
 #define DST_TIME_DIFF 1
 
 extern __alarm_server_context_t alarm_context;
 extern GSList *g_scheduled_alarm_list;
+extern bool is_time_changed;
 
 static time_t __alarm_next_duetime_once(__alarm_info_t *__alarm_info);
 static time_t __alarm_next_duetime_repeat(__alarm_info_t *__alarm_info);
 
 static time_t __alarm_next_duetime_once(__alarm_info_t *__alarm_info);
 static time_t __alarm_next_duetime_repeat(__alarm_info_t *__alarm_info);
@@ -94,33 +93,15 @@ bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info)
                        g_quark_to_string(alarm->__alarm_info->quark_app_service_name),
                        alarm->__alarm_info->quark_app_service_name);
 
                        g_quark_to_string(alarm->__alarm_info->quark_app_service_name),
                        alarm->__alarm_info->quark_app_service_name);
 
-       if (alarm->__alarm_info->quark_app_service_name != g_quark_from_string(WAKEUP_ALARM_APP_ID)) {
-               g_scheduled_alarm_list = g_slist_append(g_scheduled_alarm_list, alarm);
-       }
-       else {
-               for (iter = g_scheduled_alarm_list; iter != NULL; iter = g_slist_next(iter)) {
-                       count++;
-                       entry = iter->data;
-                       if (entry->__alarm_info->quark_app_service_name != g_quark_from_string(WAKEUP_ALARM_APP_ID)) {
-                               prior = true;
-                               break;
-                       }
-               }
+       SECURE_LOGD("%s :target zone : [%s]\n", __FUNCTION__, g_quark_to_string(alarm->__alarm_info->zone));
+       alarm->__alarm_info->zone = __alarm_info->zone;
 
 
-               if (!prior) {
-                       g_scheduled_alarm_list = g_slist_append(g_scheduled_alarm_list, alarm);
-                       ALARM_MGR_LOG_PRINT("appended : prior is %d\tcount is %d\n", prior, count);
-               }
-               else {
-                       g_scheduled_alarm_list = g_slist_insert(g_scheduled_alarm_list, alarm, count - 1);
-                       ALARM_MGR_LOG_PRINT("appended : prior is %d\tcount is %d\n", prior, count);
-               }
-       }
+       g_scheduled_alarm_list = g_slist_append(g_scheduled_alarm_list, alarm);
 
        return true;
 }
 
 
        return true;
 }
 
-bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id)
+bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id, const char *zone)
 {
        bool result = false;
        GSList *iter = NULL;
 {
        bool result = false;
        GSList *iter = NULL;
@@ -128,6 +109,10 @@ bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id)
 
        for (iter = g_scheduled_alarm_list; iter != NULL; iter = g_slist_next(iter)) {
                alarm = iter->data;
 
        for (iter = g_scheduled_alarm_list; iter != NULL; iter = g_slist_next(iter)) {
                alarm = iter->data;
+
+               if (strcmp(g_quark_to_string(alarm->__alarm_info->zone), zone) != 0)
+                       continue;
+
                if (alarm->alarm_id == alarm_id) {
                        g_scheduled_alarm_list = g_slist_remove(g_scheduled_alarm_list, iter->data);
                        g_free(alarm);
                if (alarm->alarm_id == alarm_id) {
                        g_scheduled_alarm_list = g_slist_remove(g_scheduled_alarm_list, iter->data);
                        g_free(alarm);
@@ -228,12 +213,26 @@ static time_t __alarm_next_duetime_repeat(__alarm_info_t *__alarm_info)
        duetime_tm.tm_mday = start->day;
        duetime_tm.tm_isdst = -1;
 
        duetime_tm.tm_mday = start->day;
        duetime_tm.tm_isdst = -1;
 
-       due_time = mktime(&duetime_tm);
-
-       while (__alarm_info->start > due_time || current_time >= due_time) {
-               due_time += alarm_info->mode.u_interval.interval;
+       if (alarm_info->alarm_type & ALARM_TYPE_PERIOD &&
+                       alarm_info->mode.u_interval.interval > 0) {
+               /* For minimize 'while loop'
+                * Duetime should be "periodic_standard_time + (interval * x) >= current" */
+               time_t periodic_standard_time = _get_periodic_alarm_standard_time();
+               time_t temp;
+               temp = (current_time - periodic_standard_time) / alarm_info->mode.u_interval.interval;
+               due_time = periodic_standard_time + (temp * alarm_info->mode.u_interval.interval);
+       } else {
+               due_time = mktime(&duetime_tm);
+       }
 
 
-               /* due_time = mktime(&duetime_tm); */
+       if (alarm_info->mode.u_interval.interval <= 0) {
+               ALARM_MGR_ASSERT_PRINT("Error! Despite repeated alarm, interval <= 0.\nalarm_id=%d, pid=%d, app_unique_name=%s, app_service_name=%s, start time=%d",
+                       __alarm_info->alarm_id, __alarm_info->pid, g_quark_to_string(__alarm_info->quark_app_unique_name),
+                       g_quark_to_string(__alarm_info->quark_app_service_name), __alarm_info->start);
+       } else {
+               while (__alarm_info->start > due_time || current_time > due_time || ((!is_time_changed) && (current_time == due_time))) {
+                       due_time += alarm_info->mode.u_interval.interval;
+               }
        }
 
        if (due_time - current_time < 10)
        }
 
        if (due_time - current_time < 10)
@@ -276,7 +275,7 @@ static time_t __alarm_next_duetime_annually(__alarm_info_t *__alarm_info)
 
        due_time = mktime(&duetime_tm);
 
 
        due_time = mktime(&duetime_tm);
 
-       while (__alarm_info->start > due_time || current_time > due_time) {
+       while (__alarm_info->start > due_time || current_time > due_time || ((!is_time_changed) && (current_time == due_time))) {
                duetime_tm.tm_year += 1;
                due_time = mktime(&duetime_tm);
        }
                duetime_tm.tm_year += 1;
                due_time = mktime(&duetime_tm);
        }
@@ -305,7 +304,6 @@ static time_t __alarm_next_duetime_monthly(__alarm_info_t *__alarm_info)
        }
 
        if (start->month != 0) {
        }
 
        if (start->month != 0) {
-
                duetime_tm.tm_mon = start->month - 1;
        }
 
                duetime_tm.tm_mon = start->month - 1;
        }
 
@@ -313,7 +311,7 @@ static time_t __alarm_next_duetime_monthly(__alarm_info_t *__alarm_info)
 
        due_time = mktime(&duetime_tm);
 
 
        due_time = mktime(&duetime_tm);
 
-       while (__alarm_info->start > due_time || current_time > due_time) {
+       while (__alarm_info->start > due_time || current_time > due_time || ((!is_time_changed) && (current_time == due_time))) {
                duetime_tm.tm_mon += 1;
                if (duetime_tm.tm_mon == 12) {
                        duetime_tm.tm_mon = 0;
                duetime_tm.tm_mon += 1;
                if (duetime_tm.tm_mon == 12) {
                        duetime_tm.tm_mon = 0;
@@ -404,7 +402,7 @@ static time_t __alarm_next_duetime_weekly(__alarm_info_t *__alarm_info)
                return due_time;
        }
 
                return due_time;
        }
 
-       if (current_time >= due_time || !(mode->u_interval.day_of_week & 1 << wday)) {
+       if (current_time > due_time || !(mode->u_interval.day_of_week & 1 << wday) || ((!is_time_changed) && (current_time == due_time))) {
                int day = wday + 1;
                int interval = 1;
                /*this week */
                int day = wday + 1;
                int interval = 1;
                /*this week */
@@ -489,7 +487,7 @@ time_t _alarm_next_duetime(__alarm_info_t *__alarm_info)
                        due_time = mktime(due_tm);
        }
 
                        due_time = mktime(due_tm);
        }
 
-        ALARM_MGR_EXCEPTION_PRINT("alarm_id: %d, next duetime: %d", __alarm_info->alarm_id, due_time);
+       ALARM_MGR_EXCEPTION_PRINT("alarm_id: %d, next duetime: %d", __alarm_info->alarm_id, due_time);
 
        if (__alarm_info->end != 0 && __alarm_info->end < due_time) {
                ALARM_MGR_LOG_PRINT("due time > end time");
 
        if (__alarm_info->end != 0 && __alarm_info->end < due_time) {
                ALARM_MGR_LOG_PRINT("due time > end time");
@@ -526,7 +524,7 @@ static bool __find_next_alarm_to_be_scheduled(time_t *min_due_time)
 
                interval = difftime(due_time, current_time);
 
 
                interval = difftime(due_time, current_time);
 
-               if (interval <= 0)      /*2008.08.06 when the alarm expires, it may makes an error.*/ {
+               if (interval < 0)       /*2008.08.06 when the alarm expires, it may makes an error.*/ {
                        ALARM_MGR_EXCEPTION_PRINT("The duetime of alarm(%d) is OVER.", entry->alarm_id);
                        continue;
                }
                        ALARM_MGR_EXCEPTION_PRINT("The duetime of alarm(%d) is OVER.", entry->alarm_id);
                        continue;
                }
index 01f4fe1..e2153dc 100755 (executable)
@@ -108,26 +108,3 @@ bool _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t
        alarm_context->c_due_time = due_time;
        return true;
 }
        alarm_context->c_due_time = due_time;
        return true;
 }
-
-int _set_sys_time(time_t _time)
-{
-       struct tm result;
-       /* Ignore return value of gmtime_r(). */
-       (void) gmtime_r(&_time, &result);
-
-       stime(&_time);
-
-       return 1;
-}
-
-int _set_time(time_t _time)
-{
-       ALARM_MGR_LOG_PRINT("ENTER FUNC _set_time(%d)", _time);
-       _set_rtc_time(_time);
-       //_set_sys_time(_time);
-
-       /* inoti (broadcasting without data 
-        * send system noti that time has changed */
-
-       return 0;
-}
index 51f1b3c..9589412 100755 (executable)
 #include <dlfcn.h>
 #include <pkgmgr-info.h>
 #include <device/display.h>
 #include <dlfcn.h>
 #include <pkgmgr-info.h>
 #include <device/display.h>
+#include <vasum.h>
+#include <appsvc.h>
+#include <eventsystem.h>
 
 
+#define SYSTEM_UID             200
 #define SIG_TIMER 0x32
 #define SIG_TIMER 0x32
-#define WAKEUP_ALARM_APP_ID       "org.tizen.alarm.ALARM"
-       /* alarm ui application's alarm's dbus_service name instead of 21
-          (alarm application's app_id) value */
 
 __alarm_server_context_t alarm_context;
 bool g_dummy_timer_is_set = FALSE;
 
 __alarm_server_context_t alarm_context;
 bool g_dummy_timer_is_set = FALSE;
@@ -88,14 +89,17 @@ GSList *g_expired_alarm_list = NULL;
 #define ALARM_SET_RTC               _IOW('a', 5, struct timespec)
 #define ALARM_CLEAR(type)           _IO('a', 0 | ((type) << 4))
 
 #define ALARM_SET_RTC               _IOW('a', 5, struct timespec)
 #define ALARM_CLEAR(type)           _IO('a', 0 | ((type) << 4))
 
+#define MAX_ZONE_NAME_LEN 128
 // For module log
 // For module log
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
 #define ALARMMGR_LOG_BUFFER_SIZE       10000
 #define ALARMMGR_LOG_BUFFER_STRING_SIZE        200
 #define ALARMMGR_LOG_TAG_SIZE          20
 #define ALARMMGR_LOG_MESSAGE_SIZE      120
 #define ALARMMGR_LOG_BUFFER_SIZE       10000
 #define ALARMMGR_LOG_BUFFER_STRING_SIZE        200
 #define ALARMMGR_LOG_TAG_SIZE          20
 #define ALARMMGR_LOG_MESSAGE_SIZE      120
-#define ALARMMGR_LOG_FILE_PATH "/var/log/alarmmgr.log"
+// ALARMMGR_LOG_FILE_PATH is defined in CMakeLists.txt
 static int log_index = 0;
 static int log_fd = 0;
 static int log_index = 0;
 static int log_fd = 0;
+#endif
 
 // display lock and unlock
 #define DEVICED_BUS_NAME "org.tizen.system.deviced"
 
 // display lock and unlock
 #define DEVICED_BUS_NAME "org.tizen.system.deviced"
@@ -123,13 +127,19 @@ static int gfd = 0;
 GDBusObjectManagerServer *alarmmgr_server = NULL;
 static AlarmManager* interface = NULL;
 
 GDBusObjectManagerServer *alarmmgr_server = NULL;
 static AlarmManager* interface = NULL;
 
+GSList *alarmmgr_db_list = NULL;
+bool is_time_changed = false;  // for calculating next duetime
+
+#define BILLION 1000000000     // for calculating nano seconds
+static time_t periodic_alarm_standard_time = 0;
+
 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info);
 static void __alarm_generate_alarm_id(__alarm_info_t *__alarm_info, alarm_id_t *alarm_id);
 static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
                                   __alarm_info_t *__alarm_info,
                                   int *error_code);
 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info);
 static void __alarm_generate_alarm_id(__alarm_info_t *__alarm_info, alarm_id_t *alarm_id);
 static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
                                   __alarm_info_t *__alarm_info,
                                   int *error_code);
 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
-                                    int *error_code);
+                                    int *error_code, const char *zone);
 static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
                                           __alarm_info_t *__alarm_info);
 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time);
 static bool __alarm_set_start_and_end_time(alarm_info_t *alarm_info,
                                           __alarm_info_t *__alarm_info);
 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time);
@@ -137,19 +147,21 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
                        int pid, periodic_method_e method, long requested_interval, int is_ref,
                        char *app_service_name, char *app_service_name_mod,
                        const char *dst_service_name, const char *dst_service_name_mod,
                        int pid, periodic_method_e method, long requested_interval, int is_ref,
                        char *app_service_name, char *app_service_name_mod,
                        const char *dst_service_name, const char *dst_service_name_mod,
-                       int *error_code);
+                       int *error_code, const char *zone);
 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
-                          int pid, char *bundle_data, int *error_code);
+                       long requested_interval, int pid, char *bundle_data,
+                       int *error_code, const char *zone);
 
 
-static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code);
+static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code, const char *zone);
 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
-                          alarm_info_t *alarm_info, int *error_code);
+                          alarm_info_t *alarm_info, int *error_code, const char *zone);
 static void __alarm_send_noti_to_application(const char *app_service_name, alarm_id_t alarm_id);
 static void __alarm_expired();
 static gboolean __alarm_handler_idle(gpointer user_data);
 static void __clean_registry();
 static bool __alarm_manager_reset();
 static void __on_system_time_external_changed(keynode_t *node, void *data);
 static void __alarm_send_noti_to_application(const char *app_service_name, alarm_id_t alarm_id);
 static void __alarm_expired();
 static gboolean __alarm_handler_idle(gpointer user_data);
 static void __clean_registry();
 static bool __alarm_manager_reset();
 static void __on_system_time_external_changed(keynode_t *node, void *data);
+
 static void __initialize_timer();
 static void __initialize_alarm_list();
 static void __initialize_scheduled_alarm_list();
 static void __initialize_timer();
 static void __initialize_alarm_list();
 static void __initialize_scheduled_alarm_list();
@@ -160,24 +172,28 @@ static bool __initialize_db();
 static void __initialize();
 void on_bus_name_owner_changed(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path,
              const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data);
 static void __initialize();
 void on_bus_name_owner_changed(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path,
              const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data);
-bool __get_caller_unique_name(int pid, char *unique_name);
+bool __get_caller_unique_name(int pid, char *unique_name, const char *zone);
 
 
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
 static void __initialize_module_log(void);
 static bool __save_module_log(const char *tag, const char *messgae);
 static void __initialize_module_log(void);
 static bool __save_module_log(const char *tag, const char *messgae);
+#endif
 
 int __display_lock_state(char *state, char *flag, unsigned int timeout);
 int __display_unlock_state(char *state, char *flag);
 
 
 int __display_lock_state(char *state, char *flag, unsigned int timeout);
 int __display_unlock_state(char *state, char *flag);
 
+int __set_time(time_t _time);
+
 static void __rtc_set()
 {
 #ifdef __WAKEUP_USING_RTC__
        const char *rtc = default_rtc;
 static void __rtc_set()
 {
 #ifdef __WAKEUP_USING_RTC__
        const char *rtc = default_rtc;
-       struct rtc_wkalrm rtc_wk;
        struct tm due_tm;
        struct timespec alarm_time;
        struct tm due_tm;
        struct timespec alarm_time;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
-#ifdef _SIMUL                  /*if build is simulator, we don't need to set
-                                  RTC because RTC does not work in simulator.*/
+#endif
+#ifdef _SIMUL  // RTC does not work in simulator.
        ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, we don't set RTC.");
        return;
 #endif
        ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, we don't set RTC.");
        return;
 #endif
@@ -192,16 +208,15 @@ static void __rtc_set()
 
        /* Read the RTC time/date */
        int retval = 0;
 
        /* Read the RTC time/date */
        int retval = 0;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char *timebuf = ctime(&alarm_context.c_due_time);
        char *timebuf = ctime(&alarm_context.c_due_time);
-       if (timebuf == NULL) {
-               ALARM_MGR_EXCEPTION_PRINT("timebuf is NULL.");
-               return;
+       if (timebuf) {
+               timebuf[strlen(timebuf) - 1] = '\0';    // to avoid new line
+               snprintf(log_message, sizeof(log_message), "wakeup time: %d, %s", (int)alarm_context.c_due_time, timebuf);
        }
        }
+#endif
 
 
-       timebuf[strlen(timebuf) - 1] = '\0';    // to avoid new line
-       sprintf(log_message, "wakeup time: %d, %s", alarm_context.c_due_time, timebuf);
-
-       ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d.", alarm_context.c_due_time);
+       ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d.", (int)alarm_context.c_due_time);
 
        if (alarm_context.c_due_time != -1) {
                retval = ioctl(gfd, ALARM_CLEAR(ALARM_RTC_WAKEUP));
 
        if (alarm_context.c_due_time != -1) {
                retval = ioctl(gfd, ALARM_CLEAR(ALARM_RTC_WAKEUP));
@@ -229,11 +244,15 @@ static void __rtc_set()
                                ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
                        }
                        ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror(errno));
                                ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
                        }
                        ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror(errno));
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                        __save_module_log("FAIL: SET RTC", log_message);
                        __save_module_log("FAIL: SET RTC", log_message);
+#endif
                        return;
                }
                ALARM_MGR_EXCEPTION_PRINT("[alarm-server]RTC ALARM_SET ioctl is successfully done.");
                        return;
                }
                ALARM_MGR_EXCEPTION_PRINT("[alarm-server]RTC ALARM_SET ioctl is successfully done.");
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                __save_module_log("SET RTC", log_message);
                __save_module_log("SET RTC", log_message);
+#endif
        }
        else {
                ALARM_MGR_EXCEPTION_PRINT("[alarm-server]alarm_context.c_due_time is"
        }
        else {
                ALARM_MGR_EXCEPTION_PRINT("[alarm-server]alarm_context.c_due_time is"
@@ -243,19 +262,21 @@ static void __rtc_set()
        return;
 }
 
        return;
 }
 
-int _set_rtc_time(time_t _time)
+int __set_time(time_t _time)
 {
 {
+       // Using /dev/alarm, this function changes both OS time and RTC.
        int ret = 0;
        const char *rtc0 = default_rtc;
        struct timespec rtc_time;
        int ret = 0;
        const char *rtc0 = default_rtc;
        struct timespec rtc_time;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
 
        if (gfd == 0) {
                gfd = open(rtc0, O_RDWR);
 
        if (gfd == 0) {
                gfd = open(rtc0, O_RDWR);
-
                if (gfd == -1) {
                if (gfd == -1) {
-                       ALARM_MGR_LOG_PRINT("error to open /dev/alarm.");
+                       ALARM_MGR_EXCEPTION_PRINT("Opening the /dev/alarm is failed.");
                        perror("\t");
                }
        }
                        perror("\t");
                }
        }
@@ -263,26 +284,300 @@ int _set_rtc_time(time_t _time)
        rtc_time.tv_sec = _time;
        rtc_time.tv_nsec = 0;
 
        rtc_time.tv_sec = _time;
        rtc_time.tv_nsec = 0;
 
-       strncpy(log_tag, "SET RTC", strlen("SET RTC"));
-       char *timebuf = ctime(&_time);
-       if (timebuf) {
-               timebuf[strlen(timebuf) - 1] = '\0';    // to avoid new line
-               sprintf(log_message, "rtc time = %d, %s", _time, timebuf);
-       }
-
        ret = ioctl(gfd, ALARM_SET_RTC, &rtc_time);
        if (ret == -1) {
        ret = ioctl(gfd, ALARM_SET_RTC, &rtc_time);
        if (ret == -1) {
-               ALARM_MGR_LOG_PRINT("ALARM_SET_RTC ioctl is failed. errno = %s", strerror(errno));
+               ALARM_MGR_EXCEPTION_PRINT("ALARM_SET_RTC ioctl is failed. errno = %s", strerror(errno));
+       #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "FAIL: SET RTC", strlen("FAIL: SET RTC"));
                strncpy(log_tag, "FAIL: SET RTC", strlen("FAIL: SET RTC"));
-
+       #endif
                perror("\t");
        }
                perror("\t");
        }
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       else {
+               strncpy(log_tag, "SET RTC", strlen("SET RTC"));
+       }
+
+       char *timebuf = ctime(&_time);
+       if (timebuf) {
+               timebuf[strlen(timebuf) - 1] = '\0';    // to avoid new line
+               snprintf(log_message, sizeof(log_message), "RTC & OS =%d, %s", (int)_time, timebuf);
+       }
 
        __save_module_log(log_tag, log_message);
 
        __save_module_log(log_tag, log_message);
+#endif
 
        return 1;
 }
 
 
        return 1;
 }
 
+
+#define ZONE_PREFIX_PATH "/var/lib/lxc"
+#define ZONE_INFIX_PATH "/rootfs"
+
+static inline int __read_proc(const char *path, char *buf, int size)
+{
+       int fd = 0;
+       int ret = 0;
+
+       if (buf == NULL || path == NULL)
+               return -1;
+
+       fd = open(path, O_RDONLY);
+       if (fd < 0)
+               return -1;
+
+       ret = read(fd, buf, size - 1);
+       if (ret <= 0) {
+               close(fd);
+               return -1;
+       } else
+               buf[ret] = 0;
+
+       close(fd);
+
+       return ret;
+}
+
+static char *__proc_get_cmdline_bypid(int pid)
+{
+       char buf[1024] = {'\0', };
+       int ret = 0;
+
+       snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
+       ret = __read_proc(buf, buf, sizeof(buf));
+       if (ret <= 0)
+               return NULL;
+
+       /* support app launched by shell script*/
+       if (strncmp(buf, "/bin/sh", 7) == 0)
+               return strdup(&buf[7 + 1]);
+       else
+               return strdup(buf);
+}
+
+int __get_appid_func(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+       int ret = -1;
+       char *appid;
+       char **return_appid = (char **)user_data;
+       ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+       ALARM_MGR_LOG_PRINT("appid %s.", appid);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("Failed to get appid\n");
+       } else {
+               *return_appid = strdup(appid);
+               ret = 0;
+       }
+
+       return ret;
+}
+
+static int __zone_get_appid_bypid(int pid, const char *zone, char **appid)
+{
+       int ret = -1;
+       char cmdline[PATH_MAX];
+       char *appid_tmp = NULL;
+       int i = 0;
+
+       ret = aul_app_get_cmdline_bypid(pid, cmdline, PATH_MAX);
+       if (ret != 0) {
+               ALARM_MGR_EXCEPTION_PRINT("get_cmdline_bypid is failed\n");
+               return -1;
+       }
+
+       ALARM_MGR_LOG_PRINT("cmdline(%s)", cmdline);
+
+       if (strncmp(zone, "/", 1) == 0) {
+               pkgmgrinfo_pkginfo_set_zone(NULL, NULL, 0);
+       } else {
+               pkgmgrinfo_pkginfo_set_zone(zone, NULL, 0);
+       }
+
+       pkgmgrinfo_appinfo_filter_h handle;
+       ret = pkgmgrinfo_appinfo_filter_create(&handle);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("appinfo filter handle create failed\n");
+               return -1;
+       }
+
+       ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+                       PMINFO_APPINFO_PROP_APP_EXEC, cmdline);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("pkgmgrinfo_appinfo_filter_add_string() failed: exec(%s)", cmdline);
+               goto catch;
+       }
+
+       ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __get_appid_func, &appid_tmp);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n");
+               goto catch;
+       }
+
+       if (appid_tmp) {
+               ALARM_MGR_LOG_PRINT("appid_tmp(%s)", appid_tmp);
+               ret = 0;
+       } else
+               ret = -1;
+
+       *appid = appid_tmp;
+
+catch:
+       pkgmgrinfo_appinfo_filter_destroy(handle);
+
+       return ret;
+}
+
+int __get_pkgid_func(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+       int ret = -1;
+       char *pkgid;
+       char **return_pkgid = (char **)user_data;
+       ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+       ALARM_MGR_LOG_PRINT("pkgid %s.", pkgid);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("Failed to get pkgid\n");
+       } else {
+               *return_pkgid = strdup(pkgid);
+               ret = 0;
+       }
+
+       return ret;
+}
+
+static int __zone_get_pkgid_bypid(int pid, const char *zone, char **pkgid)
+{
+       int ret = -1;
+       char cmdline[PATH_MAX];
+       char *pkgid_tmp = NULL;
+       int i = 0;
+
+       ret = aul_app_get_cmdline_bypid(pid, cmdline, PATH_MAX);
+       if (ret != 0) {
+               ALARM_MGR_EXCEPTION_PRINT("get_cmdline_bypid is failed\n");
+               return -1;
+       }
+
+       ALARM_MGR_LOG_PRINT("cmdline(%s)", cmdline);
+
+       if (strncmp(zone, "/", 1) == 0) {
+               pkgmgrinfo_pkginfo_set_zone(NULL, NULL, 0);
+       } else {
+               pkgmgrinfo_pkginfo_set_zone(zone, NULL, 0);
+       }
+
+       pkgmgrinfo_appinfo_filter_h handle;
+       ret = pkgmgrinfo_appinfo_filter_create(&handle);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("appinfo filter handle create failed\n");
+               return -1;
+       }
+
+       ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+                       PMINFO_APPINFO_PROP_APP_EXEC, cmdline);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("pkgmgrinfo_appinfo_filter_add_string() failed: exec(%s)", cmdline);
+               goto catch;
+       }
+
+       ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __get_pkgid_func, &pkgid_tmp);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n");
+               goto catch;
+       }
+
+       if (pkgid_tmp) {
+               ALARM_MGR_LOG_PRINT("pkgid_tmp(%s)", pkgid_tmp);
+               ret = 0;
+       } else
+               ret = -1;
+
+       *pkgid = pkgid_tmp;
+
+catch:
+       pkgmgrinfo_appinfo_filter_destroy(handle);
+
+       return ret;
+}
+
+static int __zone_get_pkgid_byappid(const char *appid, const char *zone, char **pkgid)
+{
+       int ret = -1;
+       char *pkgid_tmp = NULL;
+       int i;
+
+       if (strncmp(zone, "/", 1) == 0) {
+               pkgmgrinfo_pkginfo_set_zone(NULL, NULL, 0);
+       } else {
+               pkgmgrinfo_pkginfo_set_zone(zone, NULL, 0);
+       }
+
+       pkgmgrinfo_appinfo_filter_h handle;
+       ret = pkgmgrinfo_appinfo_filter_create(&handle);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("appinfo filter handle create failed\n");
+               return -1;
+       }
+
+       ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+                       PMINFO_APPINFO_PROP_APP_ID, appid);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("pkgmgrinfo_appinfo_filter_add_string() failed : appid(%s)", appid);
+               goto catch;
+       }
+
+       ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __get_pkgid_func, &pkgid_tmp);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n");
+               goto catch;
+       }
+
+       if (pkgid_tmp) {
+               ALARM_MGR_LOG_PRINT("pkgid_tmp(%s)", pkgid_tmp);
+               ret = 0;
+       } else
+               ret = -1;
+
+       *pkgid = pkgid_tmp;
+catch:
+       pkgmgrinfo_appinfo_filter_destroy(handle);
+       return ret;
+}
+
+bool _get_zone_name(int pid, char *zone_name, int len)
+{
+       vsm_zone_h zone;
+       vsm_context_h ctx = vsm_create_context();
+       const char *zone_name_tmp = NULL;
+       bool ret = true;
+       if (ctx == NULL) {
+                       ALARM_MGR_EXCEPTION_PRINT("vsm_create_context failed");
+                       return false;
+       }
+       zone = vsm_lookup_zone_by_pid(ctx, pid);
+
+       if (zone != NULL && !vsm_is_host_zone(zone)) {
+               zone_name_tmp = vsm_get_zone_name(zone);
+               if (zone_name_tmp == NULL) {
+                       ALARM_MGR_EXCEPTION_PRINT("failed to get zone");
+                       ret = false;
+                       goto err;
+               }
+       } else if (vsm_is_host_zone(zone)) {
+               zone_name_tmp = "/";
+       } else {
+               ALARM_MGR_EXCEPTION_PRINT("could not get zone name");
+               ret = false;
+               goto err;
+       }
+
+       snprintf(zone_name, len, "%s", zone_name_tmp);
+       ALARM_MGR_EXCEPTION_PRINT("zone name [%s]", zone_name);
+err:
+       if (vsm_cleanup_context(ctx) != 0)
+               ALARM_MGR_EXCEPTION_PRINT("vsm cleanup failed");
+       return ret;
+}
+
+
 bool __alarm_clean_list()
 {
        g_slist_free_full(alarm_context.alarms, g_free);
 bool __alarm_clean_list()
 {
        g_slist_free_full(alarm_context.alarms, g_free);
@@ -355,6 +650,10 @@ static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
        for (iter = alarm_context.alarms; iter != NULL;
             iter = g_slist_next(iter)) {
                entry = iter->data;
        for (iter = alarm_context.alarms; iter != NULL;
             iter = g_slist_next(iter)) {
                entry = iter->data;
+
+               if (strcmp(g_quark_to_string(entry->zone), g_quark_to_string(__alarm_info->zone)) != 0)
+                       continue;
+
                if (entry->alarm_id == alarm_id) {
 
                        found = true;
                if (entry->alarm_id == alarm_id) {
 
                        found = true;
@@ -384,27 +683,33 @@ static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
 }
 
 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
 }
 
 static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
-                                    int *error_code)
+                                    int *error_code, const char *zone)
 {
        bool found = false;
 {
        bool found = false;
-
        alarm_info_t *alarm_info = NULL;
        alarm_info_t *alarm_info = NULL;
-
        GSList *iter = NULL;
        __alarm_info_t *entry = NULL;
 
        /*list alarms */
        ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)", alarm_id);
        GSList *iter = NULL;
        __alarm_info_t *entry = NULL;
 
        /*list alarms */
        ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)", alarm_id);
+       if (zone == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: zone is NULL");
+               return false;
+       }
 
        for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
                entry = iter->data;
 
        for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
                entry = iter->data;
+
+               if (zone && strcmp(g_quark_to_string(entry->zone), zone) != 0)
+                       continue;
+
                if (entry->alarm_id == alarm_id) {
                        alarm_info = &entry->alarm_info;
 
                if (entry->alarm_id == alarm_id) {
                        alarm_info = &entry->alarm_info;
 
-                       ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Remove alarm id(%d)", entry->alarm_id);
+                       ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Remove alarm id(%d) zone(%s)", entry->alarm_id, zone);
 
                        if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
 
                        if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
-                               _delete_alarms(alarm_id);
+                               _delete_alarms(alarm_id, zone);
                        }
 
                        alarm_context.alarms = g_slist_remove(alarm_context.alarms, iter->data);
                        }
 
                        alarm_context.alarms = g_slist_remove(alarm_context.alarms, iter->data);
@@ -522,6 +827,44 @@ static bool alarm_get_tz_info(int *gmt_idx, int *dst)
 }
 */
 
 }
 */
 
+gboolean __update_relative_alarms(gpointer user_data)
+{
+       GSList *iter = NULL;
+       GSList *iter_db = NULL;
+       __alarm_info_t *entry = NULL;
+       char *error_message = NULL;
+       int ret = SQLITE_OK;
+       sqlite3 *alarmmgr_db = NULL;
+
+       for (iter_db = alarmmgr_db_list; iter_db != NULL; iter_db = g_slist_next(iter_db)) {
+               alarmmgr_db = ((_zone_alarm_db_list_t *)iter_db->data)->alarmmgr_db;
+               ret = sqlite3_exec(alarmmgr_db, "BEGIN EXCLUSIVE", NULL, NULL, &error_message);
+               if (ret != SQLITE_OK) {
+                       SECURE_LOGE("sqlite3_exec() is failed. ret = %d, error message = %s", ret, error_message);
+                       return false;
+               }
+       }
+
+       for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
+               entry = iter->data;
+               alarm_info_t *alarm_info = &(entry->alarm_info);
+               if (alarm_info->alarm_type & ALARM_TYPE_RELATIVE) {
+                       _update_alarms(entry);
+               }
+       }
+
+       for (iter_db = alarmmgr_db_list; iter_db != NULL; iter_db = g_slist_next(iter_db)) {
+               alarmmgr_db = ((_zone_alarm_db_list_t *)iter_db->data)->alarmmgr_db;
+               ret = sqlite3_exec(alarmmgr_db, "COMMIT", NULL, NULL, &error_message);
+               if (ret != SQLITE_OK) {
+                       SECURE_LOGE("sqlite3_exec() is failed. ret = %d, error message = %s", ret, error_message);
+                       return false;
+               }
+       }
+
+       return false;
+}
+
 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
 {
        time_t current_time;
 static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
 {
        time_t current_time;
@@ -532,22 +875,18 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
        struct tm *p_time = NULL ;
        struct tm due_time_result ;
        struct tm fixed_time = { 0, };
        struct tm *p_time = NULL ;
        struct tm due_time_result ;
        struct tm fixed_time = { 0, };
+       is_time_changed = true;
 
 
-       for (iter = alarm_context.alarms; iter != NULL;
-            iter = g_slist_next(iter)) {
+       tzset();
+       for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
                entry = iter->data;
                alarm_info_t *alarm_info = &(entry->alarm_info);
                if (alarm_info->alarm_type & ALARM_TYPE_RELATIVE) {
                entry = iter->data;
                alarm_info_t *alarm_info = &(entry->alarm_info);
                if (alarm_info->alarm_type & ALARM_TYPE_RELATIVE) {
-                       /*diff_time Ã³\B8\AE */
-
                        entry->due_time += diff_time;
 
                        entry->due_time += diff_time;
 
-                       alarm_date_t *start = &alarm_info->start; /**< start
-                                                       time of the alarm */
-                       alarm_date_t *end = &alarm_info->end;;
-                                               /**< end time of the alarm */
+                       alarm_date_t *start = &alarm_info->start;       /**< start time of the alarm */
+                       alarm_date_t *end = &alarm_info->end;   /**< end time of the alarm */
 
 
-                       tzset();
                        p_time = localtime_r(&entry->due_time, &due_time_result);
                        if (p_time != NULL) {
                                start->year = p_time->tm_year + 1900;
                        p_time = localtime_r(&entry->due_time, &due_time_result);
                        if (p_time != NULL) {
                                start->year = p_time->tm_year + 1900;
@@ -561,7 +900,6 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
                                end->month = p_time->tm_mon + 1;
                                end->day = p_time->tm_mday;
 
                                end->month = p_time->tm_mon + 1;
                                end->day = p_time->tm_mday;
 
-
                                memset(&fixed_time, 0, sizeof(fixed_time));
                                fixed_time.tm_year = p_time->tm_year;
                                fixed_time.tm_mon = p_time->tm_mon;
                                memset(&fixed_time, 0, sizeof(fixed_time));
                                fixed_time.tm_year = p_time->tm_year;
                                fixed_time.tm_mon = p_time->tm_mon;
@@ -577,15 +915,8 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
                        fixed_time.tm_sec = 59;
 
                        entry->end = mktime(&fixed_time);
                        fixed_time.tm_sec = 59;
 
                        entry->end = mktime(&fixed_time);
-
-                       ALARM_MGR_LOG_PRINT("alarm_info->alarm_type is "
-                                           "ALARM_TYPE_RELATIVE\n");
-
-                       _update_alarms(entry);
                }
                }
-
                _alarm_next_duetime(entry);
                _alarm_next_duetime(entry);
-               ALARM_MGR_LOG_PRINT("entry->due_time is %d\n", entry->due_time);
        }
 
        time(&current_time);
        }
 
        time(&current_time);
@@ -596,15 +927,14 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
 
                double interval = 0;
 
 
                double interval = 0;
 
-               ALARM_MGR_LOG_PRINT("alarm[%d] with duetime(%u) at "
-               "current(%u)\n", entry->alarm_id, due_time, current_time);
+               ALARM_MGR_LOG_PRINT("alarm[%d] with duetime(%u) at current(%u)", entry->alarm_id, due_time, current_time);
                if (due_time == 0) {    /* 0 means this alarm has been disabled */
                        continue;
                }
 
                interval = difftime(due_time, current_time);
 
                if (due_time == 0) {    /* 0 means this alarm has been disabled */
                        continue;
                }
 
                interval = difftime(due_time, current_time);
 
-               if (interval <= 0) {
+               if (interval < 0) {
                        ALARM_MGR_EXCEPTION_PRINT("The duetime of alarm(%d) is OVER.", entry->alarm_id);
                        continue;
                }
                        ALARM_MGR_EXCEPTION_PRINT("The duetime of alarm(%d) is OVER.", entry->alarm_id);
                        continue;
                }
@@ -614,16 +944,18 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
                if ((interval < 0) || min_time == -1) {
                        min_time = due_time;
                }
                if ((interval < 0) || min_time == -1) {
                        min_time = due_time;
                }
-
        }
 
        }
 
+       is_time_changed = false;
        alarm_context.c_due_time = min_time;
 
        alarm_context.c_due_time = min_time;
 
+       g_idle_add(__update_relative_alarms, NULL);
        return true;
 }
 
 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
        return true;
 }
 
 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
-                          int pid, char *bundle_data, int *error_code)
+                       long requested_interval, int pid, char *bundle_data,
+                       int *error_code, const char *zone)
 {
        time_t current_time;
        time_t due_time;
 {
        time_t current_time;
        time_t due_time;
@@ -632,7 +964,7 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
        char app_name[512] = { 0 };
        bundle *b;
        char caller_appid[256] = { 0 };
        char app_name[512] = { 0 };
        bundle *b;
        char caller_appid[256] = { 0 };
-       char* callee_appid = NULL;
+       const char* callee_appid = NULL;
        char* caller_pkgid = NULL;
        char* callee_pkgid = NULL;
        pkgmgrinfo_pkginfo_h caller_handle;
        char* caller_pkgid = NULL;
        char* callee_pkgid = NULL;
        pkgmgrinfo_pkginfo_h caller_handle;
@@ -651,8 +983,12 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
 
        __alarm_info->pid = pid;
        __alarm_info->alarm_id = -1;
 
        __alarm_info->pid = pid;
        __alarm_info->alarm_id = -1;
+       __alarm_info->requested_interval = requested_interval;
+       if (alarm_info->alarm_type & ALARM_TYPE_PERIOD)
+               __alarm_info->method = QUANTUMIZE;
 
 
-       if (!__get_caller_unique_name(pid, app_name)) {
+       if (!__get_caller_unique_name(pid, app_name, zone)) {
+               ALARM_MGR_EXCEPTION_PRINT("get_caller_unique_name failed with pid[%d]\n", pid);
                *error_code = ERR_ALARM_SYSTEM_FAIL;
                free(__alarm_info);
                return false;
                *error_code = ERR_ALARM_SYSTEM_FAIL;
                free(__alarm_info);
                return false;
@@ -663,14 +999,30 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
        // caller
        __alarm_info->quark_caller_pkgid = g_quark_from_string("null");
 
        // caller
        __alarm_info->quark_caller_pkgid = g_quark_from_string("null");
 
-       if (aul_app_get_appid_bypid(pid, caller_appid, 256) == AUL_R_OK) {
-               if (pkgmgrinfo_appinfo_get_appinfo(caller_appid, &caller_handle) == PMINFO_R_OK) {
-                       if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
-                               if (caller_pkgid) {
-                                       __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+       if (zone == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("zone is null");
+               *error_code = ERR_ALARM_SYSTEM_FAIL;
+               free(__alarm_info);
+               return false;
+       }
+
+       __alarm_info->zone = g_quark_from_string(zone);
+       if (strcmp(zone, "/") != 0) {
+               if (__zone_get_pkgid_bypid(pid, zone, &caller_pkgid) == 0) {
+                       __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+                       free(caller_pkgid);
+               }
+       } else {
+               /*request from host, such as pushd*/
+               if (aul_app_get_appid_bypid(pid, caller_appid, 256) == AUL_R_OK) {
+                       if (pkgmgrinfo_appinfo_get_appinfo(caller_appid, &caller_handle) == PMINFO_R_OK) {
+                               if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
+                                       if (caller_pkgid) {
+                                               __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+                                       }
                                }
                                }
+                               pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
                        }
                        }
-                       pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
                }
        }
 
                }
        }
 
@@ -679,13 +1031,24 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
 
        b = bundle_decode((bundle_raw *)bundle_data, strlen(bundle_data));
        callee_appid = appsvc_get_appid(b);
 
        b = bundle_decode((bundle_raw *)bundle_data, strlen(bundle_data));
        callee_appid = appsvc_get_appid(b);
-       if (pkgmgrinfo_appinfo_get_appinfo(callee_appid, &callee_handle) == PMINFO_R_OK) {
-               if (pkgmgrinfo_appinfo_get_pkgid(callee_handle, &callee_pkgid) == PMINFO_R_OK) {
-                       if (callee_pkgid) {
-                               __alarm_info->quark_callee_pkgid = g_quark_from_string(callee_pkgid);
+
+       if (strcmp(zone, "/") != 0) {
+               if (!__zone_get_pkgid_byappid(callee_appid, zone, &callee_pkgid)) {
+                       __alarm_info->quark_callee_pkgid = g_quark_from_string(callee_pkgid);
+                       free(callee_pkgid);
+               }
+
+       }
+       else {
+               /*it is now happened in host side. */
+               if (pkgmgrinfo_appinfo_get_appinfo(callee_appid, &callee_handle) == PMINFO_R_OK) {
+                       if (pkgmgrinfo_appinfo_get_pkgid(callee_handle, &callee_pkgid) == PMINFO_R_OK) {
+                               if (callee_pkgid) {
+                                       __alarm_info->quark_callee_pkgid = g_quark_from_string(callee_pkgid);
+                               }
                        }
                        }
+                       pkgmgrinfo_appinfo_destroy_appinfo(callee_handle);
                }
                }
-               pkgmgrinfo_appinfo_destroy_appinfo(callee_handle);
        }
 
        SECURE_LOGD("caller_pkgid = %s, callee_pkgid = %s",
        }
 
        SECURE_LOGD("caller_pkgid = %s, callee_pkgid = %s",
@@ -763,7 +1126,7 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
                        int pid, periodic_method_e method, long requested_interval, int is_ref,
                        char *app_service_name, char *app_service_name_mod,
                        const char *dst_service_name, const char *dst_service_name_mod,
                        int pid, periodic_method_e method, long requested_interval, int is_ref,
                        char *app_service_name, char *app_service_name_mod,
                        const char *dst_service_name, const char *dst_service_name_mod,
-                       int *error_code)
+                       int *error_code, const char *zone)
 {
        time_t current_time;
        time_t due_time;
 {
        time_t current_time;
        time_t due_time;
@@ -789,21 +1152,30 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
        __alarm_info->is_ref = is_ref;
 
        // Get caller_appid to get caller's package id. There is no callee.
        __alarm_info->is_ref = is_ref;
 
        // Get caller_appid to get caller's package id. There is no callee.
-       if (aul_app_get_appid_bypid(pid, caller_appid, 256) == AUL_R_OK) {
-               if (pkgmgrinfo_appinfo_get_appinfo(caller_appid, &caller_handle) == PMINFO_R_OK) {
-                       if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
-                               if (caller_pkgid) {
-                                       __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+
+       __alarm_info->zone = g_quark_from_string(zone);
+       if (strcmp(zone, "/") != 0) {
+               if (__zone_get_pkgid_bypid(pid, zone, &caller_pkgid) == 0) {
+                       __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+                       free(caller_pkgid);
+               }
+       } else {
+               /*request from host, such as pushd*/
+               if (aul_app_get_appid_bypid(pid, caller_appid, 256) == AUL_R_OK) {
+                       if (pkgmgrinfo_appinfo_get_appinfo(caller_appid, &caller_handle) == PMINFO_R_OK) {
+                               if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
+                                       if (caller_pkgid) {
+                                               __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+                                       }
                                }
                                }
+                               pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
                        }
                        }
-                       pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
                }
        }
 
        __alarm_info->quark_callee_pkgid = g_quark_from_string("null");
        SECURE_LOGD("caller_pkgid = %s, callee_pkgid = null", g_quark_to_string(__alarm_info->quark_caller_pkgid));
                }
        }
 
        __alarm_info->quark_callee_pkgid = g_quark_from_string("null");
        SECURE_LOGD("caller_pkgid = %s, callee_pkgid = null", g_quark_to_string(__alarm_info->quark_caller_pkgid));
-
-       if (!__get_caller_unique_name(pid, app_name)) {
+       if (!__get_caller_unique_name(pid, app_name, zone)) {
                *error_code = ERR_ALARM_SYSTEM_FAIL;
                free(__alarm_info);
                return false;
                *error_code = ERR_ALARM_SYSTEM_FAIL;
                free(__alarm_info);
                return false;
@@ -815,7 +1187,6 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
        __alarm_info->quark_dst_service_name = g_quark_from_string(dst_service_name);
        __alarm_info->quark_dst_service_name_mod = g_quark_from_string(dst_service_name_mod);
        __alarm_info->quark_bundle = g_quark_from_string("null");
        __alarm_info->quark_dst_service_name = g_quark_from_string(dst_service_name);
        __alarm_info->quark_dst_service_name_mod = g_quark_from_string(dst_service_name_mod);
        __alarm_info->quark_bundle = g_quark_from_string("null");
-
        __alarm_set_start_and_end_time(alarm_info, __alarm_info);
        memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
        __alarm_generate_alarm_id(__alarm_info, alarm_id);
        __alarm_set_start_and_end_time(alarm_info, __alarm_info);
        memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
        __alarm_generate_alarm_id(__alarm_info, alarm_id);
@@ -877,7 +1248,7 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
 }
 
 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
 }
 
 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
-                          alarm_info_t *alarm_info, int *error_code)
+                          alarm_info_t *alarm_info, int *error_code, const char *zone)
 {
        time_t current_time;
        time_t due_time;
 {
        time_t current_time;
        time_t due_time;
@@ -910,6 +1281,7 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
                "(%d) is less than current time(%d)", alarm_context.c_due_time, current_time);
                alarm_context.c_due_time = -1;
        }
                "(%d) is less than current time(%d)", alarm_context.c_due_time, current_time);
                alarm_context.c_due_time = -1;
        }
+       __alarm_info->zone = g_quark_from_string(zone);
 
        due_time = _alarm_next_duetime(__alarm_info);
        if (!__alarm_update_in_list(pid, alarm_id, __alarm_info, error_code)) {
 
        due_time = _alarm_next_duetime(__alarm_info);
        if (!__alarm_update_in_list(pid, alarm_id, __alarm_info, error_code)) {
@@ -919,7 +1291,7 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
                return false;
        }
 
                return false;
        }
 
-       result = _remove_from_scheduled_alarm_list(pid, alarm_id);
+       result = _remove_from_scheduled_alarm_list(pid, alarm_id, zone);
 
        if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
                /*there is no scheduled alarm */
 
        if (result == true && g_slist_length(g_scheduled_alarm_list) == 0) {
                /*there is no scheduled alarm */
@@ -983,14 +1355,14 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
        return true;
 }
 
        return true;
 }
 
-static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code)
+static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code, const char *zone)
 {
        bool result = false;
 
        SECURE_LOGD("[alarm-server]:delete alarm: alarm(%d) pid(%d)\n", alarm_id, pid);
 {
        bool result = false;
 
        SECURE_LOGD("[alarm-server]:delete alarm: alarm(%d) pid(%d)\n", alarm_id, pid);
-       result = _remove_from_scheduled_alarm_list(pid, alarm_id);
+       result = _remove_from_scheduled_alarm_list(pid, alarm_id, zone);
 
 
-       if (!__alarm_remove_from_list(pid, alarm_id, error_code)) {
+       if (!__alarm_remove_from_list(pid, alarm_id, error_code, zone)) {
 
                SECURE_LOGE("[alarm-server]:delete alarm: "
                                          "alarm(%d) pid(%d) has failed with error_code(%d)\n",
 
                SECURE_LOGE("[alarm-server]:delete alarm: "
                                          "alarm(%d) pid(%d) has failed with error_code(%d)\n",
@@ -1023,7 +1395,7 @@ static bool __can_skip_expired_cb(alarm_id_t alarm_id)
                        int dur = entry->requested_interval;
                        int from, to;
 
                        int dur = entry->requested_interval;
                        int from, to;
 
-                       if (!(alarm->alarm_type & ALARM_TYPE_PERIOD) || entry->method == CUT_OFF)
+                       if (dur == 0 || !(alarm->alarm_type & ALARM_TYPE_PERIOD) || entry->method == CUT_OFF)
                                return false;
 
                        ts_tm.tm_hour = alarm->start.hour;
                                return false;
 
                        ts_tm.tm_hour = alarm->start.hour;
@@ -1103,6 +1475,34 @@ static int __get_caller_pid(const char *name)
        return pid;
 }
 
        return pid;
 }
 
+static int __is_ui_app(const char *appid)
+{
+       if (appid == NULL)
+               return 0;
+
+       int ret = 0;
+       pkgmgrinfo_appinfo_h appinfo_h = NULL;
+
+       ret = pkgmgrinfo_appinfo_get_appinfo(appid, &appinfo_h);
+
+       if (ret < 0 ) {
+               return 0;
+       }
+
+       char *component = NULL;
+       int found = 0;
+
+       ret = pkgmgrinfo_appinfo_get_component_type(appinfo_h, &component);
+       if (ret == 0 && component != NULL && strncmp(component, "uiapp", 5) == 0) {
+               found = 1;
+       }
+
+       if (appinfo_h)
+               pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
+
+       return found;
+}
+
 static void __alarm_expired()
 {
        const char *destination_app_service_name = NULL;
 static void __alarm_expired()
 {
        const char *destination_app_service_name = NULL;
@@ -1113,7 +1513,9 @@ static void __alarm_expired()
        int b_len = 0;
        bundle *b = NULL;
        char *appid = NULL;
        int b_len = 0;
        bundle *b = NULL;
        char *appid = NULL;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
        GError *error = NULL;
        GVariant *result = NULL;
        gboolean name_has_owner_reply = false;
        GError *error = NULL;
        GVariant *result = NULL;
        gboolean name_has_owner_reply = false;
@@ -1126,7 +1528,7 @@ static void __alarm_expired()
        time(&current_time);
 
        interval = difftime(alarm_context.c_due_time, current_time);
        time(&current_time);
 
        interval = difftime(alarm_context.c_due_time, current_time);
-       ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), current_time(%d), interval(%d)",
+       ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), current_time(%d), interval(%f)",
                alarm_context.c_due_time, current_time, interval);
 
        if (alarm_context.c_due_time > current_time + 1) {
                alarm_context.c_due_time, current_time, interval);
 
        if (alarm_context.c_due_time > current_time + 1) {
@@ -1136,7 +1538,7 @@ static void __alarm_expired()
        }
        // 10 seconds is maximum permitted delay from timer expire to this function
        if (alarm_context.c_due_time + 10 < current_time) {
        }
        // 10 seconds is maximum permitted delay from timer expire to this function
        if (alarm_context.c_due_time + 10 < current_time) {
-               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: False Alarm. due time is (%d) seconds past\n",
+               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: False Alarm. due time is (%d) seconds past.",
                        current_time - alarm_context.c_due_time);
                goto done;
        }
                        current_time - alarm_context.c_due_time);
                goto done;
        }
@@ -1145,58 +1547,99 @@ static void __alarm_expired()
        __scheduled_alarm_t *alarm = NULL;
 
        for (iter = g_scheduled_alarm_list; iter != NULL; iter = g_slist_next(iter)) {
        __scheduled_alarm_t *alarm = NULL;
 
        for (iter = g_scheduled_alarm_list; iter != NULL; iter = g_slist_next(iter)) {
-               const gchar *quark_bundle = NULL;
                alarm = iter->data;
                alarm_id = alarm->alarm_id;
                alarm = iter->data;
                alarm_id = alarm->alarm_id;
-
                __alarm_info = alarm->__alarm_info;
                __alarm_info = alarm->__alarm_info;
-
                app_pid = __alarm_info->pid;
 
                app_pid = __alarm_info->pid;
 
-               quark_bundle = g_quark_to_string(__alarm_info->quark_bundle);
-               if (quark_bundle && strncmp(quark_bundle, "null", 4) != 0) {
-                               b_len = strlen(quark_bundle);
+               char *old_zone;
+               const char *zone = g_quark_to_string(__alarm_info->zone);
+               ALARM_MGR_EXCEPTION_PRINT("zone %s\n", zone);
 
 
-                               b = bundle_decode((bundle_raw *)quark_bundle, b_len);
+               if (zone && strncmp(zone, "/", 1) == 0) {
+                       aul_set_zone(NULL, &old_zone);
+                       pkgmgrinfo_pkginfo_set_zone(NULL, NULL, 0);
+               }
+               else {
+                       aul_set_zone(zone, &old_zone);
+                       pkgmgrinfo_pkginfo_set_zone(zone, NULL, 0);
+               }
 
 
-                               if (b == NULL)
-                               {
-                                       ALARM_MGR_EXCEPTION_PRINT("Error!!!..Unable to decode the bundle!!\n");
+               // Case #1. The process is an application launched by app_control.
+               // It registered an alarm using launch-based APIs like alarm_schedule_xxx, alarmmgr_xxx_appsvc.
+               if (g_quark_to_string(__alarm_info->quark_bundle) != NULL && strncmp(g_quark_to_string(__alarm_info->quark_bundle), "null", 4) != 0) {
+                       b_len = strlen(g_quark_to_string(__alarm_info->quark_bundle));
+
+                       b = bundle_decode((bundle_raw *)g_quark_to_string(__alarm_info->quark_bundle), b_len);
+
+                       if (b == NULL)
+                       {
+                               ALARM_MGR_EXCEPTION_PRINT("Error!!!..Unable to decode the bundle!!\n");
+                       }
+                       else
+                       {
+                               snprintf(alarm_id_val,31,"%d",alarm_id);
+
+                               if (bundle_add_str(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){
+                                       ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n");
                                }
                                else
                                {
                                }
                                else
                                {
-                                       snprintf(alarm_id_val,31,"%d",alarm_id);
-
-                                       if (bundle_add_str(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){
-                                               ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n");
+                                       // Checking api version
+                                       int ret;
+                                       int result = 0;
+                                       pkgmgrinfo_pkginfo_h pkginfo = NULL;
+                                       const char *api_version = "2.4";
+                                       const char *pkgid = g_quark_to_string(__alarm_info->quark_caller_pkgid);
+
+                                       if (pkgid != NULL) {
+                                               ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkginfo);
+                                               if (ret != PMINFO_R_OK) {
+                                                       ALARM_MGR_EXCEPTION_PRINT("Failed to get pkginfo\n");
+                                               }
+                                               else {
+                                                       ret = pkgmgrinfo_pkginfo_check_api_version(pkginfo, api_version, &result);
+                                                       if (ret != PMINFO_R_OK) {
+                                                               ALARM_MGR_EXCEPTION_PRINT("Failed to check api version\n");
+                                                       }
+                                                       pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+                                               }
                                        }
                                        }
-                                       else
-                                       {
+
+                                       if (result < 0) { /* before 2.4 */
+                                               if ( appsvc_run_service(b, 0, NULL, NULL) < 0) {
+                                                       ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
+                                               }
+                                               else {
+                                                       ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
+                                               }
+                                       } else { /* since 2.4 */
                                                appid = (char *)appsvc_get_appid(b);
                                                appid = (char *)appsvc_get_appid(b);
-                                               if( (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_NOLAUNCH) && !aul_app_is_running(appid))
-                                               {
+                                               if( (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_NOLAUNCH) && !aul_app_is_running(appid))  {
                                                        ALARM_MGR_EXCEPTION_PRINT("This alarm is ignored\n");
                                                        ALARM_MGR_EXCEPTION_PRINT("This alarm is ignored\n");
-                                               }
-                                               else
-                                               {
-                                                       if ( appsvc_run_service(b, 0, NULL, NULL) < 0)
-                                                       {
-                                                               ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
+                                               } else if ( !(__alarm_info->alarm_info.alarm_type & ALARM_TYPE_INEXACT) ||
+                                                               !__can_skip_expired_cb(__alarm_info->alarm_id) ) {
+                                                       if (appsvc_run_service(b, 0, NULL, NULL ) < 0) {
+                                                               ALARM_MGR_EXCEPTION_PRINT("Unable to launch app [%s] \n", appid);
                                                        }
                                                        }
-                                                       else
-                                                       {
+                                                       else {
                                                                ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
                                                                ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
+                                                               if (__is_ui_app(appid)) {
+                                                                       device_display_change_state(DISPLAY_STATE_NORMAL);
+                                                               }
                                                        }
                                                }
                                        }
                                                        }
                                                }
                                        }
-                                       bundle_free(b);
                                }
                                }
-
+                               bundle_free(b);
+                       }
                }
                else
                {
                }
                else
                {
-                       const gchar *dst_service_name = g_quark_to_string(__alarm_info->quark_dst_service_name);
-                       if (dst_service_name && strncmp(dst_service_name, "null", 4) == 0) {
+                       char appid[MAX_SERVICE_NAME_LEN] = { 0, };
+                       pkgmgrinfo_appinfo_h appinfo_handle = NULL;
+
+                       if (g_quark_to_string(__alarm_info->quark_bundle) != NULL && strncmp(g_quark_to_string(__alarm_info->quark_dst_service_name), "null", 4) == 0) {
                                SECURE_LOGD("[alarm-server]:destination is null, so we send expired alarm to %s(%u).",
                                        g_quark_to_string(__alarm_info->quark_app_service_name), __alarm_info->quark_app_service_name);
                                        destination_app_service_name = g_quark_to_string(__alarm_info->quark_app_service_name_mod);
                                SECURE_LOGD("[alarm-server]:destination is null, so we send expired alarm to %s(%u).",
                                        g_quark_to_string(__alarm_info->quark_app_service_name), __alarm_info->quark_app_service_name);
                                        destination_app_service_name = g_quark_to_string(__alarm_info->quark_app_service_name_mod);
@@ -1227,19 +1670,33 @@ static void __alarm_expired()
                                                                NULL,
                                                                &error);
                        if (result == NULL) {
                                                                NULL,
                                                                &error);
                        if (result == NULL) {
-                               ALARM_MGR_EXCEPTION_PRINT("g_dbus_connection_call_sync() is failed. err: %s", error->message);
-                               g_error_free(error);
+                               ALARM_MGR_EXCEPTION_PRINT("g_dbus_connection_call_sync() is failed");
+                               if (error) {
+                                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                                       g_error_free(error);
+                               }
                        } else {
                                g_variant_get (result, "(b)", &name_has_owner_reply);
                        }
 
                        } else {
                                g_variant_get (result, "(b)", &name_has_owner_reply);
                        }
 
-                       if (name_has_owner_reply == false) {
+                       if (g_quark_to_string(__alarm_info->quark_dst_service_name) != NULL && strncmp(g_quark_to_string(__alarm_info->quark_dst_service_name), "null",4) == 0)
+                               if (g_quark_to_string(__alarm_info->quark_app_service_name) != NULL && strlen(g_quark_to_string(__alarm_info->quark_app_service_name)) > 6)
+                                       strncpy(appid, g_quark_to_string(__alarm_info->quark_app_service_name) + 6, strlen(g_quark_to_string(__alarm_info->quark_app_service_name)) - 6);
+                       else
+                               if (g_quark_to_string(__alarm_info->quark_dst_service_name)  != NULL && strlen(g_quark_to_string(__alarm_info->quark_dst_service_name)) > 6)
+                                       strncpy(appid,  g_quark_to_string(__alarm_info->quark_dst_service_name) + 6, strlen(g_quark_to_string(__alarm_info->quark_dst_service_name)) - 6);
+
+                       pkgmgrinfo_appinfo_get_appinfo(appid, &appinfo_handle);
+                       ALARM_MGR_LOG_PRINT("appid : %s (%x)", appid, appinfo_handle);
+
+                       // Case #2. The process was killed && App type
+                       // This app is launched and owner of DBus connection is changed. and then, expiration noti is sent by DBus.
+                       if (name_has_owner_reply == false && appinfo_handle) {
                                __expired_alarm_t *expire_info;
                                __expired_alarm_t *expire_info;
-                               char appid[MAX_SERVICE_NAME_LEN] = { 0, };
                                char alarm_id_str[32] = { 0, };
 
                                if (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_WITHCB) {
                                char alarm_id_str[32] = { 0, };
 
                                if (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_WITHCB) {
-                                       __alarm_remove_from_list(__alarm_info->pid, alarm_id, NULL);
+                                       __alarm_remove_from_list(__alarm_info->pid, alarm_id, NULL, zone);
                                        goto done;
                                }
 
                                        goto done;
                                }
 
@@ -1253,13 +1710,6 @@ static void __alarm_expired()
                                expire_info->alarm_id = alarm_id;
                                g_expired_alarm_list = g_slist_append(g_expired_alarm_list, expire_info);
 
                                expire_info->alarm_id = alarm_id;
                                g_expired_alarm_list = g_slist_append(g_expired_alarm_list, expire_info);
 
-                               if (strncmp(g_quark_to_string(__alarm_info->quark_dst_service_name), "null",4) == 0) {
-                                       strncpy(appid,g_quark_to_string(__alarm_info->quark_app_service_name)+6,strlen(g_quark_to_string(__alarm_info->quark_app_service_name))-6);
-                               }
-                               else {
-                                       strncpy(appid,g_quark_to_string(__alarm_info->quark_dst_service_name)+6,strlen(g_quark_to_string(__alarm_info->quark_dst_service_name))-6);
-                               }
-
                                snprintf(alarm_id_str, 31, "%d", alarm_id);
 
                                SECURE_LOGD("before aul_launch appid(%s) alarm_id_str(%s)", appid, alarm_id_str);
                                snprintf(alarm_id_str, 31, "%d", alarm_id);
 
                                SECURE_LOGD("before aul_launch appid(%s) alarm_id_str(%s)", appid, alarm_id_str);
@@ -1267,27 +1717,30 @@ static void __alarm_expired()
                                bundle *kb;
                                kb = bundle_create();
                                bundle_add_str(kb, "__ALARM_MGR_ID", alarm_id_str);
                                bundle *kb;
                                kb = bundle_create();
                                bundle_add_str(kb, "__ALARM_MGR_ID", alarm_id_str);
-                               aul_launch_app(appid, kb);
+                               aul_launch_app(appid, kb);      // on_bus_name_owner_changed will be called.
                                bundle_free(kb);
                        } else {
                                bundle_free(kb);
                        } else {
+                               // Case #3. The process is alive or was killed && non-app type(daemon)
+                               // Expiration noti is sent by DBus. it makes the process alive. (dbus auto activation)
                                ALARM_MGR_LOG_PRINT("before alarm_send_noti_to_application");
                                ALARM_MGR_LOG_PRINT("WAKEUP pid: %d", __alarm_info->pid);
 
                                aul_update_freezer_status(__alarm_info->pid, "wakeup");
                                ALARM_MGR_LOG_PRINT("before alarm_send_noti_to_application");
                                ALARM_MGR_LOG_PRINT("WAKEUP pid: %d", __alarm_info->pid);
 
                                aul_update_freezer_status(__alarm_info->pid, "wakeup");
-                               __alarm_send_noti_to_application(destination_app_service_name, alarm_id);
+                               __alarm_send_noti_to_application(destination_app_service_name, alarm_id);       // dbus auto activation
                                ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application");
                        }
                }
 
                                ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application");
                        }
                }
 
-               ALARM_MGR_EXCEPTION_PRINT("alarm_id[%d] is expired.", alarm_id);
+               ALARM_MGR_LOG_PRINT("alarm_id[%d] is expired.", alarm_id);
 
 
-               sprintf(log_message, "alarmID: %d, pid: %d, unique_name: %s, duetime: %d",
-                       alarm_id, app_pid, g_quark_to_string(__alarm_info->quark_app_unique_name), __alarm_info->due_time);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+               snprintf(log_message, sizeof(log_message), "alarmID: %d, pid: %d, duetime: %d", alarm_id, app_pid, (int)__alarm_info->due_time);
                __save_module_log("EXPIRED", log_message);
                memset(log_message, '\0', sizeof(log_message));
                __save_module_log("EXPIRED", log_message);
                memset(log_message, '\0', sizeof(log_message));
+#endif
 
                if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE) {
 
                if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE) {
-                       __alarm_remove_from_list(__alarm_info->pid, alarm_id, NULL);
+                       __alarm_remove_from_list(__alarm_info->pid, alarm_id, NULL, zone);
                } else {
                        _alarm_next_duetime(__alarm_info);
                }
                } else {
                        _alarm_next_duetime(__alarm_info);
                }
@@ -1304,10 +1757,13 @@ static gboolean __alarm_handler_idle(gpointer user_data)
 {
        GPollFD *gpollfd = (GPollFD *) user_data;
        uint64_t exp;
 {
        GPollFD *gpollfd = (GPollFD *) user_data;
        uint64_t exp;
+       time_t current_time;
+
        if (gpollfd == NULL) {
                ALARM_MGR_EXCEPTION_PRINT("gpollfd is NULL");
                return false;
        }
        if (gpollfd == NULL) {
                ALARM_MGR_EXCEPTION_PRINT("gpollfd is NULL");
                return false;
        }
+
        if (read(gpollfd->fd, &exp, sizeof(uint64_t)) < 0) {
                ALARM_MGR_EXCEPTION_PRINT("Reading the fd is failed.");
                return false;
        if (read(gpollfd->fd, &exp, sizeof(uint64_t)) < 0) {
                ALARM_MGR_EXCEPTION_PRINT("Reading the fd is failed.");
                return false;
@@ -1328,6 +1784,15 @@ static gboolean __alarm_handler_idle(gpointer user_data)
 
        _alarm_schedule();
 
 
        _alarm_schedule();
 
+       // Previous alarm can be expired late as tolerance of RTC.
+       // In this case, Expire alarms forcibly if real duetime is same to current time.
+       time(&current_time);
+       if (alarm_context.c_due_time == current_time) {
+               ALARM_MGR_LOG_PRINT("Expire alarms forcibly when duetime is same to current time(%d).", current_time)
+               __alarm_expired();
+               _alarm_schedule();
+       }
+
        __rtc_set();
 
        ALARM_MGR_EXCEPTION_PRINT("Unlock the display from LCD OFF");
        __rtc_set();
 
        ALARM_MGR_EXCEPTION_PRINT("Unlock the display from LCD OFF");
@@ -1378,39 +1843,20 @@ static void __on_system_time_external_changed(keynode_t *node, void *data)
        ALARM_MGR_EXCEPTION_PRINT("diff_time is %f, New time is %s\n", diff_time, ctime(&cur_time));
 
        ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed externally\n");
        ALARM_MGR_EXCEPTION_PRINT("diff_time is %f, New time is %s\n", diff_time, ctime(&cur_time));
 
        ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed externally\n");
-       ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n",
-                           alarm_context.c_due_time);
+       ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d", alarm_context.c_due_time);
 
 
-       // set rtc time only because the linux time is set externally
-       _set_rtc_time(cur_time);
+       __set_time(cur_time);
 
        vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
 
        vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
+       bundle *b = NULL;
+       b = bundle_create();
+       bundle_add_str(b, EVT_KEY_TIME_CHANGED, EVT_VAL_TIME_CHANGED_TRUE);
+       eventsystem_send_system_event(SYS_EVENT_TIME_CHANGED, b);
+       bundle_free(b);
 
        __alarm_update_due_time_of_all_items_in_list(diff_time);
 
 
        __alarm_update_due_time_of_all_items_in_list(diff_time);
 
-       ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n",
-                           alarm_context.c_due_time);
-       _clear_scheduled_alarm_list();
-       _alarm_schedule();
-       __rtc_set();
-
-       return;
-}
-
-static void __on_time_zone_changed(keynode_t *node, void *data)
-{
-       double diff_time = 0;
-
-       _alarm_disable_timer(alarm_context);
-
-       tzset();
-
-       ALARM_MGR_LOG_PRINT("[alarm-server] time zone has been changed\n");
-       ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n", alarm_context.c_due_time);
-
-       __alarm_update_due_time_of_all_items_in_list(diff_time);
-
-       ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n", alarm_context.c_due_time);
+       ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d",  alarm_context.c_due_time);
        _clear_scheduled_alarm_list();
        _alarm_schedule();
        __rtc_set();
        _clear_scheduled_alarm_list();
        _alarm_schedule();
        __rtc_set();
@@ -1420,12 +1866,13 @@ static void __on_time_zone_changed(keynode_t *node, void *data)
 
 static int __on_app_uninstalled(int req_id, const char *pkg_type,
                                const char *pkgid, const char *key, const char *val,
 
 static int __on_app_uninstalled(int req_id, const char *pkg_type,
                                const char *pkgid, const char *key, const char *val,
-                               const void *pmsg, void *user_data)
+                               const void *pmsg, void *user_data, const char *sender_zone)
 {
        GSList* gs_iter = NULL;
        __alarm_info_t* entry = NULL;
        alarm_info_t* alarm_info = NULL;
        bool is_deleted = false;
 {
        GSList* gs_iter = NULL;
        __alarm_info_t* entry = NULL;
        alarm_info_t* alarm_info = NULL;
        bool is_deleted = false;
+       const char *zone = NULL;
 
        SECURE_LOGD("pkg_type(%s), pkgid(%s), key(%s), value(%s)", pkg_type, pkgid, key, val);
 
 
        SECURE_LOGD("pkg_type(%s), pkgid(%s), key(%s), value(%s)", pkg_type, pkgid, key, val);
 
@@ -1436,13 +1883,27 @@ static int __on_app_uninstalled(int req_id, const char *pkg_type,
                        bool is_found = false;
                        entry = gs_iter->data;
 
                        bool is_found = false;
                        entry = gs_iter->data;
 
-                       char* caller_pkgid = g_quark_to_string(entry->quark_caller_pkgid);
-                       char* callee_pkgid = g_quark_to_string(entry->quark_callee_pkgid);
+                       const char* caller_pkgid = g_quark_to_string(entry->quark_caller_pkgid);
+                       const char* callee_pkgid = g_quark_to_string(entry->quark_callee_pkgid);
+
+                       zone = g_quark_to_string(entry->zone);
+                       if (zone == NULL) {
+                               gs_iter = g_slist_next(gs_iter);
+                               continue;
+                       }
+
+                       if (sender_zone == NULL && strcmp(zone, "/") != 0) { //sender_zone is host, zone is not host
+                               gs_iter = g_slist_next(gs_iter);
+                               continue;
+                       } else if(sender_zone != NULL && strcmp(sender_zone, zone) != 0) {
+                               gs_iter = g_slist_next(gs_iter);
+                               continue;
+                       }
 
                        if ((caller_pkgid && strncmp(pkgid, caller_pkgid, strlen(pkgid)) == 0) ||
                                (callee_pkgid && strncmp(pkgid, callee_pkgid, strlen(pkgid)) == 0))
                        {
 
                        if ((caller_pkgid && strncmp(pkgid, caller_pkgid, strlen(pkgid)) == 0) ||
                                (callee_pkgid && strncmp(pkgid, callee_pkgid, strlen(pkgid)) == 0))
                        {
-                               if (_remove_from_scheduled_alarm_list(pkgid, entry->alarm_id))
+                               if (_remove_from_scheduled_alarm_list(entry->pid, entry->alarm_id, zone))
                                {
                                        is_deleted = true;
                                }
                                {
                                        is_deleted = true;
                                }
@@ -1450,7 +1911,7 @@ static int __on_app_uninstalled(int req_id, const char *pkg_type,
                                alarm_info = &entry->alarm_info;
                                if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
                                {
                                alarm_info = &entry->alarm_info;
                                if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
                                {
-                                       if(!_delete_alarms(entry->alarm_id))
+                                       if(!_delete_alarms(entry->alarm_id, zone))
                                        {
                                                SECURE_LOGE("_delete_alarms() is failed. pkgid[%s], alarm_id[%d]", pkgid, entry->alarm_id);
                                        }
                                        {
                                                SECURE_LOGE("_delete_alarms() is failed. pkgid[%s], alarm_id[%d]", pkgid, entry->alarm_id);
                                        }
@@ -1487,32 +1948,25 @@ int __check_privilege_by_cookie(char *e_cookie, const char *label, const char *a
        char buf[128] = {0,};
        FILE *fp = NULL;
        char title[128] = {0,};
        char buf[128] = {0,};
        FILE *fp = NULL;
        char title[128] = {0,};
-       int uid = -1;
+       uid_t uid = -1;
+
+       cookie = g_base64_decode(e_cookie, &size);
+       if (cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!");
+               return ERR_ALARM_SYSTEM_FAIL;
+       }
 
        if (check_root) {
 
        if (check_root) {
-               // Gets the userID from /proc/pid/status to check if the process is the root or not.
-               snprintf(buf, sizeof(buf), "/proc/%d/status", pid);
-               fp = fopen(buf, "r");
-               if(fp) {
-                       while (fgets(buf, sizeof(buf), fp) != NULL) {
-                               if(strncmp(buf, "Uid:", 4) == 0) {
-                                       sscanf(buf, "%s %d", title, &uid);
-                                       break;
-                               }
-                       }
-                       fclose(fp);
+               // Gets the userID from security api to check if the process is the root or not.
+               retval = security_server_get_uid_by_cookie((const char *)cookie, &uid);
+               if (retval != SECURITY_SERVER_API_SUCCESS) {
+                       ALARM_MGR_EXCEPTION_PRINT("Failed to security_server_get_uid_by_cookie[%d]", retval);
                }
 
                ALARM_MGR_LOG_PRINT("uid : %d", uid);
        }
 
                }
 
                ALARM_MGR_LOG_PRINT("uid : %d", uid);
        }
 
-       if (uid != 0) { // Checks the cookie only when the process is not the root
-               cookie = g_base64_decode(e_cookie, &size);
-               if (cookie == NULL) {
-                       ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!");
-                       return ERR_ALARM_SYSTEM_FAIL;
-               }
-
+       if (uid != 0 && uid != SYSTEM_UID) {    // Checks the cookie only when the process is not the root
                retval = security_server_check_privilege_by_cookie((const char *)cookie, label, access);
                g_free(cookie);
 
                retval = security_server_check_privilege_by_cookie((const char *)cookie, label, access);
                g_free(cookie);
 
@@ -1529,65 +1983,45 @@ int __check_privilege_by_cookie(char *e_cookie, const char *label, const char *a
        return ALARMMGR_RESULT_SUCCESS;
 }
 
        return ALARMMGR_RESULT_SUCCESS;
 }
 
-bool __get_caller_unique_name(int pid, char *unique_name)
+bool __get_caller_unique_name(int pid, char *unique_name, const char *zone)
 {
 {
-       char caller_appid[256] = {0,};
-
        if (unique_name == NULL)
        {
                ALARM_MGR_EXCEPTION_PRINT("unique_name should not be NULL.");
                return false;
        }
 
        if (unique_name == NULL)
        {
                ALARM_MGR_EXCEPTION_PRINT("unique_name should not be NULL.");
                return false;
        }
 
-       if (aul_app_get_appid_bypid(pid, caller_appid, sizeof(caller_appid)) == AUL_R_OK)
+       char *caller_appid = NULL;
+       if (__zone_get_appid_bypid(pid, zone, &caller_appid) == 0)
        {
                // When a caller is an application, the unique name is appID.
                strncpy(unique_name, caller_appid, strlen(caller_appid));
        {
                // When a caller is an application, the unique name is appID.
                strncpy(unique_name, caller_appid, strlen(caller_appid));
+               free(caller_appid);
        }
        else
        {
                // Otherwise, the unique name is /proc/pid/cmdline.
        }
        else
        {
                // Otherwise, the unique name is /proc/pid/cmdline.
-               char proc_file[512] = {0,};
-               char process_name[512] = {0,};
-               int fd = 0;
-               int i = 0;
-
-               snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
-
-               fd = open(proc_file, O_RDONLY);
-               if (fd < 0) {
-                       SECURE_LOGE("Caution!! pid(%d) seems to be killed, so we failed to get proc file(%s) and do not create alarm_info.", pid, proc_file);
+               char caller_cmdline[PATH_MAX];
+               int ret = 0;
+               ret = aul_app_get_cmdline_bypid(pid, caller_cmdline, PATH_MAX);
+               if (ret != 0) {
+                       ALARM_MGR_EXCEPTION_PRINT("get cmdline is failed");
                        return false;
                        return false;
-               }
-               else {
-                       if (read(fd, process_name, 512) <= 0)
-                       {
-                               ALARM_MGR_EXCEPTION_PRINT("Unable to get the process name.");
-                               close(fd);
-                               return false;
-                       }
-                       close(fd);
 
 
-                       while (process_name[i] != '\0') {
-                               if (process_name[i] == ' ') {
-                                       process_name[i] = '\0';
-                                       break;
-                               }
-                               ++i;
-                       }
-                       strncpy(unique_name, process_name, strlen(process_name));
                }
                }
+               strncpy(unique_name, caller_cmdline, strlen(caller_cmdline));
        }
 
        SECURE_LOGD("unique_name= %s", unique_name);
        return true;
 }
 
        }
 
        SECURE_LOGD("unique_name= %s", unique_name);
        return true;
 }
 
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
 static void __initialize_module_log(void)
 {
 static void __initialize_module_log(void)
 {
-       log_fd = open(ALARMMGR_LOG_FILE_PATH, O_CREAT | O_WRONLY, 0644);
+       log_fd = open(ALARMMGR_LOG_FILE_PATH, O_WRONLY);
        if (log_fd == -1) {
        if (log_fd == -1) {
-               ALARM_MGR_EXCEPTION_PRINT("Opening the file for alarmmgr log is failed.");
+               ALARM_MGR_EXCEPTION_PRINT("Opening the file for alarmmgr log is failed. err: %s", strerror(errno));
                return;
        }
 
                return;
        }
 
@@ -1624,7 +2058,7 @@ static bool __save_module_log(const char *tag, const char *message)
 
        int ret = write(log_fd, buffer, strlen(buffer));
        if (ret < 0) {
 
        int ret = write(log_fd, buffer, strlen(buffer));
        if (ret < 0) {
-               ALARM_MGR_EXCEPTION_PRINT("Writing the alarmmgr log is failed.");
+               ALARM_MGR_EXCEPTION_PRINT("Writing the alarmmgr log is failed. err: %s", strerror(errno));
                return false;
        }
 
                return false;
        }
 
@@ -1633,13 +2067,13 @@ static bool __save_module_log(const char *tag, const char *message)
        }
        return true;
 }
        }
        return true;
 }
+#endif // _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
 
 int __display_lock_state(char *state, char *flag, unsigned int timeout)
 {
        GDBusMessage *msg = NULL;
        GDBusMessage *reply = NULL;
        GVariant *body = NULL;
 
 int __display_lock_state(char *state, char *flag, unsigned int timeout)
 {
        GDBusMessage *msg = NULL;
        GDBusMessage *reply = NULL;
        GVariant *body = NULL;
-       GError *error = NULL;
        int ret = ALARMMGR_RESULT_SUCCESS;
        int val = -1;
 
        int ret = ALARMMGR_RESULT_SUCCESS;
        int val = -1;
 
@@ -1651,10 +2085,9 @@ int __display_lock_state(char *state, char *flag, unsigned int timeout)
 
        g_dbus_message_set_body(msg, g_variant_new("(sssi)", state, flag, "NULL", timeout));
 
 
        g_dbus_message_set_body(msg, g_variant_new("(sssi)", state, flag, "NULL", timeout));
 
-       reply =  g_dbus_connection_send_message_with_reply_sync(alarm_context.connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, DEVICED_DBUS_REPLY_TIMEOUT, NULL, NULL, &error);
+       reply =  g_dbus_connection_send_message_with_reply_sync(alarm_context.connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, DEVICED_DBUS_REPLY_TIMEOUT, NULL, NULL, NULL);
        if (!reply) {
        if (!reply) {
-               ALARM_MGR_EXCEPTION_PRINT("No reply. error = %s", error->message);
-               g_error_free(error);
+               ALARM_MGR_EXCEPTION_PRINT("No reply. g_dbus_connection_send_message_with_reply_sync() is failed.");
                ret = ERR_ALARM_SYSTEM_FAIL;
        } else {
                body = g_dbus_message_get_body(reply);
                ret = ERR_ALARM_SYSTEM_FAIL;
        } else {
                body = g_dbus_message_get_body(reply);
@@ -1674,7 +2107,8 @@ int __display_lock_state(char *state, char *flag, unsigned int timeout)
 
        g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL);
        g_object_unref(msg);
 
        g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL);
        g_object_unref(msg);
-       g_object_unref(reply);
+       if (reply)
+               g_object_unref(reply);
 
        return ret;
 }
 
        return ret;
 }
@@ -1684,7 +2118,6 @@ int __display_unlock_state(char *state, char *flag)
        GDBusMessage *msg = NULL;
        GDBusMessage *reply = NULL;
        GVariant *body = NULL;
        GDBusMessage *msg = NULL;
        GDBusMessage *reply = NULL;
        GVariant *body = NULL;
-       GError *error = NULL;
        int ret = ALARMMGR_RESULT_SUCCESS;
        int val = -1;
 
        int ret = ALARMMGR_RESULT_SUCCESS;
        int val = -1;
 
@@ -1696,10 +2129,9 @@ int __display_unlock_state(char *state, char *flag)
 
        g_dbus_message_set_body(msg, g_variant_new("(ss)", state, flag ));
 
 
        g_dbus_message_set_body(msg, g_variant_new("(ss)", state, flag ));
 
-       reply =  g_dbus_connection_send_message_with_reply_sync(alarm_context.connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, DEVICED_DBUS_REPLY_TIMEOUT, NULL, NULL, &error);
+       reply =  g_dbus_connection_send_message_with_reply_sync(alarm_context.connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, DEVICED_DBUS_REPLY_TIMEOUT, NULL, NULL, NULL);
        if (!reply) {
        if (!reply) {
-               ALARM_MGR_EXCEPTION_PRINT("No reply. error = %s", error->message);
-               g_error_free(error);
+               ALARM_MGR_EXCEPTION_PRINT("No reply. g_dbus_connection_send_message_with_reply_sync() is failed.");
                ret = ERR_ALARM_SYSTEM_FAIL;
        } else {
                body = g_dbus_message_get_body(reply);
                ret = ERR_ALARM_SYSTEM_FAIL;
        } else {
                body = g_dbus_message_get_body(reply);
@@ -1719,12 +2151,13 @@ int __display_unlock_state(char *state, char *flag)
 
        g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL);
        g_object_unref(msg);
 
        g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL);
        g_object_unref(msg);
-       g_object_unref(reply);
+       if (reply)
+               g_object_unref(reply);
 
        return ret;
 }
 
 
        return ret;
 }
 
-static long __get_proper_interval(long interval)
+static long __get_proper_interval(long interval, int alarm_type)
 {
        GSList *gs_iter = NULL;
        __alarm_info_t *entry = NULL;
 {
        GSList *gs_iter = NULL;
        __alarm_info_t *entry = NULL;
@@ -1740,13 +2173,82 @@ static long __get_proper_interval(long interval)
                }
        }
 
                }
        }
 
-       while (maxInterval * 2 <= interval) {
+       while (maxInterval * 2 <= interval ||
+                       (alarm_type & ALARM_TYPE_INEXACT && maxInterval < MIN_INEXACT_INTERVAL) ) {
                maxInterval *= 2;
        }
 
        return maxInterval;
 }
 
                maxInterval *= 2;
        }
 
        return maxInterval;
 }
 
+gboolean __alarm_expired_directly(gpointer user_data)
+{
+       if (g_scheduled_alarm_list == NULL || g_scheduled_alarm_list->data == NULL) {
+               return false;
+       }
+
+       int time_sec = (int)user_data;
+       __scheduled_alarm_t *alarm = g_scheduled_alarm_list->data;
+       __alarm_info_t *alarm_info = alarm->__alarm_info;
+
+       // Expire alarms with duetime equal to newtime by force
+       if (alarm_info->due_time == time_sec) {
+               if (__display_lock_state(DEVICED_LCD_OFF, DEVICED_STAY_CUR_STATE, 0) != ALARMMGR_RESULT_SUCCESS) {
+                       ALARM_MGR_EXCEPTION_PRINT("__display_lock_state() is failed");
+               }
+
+               if (g_dummy_timer_is_set == true) {
+                       ALARM_MGR_LOG_PRINT("dummy alarm timer has expired.");
+               }
+               else {
+                       ALARM_MGR_LOG_PRINT("due_time=%d is expired.", alarm_info->due_time);
+                       __alarm_expired();
+               }
+
+               _alarm_schedule();
+               __rtc_set();
+
+               if (__display_unlock_state(DEVICED_LCD_OFF, DEVICED_SLEEP_MARGIN) != ALARMMGR_RESULT_SUCCESS) {
+                       ALARM_MGR_EXCEPTION_PRINT("__display_unlock_state() is failed");
+               }
+       }
+
+       return false;
+}
+
+void __reschedule_alarms_with_newtime(int cur_time, int new_time, double diff_time)
+{
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
+
+       vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
+       bundle *b = NULL;
+       b = bundle_create();
+       bundle_add_str(b, EVT_KEY_TIME_CHANGED, EVT_VAL_TIME_CHANGED_TRUE);
+       eventsystem_send_system_event(SYS_EVENT_TIME_CHANGED, b);
+       bundle_free(b);
+
+       __alarm_update_due_time_of_all_items_in_list(diff_time);        // Rescheduling alarms with ALARM_TYPE_RELATIVE
+       ALARM_MGR_LOG_PRINT("Next duetime is %d", alarm_context.c_due_time);
+
+       _clear_scheduled_alarm_list();
+       _alarm_schedule();
+       __rtc_set();
+
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       char *timebuf = ctime(&new_time);
+       if (timebuf) {
+               timebuf[strlen(timebuf) - 1] = '\0';    // to avoid newline
+               snprintf(log_message, sizeof(log_message), "Current: %d, New: %d, %s, diff: %f", cur_time, new_time, timebuf, diff_time);
+       }
+       __save_module_log("CHANGE TIME", log_message);
+#endif
+
+       g_idle_add(__alarm_expired_directly, (gpointer)new_time);       // Expire alarms with duetime equal to newtime directly
+       return;
+}
+
 gboolean alarm_manager_alarm_set_rtc_time(AlarmManager *pObj, GDBusMethodInvocation *invoc, int pid,
                                int year, int mon, int day,
                                int hour, int min, int sec, char *e_cookie,
 gboolean alarm_manager_alarm_set_rtc_time(AlarmManager *pObj, GDBusMethodInvocation *invoc, int pid,
                                int year, int mon, int day,
                                int hour, int min, int sec, char *e_cookie,
@@ -1755,13 +2257,12 @@ gboolean alarm_manager_alarm_set_rtc_time(AlarmManager *pObj, GDBusMethodInvocat
        struct timespec alarm_time;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        struct timespec alarm_time;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
-
-       struct rtc_time rtc_tm = {0,};
-       struct rtc_wkalrm rtc_wk;
        struct tm *alarm_tm = NULL;
 
        struct tm *alarm_tm = NULL;
 
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", false, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", false, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
@@ -1809,68 +2310,106 @@ gboolean alarm_manager_alarm_set_rtc_time(AlarmManager *pObj, GDBusMethodInvocat
                }
                ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror(errno));
                return_code = ERR_ALARM_SYSTEM_FAIL;
                }
                ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror(errno));
                return_code = ERR_ALARM_SYSTEM_FAIL;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "FAIL: SET RTC", strlen("FAIL: SET RTC"));
                strncpy(log_tag, "FAIL: SET RTC", strlen("FAIL: SET RTC"));
+#endif
        }
        else{
                ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
        }
        else{
                ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "SET RTC", strlen("SET RTC"));
                strncpy(log_tag, "SET RTC", strlen("SET RTC"));
+#endif
        }
 
        }
 
-       sprintf(log_message, "wakeup rtc time: %d, %s", rtc_time, ctime(&rtc_time));
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       snprintf(log_message, sizeof(log_message), "wakeup rtc time: %d, %s", (int)rtc_time, ctime(&rtc_time));
        __save_module_log(log_tag, log_message);
        __save_module_log(log_tag, log_message);
+#endif
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
        return true;
 }
 
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
        return true;
 }
 
-gboolean alarm_manager_alarm_set_time(AlarmManager *pObj, GDBusMethodInvocation *invoc, int _time, gpointer user_data)
+static int accrue_msec = 0;    // To check a millisecond part of current time at changing the system time(sec)
+
+gboolean alarm_manager_alarm_set_time(AlarmManager *pObj, GDBusMethodInvocation *invoc, int time_sec, gpointer user_data)
 {
 {
-       static int diff_msec = 0;       // To check a millisecond part of current time at changing the system time
        double diff_time = 0.0;
        double diff_time = 0.0;
-       struct timeval before;
+       struct timeval cur_time = {0,};
        int return_code = ALARMMGR_RESULT_SUCCESS;
        int return_code = ALARMMGR_RESULT_SUCCESS;
-       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
 
 
-       _alarm_disable_timer(alarm_context);
+       _alarm_disable_timer(alarm_context);    // Disable the timer to reschedule the alarm before the time is changed.
 
 
-       gettimeofday(&before, NULL);
-       diff_msec += (before.tv_usec / 1000);   // Accrue the millisecond to compensate the time
-       ALARM_MGR_LOG_PRINT("Current time = %s. usec = %ld. diff_msec = %d.\n", ctime(&before.tv_sec), before.tv_usec, diff_msec);
+       tzset();
+       gettimeofday(&cur_time, NULL);
 
 
-       if (diff_msec > 500) {
-               diff_time = difftime(_time, before.tv_sec) - 1;
-               diff_msec -= 1000;
-       }
-       else {
-               diff_time = difftime(_time, before.tv_sec);
+       accrue_msec += (cur_time.tv_usec / 1000);       // Accrue the millisecond to compensate the time
+       if (accrue_msec > 500) {
+               diff_time = difftime(time_sec, cur_time.tv_sec) - 1;
+               accrue_msec -= 1000;
+       else {
+               diff_time = difftime(time_sec, cur_time.tv_sec);
        }
 
        }
 
+       __set_time(time_sec);   // Change both OS time and RTC
+       ALARM_MGR_EXCEPTION_PRINT("[TIMESTAMP]Current time(%d), New time(%d)(%s), diff_time(%f)",
+                                                                       cur_time.tv_sec, time_sec, ctime(&time_sec), diff_time);
+
+       __reschedule_alarms_with_newtime(cur_time.tv_sec, time_sec, diff_time);
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+       return true;
+}
+
+gboolean alarm_manager_alarm_set_time_with_propagation_delay(AlarmManager *pObj, GDBusMethodInvocation *invoc,
+       guint new_sec, guint new_nsec, guint req_sec, guint req_nsec, gpointer user_data)
+{
+       double diff_time = 0.0;
+       struct timespec cur_time = {0,};
+       struct timespec delay = {0,};
+       struct timespec sleep_time = {0,};
+       guint real_newtime = 0;
+       accrue_msec = 0;                // reset accrued msec
+
+       _alarm_disable_timer(alarm_context);    // Disable the timer to reschedule the alarm before the time is changed.
+
        tzset();
        tzset();
+       clock_gettime(CLOCK_REALTIME, &cur_time);
 
 
-       char *timebuf = ctime(&_time);
-       if (timebuf) {
-               timebuf[strlen(timebuf) - 1] = '\0';    // to avoid newline
-               sprintf(log_message, "Current: %d, New: %d, %s, diff: %f", before.tv_sec, _time, timebuf, diff_time);
-               __save_module_log("CHANGE TIME", log_message);
+       // Check validation of requested time
+       if (req_sec > cur_time.tv_sec || (req_sec == cur_time.tv_sec && req_nsec > cur_time.tv_nsec)) {
+               ALARM_MGR_EXCEPTION_PRINT("The requeted time(%d.%09d) must be equal to or less than current time(%d.%09d).",
+                       req_sec, req_nsec, cur_time.tv_sec, cur_time.tv_nsec);
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ERR_ALARM_INVALID_PARAM));
+               return true;
        }
 
        }
 
-       ALARM_MGR_EXCEPTION_PRINT("[TIMESTAMP]Current time(%d), New time(%d)(%s), diff_time(%f)", before.tv_sec, _time, ctime(&_time), diff_time);
-
-       ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed\n");
-       ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n", alarm_context.c_due_time);
+       // Compensate propagation delay
+       if (req_nsec > cur_time.tv_nsec) {
+               delay.tv_sec = cur_time.tv_sec - 1 - req_sec;
+               delay.tv_nsec = cur_time.tv_nsec + BILLION - req_nsec;
+       } else {
+               delay.tv_sec = cur_time.tv_sec - req_sec;
+               delay.tv_nsec = cur_time.tv_nsec - req_nsec;
+       }
 
 
-       _set_time(_time - 1);
-       __alarm_update_due_time_of_all_items_in_list(diff_time);
+       if (new_nsec + delay.tv_nsec >= BILLION) {
+               real_newtime = new_sec + delay.tv_sec + 2;
+               sleep_time.tv_nsec = BILLION - ((delay.tv_nsec + new_nsec) - BILLION);
+       } else {
+               real_newtime = new_sec + delay.tv_sec + 1;
+               sleep_time.tv_nsec = BILLION - (delay.tv_nsec + new_nsec);
+       }
 
 
-       ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d", alarm_context.c_due_time);
-       _clear_scheduled_alarm_list();
-       _alarm_schedule();
-       __rtc_set();
-       _set_time(_time);
+       nanosleep(&sleep_time, NULL);   // Wait until 0 nsec to match both OS time and RTC(sec)
 
 
-       vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
+       __set_time(real_newtime);       // Change both OS time and RTC
 
 
-       g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+       diff_time = difftime(real_newtime, cur_time.tv_sec);
+       ALARM_MGR_EXCEPTION_PRINT("[TIMESTAMP]Current time(%d.%09d), New time(%d.%09d), Real Newtime(%d), diff_time(%f)",
+               cur_time.tv_sec, cur_time.tv_nsec, new_sec, new_nsec, real_newtime, diff_time);
+       ALARM_MGR_LOG_PRINT("Requested(%d.%09d) Delay(%d.%09d) Sleep(%09d)", req_sec, req_nsec, delay.tv_sec, delay.tv_nsec, sleep_time.tv_nsec);
+       __reschedule_alarms_with_newtime(cur_time.tv_sec, real_newtime, diff_time);
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ALARMMGR_RESULT_SUCCESS));
        return true;
 }
 
        return true;
 }
 
@@ -1878,9 +2417,11 @@ gboolean alarm_manager_alarm_set_timezone(AlarmManager *pObject, GDBusMethodInvo
 {
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
 {
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
+       struct stat statbuf;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
-       struct stat statbuf;
+#endif
 
        ALARM_MGR_EXCEPTION_PRINT("[TIMESTAMP]Set the timezone to %s.", tzpath_str);
 
 
        ALARM_MGR_EXCEPTION_PRINT("[TIMESTAMP]Set the timezone to %s.", tzpath_str);
 
@@ -1919,16 +2460,29 @@ gboolean alarm_manager_alarm_set_timezone(AlarmManager *pObject, GDBusMethodInvo
        __rtc_set();
 
        vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED, 0);
        __rtc_set();
 
        vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED, 0);
+       bundle *b = NULL;
+       b = bundle_create();
+       bundle_add_str(b, EVT_KEY_TIME_CHANGED, EVT_VAL_TIME_CHANGED_TRUE);
+       eventsystem_send_system_event(SYS_EVENT_TIME_CHANGED, b);
+       bundle_free(b);
+
+       b = NULL;
+       b = bundle_create();
+       bundle_add_str(b, EVT_KEY_TIME_ZONE, tzpath_str);
+       eventsystem_send_system_event(SYS_EVENT_TIME_ZONE, b);
+       bundle_free(b);
 
 done:
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
 
 done:
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        if (return_code == ALARMMGR_RESULT_SUCCESS) {
                strncpy(log_tag, "SET TIMEZONE", strlen("SET TIMEZONE"));
        } else {
                strncpy(log_tag, "FAIL: SET TIMEZONE", strlen("FAIL: SET TIMEZONE"));
        }
        if (return_code == ALARMMGR_RESULT_SUCCESS) {
                strncpy(log_tag, "SET TIMEZONE", strlen("SET TIMEZONE"));
        } else {
                strncpy(log_tag, "FAIL: SET TIMEZONE", strlen("FAIL: SET TIMEZONE"));
        }
-       sprintf(log_message, "Set the timezone to %s.", tzpath_str);
+       snprintf(log_message, sizeof(log_message), "Set the timezone to %s.", tzpath_str);
        __save_module_log(log_tag, log_message);
        __save_module_log(log_tag, log_message);
+#endif
 
        return true;
 }
 
        return true;
 }
@@ -1940,25 +2494,42 @@ gboolean alarm_manager_alarm_create_appsvc(AlarmManager *pObject, GDBusMethodInv
                                    int start_hour, int start_min,
                                    int start_sec, int end_year, int end_month,
                                    int end_day, int mode_day_of_week,
                                    int start_hour, int start_min,
                                    int start_sec, int end_year, int end_month,
                                    int end_day, int mode_day_of_week,
-                                   int mode_repeat, int alarm_type,
-                                   int reserved_info,
-                                   char *bundle_data, char *e_cookie,
+                                   unsigned int mode_interval, int mode_repeat,
+                                       int alarm_type, int reserved_info,
+                                       char *bundle_data, char *e_cookie,
                                    gpointer user_data)
 {
        alarm_info_t alarm_info;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        int alarm_id = 0;
                                    gpointer user_data)
 {
        alarm_info_t alarm_info;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        int alarm_id = 0;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
        bool ret = true;
        bool ret = true;
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", false, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", false, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
-               sprintf(log_message, "pid: %d, Smack denied (alarm-server::alarm, w)", pid);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+               snprintf(log_message, sizeof(log_message), "pid: %d, Smack denied (alarm-server::alarm, w)", pid);
                __save_module_log("FAIL: CREATE", log_message);
                __save_module_log("FAIL: CREATE", log_message);
+#endif
                return true;
        }
 
                return true;
        }
 
@@ -1979,20 +2550,36 @@ gboolean alarm_manager_alarm_create_appsvc(AlarmManager *pObject, GDBusMethodInv
        alarm_info.alarm_type = alarm_type;
        alarm_info.reserved_info = reserved_info;
 
        alarm_info.alarm_type = alarm_type;
        alarm_info.reserved_info = reserved_info;
 
-       if (!__alarm_create_appsvc(&alarm_info, &alarm_id, pid, bundle_data, &return_code)) {
+       if ((alarm_info.alarm_type & ALARM_TYPE_INEXACT)) {
+               alarm_info.alarm_type |= ALARM_TYPE_PERIOD;
+               alarm_info.mode.u_interval.interval =
+                       __get_proper_interval(mode_interval, alarm_info.alarm_type);
+       } else if (mode_interval <= 0){
+               alarm_info.mode.u_interval.interval = 0;
+       }
+
+       ALARM_MGR_LOG_PRINT("u_interval.interval[%d]", alarm_info.mode.u_interval.interval);
+
+       if (!__alarm_create_appsvc(&alarm_info, &alarm_id, mode_interval, pid, bundle_data, &return_code, zone)) {
                ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
                ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
                strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
+#endif
                ret = false;
                ret = false;
-       } else {
+       }
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       else {
                strncpy(log_tag, "CREATE", strlen("CREATE"));
                strncpy(log_tag, "CREATE", strlen("CREATE"));
-               ret = true;
        }
        }
+#endif
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
 
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
 
-       sprintf(log_message, "alarmID: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       snprintf(log_message, sizeof(log_message), "alarmID: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
                alarm_id, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
        __save_module_log(log_tag, log_message);
                alarm_id, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
        __save_module_log(log_tag, log_message);
+#endif
 
        return ret;
 }
 
        return ret;
 }
@@ -2012,16 +2599,33 @@ gboolean alarm_manager_alarm_create(AlarmManager *obj, GDBusMethodInvocation *in
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        int alarm_id = 0;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        int alarm_id = 0;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
        bool ret = true;
        bool ret = true;
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
-               sprintf(log_message, "pid: %d, Smack denied (alarm-server::alarm, w)", pid);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+               snprintf(log_message, sizeof(log_message), "pid: %d, Smack denied (alarm-server::alarm, w)", pid);
                __save_module_log("FAIL: CREATE", log_message);
                __save_module_log("FAIL: CREATE", log_message);
+#endif
                return true;
        }
 
                return true;
        }
 
@@ -2043,24 +2647,42 @@ gboolean alarm_manager_alarm_create(AlarmManager *obj, GDBusMethodInvocation *in
        alarm_info.reserved_info = reserved_info;
 
        if (!__alarm_create(&alarm_info, &alarm_id, pid, 0, 0, 0, app_service_name,app_service_name_mod,
        alarm_info.reserved_info = reserved_info;
 
        if (!__alarm_create(&alarm_info, &alarm_id, pid, 0, 0, 0, app_service_name,app_service_name_mod,
-                      reserved_service_name, reserved_service_name_mod, &return_code)) {
+                      reserved_service_name, reserved_service_name_mod, &return_code, zone)) {
                ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
                ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
                strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
+#endif
                ret = false;
                ret = false;
-       } else {
+       }
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       else {
                strncpy(log_tag, "CREATE", strlen("CREATE"));
                strncpy(log_tag, "CREATE", strlen("CREATE"));
-               ret = true;
        }
        }
+#endif
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
 
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
 
-       sprintf(log_message, "alarmID: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       snprintf(log_message, sizeof(log_message), "alarmID: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
                alarm_id, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
        __save_module_log(log_tag, log_message);
                alarm_id, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
        __save_module_log(log_tag, log_message);
+#endif
 
        return ret;
 }
 
 
        return ret;
 }
 
+time_t _get_periodic_alarm_standard_time(void)
+{
+       /* To avoid start time of all devices are same. */
+       if (periodic_alarm_standard_time == 0) {
+               srand((unsigned int)time(NULL));
+               periodic_alarm_standard_time = rand() % BILLION + 1; /* 1 ~ 1000000000 */
+       }
+
+       ALARM_MGR_LOG_PRINT("periodic_standard_time : [%d]", periodic_alarm_standard_time);
+       return periodic_alarm_standard_time;
+}
+
 gboolean alarm_manager_alarm_create_periodic(AlarmManager *obj, GDBusMethodInvocation *invoc,
                char *app_service_name, char *app_service_name_mod, int interval,
                int is_ref, int method, char *e_cookie, gpointer user_data)
 gboolean alarm_manager_alarm_create_periodic(AlarmManager *obj, GDBusMethodInvocation *invoc,
                char *app_service_name, char *app_service_name_mod, int interval,
                int is_ref, int method, char *e_cookie, gpointer user_data)
@@ -2069,42 +2691,53 @@ gboolean alarm_manager_alarm_create_periodic(AlarmManager *obj, GDBusMethodInvoc
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        int alarm_id = 0;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        int alarm_id = 0;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
        bool ret = true;
        bool ret = true;
-       int pid;
+       int pid = -1;
        const char *name = g_dbus_method_invocation_get_sender(invoc);
        const char *name = g_dbus_method_invocation_get_sender(invoc);
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
 
 
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
        pid = __get_caller_pid(name);
        pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        if (is_ref)
 
        if (is_ref)
-               retval = __check_privilege_by_cookie(e_cookie,
-                       "alarm-server::alarm-ref-periodic", "w", true, pid);
+               retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm-ref-periodic", "w", true, pid);
        else
        else
-               retval = __check_privilege_by_cookie(e_cookie,
-                       "alarm-server::alarm-periodic", "w", true, pid);
+               retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm-periodic", "w", true, pid);
 
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
 
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
-               g_dbus_method_invocation_return_value(invoc,
-                       g_variant_new("(ii)", alarm_id, return_code));
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                if (is_ref)
                if (is_ref)
-                       sprintf(log_message,
-                               "pid: %d, Smack denied (alarm-server::alarm-ref-periodic, w)", pid);
+                       snprintf(log_message, sizeof(log_message), "pid: %d, Smack denied (alarm-server::alarm-ref-periodic, w)", pid);
                else
                else
-                       sprintf(log_message,
-                               "pid: %d, Smack denied (alarm-server::alarm-periodic, w)", pid);
-
+                       snprintf(log_message, sizeof(log_message), "pid: %d, Smack denied (alarm-server::alarm-periodic, w)", pid);
                __save_module_log("FAIL: CREATE", log_message);
                __save_module_log("FAIL: CREATE", log_message);
+#endif
                return true;
        }
 
                return true;
        }
 
-       alarm_info.start.year = 1900;
-       alarm_info.start.month = 1;
-       alarm_info.start.day = 0;
-       alarm_info.start.hour = 0;
-       alarm_info.start.min = 0;
-       alarm_info.start.sec = 0;
+       struct tm standard_tm;
+       time_t standard_time = _get_periodic_alarm_standard_time();
+       localtime_r(&standard_time, &standard_tm);
+
+       alarm_info.start.year = standard_tm.tm_year + 1900;
+       alarm_info.start.month = standard_tm.tm_mon + 1;
+       alarm_info.start.day = standard_tm.tm_mday;
+       alarm_info.start.hour = standard_tm.tm_hour;
+       alarm_info.start.min = standard_tm.tm_min;
+       alarm_info.start.sec = standard_tm.tm_sec;
 
        alarm_info.end.year = 0;
        alarm_info.end.month = 0;
 
        alarm_info.end.year = 0;
        alarm_info.end.month = 0;
@@ -2124,29 +2757,33 @@ gboolean alarm_manager_alarm_create_periodic(AlarmManager *obj, GDBusMethodInvoc
                if (is_ref)
                        alarm_info.mode.u_interval.interval = interval * 60;
                else
                if (is_ref)
                        alarm_info.mode.u_interval.interval = interval * 60;
                else
-                       alarm_info.mode.u_interval.interval = __get_proper_interval(interval * 60);
+                       alarm_info.mode.u_interval.interval = __get_proper_interval(interval * 60, alarm_info.alarm_type);
        }
 
        if (!__alarm_create(&alarm_info, &alarm_id, pid, method, interval * 60, is_ref,
                            app_service_name, app_service_name_mod,
        }
 
        if (!__alarm_create(&alarm_info, &alarm_id, pid, method, interval * 60, is_ref,
                            app_service_name, app_service_name_mod,
-                           "null", "null", &return_code)) {
+                           "null", "null", &return_code, zone)) {
                ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
                ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
                strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
+#endif
                ret = false;
        } else {
                ret = false;
        } else {
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "CREATE", strlen("CREATE"));
                strncpy(log_tag, "CREATE", strlen("CREATE"));
+#endif
                ret = true;
        }
 
        g_dbus_method_invocation_return_value(invoc,
                        g_variant_new("(ii)", alarm_id, return_code));
                ret = true;
        }
 
        g_dbus_method_invocation_return_value(invoc,
                        g_variant_new("(ii)", alarm_id, return_code));
-
-       sprintf(log_message, "alarmID: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       snprintf(log_message, sizeof(log_message), "alarmID: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
                        alarm_id, pid, alarm_info.start.year, alarm_info.start.month,
                        alarm_info.start.day, alarm_info.start.hour,
                        alarm_info.start.min, alarm_info.start.sec);
        __save_module_log(log_tag, log_message);
                        alarm_id, pid, alarm_info.start.year, alarm_info.start.month,
                        alarm_info.start.day, alarm_info.start.hour,
                        alarm_info.start.min, alarm_info.start.sec);
        __save_module_log(log_tag, log_message);
-
+#endif
        return ret;
 }
 
        return ret;
 }
 
@@ -2156,33 +2793,55 @@ gboolean alarm_manager_alarm_delete(AlarmManager *obj, GDBusMethodInvocation *in
 {
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
 {
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
        bool ret = true;
        bool ret = true;
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
-               sprintf(log_message, "alarmID: %d, pid: %d, Smack denied (alarm-server::alarm, w)", alarm_id, pid);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+               snprintf(log_message, sizeof(log_message), "alarmID: %d, pid: %d, Smack denied (alarm-server::alarm, w)", alarm_id, pid);
                __save_module_log("FAIL: DELETE", log_message);
                __save_module_log("FAIL: DELETE", log_message);
+#endif
                return true;
                return true;
+
        }
 
        }
 
-       if (!__alarm_delete(pid, alarm_id, &return_code)) {
+       if (!__alarm_delete(pid, alarm_id, &return_code, zone)) {
                ALARM_MGR_EXCEPTION_PRINT("Unable to delete the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code);
                ALARM_MGR_EXCEPTION_PRINT("Unable to delete the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "FAIL: DELETE", strlen("FAIL: DELETE"));
                strncpy(log_tag, "FAIL: DELETE", strlen("FAIL: DELETE"));
+#endif
                ret = false;
        } else {
                ALARM_MGR_EXCEPTION_PRINT("alarm_id[%d] is removed.", alarm_id);
                ret = false;
        } else {
                ALARM_MGR_EXCEPTION_PRINT("alarm_id[%d] is removed.", alarm_id);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "DELETE", strlen("DELETE"));
                strncpy(log_tag, "DELETE", strlen("DELETE"));
-               ret = true;
+#endif
        }
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
 
        }
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
 
-       sprintf(log_message, "alarmID: %d, pid: %d", alarm_id, pid);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       snprintf(log_message, sizeof(log_message), "alarmID: %d, pid: %d", alarm_id, pid);
        __save_module_log(log_tag, log_message);
        __save_module_log(log_tag, log_message);
+#endif
 
        return ret;
 }
 
        return ret;
 }
@@ -2197,22 +2856,41 @@ gboolean alarm_manager_alarm_delete_all(AlarmManager *obj, GDBusMethodInvocation
        bool is_deleted = false;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        bool is_deleted = false;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       bool ret = true;
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
-               sprintf(log_message, "pid: %d, Smack denied (alarm-server::alarm, w)", pid);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+               snprintf(log_message, sizeof(log_message), "pid: %d, Smack denied (alarm-server::alarm, w)", pid);
                __save_module_log("FAIL: DELETE ALL", log_message);
                __save_module_log("FAIL: DELETE ALL", log_message);
+#endif
                return true;
        }
 
                return true;
        }
 
-       if (!__get_caller_unique_name(pid, app_name)) {
+       if (!__get_caller_unique_name(pid, app_name, zone)) {
                return_code = ERR_ALARM_SYSTEM_FAIL;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
                return_code = ERR_ALARM_SYSTEM_FAIL;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
-               sprintf(log_message, "pid: %d. Can not get the unique_name.", pid);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+               snprintf(log_message, sizeof(log_message), "pid: %d. Can not get the unique_name.", pid);
                __save_module_log("FAIL: DELETE ALL", log_message);
                __save_module_log("FAIL: DELETE ALL", log_message);
+#endif
                return true;
        }
 
                return true;
        }
 
@@ -2222,11 +2900,17 @@ gboolean alarm_manager_alarm_delete_all(AlarmManager *obj, GDBusMethodInvocation
        {
                bool is_found = false;
                entry = gs_iter->data;
        {
                bool is_found = false;
                entry = gs_iter->data;
-               char* tmp_appname = g_quark_to_string(entry->quark_app_unique_name);
+
+               if (zone[0] != '\0' && strcmp(zone, g_quark_to_string(entry->zone)) != 0) {
+                       gs_iter = g_slist_next(gs_iter);
+                       continue;
+               }
+
+               const char* tmp_appname = g_quark_to_string(entry->quark_app_unique_name);
                SECURE_LOGD("Try to remove app_name[%s], alarm_id[%d]\n", tmp_appname, entry->alarm_id);
                if (tmp_appname && strncmp(app_name, tmp_appname, strlen(tmp_appname)) == 0)
                {
                SECURE_LOGD("Try to remove app_name[%s], alarm_id[%d]\n", tmp_appname, entry->alarm_id);
                if (tmp_appname && strncmp(app_name, tmp_appname, strlen(tmp_appname)) == 0)
                {
-                       if (_remove_from_scheduled_alarm_list(pid, entry->alarm_id))
+                       if (_remove_from_scheduled_alarm_list(pid, entry->alarm_id, zone))
                        {
                                is_deleted = true;
                        }
                        {
                                is_deleted = true;
                        }
@@ -2234,7 +2918,7 @@ gboolean alarm_manager_alarm_delete_all(AlarmManager *obj, GDBusMethodInvocation
                        alarm_info = &entry->alarm_info;
                        if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
                        {
                        alarm_info = &entry->alarm_info;
                        if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
                        {
-                               if(!_delete_alarms(entry->alarm_id))
+                               if(!_delete_alarms(entry->alarm_id, zone))
                                {
                                        SECURE_LOGE("_delete_alarms() is failed. pid[%d], alarm_id[%d]", pid, entry->alarm_id);
                                }
                                {
                                        SECURE_LOGE("_delete_alarms() is failed. pid[%d], alarm_id[%d]", pid, entry->alarm_id);
                                }
@@ -2259,8 +2943,14 @@ gboolean alarm_manager_alarm_delete_all(AlarmManager *obj, GDBusMethodInvocation
                _alarm_schedule();
        }
 
                _alarm_schedule();
        }
 
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       snprintf(log_message, sizeof(log_message), "pid: %d, unique_name: %s", pid, app_name);
+       __save_module_log("DELETE ALL", log_message);
+#endif
+
        __rtc_set();
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
        __rtc_set();
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+
        return true;
 }
 
        return true;
 }
 
@@ -2277,8 +2967,22 @@ gboolean alarm_manager_alarm_update(AlarmManager *pObj, GDBusMethodInvocation *i
        int return_code = ALARMMGR_RESULT_SUCCESS;
        alarm_info_t alarm_info;
        bool ret = true;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        alarm_info_t alarm_info;
        bool ret = true;
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
        char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
        char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+#endif
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        alarm_info.start.year = start_year;
        alarm_info.start.month = start_month;
 
        alarm_info.start.year = start_year;
        alarm_info.start.month = start_month;
@@ -2297,20 +3001,26 @@ gboolean alarm_manager_alarm_update(AlarmManager *pObj, GDBusMethodInvocation *i
        alarm_info.alarm_type = alarm_type;
        alarm_info.reserved_info = reserved_info;
 
        alarm_info.alarm_type = alarm_type;
        alarm_info.reserved_info = reserved_info;
 
-       if (!__alarm_update(pid, app_service_name, alarm_id, &alarm_info, &return_code)) {
+       if (!__alarm_update(pid, app_service_name, alarm_id, &alarm_info, &return_code, zone)) {
                ALARM_MGR_EXCEPTION_PRINT("Unable to update the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code);
                ALARM_MGR_EXCEPTION_PRINT("Unable to update the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code);
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
                strncpy(log_tag, "FAIL: UPDATE", strlen("FAIL: UPDATE"));
                strncpy(log_tag, "FAIL: UPDATE", strlen("FAIL: UPDATE"));
+#endif
                ret = false;
                ret = false;
-       } else {
+       }
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       else {
                strncpy(log_tag, "UPDATE", strlen("UPDATE"));
                strncpy(log_tag, "UPDATE", strlen("UPDATE"));
-               ret = true;
        }
        }
+#endif
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
 
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
 
-       sprintf(log_message, "alarmID: %d, appname: %s, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       snprintf(log_message, sizeof(log_message), "alarmID: %d, appname: %s, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
                alarm_id, app_service_name, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
        __save_module_log(log_tag, log_message);
                alarm_id, app_service_name, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
        __save_module_log(log_tag, log_message);
+#endif
 
        return ret;
 }
 
        return ret;
 }
@@ -2324,6 +3034,20 @@ gboolean alarm_manager_alarm_get_number_of_ids(AlarmManager *pObject, GDBusMetho
        int retval = 0;
        int num_of_ids = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        int retval = 0;
        int num_of_ids = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
+       bool ret = true;
+
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
@@ -2332,7 +3056,7 @@ gboolean alarm_manager_alarm_get_number_of_ids(AlarmManager *pObject, GDBusMetho
                return true;
        }
 
                return true;
        }
 
-       if (!__get_caller_unique_name(pid, app_name)) {
+       if (!__get_caller_unique_name(pid, app_name, zone)) {
                return_code = ERR_ALARM_SYSTEM_FAIL;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
                return true;
                return_code = ERR_ALARM_SYSTEM_FAIL;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
                return true;
@@ -2342,9 +3066,14 @@ gboolean alarm_manager_alarm_get_number_of_ids(AlarmManager *pObject, GDBusMetho
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
-               const gchar *app_unique_name = g_quark_to_string(entry->quark_app_unique_name);
+
+               if (zone[0] != '\0' && strcmp(zone, g_quark_to_string(entry->zone)) != 0)
+                       continue;
+
                SECURE_LOGD("app_name=%s, quark_app_unique_name=%s", app_name, g_quark_to_string(entry->quark_app_unique_name));
                SECURE_LOGD("app_name=%s, quark_app_unique_name=%s", app_name, g_quark_to_string(entry->quark_app_unique_name));
-               if (app_unique_name && strncmp(app_name, app_unique_name, strlen(app_name)) == 0) {
+               const gchar *quark_app_unique_name = g_quark_to_string(entry->quark_app_unique_name);
+               if (quark_app_unique_name &&
+                               strncmp(app_name, quark_app_unique_name, strlen(app_name)) == 0) {
                        (num_of_ids)++;
                        SECURE_LOGD("inc number of alarms of app (pid:%d, unique_name:%s) is %d.", pid, app_name, num_of_ids);
                }
                        (num_of_ids)++;
                        SECURE_LOGD("inc number of alarms of app (pid:%d, unique_name:%s) is %d.", pid, app_name, num_of_ids);
                }
@@ -2352,7 +3081,8 @@ gboolean alarm_manager_alarm_get_number_of_ids(AlarmManager *pObject, GDBusMetho
 
        SECURE_LOGD("number of alarms of the process (pid:%d, unique_name:%s) is %d.", pid, app_name, num_of_ids);
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
 
        SECURE_LOGD("number of alarms of the process (pid:%d, unique_name:%s) is %d.", pid, app_name, num_of_ids);
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
-       return true;
+
+       return ret;
 }
 
 gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
 }
 
 gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
@@ -2366,6 +3096,20 @@ gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodI
        GVariantBuilder* builder = NULL;
        int num_of_ids = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        GVariantBuilder* builder = NULL;
        int num_of_ids = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
+       bool ret = true;
+
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        if (max_number_of_ids <= 0) {
                SECURE_LOGE("called for pid(%d), but max_number_of_ids(%d) is less than 0.", pid, max_number_of_ids);
 
        if (max_number_of_ids <= 0) {
                SECURE_LOGE("called for pid(%d), but max_number_of_ids(%d) is less than 0.", pid, max_number_of_ids);
@@ -2373,7 +3117,7 @@ gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodI
                return true;
        }
 
                return true;
        }
 
-       if (!__get_caller_unique_name(pid, app_name)) {
+       if (!__get_caller_unique_name(pid, app_name, zone)) {
                return_code = ERR_ALARM_SYSTEM_FAIL;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", g_variant_new("ai", NULL), num_of_ids, return_code));
                return true;
                return_code = ERR_ALARM_SYSTEM_FAIL;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", g_variant_new("ai", NULL), num_of_ids, return_code));
                return true;
@@ -2385,8 +3129,12 @@ gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodI
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
 
-               const gchar *app_unique_name = g_quark_to_string(entry->quark_app_unique_name);
-               if (app_unique_name && strncmp(app_name, app_unique_name, strlen(app_name)) == 0) {
+               if (zone[0] != '\0' && strcmp(zone, g_quark_to_string(entry->zone)) != 0)
+                       continue;
+
+               const gchar *quark_app_unique_name = g_quark_to_string(entry->quark_app_unique_name);
+               if (quark_app_unique_name &&
+                               strncmp(app_name, quark_app_unique_name, strlen(app_name)) == 0) {
                        g_variant_builder_add (builder, "i", entry->alarm_id);
                        index ++;
                        SECURE_LOGE("called for alarmid(%d), but max_number_of_ids(%d) index %d.", entry->alarm_id, max_number_of_ids, index);
                        g_variant_builder_add (builder, "i", entry->alarm_id);
                        index ++;
                        SECURE_LOGE("called for alarmid(%d), but max_number_of_ids(%d) index %d.", entry->alarm_id, max_number_of_ids, index);
@@ -2400,7 +3148,8 @@ gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodI
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", arr, num_of_ids, return_code));
 
        g_variant_builder_unref(builder);
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", arr, num_of_ids, return_code));
 
        g_variant_builder_unref(builder);
-       return true;
+
+       return ret;
 }
 
 gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodInvocation *invoc ,
 }
 
 gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodInvocation *invoc ,
@@ -2413,6 +3162,20 @@ gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodI
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        gchar *b_data = NULL;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        gchar *b_data = NULL;
+       bool ret = true;
+
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        SECURE_LOGD("called for pid(%d) and alarm_id(%d)\n", pid, alarm_id);
 
 
        SECURE_LOGD("called for pid(%d) and alarm_id(%d)\n", pid, alarm_id);
 
@@ -2421,10 +3184,15 @@ gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodI
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code));
                return true;
                return_code = retval;
                g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code));
                return true;
+
        }
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
        }
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
+
+               if (zone[0] != '\0' && strcmp(zone, g_quark_to_string(entry->zone)) != 0)
+                       continue;
+
                if (entry->alarm_id == alarm_id) {
                        found = true;
                        b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
                if (entry->alarm_id == alarm_id) {
                        found = true;
                        b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
@@ -2444,7 +3212,8 @@ gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodI
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code));
        g_free(b_data);
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code));
        g_free(b_data);
-       return true;
+
+       return ret;
 }
 
 gboolean alarm_manager_alarm_get_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
 }
 
 gboolean alarm_manager_alarm_get_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
@@ -2457,6 +3226,20 @@ gboolean alarm_manager_alarm_get_info(AlarmManager *pObject, GDBusMethodInvocati
        alarm_info_t *alarm_info = NULL;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        alarm_info_t *alarm_info = NULL;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
+       bool ret = true;
+
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
@@ -2467,6 +3250,10 @@ gboolean alarm_manager_alarm_get_info(AlarmManager *pObject, GDBusMethodInvocati
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
+
+               if (zone[0] != '\0' && strcmp(zone, g_quark_to_string(entry->zone)) != 0)
+                       continue;
+
                if (entry->alarm_id == alarm_id) {
                        alarm_info = &(entry->alarm_info);
                        break;
                if (entry->alarm_id == alarm_id) {
                        alarm_info = &(entry->alarm_info);
                        break;
@@ -2484,7 +3271,7 @@ gboolean alarm_manager_alarm_get_info(AlarmManager *pObject, GDBusMethodInvocati
                                                        alarm_info->end.day, alarm_info->mode.u_interval.day_of_week, alarm_info->mode.repeat, alarm_info->alarm_type, alarm_info->reserved_info, return_code));
        }
 
                                                        alarm_info->end.day, alarm_info->mode.u_interval.day_of_week, alarm_info->mode.repeat, alarm_info->alarm_type, alarm_info->reserved_info, return_code));
        }
 
-       return true;
+       return ret;
 }
 
 gboolean alarm_manager_alarm_get_next_duetime(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
 }
 
 gboolean alarm_manager_alarm_get_next_duetime(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
@@ -2498,6 +3285,20 @@ gboolean alarm_manager_alarm_get_next_duetime(AlarmManager *pObject, GDBusMethod
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        time_t duetime = 0;
        int retval = 0;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        time_t duetime = 0;
+       bool ret = true;
+
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
 
        retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
        if (retval != ALARMMGR_RESULT_SUCCESS) {
@@ -2508,6 +3309,10 @@ gboolean alarm_manager_alarm_get_next_duetime(AlarmManager *pObject, GDBusMethod
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
+
+               if (zone[0] != '\0' && strcmp(zone, g_quark_to_string(entry->zone)) != 0)
+                       continue;
+
                if (entry->alarm_id == alarm_id) {
                        find_item = entry;
                        break;
                if (entry->alarm_id == alarm_id) {
                        find_item = entry;
                        break;
@@ -2525,7 +3330,8 @@ gboolean alarm_manager_alarm_get_next_duetime(AlarmManager *pObject, GDBusMethod
        ALARM_MGR_LOG_PRINT("Next duetime : %s", ctime(&duetime));
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", duetime, return_code));
        ALARM_MGR_LOG_PRINT("Next duetime : %s", ctime(&duetime));
 
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", duetime, return_code));
-       return true;
+
+       return ret;
 }
 
 gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid, char *e_cookie, gpointer user_data)
 }
 
 gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid, char *e_cookie, gpointer user_data)
@@ -2555,6 +3361,20 @@ gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvo
        GSList *gs_iter = NULL;
        __alarm_info_t *entry = NULL;
        char *error_message = NULL;
        GSList *gs_iter = NULL;
        __alarm_info_t *entry = NULL;
        char *error_message = NULL;
+       bool ret = true;
+
+       char zone[MAX_ZONE_NAME_LEN] = {0, };
+       const char *name = g_dbus_method_invocation_get_sender(invoc);
+
+       ALARM_MGR_LOG_PRINT("before getting actual pid[%d]", pid);
+       pid = __get_caller_pid(name);
+       ALARM_MGR_LOG_PRINT("after getting actual pid[%d]", pid);
+
+       if (_get_zone_name(pid, zone, MAX_ZONE_NAME_LEN) != true) {
+               ALARM_MGR_EXCEPTION_PRINT("failed to get zone name with pid[%d]", pid);
+               //Disabled zone
+               memcpy(zone, "/", 1);
+       }
 
        return_code = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
        if (return_code != ALARMMGR_RESULT_SUCCESS) {
 
        return_code = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
        if (return_code != ALARMMGR_RESULT_SUCCESS) {
@@ -2565,7 +3385,7 @@ gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvo
        // Open a DB
        time(&current_time);
        localtime_r(&current_time, &current_tm);
        // Open a DB
        time(&current_time);
        localtime_r(&current_time, &current_tm);
-       sprintf(db_path_tmp, "/tmp/alarmmgr_%d%d%d_%02d%02d%02d.db",
+       snprintf(db_path_tmp, sizeof(db_path_tmp), "/tmp/alarmmgr_%d%d%d_%02d%02d%02d.db",
                current_tm.tm_year + 1900, current_tm.tm_mon + 1, current_tm.tm_mday, current_tm.tm_hour, current_tm.tm_min, current_tm.tm_sec);
        db_path = strdup(db_path_tmp);
 
                current_tm.tm_year + 1900, current_tm.tm_mon + 1, current_tm.tm_mday, current_tm.tm_hour, current_tm.tm_min, current_tm.tm_sec);
        db_path = strdup(db_path_tmp);
 
@@ -2596,6 +3416,10 @@ gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvo
        int index = 0;
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
        int index = 0;
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
+
+               if (zone[0] != '\0' && strcmp(g_quark_to_string(entry->zone), zone)!= 0)
+                       continue;
+
                ++index;
                SECURE_LOGD("#%d alarm id[%d] app_name[%s] duetime[%d]",
                        index, entry->alarm_id, g_quark_to_string(entry->quark_app_unique_name), entry->start);
                ++index;
                SECURE_LOGD("#%d alarm id[%d] app_name[%s] duetime[%d]",
                        index, entry->alarm_id, g_quark_to_string(entry->quark_app_unique_name), entry->start);
@@ -2634,6 +3458,7 @@ gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvo
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
        free(db_path);
        return true;
        g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
        free(db_path);
        return true;
+
 }
 
 static void __timer_glib_finalize(GSource *src)
 }
 
 static void __timer_glib_finalize(GSource *src)
@@ -2704,12 +3529,9 @@ static void __initialize_timer()
 
        gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
        if (gpollfd == NULL) {
 
        gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
        if (gpollfd == NULL) {
-               ALARM_MGR_EXCEPTION_PRINT("out of memory.\n");
-               close(fd);
-               g_source_unref(src);
+               ALARM_MGR_EXCEPTION_PRINT("Out of memory\n");
                exit(1);
        }
                exit(1);
        }
-
        gpollfd->events = POLLIN;
        gpollfd->fd = fd;
 
        gpollfd->events = POLLIN;
        gpollfd->fd = fd;
 
@@ -2746,24 +3568,17 @@ static void __initialize_scheduled_alarm_list()
 
 static bool __initialize_noti()
 {
 
 static bool __initialize_noti()
 {
-       // system state change noti
-       if (vconf_notify_key_changed
-           (VCONFKEY_SETAPPL_TIMEZONE_ID, __on_time_zone_changed, NULL) < 0) {
-               ALARM_MGR_LOG_PRINT(
-                       "Failed to add callback for time zone changing event\n");
-       }
-
+       // VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL is set by OSP app-service.
        if (vconf_notify_key_changed
            (VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, __on_system_time_external_changed, NULL) < 0) {
        if (vconf_notify_key_changed
            (VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, __on_system_time_external_changed, NULL) < 0) {
-               ALARM_MGR_LOG_PRINT(
-                       "Failed to add callback for time external changing event\n");
+               ALARM_MGR_LOG_PRINT("Failed to add callback for time external changing event.");
        }
 
        // If the caller or callee app is uninstalled, all registered alarms will be canceled.
        int event_type = PMINFO_CLIENT_STATUS_UNINSTALL;
        pkgmgrinfo_client* pc = pkgmgrinfo_client_new(PMINFO_LISTENING);
        pkgmgrinfo_client_set_status_type(pc, event_type);
        }
 
        // If the caller or callee app is uninstalled, all registered alarms will be canceled.
        int event_type = PMINFO_CLIENT_STATUS_UNINSTALL;
        pkgmgrinfo_client* pc = pkgmgrinfo_client_new(PMINFO_LISTENING);
        pkgmgrinfo_client_set_status_type(pc, event_type);
-       pkgmgrinfo_client_listen_status(pc, __on_app_uninstalled, NULL);
+       pkgmgrinfo_client_listen_status_with_zone(pc, __on_app_uninstalled, NULL);
 
        return true;
 }
 
        return true;
 }
@@ -2826,6 +3641,7 @@ static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpoi
        g_signal_connect(interface, "handle_alarm_set_timezone", G_CALLBACK(alarm_manager_alarm_set_timezone), NULL);
        g_signal_connect(interface, "handle_alarm_update", G_CALLBACK(alarm_manager_alarm_update), NULL);
        g_signal_connect(interface, "handle_alarm_get_all_info", G_CALLBACK(alarm_manager_alarm_get_all_info), NULL);
        g_signal_connect(interface, "handle_alarm_set_timezone", G_CALLBACK(alarm_manager_alarm_set_timezone), NULL);
        g_signal_connect(interface, "handle_alarm_update", G_CALLBACK(alarm_manager_alarm_update), NULL);
        g_signal_connect(interface, "handle_alarm_get_all_info", G_CALLBACK(alarm_manager_alarm_get_all_info), NULL);
+       g_signal_connect(interface, "handle_alarm_set_time_with_propagation_delay", G_CALLBACK(alarm_manager_alarm_set_time_with_propagation_delay), NULL);
 
        guint subsc_id = g_dbus_connection_signal_subscribe(connection, "org.freedesktop.DBus", "org.freedesktop.DBus",
                                                        "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
 
        guint subsc_id = g_dbus_connection_signal_subscribe(connection, "org.freedesktop.DBus", "org.freedesktop.DBus",
                                                        "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
@@ -2867,12 +3683,13 @@ static bool __initialize_dbus()
                return false;
        }
 
                return false;
        }
 
+       ALARM_MGR_LOG_PRINT("__initialize_dbus Exit");
        return true;
 }
 
 #define ALARMMGR_DB_FILE "/opt/dbspace/.alarmmgr.db"
        return true;
 }
 
 #define ALARMMGR_DB_FILE "/opt/dbspace/.alarmmgr.db"
-sqlite3 *alarmmgr_db;
-#define QUERY_CREATE_TABLE_ALARMMGR "create table alarmmgr \
+
+#define QUERY_CREATE_TABLE_ALARMMGR "create table if not exists alarmmgr \
                                (alarm_id integer primary key,\
                                                start integer,\
                                                end integer,\
                                (alarm_id integer primary key,\
                                                start integer,\
                                                end integer,\
@@ -2897,34 +3714,155 @@ sqlite3 *alarmmgr_db;
                                                dst_service_name_mod text \
                                                )"
 
                                                dst_service_name_mod text \
                                                )"
 
+void vsm_iter_cb(vsm_zone_h zone, void *user_data)
+{
+
+       char *error_message = NULL;
+       int ret;
+       char db_path[1024] = { '\0' };
+       const char* zone_name = NULL;
+       sqlite3 *alarmmgr_zone_db = NULL;
+
+       zone_name = vsm_get_zone_name(zone);
+       if (!zone_name) {
+               ALARM_MGR_EXCEPTION_PRINT("Failed to get zone name");
+               return;
+       }
+
+       ALARM_MGR_LOG_PRINT("Zone : %s\n", zone_name);
+
+       _zone_alarm_db_list_t *alarm_db_list = NULL;
+       alarm_db_list = malloc(sizeof(_zone_alarm_db_list_t));
+       if (alarm_db_list == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("malloc failed");
+               return;
+       }
+
+       alarm_db_list->zone = strdup(zone_name);
+
+       snprintf(db_path, 1024, "%s/%s%s%s", ZONE_PREFIX_PATH, zone_name, ZONE_INFIX_PATH, ALARMMGR_DB_FILE);
+       if (access(db_path, F_OK) == 0) {
+               ALARM_MGR_LOG_PRINT("db[%s] exists", db_path);
+
+               ret = db_util_open(db_path, &alarmmgr_zone_db, DB_UTIL_REGISTER_HOOK_METHOD);
+               if (ret != SQLITE_OK) {
+                       ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", db_path);
+
+                       if (alarm_db_list->zone)
+                               free(alarm_db_list->zone);
+                       if (alarm_db_list)
+                               free(alarm_db_list);
+
+                       return;
+               }
+
+               alarm_db_list->alarmmgr_db = alarmmgr_zone_db;
+               alarmmgr_db_list = g_slist_append(alarmmgr_db_list, alarm_db_list);
+
+               ALARM_MGR_LOG_PRINT("alarmmgr_db_list length:[%d]\n", g_slist_length(alarmmgr_db_list));
+               return;
+       }
+
+       ret = db_util_open(db_path, &alarmmgr_zone_db, DB_UTIL_REGISTER_HOOK_METHOD);
+       if (ret != SQLITE_OK) {
+               ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", db_path);
+               free(alarm_db_list->zone);
+               free(alarm_db_list);
+               return;
+       }
+
+
+       if (SQLITE_OK != sqlite3_exec(alarmmgr_zone_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL, &error_message)) {
+               ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, error message = %s", QUERY_CREATE_TABLE_ALARMMGR, error_message);
+               if (error_message != NULL)
+                       free(error_message);
+               free(alarm_db_list->zone);
+               free(alarm_db_list);
+               return;
+       }
+
+       alarm_db_list->alarmmgr_db = alarmmgr_zone_db;
+       alarmmgr_db_list = g_slist_append(alarmmgr_db_list, alarm_db_list);
+
+       ALARM_MGR_LOG_PRINT("alarmmgr_db_list length:[%d]\n", g_slist_length(alarmmgr_db_list));
+
+}
+
 static bool __initialize_db()
 {
        char *error_message = NULL;
        int ret;
 static bool __initialize_db()
 {
        char *error_message = NULL;
        int ret;
+       char db_path[1024] = { '\0' };
+
+       sqlite3 *alarmmgr_host_db = NULL;
+       vsm_zone_h zone;
+       vsm_context_h ctx = vsm_create_context();
+       if (ctx == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("vsm_create_context failed");
+       } else {
+               ret = vsm_iterate_zone(ctx, vsm_iter_cb, NULL);
+               if( ret != VSM_ERROR_NONE )
+               {
+                       ALARM_MGR_LOG_PRINT("vsm_iterate_zone failed\n");
+               }
+       }
+
+       _zone_alarm_db_list_t *alarm_db_list = NULL;
+       alarm_db_list = malloc(sizeof(_zone_alarm_db_list_t));
+       if (alarm_db_list == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("malloc failed");
+               return false;
+       }
+
+       alarm_db_list->zone = strdup("/");
 
 
-       if (access("/opt/dbspace/.alarmmgr.db", F_OK) == 0) {
-               ret = db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db, DB_UTIL_REGISTER_HOOK_METHOD);
+       snprintf(db_path, 1024, "%s", ALARMMGR_DB_FILE);
+       if (access(db_path, F_OK) == 0) {
+               ALARM_MGR_LOG_PRINT("db[%s] exists", db_path);
 
 
+               ret = db_util_open(db_path, &alarmmgr_host_db, DB_UTIL_REGISTER_HOOK_METHOD);
                if (ret != SQLITE_OK) {
                if (ret != SQLITE_OK) {
-                       ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", ALARMMGR_DB_FILE);
+                       ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", db_path);
+                       free(alarm_db_list->zone);
+                       free(alarm_db_list);
                        return false;
                }
 
                        return false;
                }
 
+               alarm_db_list->alarmmgr_db = alarmmgr_host_db;
+               alarmmgr_db_list = g_slist_append(alarmmgr_db_list, alarm_db_list);
+
                return true;
        }
 
                return true;
        }
 
-       ret = db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db, DB_UTIL_REGISTER_HOOK_METHOD);
-
+       ret = db_util_open(db_path, &alarmmgr_host_db, DB_UTIL_REGISTER_HOOK_METHOD);
        if (ret != SQLITE_OK) {
        if (ret != SQLITE_OK) {
-               ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", ALARMMGR_DB_FILE);
+               ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", db_path);
+               if (alarm_db_list->zone)
+                       free(alarm_db_list->zone);
+
+               if (alarm_db_list)
+                       free(alarm_db_list);
+
                return false;
        }
 
                return false;
        }
 
-       if (SQLITE_OK != sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL, &error_message)) {
+       if (SQLITE_OK != sqlite3_exec(alarmmgr_host_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL, &error_message)) {
                ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, error message = %s", QUERY_CREATE_TABLE_ALARMMGR, error_message);
                ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, error message = %s", QUERY_CREATE_TABLE_ALARMMGR, error_message);
+               if (error_message != NULL)
+                       free(error_message);
+
+               if (alarm_db_list->zone)
+                       free(alarm_db_list->zone);
+
+               if (alarm_db_list)
+                       free(alarm_db_list);
+
                return false;
        }
 
                return false;
        }
 
+       alarm_db_list->alarmmgr_db = alarmmgr_host_db;
+       alarmmgr_db_list = g_slist_append(alarmmgr_db_list, alarm_db_list);
+
        return true;
 }
 
        return true;
 }
 
@@ -2939,15 +3877,19 @@ static void __initialize()
                                          "alarm-server cannot be runned.\n");
                exit(1);
        }
                                          "alarm-server cannot be runned.\n");
                exit(1);
        }
+
+#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
+       __initialize_module_log();      // for module log
+#endif
+
        __initialize_scheduled_alarm_list();
        __initialize_db();
        __initialize_alarm_list();
        __initialize_noti();
 
        __initialize_scheduled_alarm_list();
        __initialize_db();
        __initialize_alarm_list();
        __initialize_noti();
 
-       __initialize_module_log();      // for module log
-
 }
 
 }
 
+
 int main()
 {
        GMainLoop *mainloop = NULL;
 int main()
 {
        GMainLoop *mainloop = NULL;
index f3ec7ed..a074365 100644 (file)
@@ -8,10 +8,22 @@
                        <label name="alarm-server::alarm-periodic"/>
                </provide>
                <request>
                        <label name="alarm-server::alarm-periodic"/>
                </provide>
                <request>
+                       <smack request="_" type="rwx"/>
                        <smack request="deviced::display" type="rw"/>
                        <smack request="alarm-server::alarm-ref-periodic" type="w"/>
                        <smack request="alarm-server::alarm-periodic" type="w"/>
                        <smack request="security-server::api-cookie-check" type="w"/>
                        <smack request="deviced::display" type="rw"/>
                        <smack request="alarm-server::alarm-ref-periodic" type="w"/>
                        <smack request="alarm-server::alarm-periodic" type="w"/>
                        <smack request="security-server::api-cookie-check" type="w"/>
+                       <smack request="pkgmgr::db" type="rl"/>
+                       <smack request="system::sys_logging" type="rx"/>
+                       <smack request="device::sys_logging" type="rw"/>
+                       <smack request="device::app_logging" type="rw"/>
+                       <smack request="device::alarm" type="rw"/>
+                       <smack request="aul::launch" type="x"/>
+                       <smack request="app-svc::jump" type="x"/>
+                       <smack request="app-svc::db" type="rw"/>
+                       <smack request="tizen::vconf::public::r::platform::rw" type="rw"/>
+                       <smack request="tizen::vconf::platform::rw" type="rw"/>
+                       <smack request="tizen::vconf::setting::admin" type="rl"/>
                </request>
        </define>
        <assign>
                </request>
        </define>
        <assign>
index 61ed86a..b26f9a7 100755 (executable)
@@ -46,6 +46,7 @@
       <arg type="i" name="alarm_info_end_month" direction="in" />
       <arg type="i" name="alarm_info_end_day" direction="in" />
       <arg type="i" name="alarm_info_mode_day_of_week" direction="in" />
       <arg type="i" name="alarm_info_end_month" direction="in" />
       <arg type="i" name="alarm_info_end_day" direction="in" />
       <arg type="i" name="alarm_info_mode_day_of_week" direction="in" />
+      <arg type="u" name="alarm_info_mode_interval" direction="in" />
       <arg type="i" name="alarm_info_mode_repeat" direction="in" />
       <arg type="i" name="alarm_info_alarm_type" direction="in" />
       <arg type="i" name="alarm_info_reserved_info" direction="in" />
       <arg type="i" name="alarm_info_mode_repeat" direction="in" />
       <arg type="i" name="alarm_info_alarm_type" direction="in" />
       <arg type="i" name="alarm_info_reserved_info" direction="in" />
       <arg type="i" name="time" direction="in" />
       <arg type="i" name="return_code" direction="out" />
     </method>
       <arg type="i" name="time" direction="in" />
       <arg type="i" name="return_code" direction="out" />
     </method>
-    <method name="alarm_set_timezone">
-      <arg type="s" name="tzpath_str" direction="in" />
-      <arg type="i" name="return_code" direction="out" />
+    <method name="alarm_set_time_with_propagation_delay">
+         <arg type="u" name="new_sec" direction="in" />
+         <arg type="u" name="new_nsec" direction="in" />
+         <arg type="u" name="req_sec" direction="in" />
+         <arg type="u" name="req_nsec" direction="in" />
+         <arg type="i" name="return_code" direction="out" />
+    </method>
+       <method name="alarm_set_timezone">
+         <arg type="s" name="tzpath_str" direction="in" />
+         <arg type="i" name="return_code" direction="out" />
     </method>
   </interface>
 </node>
     </method>
   </interface>
 </node>
old mode 100644 (file)
new mode 100755 (executable)
similarity index 61%
rename from alarmmgr_log_dump.sh
rename to alarmmgr_log_dump.sh.in
index 94fbd03..9fa523f
@@ -1,8 +1,8 @@
-#!bin/sh
+#!/bin/sh
 
 ALARMMGR_DUMP=$1/alarmmgr
 mkdir -p $ALARMMGR_DUMP
 
 ALARMMGR_DUMP=$1/alarmmgr
 mkdir -p $ALARMMGR_DUMP
-cp -f /var/log/alarmmgr.log $ALARMMGR_DUMP
+cp -f @_APPFW_ALARM_MANAGER_MODULE_LOG_PATH@ $ALARMMGR_DUMP
 
 alarmmgr_get_all_info
 mv -f /tmp/alarmmgr_* $ALARMMGR_DUMP
 
 alarmmgr_get_all_info
 mv -f /tmp/alarmmgr_* $ALARMMGR_DUMP
old mode 100644 (file)
new mode 100755 (executable)
index d3df4c6..9216a77
 #include <appsvc.h>
 #include <gio/gio.h>
 
 #include <appsvc.h>
 #include <gio/gio.h>
 
+#include <sqlite3.h>
+
 #define INIT_ALARM_LIST_SIZE 64
 #define INIT_SCHEDULED_ALARM_LIST_SIZE 32
 #define MAX_BUNDLE_NAME_LEN 2048
 #define MAX_SERVICE_NAME_LEN 256
 #define MAX_PKG_NAME_LEN MAX_SERVICE_NAME_LEN-8
 #define MAX_PKG_ID_LEN 256
 #define INIT_ALARM_LIST_SIZE 64
 #define INIT_SCHEDULED_ALARM_LIST_SIZE 32
 #define MAX_BUNDLE_NAME_LEN 2048
 #define MAX_SERVICE_NAME_LEN 256
 #define MAX_PKG_NAME_LEN MAX_SERVICE_NAME_LEN-8
 #define MAX_PKG_ID_LEN 256
+#define MIN_INEXACT_INTERVAL 600
 
 #define SYSTEM_TIME_CHANGED "setting_time_changed"
 
 
 #define SYSTEM_TIME_CHANGED "setting_time_changed"
 
@@ -118,26 +121,26 @@ typedef struct {
 } alarm_info_t;
 
 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm,
 } alarm_info_t;
 
 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm,
-                        alarm_id_t *id, const char *dst_service_name,const char *dst_service_name_mod,
-                        int *error_code);
+                       alarm_id_t *id, const char *dst_service_name,const char *dst_service_name_mod, int *error_code);
 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
                        alarm_id_t *alarm_id, bundle *b,int *error_code);
 bool _send_alarm_update(alarm_context_t context, int pid, alarm_id_t alarm_id,
 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
                        alarm_id_t *alarm_id, bundle *b,int *error_code);
 bool _send_alarm_update(alarm_context_t context, int pid, alarm_id_t alarm_id,
-                        alarm_info_t *alarm_info, int *error_code);
-bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
-                        int *error_code);
+                       alarm_info_t *alarm_info, int *error_code);
+bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
+bool _send_alarm_delete_all(alarm_context_t context, int *error_code);
 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
-                                 alarm_id_t *alarm_id, int *num_of_ids,
-                                 int *error_code);
-bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
-                                   int *error_code);
-bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
-                          alarm_info_t *alarm_info, int *error_code);
+                       alarm_id_t *alarm_id, int *num_of_ids, int *error_code);
+bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, int *error_code);
+bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, alarm_info_t *alarm_info, int *error_code);
+bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, time_t* duetime, int *error_code);
+bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code);
 bool _send_alarm_reset(alarm_context_t context, int *error_code);
 bool _send_alarm_reset(alarm_context_t context, int *error_code);
-bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id);
+bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id, const char *zone);
 bool _load_alarms_from_registry();
 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code);
 bool _load_alarms_from_registry();
 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code);
+bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, int *error_code);
+bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code);
 
 /*  alarm manager*/
 typedef struct {
 
 /*  alarm manager*/
 typedef struct {
@@ -167,9 +170,15 @@ typedef struct {
        periodic_method_e method;
        long requested_interval;
        int is_ref;
        periodic_method_e method;
        long requested_interval;
        int is_ref;
+       GQuark zone;
 } __alarm_info_t;
 
 typedef struct {
 } __alarm_info_t;
 
 typedef struct {
+       char *zone;
+       sqlite3 *alarmmgr_db;
+} _zone_alarm_db_list_t;
+
+typedef struct {
        bool used;
        __alarm_info_t *__alarm_info;
 } __alarm_entry_t;
        bool used;
        __alarm_info_t *__alarm_info;
 } __alarm_entry_t;
@@ -195,13 +204,18 @@ typedef struct {
        alarm_id_t alarm_id;
 } __expired_alarm_t;
 
        alarm_id_t alarm_id;
 } __expired_alarm_t;
 
+typedef struct _bg_category_cb_info_t {
+       char *appid;
+       bool has_bg;
+} bg_category_cb_info_t;
+
 time_t _alarm_next_duetime(__alarm_info_t *alarm_info);
 bool _alarm_schedule();
 bool _clear_scheduled_alarm_list();
 bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);
 
 bool _save_alarms(__alarm_info_t *__alarm_info);
 time_t _alarm_next_duetime(__alarm_info_t *alarm_info);
 bool _alarm_schedule();
 bool _clear_scheduled_alarm_list();
 bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);
 
 bool _save_alarms(__alarm_info_t *__alarm_info);
-bool _delete_alarms(alarm_id_t alarm_id);
+bool _delete_alarms(alarm_id_t alarm_id, const char *zone);
 bool _update_alarms(__alarm_info_t *__alarm_info);
 
 bool _alarm_destory_timer(timer_t timer);
 bool _update_alarms(__alarm_info_t *__alarm_info);
 
 bool _alarm_destory_timer(timer_t timer);
@@ -209,21 +223,11 @@ bool _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t
 bool _alarm_disable_timer(__alarm_server_context_t alarm_context);
 bool _init_scheduled_alarm_list();
 
 bool _alarm_disable_timer(__alarm_server_context_t alarm_context);
 bool _init_scheduled_alarm_list();
 
-int _set_rtc_time(time_t _time);
-int _set_sys_time(time_t _time);
-int _set_time(time_t _time);
-
-#ifdef _DEBUG_MODE_
-#define ALARM_MGR_LOG_PRINT(FMT, ARG...)  do { printf("%5d", getpid()); printf
-       ("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)
-#define ALARM_MGR_EXCEPTION_PRINT(FMT, ARG...)  do { printf("%5d", getpid());
-       printf("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)
-#define ALARM_MGR_ASSERT_PRINT(FMT, ARG...) do { printf("%5d", getpid()); printf
-       ("%s() : "FMT"\n", __FUNCTION__, ##ARG); } while (false)
-#else
+time_t _get_periodic_alarm_standard_time(void);
+
 #define ALARM_MGR_LOG_PRINT(FMT, ARG...) LOGD(FMT, ##ARG);
 #define ALARM_MGR_LOG_PRINT(FMT, ARG...) LOGD(FMT, ##ARG);
-#define ALARM_MGR_EXCEPTION_PRINT(FMT, ARG...) LOGW(FMT, ##ARG);
-#define ALARM_MGR_ASSERT_PRINT(FMT, ARG...) LOGE(FMT, ##ARG);
-#endif
+#define ALARM_MGR_WARNING_PRINT(FMT, ARG...) LOGW(FMT, ##ARG);
+#define ALARM_MGR_EXCEPTION_PRINT(FMT, ARG...) LOGE(FMT, ##ARG);
+#define ALARM_MGR_ASSERT_PRINT(FMT, ARG...) LOGF(FMT, ##ARG);
 
 #endif /*_ALARM_INTERNAL_H*/
 
 #endif /*_ALARM_INTERNAL_H*/
old mode 100755 (executable)
new mode 100644 (file)
index 3e9edf6..fe34d18
@@ -149,8 +149,9 @@ int main(int argc, char** argv)
  * @{
  */
 
  * @{
  */
 
-#include<sys/types.h>
-#include<stdbool.h>
+#include <sys/types.h>
+#include <stdbool.h>
+#include <time.h>
 
 #ifdef __cplusplus
 extern "C" {
 
 #ifdef __cplusplus
 extern "C" {
@@ -185,6 +186,7 @@ typedef enum {
 * This enumeration has error codes of alarm
 */
        typedef enum {
 * This enumeration has error codes of alarm
 */
        typedef enum {
+               ERR_ALARM_NOT_PERMITTED_APP = -11,
                ERR_ALARM_INVALID_PARAM = -10,
                                     /**<Invalid parameter*/
                ERR_ALARM_INVALID_ID,   /**<Invalid id*/
                ERR_ALARM_INVALID_PARAM = -10,
                                     /**<Invalid parameter*/
                ERR_ALARM_INVALID_ID,   /**<Invalid id*/
@@ -225,6 +227,7 @@ typedef enum {
 #define ALARM_TYPE_DEFAULT     0x0     /*< non volatile */
 #define ALARM_TYPE_VOLATILE    0x02    /*< volatile */
 #define ALARM_TYPE_NOLAUNCH 0x04       /*<without launch */
 #define ALARM_TYPE_DEFAULT     0x0     /*< non volatile */
 #define ALARM_TYPE_VOLATILE    0x02    /*< volatile */
 #define ALARM_TYPE_NOLAUNCH 0x04       /*<without launch */
+#define ALARM_TYPE_INEXACT 0x08        /*<inexact alarm */
 
 
 /**
 
 
 /**
@@ -277,7 +280,6 @@ typedef struct alarm_info_t alarm_entry_t;
        }
 }
  * @endcode
        }
 }
  * @endcode
- * @limo
  */
 int alarmmgr_init(const char *appid);
 
  */
 int alarmmgr_init(const char *appid);
 
@@ -358,7 +360,6 @@ int callback(alarm_id_t alarm_id,void* user_param)
 }
 
  * @endcode
 }
 
  * @endcode
- * @limo
  */
 int alarmmgr_set_cb(alarm_cb_t handler, void *user_param);
 
  */
 int alarmmgr_set_cb(alarm_cb_t handler, void *user_param);
 
@@ -394,7 +395,6 @@ int alarmmgr_set_cb(alarm_cb_t handler, void *user_param);
 
 
  * @endcode
 
 
  * @endcode
- * @limo
  */
 alarm_entry_t *alarmmgr_create_alarm(void);
 
  */
 alarm_entry_t *alarmmgr_create_alarm(void);
 
@@ -441,7 +441,6 @@ alarm_entry_t *alarmmgr_create_alarm(void);
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_free_alarm(alarm_entry_t *alarm);
 
  */
 int alarmmgr_free_alarm(alarm_entry_t *alarm);
 
@@ -503,7 +502,6 @@ int alarmmgr_free_alarm(alarm_entry_t *alarm);
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time);
 
  */
 int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time);
 
@@ -572,7 +570,6 @@ int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time);
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_get_time(const alarm_entry_t *alarm, alarm_date_t *time);
 
  */
 int alarmmgr_get_time(const alarm_entry_t *alarm, alarm_date_t *time);
 
@@ -631,7 +628,6 @@ int alarmmgr_get_time(const alarm_entry_t *alarm, alarm_date_t *time);
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
                                     alarm_repeat_mode_t repeat_mode,
  */
 int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
                                     alarm_repeat_mode_t repeat_mode,
@@ -687,7 +683,6 @@ int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
                                     alarm_repeat_mode_t *repeat_mode,
  */
 int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
                                     alarm_repeat_mode_t *repeat_mode,
@@ -738,7 +733,6 @@ int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type);
 
  */
 int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type);
 
@@ -783,7 +777,6 @@ int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type);
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type);
 
  */
 int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type);
 
@@ -872,7 +865,6 @@ int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type);
 
 }
  * @endcode
 
 }
  * @endcode
- * @limo
  */
 int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm,void *bundle_data, alarm_id_t *alarm_id);
 
  */
 int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm,void *bundle_data, alarm_id_t *alarm_id);
 
@@ -957,7 +949,6 @@ int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm,void *bundle_d
         alarmmgr_free_alarm( alarm) ;
  }
  * @endcode
         alarmmgr_free_alarm( alarm) ;
  }
  * @endcode
- * @limo
  */
 int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
                                              const char *destination,
  */
 int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
                                              const char *destination,
@@ -1021,7 +1012,6 @@ int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
                               time_t interval, void *bundle_data,
  */
 int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
                               time_t interval, void *bundle_data,
@@ -1090,7 +1080,6 @@ int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
                               time_t interval, const char *destination,
  */
 int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
                               time_t interval, const char *destination,
@@ -1144,7 +1133,6 @@ int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_remove_alarm(alarm_id_t alarm_id);
 
  */
 int alarmmgr_remove_alarm(alarm_id_t alarm_id);
 
@@ -1208,7 +1196,6 @@ int alarmmgr_remove_all(void);
  }
 
  * @endcode
  }
 
  * @endcode
- * @limo
  */
 int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param);
 
  */
 int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param);
 
@@ -1268,7 +1255,6 @@ int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param);
        alarmmgr_remove_alarm( alarm_id) ;
  }
  * @endcode
        alarmmgr_remove_alarm( alarm_id) ;
  }
  * @endcode
- * @limo
  */
 int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm);
 
  */
 int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm);
 
@@ -1332,7 +1318,6 @@ int main(int argc,char **argv {
 
  }
  * @endcode
 
  }
  * @endcode
- * @limo
  */
 void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code);
 
  */
 void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code);
 
@@ -1380,7 +1365,6 @@ int main(int argc,char **argv {
 
  }
  * @endcode
 
  }
  * @endcode
- * @limo
  */
 int alarmmgr_set_rtc_time(alarm_date_t *time);
 
  */
 int alarmmgr_set_rtc_time(alarm_date_t *time);
 
@@ -1396,6 +1380,19 @@ int alarmmgr_set_rtc_time(alarm_date_t *time);
 int alarmmgr_set_systime(int new_time);
 
 /**
 int alarmmgr_set_systime(int new_time);
 
 /**
+ * This function changes the system time and compensates the time using propagation delay.
+ * @param      [in]            new_time                system time to be set (seconds, nanoseconds)
+ * @param      [in]            req_time                time to request to change the system time (seconds, nanoseconds)
+ *
+ * @return     @c ALARMMGR_RESULT_SUCCESS on success,
+ *                     otherwise a negative error value
+ * @retval     #ALARMMGR_RESULT_SUCCESS        Successful
+ * @retval     #ERR_ALARM_SYSTEM_FAIL          System failure
+ * @retval     #ERR_ALARM_INVALID_PARAM        invalid parameter
+ */
+int alarmmgr_set_systime_with_propagation_delay(struct timespec new_time, struct timespec req_time);
+
+/**
  * This function changes the timezone which tranferred by other module
  * @param      [in]            tzpath_str      the path to timezone definition file
  *
  * This function changes the timezone which tranferred by other module
  * @param      [in]            tzpath_str      the path to timezone definition file
  *
index a7b19a8..228b3d6 100644 (file)
@@ -1,6 +1,6 @@
 Name:       alarm-manager
 Summary:    Alarm library
 Name:       alarm-manager
 Summary:    Alarm library
-Version:    0.4.163
+Version:    0.4.179
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
@@ -23,15 +23,18 @@ BuildRequires: pkgconfig(pkgmgr-info)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(gio-unix-2.0)
 BuildRequires: pkgconfig(capi-system-device)
 BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(gio-unix-2.0)
 BuildRequires: pkgconfig(capi-system-device)
-BuildRequires: python-xml
+BuildRequires: pkgconfig(vasum)
+BuildRequires: pkgconfig(eventsystem)
 
 %description
 Alarm Server and devel libraries
 
 
 %description
 Alarm Server and devel libraries
 
+
 %package -n alarm-server
 Summary:    Alarm server (devel)
 Group:      Development/Libraries
 
 %package -n alarm-server
 Summary:    Alarm server (devel)
 Group:      Development/Libraries
 
+
 %description -n alarm-server
 Alarm Server
 
 %description -n alarm-server
 Alarm Server
 
@@ -41,6 +44,7 @@ Summary:    Alarm server libraries
 Group:      Development/Libraries
 Requires:   alarm-server = %{version}-%{release}
 
 Group:      Development/Libraries
 Requires:   alarm-server = %{version}-%{release}
 
+
 %description -n libalarm
 Alarm server library
 
 %description -n libalarm
 Alarm server library
 
@@ -54,23 +58,30 @@ Requires:   libalarm = %{version}-%{release}
 %description -n libalarm-devel
 Alarm server library (devel)
 
 %description -n libalarm-devel
 Alarm server library (devel)
 
+
 %prep
 %setup -q
 
 %prep
 %setup -q
 
+
 %build
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %build
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+
 %if 0%{?sec_build_binary_debug_enable}
 export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
 export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
 export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
 %if 0%{?sec_build_binary_debug_enable}
 export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
 export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
 export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+%define appfw_feature_alarm_manager_module_log 1
 %endif
 %ifarch %{ix86}
        ARCH=x86
 %else
        ARCH=arm
 %endif
 %endif
 %ifarch %{ix86}
        ARCH=x86
 %else
        ARCH=arm
 %endif
-
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=${ARCH}
+%if 0%{?appfw_feature_alarm_manager_module_log}
+       %define module_log_path /var/log/alarmmgr.log
+       _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG=ON
+%endif
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=${ARCH} -D_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG:BOOL=${_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG} -D_APPFW_ALARM_MANAGER_MODULE_LOG_PATH=%{module_log_path}
 
 make %{?jobs:-j%jobs}
 
 
 make %{?jobs:-j%jobs}
 
@@ -87,17 +98,23 @@ mkdir -p %{buildroot}/usr/share/license
 cp LICENSE %{buildroot}/usr/share/license/alarm-server
 cp LICENSE %{buildroot}/usr/share/license/libalarm
 
 cp LICENSE %{buildroot}/usr/share/license/alarm-server
 cp LICENSE %{buildroot}/usr/share/license/libalarm
 
+%if 0%{?appfw_feature_alarm_manager_module_log}
+       mkdir -p %{buildroot}/`dirname %{module_log_path}`
+       touch %{buildroot}/%{module_log_path}
+%endif
+
 %post -p /sbin/ldconfig
 
 %postun -p /sbin/ldconfig
 
 %post -n alarm-server
 
 %post -p /sbin/ldconfig
 
 %postun -p /sbin/ldconfig
 
 %post -n alarm-server
 
-vconftool set -t int db/system/timechange 0 -g 5000 -s system::vconf_system
-vconftool set -t double db/system/timechange_external 0 -g 5000 -s system::vconf_system
-vconftool set -t int memory/system/timechanged 0 -i -g 5000 -s system::vconf_system
+chown system:system /opt/dbspace/.alarmmgr.db
+chown system:system /opt/dbspace/.alarmmgr.db-journal
+chown system:system /var/log/alarmmgr.log
 
 chmod 755 /usr/bin/alarm-server
 
 chmod 755 /usr/bin/alarm-server
+/usr/sbin/setcap CAP_DAC_OVERRIDE+eip /usr/bin/alarm-server
 
 %post -n libalarm
 chmod 644 /usr/lib/libalarm.so.0.0.0
 
 %post -n libalarm
 chmod 644 /usr/lib/libalarm.so.0.0.0
@@ -109,7 +126,10 @@ chmod 644 /usr/lib/libalarm.so.0.0.0
 %{_libdir}/systemd/system/multi-user.target.wants/alarm-server.service
 %{_libdir}/systemd/system/alarm-server.service
 /usr/share/license/alarm-server
 %{_libdir}/systemd/system/multi-user.target.wants/alarm-server.service
 %{_libdir}/systemd/system/alarm-server.service
 /usr/share/license/alarm-server
-%attr(0755,root,root) /opt/etc/dump.d/module.d/alarmmgr_log_dump.sh
+%if 0%{?appfw_feature_alarm_manager_module_log}
+%attr(0755,system,system) /opt/etc/dump.d/module.d/alarmmgr_log_dump.sh
+%attr(0644,system,system) %{module_log_path}
+%endif
 
 %files -n libalarm
 %manifest alarm-lib.manifest
 
 %files -n libalarm
 %manifest alarm-lib.manifest
@@ -121,4 +141,3 @@ chmod 644 /usr/lib/libalarm.so.0.0.0
 %{_includedir}/*.h
 %{_libdir}/pkgconfig/*.pc
 %{_libdir}/*.so
 %{_includedir}/*.h
 %{_libdir}/pkgconfig/*.pc
 %{_libdir}/*.so
-
index 49bb577..caff6d0 100644 (file)
@@ -3,6 +3,9 @@ Description=Alarm server
 After=system-server.service
 
 [Service]
 After=system-server.service
 
 [Service]
+User=system
+Group=system
+SmackProcessLabel=alarm-server
 ExecStart=/usr/bin/alarm-server
 TimeoutStopSec=3s
 Restart=always
 ExecStart=/usr/bin/alarm-server
 TimeoutStopSec=3s
 Restart=always
index b773f08..0b91067 100644 (file)
@@ -122,6 +122,7 @@ bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info
                                                    alarm_info->end.month,
                                                    alarm_info->end.day,
                                                    alarm_info->mode.u_interval.day_of_week,
                                                    alarm_info->end.month,
                                                    alarm_info->end.day,
                                                    alarm_info->mode.u_interval.day_of_week,
+                                                   alarm_info->mode.u_interval.interval,
                                                    alarm_info->mode.repeat,
                                                    alarm_info->alarm_type,
                                                    alarm_info->reserved_info,
                                                    alarm_info->mode.repeat,
                                                    alarm_info->alarm_type,
                                                    alarm_info->reserved_info,
@@ -132,7 +133,10 @@ bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info
                /* error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
                "alarm_manager_call_alarm_create_appsvc_sync()failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
                /* error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
                "alarm_manager_call_alarm_create_appsvc_sync()failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
-               ALARM_MGR_EXCEPTION_PRINT("error->message is %s.", error->message);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
        }
 
        g_free(e_cookie);
        }
 
        g_free(e_cookie);
@@ -201,7 +205,10 @@ bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
                /* error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
                "alarm_manager_call_alarm_create_sync()failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
                /* error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
                "alarm_manager_call_alarm_create_sync()failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
-               ALARM_MGR_EXCEPTION_PRINT("error->message is %s", error->message);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -245,12 +252,13 @@ bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_r
        if (!alarm_manager_call_alarm_create_periodic_sync((AlarmManager*)context.proxy,
                        g_quark_to_string(context.quark_app_service_name),
                        g_quark_to_string(context.quark_app_service_name_mod),
        if (!alarm_manager_call_alarm_create_periodic_sync((AlarmManager*)context.proxy,
                        g_quark_to_string(context.quark_app_service_name),
                        g_quark_to_string(context.quark_app_service_name_mod),
-                       interval, is_ref, method,
-                       e_cookie,
-                   alarm_id, &return_code, NULL, &error)) {
+                       interval, is_ref, method, e_cookie, alarm_id, &return_code, NULL, &error)) {
                ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_create_periodic_sync()failed. alarm_id[%d], return_code[%d]",
                        alarm_id, return_code);
                ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_create_periodic_sync()failed. alarm_id[%d], return_code[%d]",
                        alarm_id, return_code);
-               ALARM_MGR_EXCEPTION_PRINT("error->message is %s", error->message);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -277,7 +285,6 @@ bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id
        bundle *b = NULL;
        char *e_cookie = NULL;
        gchar *b_data = NULL;
        bundle *b = NULL;
        char *e_cookie = NULL;
        gchar *b_data = NULL;
-       int len = 0;
 
        e_cookie = __get_cookie(error_code);
        if (e_cookie == NULL) {
 
        e_cookie = __get_cookie(error_code);
        if (e_cookie == NULL) {
@@ -290,7 +297,10 @@ bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_appsvc_info_sync() failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_appsvc_info_sync() failed. alarm_id[%d], return_code[%d].", alarm_id, return_code);
-
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -325,6 +335,7 @@ bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id
 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code){
 
        GError *error = NULL;
 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code){
 
        GError *error = NULL;
+       int return_code = 0;
        char *e_cookie = NULL;
 
        e_cookie = __get_cookie(error_code);
        char *e_cookie = NULL;
 
        e_cookie = __get_cookie(error_code);
@@ -334,12 +345,15 @@ bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *
        }
 
        if (!alarm_manager_call_alarm_set_rtc_time_sync
        }
 
        if (!alarm_manager_call_alarm_set_rtc_time_sync
-           ((AlarmManager*)context.proxy, context.pid,
-               time->year, time->month, time->day,
-                time->hour, time->min, time->sec,
-                 e_cookie, NULL, NULL, &error)) {
+           ((AlarmManager*)context.proxy, context.pid, time->year, time->month, time->day,
+                time->hour, time->min, time->sec, e_cookie, &return_code, NULL, &error)) {
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_rtc_time() failed. return_code[%d]", return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -350,6 +364,13 @@ bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *
 
        g_free(e_cookie);
 
 
        g_free(e_cookie);
 
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
        return true;
 }
 
        return true;
 }
 
@@ -370,6 +391,10 @@ bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_sync() failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_sync() failed. alarm_id[%d], return_code[%d]", alarm_id, return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -407,6 +432,10 @@ bool _send_alarm_delete_all(alarm_context_t context, int *error_code)
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_all_sync() failed. return_code[%d]", return_code);
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_all_sync() failed. return_code[%d]", return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -434,7 +463,6 @@ bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
        GError *error = NULL;
        GVariant *alarm_array = NULL;
        int return_code = 0;
        GError *error = NULL;
        GVariant *alarm_array = NULL;
        int return_code = 0;
-       int i = 0;
 
        if (!alarm_manager_call_alarm_get_list_of_ids_sync((AlarmManager*)context.proxy,
                             context.pid, maxnum_of_ids, &alarm_array,
 
        if (!alarm_manager_call_alarm_get_list_of_ids_sync((AlarmManager*)context.proxy,
                             context.pid, maxnum_of_ids, &alarm_array,
@@ -442,7 +470,11 @@ bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
                /* g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
-               "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
+               "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. alarm_id[%d], return_code[%d]", alarm_id, return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -490,10 +522,11 @@ bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
        if (!alarm_manager_call_alarm_get_number_of_ids_sync((AlarmManager*)context.proxy, context.pid, e_cookie, num_of_ids, &return_code, NULL, &error)) {
                /* g_dbus_proxy_call_sync error */
                /* error_code should be set */
        if (!alarm_manager_call_alarm_get_number_of_ids_sync((AlarmManager*)context.proxy, context.pid, e_cookie, num_of_ids, &return_code, NULL, &error)) {
                /* g_dbus_proxy_call_sync error */
                /* error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "alarm_manager_call_alarm_get_number_of_ids_sync() failed by dbus. return_code[%d], return_code[%s].",
-               return_code, error->message);
-
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_number_of_ids_sync() failed by dbus. return_code[%d]", return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -535,7 +568,11 @@ bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
                /* g_dbus_proxy_call_sync error */
                /* error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
                /* g_dbus_proxy_call_sync error */
                /* error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
-               "alarm_manager_call_alarm_get_info_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
+               "alarm_manager_call_alarm_get_info_sync() failed by dbus. alarm_id[%d], return_code[%d]", alarm_id, return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -570,11 +607,15 @@ bool _send_alarm_get_next_duetime(alarm_context_t context,
        }
 
        if (!alarm_manager_call_alarm_get_next_duetime_sync((AlarmManager*)context.proxy,
        }
 
        if (!alarm_manager_call_alarm_get_next_duetime_sync((AlarmManager*)context.proxy,
-                            context.pid, alarm_id, e_cookie, duetime, &return_code, NULL, &error)) {
+                            context.pid, alarm_id, e_cookie, (gint *)duetime, &return_code, NULL, &error)) {
                /*g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
                /*g_dbus_proxy_call_sync error */
                /*error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
-               "alarm_manager_call_alarm_get_next_duetime_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
+               "alarm_manager_call_alarm_get_next_duetime_sync() failed by dbus. alarm_id[%d], return_code[%d]", alarm_id, return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -609,7 +650,11 @@ bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *err
        if (!alarm_manager_call_alarm_get_all_info_sync((AlarmManager*)context.proxy, context.pid, e_cookie, db_path, &return_code, NULL, &error)) {
                /*g_dbus_proxy_call_sync error */
                /*error_code should be set */
        if (!alarm_manager_call_alarm_get_all_info_sync((AlarmManager*)context.proxy, context.pid, e_cookie, db_path, &return_code, NULL, &error)) {
                /*g_dbus_proxy_call_sync error */
                /*error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_all_info_sync() failed by dbus. return_code[%d][%s]", return_code, error->message);
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_all_info_sync() failed by dbus. return_code[%d]", return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -637,7 +682,41 @@ bool _send_alarm_set_time(alarm_context_t context, int new_time, int *error_code
        if (!alarm_manager_call_alarm_set_time_sync((AlarmManager*)context.proxy, new_time, &return_code, NULL, &error)) {
                /*g_dbus_proxy_call_sync error */
                /*error_code should be set */
        if (!alarm_manager_call_alarm_set_time_sync((AlarmManager*)context.proxy, new_time, &return_code, NULL, &error)) {
                /*g_dbus_proxy_call_sync error */
                /*error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_time_sync() failed by dbus. return_code[%d][%s]", return_code, error->message);
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_time_sync() failed by dbus. return_code[%d]", return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               return false;
+       }
+
+       if (return_code != ALARMMGR_RESULT_SUCCESS) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+
+
+bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+
+       if (!alarm_manager_call_alarm_set_time_with_propagation_delay_sync((AlarmManager*)context.proxy, new_sec, new_nsec, req_sec, req_nsec, &return_code, NULL, &error)) {
+               /*g_dbus_proxy_call_sync error */
+               /*error_code should be set */
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_time_with_propagation_delay_sync() failed by dbus. return_code[%d]", return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
@@ -662,7 +741,11 @@ bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *er
        if (!alarm_manager_call_alarm_set_timezone_sync((AlarmManager*)context.proxy, tzpath_str, &return_code, NULL, &error)) {
                /*g_dbus_proxy_call_sync error */
                /*error_code should be set */
        if (!alarm_manager_call_alarm_set_timezone_sync((AlarmManager*)context.proxy, tzpath_str, &return_code, NULL, &error)) {
                /*g_dbus_proxy_call_sync error */
                /*error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_timezone_sync() failed by dbus. return_code[%d][%s]", return_code, error->message);
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_timezone_sync() failed by dbus. return_code[%d]", return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
                if (error_code) {
                        *error_code = ERR_ALARM_SYSTEM_FAIL;
                }
old mode 100755 (executable)
new mode 100644 (file)
index 5f92a13..5f8edc7
@@ -20,9 +20,6 @@
  *
  */
 
  *
  */
 
-
-
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -40,6 +37,8 @@
 #include <appsvc.h>
 #include <aul.h>
 #include <gio/gio.h>
 #include <appsvc.h>
 #include <aul.h>
 #include <gio/gio.h>
+#include <security-server.h>
+#include <pkgmgr-info.h>
 
 #define MAX_KEY_SIZE 256
 #define MAX_PROC_NAME_LEN 512
 
 #define MAX_KEY_SIZE 256
 #define MAX_PROC_NAME_LEN 512
@@ -90,6 +89,19 @@ static const GDBusInterfaceVTable interface_vtable =
        NULL
 };
 
        NULL
 };
 
+static int __bg_category_func(const char *name, void *user_data)
+{
+       bg_category_cb_info_t *info = (bg_category_cb_info_t *)user_data;
+       ALARM_MGR_LOG_PRINT("appid[%s], bg name = %s", info->appid, name);
+       if (name &&
+                       strncmp("enable", name, strlen(name)) && strncmp("disable", name, strlen(name))) {
+               info->has_bg = true;
+               return -1;
+       }
+
+       return 0;
+}
+
 static void __add_resultcb(alarm_id_t alarm_id, alarm_cb_t cb_func, void *data)
 {
        alarm_cb_info_t *info;
 static void __add_resultcb(alarm_id_t alarm_id, alarm_cb_t cb_func, void *data)
 {
        alarm_cb_info_t *info;
@@ -149,7 +161,7 @@ static void __handle_expiry_method_call(GDBusConnection *conn,
                 const gchar *method, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
 {
        if (method && strcmp(method, "alarm_expired") == 0) {
                 const gchar *method, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
 {
        if (method && strcmp(method, "alarm_expired") == 0) {
-               const gchar *package_name = NULL;
+               gchar *package_name = NULL;
                alarm_id_t alarm_id = 0;
                alarm_cb_info_t *info = NULL;
                g_variant_get(param, "(is)", &alarm_id, &package_name);
                alarm_id_t alarm_id = 0;
                alarm_cb_info_t *info = NULL;
                g_variant_get(param, "(is)", &alarm_id, &package_name);
@@ -237,6 +249,54 @@ static bool __alarm_validate_time(alarm_date_t *date, int *error_code)
        return true;
 }
 
        return true;
 }
 
+static bool __is_permitted(const char *app_id, int alarm_type)
+{
+       if (app_id == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("app_id is NULL. Only expicit launch is permitted\n");
+               return false;
+       }
+
+       pkgmgrinfo_appinfo_h handle = NULL;
+       int ret;
+       bool _return = false;
+
+       ret = pkgmgrinfo_appinfo_get_appinfo(app_id, &handle);
+       if (ret != PMINFO_R_OK) {
+               ALARM_MGR_EXCEPTION_PRINT("Failed to get appinfo [%s]\n", app_id);
+       } else {
+               char *app_type = NULL;
+               ret = pkgmgrinfo_appinfo_get_component_type(handle, &app_type);
+               if (app_type && strcmp("uiapp", app_type) == 0) {
+                       ALARM_MGR_LOG_PRINT("[%s] is ui application. It is allowed", app_id);
+                       _return = true;
+                       goto out;
+               } else if (app_type && strcmp("svcapp", app_type) == 0) {
+                       ALARM_MGR_LOG_PRINT("[%s] is service application.", app_id);
+
+                       bg_category_cb_info_t info = {
+                               .appid = app_id,
+                               .has_bg = false
+                       };
+
+                       if (alarm_type & ALARM_TYPE_INEXACT) {
+                               ret = pkgmgrinfo_appinfo_foreach_background_category(handle, __bg_category_func, &info);
+                               if (ret == PMINFO_R_OK && info.has_bg) {
+                                       ALARM_MGR_LOG_PRINT("[%s] has background categories.", app_id);
+                                       _return = true;
+                                       goto out;
+                               } else {
+                                       ALARM_MGR_EXCEPTION_PRINT("Failed to foreach background category. [%s] is not allowed\n", app_id);
+                               }
+                       }
+               }
+       }
+
+out :
+       if (handle)
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return _return;
+}
+
 static int __sub_init()
 {
        GError *error = NULL;
 static int __sub_init()
 {
        GError *error = NULL;
@@ -260,8 +320,11 @@ static int __sub_init()
 
        alarm_context.connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
        if (alarm_context.connection == NULL) {
 
        alarm_context.connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
        if (alarm_context.connection == NULL) {
-               ALARM_MGR_EXCEPTION_PRINT("g_bus_get_sync() is failed. error: %s", error->message);
-               g_error_free(error);
+               ALARM_MGR_EXCEPTION_PRINT("g_bus_get_sync() is failed.");
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                pthread_mutex_unlock(&init_lock);
                return ERR_ALARM_SYSTEM_FAIL;
        }
                pthread_mutex_unlock(&init_lock);
                return ERR_ALARM_SYSTEM_FAIL;
        }
@@ -293,7 +356,7 @@ static int __sub_init()
                return ERR_ALARM_SYSTEM_FAIL;
        }
        else {
                return ERR_ALARM_SYSTEM_FAIL;
        }
        else {
-               ret = read(fd, process_name, MAX_LEN);
+               ret = read(fd, process_name, MAX_LEN - 1);
                close(fd);
                if (ret < 0) {
                        ALARM_MGR_EXCEPTION_PRINT("Unable to read the proc file(%d).", getpid());
                close(fd);
                if (ret < 0) {
                        ALARM_MGR_EXCEPTION_PRINT("Unable to read the proc file(%d).", getpid());
@@ -324,7 +387,6 @@ static int __sub_init()
 EXPORT_API int alarmmgr_init(const char *appid)
 {
        SECURE_LOGD("Enter");
 EXPORT_API int alarmmgr_init(const char *appid)
 {
        SECURE_LOGD("Enter");
-       int request_name_result = 0;
        char service_name[MAX_SERVICE_NAME_LEN] = { 0 };
        char service_name_mod[MAX_SERVICE_NAME_LEN]= { 0 };
        int ret = ALARMMGR_RESULT_SUCCESS;
        char service_name[MAX_SERVICE_NAME_LEN] = { 0 };
        char service_name_mod[MAX_SERVICE_NAME_LEN]= { 0 };
        int ret = ALARMMGR_RESULT_SUCCESS;
@@ -551,9 +613,10 @@ EXPORT_API int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
        }
 
        alarm_info->mode.repeat = repeat;
        }
 
        alarm_info->mode.repeat = repeat;
-
-       if (repeat == ALARM_REPEAT_MODE_REPEAT
-           || repeat == ALARM_REPEAT_MODE_WEEKLY) {
+       if (repeat == ALARM_REPEAT_MODE_REPEAT || repeat == ALARM_REPEAT_MODE_WEEKLY) {
+               if (interval <= 0) {
+                       return ERR_ALARM_INVALID_PARAM;
+               }
                alarm_info->mode.u_interval.interval = interval;
        }
 
                alarm_info->mode.u_interval.interval = interval;
        }
 
@@ -611,26 +674,17 @@ EXPORT_API int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type)
 
 static int __alarmmgr_init_appsvc(void)
 {
 
 static int __alarmmgr_init_appsvc(void)
 {
-       int ret;
-
        if (b_initialized) {
        if (b_initialized) {
-               ALARM_MGR_EXCEPTION_PRINT("alarm was already initialized\n");
+               ALARM_MGR_EXCEPTION_PRINT("alarm was already initialized.");
                return ALARMMGR_RESULT_SUCCESS;
        }
                return ALARMMGR_RESULT_SUCCESS;
        }
-#if !GLIB_CHECK_VERSION(2,32,0)
-       g_thread_init(NULL);
-#endif
-
-       dbus_g_thread_init();
 
 
-       ret = __sub_init();
+       int ret = __sub_init();
        if (ret < 0)
                return ret;
 
        b_initialized = true;
        if (ret < 0)
                return ret;
 
        b_initialized = true;
-
        return ALARMMGR_RESULT_SUCCESS;
        return ALARMMGR_RESULT_SUCCESS;
-
 }
 
 EXPORT_API void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code){
 }
 
 EXPORT_API void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code){
@@ -742,6 +796,36 @@ EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, vo
                return ERR_ALARM_INVALID_PARAM;
        }
 
                return ERR_ALARM_INVALID_PARAM;
        }
 
+       // Checking api version
+       int ret;
+       int result = 0;
+       pkgmgrinfo_pkginfo_h pkginfo = NULL;
+       char pkgid[512] = {0, };
+       const char *api_version = "2.4";
+
+       if (aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid)) != AUL_R_OK) {
+               ALARM_MGR_EXCEPTION_PRINT("aul_app_get_pkgid_bypid() is failed. PID %d may not be app.", getpid());
+       } else {
+               ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkginfo);
+               if (ret != PMINFO_R_OK) {
+                       ALARM_MGR_EXCEPTION_PRINT("Failed to get pkginfo\n");
+               }
+               else {
+                       ret = pkgmgrinfo_pkginfo_check_api_version(pkginfo, api_version, &result);
+                       pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+                       if (ret) {
+                               ALARM_MGR_EXCEPTION_PRINT("Failed to check api version [%d]\n", ret);
+                               return ERR_ALARM_SYSTEM_FAIL;
+                       }
+               }
+       }
+
+       if (result >= 0 && //Since 2.4
+                       !__is_permitted(appid, alarm_info->alarm_type)) {
+               ALARM_MGR_EXCEPTION_PRINT("[%s] is not permitted \n", appid);
+               return ERR_ALARM_NOT_PERMITTED_APP;
+       }
+
        if (alarm_info == NULL || alarm_id == NULL) {
                ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
                return ERR_ALARM_INVALID_PARAM;
        if (alarm_info == NULL || alarm_id == NULL) {
                ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
                return ERR_ALARM_INVALID_PARAM;
@@ -888,7 +972,7 @@ EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
        struct tm duetime_tm;
        alarm_info_t alarm_info;
        const char *operation = NULL;
        struct tm duetime_tm;
        alarm_info_t alarm_info;
        const char *operation = NULL;
-       char *appid = NULL;
+       const char *appid = NULL;
 
        ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
 
 
        ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
 
@@ -932,6 +1016,41 @@ EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
        alarm_info.alarm_type = alarm_type;
        alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
 
        alarm_info.alarm_type = alarm_type;
        alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
 
+       // Checking api version
+       int ret;
+       int result = 0;
+       pkgmgrinfo_pkginfo_h pkginfo = NULL;
+       char pkgid[512] = {0, };
+       const char *api_version = "2.4";
+
+       if (aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid)) != AUL_R_OK) {
+               ALARM_MGR_EXCEPTION_PRINT("aul_app_get_pkgid_bypid() is failed. PID %d may not be app.", getpid());
+       } else {
+               ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkginfo);
+               if (ret != PMINFO_R_OK) {
+                       ALARM_MGR_EXCEPTION_PRINT("Failed to get pkginfo\n");
+               }
+               else {
+                       ret = pkgmgrinfo_pkginfo_check_api_version(pkginfo, api_version, &result);
+                       pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+                       if (ret) {
+                               ALARM_MGR_EXCEPTION_PRINT("Failed to check api version [%d]\n", ret);
+                               return ERR_ALARM_SYSTEM_FAIL;
+                       }
+               }
+       }
+
+       if (result < 0) {
+               if (alarm_info.alarm_type & ALARM_TYPE_INEXACT) {
+                       alarm_info.alarm_type ^= ALARM_TYPE_INEXACT;
+               }
+       } else { //Since 2.4
+               if (!__is_permitted(appid, alarm_info.alarm_type)) {
+                       ALARM_MGR_EXCEPTION_PRINT("[%s] is not permitted \n", appid);
+                       return ERR_ALARM_NOT_PERMITTED_APP;
+               }
+       }
+
        gettimeofday(&current_time, NULL);
 
        if (current_time.tv_usec > 500 * 1000)
        gettimeofday(&current_time, NULL);
 
        if (current_time.tv_usec > 500 * 1000)
@@ -960,6 +1079,10 @@ EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
        alarm_info.start.min = duetime_tm.tm_min;
        alarm_info.start.sec = duetime_tm.tm_sec;
 
        alarm_info.start.min = duetime_tm.tm_min;
        alarm_info.start.sec = duetime_tm.tm_sec;
 
+       if ((alarm_info.alarm_type & ALARM_TYPE_INEXACT) && interval < MIN_INEXACT_INTERVAL) {
+               interval = MIN_INEXACT_INTERVAL;
+       }
+
        if (interval <= 0) {
                alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
                alarm_info.mode.u_interval.interval = 0;
        if (interval <= 0) {
                alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
                alarm_info.mode.u_interval.interval = 0;
@@ -971,7 +1094,7 @@ EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
        ALARM_MGR_EXCEPTION_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
                trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
                alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
        ALARM_MGR_EXCEPTION_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
                trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
                alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
-               alarm_info.mode.repeat, alarm_info.mode.u_interval, alarm_info.alarm_type);
+               alarm_info.mode.repeat, alarm_info.mode.u_interval.interval, alarm_info.alarm_type);
 
        if (!_send_alarm_create_appsvc(alarm_context, &alarm_info, alarm_id, b, &error_code)) {
                return error_code;
 
        if (!_send_alarm_create_appsvc(alarm_context, &alarm_info, alarm_id, b, &error_code)) {
                return error_code;
@@ -1098,10 +1221,6 @@ EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
 EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
                                  time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id)
 {
 EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
                                  time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id)
 {
-       char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
-       char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
-       int i = 0;
-       int j = 0;
        int error_code = 0;
        struct timeval current_time;
        struct tm duetime_tm;
        int error_code = 0;
        struct timeval current_time;
        struct tm duetime_tm;
@@ -1185,7 +1304,6 @@ EXPORT_API int alarmmgr_remove_alarm(alarm_id_t alarm_id)
        int error_code;
        int ret;
        alarm_cb_info_t *info;
        int error_code;
        int ret;
        alarm_cb_info_t *info;
-       alarm_info_t alarm;
 
        ret = __sub_init();
        if (ret < 0)
 
        ret = __sub_init();
        if (ret < 0)
@@ -1264,11 +1382,12 @@ EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param)
        SECURE_LOGD("alarm_manager_call_alarm_get_number_of_ids_sync() is called");
        if (!alarm_manager_call_alarm_get_number_of_ids_sync(
            (AlarmManager*)alarm_context.proxy, alarm_context.pid, e_cookie, &maxnum_of_ids, &return_code, NULL, &error)) {
        SECURE_LOGD("alarm_manager_call_alarm_get_number_of_ids_sync() is called");
        if (!alarm_manager_call_alarm_get_number_of_ids_sync(
            (AlarmManager*)alarm_context.proxy, alarm_context.pid, e_cookie, &maxnum_of_ids, &return_code, NULL, &error)) {
-               /* dbus-glib error */
-               /* error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-                   "alarm_manager_call_alarm_get_number_of_ids_sync() is failed by dbus. return_code[%d], err message[%s]",
-                   return_code, error->message);
+               /* dbus error. error_code should be set */
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_number_of_ids_sync() is failed by dbus. return_code[%d]", return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message);
+                       g_error_free(error);
+               }
                g_free(e_cookie);
                return ERR_ALARM_SYSTEM_FAIL;
        }
                g_free(e_cookie);
                return ERR_ALARM_SYSTEM_FAIL;
        }
@@ -1285,10 +1404,13 @@ EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param)
        SECURE_LOGD("alarm_manager_call_alarm_get_list_of_ids_sync() is called");
        if (!alarm_manager_call_alarm_get_list_of_ids_sync(
                     (AlarmManager*)alarm_context.proxy, alarm_context.pid, maxnum_of_ids, &alarm_array, &num_of_ids, &return_code, NULL, &error)) {
        SECURE_LOGD("alarm_manager_call_alarm_get_list_of_ids_sync() is called");
        if (!alarm_manager_call_alarm_get_list_of_ids_sync(
                     (AlarmManager*)alarm_context.proxy, alarm_context.pid, maxnum_of_ids, &alarm_array, &num_of_ids, &return_code, NULL, &error)) {
-               /*dbus-glib error */
-               /* error_code should be set */
+               /* dbus error. error_code should be set */
                ALARM_MGR_EXCEPTION_PRINT(
                    "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. num_of_ids[%d], return_code[%d].", num_of_ids, return_code);
                ALARM_MGR_EXCEPTION_PRINT(
                    "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. num_of_ids[%d], return_code[%d].", num_of_ids, return_code);
+               if (error) {
+                       ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s.", error->message);
+                       g_error_free(error);
+               }
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
@@ -1296,11 +1418,6 @@ EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param)
                return return_code;
        }
 
                return return_code;
        }
 
-       if (error != NULL) {
-               ALARM_MGR_LOG_PRINT("Alarm server is not ready dbus. error message %s.", error->message);
-               return ERR_ALARM_SYSTEM_FAIL;
-       }
-
        if (alarm_array == NULL) {
                ALARM_MGR_LOG_PRINT("alarm server is not initilized.");
                return ERR_ALARM_SYSTEM_FAIL;
        if (alarm_array == NULL) {
                ALARM_MGR_LOG_PRINT("alarm server is not initilized.");
                return ERR_ALARM_SYSTEM_FAIL;
@@ -1538,13 +1655,14 @@ EXPORT_API int alarmmgr_add_reference_periodic_alarm_withcb(int interval,
 EXPORT_API int alarmmgr_set_systime(int new_time)
 {
        int error_code;
 EXPORT_API int alarmmgr_set_systime(int new_time)
 {
        int error_code;
-       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_set_systime() is called.");
+       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_set_systime(%d) is called.", new_time);
 
        if (__sub_init() < 0) {
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
        if (!_send_alarm_set_time(alarm_context, new_time, &error_code)) {
 
        if (__sub_init() < 0) {
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
        if (!_send_alarm_set_time(alarm_context, new_time, &error_code)) {
+               ALARM_MGR_EXCEPTION_PRINT("Failed to set time. error: %d", error_code);
                return error_code;
        }
 
                return error_code;
        }
 
@@ -1552,6 +1670,25 @@ EXPORT_API int alarmmgr_set_systime(int new_time)
        return ALARMMGR_RESULT_SUCCESS;
 }
 
        return ALARMMGR_RESULT_SUCCESS;
 }
 
+EXPORT_API int alarmmgr_set_systime_with_propagation_delay(struct timespec new_time, struct timespec req_time)
+{
+       int error_code;
+       ALARM_MGR_LOG_PRINT("[alarm-lib] New: %d(sec) %09d(nsec), Requested: %d(sec) %09d(nsec)",
+               new_time.tv_sec, new_time.tv_nsec, req_time.tv_sec, req_time.tv_nsec);
+
+       if (__sub_init() < 0) {
+               return ERR_ALARM_SYSTEM_FAIL;
+       }
+
+       if (!_send_alarm_set_time_with_propagation_delay(alarm_context, new_time.tv_sec, new_time.tv_nsec, req_time.tv_sec, req_time.tv_nsec, &error_code)) {
+               ALARM_MGR_EXCEPTION_PRINT("Failed to set time with propagation delay. error: %d", error_code);
+               return error_code;
+       }
+
+       ALARM_MGR_LOG_PRINT("[alarm-lib]: successfully set the time by pid(%d).", alarm_context.pid);
+       return ALARMMGR_RESULT_SUCCESS;
+}
+
 EXPORT_API int alarmmgr_set_timezone(char *tzpath_str)
 {
        int error_code;
 EXPORT_API int alarmmgr_set_timezone(char *tzpath_str)
 {
        int error_code;