tizen 2.3 release tizen_2.3 submit/tizen_2.3/20150202.061218 tizen_2.3_release
authorjk7744.park <jk7744.park@samsung.com>
Sun, 1 Feb 2015 04:33:15 +0000 (13:33 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Sun, 1 Feb 2015 04:33:15 +0000 (13:33 +0900)
27 files changed:
CMakeLists.txt [new file with mode: 0644]
Makefile.am [deleted file]
alarm-expire.xml [deleted file]
alarm-lib-stub.c [deleted file]
alarm-manager-registry.c
alarm-manager-schedule.c
alarm-manager-sync-scheduler.c [deleted file]
alarm-manager-timer.c
alarm-manager.c
alarm-server-mobile.manifest [deleted file]
alarm-server.manifest [moved from alarm-server-wearable.manifest with 62% similarity, mode: 0644]
alarm-server.rule [new file with mode: 0644]
alarm-service.pc.in
alarm_mgr.xml
alarmmgr_log_dump.sh [new file with mode: 0644]
autogen.sh [deleted file]
configure.ac [deleted file]
debian/control
include/alarm-internal.h [changed mode: 0755->0644]
include/alarm.h
packaging/alarm-manager.spec
packaging/alarm-server.service
src/CMakeLists.txt [new file with mode: 0755]
src/alarm-lib-stub.c [new file with mode: 0644]
src/alarm-lib.c [moved from alarm-lib.c with 66% similarity]
tool/CMakeLists.txt [new file with mode: 0644]
tool/alarmmgr_get_all_info.c [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2032a88
--- /dev/null
@@ -0,0 +1,61 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET (this_target alarm-server)
+SET (EXPORT_API "__attribute__ ((visibility(\"default\")))")
+
+ADD_DEFINITIONS("-DEXPORT_API=${EXPORT_API}")
+
+SET(CMAKE_EXECUTABLE_SUFFIX "")
+SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/output")
+
+INCLUDE_DIRECTORIES(
+       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")
+
+message("${DEPS_PKGS}")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED ${DEPS_PKGS})
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -Wall -Wno-unused")
+ENDFOREACH(flag)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(TEST_CFLAGS "${TEST_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET (${this_target}_SOURCE_FILES
+       alarm-manager-registry.c
+       alarm-manager-schedule.c
+       alarm-manager-timer.c
+       alarm-manager.c
+       )
+
+ADD_CUSTOM_COMMAND(
+        WORKING_DIRECTORY
+        OUTPUT alarm-mgr-stub.c
+        COMMAND gdbus-codegen --interface-prefix com.samsung.
+                               --generate-c-code alarm-mgr-stub
+                               ./alarm_mgr.xml
+        COMMENT "Generating Server GDBus .c/.h")
+
+ADD_EXECUTABLE (${this_target} ${${this_target}_SOURCE_FILES} alarm-mgr-stub.c)
+ADD_DEPENDENCIES(${this_target} alarm)
+
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS} -fpie")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_CFLAGS}")
+
+TARGET_LINK_LIBRARIES(${this_target} ${pkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(${this_target} "-lrt -lm -pie")
+TARGET_LINK_LIBRARIES(${this_target} alarm)
+
+ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(tool)
+
+INSTALL(TARGETS ${this_target} DESTINATION bin)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/alarmmgr_log_dump.sh DESTINATION /opt/etc/dump.d/module.d)
diff --git a/Makefile.am b/Makefile.am
deleted file mode 100644 (file)
index 63b18e4..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-ALARM_CFLAGS+=-DEXPORT_API="__attribute__ ((visibility(\"default\")))"
-AM_CFLAGS = $(ALARM_MANAGER_CFLAGS)
-
-lib_LTLIBRARIES = libalarm.la
-alarmincludedir = $(includedir)
-alarminclude_HEADERS = include/alarm.h
-
-libalarm_la_SOURCES =  \
-       alarm-lib.c \
-       alarm-lib-stub.c 
-libalarm_la_CPPFLAGS = $(ALARM_CFLAGS) $(ALARM_CPPFLAGS) $(ALARM_MANAGER_CFLAGS) $(ALARM_MANAGER_FEATURE_CFLAGS)\
-                     -I$(srcdir)/include 
-libalarm_la_LIBADD = $(ALARM_MANAGER_LIBS)
-
-bin_PROGRAMS=alarm-server
-alarm_server_SOURCES = \
-       alarm-manager-registry.c \
-       alarm-manager-schedule.c \
-       alarm-manager-timer.c \
-       alarm-manager.c \
-       alarm-manager-sync-scheduler.c
-
-alarm_server_CPPFLAGS = $(ALARM_CFLAGS) $(ALARM_CPPFLAGS) $(ALARM_MANAGER_SERVER_CFLAGS) $(ALARM_MANAGER_FEATURE_CFLAGS)\
-                     -I$(srcdir)/include 
-
-alarm_server_LDADD = $(ALARM_MANAGER_SERVER_LIBS) -lrt -lm
-
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = alarm-service.pc
-
diff --git a/alarm-expire.xml b/alarm-expire.xml
deleted file mode 100644 (file)
index 2521b88..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<node name="/com/samsung/alarm/client">
-  <interface name="com.samsung.alarm.client">
-    <method name="alarm_expired">
-      <arg type="i" name="alarm_id" direction="in" />
-    </method>
-  </interface>
-</node>
diff --git a/alarm-lib-stub.c b/alarm-lib-stub.c
deleted file mode 100755 (executable)
index a188e69..0000000
+++ /dev/null
@@ -1,652 +0,0 @@
-/*
- *  alarm-manager
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
- * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-
-#include<stdio.h>
-#include<stdlib.h>
-#include<errno.h>
-#include<sys/types.h>
-#include<string.h>
-#include<dbus/dbus.h>
-#include<glib.h>
-
-#include "alarm.h"
-#include "alarm-internal.h"
-#include "alarm-stub.h"
-#include "security-server.h"
-
-#define ALARM_SERVICE_NAME     "appframework.alarm"
-#define ALARM_OBJECT_PATH      "/appframework/alarm"
-#define ALARM_INTERFACE_NAME "appframework.alarm"
-
-
-bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
-                       alarm_id_t *alarm_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_delete(alarm_context_t context, alarm_id_t alarm_id,
-                       int *error_code);
-#ifdef __ALARM_BOOT
-bool _send_alarm_power_on(alarm_context_t context, bool on_off,
-                         int *error_code);
-bool _send_alarm_power_off(alarm_context_t context, int *error_code);
-bool _send_alarm_check_next_duetime(alarm_context_t context, int *error_code);
-#endif
-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);
-
-
-
-bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
-                       alarm_id_t *alarm_id, bundle *b,
-                       int *error_code)
-{
-       GError *error = NULL;
-       int return_code = 0;
-
-       char cookie[256] = {0,};
-       char *e_cookie = NULL;
-       int size = 0;
-       int retval = 0;
-
-       bundle_raw *b_data = NULL;
-       int datalen = 0;
-
-       size = security_server_get_cookie_size();
-       retval = security_server_request_cookie(cookie, size);
-
-       if (retval < 0) {
-               ALARM_MGR_EXCEPTION_PRINT(
-                       "security_server_request_cookie failed\n");
-               if (error_code)
-                       *error_code = -1;       /* TODO: Need to redefine error codes */
-               return false;
-       }
-
-       e_cookie = g_base64_encode((const guchar *)cookie, size);
-
-       if (NULL == e_cookie)
-       {
-               ALARM_MGR_EXCEPTION_PRINT(
-                       "g_base64_encode failed\n");
-               if (error_code)
-                       *error_code = -1;       /* TODO: Need to redefine error codes */
-               return false;
-       }
-
-       if (bundle_encode(b, &b_data, &datalen))
-       {
-               ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n");
-               if (error_code){
-                       *error_code = -1;       /* TODO: Need to redefine error codes*/
-               }
-               if (e_cookie)
-               {
-                       g_free(e_cookie);
-                       e_cookie = NULL;
-               }
-               return false;
-       }
-
-       if (!com_samsung_alarm_manager_alarm_create_appsvc(context.proxy, context.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,
-                                                   alarm_info->end.year,
-                                                   alarm_info->end.month,
-                                                   alarm_info->end.day,
-                                                   alarm_info->mode.u_interval.day_of_week,
-                                                   alarm_info->mode.repeat,
-                                                   alarm_info->alarm_type,
-                                                   alarm_info->reserved_info,
-                                                   (char *)b_data, e_cookie,
-                                                   alarm_id, &return_code,
-                                                   &error)) {
-               /* dbus-glib error */
-               /* error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_create()failed.alarm_id[%d], "
-               "return_code[%d]\n", alarm_id, return_code);
-               ALARM_MGR_EXCEPTION_PRINT("error->message is %s\n",
-                                         error->message);
-       }
-
-       if (e_cookie)
-       {
-               g_free(e_cookie);
-               e_cookie = NULL;
-       }
-
-       if (b_data)
-       {
-               free(b_data);
-               b_data = NULL;
-       }
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-
-       return true;
-}
-
-
-
-bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
-                       alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
-                       int *error_code)
-{
-       GError *error = NULL;
-       int return_code = 0;
-
-       char cookie[256];
-       char *e_cookie;
-       int size;
-       int retval;
-
-       /*TODO: Dbus bus name validation is must & will be added to avoid alarm-server crash*/
-       if (g_quark_to_string(context.quark_app_service_name) == NULL
-               && strlen(dst_service_name) == 4
-               && strncmp(dst_service_name, "null",4) == 0 ){
-                       ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
-               if (error_code)
-                       *error_code = ERR_ALARM_INVALID_PARAM;
-               return false;
-       }
-
-       size = security_server_get_cookie_size();
-       retval = security_server_request_cookie(cookie, size);
-
-       if (retval < 0) {
-               ALARM_MGR_EXCEPTION_PRINT(
-                       "security_server_request_cookie failed\n");
-               return false;
-       }
-
-       e_cookie = g_base64_encode((const guchar *)cookie, size);
-
-       if (!com_samsung_alarm_manager_alarm_create(context.proxy, context.pid,
-                       g_quark_to_string(context.quark_app_service_name),
-                       g_quark_to_string(context.quark_app_service_name_mod),
-                                                   alarm_info->start.year,
-                                                   alarm_info->start.month,
-                                                   alarm_info->start.day,
-                                                   alarm_info->start.hour,
-                                                   alarm_info->start.min,
-                                                   alarm_info->start.sec,
-                                                   alarm_info->end.year,
-                                                   alarm_info->end.month,
-                                                   alarm_info->end.day,
-                                                   alarm_info->mode.u_interval.day_of_week,
-                                                   alarm_info->mode.repeat,
-                                                   alarm_info->alarm_type,
-                                                   alarm_info->reserved_info,
-                                                   dst_service_name, dst_service_name_mod, e_cookie,
-                                                   alarm_id, &return_code,
-                                                   &error)) {
-               /* dbus-glib error */
-               /* error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_create()failed.alarm_id[%d], "
-               "return_code[%d]\n", alarm_id, return_code);
-               ALARM_MGR_EXCEPTION_PRINT("error->message is %s\n",
-                                         error->message);
-               if (error_code)
-                       *error_code = -1;       /* -1 means that system
-                                                  failed internally. */
-               return false;
-       }
-
-       g_free(e_cookie);
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-
-       return true;
-}
-bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
-{
-       GError *error = NULL;
-       int return_code = 0;
-
-       bundle *b = NULL;
-
-       char cookie[256] = {0,};
-       char *e_cookie = NULL;
-       int size = 0;
-       int retval = 0;
-
-       gchar *b_data = NULL;
-       int len = 0;
-
-       size = security_server_get_cookie_size();
-       retval = security_server_request_cookie(cookie, size);
-
-       if (retval < 0) {
-               ALARM_MGR_EXCEPTION_PRINT(
-                       "security_server_request_cookie failed\n");
-               if (error_code)
-                       *error_code = -1; /*TODO: define error*/
-               return NULL;
-       }
-
-       e_cookie = g_base64_encode((const guchar *)cookie, size);
-
-       if (NULL == e_cookie)
-       {
-               ALARM_MGR_EXCEPTION_PRINT(
-                       "g_base64_encode failed\n");
-               if (error_code)
-                       *error_code = -1; /*TODO: define error*/
-               return NULL;
-       }
-
-
-       if (!com_samsung_alarm_manager_alarm_get_appsvc_info
-           (context.proxy, context.pid, alarm_id, e_cookie, &b_data, &return_code, &error)) {
-               /* dbus-glib error */
-               /*error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_delete() failed. "
-                    "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
-               if (error_code)
-                       *error_code = ERR_ALARM_SYSTEM_FAIL; /*-1 means that system
-                                                               failed internally.*/
-               if (e_cookie)
-                       g_free(e_cookie);
-               if (b_data)
-                       g_free(b_data);
-
-               return NULL;
-       }
-
-       if (return_code != 0){
-               if (error_code)
-                       *error_code = return_code;
-       } else {
-               b = bundle_decode((bundle_raw *)b_data, len);
-       }
-
-       if (e_cookie)
-               g_free(e_cookie);
-       if (b_data)
-               g_free(b_data);
-
-       return b;
-}
-
-
-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 cookie[256] = {0,};
-       char *e_cookie = NULL;
-       int size = 0;
-       int retval = 0;
-
-       size = security_server_get_cookie_size();
-       retval = security_server_request_cookie(cookie, size);
-
-       if (retval < 0) {
-               ALARM_MGR_EXCEPTION_PRINT(
-                       "security_server_request_cookie failed\n");
-               if (error_code)
-                       *error_code = -1; /*TODO: define error*/
-               return false;
-       }
-
-       e_cookie = g_base64_encode((const guchar *)cookie, size);
-
-       if (NULL == e_cookie)
-       {
-               ALARM_MGR_EXCEPTION_PRINT(
-                       "g_base64_encode failed\n");
-               if (error_code)
-                       *error_code = -1; /*TODO: define error*/
-               return false;
-       }
-
-       if (!com_samsung_alarm_manager_alarm_set_rtc_time
-           (context.proxy, context.pid,
-               time->year, time->month, time->day,
-                time->hour, time->min, time->sec,
-                 e_cookie, &return_code, &error)) {
-               /* dbus-glib error */
-               /*error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_set_rtc_time() failed. "
-                    "return_code[%d]\n", return_code);
-               if (error_code)
-                       *error_code = ERR_ALARM_SYSTEM_FAIL; /*-1 means that system
-                                                               failed internally.*/
-               if (e_cookie)
-                       g_free(e_cookie);
-
-               return false;
-       }
-       if (e_cookie)
-       {
-               g_free(e_cookie);
-               e_cookie = NULL;
-       }
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-
-       return true;
-
-}
-
-bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id,
-                       int *error_code)
-{
-       GError *error = NULL;
-       int return_code = 0;
-
-       char cookie[256];
-       char *e_cookie;
-       int size;
-       int retval;
-
-       size = security_server_get_cookie_size();
-       retval = security_server_request_cookie(cookie, size);
-
-       if (retval < 0) {
-               ALARM_MGR_EXCEPTION_PRINT(
-                       "security_server_request_cookie failed\n");
-               return false;
-       }
-
-       e_cookie = g_base64_encode((const guchar *)cookie, size);
-
-       if (!com_samsung_alarm_manager_alarm_delete
-           (context.proxy, context.pid, alarm_id, e_cookie, &return_code,
-            &error)) {
-               /* dbus-glib error */
-               /*error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_delete() failed. "
-                    "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
-               if (error_code)
-                       *error_code = -1;       /*-1 means that system
-                                                       failed internally.*/
-
-               return false;
-       }
-
-       g_free(e_cookie);
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-
-       return true;
-
-}
-
-#ifdef __ALARM_BOOT
-bool _send_alarm_power_on(alarm_context_t context, bool on_off,
-                          int *error_code)
-{
-       GError *error = NULL;
-       int return_code = 0;
-
-       if (!com_samsung_alarm_manager_alarm_power_on
-           (context.proxy, context.pid, on_off, &return_code, &error)) {
-               /* dbus-glib error */
-               /* error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_power_on failed. "
-                    "return_code[%d]\n", return_code);
-               if (error_code)
-                       *error_code = -1;       /*-1 means that system
-                                                       failed internally*/
-               return false;
-       }
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-
-       return true;
-
-}
-
-bool _send_alarm_power_off(alarm_context_t context, int *error_code)
-{
-       GError *error = NULL;
-       int return_code = 0;
-
-       if (!com_samsung_alarm_manager_alarm_power_off(context.proxy,
-                               context.pid, &return_code, &error)) {
-               /* dbus-glib error */
-               /* error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_power_off failed. "
-                    "return_code[%d]\n", return_code);
-               if (error_code)
-                       *error_code = -1;       /*-1 means that system
-                                               failed internally.*/
-               return false;
-       }
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-
-       return true;
-
-}
-
-bool _send_alarm_check_next_duetime(alarm_context_t context, int *error_code)
-{
-       GError *error = NULL;
-       int return_code = 0;
-
-       if (!com_samsung_alarm_manager_alarm_check_next_duetime(context.proxy,
-                                       context.pid, &return_code, &error)) {
-               /*dbus-glib error */
-               /*error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_power_check_next_duetime's "
-               "return value is false. return_code[%d]\n", return_code);
-               if (error_code)
-                       *error_code = -1;       /*-1 means that system
-                                               failed internally*/
-               return false;
-       }
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-
-       return true;
-
-}
-
-#endif                         /* __ALARM_BOOT */
-
-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)
-{
-
-       GError *error = NULL;
-       GArray *alarm_array = NULL;
-       int return_code = 0;
-       int i = 0;
-
-       if (!com_samsung_alarm_manager_alarm_get_list_of_ids(context.proxy,
-                            context.pid, maxnum_of_ids, &alarm_array,
-                            num_of_ids, &return_code, &error)) {
-               /*dbus-glib error */
-               /*error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_get_list_of_ids() failed. "
-                    "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
-               if (error_code)
-                       *error_code = -1;       /*-1 means that system
-                                                       failed internally.*/
-
-               return false;
-       }
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       } else {
-               for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
-                       alarm_id[i] = g_array_index(alarm_array, alarm_id_t, i);
-                       ALARM_MGR_LOG_PRINT(" alarm_id(%d)\n", alarm_id[i]);
-               }
-
-               *num_of_ids = alarm_array->len;
-               g_array_free(alarm_array, true);
-       }
-
-       return true;
-}
-
-bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
-                                  int *error_code)
-{
-       GError *error = NULL;
-       gint return_code = 0;
-
-       if (!com_samsung_alarm_manager_alarm_get_number_of_ids(context.proxy,
-                            context.pid, num_of_ids, &return_code, &error)) {
-               /* dbus-glib error */
-               /* error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_get_number_of_ids() failed. "
-               "return_code[%d], return_code[%s]\n", \
-                       return_code, error->message);
-               if (error_code)
-                       *error_code = -1;       /*-1 means that system
-                                                       failed internally*/
-               return false;
-       }
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-
-       return true;
-
-}
-
-bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
-                         alarm_info_t *alarm_info, int *error_code)
-{
-       GError *error = NULL;
-       int return_code = 0;
-
-       if (!com_samsung_alarm_manager_alarm_get_info(context.proxy,
-                    context.pid, alarm_id, &alarm_info->start.year,
-                    &alarm_info->start.month, &alarm_info->start.day,
-                    &alarm_info->start.hour, &alarm_info->start.min,
-                    &alarm_info->start.sec, &alarm_info->end.year,
-                    &alarm_info->end.month, &alarm_info->end.day,
-                     &alarm_info->mode.u_interval.day_of_week,
-                     (gint *)&alarm_info->mode.repeat,
-                    &alarm_info->alarm_type, &alarm_info->reserved_info,
-                                                     &return_code, &error)) {
-               /*dbus-glib error */
-               /* error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_get_info() failed. "
-                    "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
-               if (error_code)
-                       *error_code = -1;       /*-1 means that system failed
-                                                               internally.*/
-               return false;
-       }
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-       return true;
-
-}
-
-bool _send_alarm_get_next_duetime(alarm_context_t context,
-                                alarm_id_t alarm_id, time_t* duetime,
-                                int *error_code)
-{
-       GError *error = NULL;
-       int return_code = 0;
-
-       if (!com_samsung_alarm_manager_alarm_get_next_duetime(context.proxy,
-                            context.pid, alarm_id, duetime, &return_code, &error)) {
-               /*dbus-glib error */
-               /*error_code should be set */
-               ALARM_MGR_EXCEPTION_PRINT(
-               "com_samsung_alarm_manager_alarm_get_next_duetime() failed. "
-                    "alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
-               if (error_code)
-                       *error_code = -1;       /*-1 means that system
-                                                       failed internally.*/
-
-               return false;
-       }
-
-       if (return_code != 0) {
-               if (error_code)
-                       *error_code = return_code;
-               return false;
-       }
-       return true;
-}
-
index 0a749f1..21c4c12 100644 (file)
@@ -20,9 +20,6 @@
  *
  */
 
-
-
-
 #include<stdio.h>
 #include<stdlib.h>
 #include<time.h>
 #include<string.h>
 #include<sys/types.h>
 
-#include<dbus/dbus.h>
 #include<glib.h>
 #include <db-util.h>
 #if !GLIB_CHECK_VERSION (2, 31, 0)
 #include <glib/gmacros.h>
-#else
 #endif
-
 #include"alarm.h"
 #include"alarm-internal.h"
 
 extern __alarm_server_context_t alarm_context;
 extern sqlite3 *alarmmgr_db;
 
-#ifdef __ALARM_BOOT
-extern bool enable_power_on_alarm;
-#endif
-
 bool _save_alarms(__alarm_info_t *__alarm_info);
 bool _update_alarms(__alarm_info_t *__alarm_info);
 bool _delete_alarms(alarm_id_t alarm_id);
-#ifdef __ALARM_BOOT
-bool _update_power_on(bool on_off);
-#endif
 bool _load_alarms_from_registry(void);
 
 bool _save_alarms(__alarm_info_t *__alarm_info)
@@ -70,15 +57,17 @@ bool _save_alarms(__alarm_info_t *__alarm_info)
        alarm_mode_t *mode = &alarm_info->mode;
 
        char *query = sqlite3_mprintf("insert into alarmmgr( alarm_id, start,\
-                       end, pid, app_unique_name, app_service_name, app_service_name_mod, bundle, year,\
+                       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,\
                        alarm_type, reserved_info, dst_service_name, dst_service_name_mod)\
-                       values (%d,%d,%d,%d,%Q,%Q,%Q,%Q,%d,%d,%d,%d,%d,%d,%d,%d,\
+                       values (%d,%d,%d,%d,%Q,%Q,%Q,%Q,%Q,%Q,%d,%d,%d,%d,%d,%d,%d,%d,\
                        %d,%d,%Q,%Q)",\
                        __alarm_info->alarm_id,
                        (int)__alarm_info->start,
                        (int)__alarm_info->end,
                        __alarm_info->pid,
+                       (char *)g_quark_to_string(__alarm_info->quark_caller_pkgid),
+                       (char *)g_quark_to_string(__alarm_info->quark_callee_pkgid),
                        (char *)g_quark_to_string(
                                __alarm_info->quark_app_unique_name),
                        (char *)g_quark_to_string(
@@ -102,11 +91,8 @@ bool _save_alarms(__alarm_info_t *__alarm_info)
                        (char *)g_quark_to_string(
                        __alarm_info->quark_dst_service_name_mod));
 
-       if (SQLITE_OK !=
-           sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
-               SECURE_LOGE(
-                   "Don't execute query = %s, error message = %s\n", query,
-                    error_message);
+       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);
                return false;
        }
@@ -124,7 +110,7 @@ bool _update_alarms(__alarm_info_t *__alarm_info)
        alarm_mode_t *mode = &alarm_info->mode;
 
        char *query = sqlite3_mprintf("update alarmmgr set start=%d, end=%d,\
-                       pid=%d, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\
+                       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,\
                        day_of_week=%d, repeat=%d, alarm_type=%d,\
                        reserved_info=%d, dst_service_name=%Q, dst_service_name_mod=%Q\
@@ -132,6 +118,8 @@ bool _update_alarms(__alarm_info_t *__alarm_info)
                        (int)__alarm_info->start,
                        (int)__alarm_info->end,
                        __alarm_info->pid,
+                       (char *)g_quark_to_string(__alarm_info->quark_caller_pkgid),
+                       (char *)g_quark_to_string(__alarm_info->quark_callee_pkgid),
                        (char *)g_quark_to_string(
                                __alarm_info->quark_app_unique_name),
                        (char *)g_quark_to_string(
@@ -156,11 +144,8 @@ bool _update_alarms(__alarm_info_t *__alarm_info)
                                __alarm_info->quark_dst_service_name_mod),
                        __alarm_info->alarm_id);
 
-       if (SQLITE_OK !=
-           sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
-               SECURE_LOGE(
-                   "Don't execute query = %s, error message = %s\n", query,
-                    error_message);
+       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);
                return false;
        }
@@ -174,11 +159,8 @@ bool _delete_alarms(alarm_id_t alarm_id)
        char *error_message = NULL;
        char *query = sqlite3_mprintf("delete from alarmmgr where alarm_id=%d", alarm_id);
 
-       if (SQLITE_OK !=
-           sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
-               SECURE_LOGE(
-                   "Don't execute query = %s, error message = %s\n", query,
-                    error_message);
+       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);
                return false;
        }
@@ -187,38 +169,6 @@ bool _delete_alarms(alarm_id_t alarm_id)
        return true;
 }
 
-#ifdef __ALARM_BOOT
-bool _update_power_on(bool on_off)
-{
-/*     GConfClient* pGCC;
-       char key[MAX_GCONF_PATH_LEN];
-       GError* error = NULL;
-       
-       g_type_init();
-       pGCC = gconf_client_get_default();
-
-       if(!pGCC)
-       {
-               ALARM_MGR_EXCEPTION_PRINT(" gconf get failed.. \n");
-               return false;
-       }
-
-       sprintf(key,"/Services/AlarmMgr/Auto_poweron"); 
-
-       
-       if(!gconf_client_set_bool(pGCC, key, on_off, &error))
-       {
-               ALARM_MGR_EXCEPTION_PRINT("set string has failed...\n");
-               return false;
-       }
-
-       gconf_client_suggest_sync(pGCC, NULL);
-       g_object_unref(pGCC);
-*/
-       return false;
-}
-#endif
-
 bool _load_alarms_from_registry()
 {
        int i = 0;
@@ -229,6 +179,8 @@ bool _load_alarms_from_registry()
        __alarm_info_t *__alarm_info = NULL;
        alarm_date_t *start = NULL;
        alarm_mode_t *mode = NULL;
+       char caller_pkgid[MAX_PKG_ID_LEN] = {0,};
+       char callee_pkgid[MAX_PKG_ID_LEN] = {0,};
        char app_unique_name[MAX_SERVICE_NAME_LEN] = {0,};
        char app_service_name[MAX_SERVICE_NAME_LEN] = {0,};
        char app_service_name_mod[MAX_SERVICE_NAME_LEN] = {0,};
@@ -236,64 +188,58 @@ bool _load_alarms_from_registry()
        char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = {0,};
        char bundle[MAX_BUNDLE_NAME_LEN] = {0,};
 
-#ifdef __ALARM_BOOT
-       /*sprintf(path, "/Services/AlarmMgr/Auto_poweron"); */
-
-       enable_power_on_alarm = 0;
-       /*gconf_client_get_bool(pGCC, path, NULL); */
-#endif
-
        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 error\n");
+       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("[alarm-server]:Malloc failed\n");
+               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;
 
-               memset(app_service_name, 0, MAX_SERVICE_NAME_LEN);
-               memset(app_service_name_mod, 0, MAX_SERVICE_NAME_LEN);
-               memset(dst_service_name, 0, MAX_SERVICE_NAME_LEN);
-               memset(dst_service_name_mod, 0, MAX_SERVICE_NAME_LEN);
-
                __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(app_unique_name, (const char *)sqlite3_column_text(stmt, 4),
+
+               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, 5),
+               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, 6),
+               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, 7),
-                       MAX_BUNDLE_NAME_LEN - 1);               
-               start->year = sqlite3_column_int(stmt, 8);
-               start->month = sqlite3_column_int(stmt, 9);
-               start->day = sqlite3_column_int(stmt, 10);
-               start->hour = sqlite3_column_int(stmt, 11);
-               start->min = sqlite3_column_int(stmt, 12);
-               start->sec = sqlite3_column_int(stmt, 13);
-               mode->u_interval.day_of_week = sqlite3_column_int(stmt, 14);
-               mode->repeat = sqlite3_column_int(stmt, 15);
-               alarm_info->alarm_type = sqlite3_column_int(stmt, 16);
-               alarm_info->reserved_info = sqlite3_column_int(stmt, 17);
-               strncpy(dst_service_name, (const char *)sqlite3_column_text(stmt, 18),
+               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, 19),
+               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 =
@@ -307,16 +253,15 @@ bool _load_alarms_from_registry()
                __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);
+               alarm_context.alarms = g_slist_append(alarm_context.alarms, __alarm_info);
        }
 
+
+       _alarm_schedule();
        if (SQLITE_OK != sqlite3_finalize(stmt)) {
-               ALARM_MGR_EXCEPTION_PRINT("error : sqlite3_finalize\n");
+               ALARM_MGR_EXCEPTION_PRINT("sqlite3_finalize() is failed.");
                return false;
        }
 
-       _alarm_schedule();
-
        return true;
 }
index 34475c8..2e3f5e6 100644 (file)
@@ -20,9 +20,6 @@
  *
  */
 
-
-
-
 #define _BSD_SOURCE            /*localtime_r requires */
 #include<stdio.h>
 #include<stdlib.h>
@@ -31,7 +28,6 @@
 #include<string.h>
 #include<sys/types.h>
 
-#include<dbus/dbus.h>
 #include<glib.h>
 
 #include"alarm.h"
 extern __alarm_server_context_t alarm_context;
 extern GSList *g_scheduled_alarm_list;
 
-#ifdef __ALARM_BOOT
-extern bool enable_power_on_alarm;
-#endif
-
-static void __free_scheduled_alarm(gpointer data, gpointer user_data);
 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_annually(__alarm_info_t *__alarm_info);
 static time_t __alarm_next_duetime_monthly(__alarm_info_t *__alarm_info);
 static time_t __alarm_next_duetime_weekly(__alarm_info_t *__alarm_info);
 static bool __find_next_alarm_to_be_scheduled(time_t *min_due_time);
-#ifdef __ALARM_BOOT
-/*alarm boot*/
-static bool __find_next_alarm_to_be_scheduled_power_on(time_t *min_due_time);
-bool _alarm_find_mintime_power_on(time_t *min_time);
-#endif
 bool _alarm_schedule(void);
 
-static void __free_scheduled_alarm(gpointer data, gpointer user_data)
-{
-       if (data != NULL) {
-               g_free(data);
-       }
-}
-
 bool _clear_scheduled_alarm_list()
 {
-
-       g_slist_foreach(g_scheduled_alarm_list, __free_scheduled_alarm, NULL);
-       g_slist_free(g_scheduled_alarm_list);
-
+       g_slist_free_full(g_scheduled_alarm_list, g_free);
        g_scheduled_alarm_list = NULL;
 
        return true;
@@ -91,9 +67,9 @@ bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info)
 /*
  *     20080328. Sewook Park(sewook7.park@samsung.com)
  *     When multiple alarms are expired at same time, dbus rpc call for alarm
- *     ui should be invoked first.(Ui conflicting manager cannot manage the 
- *     different kinds of alarm popups(wake up alarm/org alarm) correctly, 
- *     when they are displayed at same time)So when arranging the schedule 
+ *     ui should be invoked first.(Ui conflicting manager cannot manage the
+ *     different kinds of alarm popups(wake up alarm/org alarm) correctly,
+ *     when they are displayed at same time)So when arranging the schedule
  *     alarm list, wake up alarm element is located ahead.
  */
 
@@ -114,41 +90,30 @@ bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info)
        alarm->__alarm_info = __alarm_info;
 
        SECURE_LOGD("%s :alarm->pid =%d, app_service_name=%s(%u)\n",
-                           __FUNCTION__, alarm->pid,
-                       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);
-               return true;
-       } else {
-               for (iter = g_scheduled_alarm_list; iter != NULL;
-                    iter = g_slist_next(iter)) {
+                       __FUNCTION__, alarm->pid,
+                       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)) {
+                       if (entry->__alarm_info->quark_app_service_name != g_quark_from_string(WAKEUP_ALARM_APP_ID)) {
                                prior = true;
                                break;
                        }
                }
 
                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);
+                       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);
                }
        }
 
@@ -161,17 +126,14 @@ bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id)
        GSList *iter = NULL;
        __scheduled_alarm_t *alarm = NULL;
 
-       for (iter = g_scheduled_alarm_list; iter != NULL;
-            iter = g_slist_next(iter)) {
+       for (iter = g_scheduled_alarm_list; iter != NULL; iter = g_slist_next(iter)) {
                alarm = iter->data;
                if (alarm->alarm_id == alarm_id) {
-                       g_scheduled_alarm_list =
-                           g_slist_remove(g_scheduled_alarm_list, iter->data);
-                       /*g_free(iter->data); */
+                       g_scheduled_alarm_list = g_slist_remove(g_scheduled_alarm_list, iter->data);
+                       g_free(alarm);
                        result = true;
                        break;
                }
-
        }
 
        if (g_slist_length(g_scheduled_alarm_list) == 0) {
@@ -184,18 +146,25 @@ bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id)
 static time_t __alarm_next_duetime_once(__alarm_info_t *__alarm_info)
 {
        time_t due_time = 0;
+       time_t due_time_tmp = 0;
        time_t current_time = 0;
        struct tm duetime_tm;
+       struct tm tmp_tm;
+       int current_dst = 0;
 
        alarm_info_t *alarm_info = &__alarm_info->alarm_info;
        alarm_date_t *start = &alarm_info->start;
 
+       tzset();
        time(&current_time);
        localtime_r(&current_time, &duetime_tm);
        duetime_tm.tm_hour = start->hour;
        duetime_tm.tm_min = start->min;
        duetime_tm.tm_sec = start->sec;
 
+       current_dst = duetime_tm.tm_isdst;
+       duetime_tm.tm_isdst = -1;
+
        if (start->year == 0 && start->month == 0 && start->day == 0)
                /*any date */  {
                due_time = mktime(&duetime_tm);
@@ -209,8 +178,33 @@ static time_t __alarm_next_duetime_once(__alarm_info_t *__alarm_info)
                due_time = mktime(&duetime_tm);
        }
 
-       return due_time;
+       if (due_time <= current_time) {
+               ALARM_MGR_EXCEPTION_PRINT("duetime is less than or equal to current time. current_dst = %d", current_dst);
+               duetime_tm.tm_isdst = 0;        // DST off
 
+               due_time_tmp = mktime(&duetime_tm);
+               localtime_r(&due_time_tmp, &tmp_tm);
+
+               ALARM_MGR_LOG_PRINT("%d:%d:%d. duetime = %d", tmp_tm.tm_hour, tmp_tm.tm_min, tmp_tm.tm_sec, due_time);
+               if (tmp_tm.tm_hour == start->hour && tmp_tm.tm_min == start->min && tmp_tm.tm_sec == start->sec ) {
+                       due_time = due_time_tmp;
+                       ALARM_MGR_EXCEPTION_PRINT("due_time = %d",due_time);
+               }
+       }
+       else {
+               localtime_r(&due_time, &tmp_tm);
+               ALARM_MGR_LOG_PRINT("%d:%d:%d. current_dst = %d, duetime_dst = %d", tmp_tm.tm_hour, tmp_tm.tm_min, tmp_tm.tm_sec, current_dst, tmp_tm.tm_isdst);
+
+               if (current_dst == 1 && tmp_tm.tm_isdst == 1 && tmp_tm.tm_hour == start->hour + 1) {
+                       // When the calculated duetime is forwarded 1hour due to DST, Adds 23hours.
+                       due_time += 60 * 60 * 23;
+                       localtime_r(&due_time, &duetime_tm);
+                       ALARM_MGR_EXCEPTION_PRINT("due_time = %d",due_time);
+               }
+       }
+
+       ALARM_MGR_EXCEPTION_PRINT("Final due_time = %d, %s",due_time, ctime(&due_time));
+       return due_time;
 }
 
 static time_t __alarm_next_duetime_repeat(__alarm_info_t *__alarm_info)
@@ -336,12 +330,14 @@ static time_t __alarm_next_duetime_weekly(__alarm_info_t *__alarm_info)
        struct tm tmp_tm;
        int wday;
        int current_dst = 0;
+       struct tm before_tm;
+       struct tm after_tm;
 
        alarm_info_t *alarm_info = &__alarm_info->alarm_info;
        alarm_date_t *start = &alarm_info->start;
-
        alarm_mode_t *mode = &alarm_info->mode;
 
+       tzset();
        time(&current_time);
        localtime_r(&current_time, &duetime_tm);
        wday = duetime_tm.tm_wday;
@@ -349,46 +345,62 @@ static time_t __alarm_next_duetime_weekly(__alarm_info_t *__alarm_info)
        duetime_tm.tm_min = start->min;
        duetime_tm.tm_sec = start->sec;
        current_dst = duetime_tm.tm_isdst;
+
        duetime_tm.tm_isdst = -1;
 
        if (__alarm_info->start != 0) {
-
-               if (__alarm_info->start >= current_time)        /*case 1*/ {
+               if (__alarm_info->start >= current_time)        {
                        duetime_tm.tm_year = start->year - 1900;
                        duetime_tm.tm_mon = start->month - 1;
                        duetime_tm.tm_mday = start->day;
-               } else  /*case 3*/ {
-                       /*don't need to be set */
                }
        }
-       /*case 4 */
 
        due_time = mktime(&duetime_tm);
+       localtime_r(&due_time, &tmp_tm);
+       ALARM_MGR_EXCEPTION_PRINT("%d:%d:%d. duetime = %d, isdst = %d", tmp_tm.tm_hour, tmp_tm.tm_min, tmp_tm.tm_sec, due_time, tmp_tm.tm_isdst);
 
-       if( current_dst == 1 && due_time < current_time) {
+       if (due_time <= current_time) {
+               ALARM_MGR_EXCEPTION_PRINT("duetime is less than or equal to current time. current_dst = %d", current_dst);
                duetime_tm.tm_isdst = 0;
+
                due_time = mktime(&duetime_tm);
                localtime_r(&due_time, &tmp_tm);
-               SECURE_LOGD("%d %d %d : %d", tmp_tm.tm_hour, tmp_tm.tm_min, tmp_tm.tm_sec, due_time);
-               if( tmp_tm.tm_hour != start->hour || tmp_tm.tm_min != start->min || tmp_tm.tm_sec != start->sec ) {
+
+               SECURE_LOGD("%d:%d:%d. duetime = %d", tmp_tm.tm_hour, tmp_tm.tm_min, tmp_tm.tm_sec, due_time);
+               if (tmp_tm.tm_hour != start->hour || tmp_tm.tm_min != start->min || tmp_tm.tm_sec != start->sec ) {
                        duetime_tm.tm_hour = start->hour;
                        duetime_tm.tm_min = start->min;
                        duetime_tm.tm_sec = start->sec;
                        duetime_tm.tm_isdst = -1;
                        due_time = mktime(&duetime_tm);
-                       SECURE_LOGD("%d",due_time); 
+                       ALARM_MGR_EXCEPTION_PRINT("due_time = %d",due_time);
                }
        }
+       else {
+               if (current_dst == 1 && tmp_tm.tm_isdst == 1 && tmp_tm.tm_hour == start->hour + 1) {
+                       // When the calculated duetime is forwarded 1hour due to DST, Adds 23hours.
+                       due_time += 60 * 60 * 23;
+                       localtime_r(&due_time, &duetime_tm);
+                       ALARM_MGR_EXCEPTION_PRINT("due_time = %d",due_time);
+               }
+       }
+
+       // Gets the dst before calculating the duedate as interval
+       localtime_r(&due_time, &before_tm);
+       SECURE_LOGD("before_dst = %d", before_tm.tm_isdst);
+
        wday = duetime_tm.tm_wday;
-       SECURE_LOGD("current_time(%d) due_time(%d)", current_time, due_time);
 
-       /* CQ defect(72810) : only one time alarm function is not working 
+       ALARM_MGR_EXCEPTION_PRINT("current_time(%d) due_time(%d)", current_time, due_time);
+
+       /* CQ defect(72810) : only one time alarm function is not working
           under all recurrence_disabled. */
-       if (due_time > current_time && mode->u_interval.day_of_week == 0)
+       if (due_time > current_time && mode->u_interval.day_of_week == 0) {
                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)) {
                int day = wday + 1;
                int interval = 1;
                /*this week */
@@ -397,22 +409,32 @@ static time_t __alarm_next_duetime_weekly(__alarm_info_t *__alarm_info)
                        day = 0;
                }
 
-               while (!(mode->u_interval.day_of_week & 1 << day)
-                      && interval < 8) {
+               while (!(mode->u_interval.day_of_week & 1 << day) && interval < 8) {
                        day += 1;
                        interval += 1;
 
                        if (day == 7) {
                                day = 0;
                        }
-
                }
+
                ALARM_MGR_LOG_PRINT("interval : %d\n", interval);
                due_time += 60 * 60 * 24 * interval;
        }
 
-       return due_time;
+       // Gets the dst after calculating the duedate as interval
+       localtime_r(&due_time, &after_tm);
+       SECURE_LOGD("after_dst = %d", after_tm.tm_isdst);
+
+       // Revise the duetime as difference in tm_isdst
+       if (before_tm.tm_isdst == 1 && after_tm.tm_isdst == 0) {
+               due_time += 60 * 60;    // Add an hour
+       } else if (before_tm.tm_isdst == 0 && after_tm.tm_isdst == 1) {
+               due_time -= 60 * 60;    // Subtract an hour
+       }
 
+       ALARM_MGR_EXCEPTION_PRINT("Final due_time = %d", due_time);
+       return due_time;
 }
 
 time_t _alarm_next_duetime(__alarm_info_t *__alarm_info)
@@ -449,7 +471,7 @@ time_t _alarm_next_duetime(__alarm_info_t *__alarm_info)
                return 0;
        }
 
-       if (mode->repeat != ALARM_REPEAT_MODE_WEEKLY) {
+       if (mode->repeat != ALARM_REPEAT_MODE_WEEKLY && mode->repeat != ALARM_REPEAT_MODE_ONCE) {
                due_tm = localtime(&due_time);
                if (is_dst==0 && due_tm->tm_isdst==1){
                                ALARM_MGR_LOG_PRINT("DST alarm found, enable\n");
@@ -458,10 +480,10 @@ time_t _alarm_next_duetime(__alarm_info_t *__alarm_info)
                                ALARM_MGR_LOG_PRINT("DST alarm found. disable\n");
                                due_tm->tm_hour = due_tm->tm_hour + DST_TIME_DIFF;
                }
-               due_time = mktime(due_tm);
+               due_time = mktime(due_tm);
        }
 
-       ALARM_MGR_LOG_PRINT("due_time %d\n", 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");
@@ -471,7 +493,6 @@ time_t _alarm_next_duetime(__alarm_info_t *__alarm_info)
        __alarm_info->due_time = due_time;
 
        return due_time;
-
 }
 
 static bool __find_next_alarm_to_be_scheduled(time_t *min_due_time)
@@ -493,89 +514,14 @@ static bool __find_next_alarm_to_be_scheduled(time_t *min_due_time)
 
                SECURE_LOGD("alarm[%d] with duetime(%u) at current(%u) pid: (%d)\n",
                        entry->alarm_id, due_time, current_time, entry->pid);
-               if (due_time == 0)      /*0 means this alarm 
-                       has been disabled*/ {
-                       continue;
-               }
-
-               interval = difftime(due_time, current_time);
-
-               if (interval <= 0)      /*2008.08.06 when the alarm expires, 
-                       it may makes an error.*/ {
-                       ALARM_MGR_LOG_PRINT("this may be error.. alarm[%d]\n",
-                                           entry->alarm_id);
-                       continue;
-               }
-
-               interval = difftime(due_time, min_time);
-
-               if ((interval < 0) || min_time == -1) {
-                       min_time = due_time;
-               }
-
-       }
-
-       *min_due_time = min_time;
-       return true;
-}
-
-#ifdef __ALARM_BOOT
-/*alarm boot*/
-static bool __find_next_alarm_to_be_scheduled_power_on(time_t *min_due_time)
-{
-       time_t current_time;
-       time_t min_time = -1;
-       time_t due_time;
-       struct tm duetime_tm;
-       __alarm_info_t *entry = NULL;
-       struct tm *temp_info;
-       GSList *iter = NULL;
-
-       time(&current_time);
-
-       tzset();                /*for portability tzset() need to be called
-                               before locatime_r,refer manpage localtime_r*/
-       temp_info = localtime_r(&current_time, &duetime_tm);
-
-       if (temp_info != NULL)
-               ALARM_MGR_LOG_PRINT
-                   ("__find_next_alarm_to_be_scheduled_power_on "
-                    ": %d %d %d %d %d\n", temp_info->tm_year,
-                    temp_info->tm_mon, temp_info->tm_mday, temp_info->tm_hour,
-                    temp_info->tm_min);
-
-       for (iter = alarm_context.alarms; iter != NULL;
-            iter = g_slist_next(iter)) {
-               entry = iter->data;
-               due_time = entry->due_time;
-
-               double interval = 0;
-
-               SECURE_LOGD("%s\n", g_quark_to_string(
-                       entry->quark_dst_service_name));
-
-               /*if(entry->quark_dst_service_name  != g_quark_from_string
-                  (WAKEUP_ALARM_APP_ID)) continue; */
-
-               if (strcmp
-                   (g_quark_to_string(entry->quark_dst_service_name),
-                    WAKEUP_ALARM_APP_ID) != 0)
-                       continue;
-
-               ALARM_MGR_LOG_PRINT(
-                   "alarm[%d] with duetime(%u) at current(%u)\n",
-                    entry->alarm_id, due_time, current_time);
-               if (due_time == 0)      /* 0 means this alarm has 
-                       been disabled*/ {
+               if (due_time == 0)      /*0 means this alarm has been disabled*/ {
                        continue;
                }
 
                interval = difftime(due_time, current_time);
 
-               if (interval <= 0)      /*2008.08.06 when the alarm expires, 
-               it may makes an error.*/ {
-                       ALARM_MGR_LOG_PRINT("this may be error.. alarm[%d]\n",
-                                           entry->alarm_id);
+               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;
                }
 
@@ -590,60 +536,29 @@ static bool __find_next_alarm_to_be_scheduled_power_on(time_t *min_due_time)
        *min_due_time = min_time;
        return true;
 }
-#endif
 
 bool _alarm_schedule()
 {
-       time_t current_time;
-       time_t due_time;
-       time_t min_time;
-       GSList *iter;
+       time_t due_time = 0;
+       time_t min_time = 0;
+       GSList *iter = NULL;
        __alarm_info_t *entry = NULL;
 
-       int min = -1;
-
-       time(&current_time);
-
-       min_time = 0;
-
        __find_next_alarm_to_be_scheduled(&min_time);
 
        if (min_time == -1) {
-               ALARM_MGR_LOG_PRINT("[alarm-server][schedule]: There is no "
-                                   "alarm to be scheduled..\n");
+               ALARM_MGR_LOG_PRINT("[alarm-server][schedule]: There is no alarm to be scheduled.");
        } else {
-               for (iter = alarm_context.alarms; iter != NULL;
-                    iter = g_slist_next(iter)) {
+               for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
                        entry = iter->data;
                        due_time = entry->due_time;
 
                        if (due_time == min_time) {
                                _add_to_scheduled_alarm_list(entry);
                        }
-
-       }
-
-               _alarm_set_timer(&alarm_context, alarm_context.timer, min_time,
-                                min);
-
-       }
-
-       return true;
-}
-
-#ifdef __ALARM_BOOT
-/*alarm boot*/
-bool _alarm_find_mintime_power_on(time_t *min_time)
-{
-
-       __find_next_alarm_to_be_scheduled_power_on(min_time);
-
-       if ((*min_time) == -1) {
-               ALARM_MGR_LOG_PRINT("[alarm-server][schedule]: There is no "
-                                   "alarm boot to be scheduled..\n");
-               return false;
+               }
+               _alarm_set_timer(&alarm_context, alarm_context.timer, min_time);
        }
 
        return true;
 }
-#endif
diff --git a/alarm-manager-sync-scheduler.c b/alarm-manager-sync-scheduler.c
deleted file mode 100644 (file)
index aea0af7..0000000
+++ /dev/null
@@ -1,448 +0,0 @@
-
-// Power savings by syncronizing start points of periodic network activitiy
-// frequently triggered by applications during sleep and/or active state.
-//
-
-#include <math.h>
-#include <aul.h>
-#include"alarm-internal.h"
-
-static bool g_white_list = true;
-static bool g_white_list_plus_auto_add = false;
-static bool g_app_sync_on = false;
-
-#define SYNC_COPRIME_VALUE     60 // [s] 1 min
-#define SYNC_MIN_VALUE                 (5*60)  // [s] 5 min
-#define SYNC_MAX_VALUE         (4*60*60)  // [s] 4 hr
-#define INTERVAL_HOUR  (60*60)
-#define INTERVAL_HALF_DAY      (12*60*60)
-
-#define MAX_INT_VALUE  2147483647
-#define APP_SYNC_LOG   1
-
-#define CSC_BUFFER_SIZE 256
-
-// [ms] global unit interval; Greatest Common Divisor of RepeatIntervals interested
-static int g_interval_gcd = SYNC_MAX_VALUE;
-
-static GSList* g_adjustable_repeating_alarms = NULL;
-static GSList* g_target_packages = NULL;
-//static GSList* g_csc_packages = NULL;
-
-static int __gcd(int first_value, int second_value)
-{
-       if (second_value == 0)
-               return first_value;
-       else
-               return __gcd(second_value, first_value % second_value);
-}
-
-void __convert_time_to_alarm_date_t(time_t time, alarm_date_t* alarm_date)
-{
-       struct tm time_tm;
-       localtime_r(&time, &time_tm);
-
-       alarm_date->year = time_tm.tm_year + 1900;
-       alarm_date->month = time_tm.tm_mon + 1;
-       alarm_date->day = time_tm.tm_mday;
-       alarm_date->hour = time_tm.tm_hour;
-       alarm_date->min = time_tm.tm_min;
-       alarm_date->sec = time_tm.tm_sec;
-}
-
-void __convert_alarm_date_t_to_time(alarm_date_t* alarm_date, time_t* time)
-{
-       struct tm alarm_tm = {0, };
-
-       alarm_tm.tm_year = alarm_date->year - 1900;
-       alarm_tm.tm_mon = alarm_date->month - 1;
-       alarm_tm.tm_mday = alarm_date->day;
-
-       alarm_tm.tm_hour = alarm_date->hour;
-       alarm_tm.tm_min = alarm_date->min;
-       alarm_tm.tm_sec = alarm_date->sec;
-
-       *time = mktime(&alarm_tm);
-}
-
-static int __compare_func(const char* a, const char* b)
-{
-       if (0 == g_strcmp0(a, b)) {
-               return 0;
-       }
-
-       return 1;
-}
-
-static bool __sync_scheduler_look_for_non_adjustable_alarm(GSList* alarmList, __alarm_info_t* __alarm_info)
-{
-// ±âÁ¸ alarm ¸®½ºÆ®¿¡¼­ µ¿ÀÏÇÑ alarm ÀÇ  original alarm ½Ã°£ÀÌ ÇöÀç ¿äû½Ã°£°ú °°À¸¸é return ture;
-
-       GSList *gs_iter = NULL;
-       __alarm_info_t *entry = NULL;
-
-       for (gs_iter = alarmList; gs_iter != NULL;
-                gs_iter = g_slist_next(gs_iter)) {
-
-               entry = gs_iter->data;
-
-               if (__alarm_info->start == entry->start) {
-                       if (!g_strcmp0(g_quark_to_string(__alarm_info->quark_app_unique_name), g_quark_to_string(entry->quark_app_unique_name)) &&
-                               !g_strcmp0(g_quark_to_string(__alarm_info->quark_app_service_name), g_quark_to_string(entry->quark_app_service_name)) &&
-                               !g_strcmp0(g_quark_to_string(__alarm_info->quark_dst_service_name), g_quark_to_string(entry->quark_dst_service_name)) &&
-                               !g_strcmp0(g_quark_to_string(__alarm_info->quark_bundle), g_quark_to_string(entry->quark_bundle))) {
-                               ALARM_MGR_LOG_PRINT("This is non adjustable alarm");
-                               return true;
-                       }
-               }
-       }
-
-       return false;
-}
-
-static int __sync_scheduler_calculate_gcd_of_repeat_intervals(int interval_old, int interval_new)
-{
-       int new_interval_gcd = interval_old;
-       int temp_interval_gcd = __gcd(interval_old, interval_new);
-
-       if (temp_interval_gcd > SYNC_COPRIME_VALUE) {
-               if ((temp_interval_gcd % SYNC_MIN_VALUE) == 0) {
-                       new_interval_gcd = temp_interval_gcd;
-               }
-       }
-
-       return new_interval_gcd;
-}
-
-// list Áß¿¡¼­ interval ÀÌ °°Àº °¡Àå  ÃÖ½ÅÀÇ alarm À» ¸®ÅÏ , °°Àº °ÍÀÌ ¾øÀ¸¸é ¹è¼ö interval À» °¡Áø alarm ÀÌ ¸®ÅÏ
-static __alarm_info_t* __sync_scheduler_time_to_next_repeating_alarm(int interval)
-{
-       int next_alarm = MAX_INT_VALUE;
-       int next_alarm_with_same_interval = MAX_INT_VALUE;
-       __alarm_info_t* alarm_result = NULL;
-       __alarm_info_t* alarm_result_with_same_interval = NULL;
-       GSList *gs_iter = NULL;
-       __alarm_info_t *entry = NULL;
-
-       bool is_int_same_as_gcd = (interval == g_interval_gcd);
-       time_t now_rtc;
-       time(&now_rtc);
-
-       for (gs_iter = g_adjustable_repeating_alarms; gs_iter != NULL;
-                gs_iter = g_slist_next(gs_iter)) {
-               time_t when = 0;
-               entry = gs_iter->data;
-
-               __convert_alarm_date_t_to_time(&entry->alarm_info.start, &when);
-
-               if (now_rtc < (when + g_interval_gcd)) {        // Accept ealier time of one GCD interval
-                       // Look for the alarm with same interval as GCD
-                       if (is_int_same_as_gcd) {
-                               if (when < next_alarm) {
-                                       next_alarm = when;
-                                       alarm_result = entry;
-                               }
-                       }
-                       // Look for the alarm with same interval or multiples of interval
-                       else {
-                               if (entry->alarm_info.mode.u_interval.interval != 0) {
-                                       if (entry->alarm_info.mode.u_interval.interval == interval) {
-                                               if (when < next_alarm_with_same_interval) {
-                                                       next_alarm_with_same_interval = when;
-                                                       alarm_result_with_same_interval = entry;
-                                               }
-                                       }
-                                       else if (((entry->alarm_info.mode.u_interval.interval > interval) && (entry->alarm_info.mode.u_interval.interval % interval == 0)) ||
-                                                        ((entry->alarm_info.mode.u_interval.interval < interval) && (interval % entry->alarm_info.mode.u_interval.interval == 0))) {
-                                               if (when < next_alarm) {
-                                                       next_alarm = when;
-                                                       alarm_result = entry;
-                                               }
-                                       }
-                               }
-                       }
-               }
-               else {
-                       // Old alarms eventually left must be removed.
-                       if ((when + INTERVAL_HALF_DAY) < now_rtc) {
-                               g_adjustable_repeating_alarms =
-                                       g_slist_remove(g_adjustable_repeating_alarms, gs_iter->data);
-                       }
-               }
-
-       }
-
-
-       // Next alarm with same interval value goes first.
-       if (alarm_result_with_same_interval != NULL)
-               alarm_result = alarm_result_with_same_interval;
-
-       return alarm_result;
-
-}
-
-//inputDistance = gcd or alarm's repeated interval
-static void __sync_scheduler_adjust_alarm_time(__alarm_info_t* __alarm_info, int input_distance)
-{
-       int next_alarm_when = MAX_INT_VALUE;
-       int distance = input_distance;
-       time_t new_time;
-
-       // Retreve the nearest alarm with same RepeatInterval or multiples of RepeatInterval
-       if (__alarm_info->alarm_info.mode.u_interval.interval != g_interval_gcd) {
-               __alarm_info_t* a = __sync_scheduler_time_to_next_repeating_alarm(__alarm_info->alarm_info.mode.u_interval.interval);
-               if (a != NULL) {
-                       __convert_alarm_date_t_to_time(&a->alarm_info.start, (time_t*)&next_alarm_when);
-                       // Same RepeatInterval or co-prime RepeatInterval with GCD
-                       if ((a->alarm_info.mode.u_interval.interval == __alarm_info->alarm_info.mode.u_interval.interval) ||
-                               (__alarm_info->alarm_info.mode.u_interval.interval % g_interval_gcd != 0)) {
-                               distance = __alarm_info->alarm_info.mode.u_interval.interval;
-                       }
-                       // Multiples of RepeatInterval
-                       else {
-                               distance = __gcd(__alarm_info->alarm_info.mode.u_interval.interval, a->alarm_info.mode.u_interval.interval);
-                       }
-               }
-       }
-       // Retreve the nearest alarm using GCD based RepeatInterval
-       if (next_alarm_when == MAX_INT_VALUE) {
-               __alarm_info_t* a = __sync_scheduler_time_to_next_repeating_alarm(g_interval_gcd);
-               if (a != NULL) {
-                       __convert_alarm_date_t_to_time(&a->alarm_info.start, (time_t*)&next_alarm_when);
-               }
-       }
-
-       if (next_alarm_when != MAX_INT_VALUE) {
-               ALARM_MGR_LOG_PRINT("next: %d", next_alarm_when);
-
-               // If the requested alarm is after the very next alarm to be triggered,
-               // place it somewhere aligned with the point that is one of multiples of
-               // requested distance and nearest to the very next alarm.
-               if (next_alarm_when <= __alarm_info->start) {
-                       int count = (__alarm_info->start - next_alarm_when) / distance;
-                       new_time = next_alarm_when + distance * count;
-               }
-               // If the requested alarm is before the very next alarm to be triggered,
-               // find the earlier aligned point around the requested alarm
-               else {
-                       int count = (next_alarm_when - __alarm_info->start) / distance;
-                       count++;  // move to one more earlier point
-                       new_time = next_alarm_when - distance * count;
-               }
-
-               __convert_time_to_alarm_date_t(new_time, &__alarm_info->alarm_info.start);
-               ALARM_MGR_EXCEPTION_PRINT("AppSync original time : %s", ctime(&__alarm_info->start));
-               ALARM_MGR_EXCEPTION_PRINT("AppSync change time : %s", ctime(&new_time));
-       }
-       else {
-               ALARM_MGR_LOG_PRINT("next: MAX_INT_VALUE");
-       }
-}
-
-//csc ¿¡ ÀÇÇØ targetPackageList °¡ ±¸¼ºµÈ »óÅ¿¡¼­ white list ¿¡ ÇØ´ç package Á¸Àç È®ÀÎ
-// target_package_list ¿¡¼­ appid °¡ Á¸ÀçÇϸé return true;
-static bool __sync_scheduler_look_for_target_package(GSList* target_package_list, char* appid)
-{
-       GSList* list = g_slist_find_custom(target_package_list, appid, (GCompareFunc)__compare_func);
-
-       if (appid[0] == 0) {
-               return false;
-       }
-
-       if (NULL == list) {
-               SECURE_LOGD("%s is NOT found in the app sync white list", appid);
-               return false;
-       } else {
-               SECURE_LOGD("%s is found in the app sync white list", appid);
-               return true;
-       }
-}
-
-bool _sync_scheduler_app_sync_on()
-{
-       return g_app_sync_on;
-}
-
-// CSC ¿Í Account ·Î ºÎÅÍ g_target_packages ±¸¼º
-void _sync_scheduler_init()
-{
-       int ret = 0;
-
-       char cscAppData[CSC_BUFFER_SIZE] = {0,};
-       char** cscAppSyncList = NULL;
-
-       g_target_packages = g_slist_alloc();
-
-       // Check the AppSync feature frm CSC
-#if 0
-       if (csc_feature_get_bool(CSC_FEATURE_DEF_BOOL_FRAMEWORK_APP_SYNC_DISABLE) == CSC_FEATURE_BOOL_FALSE) {
-#else
-       if (true) {
-#endif
-               g_app_sync_on = true;
-
-               // TODO: Get app sync data from csc file (cscAppData)
-               //ret = csc_feature_get_str(CSC_FEATURE_DEF_STR_ALARM_MANAGER_APP_SYNC, cscAppData, CSC_BUFFER_SIZE);
-
-               cscAppSyncList = g_strsplit(cscAppData, ",", 0);
-
-               // Check the whitelist mode
-               if (0 == g_strcmp0(*cscAppSyncList, "whitelist")) {
-
-                       // Load Whitelist of target packages
-                       for (cscAppSyncList++; NULL != *cscAppSyncList; cscAppSyncList++) {
-                               ALARM_MGR_LOG_PRINT("CSC data, %s", *cscAppSyncList);
-                               g_target_packages = g_slist_append(g_target_packages, g_strdup(*cscAppSyncList));
-                       }
-               } else if (0 == g_strcmp0(*cscAppSyncList, "blacklist")) {
-
-                       // Disable Whitelist depending on Blacklist selection.
-                       g_white_list = false;
-                       g_white_list_plus_auto_add = false;
-
-                       // Load Blacklist of target packages
-                       for (cscAppSyncList++; NULL != *cscAppSyncList; cscAppSyncList++) {
-                               ALARM_MGR_LOG_PRINT("CSC data, %s", *cscAppSyncList);
-                               g_target_packages = g_slist_append(g_target_packages, g_strdup(*cscAppSyncList));
-                       }
-               } else { // default lists
-                       //g_target_packages = g_slist_append(g_target_packages, "com.samsung.helloworld");
-               }
-
-               // Free the csc list
-               g_strfreev(cscAppSyncList);
-
-               if (APP_SYNC_LOG) {
-                       GSList *gs_iter = NULL;
-                       int i = 0;
-                       for (gs_iter = g_target_packages; gs_iter != NULL;
-                                gs_iter = g_slist_next(gs_iter), i++) {
-                               SECURE_LOGD("target package [%d] : %s",
-                                       i, gs_iter->data);
-                       }
-               }
-       } else {
-               ALARM_MGR_EXCEPTION_PRINT("App sync is disabled", *cscAppSyncList);
-       }
-}
-
-void _sync_scheduler_repeating_alarms(__alarm_info_t* __alarm_info)
-{
-       int ret;
-
-       // true ¸é ±âÁ¸°ú µ¿ÀÏÇÑ alarm ¿äûÀ̹ǷÎ, ¹«½Ã
-       bool is_non_adjustable_alarm = __sync_scheduler_look_for_non_adjustable_alarm(
-                                               g_adjustable_repeating_alarms, __alarm_info);
-
-       // Remove this alarm if already scheduled.
-       // replace pre existed alarm and remove from the appsync list
-       //removeLocked(alarm.operation);
-
-       char appid[255] = {0,};
-       ret = aul_app_get_appid_bypid(__alarm_info->pid, appid, sizeof(appid));
-       if (ret != AUL_R_OK)
-               ALARM_MGR_LOG_PRINT("Cannot get the appid");
-
-       if ( (is_non_adjustable_alarm == false) &&
-               (__sync_scheduler_look_for_target_package(g_target_packages, appid) == g_white_list)) {
-
-               if ((__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_REPEAT) &&
-                       (__alarm_info->alarm_info.mode.u_interval.interval >= SYNC_MIN_VALUE) &&
-                       (__alarm_info->alarm_info.mode.u_interval.interval <= SYNC_MAX_VALUE)) {
-                       g_interval_gcd = __sync_scheduler_calculate_gcd_of_repeat_intervals(g_interval_gcd,
-                               __alarm_info->alarm_info.mode.u_interval.interval);
-
-                       // If new RepeatInterval belongs to multiples of gIntervalGcd,
-                       // the alarm will start at the nearest scheduling point
-                       // around the requested alarm time. The scheduling points are
-                       // calculated on the unit of gIntervalGcd from the next repeating alarm
-                       // to be triggered.
-                       if (__alarm_info->alarm_info.mode.u_interval.interval % g_interval_gcd == 0) {
-                               __sync_scheduler_adjust_alarm_time(__alarm_info, g_interval_gcd);
-                               g_adjustable_repeating_alarms = g_slist_append(g_adjustable_repeating_alarms, __alarm_info);
-                       }
-                       // If not, the alarm will start at the nearest scheduling point around
-                       // the requested alarm time. The scheduling points are calculated on
-                       // the unit of alarm.repeatInterval from the next repeating alarm to be triggered.
-                       else {
-                               __sync_scheduler_adjust_alarm_time(__alarm_info, __alarm_info->alarm_info.mode.u_interval.interval);
-                       }
-               }
-               else if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE) {
-
-                       // The package of the alarms registered to account manager could be adjusted
-                       time_t now;
-                       time(&now);
-                       int distance_to_alarm = __alarm_info->start - now;
-                       int sync_tolerance_value = (distance_to_alarm >= (INTERVAL_HOUR - SYNC_MIN_VALUE)) ? 60 : 10; // [s] 30s or 5s
-                       int distance_to_alarm_rounded = (int) round((double)distance_to_alarm/(double)sync_tolerance_value) * sync_tolerance_value;
-
-                       // Optimize code for com.android.email is omitted.
-                       // Optimize code for com.google.android.gsf is omitted.
-
-                       // Adjust the alarm that occurs periodically in the range
-                       // between SYNC_MIN_VALUE and SYNC_MAX_VALUE
-                       if ((distance_to_alarm_rounded <= SYNC_MAX_VALUE) &&
-                               (distance_to_alarm_rounded >= SYNC_MIN_VALUE) &&
-                               (distance_to_alarm_rounded % SYNC_MIN_VALUE == 0)) {
-                               __alarm_info_t* new_alarm;
-                               g_interval_gcd = __sync_scheduler_calculate_gcd_of_repeat_intervals(g_interval_gcd, distance_to_alarm_rounded);
-                               new_alarm = malloc(sizeof(__alarm_info_t));
-
-                               memcpy(new_alarm, __alarm_info, sizeof(__alarm_info_t));
-                               new_alarm->alarm_info.mode.u_interval.interval = distance_to_alarm_rounded;
-                               __sync_scheduler_adjust_alarm_time(new_alarm, g_interval_gcd);
-                               g_adjustable_repeating_alarms = g_slist_append(g_adjustable_repeating_alarms, new_alarm);
-                               memcpy(&(__alarm_info->alarm_info.start), &(new_alarm->alarm_info.start), sizeof(alarm_date_t));
-                       }
-               }
-               if (APP_SYNC_LOG) {
-                       GSList *gs_iter = NULL;
-                       __alarm_info_t *entry = NULL;
-                       int i = 0;
-                       time_t due_time = 0;
-                       struct tm duetime_tm;
-                       alarm_date_t *start;
-
-                       for (gs_iter = g_adjustable_repeating_alarms; gs_iter != NULL;
-                                gs_iter = g_slist_next(gs_iter), i++) {
-
-                               entry = gs_iter->data;
-                               start = &entry->alarm_info.start;
-
-                               duetime_tm.tm_hour = start->hour;
-                               duetime_tm.tm_min = start->min;
-                               duetime_tm.tm_sec = start->sec;
-
-                               duetime_tm.tm_year = start->year - 1900;
-                               duetime_tm.tm_mon = start->month - 1;
-                               duetime_tm.tm_mday = start->day;
-
-                               due_time = mktime(&duetime_tm);
-
-                               ALARM_MGR_LOG_PRINT("List[%d] : Interval %d Start %s",
-                                       i, entry->alarm_info.mode.u_interval.interval, ctime(&due_time));
-                       }
-               }
-               ALARM_MGR_LOG_PRINT("Interval GCD : %d", g_interval_gcd);
-       }
-}
-
-void _sync_scheduler_remove_repeating_alarm(alarm_id_t alarm_id)
-{
-// __alarm_delete ÇÔ¼ö¿¡¼­ È£Ãâ
-//g_adjustable_repeating_alarms ¿¡¼­ alarm »èÁ¦
-       GSList *gs_iter = NULL;
-       __alarm_info_t *entry = NULL;
-
-       for (gs_iter = g_adjustable_repeating_alarms; gs_iter != NULL;
-                gs_iter = g_slist_next(gs_iter)) {
-               entry = gs_iter->data;
-
-               if (entry->alarm_id == alarm_id) {
-                       g_adjustable_repeating_alarms =
-                               g_slist_remove(g_adjustable_repeating_alarms, gs_iter->data);
-               }
-       }
-}
-
index 0573447..01f4fe1 100755 (executable)
 
 #define _BSD_SOURCE            /*gmtime_r requires */
 
-#include<stdio.h>
-#include<stdlib.h>
-#include<time.h>
-#include<signal.h>
-#include<string.h>
-#include<sys/types.h>
-#include<errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <sys/timerfd.h>
 
-#include<dbus/dbus.h>
-#include<glib.h>
+#include <glib.h>
 
-#include"alarm.h"
-#include"alarm-internal.h"
+#include "alarm.h"
+#include "alarm-internal.h"
 
 extern bool g_dummy_timer_is_set;
 
@@ -49,26 +49,6 @@ bool _alarm_destory_timer(timer_t timer)
                return false;
 }
 
-timer_t _alarm_create_timer()
-{
-       timer_t timer = (timer_t) -1;
-       struct sigevent timer_event;
-
-       ALARM_MGR_LOG_PRINT("[alarm-server][timer]\n");
-
-       timer_event.sigev_notify = SIGEV_SIGNAL;
-       timer_event.sigev_signo = SIG_TIMER;
-       timer_event.sigev_value.sival_ptr = (void *)timer;
-
-       if (timer_create(CLOCK_REALTIME, &timer_event, &timer) < 0) {
-               perror("create timer has failed\n");
-               exit(1);
-       }
-
-       return timer;
-
-}
-
 bool _alarm_disable_timer(__alarm_server_context_t alarm_context)
 {
        struct itimerspec time_spec;
@@ -77,7 +57,7 @@ bool _alarm_disable_timer(__alarm_server_context_t alarm_context)
        time_spec.it_value.tv_nsec = 0;
        time_spec.it_interval.tv_sec = time_spec.it_interval.tv_nsec = 0;
 
-       if (timer_settime(alarm_context.timer, 0, &time_spec, NULL) < 0) {
+       if (timerfd_settime(alarm_context.timer, 0, &time_spec, NULL) < 0) {
                perror("disable timer has failed\n");
                return false;
        }
@@ -85,23 +65,19 @@ bool _alarm_disable_timer(__alarm_server_context_t alarm_context)
        return true;
 }
 
-bool _alarm_set_timer(__alarm_server_context_t *alarm_context, timer_t timer,
-                     time_t due_time, alarm_id_t id)
+bool _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t due_time)
 {
        struct itimerspec time_spec;
        time_t current_time;
        double interval;
        char due_time_r[100] = { 0 };
        struct tm ts_ret;
-       
        extern int errno;
 
        time(&current_time);
 
        interval = difftime(due_time, current_time);
-       ALARM_MGR_LOG_PRINT("[alarm-server][timer]: remain time from "
-                           "current is %f , due_time is %d\n", interval,
-                           due_time);
+       ALARM_MGR_LOG_PRINT("[alarm-server][timer]: remain time from current is %f , due_time is %d.", interval, due_time);
 
        /*set timer as absolute time */
        /*we create dummy timer when the interval is longer than one day. */
@@ -113,23 +89,21 @@ bool _alarm_set_timer(__alarm_server_context_t *alarm_context, timer_t timer,
                interval = 60 * 60 * 12;
                g_dummy_timer_is_set = true;
                strftime(due_time_r, 30, "%c", &ts_ret);
-               ALARM_MGR_LOG_PRINT("create dummy alarm timer(%d), "
-                                   "due_time(%s) \n", timer, due_time_r);
-       } else
+               ALARM_MGR_LOG_PRINT("create dummy alarm timer(%d), due_time(%s)", timer, due_time_r);
+       }
+       else {
                g_dummy_timer_is_set = false;
+       }
 
        time_spec.it_value.tv_sec = due_time;
        time_spec.it_value.tv_nsec = 0;
        time_spec.it_interval.tv_sec = time_spec.it_interval.tv_nsec = 0;
 
-       if (interval > 0
-           && timer_settime(timer, TIMER_ABSTIME, &time_spec, NULL) != 0) {
-               ALARM_MGR_EXCEPTION_PRINT("set timer has failed : timer(%d), "
-                                         "due_time(%u) , errno(%d)\n", timer,
-                                         due_time, errno);
+       if (interval > 0 && timerfd_settime(timer, TFD_TIMER_ABSTIME, &time_spec, NULL) != 0) {
+               ALARM_MGR_EXCEPTION_PRINT("set timer has failed : timer(%d), due_time(%u) , errno(%d).", timer, due_time, errno);
                return false;
        }
-       /* we set c_due_time to due_time due to allow newly created alarm can 
+       /* we set c_due_time to due_time due to allow newly created alarm can
           be schedlued when its interval is less than the current alarm */
        alarm_context->c_due_time = due_time;
        return true;
index 854685c..7efb17e 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <sys/timerfd.h>
+#include <poll.h>
+#include <stdint.h>
 
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
 #include <glib.h>
 #if !GLIB_CHECK_VERSION (2, 31, 0)
 #include <glib/gmacros.h>
-#else
 #endif
 
-/*#include "global-gconf.h"*/
+#include "gio/gio.h"
 #include "alarm.h"
 #include "alarm-internal.h"
-
-/*#include"limo-event-delivery.h"*/
+#include "alarm-mgr-stub.h"
 
 #include <aul.h>
 #include <bundle.h>
 #define WAKEUP_ALARM_APP_ID       "com.samsung.alarm.ALARM"
        /* alarm ui application's alarm's dbus_service name instead of 21
           (alarm application's app_id) value */
-#define WAKEUP_ALARMBOOTING_APP_ID     "com.samsung.alarmboot.ui.ALARM"
-/*alrmbooting ui application's dbus_service name instead of 121(alarmbooting
-       application's app_id) value */
-
-#ifdef WEARABLE_PROFILE
-#include "dd-display.h"
-#endif
 
 __alarm_server_context_t alarm_context;
 bool g_dummy_timer_is_set = FALSE;
 
 GSList *g_scheduled_alarm_list = NULL;
-
 GSList *g_expired_alarm_list = NULL;
 
 #ifndef RTC_WKALM_BOOT_SET
 #define RTC_WKALM_BOOT_SET _IOW('p', 0x80, struct rtc_wkalrm)
 #endif
 
-#ifdef __ALARM_BOOT
-bool enable_power_on_alarm;
-bool alarm_boot;
-time_t ab_due_time = -1;
-bool poweron_alarm_expired = false;
-#endif
-
 /*     2008. 6. 3 sewook7.park
        When the alarm becoms sleeping mode, alarm timer is not expired.
        So using RTC, phone is awaken before alarm rings.
 */
 #define __WAKEUP_USING_RTC__
 #ifdef __WAKEUP_USING_RTC__
-#include<errno.h>
+#include <errno.h>
 #include <linux/rtc.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
@@ -103,7 +87,25 @@ bool poweron_alarm_expired = false;
 #define ALARM_SET_RTC               _IOW('a', 5, struct timespec)
 #define ALARM_CLEAR(type)           _IO('a', 0 | ((type) << 4))
 
-
+// For 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_FILE_PATH "/var/log/alarmmgr.log"
+static int log_index = 0;
+static int log_fd = 0;
+
+// display lock and unlock
+#define DEVICED_BUS_NAME "org.tizen.system.deviced"
+#define DEVICED_PATH_DISPLAY           "/Org/Tizen/System/DeviceD/Display"
+#define DEVICED_INTERFACE_DISPLAY      "org.tizen.system.deviced.display"
+#define DEVICED_LOCK_STATE             "lockstate"
+#define DEVICED_UNLOCK_STATE   "unlockstate"
+#define DEVICED_DBUS_REPLY_TIMEOUT     (120*1000)
+#define DEVICED_LCD_OFF                "lcdoff"
+#define DEVICED_STAY_CUR_STATE "staycurstate"
+#define DEVICED_SLEEP_MARGIN           "sleepmargin"
 
 static const char default_rtc[] = "/dev/alarm";
 
@@ -111,6 +113,12 @@ static int gfd = 0;
 
 #endif                         /*__WAKEUP_USING_RTC__*/
 
+/*  GDBus Declaration */
+#define ALARM_MGR_DBUS_PATH    "/com/samsung/alarm/manager"
+#define ALARM_MGR_DBUS_NAME    "com.samsung.alarm.manager"
+GDBusObjectManagerServer *alarmmgr_server = NULL;
+static AlarmManager* interface = NULL;
+
 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,
@@ -130,200 +138,107 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
 static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code);
 static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
                           alarm_info_t *alarm_info, int *error_code);
-static bool __alarm_power_on(int app_id, bool on_off, int *error_code);
-static bool __alarm_power_off(int app_id, int *error_code);
-static bool __alarm_check_next_duetime(int app_id, int *error_code);
-static void __alarm_send_noti_to_application(const char *app_service_name,
-                                            alarm_id_t alarm_id);
+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();
-static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext);
+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 __hibernation_leave_callback();
 static bool __initialize_noti();
 
 static bool __initialize_dbus();
 static bool __initialize_db();
 static void __initialize();
-static bool __check_false_alarm();
-static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
-                                              DBusMessage *message,
-                                              void *user_data);
+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);
 
-static int __rtc_set_b2()
+static void __initialize_module_log(void);
+static bool __save_module_log(const char *tag, const char *messgae);
+
+int __display_lock_state(char *state, char *flag, unsigned int timeout);
+int __display_unlock_state(char *state, char *flag);
+
+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;
+       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.*/
-       ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, "
-                                 "we don't set RTC.\n");
+       ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, we don't set RTC.");
        return;
 #endif
 
        if (gfd == 0) {
                gfd = open(rtc, O_RDWR);
                if (gfd == -1) {
-                       ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
+                       ALARM_MGR_EXCEPTION_PRINT("RTC open failed.");
+                       return;
                }
        }
 
        /* Read the RTC time/date */
-       int retval;
+       int retval = 0;
+       char *timebuf = ctime(&alarm_context.c_due_time);
+       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\n", \
-                           alarm_context.c_due_time);
+       ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d.", alarm_context.c_due_time);
 
        if (alarm_context.c_due_time != -1) {
-
-               /*retval = ioctl(gfd, ALARM_CLEAR(ALARM_RTC_WAKEUP));
+               retval = ioctl(gfd, ALARM_CLEAR(ALARM_RTC_WAKEUP));
                if (retval == -1) {
                        if (errno == ENOTTY) {
-                               ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
-                                                         "supported.\n");
+                               ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
                        }
-                       ALARM_MGR_EXCEPTION_PRINT("ALARM_CLEAR ioctl");
-                       //close(fd);
-                       return -1;
-               }*/
+                       ALARM_MGR_EXCEPTION_PRINT("ALARM_CLEAR ioctl is failed. errno = %s", strerror(errno));
+                       return;
+               }
+               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]ALARM_CLEAR ioctl is successfully done.");
 
                time_t due_time = alarm_context.c_due_time;
                gmtime_r(&due_time, &due_tm);
 
-               ALARM_MGR_LOG_PRINT("Setted RTC Alarm date/time is "
-                       "%d-%d-%d, %02d:%02d:%02d.\n", due_tm.tm_mday,
-                       due_tm.tm_mon + 1, due_tm.tm_year + 1900,
+               ALARM_MGR_EXCEPTION_PRINT("Setted RTC Alarm date/time is %d-%d-%d, %02d:%02d:%02d (UTC).",
+                       due_tm.tm_mday, due_tm.tm_mon + 1, due_tm.tm_year + 1900,
                        due_tm.tm_hour, due_tm.tm_min, due_tm.tm_sec);
 
-               alarm_time.tv_sec = due_time;
-               alarm_time.tv_nsec = 0;
+               alarm_time.tv_sec = due_time - 1;
+               alarm_time.tv_nsec = 500000000; // Wakeup is 500ms faster than expiring time to correct RTC error.
                retval = ioctl(gfd, ALARM_SET(ALARM_RTC_WAKEUP), &alarm_time);
                if (retval == -1) {
                        if (errno == ENOTTY) {
-                               ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
-                                                         "supported.\n");
+                               ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
                        }
-                       ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
-                       //close(fd);
-                       return -1;
+                       ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror(errno));
+                       __save_module_log("FAIL: SET RTC", log_message);
+                       return;
                }
-               ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
-
-               ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is on");
-       } else
-               ALARM_MGR_LOG_PRINT("[alarm-server]alarm_context.c_due_time is"
-                                   "less than 10 sec. RTC alarm does not need to be set\n");
-
-       //close(fd);
-#endif                         /* __WAKEUP_USING_RTC__ */
-       return 0;
-}
-
-
-static void __rtc_set()
-{
-#ifdef __WAKEUP_USING_RTC__
-
-       const char *rtc = "/dev/rtc0";
-       int fd = 0;
-       struct rtc_time rtc_tm;
-       struct rtc_wkalrm rtc_wk;
-       struct tm due_tm;
-
-#ifdef _SIMUL                  /*if build is simulator, we don't need to set
-                                  RTC because RTC does not work in simulator.*/
-       ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, "
-                                 "we don't set RTC.\n");
-       return;
-#endif
-
-       if(__rtc_set_b2() == 0)
-               return;
-
-       fd = open(rtc, O_RDONLY);
-       if (fd == -1) {
-               ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
-               return;
+               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]RTC ALARM_SET ioctl is successfully done.");
+               __save_module_log("SET RTC", log_message);
        }
-
-       /* Read the RTC time/date */
-       int retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
-       if (retval == -1) {
-               ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed");
-               close(fd);
-               return;
+       else {
+               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]alarm_context.c_due_time is"
+                       "less than 10 sec. RTC alarm does not need to be set");
        }
-
-       ALARM_MGR_LOG_PRINT("\n\nCurrent RTC date/time is %d-%d-%d, "
-               "%02d:%02d:%02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
-               rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min,
-               rtc_tm.tm_sec);
-
-       ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d\n", \
-                           alarm_context.c_due_time);
-
-       if (alarm_context.c_due_time != -1) {
-               time_t due_time = alarm_context.c_due_time;
-               gmtime_r(&due_time, &due_tm);
-
-               rtc_tm.tm_mday = due_tm.tm_mday;
-               rtc_tm.tm_mon = due_tm.tm_mon;
-               rtc_tm.tm_year = due_tm.tm_year;
-               rtc_tm.tm_hour = due_tm.tm_hour;
-               rtc_tm.tm_min = due_tm.tm_min;
-               rtc_tm.tm_sec = due_tm.tm_sec;
-               memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm));
-               rtc_wk.enabled = 1;
-               rtc_wk.pending = 0;
-
-               ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
-                       "%d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_mday,
-                       rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,
-                       rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
-
-               retval = ioctl(fd, RTC_WKALM_SET, &rtc_wk);
-               if (retval == -1) {
-                       if (errno == ENOTTY) {
-                               ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
-                                                         "supported.\n");
-                       }
-                       ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
-                       close(fd);
-                       return;
-               }
-               ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
-
-               /* Enable alarm interrupts */
-               retval = ioctl(fd, RTC_AIE_ON, 0);
-               if (retval == -1) {
-                       ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed");
-                       close(fd);
-                       return;
-               }
-               ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is on");
-       } else
-               ALARM_MGR_LOG_PRINT("[alarm-server]alarm_context.c_due_time is"
-                                   "less than 10 sec. RTC alarm does not need to be set\n");
-
-       close(fd);
-
 #endif                         /* __WAKEUP_USING_RTC__ */
+       return;
 }
 
-
 int _set_rtc_time(time_t _time)
 {
-       int retval0 = 0;
+       int ret = 0;
        const char *rtc0 = default_rtc;
        struct timespec rtc_time;
+       char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
 
        if (gfd == 0) {
                gfd = open(rtc0, O_RDWR);
@@ -337,33 +252,27 @@ int _set_rtc_time(time_t _time)
        rtc_time.tv_sec = _time;
        rtc_time.tv_nsec = 0;
 
-       retval0 = ioctl(gfd, ALARM_SET_RTC, &rtc_time);
+       strncpy(log_tag, "SET RTC", strlen("SET RTC"));
+       char *timebuf = ctime(&_time);
+       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) {
+               ALARM_MGR_LOG_PRINT("ALARM_SET_RTC ioctl is failed. errno = %s", strerror(errno));
+               strncpy(log_tag, "FAIL: SET RTC", strlen("FAIL: SET RTC"));
 
-       if (retval0 == -1) {
-               /*if (gfd != -1)
-                       close(fd0);*/
-               ALARM_MGR_LOG_PRINT("error to ioctl fd0.");
-               ALARM_MGR_LOG_PRINT("retval0 : %d", retval0);
-               
                perror("\t");
        }
-       /*if (gfd != -1)
-               close(fd0);*/
+
+       __save_module_log(log_tag, log_message);
 
        return 1;
 }
 
-
 bool __alarm_clean_list()
 {
-       GSList *iter = NULL;
-
-       for (iter = alarm_context.alarms; iter != NULL;
-            iter = g_slist_next(iter)) {
-               free(iter->data);
-       }
-
-       g_slist_free(alarm_context.alarms);
+       g_slist_free_full(alarm_context.alarms, g_free);
        return true;
 }
 
@@ -371,13 +280,11 @@ static void __alarm_generate_alarm_id(__alarm_info_t *__alarm_info, alarm_id_t *
 {
        bool unique_id = false;
        __alarm_info_t *entry = NULL;
-
        GSList *iter = NULL;
 
-       /* FIXME: alarm id must be unique. */
-       __alarm_info->alarm_id = (int)(void *)__alarm_info;
-       ALARM_MGR_LOG_PRINT("__alarm_info->alarm_id is %d", \
-                           __alarm_info->alarm_id);
+       srand((unsigned int)time(NULL));
+       __alarm_info->alarm_id = (rand() % INT_MAX) + 1;
+       ALARM_MGR_LOG_PRINT("__alarm_info->alarm_id is %d", __alarm_info->alarm_id);
 
        while (unique_id == false) {
                unique_id = true;
@@ -399,34 +306,25 @@ static void __alarm_generate_alarm_id(__alarm_info_t *__alarm_info, alarm_id_t *
 
 static bool __alarm_add_to_list(__alarm_info_t *__alarm_info)
 {
-
        alarm_info_t *alarm_info = &__alarm_info->alarm_info;
        __alarm_info_t *entry = NULL;
-
        GSList *iter = NULL;
 
-       /* list alarms */
-       ALARM_MGR_LOG_PRINT("[alarm-server]: before add\n");
-       for (iter = alarm_context.alarms; iter != NULL;
-            iter = g_slist_next(iter)) {
-               entry = iter->data;
-               /*ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
-                  entry->alarm_id); */
-       }
+       ALARM_MGR_LOG_PRINT("[alarm-server]: Before add alarm_id(%d)", __alarm_info->alarm_id);
 
-       alarm_context.alarms =
-           g_slist_append(alarm_context.alarms, __alarm_info);
-       /*list alarms */
-       ALARM_MGR_LOG_PRINT("[alarm-server]: after add\n");
-       for (iter = alarm_context.alarms; iter != NULL;
-            iter = g_slist_next(iter)) {
+       alarm_context.alarms = g_slist_append(alarm_context.alarms, __alarm_info);
+       ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: After add alarm_id(%d)", __alarm_info->alarm_id);
+
+       // alarm list
+       for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
                entry = iter->data;
-               ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
-                                   entry->alarm_id);
+               ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d).", entry->alarm_id);
        }
 
        if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
-               _save_alarms(__alarm_info);
+               if (!_save_alarms(__alarm_info)) {
+                       ALARM_MGR_EXCEPTION_PRINT("Saving alarm_id(%d) in DB is failed.", __alarm_info->alarm_id);
+               }
        }
 
        return true;
@@ -464,7 +362,9 @@ static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
        }
 
        if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
-               _update_alarms(__alarm_info);
+               if (!_update_alarms(__alarm_info)) {
+                       ALARM_MGR_EXCEPTION_PRINT("Updating alarm_id(%d) in DB is failed.", __alarm_info->alarm_id);
+               }
        }
 
        return true;
@@ -481,25 +381,21 @@ static bool __alarm_remove_from_list(int pid, alarm_id_t alarm_id,
        __alarm_info_t *entry = NULL;
 
        /*list alarms */
-       ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)\n",
-                           alarm_id);
+       ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)", alarm_id);
 
-       for (iter = alarm_context.alarms; iter != NULL;
-            iter = g_slist_next(iter)) {
+       for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
                entry = iter->data;
                if (entry->alarm_id == alarm_id) {
                        alarm_info = &entry->alarm_info;
 
-                       ALARM_MGR_LOG_PRINT("[alarm-server]: "
-                                           "__alarm_remove_from_list : alarm id(%d)\n",
-                                           entry->alarm_id);
+                       ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Remove alarm id(%d)", entry->alarm_id);
 
                        if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
                                _delete_alarms(alarm_id);
                        }
 
-                       alarm_context.alarms =
-                           g_slist_remove(alarm_context.alarms, iter->data);
+                       alarm_context.alarms = g_slist_remove(alarm_context.alarms, iter->data);
+                       g_free(entry);
                        found = true;
                        break;
                }
@@ -681,8 +577,7 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
 
        time(&current_time);
 
-       for (iter = alarm_context.alarms; iter != NULL;
-            iter = g_slist_next(iter)) {
+       for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
                entry = iter->data;
                due_time = entry->due_time;
 
@@ -690,16 +585,14 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
 
                ALARM_MGR_LOG_PRINT("alarm[%d] with duetime(%u) at "
                "current(%u)\n", entry->alarm_id, due_time, current_time);
-               if (due_time == 0) {    /* 0 means this alarm has been
-                                          disabled */
+               if (due_time == 0) {    /* 0 means this alarm has been disabled */
                        continue;
                }
 
                interval = difftime(due_time, current_time);
 
                if (interval <= 0) {
-                       ALARM_MGR_LOG_PRINT("this may be error.. alarm[%d]\n", \
-                                           entry->alarm_id);
+                       ALARM_MGR_EXCEPTION_PRINT("The duetime of alarm(%d) is OVER.", entry->alarm_id);
                        continue;
                }
 
@@ -717,22 +610,20 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
 }
 
 static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
-                          int pid,char *bundle_data, int *error_code){
-
+                          int pid, char *bundle_data, int *error_code)
+{
        time_t current_time;
        time_t due_time;
        struct tm ts_ret;
        char due_time_r[100] = { 0 };
-       char proc_file[512] = { 0 };
-       char process_name[512] = { 0 };
        char app_name[512] = { 0 };
-       char *word = NULL;
-       char *proc_name_ptr = NULL;
-       int fd = 0;
-       int ret = 0;
-       int i = 0;
        bundle *b;
-       char caller_appid[512];
+       char caller_appid[256] = { 0 };
+       char* callee_appid = NULL;
+       char* caller_pkgid = NULL;
+       char* callee_pkgid = NULL;
+       pkgmgrinfo_pkginfo_h caller_handle;
+       pkgmgrinfo_pkginfo_h callee_handle;
        bundle_raw *b_data = NULL;
        int datalen = 0;
 
@@ -740,66 +631,54 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
 
        __alarm_info = malloc(sizeof(__alarm_info_t));
        if (__alarm_info == NULL) {
-               SECURE_LOGE("Caution!! app_pid=%d, malloc "
-                                         "failed. it seems to be OOM\n", pid);
-               *error_code = -1;       /* -1 means that system
-                                          failed internally. */
+               SECURE_LOGE("Caution!! app_pid=%d, malloc failed. it seems to be OOM.", pid);
+               *error_code = ERR_ALARM_SYSTEM_FAIL;
                return false;
        }
+
        __alarm_info->pid = pid;
        __alarm_info->alarm_id = -1;
 
-
-       /* we should consider to check whether  pid is running or Not
-        */
-       memset(process_name, '\0', 512);
-       memset(proc_file, '\0', 512);
-       snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
-
-       fd = open(proc_file, O_RDONLY);
-       if (fd < 0) {           /* failure */
-               SECURE_LOGE("Caution!! app_pid(%d) seems to be "
-                                         "killed, so we failed to get proc file(%s) and do not create "
-                                         "alarm_info\n", pid, proc_file);
-               *error_code = -1;       /*-1 means that system failed
-                                                       internally.*/
+       if (!__get_caller_unique_name(pid, app_name)) {
+               *error_code = ERR_ALARM_SYSTEM_FAIL;
                free(__alarm_info);
                return false;
-       } else {
-               ret = read(fd, process_name, 512);
-               close(fd);
-               if (ret <=0)
-               {
-                       ALARM_MGR_EXCEPTION_PRINT("Unable to get application name\n");
-                       *error_code = -1;
-                       free(__alarm_info);
-                       return false;
-               }
-               while (process_name[i] != '\0') {
-                       if (process_name[i] == ' ') {
-                               process_name[i] = '\0';
-                               break;
-                       }
-                       i++;
-               }
+       }
+       __alarm_info->quark_app_unique_name = g_quark_from_string(app_name);
 
-               word = strtok_r(process_name, "/", &proc_name_ptr);
-               while (word != NULL) {
-                       memset(app_name, 0, 512);
-                       snprintf(app_name, 512, "%s", word);
-                       word = strtok_r(NULL, "/", &proc_name_ptr);
+       // Get caller_appid and callee_appid to get each package id
+       // 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);
+                               }
+                       }
+                       pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
                }
-               __alarm_info->quark_app_unique_name =
-                   g_quark_from_string(app_name);
        }
 
+       // callee
+       __alarm_info->quark_callee_pkgid = g_quark_from_string("null");
+
        b = bundle_decode((bundle_raw *)bundle_data, strlen(bundle_data));
-       ret = aul_app_get_appid_bypid(pid, caller_appid, 512);
-       if(ret == 0) {
-               bundle_add(b, "__ALARM_MGR_CALLER_APPID", caller_appid);
+       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);
+                       }
+               }
+               pkgmgrinfo_appinfo_destroy_appinfo(callee_handle);
        }
-       bundle_encode(b, &b_data, &datalen);
 
+       SECURE_LOGD("caller_pkgid = %s, callee_pkgid = %s",
+               g_quark_to_string(__alarm_info->quark_caller_pkgid), g_quark_to_string(__alarm_info->quark_callee_pkgid));
+
+       bundle_encode(b, &b_data, &datalen);
        __alarm_info->quark_bundle=g_quark_from_string(b_data);
        __alarm_info->quark_app_service_name = g_quark_from_string("null");
        __alarm_info->quark_dst_service_name = g_quark_from_string("null");
@@ -811,29 +690,23 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
                free(b_data);
                b_data = 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);
 
-#ifdef __APP_SYNC
-       if (_sync_scheduler_app_sync_on())
-               _sync_scheduler_repeating_alarms(__alarm_info);
-#endif
-
        time(&current_time);
 
        if (alarm_context.c_due_time < current_time) {
                ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
-               "(%d) is less than current time(%d)", alarm_context.c_due_time,
-                                         current_time);
+               "(%d) is less than current time(%d)", alarm_context.c_due_time, current_time);
                alarm_context.c_due_time = -1;
        }
 
        due_time = _alarm_next_duetime(__alarm_info);
        if (__alarm_add_to_list(__alarm_info) == false) {
                free(__alarm_info);
-               *error_code = -1;
+               *error_code = ERR_ALARM_SYSTEM_FAIL;
                return false;
        }
 
@@ -846,10 +719,10 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
                     "current_time(%d) is same as due_time(%d)", current_time,
                     due_time);
                return true;
-       }else if (difftime(due_time, current_time) <  0){
+       } else if (difftime(due_time, current_time) < 0) {
                ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time);
                return true;
-       }else {
+       } else {
                localtime_r(&due_time, &ts_ret);
                strftime(due_time_r, 30, "%c", &ts_ret);
                SECURE_LOGD("[alarm-server]:Create a new alarm: "
@@ -857,47 +730,32 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
                                    due_time_r);
        }
 
-       ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
-                           "due_time(%d)", alarm_context.c_due_time, due_time);
+       ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:alarm_context.c_due_time(%d), due_time(%d)", alarm_context.c_due_time, due_time);
 
-       if (alarm_context.c_due_time == -1
-           || due_time < alarm_context.c_due_time) {
+       if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
                _clear_scheduled_alarm_list();
                _add_to_scheduled_alarm_list(__alarm_info);
-               _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
-                                *alarm_id);
+               _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
                alarm_context.c_due_time = due_time;
-
        } else if (due_time == alarm_context.c_due_time) {
                _add_to_scheduled_alarm_list(__alarm_info);
-
        }
 
        __rtc_set();
 
-#ifdef __ALARM_BOOT
-       /*alarm boot */
-       if (enable_power_on_alarm) {
-               __alarm_power_on(0, enable_power_on_alarm, NULL);
-       }
-#endif
-
        return true;
-
 }
 
 static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
                           int pid, char *app_service_name, char *app_service_name_mod,
                           const char *dst_service_name,const char *dst_service_name_mod,  int *error_code)
 {
-
        time_t current_time;
        time_t due_time;
-       char proc_file[256] = { 0 };
-       char process_name[512] = { 0 };
-       char app_name[256] = { 0 };
-       char *word = NULL;
-       char *proc_name_ptr = NULL;
+       char app_name[512] = { 0 };
+       char caller_appid[256] = { 0 };
+       char* caller_pkgid = NULL;
+       pkgmgrinfo_pkginfo_h caller_handle;
 
        __alarm_info_t *__alarm_info = NULL;
 
@@ -905,83 +763,45 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
        if (__alarm_info == NULL) {
                SECURE_LOGE("Caution!! app_pid=%d, malloc "
                                          "failed. it seems to be OOM\n", pid);
-               *error_code = -1;       /* -1 means that system
-                                          failed internally. */
+               *error_code = ERR_ALARM_SYSTEM_FAIL;
                return false;
        }
        __alarm_info->pid = pid;
        __alarm_info->alarm_id = -1;
+       __alarm_info->quark_caller_pkgid = g_quark_from_string("null");
+
+       // 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);
+                               }
+                       }
+                       pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
+               }
+       }
 
-       /* we should consider to check whether  pid is running or Not
-        */
-       memset(process_name, '\0', 512);
-       memset(proc_file, '\0', 256);
-       snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
+       __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));
 
-       int fd;
-       int ret;
-       int i = 0;
-       fd = open(proc_file, O_RDONLY);
-       if (fd < 0) {   /* failure */
-               __alarm_info->quark_app_unique_name =
-                   g_quark_from_string("unknown");
-               SECURE_LOGE("Caution!! app_pid(%d) seems to be "
-                                         "killed, so we failed to get proc file(%s) and do not create "
-                                         "alarm_info\n", pid, proc_file);
-               *error_code = -1;       /*-1 means that system failed
-                                                       internally.*/
+       if (!__get_caller_unique_name(pid, app_name)) {
+               *error_code = ERR_ALARM_SYSTEM_FAIL;
                free(__alarm_info);
                return false;
-       } else {
-               ret = read(fd, process_name, 512);
-               if (ret < 0 ) {
-                       *error_code = -1;       /*-1 means that system failed
-                                                       internally.*/
-                       free(__alarm_info);
-                       close(fd);
-                       return false;
-               }
-               close(fd);
-               while (process_name[i] != '\0') {
-                       if (process_name[i] == ' ') {
-                               process_name[i] = '\0';
-                               break;
-                       }
-                       i++;
-               }
-               /* if (readlink(proc_file, process_name, 256)!=-1) */
-               /*success */
-
-               word = strtok_r(process_name, "/", &proc_name_ptr);
-               while (word != NULL) {
-                       memset(app_name, 0, 256);
-                       snprintf(app_name, 256, "%s", word);
-                       word = strtok_r(NULL, "/", &proc_name_ptr);
-               }
-               __alarm_info->quark_app_unique_name =
-                   g_quark_from_string(app_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_app_unique_name = g_quark_from_string(app_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("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);
 
-#ifdef __APP_SYNC
-       if (_sync_scheduler_app_sync_on())
-               _sync_scheduler_repeating_alarms(__alarm_info);
-#endif
-
        time(&current_time);
 
        SECURE_LOGD("[alarm-server]:pid=%d, app_unique_name=%s, "
@@ -993,8 +813,7 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
 
        if (alarm_context.c_due_time < current_time) {
                ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
-               "(%d) is less than current time(%d)", alarm_context.c_due_time,
-                                         current_time);
+               "(%d) is less than current time(%d)", alarm_context.c_due_time, current_time);
                alarm_context.c_due_time = -1;
        }
 
@@ -1005,55 +824,37 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
        }
 
        if (due_time == 0) {
-               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
-               "due_time is 0, alarm(%d) \n", *alarm_id);
+               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: due_time is 0, alarm(%d).", *alarm_id);
                return true;
        } else if (current_time == due_time) {
-               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
-                    "current_time(%d) is same as due_time(%d)", current_time,
-                    due_time);
+               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%d) is same as due_time(%d).",
+                       current_time, due_time);
                return true;
-       }else if (difftime(due_time, current_time) <  0){
-               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time);
+       } else if (difftime(due_time, current_time) <  0) {
+               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list.",
+                       due_time, current_time);
                return true;
        } else {
                char due_time_r[100] = { 0 };
                struct tm ts_ret;
                localtime_r(&due_time, &ts_ret);
                strftime(due_time_r, 30, "%c", &ts_ret);
-               SECURE_LOGD("[alarm-server]:Create a new alarm: "
-                                   "alarm(%d) due_time(%s)", *alarm_id,
-                                   due_time_r);
+               SECURE_LOGD("[alarm-server]:Create a new alarm: alarm(%d) due_time(%s)", *alarm_id, due_time_r);
        }
 
-       ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
-                           "due_time(%d)", alarm_context.c_due_time, due_time);
+       ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:alarm_context.c_due_time(%d), due_time(%d)", alarm_context.c_due_time, due_time);
 
-       if (alarm_context.c_due_time == -1
-           || due_time < alarm_context.c_due_time) {
+       if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
                _clear_scheduled_alarm_list();
                _add_to_scheduled_alarm_list(__alarm_info);
-               _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
-                                *alarm_id);
+               _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
                alarm_context.c_due_time = due_time;
-
        } else if (due_time == alarm_context.c_due_time) {
                _add_to_scheduled_alarm_list(__alarm_info);
-
        }
 
        __rtc_set();
 
-#ifdef __ALARM_BOOT
-       /*alarm boot */
-       if (enable_power_on_alarm) {
-               /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
-                * platform with app-server.because __alarm_power_on(..) fuction don't
-                * use first parameter internally, we set this value to 0(zero)
-                */
-               __alarm_power_on(0, enable_power_on_alarm, NULL);
-       }
-#endif
        return true;
 }
 
@@ -1068,10 +869,8 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
 
        __alarm_info = malloc(sizeof(__alarm_info_t));
        if (__alarm_info == NULL) {
-               SECURE_LOGE("Caution!! app_pid=%d, "
-                       "malloc failed. it seems to be OOM\n", pid);
-               *error_code = -1;       /*-1 means that system failed
-                                               internally.*/
+               SECURE_LOGE("Caution!! app_pid=%d, malloc failed. it seems to be OOM.", pid);
+               *error_code = ERR_ALARM_SYSTEM_FAIL;
                return false;
        }
 
@@ -1090,8 +889,7 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
 
        if (alarm_context.c_due_time < current_time) {
                ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
-               "(%d) is less than current time(%d)", alarm_context.c_due_time,
-                                         current_time);
+               "(%d) is less than current time(%d)", alarm_context.c_due_time, current_time);
                alarm_context.c_due_time = -1;
        }
 
@@ -1102,13 +900,6 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
                "(%d) does not exist. so this value is invalid id.", alarm_id);
                return false;
        }
-       /* ALARM_MGR_LOG_PRINT("[alarm-server]:request_pid=%d, alarm_id=%d,
-        * app_unique_name=%s, app_service_name=%s, dst_service_name=%s,
-        * c_due_time=%d", pid, alarm_id, g_quark_to_string
-        * (__alarm_info->quark_app_unique_name), g_quark_to_string
-        * (__alarm_info->quark_app_service_name), g_quark_to_string
-        * (__alarm_info->quark_dst_service_name), alarm_context.c_due_time);
-        */
 
        result = _remove_from_scheduled_alarm_list(pid, alarm_id);
 
@@ -1117,25 +908,12 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
                _alarm_disable_timer(alarm_context);
                _alarm_schedule();
 
-               ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d)\n",
-                                   alarm_id);
+               ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d).", alarm_id);
 
                __rtc_set();
 
-#ifdef __ALARM_BOOT
-               /*alarm boot */
-               if (enable_power_on_alarm) {
-                       /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in
-                        * a platform with app-server.because __alarm_power_on(..) fuction don't
-                        * use first parameter internally, we set this value to 0(zero)
-                        */
-                       __alarm_power_on(0, enable_power_on_alarm, NULL);
-               }
-#endif
-
                if (due_time == 0) {
-                       ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
-                                       "due_time is 0\n");
+                       ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: due_time is 0.");
                }
                free(__alarm_info);
                return true;
@@ -1152,7 +930,7 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
                due_time);
                free(__alarm_info);
                return true;
-       }else if (difftime(due_time, current_time)< 0){
+       } else if (difftime(due_time, current_time)< 0) {
                ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time);
                free(__alarm_info);
                return true;
@@ -1165,15 +943,12 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
                                    "due_time(%s)\n", alarm_id, due_time_r);
        }
 
-       ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
-                           "due_time(%d)", alarm_context.c_due_time, due_time);
+       ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:alarm_context.c_due_time(%d), due_time(%d)", alarm_context.c_due_time, due_time);
 
-       if (alarm_context.c_due_time == -1
-           || due_time < alarm_context.c_due_time) {
+       if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
                _clear_scheduled_alarm_list();
                _add_to_scheduled_alarm_list(__alarm_info);
-               _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
-                                alarm_id);
+               _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
                alarm_context.c_due_time = due_time;
                ALARM_MGR_LOG_PRINT("[alarm-server1]:alarm_context.c_due_time "
                     "(%d), due_time(%d)", alarm_context.c_due_time, due_time);
@@ -1185,16 +960,6 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
 
        __rtc_set();
 
-#ifdef __ALARM_BOOT
-       /*alarm boot */
-       if (enable_power_on_alarm) {
-               /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
-                * in a platform with app-server.because __alarm_power_on(..) fuction
-                * don't use first parameter internally, we set this value to 0(zero)
-                */
-               __alarm_power_on(0, enable_power_on_alarm, NULL);
-       }
-#endif
        free(__alarm_info);
 
        return true;
@@ -1207,11 +972,6 @@ static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code)
        SECURE_LOGD("[alarm-server]:delete alarm: alarm(%d) pid(%d)\n", alarm_id, pid);
        result = _remove_from_scheduled_alarm_list(pid, alarm_id);
 
-#ifdef __APP_SYNC
-       if (_sync_scheduler_app_sync_on())
-               _sync_scheduler_remove_repeating_alarm(alarm_id);
-#endif
-
        if (!__alarm_remove_from_list(pid, alarm_id, error_code)) {
 
                SECURE_LOGE("[alarm-server]:delete alarm: "
@@ -1227,215 +987,33 @@ static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code)
 
        __rtc_set();
 
-#ifdef __ALARM_BOOT
-       /*alarm boot */
-       if (enable_power_on_alarm) {
-               /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
-                * platform with app-server.because __alarm_power_on(..) fuction don't
-                * use first parameter internally, we set this value to 0(zero)
-                */
-               __alarm_power_on(0, enable_power_on_alarm, NULL);
-       }
-#endif
-
-       return true;
-}
-
-static bool __alarm_power_on(int app_id, bool on_off, int *error_code)
-{
-#if 0 // vincent.jang def __ALARM_BOOT
-       time_t min_time = 0;
-       time_t current_time = 0;
-       struct rtc_time rtc_tm = { 0, };
-       struct tm min_time_r = { 0, };
-       int fd = 0;
-       int retval;
-
-       enable_power_on_alarm = on_off;
-       /*_update_power_on(on_off); */ /*currently its empty*/
-
-       fd = open(power_rtc, O_RDONLY);
-       if (fd < 0) {
-               ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
-               return false;
-       }
-
-       if (on_off == true) {
-               if (_alarm_find_mintime_power_on(&min_time) == true) {
-
-                       ab_due_time = min_time;
-
-                       min_time = min_time - 60;
-
-                       time(&current_time);
-
-                       if (min_time <= current_time)
-                               min_time = current_time + 5;
-
-                       gmtime_r(&min_time, &min_time_r);
-
-                       ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
-                                               "%d\n", \
-                                          min_time_r.tm_year,\
-                                          min_time_r.tm_mon,\
-                                          min_time_r.tm_mday,\
-                                          min_time_r.tm_hour,\
-                                          min_time_r.tm_min);
-                       ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
-                                               "%d\n", \
-                                          min_time_r.tm_year,\
-                                          min_time_r.tm_mon,\
-                                          min_time_r.tm_mday,\
-                                          min_time_r.tm_hour,\
-                                          min_time_r.tm_min);
-
-                       rtc_tm.tm_mday = min_time_r.tm_mday;
-                       rtc_tm.tm_mon = min_time_r.tm_mon;
-                       rtc_tm.tm_year = min_time_r.tm_year;
-                       rtc_tm.tm_hour = min_time_r.tm_hour;
-                       rtc_tm.tm_min = min_time_r.tm_min;
-                       rtc_tm.tm_sec = min_time_r.tm_sec;
-                       /*set_info.time_zone = 0; */
-                       /*set_info.u_interval.day_of_week = 0; */
-
-                       /*ALARM_MGR_LOG_PRINT("####__alarm_power_on : %d %d
-                       %d %d %d\n",set_info.year,set_info.month,set_info.day,
-                       set_info.hour,set_info.minute); */
-
-                       ALARM_MGR_LOG_PRINT("due_time : %d \n", ab_due_time);
-
-                       ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
-                                           "%d-%d-%d, %02d:%02d:%02d.\n",
-                                           rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
-                               rtc_tm.tm_year + 1900, rtc_tm.tm_hour,
-                               rtc_tm.tm_min, rtc_tm.tm_sec);
-
-                       retval = ioctl(fd, RTC_ALM_SET, &rtc_tm);
-                       if (retval == -1) {
-                               if (errno == ENOTTY) {
-                                       ALARM_MGR_EXCEPTION_PRINT(
-                                       "\n...Alarm IRQs not supported.\n");
-                               }
-                               ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
-                               close(fd);
-                               return false;
-                       }
-                       ALARM_MGR_LOG_PRINT("[alarm-server]RTC "
-                                           "alarm(POWER ON) is setted");
-
-                       /* Enable alarm interrupts */
-                       retval = ioctl(fd, RTC_AIE_ON, 0);
-                       if (retval == -1) {
-                               ALARM_MGR_EXCEPTION_PRINT(
-                                   "RTC_AIE_ON ioctl failed");
-                               close(fd);
-                               return false;
-                       }
-                       ALARM_MGR_LOG_PRINT("[alarm-server]RTC(POWER ON) "
-                                           "alarm is on");
-
-               } else
-                       retval = ioctl(fd, RTC_AIE_OFF, 0);
-       } else {
-               ALARM_MGR_LOG_PRINT("__alarm_power_on : off\n");
-               retval = ioctl(fd, RTC_AIE_OFF, 0);
-       }
-
-       close(fd);
-#endif                         /* #ifdef __ALARM_BOOT */
-
-       return true;
-}
-
-static bool __alarm_power_off(int app_id, int *error_code)
-{
-#ifdef __ALARM_BOOT
-
-#endif                         /* #ifdef __ALARM_BOOT */
        return true;
 }
 
-static bool __alarm_check_next_duetime(int app_id, int *error_code)
+static void __alarm_send_noti_to_application(const char *app_service_name, alarm_id_t alarm_id)
 {
-#ifdef __ALARM_BOOT
-       time_t current_time;
-       time_t interval;
-
-       time(&current_time);
-
-       interval = ab_due_time - current_time;
-
-       ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", ab_due_time,
-                           current_time);
-
-       if (interval > 0 && interval <= 60)
-               return true;
-       else
-               return false;
-#else                          /* #ifdef __ALARM_BOOT */
-       return true;
-#endif
-}
-
-static void __alarm_send_noti_to_application(const char *app_service_name,
-                                            alarm_id_t alarm_id)
-{
-
-
-       char service_name[MAX_SERVICE_NAME_LEN];
-       char object_name[MAX_SERVICE_NAME_LEN];
-
-       DBusMessage *message;
-       DBusMessageIter iter;
+       char service_name[MAX_SERVICE_NAME_LEN] = {0,};
 
        if (app_service_name == NULL || strlen(app_service_name) == 0) {
-               ALARM_MGR_EXCEPTION_PRINT("This alarm destination is "
-                                         "invalid\n");
-               return;
-       }
-       memset(service_name, 0, MAX_SERVICE_NAME_LEN);
-       memcpy(service_name, app_service_name, strlen(app_service_name));
-
-       snprintf(object_name, MAX_SERVICE_NAME_LEN,
-                "/com/samsung/alarm/client");
-
-       SECURE_LOGD("[alarm server][send expired_alarm(alarm_id=%d)to"
-       "app_service_name(%s), object_name(%s), interface_name(%s)]\n",\
-       alarm_id, service_name, object_name, "com.samsung.alarm.client");
-
-       message = dbus_message_new_method_call(service_name,
-                                              object_name,
-                                              "com.samsung.alarm.client",
-                                              "alarm_expired");
-       if (message == NULL) {
-               ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
-                       "dbus_message_new_method_call faild. maybe OOM!.\n");
-               SECURE_LOGE("[alarm server] so we cannot "
-                       "send expired alarm to %s\n", service_name);
-               return;
-       }
-
-       dbus_message_set_no_reply(message, TRUE);
-       /*      if(service_name[0]==':') */
-       /* we don't need auto activation in a case that
-          destination_app_service_name starts with a charactor like (:) */
-       dbus_message_set_auto_start(message, FALSE);
-
-       dbus_message_iter_init_append(message, &iter);
-       if (!dbus_message_iter_append_basic
-               (&iter, DBUS_TYPE_INT32, &alarm_id)) {
-               dbus_message_unref(message);
-               ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
-               "dbus_message_iter_append_basic faild. maybe OOM!.\n");
+               ALARM_MGR_EXCEPTION_PRINT("This alarm destination is invalid.");
                return;
        }
 
-       dbus_connection_send(dbus_g_connection_get_connection
-                            (alarm_context.bus), message, NULL);
-       dbus_connection_flush(dbus_g_connection_get_connection
-                             (alarm_context.bus));
-       dbus_message_unref(message);
-
+       memcpy(service_name, app_service_name, strlen(app_service_name));
+       SECURE_LOGI("[alarm server][send expired_alarm(alarm_id=%d) to app_service_name(%s)]", alarm_id, service_name);
+
+       g_dbus_connection_call(alarm_context.connection,
+                                               service_name,
+                                               "/com/samsung/alarm/client",
+                                               "com.samsung.alarm.client",
+                                               "alarm_expired",
+                                               g_variant_new("(is)", alarm_id, service_name),
+                                               NULL,
+                                               G_DBUS_CALL_FLAGS_NONE,
+                                               -1,
+                                               NULL,
+                                               NULL,
+                                               NULL);
 }
 
 static void __alarm_expired()
@@ -1448,8 +1026,12 @@ static void __alarm_expired()
        int b_len = 0;
        bundle *b = NULL;
        char *appid = NULL;
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+       GError *error = NULL;
+       GVariant *result = NULL;
+       gboolean name_has_owner_reply = false;
 
-       ALARM_MGR_LOG_PRINT("[alarm-server]: Enter \n");
+       ALARM_MGR_LOG_PRINT("[alarm-server]: Enter");
 
        time_t current_time;
        double interval;
@@ -1457,12 +1039,11 @@ static void __alarm_expired()
        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)\n", alarm_context.c_due_time,
-               current_time, interval);
+       ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), current_time(%d), interval(%d)",
+               alarm_context.c_due_time, current_time, interval);
 
        if (alarm_context.c_due_time > current_time + 1) {
-               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: False Alarm. due time is (%d) seconds future\n",
+               ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: False Alarm. due time is (%d) seconds future",
                        alarm_context.c_due_time - current_time);
                goto done;
        }
@@ -1476,8 +1057,7 @@ static void __alarm_expired()
        GSList *iter = NULL;
        __scheduled_alarm_t *alarm = NULL;
 
-       for (iter = g_scheduled_alarm_list; iter != NULL;
-            iter = g_slist_next(iter)) {
+       for (iter = g_scheduled_alarm_list; iter != NULL; iter = g_slist_next(iter)) {
                alarm = iter->data;
                alarm_id = alarm->alarm_id;
 
@@ -1485,15 +1065,12 @@ static void __alarm_expired()
 
                app_pid = __alarm_info->pid;
 
-               if (strncmp
-                   (g_quark_to_string(__alarm_info->quark_bundle),
-                    "null", 4) != 0) {
-
+               if (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 (NULL == b)
+                               if (b == NULL)
                                {
                                        ALARM_MGR_EXCEPTION_PRINT("Error!!!..Unable to decode the bundle!!\n");
                                }
@@ -1501,12 +1078,12 @@ static void __alarm_expired()
                                {
                                        snprintf(alarm_id_val,31,"%d",alarm_id);
 
-                                       if (bundle_add(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){
+                                       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
                                        {
-                                               appid = 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))
                                                {
                                                        ALARM_MGR_EXCEPTION_PRINT("This alarm is ignored\n");
@@ -1529,44 +1106,15 @@ static void __alarm_expired()
                }
                else
                {
-                       if (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)\n",\
-                                       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);
+                       if (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);
                        } else {
-                               SECURE_LOGD("[alarm-server]:destination "
-                                                   ":%s(%u)\n",
-                                       g_quark_to_string(
-                                       __alarm_info->quark_dst_service_name),
-                                       __alarm_info->quark_dst_service_name);
-                                       destination_app_service_name = g_quark_to_string(
-                                               __alarm_info->quark_dst_service_name_mod);
-                       }
-
-#if 0 // vincent.jang def __ALARM_BOOT
-                       /* orginally this code had if(__alarm_info->app_id==21) in a
-                          platform with app-server. */
-                       /*if(__alarm_info->quark_dst_service_name  ==
-                          g_quark_from_string (WAKEUP_ALARM_APP_ID)) */
-                       if (strcmp
-                           (g_quark_to_string(__alarm_info->quark_dst_service_name),
-                            WAKEUP_ALARM_APP_ID) == 0) {
-                               int fd = 0;
-                               fd = open(power_rtc, O_RDONLY);
-                               if (fd < 0) {
-                                       ALARM_MGR_LOG_PRINT("cannot open /dev/rtc0\n");
-                               } else {
-                                       ioctl(fd, RTC_AIE_OFF, 0);
-                                       close(fd);
-                               }
+                               SECURE_LOGD("[alarm-server]:destination :%s(%u)",
+                                       g_quark_to_string(__alarm_info->quark_dst_service_name), __alarm_info->quark_dst_service_name);
+                                       destination_app_service_name = g_quark_to_string(__alarm_info->quark_dst_service_name_mod);
                        }
-#endif
 
                        /*
                         * we should consider a situation that
@@ -1575,15 +1123,27 @@ static void __alarm_expired()
                         * we don't need to send the expire event because the process was killed.
                         * this causes needless message to be sent.
                         */
-                       SECURE_LOGD("[alarm-server]: "
-                                           "destination_app_service_name :%s, app_pid=%d\n",
-                                           destination_app_service_name, app_pid);
-                       /* the following is a code that checks the above situation.
-                          please verify this code. */
-
-                       if (dbus_bus_name_has_owner(
-                            dbus_g_connection_get_connection(alarm_context.bus),
-                            destination_app_service_name, NULL) == FALSE) {
+                       SECURE_LOGD("[alarm-server]: destination_app_service_name :%s, app_pid=%d", destination_app_service_name, app_pid);
+
+                       result = g_dbus_connection_call_sync(alarm_context.connection,
+                                                               "org.freedesktop.DBus",
+                                                               "/org/freedesktop/DBus",
+                                                               "org.freedesktop.DBus",
+                                                               "NameHasOwner",
+                                                               g_variant_new ("(s)", destination_app_service_name),
+                                                               G_VARIANT_TYPE ("(b)"),
+                                                               G_DBUS_CALL_FLAGS_NONE,
+                                                               -1,
+                                                               NULL,
+                                                               &error);
+                       if (result == NULL) {
+                               ALARM_MGR_EXCEPTION_PRINT("g_dbus_connection_call_sync() is failed. err: %s", error->message);
+                               g_error_free(error);
+                       } else {
+                               g_variant_get (result, "(b)", &name_has_owner_reply);
+                       }
+
+                       if (name_has_owner_reply == false) {
                                __expired_alarm_t *expire_info;
                                char appid[MAX_SERVICE_NAME_LEN] = { 0, };
                                char alarm_id_str[32] = { 0, };
@@ -1594,116 +1154,98 @@ static void __alarm_expired()
                                }
 
                                expire_info = malloc(sizeof(__expired_alarm_t));
-                               if (G_UNLIKELY(NULL == expire_info)){
+                               if (G_UNLIKELY(NULL == expire_info)) {
                                        ALARM_MGR_ASSERT_PRINT("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n");
                                        goto done;
                                }
-                               memset(expire_info, '\0', MAX_SERVICE_NAME_LEN);
-                               strncpy(expire_info->service_name,
-                                       destination_app_service_name,
-                                       MAX_SERVICE_NAME_LEN-1);
+                               memset(expire_info, '\0', sizeof(__expired_alarm_t));
+                               strncpy(expire_info->service_name, destination_app_service_name, MAX_SERVICE_NAME_LEN-1);
                                expire_info->alarm_id = alarm_id;
-                               g_expired_alarm_list =
-                                   g_slist_append(g_expired_alarm_list, expire_info);
-
+                               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) {
+                               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
-                               {
+                               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)\n", appid, alarm_id_str);
+                               SECURE_LOGD("before aul_launch appid(%s) alarm_id_str(%s)", appid, alarm_id_str);
 
                                bundle *kb;
                                kb = bundle_create();
-                               bundle_add(kb, "__ALARM_MGR_ID", alarm_id_str);
+                               bundle_add_str(kb, "__ALARM_MGR_ID", alarm_id_str);
                                aul_launch_app(appid, kb);
                                bundle_free(kb);
                        } else {
-                               ALARM_MGR_LOG_PRINT(
-                                       "before alarm_send_noti_to_application\n");
-                               __alarm_send_noti_to_application(
-                                            destination_app_service_name, alarm_id);
+                               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_MGR_LOG_PRINT("after __alarm_send_noti_to_application");
                        }
                }
-               ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application\n");
 
-/*             if( !(__alarm_info->alarm_info.alarm_type
-                                       & ALARM_TYPE_VOLATILE) ) {
-                       __alarm_remove_from_list(__alarm_info->pid,
-                                                       alarm_id, NULL);
-               }
-               else */
-               if (__alarm_info->alarm_info.mode.repeat
-                   == ALARM_REPEAT_MODE_ONCE) {
-/*                      _alarm_next_duetime(__alarm_info);*/
-/*                      _update_alarms(__alarm_info);*/
-                       __alarm_remove_from_list(__alarm_info->pid, alarm_id,
-                                                NULL);
-               } else {
+               ALARM_MGR_EXCEPTION_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);
+               __save_module_log("EXPIRED", log_message);
+               memset(log_message, '\0', sizeof(log_message));
 
+               if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE) {
+                       __alarm_remove_from_list(__alarm_info->pid, alarm_id, NULL);
+               } else {
                        _alarm_next_duetime(__alarm_info);
-/*                      _update_alarms(__alarm_info);*/
                }
-
        }
 
  done:
        _clear_scheduled_alarm_list();
        alarm_context.c_due_time = -1;
 
-       ALARM_MGR_LOG_PRINT("[alarm-server]: Leave  \n");
+       ALARM_MGR_LOG_PRINT("[alarm-server]: Leave");
 }
 
-static gboolean __alarm_handler_idle()
+static gboolean __alarm_handler_idle(gpointer user_data)
 {
-#ifdef WEARABLE_PROFILE
-       display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
-#endif
-       if (g_dummy_timer_is_set == true) {
-               ALARM_MGR_LOG_PRINT("dummy alarm timer has expired\n");
-       } else {
-               ALARM_MGR_LOG_PRINT("__alarm_handler \n");
-               ALARM_MGR_LOG_PRINT("__alarm_handler \n");
+       GPollFD *gpollfd = (GPollFD *) user_data;
+       uint64_t exp;
+       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;
+       }
 
-               __alarm_expired();
+       ALARM_MGR_EXCEPTION_PRINT("Lock the display not to enter LCD OFF");
+       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("__alarm_handler_idle");
+               __alarm_expired();
        }
 
        _alarm_schedule();
 
        __rtc_set();
 
-#ifdef __ALARM_BOOT
-       /*alarm boot */
-       if (enable_power_on_alarm) {
-               /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
-                *in a platform with app-server.because __alarm_power_on(..) fuction
-                *don't use first parameter internally, we set this value to 0(zero)
-                */
-               __alarm_power_on(0, enable_power_on_alarm, NULL);
+       ALARM_MGR_EXCEPTION_PRINT("Unlock the display from LCD OFF");
+       if (__display_unlock_state(DEVICED_LCD_OFF, DEVICED_SLEEP_MARGIN) != ALARMMGR_RESULT_SUCCESS) {
+               ALARM_MGR_EXCEPTION_PRINT("__display_unlock_state() is failed");
        }
-#endif
-#ifdef WEARABLE_PROFILE
-       display_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
-#endif
-       return false;
 
-}
-
-static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext)
-{
-       /* we moved __alarm_expired() function to __alarm_handler_idle GSource
-          because of signal safety. */
-       g_idle_add_full(G_PRIORITY_HIGH, __alarm_handler_idle, NULL, NULL);
+       return false;
 }
 
 static void __clean_registry()
@@ -1714,7 +1256,6 @@ static void __clean_registry()
 
 static bool __alarm_manager_reset()
 {
-
        _alarm_disable_timer(alarm_context);
 
        __alarm_clean_list();
@@ -1725,143 +1266,9 @@ static bool __alarm_manager_reset()
        return true;
 }
 
-static int __alarm_delete_handler(pkgmgrinfo_appinfo_h handle, void* data)
-{
-       char* appid;
-       GSList* gs_iter = NULL;
-       __alarm_info_t* entry = NULL;
-       alarm_info_t* alarm_info = NULL;
-       gchar* bundle_data = NULL;
-       bundle* b = NULL;
-       const char* caller_appid = NULL;
-       const char* callee_appid = NULL;
-       bool isDeleted = false;
-
-       pkgmgrinfo_appinfo_get_appid(handle, &appid);   // uninstalled app id
-       SECURE_LOGD("The uninstalled appid is [%s]\n", appid);
-
-       // If the uninstalled app is same to caller or callee app, all alarms registered in the app will be deleted.
-       for (gs_iter = alarm_context.alarms; gs_iter != NULL; )
-       {
-               bool isFound = false;
-               entry = gs_iter->data;
-
-               bundle_data = g_strdup(g_quark_to_string(entry->quark_bundle));
-               b = bundle_decode((bundle_raw*)bundle_data, strlen(bundle_data));
-               caller_appid = bundle_get_val(b, "__ALARM_MGR_CALLER_APPID");
-               callee_appid = appsvc_get_appid(b);
-
-               SECURE_LOGD("Try to remove alarm_id[%d], caller_appid[%s], callee_appid[%s]", entry->alarm_id, caller_appid, callee_appid);
-
-               if (strcmp(appid, caller_appid) == 0 || strcmp(appid, callee_appid) == 0)
-               {
-                       if (_remove_from_scheduled_alarm_list(appid, entry->alarm_id))
-                       {
-                               isDeleted = true;
-                       }
-
-                       alarm_info = &entry->alarm_info;
-                       if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
-                       {
-                               if(!_delete_alarms(entry->alarm_id))
-                               {
-                                       SECURE_LOGD("_delete_alarms() is failed. appid[%s], alarm_id[%d]", appid, entry->alarm_id);
-                               }
-                       }
-                       SECURE_LOGD("Removing is done! alarm_id[%d]", entry->alarm_id);
-                       isFound = true;
-               }
-
-               gs_iter = g_slist_next(gs_iter);
-
-               if (isFound)
-               {
-                       alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry);
-               }
-       }
-
-       if (isDeleted && (g_slist_length(g_scheduled_alarm_list) == 0))
-       {
-               _alarm_disable_timer(alarm_context);
-               _alarm_schedule();
-       }
-
-       __rtc_set();
-
-       return 0;
-}
-
-static void __alarm_delete_for_webapp(char* pkgid)
-{
-       GSList* gs_iter = NULL;
-       __alarm_info_t* entry = NULL;
-       alarm_info_t* alarm_info = NULL;
-       gchar* bundle_data = NULL;
-       bundle* b = NULL;
-       const char* caller_appid = NULL;
-       const char* callee_appid = NULL;
-       const char* appid = NULL;
-       bool isDeleted = false;
-
-       SECURE_LOGD("The uninstalled pkgid of webapp is [%s]\n", pkgid);
-
-       // If the uninstalled web app(wgt) is same to caller or callee app, all alarms registered in the app will be deleted.
-       for (gs_iter = alarm_context.alarms; gs_iter != NULL; )
-       {
-               entry = gs_iter->data;
-
-               bundle_data = g_strdup(g_quark_to_string(entry->quark_bundle));
-               b = bundle_decode((bundle_raw*)bundle_data, strlen(bundle_data));
-               caller_appid = bundle_get_val(b, "__ALARM_MGR_CALLER_APPID");
-               callee_appid = appsvc_get_appid(b);
-
-               SECURE_LOGD("Try to remove alarm_id[%d], caller_appid[%s], callee_appid[%s]", entry->alarm_id, caller_appid, callee_appid);
-
-               if (strncmp(pkgid, caller_appid, 10) == 0)
-               {
-                       appid = caller_appid;
-               }
-               else if (strncmp(pkgid, callee_appid, 10) == 0)
-               {
-                       appid = callee_appid;
-               }
-               else
-               {
-                       gs_iter = g_slist_next(gs_iter);
-                       continue;
-               }
-
-               if (_remove_from_scheduled_alarm_list(appid, entry->alarm_id))
-               {
-                       isDeleted = true;
-               }
-
-               alarm_info = &entry->alarm_info;
-               if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
-               {
-                       if(!_delete_alarms(entry->alarm_id))
-                       {
-                               SECURE_LOGD("_delete_alarms() is failed. appid[%s], alarm_id[%d]", appid, entry->alarm_id);
-                       }
-               }
-               SECURE_LOGD("Removing is done! alarm_id[%d]", entry->alarm_id);
-
-               gs_iter = g_slist_next(gs_iter);
-               alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry);
-       }
-
-       if (isDeleted && (g_slist_length(g_scheduled_alarm_list) == 0))
-       {
-               _alarm_disable_timer(alarm_context);
-               _alarm_schedule();
-       }
-
-       __rtc_set();
-}
-
 static void __on_system_time_external_changed(keynode_t *node, void *data)
 {
-       double diff_time;
+       double diff_time = 0.0;
        time_t cur_time = 0;
 
        _alarm_disable_timer(alarm_context);
@@ -1869,7 +1276,10 @@ static void __on_system_time_external_changed(keynode_t *node, void *data)
        if (node) {
                diff_time = vconf_keynode_get_dbl(node);
        } else {
-               vconf_get_dbl(VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, &diff_time);
+               if (vconf_get_dbl(VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, &diff_time) != VCONF_OK) {
+                       ALARM_MGR_EXCEPTION_PRINT("Failed to get value of VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL.");
+                       return;
+               }
        }
 
        tzset();
@@ -1893,17 +1303,7 @@ static void __on_system_time_external_changed(keynode_t *node, void *data)
        _clear_scheduled_alarm_list();
        _alarm_schedule();
        __rtc_set();
-#ifdef __ALARM_BOOT
-       /*alarm boot */
-       if (enable_power_on_alarm) {
-/* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
-APP_ID) in a platform with app-server. because _alarm_power_
-on(..) fuction don't use first parameter internally, we set
-this value to 0(zero)
-*/
-               __alarm_power_on(0, enable_power_on_alarm, NULL);
-       }
-#endif
+
        return;
 }
 
@@ -1924,17 +1324,7 @@ static void __on_time_zone_changed(keynode_t *node, void *data)
        _clear_scheduled_alarm_list();
        _alarm_schedule();
        __rtc_set();
-#ifdef __ALARM_BOOT
-       /*alarm boot */
-       if (enable_power_on_alarm) {
-/* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
-APP_ID) in a platform with app-server. because _alarm_power_
-on(..) fuction don't use first parameter internally, we set
-this value to 0(zero)
-*/
-               __alarm_power_on(0, enable_power_on_alarm, NULL);
-       }
-#endif
+
        return;
 }
 
@@ -1942,186 +1332,431 @@ 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)
 {
-       pkgmgrinfo_pkginfo_h handle;
+       GSList* gs_iter = NULL;
+       __alarm_info_t* entry = NULL;
+       alarm_info_t* alarm_info = NULL;
+       bool is_deleted = false;
 
        SECURE_LOGD("pkg_type(%s), pkgid(%s), key(%s), value(%s)", pkg_type, pkgid, key, val);
 
-       if (strncmp(key, "start", 5) == 0 && strncmp(val, "uninstall", 9) == 0)
+       if (strncmp(key, "end", 3) == 0 && strncmp(val, "ok", 2) == 0)
        {
-               if (strncmp(pkg_type, "wgt", 3) != 0)
+               for (gs_iter = alarm_context.alarms; gs_iter != NULL; )
                {
-                       if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle) != PMINFO_R_OK)
+                       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);
+
+                       if ((caller_pkgid && strncmp(pkgid, caller_pkgid, strlen(pkgid)) == 0) ||
+                               (callee_pkgid && strncmp(pkgid, callee_pkgid, strlen(pkgid)) == 0))
                        {
-                               ALARM_MGR_EXCEPTION_PRINT("Getting package info is failed.\n");
-                               return PMINFO_R_ERROR;
+                               if (_remove_from_scheduled_alarm_list(pkgid, entry->alarm_id))
+                               {
+                                       is_deleted = true;
+                               }
+
+                               alarm_info = &entry->alarm_info;
+                               if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
+                               {
+                                       if(!_delete_alarms(entry->alarm_id))
+                                       {
+                                               SECURE_LOGE("_delete_alarms() is failed. pkgid[%s], alarm_id[%d]", pkgid, entry->alarm_id);
+                                       }
+                               }
+                               is_found = true;
                        }
 
-                       if (pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __alarm_delete_handler, user_data) != PMINFO_R_OK)
+                       gs_iter = g_slist_next(gs_iter);
+
+                       if (is_found)
                        {
-                               ALARM_MGR_EXCEPTION_PRINT("Getting package list is failed.\n");
-                               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-                               return PMINFO_R_ERROR;
+                               SECURE_LOGD("Remove pkgid[%s], alarm_id[%d]", pkgid, entry->alarm_id);
+                               alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry);
+                               g_free(entry);
                        }
-
-                       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
                }
-       }
-       else if (strncmp(key, "end", 3) == 0 && strncmp(val, "ok", 2) == 0)
-       {
-               if (strncmp(pkg_type, "wgt", 3) == 0)
+
+               if (is_deleted && (g_slist_length(g_scheduled_alarm_list) == 0))
                {
-                       __alarm_delete_for_webapp(pkgid);
+                       _alarm_disable_timer(alarm_context);
+                       _alarm_schedule();
                }
        }
 
-       return PMINFO_R_OK;
+       __rtc_set();
+
+       return ALARMMGR_RESULT_SUCCESS;
 }
 
-gboolean alarm_manager_alarm_set_rtc_time(void *pObject, int pid,
-                               int year, int mon, int day,
-                               int hour, int min, int sec, char *e_cookie,
-                               int *return_code){
+int __check_privilege_by_cookie(char *e_cookie, const char *label, const char *access, bool check_root, int pid) {
        guchar *cookie = NULL;
-       gsize size;
+       gsize size = 0;
        int retval = 0;
-       gboolean result = true;
+       char buf[128] = {0,};
+       FILE *fp = NULL;
+       char title[128] = {0,};
+       int uid = -1;
 
-       const char *rtc = default_rtc;
-       struct timespec alarm_time;
+       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);
+               }
 
-       struct rtc_time rtc_tm = {0,};
-       struct rtc_wkalrm rtc_wk;
-       struct tm *alarm_tm = NULL;
+               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;
+               }
+
+               retval = security_server_check_privilege_by_cookie((const char *)cookie, label, access);
+               g_free(cookie);
 
-       if (return_code){
-               *return_code = ALARMMGR_RESULT_SUCCESS;
+               if (retval < 0) {
+                       if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
+                               ALARM_MGR_EXCEPTION_PRINT("Access to alarm-server has been denied by smack.");
+                       }
+                       ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege_by_cookie() : %d.", retval);
+                       return ERR_ALARM_NO_PERMISSION;
+               }
        }
 
-       cookie = g_base64_decode(e_cookie, &size);
-       if (NULL == cookie)
+       ALARM_MGR_LOG_PRINT("The process(%d) was authenticated successfully.", pid);
+       return ALARMMGR_RESULT_SUCCESS;
+}
+
+bool __get_caller_unique_name(int pid, char *unique_name)
+{
+       char caller_appid[256] = {0,};
+
+       if (unique_name == NULL)
        {
-               if (return_code)
-                       *return_code = ERR_ALARM_NO_PERMISSION;
-               ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
-               return true;
+               ALARM_MGR_EXCEPTION_PRINT("unique_name should not be NULL.");
+               return false;
        }
 
-       retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "w");
-       if (retval < 0) {
-               if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
-                       ALARM_MGR_EXCEPTION_PRINT(
-                               "%s", "Write access has been denied by smack\n");
-               }
-               ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
-               if (return_code)
-                       *return_code = ERR_ALARM_NO_PERMISSION;
+       if (aul_app_get_appid_bypid(pid, caller_appid, sizeof(caller_appid)) == AUL_R_OK)
+       {
+               // When a caller is an application, the unique name is appID.
+               strncpy(unique_name, caller_appid, strlen(caller_appid));
        }
        else
        {
-               /*extract day of the week, day in the year &
-               daylight saving time from system*/
-               time_t ctime;
-               ctime = time(NULL);
-               alarm_tm = localtime(&ctime);
-
-               alarm_tm->tm_year = year;
-               alarm_tm->tm_mon = mon;
-               alarm_tm->tm_mday = day;
-               alarm_tm->tm_hour = hour;
-               alarm_tm->tm_min = min;
-               alarm_tm->tm_sec = sec;
-
-               /*convert to calendar time representation*/
-               time_t rtc_time = mktime(alarm_tm);
-
-               if (gfd == 0) {
-                       gfd = open(rtc, O_RDWR);
-                       if (gfd == -1) {
-                               ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
-                               if (return_code)
-                                       *return_code = ERR_ALARM_SYSTEM_FAIL;
-                               return result;
-                       }
-               }
+               // Otherwise, the unique name is /proc/pid/cmdline.
+               char proc_file[512] = {0,};
+               char process_name[512] = {0,};
+               int fd = 0;
+               int i = 0;
 
-               alarm_time.tv_sec = rtc_time;
-               alarm_time.tv_nsec = 0;
+               snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
 
-               retval = ioctl(gfd, ALARM_SET(ALARM_RTC_WAKEUP), &alarm_time);
-               if (retval == -1) {
-                       if (errno == ENOTTY) {
-                               ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
-                                                         "supported.\n");
+               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);
+                       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;
                        }
-                       ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
-                       //close(fd);
-                       if (return_code)
-                               *return_code = ERR_ALARM_SYSTEM_FAIL;
+                       strncpy(unique_name, process_name, strlen(process_name));
                }
-               else{
-                       ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
-                       //close(fd);
+       }
+
+       SECURE_LOGD("unique_name= %s", unique_name);
+       return true;
+}
+
+static void __initialize_module_log(void)
+{
+       log_fd = open(ALARMMGR_LOG_FILE_PATH, O_CREAT | O_WRONLY, 0644);
+       if (log_fd == -1) {
+               ALARM_MGR_EXCEPTION_PRINT("Opening the file for alarmmgr log is failed.");
+               return;
+       }
+
+       int offset = lseek(log_fd, 0, SEEK_END);
+       if (offset != 0) {
+               log_index = (int)(offset / ALARMMGR_LOG_BUFFER_STRING_SIZE);
+               if (log_index >= ALARMMGR_LOG_BUFFER_SIZE) {
+                       log_index = 0;
+                       lseek(log_fd, 0, SEEK_SET);
                }
        }
+       return;
+}
 
-       if (cookie){
-               g_free(cookie);
-               cookie = NULL;
+static bool __save_module_log(const char *tag, const char *message)
+{
+       char buffer[ALARMMGR_LOG_BUFFER_STRING_SIZE] = {0,};
+       time_t now;
+       int offset = 0;
+
+       if (log_fd == -1) {
+               ALARM_MGR_EXCEPTION_PRINT("The file is not ready.");
+               return false;
+       }
+
+       if (log_index != 0) {
+               offset = lseek(log_fd, 0, SEEK_CUR);
+       } else {
+               offset = lseek(log_fd, 0, SEEK_SET);
        }
 
-       return result;
+       time(&now);
+       snprintf(buffer, ALARMMGR_LOG_BUFFER_STRING_SIZE, "[%-6d] %-20s %-120s %d-%s", log_index, tag, message, (int)now, ctime(&now));
 
+       int ret = write(log_fd, buffer, strlen(buffer));
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("Writing the alarmmgr log is failed.");
+               return false;
+       }
+
+       if (++log_index >= ALARMMGR_LOG_BUFFER_SIZE) {
+               log_index = 0;
+       }
+       return true;
 }
 
-gboolean alarm_manager_alarm_set_time(void *pObject, int _time, int *return_code)
+int __display_lock_state(char *state, char *flag, unsigned int timeout)
 {
-       double diff_time;
-       time_t before;
-       gboolean result = true;
+       GDBusMessage *msg = NULL;
+       GDBusMessage *reply = NULL;
+       GVariant *body = NULL;
+       GError *error = NULL;
+       int ret = ALARMMGR_RESULT_SUCCESS;
+       int val = -1;
+
+       msg = g_dbus_message_new_method_call(DEVICED_BUS_NAME, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, DEVICED_LOCK_STATE);
+       if (!msg) {
+               ALARM_MGR_EXCEPTION_PRINT("g_dbus_message_new_method_call() is failed. (%s:%s-%s)", DEVICED_BUS_NAME, DEVICED_INTERFACE_DISPLAY, DEVICED_LOCK_STATE);
+               return ERR_ALARM_SYSTEM_FAIL;
+       }
+
+       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);
+       if (!reply) {
+               ALARM_MGR_EXCEPTION_PRINT("No reply. error = %s", error->message);
+               g_error_free(error);
+               ret = ERR_ALARM_SYSTEM_FAIL;
+       } else {
+               body = g_dbus_message_get_body(reply);
+               if (!body) {
+                       ALARM_MGR_EXCEPTION_PRINT("g_dbus_message_get_body() is failed.");
+                       ret = ERR_ALARM_SYSTEM_FAIL;
+               } else {
+                       g_variant_get(body, "(i)", &val);
+                       if (val != 0) {
+                               ALARM_MGR_EXCEPTION_PRINT("Failed to lock display");
+                               ret = ERR_ALARM_SYSTEM_FAIL;
+                       } else {
+                               ALARM_MGR_EXCEPTION_PRINT("Lock LCD OFF is successfully done");
+                       }
+               }
+       }
+
+       g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL);
+       g_object_unref(msg);
+       g_object_unref(reply);
+
+       return ret;
+}
+
+int __display_unlock_state(char *state, char *flag)
+{
+       GDBusMessage *msg = NULL;
+       GDBusMessage *reply = NULL;
+       GVariant *body = NULL;
+       GError *error = NULL;
+       int ret = ALARMMGR_RESULT_SUCCESS;
+       int val = -1;
+
+       msg = g_dbus_message_new_method_call(DEVICED_BUS_NAME, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, DEVICED_UNLOCK_STATE);
+       if (!msg) {
+               ALARM_MGR_EXCEPTION_PRINT("g_dbus_message_new_method_call() is failed. (%s:%s-%s)", DEVICED_BUS_NAME, DEVICED_INTERFACE_DISPLAY, DEVICED_UNLOCK_STATE);
+               return ERR_ALARM_SYSTEM_FAIL;
+       }
+
+       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);
+       if (!reply) {
+               ALARM_MGR_EXCEPTION_PRINT("No reply. error = %s", error->message);
+               g_error_free(error);
+               ret = ERR_ALARM_SYSTEM_FAIL;
+       } else {
+               body = g_dbus_message_get_body(reply);
+               if (!body) {
+                       ALARM_MGR_EXCEPTION_PRINT("g_dbus_message_get_body() is failed.");
+                       ret = ERR_ALARM_SYSTEM_FAIL;
+               } else {
+                       g_variant_get(body, "(i)", &val);
+                       if (val != 0) {
+                               ALARM_MGR_EXCEPTION_PRINT("Failed to unlock display");
+                               ret = ERR_ALARM_SYSTEM_FAIL;
+                       } else {
+                               ALARM_MGR_EXCEPTION_PRINT("Unlock LCD OFF is successfully done");
+                       }
+               }
+       }
 
-       if (return_code){
-               *return_code = ALARMMGR_RESULT_SUCCESS;
+       g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL);
+       g_object_unref(msg);
+       g_object_unref(reply);
+
+       return ret;
+}
+
+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,
+                               gpointer user_data) {
+       const char *rtc = default_rtc;
+       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;
+
+       char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+
+       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("(i)", return_code));
+               return true;
+       }
+
+       /*extract day of the week, day in the year & daylight saving time from system*/
+       time_t current_time;
+       current_time = time(NULL);
+       alarm_tm = localtime(&current_time);
+
+       alarm_tm->tm_year = year;
+       alarm_tm->tm_mon = mon;
+       alarm_tm->tm_mday = day;
+       alarm_tm->tm_hour = hour;
+       alarm_tm->tm_min = min;
+       alarm_tm->tm_sec = sec;
+
+       /*convert to calendar time representation*/
+       time_t rtc_time = mktime(alarm_tm);
+
+       if (gfd == 0) {
+               gfd = open(rtc, O_RDWR);
+               if (gfd == -1) {
+                       ALARM_MGR_EXCEPTION_PRINT("RTC open failed.");
+                       return_code = ERR_ALARM_SYSTEM_FAIL;
+                       g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+                       return true;
+               }
        }
 
+       alarm_time.tv_sec = rtc_time;
+       alarm_time.tv_nsec = 0;
+
+       retval = ioctl(gfd, ALARM_SET(ALARM_RTC_WAKEUP), &alarm_time);
+       if (retval == -1) {
+               if (errno == ENOTTY) {
+                       ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
+               }
+               ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror(errno));
+               return_code = ERR_ALARM_SYSTEM_FAIL;
+               strncpy(log_tag, "FAIL: SET RTC", strlen("FAIL: SET RTC"));
+       }
+       else{
+               ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
+               strncpy(log_tag, "SET RTC", strlen("SET RTC"));
+       }
+
+       sprintf(log_message, "wakeup rtc time: %d, %s", rtc_time, ctime(&rtc_time));
+       __save_module_log(log_tag, log_message);
+
+       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 diff_msec = 0;       // To check a millisecond part of current time at changing the system time
+       double diff_time = 0.0;
+       struct timeval before;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+
        _alarm_disable_timer(alarm_context);
 
-       time(&before);
-       diff_time = difftime(_time, before);
+       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);
+
+       if (diff_msec > 500) {
+               diff_time = difftime(_time, before.tv_sec) - 1;
+               diff_msec -= 1000;
+       }
+       else {
+               diff_time = difftime(_time, before.tv_sec);
+       }
 
        tzset();
 
-       ALARM_MGR_EXCEPTION_PRINT("New time is %s, diff_time is %f\n", ctime(&_time), diff_time);
+       char *timebuf = ctime(&_time);
+       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);
 
-       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);
+       ALARM_MGR_EXCEPTION_PRINT("[TIMESTAMP]Current time(%d), New time(%d)(%s), diff_time(%f)", before.tv_sec, _time, ctime(&_time), diff_time);
 
-       _set_time(_time-1);
-       vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)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);
 
+       _set_time(_time - 1);
        __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();
        _set_time(_time);
-#ifdef __ALARM_BOOT
-       /*alarm boot */
-       if (enable_power_on_alarm) {
-       /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
-       APP_ID) in a platform with app-server. because _alarm_power_
-       on(..) fuction don't use first parameter internally, we set
-       this value to 0(zero)
-       */
-                       __alarm_power_on(0, enable_power_on_alarm, NULL);
-               }
-#endif
-       return result;
+
+       vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
+
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+       return true;
 }
 
-gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid,
+gboolean alarm_manager_alarm_create_appsvc(AlarmManager *pObject, GDBusMethodInvocation *invoc,
+                                       int pid,
                                    int start_year,
                                    int start_month, int start_day,
                                    int start_hour, int start_min,
@@ -2130,13 +1765,24 @@ gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid,
                                    int mode_repeat, int alarm_type,
                                    int reserved_info,
                                    char *bundle_data, char *e_cookie,
-                                   int *alarm_id, int *return_code)
+                                   gpointer user_data)
 {
        alarm_info_t alarm_info;
-       guchar *cookie = NULL;
-       gsize size;
        int retval = 0;
-       gboolean result = true;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       int alarm_id = 0;
+       char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+       bool ret = true;
+
+       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);
+               __save_module_log("FAIL: CREATE", log_message);
+               return true;
+       }
 
        alarm_info.start.year = start_year;
        alarm_info.start.month = start_month;
@@ -2150,50 +1796,30 @@ gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid,
        alarm_info.end.day = end_day;
 
        alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
-       alarm_info.mode.repeat = mode_repeat;
-
-       alarm_info.alarm_type = alarm_type;
-       alarm_info.reserved_info = reserved_info;
-
-       *return_code = 0;
-
-       cookie = g_base64_decode(e_cookie, &size);
-       if (NULL == cookie)
-       {
-               *return_code = -1;
-               ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
-               return false;
-       }
-
-       retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "w");
-       if (retval < 0) {
-               if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
-                       ALARM_MGR_EXCEPTION_PRINT(
-                               "%s", "Write access has been denied by smack\n");
-               }
-               ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
-               *return_code = ERR_ALARM_NO_PERMISSION;
-               result = false;
-       }
-       else
-       {
-               result = __alarm_create_appsvc(&alarm_info, alarm_id, pid,
-                              bundle_data, return_code);
-               if (false == result)
-               {
-                       ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm!\n");
-               }
-       }
+       alarm_info.mode.repeat = mode_repeat;
 
-       if (cookie){
-               g_free(cookie);
-               cookie = NULL;
+       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)) {
+               ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
+               strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
+               ret = false;
+       } else {
+               strncpy(log_tag, "CREATE", strlen("CREATE"));
+               ret = true;
        }
 
-       return result;
+       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",
+               alarm_id, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
+       __save_module_log(log_tag, log_message);
+
+       return ret;
 }
 
-gboolean alarm_manager_alarm_create(void *pObject, int pid,
+gboolean alarm_manager_alarm_create(AlarmManager *obj, GDBusMethodInvocation *invoc, int pid,
                                    char *app_service_name, char *app_service_name_mod,  int start_year,
                                    int start_month, int start_day,
                                    int start_hour, int start_min,
@@ -2202,16 +1828,24 @@ gboolean alarm_manager_alarm_create(void *pObject, int pid,
                                    int mode_repeat, int alarm_type,
                                    int reserved_info,
                                    char *reserved_service_name, char *reserved_service_name_mod, char *e_cookie,
-                                   int *alarm_id, int *return_code)
+                                   gpointer user_data)
 {
        alarm_info_t alarm_info;
-       guchar *cookie;
-       gsize size;
        int retval = 0;
-       char buf[128];
-       FILE *fp = NULL;
-       char title[128];
-       int uid = -1;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       int alarm_id = 0;
+       char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+       bool ret = true;
+
+       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);
+               __save_module_log("FAIL: CREATE", log_message);
+               return true;
+       }
 
        alarm_info.start.year = start_year;
        alarm_info.start.month = start_month;
@@ -2230,171 +1864,104 @@ gboolean alarm_manager_alarm_create(void *pObject, int pid,
        alarm_info.alarm_type = alarm_type;
        alarm_info.reserved_info = reserved_info;
 
-       *return_code = 0;
-
-       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);
+       if (!__alarm_create(&alarm_info, &alarm_id, pid, app_service_name,app_service_name_mod,
+                      reserved_service_name, reserved_service_name_mod, &return_code)) {
+               ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
+               strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
+               ret = false;
+       } else {
+               strncpy(log_tag, "CREATE", strlen("CREATE"));
+               ret = true;
        }
 
-       ALARM_MGR_LOG_PRINT("uid :%d", uid);
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
 
-       if(uid != 0) {
-               cookie = g_base64_decode(e_cookie, &size);
-               retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "w");
-       }
-
-       if (retval < 0) {
-               if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
-                       ALARM_MGR_EXCEPTION_PRINT(
-                               "Write access has been denied by smack\n");
-               }
-               ALARM_MGR_EXCEPTION_PRINT("Error has occurred\n");
-               *return_code = ERR_ALARM_NO_PERMISSION;
-       }
-       else
-       {
-               /* return valule and return_code should be checked */
-               __alarm_create(&alarm_info, alarm_id, pid, app_service_name,app_service_name_mod,
-                              reserved_service_name, reserved_service_name_mod, return_code);
-       }
-       if(uid != 0)
-               g_free(cookie);
+       sprintf(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);
 
-       return true;
+       return ret;
 }
 
-gboolean alarm_manager_alarm_delete(void *pObject, int pid, alarm_id_t alarm_id,
-                                   char *e_cookie, int *return_code)
+gboolean alarm_manager_alarm_delete(AlarmManager *obj, GDBusMethodInvocation *invoc,
+                                       int pid, alarm_id_t alarm_id,
+                                   char *e_cookie, gpointer user_data)
 {
-       guchar *cookie;
-       gsize size;
        int retval = 0;
-       char buf[128];
-       FILE *fp = NULL;
-       char title[128];
-       int uid = -1;
-
-       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);
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+       bool ret = true;
+
+       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);
+               __save_module_log("FAIL: DELETE", log_message);
+               return true;
        }
 
-       ALARM_MGR_LOG_PRINT("uid :%d", uid);
-
-       if(uid != 0) {
-               cookie = g_base64_decode(e_cookie, &size);
-               retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "w");
+       if (!__alarm_delete(pid, alarm_id, &return_code)) {
+               ALARM_MGR_EXCEPTION_PRINT("Unable to delete the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code);
+               strncpy(log_tag, "FAIL: DELETE", strlen("FAIL: DELETE"));
+               ret = false;
+       } else {
+               ALARM_MGR_EXCEPTION_PRINT("alarm_id[%d] is removed.", alarm_id);
+               strncpy(log_tag, "DELETE", strlen("DELETE"));
+               ret = true;
        }
 
-       if (retval < 0) {
-               if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
-                       ALARM_MGR_EXCEPTION_PRINT(
-                               "Write access has been denied by smack\n");
-               }
-               ALARM_MGR_EXCEPTION_PRINT("Error has occurred\n");
-               *return_code = ERR_ALARM_NO_PERMISSION;
-       }
-       else
-       {
-               __alarm_delete(pid, alarm_id, return_code);
-       }
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
 
-       if(uid != 0)
-               g_free(cookie);
+       sprintf(log_message, "alarmID: %d, pid: %d", alarm_id, pid);
+       __save_module_log(log_tag, log_message);
 
-       return true;
+       return ret;
 }
 
-gboolean alarm_manager_alarm_delete_all(void *pObject, int pid, int* return_code)
+gboolean alarm_manager_alarm_delete_all(AlarmManager *obj, GDBusMethodInvocation *invoc,
+                                       int pid, char *e_cookie, gpointer user_data)
 {
        GSList* gs_iter = NULL;
-       GQuark quark_app_unique_name;   // the fullpath of pid(pid) is converted to quark value.
-       char proc_file[256] = { 0 };
-       char process_name[512] = { 0 };
-       char app_name[256] = { 0 };
-       char* word = NULL;
+       char app_name[512] = { 0 };
        alarm_info_t* alarm_info = NULL;
        __alarm_info_t* entry = NULL;
-       char* proc_name_ptr = NULL;
-       int fd;
-       int ret;
-       int i = 0;
-       bool isDeleted = false;
-       *return_code = ALARMMGR_RESULT_SUCCESS;
-
-       // we should consider to check whether  pid is running or Not
-       memset(process_name, '\0', 512);
-       memset(proc_file, '\0', 256);
-       snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
-
-       fd = open(proc_file, O_RDONLY);
-       if (fd < 0)
-       {
-               quark_app_unique_name = g_quark_from_string("unknown");
-               memcpy(app_name, "unknown", strlen("unknown") + 1);
-
-               SECURE_LOGE("Caution!! app_pid(%d) seems to be killed. so we failed to get proc file(%s)\n", pid, proc_file);
-               *return_code = ERR_ALARM_SYSTEM_FAIL;
+       bool is_deleted = false;
+       int retval = 0;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+
+       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);
+               __save_module_log("FAIL: DELETE ALL", log_message);
                return true;
        }
-       else
-       {
-               ret = read(fd, process_name, 512);
-               if (ret < 0)
-               {
-                       *return_code = ERR_ALARM_SYSTEM_FAIL;
-                       close(fd);
-                       return true;
-               }
-               close(fd);
-               while (process_name[i] != '\0')
-               {
-                       if (process_name[i] == ' ')
-                       {
-                               process_name[i] = '\0';
-                               break;
-                       }
-                       i++;
-               }
 
-               word = strtok_r(process_name, "/", &proc_name_ptr);
-               while (word != NULL)
-               {
-                       memset(app_name, 0, 256);
-                       snprintf(app_name, 256, "%s", word);
-                       word = strtok_r(NULL, "/", &proc_name_ptr);
-               }
-               quark_app_unique_name = g_quark_from_string(app_name);
+       if (!__get_caller_unique_name(pid, app_name)) {
+               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);
+               __save_module_log("FAIL: DELETE ALL", log_message);
+               return true;
        }
 
-       SECURE_LOGD("called for app(pid:%d, name=%s)\n", pid, app_name);
+       SECURE_LOGD("Called by process (pid:%d, unique_name=%s)", pid, app_name);
 
        for (gs_iter = alarm_context.alarms; gs_iter != NULL; )
        {
-               bool isFound = false;
+               bool is_found = false;
                entry = gs_iter->data;
-               SECURE_LOGD("Try to remove app_name[%s], alarm_id[%d]\n", g_quark_to_string(entry->quark_app_unique_name), entry->alarm_id);
-               if (strcmp(app_name, g_quark_to_string(entry->quark_app_unique_name)) == 0
-                       && strcmp(app_name, "unknown") != 0)
+               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)
                {
                        if (_remove_from_scheduled_alarm_list(pid, entry->alarm_id))
                        {
-                               isDeleted = true;
+                               is_deleted = true;
                        }
 
                        alarm_info = &entry->alarm_info;
@@ -2405,49 +1972,32 @@ gboolean alarm_manager_alarm_delete_all(void *pObject, int pid, int* return_code
                                        SECURE_LOGE("_delete_alarms() is failed. pid[%d], alarm_id[%d]", pid, entry->alarm_id);
                                }
                        }
-                       SECURE_LOGD("Removing is done. app_name[%s], alarm_id [%d]\n", g_quark_to_string(entry->quark_app_unique_name), entry->alarm_id);
-                       isFound = true;
+                       is_found = true;
                }
 
                gs_iter = g_slist_next(gs_iter);
 
-               if (isFound)
+               if (is_found)
                {
+                       ALARM_MGR_EXCEPTION_PRINT("alarm_id[%d] is removed.", entry->alarm_id);
+                       SECURE_LOGD("Removing is done. app_name[%s], alarm_id [%d]\n", tmp_appname, entry->alarm_id);
                        alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry);
+                       g_free(entry);
                }
        }
 
-       if (isDeleted && (g_slist_length(g_scheduled_alarm_list) == 0))
+       if (is_deleted && (g_slist_length(g_scheduled_alarm_list) == 0))
        {
                _alarm_disable_timer(alarm_context);
                _alarm_schedule();
        }
 
        __rtc_set();
-
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
        return true;
 }
 
-gboolean alarm_manager_alarm_power_on(void *pObject, int pid, bool on_off,
-                                     int *return_code)
-{
-
-       return __alarm_power_on(pid, on_off, return_code);
-}
-
-gboolean alarm_manager_alarm_power_off(void *pObject, int pid, int *return_code)
-{
-
-       return __alarm_power_off(pid, return_code);
-}
-
-bool alarm_manager_alarm_check_next_duetime(void *pObject, int pid,
-                                           int *return_code)
-{
-       return __alarm_check_next_duetime(pid, return_code);
-}
-
-gboolean alarm_manager_alarm_update(void *pObject, int pid,
+gboolean alarm_manager_alarm_update(AlarmManager *pObj, GDBusMethodInvocation *invoc, int pid,
                                    char *app_service_name, alarm_id_t alarm_id,
                                    int start_year, int start_month,
                                    int start_day, int start_hour,
@@ -2455,9 +2005,14 @@ gboolean alarm_manager_alarm_update(void *pObject, int pid,
                                    int end_month, int end_day,
                                    int mode_day_of_week, int mode_repeat,
                                    int alarm_type, int reserved_info,
-                                   int *return_code)
+                                   gpointer user_data)
 {
+       int return_code = ALARMMGR_RESULT_SUCCESS;
        alarm_info_t alarm_info;
+       bool ret = true;
+       char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+       char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+
        alarm_info.start.year = start_year;
        alarm_info.start.month = start_month;
        alarm_info.start.day = start_day;
@@ -2475,293 +2030,172 @@ gboolean alarm_manager_alarm_update(void *pObject, int pid,
        alarm_info.alarm_type = alarm_type;
        alarm_info.reserved_info = reserved_info;
 
-       *return_code = 0;
+       if (!__alarm_update(pid, app_service_name, alarm_id, &alarm_info, &return_code)) {
+               ALARM_MGR_EXCEPTION_PRINT("Unable to update the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code);
+               strncpy(log_tag, "FAIL: UPDATE", strlen("FAIL: UPDATE"));
+               ret = false;
+       } else {
+               strncpy(log_tag, "UPDATE", strlen("UPDATE"));
+               ret = true;
+       }
 
-       __alarm_update(pid, app_service_name, alarm_id, &alarm_info,
-                      return_code);
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
 
-       return true;
+       sprintf(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);
+
+       return ret;
 }
 
-gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid,
-                                              int *num_of_ids,
-                                              int *return_code)
+gboolean alarm_manager_alarm_get_number_of_ids(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid, char *e_cookie,
+                                              gpointer user_data)
 {
        GSList *gs_iter = NULL;
-       GQuark quark_app_unique_name;   /* the fullpath of pid(pid) is
-                                          converted  to quark value. */
-       char proc_file[256] = { 0 };
-       char process_name[512] = { 0 };
        char app_name[256] = { 0 };
-       char *word = NULL;
        __alarm_info_t *entry = NULL;
-       char *proc_name_ptr = NULL;
-
-       *num_of_ids = 0;
-       *return_code = 0;
+       int retval = 0;
+       int num_of_ids = 0;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
 
-       /* we should consider to check whether  pid is running or Not
-        */
-       memset(process_name, '\0', 512);
-       memset(proc_file, '\0', 256);
-       snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
+       retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
+       if (retval != ALARMMGR_RESULT_SUCCESS) {
+               return_code = retval;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
+               return true;
+       }
 
-       int fd;
-       int ret;
-       int i = 0;
-       fd = open(proc_file, O_RDONLY);
-       if (fd < 0) {           /* failure */
-               quark_app_unique_name = g_quark_from_string("unknown");
-               memcpy(app_name, "unknown", strlen("unknown") + 1);
-
-               SECURE_LOGE("Caution!! app_pid(%d) seems to be "
-                                         "killed, so we failed to get proc file(%s) \n",
-                                         pid, proc_file);
-               *return_code = -1;      /* -1 means that system
-                                          failed internally. */
+       if (!__get_caller_unique_name(pid, app_name)) {
+               return_code = ERR_ALARM_SYSTEM_FAIL;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
                return true;
-       } else {
-               ret = read(fd, process_name, 512);
-               if (ret <0 ) {
-                       *return_code = -1;      /* -1 means that system
-                                          failed internally. */
-                       close(fd);
-                       return false;
-               }
-               close(fd);
-               while (process_name[i] != '\0') {
-                       if (process_name[i] == ' ') {
-                               process_name[i] = '\0';
-                               break;
-                       }
-                       i++;
-               }
-               /*if (readlink(proc_file, process_name, 256)!=-1) */
-               /*success */
-
-               word = strtok_r(process_name, "/", &proc_name_ptr);
-               while (word != NULL) {
-                       memset(app_name, 0, 256);
-                       snprintf(app_name, 256, "%s", word);
-                       word = strtok_r(NULL, "/", &proc_name_ptr);
-               }
-               quark_app_unique_name = g_quark_from_string(app_name);
        }
 
-       SECURE_LOGD("called for  app(pid:%d, name=%s)\n",
-                           pid, app_name);
+       SECURE_LOGD("Called by process (pid:%d, unique_name:%s)", pid, app_name);
 
-       for (gs_iter = alarm_context.alarms; gs_iter != NULL;
-            gs_iter = g_slist_next(gs_iter)) {
+       for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
-               SECURE_LOGD("alarm_manager_alarm_get_number_of_ids(): "
-                                   "app_name=%s,quark_app_unique_name=%s\n",
-               app_name, g_quark_to_string(entry->quark_app_unique_name));
-               if (strcmp
-                   (app_name,
-                    g_quark_to_string(entry->quark_app_unique_name)) == 0
-                   && strcmp(app_name, "unknown") != 0) {
-                       (*num_of_ids)++;
-                       SECURE_LOGD("inc number of alarms of app "
-                                           "(pid:%d, name:%s) is %d\n",
-                                           pid, app_name, *num_of_ids);
+               SECURE_LOGD("app_name=%s, quark_app_unique_name=%s", app_name, g_quark_to_string(entry->quark_app_unique_name));
+               if (strncmp(app_name, g_quark_to_string(entry->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);
                }
        }
-       *return_code = 0;
-       SECURE_LOGD("number of alarms of app(pid:%d, name:%s) is %d\n",
-                           pid, app_name, *num_of_ids);
+
+       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;
 }
 
-gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid,
-                                            int max_number_of_ids,
-                                            GArray **arr, int *num_of_ids,
-                                            int *return_code)
+gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
+                                            int max_number_of_ids, gpointer user_data)
 {
        GSList *gs_iter = NULL;
-       GQuark quark_app_unique_name;   /* the fullpath of pid(pid) is converted
-                                          to quark value. */
-       char proc_file[256] = { 0 };
-       char process_name[512] = { 0 };
-       char app_name[256] = { 0 };
-       char *word = NULL;
+       char app_name[512] = { 0 };
        __alarm_info_t *entry = NULL;
        int index = 0;
-       char *proc_name_ptr = NULL;
-       int fd;
-       int ret;
-       int i = 0;
-       GArray *garray = NULL;
-
-       *return_code = 0;
+       GVariant* arr = NULL;
+       GVariantBuilder* builder = NULL;
+       int num_of_ids = 0;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
 
-       garray = g_array_new(false, true, sizeof(alarm_id_t));
-
-       /* we should check that there is a resource leak.
-        * Now we don't have free code for g_array_new().
-        */
        if (max_number_of_ids <= 0) {
-               *arr = garray;
-               SECURE_LOGE("called for  pid(%d), but "
-                                         "max_number_of_ids(%d) is less than 0.\n",
-                                         pid, max_number_of_ids);
+               SECURE_LOGE("called for pid(%d), but max_number_of_ids(%d) is less than 0.", pid, max_number_of_ids);
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", g_variant_new("ai", NULL), num_of_ids, return_code));
                return true;
        }
 
-       /* we should consider to check whether  pid is running or Not
-        */
-       memset(process_name, '\0', 512);
-       memset(proc_file, '\0', 256);
-       snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
-
-       fd = open(proc_file, O_RDONLY);
-       if (fd < 0) {           /* failure */
-               quark_app_unique_name = g_quark_from_string("unknown");
-               memcpy(app_name, "unknown", strlen("unknown") + 1);
-
-               SECURE_LOGE("Caution!! app_pid(%d) seems to be "
-               "killed, so we failed to get proc file(%s)\n", pid, proc_file);
-               *return_code = -1;
-               /* -1 means that system failed internally. */
+       if (!__get_caller_unique_name(pid, app_name)) {
+               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;
-       } else {
-               ret = read(fd, process_name, 512);
-               if (ret <0 ) {
-                       *return_code = -1;
-                       /* -1 means that system failed internally. */
-                       close(fd);
-                       return true;
-               }
-               close(fd);
-               while (process_name[i] != '\0') {
-                       if (process_name[i] == ' ') {
-                               process_name[i] = '\0';
-                               break;
-                       }
-                       i++;
-               }
-               /* if (readlink(proc_file, process_name, 256)!=-1) */
-               /*success */
-
-               word = strtok_r(process_name, "/", &proc_name_ptr);
-               while (word != NULL) {
-                       memset(app_name, 0, 256);
-                       snprintf(app_name, 256, "%s", word);
-                       word = strtok_r(NULL, "/", &proc_name_ptr);
-               }
-               quark_app_unique_name = g_quark_from_string(app_name);
        }
 
-       SECURE_LOGD("called for  app(pid:%d, name=%s)\n",
-                           pid, app_name);
+       SECURE_LOGD("Called by process (pid:%d, unique_name=%s).", pid, app_name);
 
-       for (gs_iter = alarm_context.alarms; gs_iter != NULL;
-            gs_iter = g_slist_next(gs_iter)) {
+       builder = g_variant_builder_new(G_VARIANT_TYPE ("ai"));
+       for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
-               if (strcmp
-                   (app_name,
-                    g_quark_to_string(entry->quark_app_unique_name)) == 0
-                   && strcmp(app_name, "unknown") != 0) {
-                       g_array_append_val(garray, entry->alarm_id);
+               if (strncmp(app_name, g_quark_to_string(entry->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);
                }
        }
 
-       *num_of_ids = index;
+       arr = g_variant_new("ai", builder);
+       num_of_ids = index;
 
-       *arr = garray;
+       SECURE_LOGE("Called by pid (%d), but max_number_of_ids(%d) return code %d.", pid, num_of_ids, return_code);
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", arr, num_of_ids, return_code));
 
+       g_variant_builder_unref(builder);
        return true;
 }
 
-gboolean alarm_manager_alarm_get_appsvc_info(void *pObject, int pid, alarm_id_t alarm_id,
-                               char *e_cookie, gchar **b_data, int *return_code)
+gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodInvocation *invoc ,
+                               int pid, alarm_id_t alarm_id,
+                               char *e_cookie, gpointer user_data)
 {
        bool found = false;
-
        GSList *gs_iter = NULL;
        __alarm_info_t *entry = NULL;
-
-       guchar *cookie = NULL;
-       gsize size;
        int retval = 0;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       gchar *b_data = NULL;
 
-       SECURE_LOGD("called for  pid(%d) and alarm_id(%d)\n", pid, alarm_id);
-
-       cookie = g_base64_decode(e_cookie, &size);
-       if (NULL == cookie)
-       {
-               if (return_code)
-                       *return_code = ERR_ALARM_SYSTEM_FAIL;
-               ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
-               return true;
-       }
-
-       retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "r");
-       if (retval < 0) {
-               if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
-                       ALARM_MGR_EXCEPTION_PRINT("Read access has been denied by smack\n");
-               }
-               ALARM_MGR_EXCEPTION_PRINT("Error has occurred\n");
-
-               if (return_code)
-                       *return_code = ERR_ALARM_NO_PERMISSION;
-
-               if (cookie)
-                       g_free(cookie);
+       SECURE_LOGD("called for pid(%d) and alarm_id(%d)\n", pid, alarm_id);
 
+       retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", false, pid);
+       if (retval != ALARMMGR_RESULT_SUCCESS) {
+               return_code = retval;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code));
                return true;
        }
 
-       if (return_code)
-               *return_code = 0;
-
-       for (gs_iter = alarm_context.alarms; gs_iter != NULL;
-            gs_iter = g_slist_next(gs_iter)) {
+       for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
                if (entry->alarm_id == alarm_id) {
                        found = true;
-                       *b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
+                       b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
                        break;
                }
        }
 
        if (found) {
-               if ( *b_data && strlen(*b_data) == 4 && strncmp(*b_data,"null",4) == 0){
-                       ALARM_MGR_EXCEPTION_PRINT("Regular alarm,not svc alarm\n");
-                       if (return_code)
-                               *return_code = ERR_ALARM_INVALID_TYPE;
+               if (b_data && strlen(b_data) == 4 && strncmp(b_data, "null", 4) == 0) {
+                       ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is an regular alarm, not svc alarm.", alarm_id);
+                       return_code = ERR_ALARM_INVALID_TYPE;
                }
        } else {
-               if (return_code)
-                       *return_code = ERR_ALARM_INVALID_ID;
+               ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is not found.", alarm_id);
+               return_code = ERR_ALARM_INVALID_ID;
        }
 
-       if (cookie)
-               g_free(cookie);
-
+       g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code));
+       g_free(b_data);
        return true;
 }
 
-gboolean alarm_manager_alarm_get_info(void *pObject, int pid,
-                                     alarm_id_t alarm_id, int *start_year,
-                                     int *start_month, int *start_day,
-                                     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,
-                                     int *return_code)
+gboolean alarm_manager_alarm_get_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
+                                     alarm_id_t alarm_id, char *e_cookie, gpointer user_data)
 {
        SECURE_LOGD("called for pid(%d) and alarm_id(%d)\n", pid, alarm_id);
 
        GSList *gs_iter = NULL;
        __alarm_info_t *entry = NULL;
-
        alarm_info_t *alarm_info = NULL;
-       *return_code = 0;
+       int retval = 0;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+
+       retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
+       if (retval != ALARMMGR_RESULT_SUCCESS) {
+               return_code = retval;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(iiiiiiiiiiiiii)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, return_code));
+               return true;
+       }
 
-       for (gs_iter = alarm_context.alarms; gs_iter != NULL;
-            gs_iter = g_slist_next(gs_iter)) {
+       for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
                if (entry->alarm_id == alarm_id) {
                        alarm_info = &(entry->alarm_info);
@@ -2769,48 +2203,40 @@ gboolean alarm_manager_alarm_get_info(void *pObject, int pid,
                }
        }
 
-       if (alarm_info == NULL)
-       {
-               ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n", alarm_id);
-               *return_code = ERR_ALARM_INVALID_ID;
+       if (alarm_info == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is not found.", alarm_id);
+               return_code = ERR_ALARM_INVALID_ID;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(iiiiiiiiiiiiii)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, return_code));
        } else {
-               ALARM_MGR_LOG_PRINT("alarm was found\n");
-               *start_year = alarm_info->start.year;
-               *start_month = alarm_info->start.month;
-               *start_day = alarm_info->start.day;
-               *start_hour = alarm_info->start.hour;
-               *start_min = alarm_info->start.min;
-               *start_sec = alarm_info->start.sec;
-
-               *end_year = alarm_info->end.year;
-               *end_year = alarm_info->end.month;
-               *end_year = alarm_info->end.day;
-
-               *mode_day_of_week = alarm_info->mode.u_interval.day_of_week;
-               *mode_repeat = alarm_info->mode.repeat;
-
-               *alarm_type = alarm_info->alarm_type;
-               *reserved_info = alarm_info->reserved_info;
-
-               *return_code = 0;
+               ALARM_MGR_LOG_PRINT("The alarm(%d) is found.", alarm_id);
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(iiiiiiiiiiiiii)", alarm_info->start.year, alarm_info->start.month,
+                                                       alarm_info->start.day, alarm_info->start.hour, alarm_info->start.min, alarm_info->start.sec, alarm_info->end.year, alarm_info->end.month,
+                                                       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;
 }
 
-gboolean alarm_manager_alarm_get_next_duetime(void *pObject, int pid,
-                                     alarm_id_t alarm_id, time_t* duetime,
-                                       int *return_code)
+gboolean alarm_manager_alarm_get_next_duetime(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
+                                     alarm_id_t alarm_id, char *e_cookie, gpointer user_data)
 {
        SECURE_LOGD("called for pid(%d) and alarm_id(%d)\n", pid, alarm_id);
 
        GSList *gs_iter = NULL;
        __alarm_info_t *entry = NULL;
        __alarm_info_t *find_item = NULL;
+       int retval = 0;
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       time_t duetime = 0;
 
-       *return_code = 0;
+       retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
+       if (retval != ALARMMGR_RESULT_SUCCESS) {
+               return_code = retval;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", duetime, return_code));
+               return true;
+       }
 
-       for (gs_iter = alarm_context.alarms; gs_iter != NULL;
-            gs_iter = g_slist_next(gs_iter)) {
+       for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
                entry = gs_iter->data;
                if (entry->alarm_id == alarm_id) {
                        find_item = entry;
@@ -2818,87 +2244,222 @@ gboolean alarm_manager_alarm_get_next_duetime(void *pObject, int pid,
                }
        }
 
-       if (find_item == NULL)
-       {
-               ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n", alarm_id);
-               *return_code = ERR_ALARM_INVALID_ID;
-       } else {
-               ALARM_MGR_LOG_PRINT("alarm was found\n");
-               *duetime = _alarm_next_duetime(find_item);
-               *return_code = 0;
+       if (find_item == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is not found.", alarm_id);
+               return_code = ERR_ALARM_INVALID_ID;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", duetime, return_code));
+               return true;
        }
+
+       duetime = _alarm_next_duetime(find_item);
+       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;
 }
 
-#include "alarm-skeleton.h"
+gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid, char *e_cookie, gpointer user_data)
+{
+       sqlite3 *alarmmgr_tool_db;
+       char *db_path = NULL;
+       char db_path_tmp[50] = {0,};
+       time_t current_time = 0;
+       struct tm current_tm;
+       const char *query_for_creating_table =  "create table alarmmgr_tool \
+                                       (alarm_id integer primary key,\
+                                                       duetime_epoch integer,\
+                                                       duetime text,\
+                                                       start_epoch integer,\
+                                                       end_epoch integer,\
+                                                       pid integer,\
+                                                       caller_pkgid text,\
+                                                       callee_pkgid text,\
+                                                       app_unique_name text,\
+                                                       app_service_name text,\
+                                                       dst_service_name text,\
+                                                       day_of_week integer,\
+                                                       repeat integer,\
+                                                       alarm_type integer)";
+       const char *query_for_deleting_table = "drop table alarmmgr_tool";
+       int return_code = ALARMMGR_RESULT_SUCCESS;
+       GSList *gs_iter = NULL;
+       __alarm_info_t *entry = NULL;
+       char *error_message = NULL;
+
+       return_code = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
+       if (return_code != ALARMMGR_RESULT_SUCCESS) {
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
+               return true;
+       }
 
-typedef struct AlarmManagerObject AlarmManagerObject;
-typedef struct AlarmManagerObjectClass AlarmManagerObjectClass;
-GType Server_Object_get_type(void);
-struct AlarmManagerObject {
-       GObject parent;
-};
-struct AlarmManagerObjectClass {
-       GObjectClass parent;
-};
+       // 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",
+               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);
+
+       if (db_util_open(db_path, &alarmmgr_tool_db, DB_UTIL_REGISTER_HOOK_METHOD) != SQLITE_OK) {
+               ALARM_MGR_EXCEPTION_PRINT("Opening [%s] failed", db_path);
+               return_code = ERR_ALARM_SYSTEM_FAIL;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
+               free(db_path);
+               return true;
+       }
 
-#define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
-
-#define ALARM_MANAGER_TYPE_OBJECT              (Server_Object_get_type())
-#define ALARM_MANAGER_OBJECT(object)           (G_TYPE_CHECK_INSTANCE_CAST \
-((object), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObject))
-#define ALARM_MANAGER_OBJECT_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST \
-((klass), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
-#define ALARM_MANAGER_IS_OBJECT(object)        (G_TYPE_CHECK_INSTANCE_TYPE \
-((object), ALARM_MANAGER_TYPE_OBJECT))
-#define ALARM_MANAGER_IS_OBJECT_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE \
-((klass), ALARM_MANAGER_TYPE_OBJECT))
-#define ALARM_MANAGER_OBJECT_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS \
-((obj), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
-G_DEFINE_TYPE(AlarmManagerObject, Server_Object, G_TYPE_OBJECT)
-static void Server_Object_init(AlarmManagerObject * obj)
+       // Drop a table
+       if (sqlite3_exec(alarmmgr_tool_db, query_for_deleting_table, NULL, NULL, &error_message) != SQLITE_OK) {
+               ALARM_MGR_EXCEPTION_PRINT("Deleting the table is failed. error message = %s", error_message);
+       }
+
+       // Create a table if it does not exist
+       if (sqlite3_exec(alarmmgr_tool_db, query_for_creating_table, NULL, NULL, &error_message) != SQLITE_OK) {
+               ALARM_MGR_EXCEPTION_PRINT("Creating the table is failed. error message = %s", error_message);
+               sqlite3_close(alarmmgr_tool_db);
+               return_code = ERR_ALARM_SYSTEM_FAIL;
+               g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
+               free(db_path);
+               return true;
+       }
+
+       // Get information of all alarms and save those into the DB.
+       int index = 0;
+       for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
+               entry = gs_iter->data;
+               ++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);
+
+               alarm_info_t *alarm_info = (alarm_info_t *) &(entry->alarm_info);
+               alarm_mode_t *mode = &alarm_info->mode;
+
+               char *query = sqlite3_mprintf("insert into alarmmgr_tool( alarm_id, duetime_epoch, duetime, start_epoch,\
+                               end_epoch, pid, caller_pkgid, callee_pkgid, app_unique_name, app_service_name, dst_service_name, day_of_week, repeat, alarm_type)\
+                               values (%d,%d,%Q,%d,%d,%d,%Q,%Q,%Q,%Q,%Q,%d,%d,%d)",
+                               entry->alarm_id,
+                               (int)entry->due_time,
+                               ctime(&(entry->due_time)),
+                               (int)entry->start,
+                               (int)entry->end,
+                               (int)entry->pid,
+                               (char *)g_quark_to_string(entry->quark_caller_pkgid),
+                               (char *)g_quark_to_string(entry->quark_callee_pkgid),
+                               (char *)g_quark_to_string(entry->quark_app_unique_name),
+                               (char *)g_quark_to_string(entry->quark_app_service_name),
+                               (char *)g_quark_to_string(entry->quark_dst_service_name),
+                               mode->u_interval.day_of_week,
+                               mode->repeat,
+                               entry->alarm_info.alarm_type);
+
+               if (sqlite3_exec(alarmmgr_tool_db, query, NULL, NULL, &error_message) != SQLITE_OK) {
+                       SECURE_LOGE("sqlite3_exec() is failed. error message = %s", error_message);
+               }
+
+               sqlite3_free(query);
+       }
+
+       sqlite3_close(alarmmgr_tool_db);
+
+       return_code = ALARMMGR_RESULT_SUCCESS;
+       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)
+{
+       GSList *fd_list;
+       GPollFD *tmp;
+
+       fd_list = src->poll_fds;
+       do {
+               tmp = (GPollFD *) fd_list->data;
+               g_free(tmp);
+
+               fd_list = fd_list->next;
+       } while (fd_list);
+
+       return;
+}
+
+static gboolean __timer_glib_check(GSource *src)
+{
+       GSList *fd_list;
+       GPollFD *tmp;
+
+       fd_list = src->poll_fds;
+       do {
+               tmp = (GPollFD *) fd_list->data;
+               if (tmp->revents & (POLLIN | POLLPRI)) {
+                       return TRUE;
+               }
+               fd_list = fd_list->next;
+       } while (fd_list);
+
+       return FALSE;
+}
+
+static gboolean __timer_glib_dispatch(GSource *src, GSourceFunc callback,
+                                 gpointer data)
 {
-       ;
+       callback(data);
+       return TRUE;
 }
 
-static void Server_Object_class_init(AlarmManagerObjectClass *klass)
+static gboolean __timer_glib_prepare(GSource *src, gint *timeout)
 {
-       ;
+       return FALSE;
 }
 
+GSourceFuncs funcs = {
+       .prepare = __timer_glib_prepare,
+       .check = __timer_glib_check,
+       .dispatch = __timer_glib_dispatch,
+       .finalize = __timer_glib_finalize
+};
+
 static void __initialize_timer()
 {
-       struct sigaction sig_timer;
-       sigemptyset(&sig_timer.sa_mask);
-       sig_timer.sa_flags = SA_SIGINFO;
-       sig_timer.sa_sigaction = (void *)__alarm_handler;
-       sigaction(SIG_TIMER, &sig_timer, NULL);
+       int fd;
+       GSource *src;
+       GPollFD *gpollfd;
+       int ret;
+
+       fd = timerfd_create(CLOCK_REALTIME, 0);
+       if (fd == -1) {
+               ALARM_MGR_EXCEPTION_PRINT("timerfd_create() is failed.\n");
+               exit(1);
+       }
+       src = g_source_new(&funcs, sizeof(GSource));
+
+       gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
+       gpollfd->events = POLLIN;
+       gpollfd->fd = fd;
 
-       alarm_context.timer = _alarm_create_timer();
+       g_source_add_poll(src, gpollfd);
+       g_source_set_callback(src, (GSourceFunc) __alarm_handler_idle,
+                             (gpointer) gpollfd, NULL);
+       g_source_set_priority(src, G_PRIORITY_HIGH);
 
+       ret = g_source_attach(src, NULL);
+       if (ret == 0) {
+               ALARM_MGR_EXCEPTION_PRINT("g_source_attach() is failed.\n");
+               return;
+       }
+
+       g_source_unref(src);
+
+       alarm_context.timer = fd;
 }
 
 static void __initialize_alarm_list()
 {
-
        alarm_context.alarms = NULL;
        alarm_context.c_due_time = -1;
 
        _load_alarms_from_registry();
 
        __rtc_set();    /*Set RTC1 Alarm with alarm due time for alarm-manager initialization*/
-
-       /*alarm boot */
-#ifdef __ALARM_BOOT
-       /*alarm boot */
-       if (enable_power_on_alarm) {
-               /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
-                * platform with app-server. because __alarm_power_on(..) fuction don't
-                * use first parameter internally, we set this value to 0(zero)
-                */
-               __alarm_power_on(0, enable_power_on_alarm, NULL);
-       }
-#endif
 }
 
 static void __initialize_scheduled_alarm_list()
@@ -2906,21 +2467,9 @@ static void __initialize_scheduled_alarm_list()
        _init_scheduled_alarm_list();
 }
 
-
-static void __hibernation_leave_callback()
-{
-
-       __initialize_scheduled_alarm_list();
-
-       __alarm_clean_list();
-
-       __initialize_alarm_list();
-}
-
 static bool __initialize_noti()
 {
-       /*system state change noti ó\B8\AE */
-
+       // system state change noti
        if (vconf_notify_key_changed
            (VCONFKEY_SETAPPL_TIMEZONE_ID, __on_time_zone_changed, NULL) < 0) {
                ALARM_MGR_LOG_PRINT(
@@ -2942,114 +2491,103 @@ static bool __initialize_noti()
        return true;
 }
 
-
-static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
-                                              DBusMessage *message,
-                                              void *user_data)
+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)
 {
-
-       if (dbus_message_is_signal
-           (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
-               char *service;
-               char *old_owner;
-               char *new_owner;
-               GSList *entry;
-               __expired_alarm_t *expire_info;
-
-               dbus_message_get_args(message,
-                                     NULL,
-                                     DBUS_TYPE_STRING, &service,
-                                     DBUS_TYPE_STRING, &old_owner,
-                                     DBUS_TYPE_STRING, &new_owner,
-                                     DBUS_TYPE_INVALID);
+       // On expiry, the killed app can be launched by aul. Then, the owner of the bus name which was registered by the app is changed.
+       // In this case, "NameOwnerChange" signal is broadcasted.
+       if (signal_name && strcmp(signal_name , "NameOwnerChanged") == 0) {
+               GSList *entry = NULL;
+               __expired_alarm_t *expire_info = NULL;
+               char *service_name = NULL;
+               g_variant_get(parameters, "(sss)", &service_name, NULL, NULL);
 
                for (entry = g_expired_alarm_list; entry; entry = entry->next) {
                        if (entry->data) {
                                expire_info = (__expired_alarm_t *) entry->data;
+                               SECURE_LOGD("expired service(%s), owner changed service(%s)", expire_info->service_name, service_name);
 
-                               SECURE_LOGD("service_name(%s), service(%s)", expire_info->service_name, service);
-
-                               if (strcmp(expire_info->service_name, service)
-                                   == 0) {
-                                       SECURE_LOGE(
-                                       "__alarm_server_filter : "
-                                            "service name(%s) alarm_id (%d)\n",
-                                            expire_info->service_name,\
-                                            expire_info->alarm_id);
-
-                                       __alarm_send_noti_to_application(
-                                            expire_info->service_name,
-                                            expire_info->alarm_id);
-                                       g_expired_alarm_list =
-                                           g_slist_remove(g_expired_alarm_list,
-                                                          entry->data);
-                                       free(expire_info);
+                               if (strcmp(expire_info->service_name, service_name) == 0) {
+                                       SECURE_LOGE("expired service name(%s) alarm_id (%d)", expire_info->service_name, expire_info->alarm_id);
+                                       __alarm_send_noti_to_application(expire_info->service_name, expire_info->alarm_id);
+                                       g_expired_alarm_list = g_slist_remove(g_expired_alarm_list, entry->data);
+                                       g_free(expire_info);
                                }
                        }
                }
-
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+               g_free(service_name);
        }
-
-       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-static bool __initialize_dbus()
+static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
-       GError *error = NULL;
-       GObject *obj = NULL;
-       DBusGConnection *connection = NULL;
-       DBusError derror;
-
-       dbus_g_object_type_install_info(ALARM_MANAGER_TYPE_OBJECT,
-                                       &dbus_glib_alarm_manager_object_info);
+       ALARM_MGR_EXCEPTION_PRINT("on_bus_acquired");
 
-       connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
-       if (!connection) {
-
-               ALARM_MGR_EXCEPTION_PRINT("dbus_g_bus_get failed\n");
-               return false;
+       interface = alarm_manager_skeleton_new();
+       if (interface == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Creating a skeleton object is failed.");
+               return;
        }
 
-       dbus_error_init(&derror);
-
-       dbus_bus_request_name(dbus_g_connection_get_connection(connection),
-                                 "com.samsung.alarm.manager",
-                                 DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &derror);
-       if (dbus_error_is_set(&derror)) {       /* failure */
-               SECURE_LOGE("Failed to dbus_bus_request_name "
-               "(com.samsung.alarm.manager): %s\n", derror.message);
-               dbus_error_free(&derror);
-               return false;
+       g_signal_connect(interface, "handle_alarm_create", G_CALLBACK(alarm_manager_alarm_create), NULL);
+       g_signal_connect(interface, "handle_alarm_create_appsvc", G_CALLBACK(alarm_manager_alarm_create_appsvc), NULL);
+       g_signal_connect(interface, "handle_alarm_delete", G_CALLBACK(alarm_manager_alarm_delete), NULL);
+       g_signal_connect(interface, "handle_alarm_delete_all", G_CALLBACK(alarm_manager_alarm_delete_all), NULL);
+       g_signal_connect(interface, "handle_alarm_get_appsvc_info", G_CALLBACK(alarm_manager_alarm_get_appsvc_info), NULL);
+       g_signal_connect(interface, "handle_alarm_get_info", G_CALLBACK(alarm_manager_alarm_get_info), NULL);
+       g_signal_connect(interface, "handle_alarm_get_list_of_ids", G_CALLBACK(alarm_manager_alarm_get_list_of_ids), NULL);
+       g_signal_connect(interface, "handle_alarm_get_next_duetime", G_CALLBACK(alarm_manager_alarm_get_next_duetime), NULL);
+       g_signal_connect(interface, "handle_alarm_get_number_of_ids", G_CALLBACK(alarm_manager_alarm_get_number_of_ids), NULL);
+       g_signal_connect(interface, "handle_alarm_set_rtc_time", G_CALLBACK(alarm_manager_alarm_set_rtc_time), NULL);
+       g_signal_connect(interface, "handle_alarm_set_time", G_CALLBACK(alarm_manager_alarm_set_time), 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);
+
+       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,
+                                                       on_bus_name_owner_changed, NULL, NULL);
+       if (subsc_id == 0) {
+               ALARM_MGR_EXCEPTION_PRINT("Subscribing to signal for invoking callback is failed.");
+               g_object_unref(interface);
+               interface = NULL;
+               return;
        }
 
-       if (!(obj = g_object_new(ALARM_MANAGER_TYPE_OBJECT, NULL))) {
-               ALARM_MGR_EXCEPTION_PRINT("Could not allocate new object\n");
-               return false;
+       if (!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(interface), connection, ALARM_MGR_DBUS_PATH, NULL)) {
+               ALARM_MGR_EXCEPTION_PRINT("Exporting the interface is failed.");
+               g_object_unref(interface);
+               interface = NULL;
+               return;
        }
 
-       dbus_g_connection_register_g_object(connection,
-                                           "/com/samsung/alarm/manager",
-                                           G_OBJECT(obj));
+       alarm_context.connection = connection;
+       g_dbus_object_manager_server_set_connection(alarmmgr_server, alarm_context.connection);
+}
 
-       /*dbus_bus_add_match (dbus_g_connection_get_connection(connection),
-          "type='signal',member='NameOwnerChanged'",NULL); */
+static bool __initialize_dbus()
+{
+       ALARM_MGR_LOG_PRINT("__initialize_dbus Enter");
 
-       dbus_bus_add_match(dbus_g_connection_get_connection(connection),
-                          "type='signal',sender='" DBUS_SERVICE_DBUS
-                          "',path='" DBUS_PATH_DBUS
-                          "',interface='" DBUS_INTERFACE_DBUS
-                          "',member='NameOwnerChanged'", NULL);
+       alarmmgr_server = g_dbus_object_manager_server_new(ALARM_MGR_DBUS_PATH);
+       if (alarmmgr_server == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Creating a new server object is failed.");
+               return false;
+       }
 
-       if (!dbus_connection_add_filter
-           (dbus_g_connection_get_connection(connection),
-            __alarm_server_filter, NULL, NULL)) {
-               ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
+       guint owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, ALARM_MGR_DBUS_NAME,
+                               G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, NULL, NULL, NULL, NULL);
 
+       if (owner_id == 0) {
+               ALARM_MGR_EXCEPTION_PRINT("Acquiring the own name is failed.");
+               g_object_unref(alarmmgr_server);
                return false;
        }
 
-       alarm_context.bus = connection;
        return true;
 }
 
@@ -3060,6 +2598,8 @@ sqlite3 *alarmmgr_db;
                                                start integer,\
                                                end integer,\
                                                pid integer,\
+                                               caller_pkgid text,\
+                                               callee_pkgid text,\
                                                app_unique_name text,\
                                                app_service_name text,\
                                                app_service_name_mod text,\
@@ -3084,37 +2624,25 @@ static bool __initialize_db()
        int ret;
 
        if (access("/opt/dbspace/.alarmmgr.db", F_OK) == 0) {
-               ret =
-                   db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
-                                DB_UTIL_REGISTER_HOOK_METHOD);
+               ret = db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db, DB_UTIL_REGISTER_HOOK_METHOD);
 
                if (ret != SQLITE_OK) {
-                       ALARM_MGR_EXCEPTION_PRINT(
-                           "====>>>> connect menu_db [%s] failed!\n",
-                            ALARMMGR_DB_FILE);
+                       ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", ALARMMGR_DB_FILE);
                        return false;
                }
 
                return true;
        }
 
-       ret =
-           db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
-                        DB_UTIL_REGISTER_HOOK_METHOD);
+       ret = db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db, DB_UTIL_REGISTER_HOOK_METHOD);
 
        if (ret != SQLITE_OK) {
-               ALARM_MGR_EXCEPTION_PRINT(
-                   "====>>>> connect menu_db [%s] failed!\n",
-                    ALARMMGR_DB_FILE);
+               ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", ALARMMGR_DB_FILE);
                return false;
        }
 
-       if (SQLITE_OK !=
-           sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL,\
-                        &error_message)) {
-               ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, "
-               "error message = %s\n", QUERY_CREATE_TABLE_ALARMMGR,
-                                         error_message);
+       if (SQLITE_OK != sqlite3_exec(alarmmgr_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);
                return false;
        }
 
@@ -3123,28 +2651,7 @@ static bool __initialize_db()
 
 static void __initialize()
 {
-
        g_type_init();
-#ifdef __ALARM_BOOT
-       FILE *fp;
-       char temp[2];
-       int size;
-
-       fp = fopen("/proc/alarm_boot", "r");
-       if (fp == NULL)
-               alarm_boot = 0;
-       else {
-
-               size = fread(&temp, 1, 1, fp);
-               if (size != 1)
-                       alarm_boot = 0;
-               else {
-                       temp[1] = 0;
-                       alarm_boot = atoi(temp);
-               }
-               fclose(fp);
-       }
-#endif
 
        __initialize_timer();
        if (__initialize_dbus() == false) {     /* because dbus's initialize
@@ -3157,41 +2664,10 @@ static void __initialize()
        __initialize_db();
        __initialize_alarm_list();
        __initialize_noti();
-#ifdef __APP_SYNC
-       _sync_scheduler_init();
-#endif
-
-}
-
-#ifdef __ALARM_BOOT
-static bool __check_false_alarm()
-{
-       time_t current_time;
-       time_t interval;
-
-       time(&current_time);
-
-       interval = ab_due_time - current_time;
-
-       ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", \
-                           alarm_context.c_due_time, current_time);
 
-       if (interval > 0 && interval <= 30) {
-               return true;
-       } else if (!poweron_alarm_expired) {
-               /* originally, first arguement's value was 121(app_id) which means
-                * alarm_booting ui application.and this application's dbus-service
-                * name had a com.samsung.alarmboot.ui in a platform with app-server.
-                * so we set "com.samsung.alarmboot.ui.ALARM" instead of 121.
-                */
-               __alarm_send_noti_to_application(
-                       WAKEUP_ALARMBOOTING_APP_ID, -1);
-               return false;
-       }
+       __initialize_module_log();      // for module log
 
-       return true;
 }
-#endif
 
 int main()
 {
@@ -3203,12 +2679,6 @@ int main()
 
        __initialize();
 
-#ifdef __ALARM_BOOT
-       if (alarm_boot){
-               __check_false_alarm();
-       }
-#endif
-
        g_main_loop_run(mainloop);
 
        return 0;
diff --git a/alarm-server-mobile.manifest b/alarm-server-mobile.manifest
deleted file mode 100755 (executable)
index 89e2890..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<manifest>
-        <define>
-                <domain name="alarm-server"/>
-                <provide>
-                        <label name="alarm-server::db"/>
-                        <label name="alarm-server::alarm"/>
-                </provide>
-        </define>
-        <request>
-                <domain name="alarm-server"/>
-        </request>
-    <assign>
-        <filesystem path="/usr/lib/systemd/system/alarm-server.service" label="_" exec_label="none" />
-        <filesystem path="/usr/lib/systemd/system/multi-user.target.wants/alarm-server.service" label="_" exec_label="none" />
-    </assign>
-</manifest>
old mode 100755 (executable)
new mode 100644 (file)
similarity index 62%
rename from alarm-server-wearable.manifest
rename to alarm-server.manifest
index 715af65..53208bc
@@ -7,9 +7,12 @@
                </provide>
                <request>
                        <smack request="deviced::display" type="rw"/>
-                        <smack request="security-server::api-cookie-check" type="w"/>
+                       <smack request="security-server::api-cookie-check" type="w"/>
                </request>
        </define>
+       <assign>
+               <filesystem path="/opt/etc/dump.d/module.d/alarmmgr_log_dump.sh" label="_" exec_label="none"/>
+       </assign>
        <request>
                <domain name="alarm-server"/>
        </request>
diff --git a/alarm-server.rule b/alarm-server.rule
new file mode 100644 (file)
index 0000000..4d7b356
--- /dev/null
@@ -0,0 +1 @@
+alarm-server resman::db rw
index 549be8a..f444f26 100644 (file)
@@ -1,12 +1,11 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@/
-localedir=@localedir@
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
 
 Name: alarm-service
 Description: alarm library
 Version: @VERSION@
-Requires: dbus-1 dbus-glib-1 glib-2.0 gobject-2.0 dlog
+Requires: glib-2.0 gobject-2.0 dlog
 Libs: -L${libdir} -lalarm
 Cflags: -I${includedir}
index 8c0908c..e52d452 100644 (file)
       <arg type="i" name="alarm_id" direction="out" />
       <arg type="i" name="return_code" direction="out" />
     </method>
-       <method name="alarm_delete">
+    <method name="alarm_delete">
       <arg type="i" name="pid" direction="in" />
       <arg type="i" name="alarm_id" direction="in" />
       <arg type="s" name="cookie" direction="in" />
       <arg type="i" name="alarm_info_return_code" direction="out" />
     </method>
     <method name="alarm_delete_all">
-         <arg type="i" name="pid" direction="in" />
-         <arg type="i" name="alarm_info_return_code" direction="out" />
-    </method>
-       <method name="alarm_power_on">
-      <arg type="i" name="pid" direction="in" />
-      <arg type="i" name="on_off" direction="in" />
-      <arg type="i" name="alarm_info_return_code" direction="out" />
-    </method>
-       <method name="alarm_power_off">
-      <arg type="i" name="pid" direction="in" />
-      <arg type="i" name="alarm_info_return_code" direction="out" />
-    </method>
-       <method name="alarm_check_next_duetime">
       <arg type="i" name="pid" direction="in" />
+      <arg type="s" name="cookie" direction="in" />
       <arg type="i" name="alarm_info_return_code" direction="out" />
     </method>
        <method name="alarm_update">
@@ -88,6 +76,7 @@
     </method>
        <method name="alarm_get_number_of_ids">
          <arg type="i" name="pid" direction="in" />
+         <arg type="s" name="cookie" direction="in" />
          <arg type="i" name="number_of_ids" direction="out" />
          <arg type="i" name="return_code" direction="out" />
     </method>
     <method name="alarm_get_info">
          <arg type="i" name="pid" direction="in" />
          <arg type="i" name="alarm_id" direction="in" />
+         <arg type="s" name="cookie" direction="in" />
       <arg type="i" name="alarm_info_start_year" direction="out" />
       <arg type="i" name="alarm_info_start_month" direction="out" />
       <arg type="i" name="alarm_info_start_day" direction="out" />
        <method name="alarm_get_next_duetime">
          <arg type="i" name="pid" direction="in" />
          <arg type="i" name="alarm_id" direction="in" />
+         <arg type="s" name="cookie" direction="in" />
          <arg type="i" name="duetime" direction="out" />
          <arg type="i" name="return_code" direction="out" />
     </method>
+       <method name="alarm_get_all_info">
+         <arg type="i" name="pid" direction="in" />
+         <arg type="s" name="cookie" direction="in" />
+         <arg type="s" name="db_path" direction="out" />
+         <arg type="i" name="return_code" direction="out" />
+    </method>
     <method name="alarm_set_time">
           <arg type="i" name="time" direction="in" />
           <arg type="i" name="return_code" direction="out" />
diff --git a/alarmmgr_log_dump.sh b/alarmmgr_log_dump.sh
new file mode 100644 (file)
index 0000000..94fbd03
--- /dev/null
@@ -0,0 +1,8 @@
+#!bin/sh
+
+ALARMMGR_DUMP=$1/alarmmgr
+mkdir -p $ALARMMGR_DUMP
+cp -f /var/log/alarmmgr.log $ALARMMGR_DUMP
+
+alarmmgr_get_all_info
+mv -f /tmp/alarmmgr_* $ALARMMGR_DUMP
diff --git a/autogen.sh b/autogen.sh
deleted file mode 100755 (executable)
index 798eba2..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-aclocal
-libtoolize --copy
-autoheader
-autoconf
-automake --add-missing --copy --foreign
-
diff --git a/configure.ac b/configure.ac
deleted file mode 100644 (file)
index e4a0c84..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#                                               -*- Autoconf -*-
-# Process this file with autoconf to produce a configure script.
-
-AC_PREREQ(2.61)
-AC_INIT([alarm-manager], [1.0])
-AM_INIT_AUTOMAKE([-Wall -Werror foreign])
-AC_CONFIG_HEADERS([config.h:config.hin])
-
-AC_CONFIG_MACRO_DIR([m4])
-# Init XO
-PLATFORM_INIT
-
-# Checks for programs.
-# AC_PROG_CXX
-AC_PROG_CC
-AC_PROG_GCC_TRADITIONAL
-AC_PROG_LIBTOOL
-
-# checks arch
-AM_CONDITIONAL(DEVELOP_VER, test $DEVELOP_VER = yes)
-
-#AM_CONDITIONAL([ARCH_IS_ARM], [test "x$ARCH" = "xarm"])
-if test "x$ARCH" = "xarm" ; then
-       ALARM_CPPFLAGS="-D__ALARM_BOOT"
-else
-       ALARM_CPPFLAGS="-D__ALARM_BOOT"
-fi
-               
-AC_SUBST(ALARM_CPPFLAGS)
-
-ALARM_CFLAGS="-fvisibility=hidden"
-AC_SUBST(ALARM_CFLAGS)
-
-dnl AC_SUBST(ACLOCAL_AMFLAGS, "-I m4")
-# Checks for libraries.
-PKG_CHECK_MODULES(ALARM_MANAGER, dbus-1 glib-2.0 dbus-glib-1 gobject-2.0 dlog security-server bundle appsvc)
-AC_SUBST(ALARM_MANAGER_CFLAGS)
-AC_SUBST(ALARM_MANAGER_LIBS)
-
-if test "$DEVICE_PROFILE" == "mobile" ; then
-PKG_CHECK_MODULES(ALARM_MANAGER_SERVER, dbus-1 glib-2.0 dbus-glib-1 dlog aul bundle security-server db-util appsvc pkgmgr-info)
-else
-PKG_CHECK_MODULES(ALARM_MANAGER_SERVER, dbus-1 glib-2.0 dbus-glib-1 deviced dlog aul bundle security-server db-util appsvc pkgmgr-info)
-fi
-AC_SUBST(ALARM_MANAGER_SERVER_CFLAGS)
-AC_SUBST(ALARM_MANAGER_SERVER_LIBS)
-
-# Checks for header files.
-AC_HEADER_STDC
-AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/ioctl.h unistd.h])
-
-# Checks for typedefs, structures, and compiler characteristics.
-AC_HEADER_STDBOOL
-AC_C_CONST
-AC_C_INLINE
-AC_STRUCT_TM
-AC_TYPE_PID_T
-AC_TYPE_SIZE_T
-AC_TYPE_SSIZE_T
-
-# Checks for library functions.
-AC_FUNC_MALLOC
-#AC_FUNC_MKTIME
-AC_FUNC_STAT
-AC_CHECK_FUNCS([localtime_r memset])
-
-AC_CONFIG_FILES([Makefile alarm-service.pc])
-AC_OUTPUT
index 3b9ea55..f2250b5 100644 (file)
@@ -2,7 +2,7 @@ Source: alarm-manager
 Section: devel
 Priority: extra
 Maintainer: SHIVAKUMAR BT<shiva.bt@samsung.com>, Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>, Venkatesha Sarpangala <sarpangala.v@samsung.com>
-Build-Depends: debhelper (>= 5), libdbus-1-dev, libglib2.0-dev, libdbus-glib-1-dev, libslp-pm-dev, dlog-dev, libheynoti-dev, libaul-1-dev, libbundle-dev, libsecurity-server-client-dev, libslp-db-util-dev, libvconf-dev, libvconf-keys-dev, libappsvc-dev
+Build-Depends: debhelper (>= 5), libdbus-1-dev, libglib2.0-dev, libdbus-glib-1-dev, libslp-pm-dev, dlog-dev, libaul-1-dev, libbundle-dev, libsecurity-server-client-dev, libslp-db-util-dev, libvconf-dev, libvconf-keys-dev, libappsvc-dev
 Standards-Version: 0.2.0
 
 Package: alarm-server
old mode 100755 (executable)
new mode 100644 (file)
index a312191..0b16610
@@ -20,9 +20,6 @@
  *
  */
 
-
-
-
 #ifndef _ALARM_INTERNAL_H
 #define _ALARM_INTERNAL_H
 
 #define ALARM_INFO_MAX 100
 
 #include "alarm.h"
-#include <dbus/dbus-glib.h>
 #include <glib.h>
 #include <dlog.h>
 #include <bundle.h>
 #include <appsvc.h>
-
-#define __APP_SYNC
+#include <gio/gio.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 SYSTEM_TIME_CHANGED "setting_time_changed"
 
@@ -72,8 +68,8 @@ application server.*/
 /*#define      _EXPIRE_ALARM_INTERFACE_IS_DBUS_GPROXY_ */
 
 typedef struct {
-       DBusGConnection *bus;
-       DBusGProxy *proxy;
+       GDBusConnection *connection;
+       GDBusProxy *proxy;
        alarm_cb_t alarm_handler;
        void *user_param;
        int pid;                /* this specifies pid*/
@@ -138,14 +134,8 @@ bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
 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_reset(alarm_context_t context, int *error_code);
-
-bool _send_alarm_power_on(alarm_context_t context, bool on_off,
-                          int *error_code);
-bool _send_alarm_check_next_duetime(alarm_context_t context, int *error_code);
-bool _send_alarm_power_off(alarm_context_t context, int *error_code);
 bool _remove_from_scheduled_alarm_list(int pid, alarm_id_t alarm_id);
 bool _load_alarms_from_registry();
-bool _alarm_find_mintime_power_on(time_t *min_time);
 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);
 
@@ -154,8 +144,10 @@ typedef struct {
        time_t start;
        time_t end;
 
-       int alarm_id;
+       alarm_id_t alarm_id;
        int pid;
+       GQuark quark_caller_pkgid;
+       GQuark quark_callee_pkgid;
        GQuark quark_app_unique_name;   /*the fullpath of application's pid is
                converted to quark value.*/
        GQuark quark_app_service_name;  /*dbus_service_name is converted  to
@@ -180,12 +172,12 @@ typedef struct {
 } __alarm_entry_t;
 
 typedef struct {
-       timer_t timer;
+       int timer;
        time_t c_due_time;
        GSList *alarms;
        int gmt_idx;
        int dst;
-       DBusGConnection *bus;
+       GDBusConnection *connection;
 } __alarm_server_context_t;
 
 typedef struct {
@@ -209,10 +201,8 @@ bool _save_alarms(__alarm_info_t *__alarm_info);
 bool _delete_alarms(alarm_id_t alarm_id);
 bool _update_alarms(__alarm_info_t *__alarm_info);
 
-timer_t _alarm_create_timer();
 bool _alarm_destory_timer(timer_t timer);
-bool _alarm_set_timer(__alarm_server_context_t *alarm_context, timer_t timer,
-                      time_t due_time, alarm_id_t id);
+bool _alarm_set_timer(__alarm_server_context_t *alarm_context, int timer, time_t due_time);
 bool _alarm_disable_timer(__alarm_server_context_t alarm_context);
 bool _init_scheduled_alarm_list();
 
@@ -220,7 +210,6 @@ 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)
@@ -234,14 +223,4 @@ int _set_time(time_t _time);
 #define ALARM_MGR_ASSERT_PRINT(FMT, ARG...) LOGE(FMT, ##ARG);
 #endif
 
-/* int alarmmgr_check_next_duetime();*/
-
-#ifdef __APP_SYNC
-bool _sync_scheduler_app_sync_on();
-void _sync_scheduler_init();
-void _sync_scheduler_repeating_alarms(__alarm_info_t *alarm_info);
-void _sync_scheduler_remove_repeating_alarm(alarm_id_t alarm_id);
-#endif //__APP_SYNC
-
-
 #endif /*_ALARM_INTERNAL_H*/
index 2883c87..4deec23 100644 (file)
@@ -122,7 +122,7 @@ int main(int argc, char** argv)
        g_type_init();
 
        mainloop = g_main_loop_new(NULL, FALSE);
-       result = alarmmgr_init("org.tizen.test");
+       result = alarmmgr_init("com.samsung.test");
 
        if(result != ALARMMGR_RESULT_SUCCESS) {
                printf("fail to alarmmgr_init : error_code : %d\n",result);
@@ -256,7 +256,7 @@ typedef struct alarm_info_t alarm_entry_t;
 ...
 {
        int ret_val = ALARMMGR_RESULT_SUCCESS;
-       const char* pkg_name = "org.tizen.test";
+       const char* pkg_name = "com.samsung.test";
 
        g_type_init();
 
@@ -830,7 +830,7 @@ int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type);
        }
 
        appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
-       appsvc_set_pkgname(b,"org.tizen.alarm-test");
+       appsvc_set_pkgname(b,"com.samsung.alarm-test");
 
     time(&current_time);
 
@@ -907,7 +907,7 @@ int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm,void *bundle_d
        struct tm current_tm;
        alarm_date_t test_time;
 
-       const char* pkg_name = "org.tizen.test";
+       const char* pkg_name = "com.samsung.test";
 
        g_type_init();
 
@@ -1002,7 +1002,7 @@ int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
                        return;
                }
 
-               appsvc_set_pkgname(b,"org.tizen.alarm-test");
+               appsvc_set_pkgname(b,"com.samsung.alarm-test");
                //appsvc_set_operation(b,APPSVC_OPERATION_SEND_TEXT);
                appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
 
@@ -1059,7 +1059,7 @@ int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
         const char* destination = NULL;
         alarm_id_t alarm_id;
 
-        const char* pkg_name = "org.tizen.test";
+        const char* pkg_name = "com.samsung.test";
 
         g_type_init();
 
@@ -1115,7 +1115,7 @@ int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
        const char* destination = NULL;
        alarm_id_t alarm_id;
 
-       const char* pkg_name = "org.tizen.test";
+       const char* pkg_name = "com.samsung.test";
 
        g_type_init();
 
@@ -1179,7 +1179,7 @@ int alarmmgr_remove_all(void);
         int ret_val = ALARMMGR_RESULT_SUCCESS;
         int n = 1;
 
-        const char* pkg_name = "org.tizen.test";
+        const char* pkg_name = "com.samsung.test";
 
         g_type_init();
 
@@ -1236,7 +1236,7 @@ int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param);
 
        alarm_entry_t *alarm;
 
-       const char* pkg_name = "org.tizen.test_get_info1";
+       const char* pkg_name = "com.samsung.test_get_info1";
 
        g_type_init();
 
@@ -1301,7 +1301,7 @@ register_alarm(){
                return;
        }
 
-       appsvc_set_pkgname(b,"org.tizen.alarm-test");
+       appsvc_set_pkgname(b,"com.samsung.alarm-test");
        appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT);
 
        if ((result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, 10, 0, (void *)b ,&alarm_id)))
@@ -1381,18 +1381,6 @@ int alarmmgr_set_rtc_time(alarm_date_t *time);
 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);
 
-/**
- * @}
- */
-
-
-/**
- * @}
- */
-
-
-int alarmmgr_power_on(bool on_off);
-
 #ifdef __cplusplus
 }
 #endif
index 8a8c48d..11f5e1d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       alarm-manager
 Summary:    Alarm library
-Version:    0.4.112
+Version:    0.4.163
 Release:    1
 Group:      System/Libraries
 License:    Apache License, Version 2.0
@@ -9,20 +9,20 @@ Source1:    alarm-server.service
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 
-BuildRequires: pkgconfig(dbus-1)
+BuildRequires: cmake
 BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(dbus-glib-1)
-%if %{_repository} == "wearable"
-BuildRequires: pkgconfig(deviced)
-%endif
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(bundle)
+BuildRequires: pkgconfig(sqlite3)
 BuildRequires: pkgconfig(security-server)
 BuildRequires: pkgconfig(db-util)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(appsvc)
 BuildRequires: pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(gio-unix-2.0)
+BuildRequires: python-xml
 
 %description
 Alarm Server and devel libraries
@@ -56,34 +56,21 @@ Alarm server library (devel)
 %prep
 %setup -q
 
-# HACK_removed_dbus_glib_alarm_manager_object_info.diff
-#%patch0 -p1
-
 %build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %if 0%{?sec_build_binary_debug_enable}
-export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
-export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE"
-export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
 %endif
-
-%if %{_repository} == "wearable"
-export CFLAGS="$CFLAGS -DWEARABLE_PROFILE"
-export DEVICE_PROFILE="wearable"
+%ifarch %{ix86}
+       ARCH=x86
 %else
-export CFLAGS="$CFLAGS -DMOBILE_PROFILE"
-export DEVICE_PROFILE="mobile"
+       ARCH=arm
 %endif
 
-export LDFLAGS+=" -Wl,--rpath=%{_libdir} -Wl,--as-needed"
-
-%autogen --disable-static
-
-dbus-binding-tool --mode=glib-server --prefix=alarm_manager ./alarm_mgr.xml > ./include/alarm-skeleton.h
-dbus-binding-tool --mode=glib-client --prefix=alarm_manager ./alarm_mgr.xml > ./include/alarm-stub.h
-dbus-binding-tool --mode=glib-server --prefix=alarm_client ./alarm-expire.xml > ./include/alarm-expire-skeleton.h
-dbus-binding-tool --mode=glib-client --prefix=alarm_client ./alarm-expire.xml > ./include/alarm-expire-stub.h
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=${ARCH}
 
-%configure --disable-static
 make %{?jobs:-j%jobs}
 
 
@@ -105,15 +92,9 @@ cp LICENSE %{buildroot}/usr/share/license/libalarm
 
 %post -n alarm-server
 
-%if %{_repository} == "wearable"
 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
-%else
-vconftool set -t int db/system/timechange 0 -g 5000 -s system::vconf
-vconftool set -t double db/system/timechange_external 0 -g 5000 -s system::vconf
-vconftool set -t int memory/system/timechanged 0 -i -g 5000 -s system::vconf
-%endif
 
 chmod 755 /usr/bin/alarm-server
 
@@ -122,15 +103,12 @@ chmod 644 /usr/lib/libalarm.so.0.0.0
 
 
 %files -n alarm-server
-%if %{_repository} == "wearable"
-%manifest alarm-server-wearable.manifest
-%else
-%manifest alarm-server-mobile.manifest
-%endif
+%manifest alarm-server.manifest
 %{_bindir}/*
 %{_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
 
 %files -n libalarm
 %manifest alarm-lib.manifest
index 07c82b8..49bb577 100644 (file)
@@ -4,6 +4,9 @@ After=system-server.service
 
 [Service]
 ExecStart=/usr/bin/alarm-server
+TimeoutStopSec=3s
+Restart=always
+RestartSec=0
 
 [Install]
 WantedBy=multi-user.target
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..4aaa344
--- /dev/null
@@ -0,0 +1,63 @@
+SET(this_target alarm)
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION_MAJOR 1)
+SET(VERSION "${VERSION_MAJOR}.1")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+SET(LIB_PKGS glib-2.0 gobject-2.0 dlog security-server bundle appsvc gio-2.0 gio-unix-2.0)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(lib_pkgs REQUIRED ${LIB_PKGS})
+
+FOREACH(flag ${lib_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -Wall -Wno-unused")
+ENDFOREACH(flag)
+
+SET(${this_target}_SOURCE_FILES
+       alarm-lib.c
+       alarm-lib-stub.c
+)
+
+ADD_CUSTOM_COMMAND(
+        WORKING_DIRECTORY
+        OUTPUT alarm-mgr-stub.c
+        COMMAND gdbus-codegen --interface-prefix com.samsung.
+                               --generate-c-code alarm-mgr-stub
+                               ../alarm_mgr.xml
+        COMMENT "Generating Server GDBus .c/.h")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${this_target} SHARED ${${this_target}_SOURCE_FILES} alarm-mgr-stub.c)
+
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both")
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}")
+
+SET_TARGET_PROPERTIES(${this_target}
+       PROPERTIES
+       VERSION 0.0.0
+       SOVERSION ${MAJORVER}
+       CLEAN_DIRECT_OUTPUT 1
+)
+
+TARGET_LINK_LIBRARIES(${this_target} ${lib_pkgs_LDFLAGS})
+
+ADD_CUSTOM_COMMAND(TARGET ${this_target}
+               POST_BUILD
+               COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER}${LIBRARY_OUTPUT_PATH}  ${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${MAJORVER}
+
+)
+
+# pkgconfig file
+CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/alarm-service.pc.in ${CMAKE_SOURCE_DIR}/alarm-service.pc @ONLY)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/alarm-service.pc DESTINATION lib/pkgconfig)
+INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/ FILES_MATCHING PATTERN "alarm.h")
+INSTALL(TARGETS ${this_target} DESTINATION lib)
+
diff --git a/src/alarm-lib-stub.c b/src/alarm-lib-stub.c
new file mode 100644 (file)
index 0000000..fec51cd
--- /dev/null
@@ -0,0 +1,587 @@
+/*
+ *  alarm-manager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
+ * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <string.h>
+#include <glib.h>
+#include "alarm.h"
+#include "alarm-internal.h"
+#include "alarm-mgr-stub.h"
+#include "security-server.h"
+
+#define ALARM_SERVICE_NAME     "appframework.alarm"
+#define ALARM_OBJECT_PATH      "/appframework/alarm"
+#define ALARM_INTERFACE_NAME "appframework.alarm"
+
+
+bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
+                       alarm_id_t *alarm_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_delete(alarm_context_t context, alarm_id_t alarm_id,
+                       int *error_code);
+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);
+
+char* __get_cookie(int *error_code)
+{
+       char *e_cookie = NULL;
+       char cookie[256] = {0,};
+       int size = 0;
+       int retval = 0;
+
+       size = security_server_get_cookie_size();
+       retval = security_server_request_cookie(cookie, size);
+       if (retval < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("security_server_request_cookie() is failed. retval = %d", retval);
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               return NULL;
+       }
+
+       e_cookie = g_base64_encode((const guchar *)cookie, size);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("g_base64_encode() is failed.");
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               return NULL;
+       }
+
+       ALARM_MGR_LOG_PRINT("Gets the cookie successfully.");
+       return e_cookie;
+}
+
+
+bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
+                       alarm_id_t *alarm_id, bundle *b,
+                       int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       char *e_cookie = NULL;
+       bundle_raw *b_data = NULL;
+       int datalen = 0;
+
+       if (bundle_encode(b, &b_data, &datalen))
+       {
+               ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n");
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               return false;
+       }
+
+       e_cookie = __get_cookie(error_code);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       if (!alarm_manager_call_alarm_create_appsvc_sync((AlarmManager*)context.proxy, context.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,
+                                                   alarm_info->end.year,
+                                                   alarm_info->end.month,
+                                                   alarm_info->end.day,
+                                                   alarm_info->mode.u_interval.day_of_week,
+                                                   alarm_info->mode.repeat,
+                                                   alarm_info->alarm_type,
+                                                   alarm_info->reserved_info,
+                                                   (char *)b_data, e_cookie,
+                                                   alarm_id, &return_code,
+                                                   NULL, &error)) {
+               /* g_dbus_proxy_call_sync error */
+               /* 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);
+       }
+
+       g_free(e_cookie);
+
+       if (b_data) {
+               free(b_data);
+               b_data = NULL;
+       }
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+
+
+bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info,
+                       alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod,
+                       int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       char *e_cookie = NULL;
+
+       /*TODO: Dbus bus name validation is must & will be added to avoid alarm-server crash*/
+       if (g_quark_to_string(context.quark_app_service_name) == NULL
+               && strlen(dst_service_name) == 4
+               && strncmp(dst_service_name, "null",4) == 0) {
+                       ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n");
+               if (error_code) {
+                       *error_code = ERR_ALARM_INVALID_PARAM;
+               }
+               return false;
+       }
+
+       e_cookie = __get_cookie(error_code);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       if (!alarm_manager_call_alarm_create_sync((AlarmManager*)context.proxy, context.pid,
+                       g_quark_to_string(context.quark_app_service_name),
+                       g_quark_to_string(context.quark_app_service_name_mod),
+                                                   alarm_info->start.year,
+                                                   alarm_info->start.month,
+                                                   alarm_info->start.day,
+                                                   alarm_info->start.hour,
+                                                   alarm_info->start.min,
+                                                   alarm_info->start.sec,
+                                                   alarm_info->end.year,
+                                                   alarm_info->end.month,
+                                                   alarm_info->end.day,
+                                                   alarm_info->mode.u_interval.day_of_week,
+                                                   alarm_info->mode.repeat,
+                                                   alarm_info->alarm_type,
+                                                   alarm_info->reserved_info,
+                                                   dst_service_name, dst_service_name_mod, e_cookie,
+                                                   alarm_id, &return_code,
+                                                   NULL, &error)) {
+               /* g_dbus_proxy_call_sync error error */
+               /* 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_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               g_free(e_cookie);
+               return false;
+       }
+
+       g_free(e_cookie);
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       bundle *b = NULL;
+       char *e_cookie = NULL;
+       gchar *b_data = NULL;
+       int len = 0;
+
+       e_cookie = __get_cookie(error_code);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       if (!alarm_manager_call_alarm_get_appsvc_info_sync
+           ((AlarmManager*)context.proxy, context.pid, alarm_id, e_cookie, &b_data, &return_code, NULL, &error)) {
+               /* 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_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+
+               g_free(e_cookie);
+
+               if (b_data) {
+                       g_free(b_data);
+               }
+
+               return NULL;
+       }
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+       } else {
+               b = bundle_decode((bundle_raw *)b_data, len);
+       }
+
+       g_free(e_cookie);
+
+       if (b_data) {
+               g_free(b_data);
+       }
+
+       return b;
+}
+
+
+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);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       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)) {
+               /* 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]\n", return_code);
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+
+               g_free(e_cookie);
+               return false;
+       }
+
+       g_free(e_cookie);
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+
+bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       char *e_cookie = NULL;
+
+       e_cookie = __get_cookie(error_code);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       if (!alarm_manager_call_alarm_delete_sync
+           ((AlarmManager*)context.proxy, context.pid, alarm_id, e_cookie, &return_code, NULL, &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);
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+
+               g_free(e_cookie);
+               return false;
+       }
+
+       g_free(e_cookie);
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+
+bool _send_alarm_delete_all(alarm_context_t context, int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       char *e_cookie = NULL;
+
+       e_cookie = __get_cookie(error_code);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       if (!alarm_manager_call_alarm_delete_all_sync
+           ((AlarmManager*)context.proxy, context.pid, e_cookie, &return_code, NULL, &error)) {
+               /* 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_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+
+               g_free(e_cookie);
+               return false;
+       }
+
+       g_free(e_cookie);
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+
+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)
+{
+       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,
+                            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_list_of_ids_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", alarm_id, return_code);
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+
+               return false;
+       }
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+       else
+       {
+               GVariantIter *iter = NULL;
+               gint i = 0;
+               g_variant_get (alarm_array, "ai", &iter);
+               while (g_variant_iter_loop (iter, "i", &alarm_id[i]))
+               {
+                       ALARM_MGR_LOG_PRINT("alarm_id (%d)", alarm_id[i]);
+                       i++;
+               }
+               g_variant_iter_free (iter);
+               *num_of_ids = i;
+               g_variant_unref(alarm_array);
+       }
+
+       return true;
+}
+
+bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids,
+                                  int *error_code)
+{
+       GError *error = NULL;
+       gint return_code = 0;
+       char *e_cookie = NULL;
+
+       e_cookie = __get_cookie(error_code);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       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);
+
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               return false;
+       }
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+
+bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id,
+                         alarm_info_t *alarm_info, int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       char *e_cookie = NULL;
+
+       e_cookie = __get_cookie(error_code);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       if (!alarm_manager_call_alarm_get_info_sync((AlarmManager*)context.proxy,
+               context.pid, alarm_id, e_cookie, &alarm_info->start.year,
+               &alarm_info->start.month, &alarm_info->start.day,
+               &alarm_info->start.hour, &alarm_info->start.min,
+               &alarm_info->start.sec, &alarm_info->end.year,
+               &alarm_info->end.month, &alarm_info->end.day,
+               &alarm_info->mode.u_interval.day_of_week,
+               (gint *)&alarm_info->mode.repeat,
+               &alarm_info->alarm_type, &alarm_info->reserved_info, &return_code, NULL, &error)) {
+               /* 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);
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               g_free(e_cookie);
+               return false;
+       }
+
+       g_free(e_cookie);
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+
+bool _send_alarm_get_next_duetime(alarm_context_t context,
+                                alarm_id_t alarm_id, time_t* duetime,
+                                int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       char *e_cookie = NULL;
+
+       e_cookie = __get_cookie(error_code);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       if (!alarm_manager_call_alarm_get_next_duetime_sync((AlarmManager*)context.proxy,
+                            context.pid, alarm_id, e_cookie, duetime, &return_code, NULL, &error)) {
+               /*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);
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               g_free(e_cookie);
+               return false;
+       }
+
+       g_free(e_cookie);
+
+       if (return_code != 0) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
+
+bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code)
+{
+       GError *error = NULL;
+       int return_code = 0;
+       char *e_cookie = NULL;
+
+       e_cookie = __get_cookie(error_code);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("Getting the cookie is failed. error_code = %d", *error_code);
+               return false;
+       }
+
+       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);
+               if (error_code) {
+                       *error_code = ERR_ALARM_SYSTEM_FAIL;
+               }
+               g_free(e_cookie);
+               return false;
+       }
+
+       g_free(e_cookie);
+
+       if (return_code != ALARMMGR_RESULT_SUCCESS) {
+               if (error_code) {
+                       *error_code = return_code;
+               }
+               return false;
+       }
+
+       return true;
+}
similarity index 66%
rename from alarm-lib.c
rename to src/alarm-lib.c
index 068e595..1abaf5b 100644 (file)
 
 
 
-#include<stdio.h>
-#include<stdlib.h>
-#include<errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
 #include <unistd.h>
 #include <sys/stat.h>
-#include<sys/types.h>
-#include<string.h>
-#include<dbus/dbus.h>
-#include<dbus/dbus-glib.h>
-#include<glib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <glib.h>
 #include <fcntl.h>
-#include <dbus/dbus-glib-lowlevel.h>
 
 #include "alarm.h"
 #include "alarm-internal.h"
-#include "alarm-stub.h"
+#include "alarm-mgr-stub.h"
 #include <bundle.h>
 #include <appsvc.h>
 #include <aul.h>
+#include <gio/gio.h>
 
 #define MAX_KEY_SIZE 256
+#define MAX_PROC_NAME_LEN 512
 
 static alarm_context_t alarm_context = { NULL, NULL, NULL, NULL, -1 };
 
@@ -52,21 +51,17 @@ static bool sub_initialized = false;
 
 pthread_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
 
-#define MAX_OBJECT_PATH_LEN 256
-#define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
+static void __handle_expiry_method_call(GDBusConnection *conn,
+       const gchar *name, const gchar *path, const gchar *interface,
+       const gchar *method, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data);
 
-static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection,
-                                              DBusMessage *message,
-                                              void *user_data);
 static int __alarm_validate_date(alarm_date_t *date, int *error_code);
 static bool __alarm_validate_time(alarm_date_t *date, int *error_code);
 static int __sub_init(void);
 static int __alarmmgr_init_appsvc(void);
-bool alarm_power_off(int *error_code);
-int alarmmgr_check_next_duetime(void);
 
 typedef struct _alarm_cb_info_t {
-       int alarm_id;
+       alarm_id_t alarm_id;
        alarm_cb_t cb_func;
        void *priv_data;
        struct _alarm_cb_info_t *next;
@@ -74,8 +69,28 @@ typedef struct _alarm_cb_info_t {
 
 static alarm_cb_info_t *alarmcb_head = NULL;
 
-static void __add_resultcb(int alarm_id, alarm_cb_t cb_func,
-                        void *data)
+guint registration_id = 0;
+
+static GDBusNodeInfo *introspection_data = NULL;
+
+static const gchar introspection_xml[] =
+  "<node name='/com/samsung/alarm/client'>"
+  "  <interface name='com.samsung.alarm.client'>"
+  "    <method name='alarm_expired'>"
+  "      <arg type='i' name='alarm_id' direction='in'/>"
+  "      <arg type='s' name='service_name' direction='in'/>"
+  "    </method>"
+  "  </interface>"
+  "</node>";
+
+static const GDBusInterfaceVTable interface_vtable =
+{
+       __handle_expiry_method_call,
+       NULL,
+       NULL
+};
+
+static void __add_resultcb(alarm_id_t alarm_id, alarm_cb_t cb_func, void *data)
 {
        alarm_cb_info_t *info;
 
@@ -90,14 +105,16 @@ static void __add_resultcb(int alarm_id, alarm_cb_t cb_func,
        alarmcb_head = info;
 }
 
-static alarm_cb_info_t *__find_resultcb(int alarm_id)
+static alarm_cb_info_t *__find_resultcb(alarm_id_t alarm_id)
 {
        alarm_cb_info_t *tmp;
 
        tmp = alarmcb_head;
        while (tmp) {
-               if (tmp->alarm_id == alarm_id)
+               if (tmp->alarm_id == alarm_id) {
+                       ALARM_MGR_LOG_PRINT("matched alarm id =  %d", alarm_id);
                        return tmp;
+               }
                tmp = tmp->next;
        }
        return NULL;
@@ -127,56 +144,27 @@ static void __remove_resultcb(alarm_cb_info_t *info)
        }
 }
 
-static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection,
-                                              DBusMessage *message,
-                                              void *user_data)
+static void __handle_expiry_method_call(GDBusConnection *conn,
+                const gchar *name, const gchar *path, const gchar *interface,
+                const gchar *method, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
 {
-       alarm_cb_info_t *info;
-
-       if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL) {
-               const char *method_name = dbus_message_get_member(message);
-               /*"alarm_expired" */
-
-               if (strcmp(method_name, "alarm_expired") == 0) {
-                       DBusMessageIter iter;
-                       alarm_id_t alarm_id;
-                       const char *service_name =
-                           dbus_message_get_destination(message);
-                       const char *object_path =
-                           dbus_message_get_path(message);
-                       /* "/com/samsung/alarm/client" */
-                       const char *interface_name =
-                           dbus_message_get_interface(message);
-                       /* "com.samsung.alarm.client" */
-
-                       dbus_message_iter_init(message, &iter);
-                       dbus_message_iter_get_basic(&iter, &alarm_id);
-
-                       SECURE_LOGD("[alarm-lib]:service_name=%s, "
-                       "object_path=%s, interface_name=%s, method_name=%s, "
-                       "alarm_id=%d, handler=%s\n",
-                       service_name ? service_name : "no name",
-                       object_path ? object_path : "no path",
-                       interface_name ? interface_name : "no interface",
-                       method_name ? method_name : "no method", alarm_id,
-                       alarm_context.alarm_handler ? "ok" : "no handler");
-
-                       if (alarm_context.alarm_handler != NULL)
-                               /* alarm_context.alarm_handler(alarm_id); */
-                               alarm_context.alarm_handler(alarm_id,
-                                       alarm_context.user_param);
-                       info = __find_resultcb(alarm_id);
-
-                       if( info && info->cb_func ) {
-                               info->cb_func(alarm_id, info->priv_data);
-                       //      __remove_resultcb(info);
-                       }
+       if (method && strcmp(method, "alarm_expired") == 0) {
+               const 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_MGR_EXCEPTION_PRINT("[alarm-lib] : Alarm expired for [%s] : Alarm id [%d]", package_name, alarm_id);
+
+               if (alarm_context.alarm_handler != NULL) {
+                       alarm_context.alarm_handler(alarm_id, alarm_context.user_param);
+               }
 
-                       return DBUS_HANDLER_RESULT_HANDLED;
+               info = __find_resultcb(alarm_id);
+               if (info && info->cb_func) {
+                       info->cb_func(alarm_id, info->priv_data);
                }
+               g_free(package_name);
        }
-
-       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
 static int __alarm_validate_date(alarm_date_t *date, int *error_code)
@@ -252,36 +240,77 @@ static bool __alarm_validate_time(alarm_date_t *date, int *error_code)
 static int __sub_init()
 {
        GError *error = NULL;
+       char proc_file[MAX_PROC_NAME_LEN] = {0, };
+       char process_name[MAX_PROC_NAME_LEN] = {0, };
+       int fd = 0;
+       int ret = 0;
+       const int MAX_LEN = MAX_PROC_NAME_LEN;
 
        pthread_mutex_lock(&init_lock);
 
        if (sub_initialized) {
-               //ALARM_MGR_LOG_PRINT("__sub_init was already called.\n");
                pthread_mutex_unlock(&init_lock);
                return ALARMMGR_RESULT_SUCCESS;
        }
 
        g_thread_init(NULL);
-       dbus_g_thread_init();
+       g_type_init();
 
-       alarm_context.bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
-       if (alarm_context.bus == NULL) {
-               ALARM_MGR_EXCEPTION_PRINT("dbus bus get failed\n");
+       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);
                pthread_mutex_unlock(&init_lock);
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
-       alarm_context.proxy = dbus_g_proxy_new_for_name(alarm_context.bus,
+       alarm_context.proxy = g_dbus_proxy_new_sync(alarm_context.connection,
+                                                       G_DBUS_PROXY_FLAGS_NONE,
+                                                       NULL,
                                                        "com.samsung.alarm.manager",
                                                        "/com/samsung/alarm/manager",
-                                                       "com.samsung.alarm.manager");
+                                                       "com.samsung.alarm.manager",
+                                                       NULL,
+                                                       NULL);
+
        if (alarm_context.proxy == NULL) {
-               ALARM_MGR_EXCEPTION_PRINT("dbus bus proxy get failed\n");
+               ALARM_MGR_EXCEPTION_PRINT("Creating a proxy is failed.");
+               g_object_unref (alarm_context.connection);
                pthread_mutex_unlock(&init_lock);
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
-       alarm_context.pid = getsid(getpid());   /*this running appliction's session id*/
+       // Only webapp which has a pid of WebProcess uses the sid. Otherwise, the pid is used.
+       snprintf(proc_file, MAX_LEN, "/proc/%d/cmdline", getpid());
+       fd = open(proc_file, O_RDONLY);
+       if (fd < 0) {
+               SECURE_LOGE("Unable to get the proc file(%d).\n", getpid());
+               g_object_unref(alarm_context.proxy);
+               g_object_unref(alarm_context.connection);
+               pthread_mutex_unlock(&init_lock);
+               return ERR_ALARM_SYSTEM_FAIL;
+       }
+       else {
+               ret = read(fd, process_name, MAX_LEN);
+               close(fd);
+               if (ret < 0) {
+                       ALARM_MGR_EXCEPTION_PRINT("Unable to read the proc file(%d).", getpid());
+                       g_object_unref(alarm_context.proxy);
+                       g_object_unref(alarm_context.connection);
+                       pthread_mutex_unlock(&init_lock);
+                       return ERR_ALARM_SYSTEM_FAIL;
+               }
+               else {
+                       if (strncmp(process_name, "/usr/bin/WebProcess", strlen("/usr/bin/WebProcess")) == 0) {
+                               alarm_context.pid = getsid(getpid());
+                               SECURE_LOGD("alarm_context.pid is set to sessionID, %d.", alarm_context.pid);
+                       }
+                       else {
+                               alarm_context.pid = getpid();
+                               SECURE_LOGD("alarm_context.pid is set to processID, %d.", alarm_context.pid);
+                       }
+               }
+       }
 
        sub_initialized = true;
 
@@ -290,50 +319,14 @@ static int __sub_init()
        return ALARMMGR_RESULT_SUCCESS;
 }
 
-bool alarm_power_off(int *error_code)
-{
-       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_off() is called\n");
-
-#ifdef __ALARM_BOOT
-       return _send_alarm_power_off(alarm_context, error_code);
-#else
-       ALARM_MGR_LOG_PRINT(
-                       "[alarm-lib]:ALARM_BOOT feature is not supported. "
-                           "so we return false.\n");
-       if (error_code)
-               *error_code = -1;       /*-1 means that system failed
-                                                       internally.*/
-       return false;
-#endif
-}
-
-int alarmmgr_check_next_duetime()
-{
-       int error_code;
-       ALARM_MGR_LOG_PRINT(
-           "[alarm-lib]:alarm_check_next_duetime() is called\n");
-
-#ifdef __ALARM_BOOT
-       if (!_send_alarm_check_next_duetime(alarm_context, &error_code))
-               return error_code;
-#else
-       ALARM_MGR_LOG_PRINT(
-                   "[alarm-lib]:ALARM_BOOT feature is not supported. "
-                           "so we return false.\n");
-       return ERR_ALARM_SYSTEM_FAIL;
-#endif
-
-       return ALARMMGR_RESULT_SUCCESS;
-}
-
 EXPORT_API int alarmmgr_init(const char *appid)
 {
-       DBusError derror;
+       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;
+       int ret = ALARMMGR_RESULT_SUCCESS;
+       guint owner_id = 0;
        int i = 0;
        int j = 0;
        int len = 0;
@@ -345,8 +338,7 @@ EXPORT_API int alarmmgr_init(const char *appid)
                return ERR_ALARM_INVALID_PARAM;
 
        if (b_initialized) {
-               SECURE_LOGD(
-                    "alarm was already initialized. app_service_name=%s\n",
+               SECURE_LOGD("alarm was already initialized. app_service_name=%s",
                     g_quark_to_string(alarm_context.quark_app_service_name));
                return ALARMMGR_RESULT_SUCCESS;
        }
@@ -355,79 +347,110 @@ EXPORT_API int alarmmgr_init(const char *appid)
        if (ret < 0)
                return ret;
 
-       memset(service_name_mod, 'a', MAX_SERVICE_NAME_LEN-1);
+       memset(service_name_mod, 'a', MAX_SERVICE_NAME_LEN - 1);
 
        len = strlen("ALARM.");
        strncpy(service_name, "ALARM.", len);
        strncpy(service_name + len, appid, strlen(appid));
 
-       j=0;
-
-        for(i=0;i<=strlen(service_name);i++)
-        {
-                if (service_name[i] == '.' )
-                {
+       for(i = 0; i <= strlen(service_name); i++) {
+               if (service_name[i] == '.') {
                        service_name_mod[j] = service_name[i];
-                        j++;
-                }
-               else{
+                       j++;
+               }
+               else {
                        service_name_mod[j] = service_name[i];
                }
-                j++;
-        }
-
-       SECURE_LOGD("[alarm-lib]: service_name %s\n", service_name);
-       SECURE_LOGD("[alarm-lib]: service_name_mod %s\n", service_name_mod);
+               j++;
+       }
 
-       dbus_error_init(&derror);
+       SECURE_LOGD("[alarm-lib]: dbus own name: %s", service_name_mod);
+       owner_id = g_bus_own_name_on_connection(alarm_context.connection, service_name_mod,
+                                                                               G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL);
+       if (owner_id == 0) {
+               ALARM_MGR_EXCEPTION_PRINT("Acquiring the own name is failed. %s", service_name_mod);
+               goto error;
+       }
 
-       request_name_result = dbus_bus_request_name(
-                         dbus_g_connection_get_connection(alarm_context.bus),
-                         service_name_mod, 0, &derror);
-       if (dbus_error_is_set(&derror)) /*failure*/ {
-               SECURE_LOGE(
-                    "Failed to dbus_bus_request_name(%s): %s\n", service_name,
-                    derror.message);
-               dbus_error_free(&derror);
+       introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
+       if (introspection_data == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("g_dbus_node_info_new_for_xml() is failed.");
+               goto error;
+       }
 
-               return ERR_ALARM_SYSTEM_FAIL;
+       registration_id = g_dbus_connection_register_object(alarm_context.connection,
+                                                                                               "/com/samsung/alarm/client",
+                                                                                               introspection_data->interfaces[0],
+                                                                                               &interface_vtable, NULL, NULL, NULL);
+       if (registration_id == 0) {
+               ALARM_MGR_EXCEPTION_PRINT("Registering the callback is failed.");
+               goto error;
        }
-       alarm_context.quark_app_service_name =
-           g_quark_from_string(service_name);
-       alarm_context.quark_app_service_name_mod=
-           g_quark_from_string(service_name_mod);
 
+       alarm_context.quark_app_service_name = g_quark_from_string(service_name);
+       alarm_context.quark_app_service_name_mod= g_quark_from_string(service_name_mod);
 
-       if (!dbus_connection_add_filter(
-            dbus_g_connection_get_connection(alarm_context.bus),
-            __expire_alarm_filter, NULL, NULL)) {
-               ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
+       b_initialized = true;
 
-               return ERR_ALARM_SYSTEM_FAIL;
+       SECURE_LOGD("Leave");
+       return ALARMMGR_RESULT_SUCCESS;
+
+error:
+       if (introspection_data) {
+               g_dbus_node_info_unref(introspection_data);
        }
+       if (registration_id != 0) {
+               g_dbus_connection_unregister_object(alarm_context.connection, registration_id);
+       }
+       g_object_unref(alarm_context.proxy);
+       alarm_context.proxy = NULL;
 
-       b_initialized = true;
-       return ALARMMGR_RESULT_SUCCESS;
+       g_object_unref(alarm_context.connection);
+       alarm_context.connection = NULL;
 
+       sub_initialized = false;
+       return ERR_ALARM_INVALID_PARAM;
 }
 
 EXPORT_API void alarmmgr_fini()
 {
-       dbus_connection_remove_filter(dbus_g_connection_get_connection
-                                     (alarm_context.bus),
-                                     __expire_alarm_filter, NULL);
+       SECURE_LOGD("Enter");
+       if (introspection_data) {
+               g_dbus_node_info_unref(introspection_data);
+       }
+
+       if (alarm_context.connection != NULL && registration_id != 0) {
+               g_dbus_connection_unregister_object(alarm_context.connection, registration_id);
+       }
+
+       if (alarm_context.proxy) {
+               g_object_unref(alarm_context.proxy);
+               alarm_context.proxy = NULL;
+       }
+
+       if (alarm_context.connection) {
+               g_object_unref(alarm_context.connection);
+               alarm_context.connection = NULL;
+       }
+
        b_initialized = false;
+       sub_initialized = false;
+
+       SECURE_LOGD("Leave");
 }
 
 EXPORT_API int alarmmgr_set_cb(alarm_cb_t handler, void *user_param)
 {
-       ALARM_MGR_LOG_PRINT("alarm_set_cb is called\n");
+       SECURE_LOGD("Enter");
 
        if (handler == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("callback is NULL.");
                return ERR_ALARM_INVALID_PARAM;
        }
        alarm_context.alarm_handler = handler;
        alarm_context.user_param = user_param;
+
+       SECURE_LOGD("Leave");
        return ALARMMGR_RESULT_SUCCESS;
 }
 
@@ -613,16 +636,18 @@ EXPORT_API void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return
 
        ret = __sub_init();
        if (ret < 0){
-               if (return_code)
+               if (return_code) {
                        *return_code = ret;
+               }
                return NULL;
        }
 
-       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_alarm_appsvc_info() is called\n");
+       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_alarm_appsvc_info() is called.");
 
        if (alarm_id <= 0) {
-               if (return_code)
+               if (return_code) {
                        *return_code = ERR_ALARM_INVALID_ID;
+               }
                return NULL;
        }
 
@@ -674,7 +699,7 @@ EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, vo
        alarm_info_t *alarm_info = NULL;        /* = (alarm_info_t*)alarm; */
        const char *operation = NULL;
        int error_code = 0;
-       char *appid = NULL;
+       const char *appid = NULL;
 
        bundle *b=(bundle *)bundle_data;
 
@@ -720,7 +745,7 @@ EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, vo
        }
        alarm_mode_t *mode = &alarm_info->mode;
 
-       ALARM_MGR_LOG_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
+       ALARM_MGR_EXCEPTION_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
                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->end.year, alarm_info->end.month, alarm_info->end.day,
@@ -747,9 +772,7 @@ EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, vo
        }
 
 
-       if (!_send_alarm_create_appsvc
-           (alarm_context, alarm_info, alarm_id, b,
-            &error_code)) {
+       if (!_send_alarm_create_appsvc(alarm_context, alarm_info, alarm_id, b, &error_code)) {
                return error_code;
        }
 
@@ -788,7 +811,7 @@ EXPORT_API int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
        if (ret < 0)
                return ret;
 
-       ALARM_MGR_LOG_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
+       ALARM_MGR_EXCEPTION_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
                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->end.year, alarm_info->end.month, alarm_info->end.day,
@@ -821,38 +844,31 @@ EXPORT_API int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
        }
 
        if (destination != NULL) {
-               memset(dst_service_name, 0,
-                      strlen(destination) + strlen("ALARM.") + 2);
-               snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "ALARM.%s",
-                        destination);
-
-               memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
-
-               j=0;
-
-               for(i=0; i<=strlen(dst_service_name); i++)
-               {
-                       if (dst_service_name[i] == '.' )
-                       {
+               memset(dst_service_name, 0, strlen(destination) + strlen("ALARM.") + 2);
+               snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "ALARM.%s", destination);
+               memset(dst_service_name_mod, 'a', MAX_SERVICE_NAME_LEN-1);
+
+               for (i=0; i<=strlen(dst_service_name); i++)
+               {
+                       if (dst_service_name[i] == '.' )
+                       {
                                dst_service_name_mod[j] = dst_service_name[i];
-                               j++;
-                       }
-                       else
-                       {
-                               dst_service_name_mod[j] = dst_service_name[i];
-                       }
-                       j++;
-               }
+                               j++;
+                       }
+                       else
+                       {
+                               dst_service_name_mod[j] = dst_service_name[i];
+                       }
+                       j++;
+               }
 
-               if (!_send_alarm_create
-                   (alarm_context, alarm_info, alarm_id, dst_service_name, dst_service_name_mod,
-                    &error_code)) {
+               if (!_send_alarm_create(alarm_context, alarm_info, alarm_id, dst_service_name, dst_service_name_mod, &error_code)) {
+                       return error_code;
+               }
+       } else {
+               if (!_send_alarm_create(alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
                        return error_code;
                }
-       } else
-           if (!_send_alarm_create
-               (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
-               return error_code;
        }
 
        return ALARMMGR_RESULT_SUCCESS;
@@ -865,7 +881,7 @@ EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
                                  alarm_id_t *alarm_id)
 {
        int error_code = 0;;
-       time_t current_time;
+       struct timeval current_time;
        struct tm duetime_tm;
        alarm_info_t alarm_info;
        const char *operation = NULL;
@@ -913,11 +929,21 @@ 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;
 
-       time(&current_time);
+       gettimeofday(&current_time, NULL);
 
-       current_time += trigger_at_time;
+       if (current_time.tv_usec > 500 * 1000)
+       {
+               // When the millisecond part of the current_time is bigger than 500ms,
+               // the duetime increases by extra 1sec.
+               current_time.tv_sec += (trigger_at_time + 1);
+       }
+       else
+       {
+               current_time.tv_sec += trigger_at_time;
+       }
 
-       localtime_r(&current_time, &duetime_tm);
+       tzset();        // Processes the TZ environment variable, and Set timezone, daylight, and tzname.
+       localtime_r(&current_time.tv_sec, &duetime_tm);
 
        alarm_info.start.year = duetime_tm.tm_year + 1900;
        alarm_info.start.month = duetime_tm.tm_mon + 1;
@@ -939,14 +965,12 @@ EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
                alarm_info.mode.u_interval.interval = interval;
        }
 
-       ALARM_MGR_LOG_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
+       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);
 
-       if (!_send_alarm_create_appsvc
-           (alarm_context, &alarm_info, alarm_id, b,
-            &error_code)) {
+       if (!_send_alarm_create_appsvc(alarm_context, &alarm_info, alarm_id, b, &error_code)) {
                return error_code;
        }
 
@@ -963,7 +987,7 @@ EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
        int i = 0;
        int j = 0;
        int error_code;
-       time_t current_time;
+       struct timeval current_time;
        struct tm duetime_tm;
        alarm_info_t alarm_info;
        int ret;
@@ -990,11 +1014,21 @@ EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
        alarm_info.alarm_type = alarm_type;
        alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
 
-       time(&current_time);
+       gettimeofday(&current_time, NULL);
 
-       current_time += trigger_at_time;
+       if (current_time.tv_usec > 500 * 1000)
+       {
+               // When the millisecond part of the current_time is bigger than 500ms,
+               // the duetime increases by extra 1sec.
+               current_time.tv_sec += (trigger_at_time + 1);
+       }
+       else
+       {
+               current_time.tv_sec += trigger_at_time;
+       }
 
-       localtime_r(&current_time, &duetime_tm);
+       tzset();        // Processes the TZ environment variable, and Set timezone, daylight, and tzname.
+       localtime_r(&current_time.tv_sec, &duetime_tm);
 
        alarm_info.start.year = duetime_tm.tm_year + 1900;
        alarm_info.start.month = duetime_tm.tm_mon + 1;
@@ -1016,7 +1050,7 @@ EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
                alarm_info.mode.u_interval.interval = interval;
        }
 
-       ALARM_MGR_LOG_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
+       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);
@@ -1065,22 +1099,22 @@ EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
        char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
        int i = 0;
        int j = 0;
-       int error_code;
-       time_t current_time;
+       int error_code = 0;
+       struct timeval current_time;
        struct tm duetime_tm;
        alarm_info_t alarm_info;
-       int ret;
-       char appid[256];
+       int ret = 0;
+       char appid[256] = {0,};
 
-       aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+       if (aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)) != AUL_R_OK) {
+               ALARM_MGR_LOG_PRINT("aul_app_get_appid_bypid() is failed. PID %d may not be app.", getpid());
+       }
 
        ret = alarmmgr_init(appid);
        if (ret < 0)
                return ret;
 
-       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_add_alarm_withcb() is called\n");
-
-       ALARM_MGR_LOG_PRINT("interval(%d)", interval);
+       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_add_alarm_withcb() is called");
 
        if (alarm_id == NULL) {
                return ERR_ALARM_INVALID_PARAM;
@@ -1094,11 +1128,21 @@ EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
        alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
        alarm_info.alarm_type |= ALARM_TYPE_WITHCB;
 
-       time(&current_time);
+       gettimeofday(&current_time, NULL);
 
-       current_time += trigger_at_time;
+       if (current_time.tv_usec > 500 * 1000)
+       {
+               // When the millisecond part of the current_time is bigger than 500ms,
+               // the duetime increases by extra 1sec.
+               current_time.tv_sec += (trigger_at_time + 1);
+       }
+       else
+       {
+               current_time.tv_sec += trigger_at_time;
+       }
 
-       localtime_r(&current_time, &duetime_tm);
+       tzset();        // Processes the TZ environment variable, and Set timezone, daylight, and tzname.
+       localtime_r(&current_time.tv_sec, &duetime_tm);
 
        alarm_info.start.year = duetime_tm.tm_year + 1900;
        alarm_info.start.month = duetime_tm.tm_mon + 1;
@@ -1120,6 +1164,11 @@ EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
                alarm_info.mode.u_interval.interval = interval;
        }
 
+       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.interval, alarm_info.alarm_type);
+
        if (!_send_alarm_create(alarm_context, &alarm_info, alarm_id, "null","null", &error_code)) {
                return error_code;
        }
@@ -1155,7 +1204,7 @@ EXPORT_API int alarmmgr_remove_alarm(alarm_id_t alarm_id)
 
 EXPORT_API int alarmmgr_remove_all(void)
 {
-       GError *error = NULL;
+       int error_code;
        int return_code = ALARMMGR_RESULT_SUCCESS;
        int ret = __sub_init();
        if (ret < 0)
@@ -1163,91 +1212,106 @@ EXPORT_API int alarmmgr_remove_all(void)
                return ret;
        }
 
-       if(!com_samsung_alarm_manager_alarm_delete_all(alarm_context.proxy, alarm_context.pid, &return_code, &error))
-       {
-               ALARM_MGR_EXCEPTION_PRINT("com_samsung_alarm_manager_alarm_delete_all() is failed by dbus. "
-                       "return_code[%d], err message[%s]\n", return_code, error->message);
-               return ERR_ALARM_SYSTEM_FAIL;
-       }
-
-       if (return_code)
-       {
-               ALARM_MGR_EXCEPTION_PRINT("com_samsung_alarm_manager_alarm_delete_all() is failed. "
-                       "return_code[%d], err message[%s]\n", return_code, error->message);
-               return ERR_ALARM_SYSTEM_FAIL;
-       }
+       if (!_send_alarm_delete_all(alarm_context, &error_code))
+               return error_code;
 
        return return_code;
 }
 
 EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param)
 {
+       SECURE_LOGD("Enter");
        GError *error = NULL;
-       GArray *alarm_array = NULL;
+       GVariant *alarm_array = NULL;
        int return_code = 0;
-       int i = 0;
-       int maxnum_of_ids;
-       int num_of_ids;
-       int alarm_id = -1;
-       int ret;
+       int maxnum_of_ids = 0;
+       int num_of_ids = 0;
+       alarm_id_t alarm_id = -1;
+       int ret = 0;
+       char *e_cookie = NULL;
+       char cookie[256] = {0,};
+       int size = 0;
+       GVariantIter *iter = NULL;
 
-       if (fn == NULL)
+       if (fn == NULL) {
                return ERR_ALARM_INVALID_PARAM;
+       }
+
+       size = security_server_get_cookie_size();
+       ret = security_server_request_cookie(cookie, size);
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("security_server_request_cookie() is failed.");
+               return ERR_ALARM_SYSTEM_FAIL;
+       }
+
+       e_cookie = g_base64_encode((const guchar *)cookie, size);
+       if (e_cookie == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("g_base64_encode() is failed.");
+               return ERR_ALARM_SYSTEM_FAIL;
+       }
 
        ret = __sub_init();
-       if (ret < 0)
+       if (ret < 0) {
+               ALARM_MGR_EXCEPTION_PRINT("__sub_init() is failed.");
+               g_free(e_cookie);
                return ret;
+       }
 
-       if (!com_samsung_alarm_manager_alarm_get_number_of_ids(
-           alarm_context.proxy, alarm_context.pid, &maxnum_of_ids,
-              &return_code, &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(
-                   "com_samsung_alarm_manager_alarm_get_number_of_ids() "
-                   "failed. return_code[%d], err message[%s]\n",
-               return_code, error->message);
+                   "alarm_manager_call_alarm_get_number_of_ids_sync() is failed by dbus. return_code[%d], err message[%s]",
+                   return_code, error->message);
+               g_free(e_cookie);
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
-       if (return_code != 0) {
+       g_free(e_cookie);
+
+       if (return_code != ALARMMGR_RESULT_SUCCESS) {
+               ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_number_of_ids_sync() is failed. return_code[%d]", return_code);
                return return_code;
+       } else {
+               ALARM_MGR_LOG_PRINT("maxnum_of_ids[%d]", maxnum_of_ids);
        }
 
-       if (!com_samsung_alarm_manager_alarm_get_list_of_ids(
-                    alarm_context.proxy, alarm_context.pid, maxnum_of_ids,
-            &alarm_array, &num_of_ids, &return_code, &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 */
                ALARM_MGR_EXCEPTION_PRINT(
-                   "com_samsung_alarm_manager_alarm_get_list_of_ids() "
-                   "failed. alarm_id[%d], return_code[%d]\n",
-                    alarm_id, return_code);
+                   "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. num_of_ids[%d], return_code[%d].", num_of_ids, return_code);
                return ERR_ALARM_SYSTEM_FAIL;
        }
 
-       if (return_code != 0) {
+       if (return_code != ALARMMGR_RESULT_SUCCESS) {
                return return_code;
-       } else {
-               if (error != NULL) {
-                       ALARM_MGR_LOG_PRINT(
-                               "Alarm server not ready dbus error message %s\n", error->message);
-                       return ERR_ALARM_SYSTEM_FAIL;
-               }
-               if (NULL == alarm_array) {
-                       ALARM_MGR_LOG_PRINT(
-                               "alarm server not initilized\n");
-                       return ERR_ALARM_SYSTEM_FAIL;
-               }
-               for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
-                       alarm_id = g_array_index(alarm_array, alarm_id_t, i);
-                       (*fn) (alarm_id, user_param);
-                       ALARM_MGR_LOG_PRINT("alarm_id(%d)\n", alarm_id);
-               }
+       }
+
+       if (error != NULL) {
+               ALARM_MGR_LOG_PRINT("Alarm server is not ready dbus. error message %s.", error->message);
+               return ERR_ALARM_SYSTEM_FAIL;
+       }
 
-               g_array_free(alarm_array, true);
+       if (alarm_array == NULL) {
+               ALARM_MGR_LOG_PRINT("alarm server is not initilized.");
+               return ERR_ALARM_SYSTEM_FAIL;
        }
 
+       g_variant_get(alarm_array, "ai", &iter);
+       while (g_variant_iter_loop(iter, "i", &alarm_id))
+       {
+               (*fn) (alarm_id, user_param);
+               ALARM_MGR_LOG_PRINT("alarm_id (%d)", alarm_id);
+       }
+       g_variant_iter_free(iter);
+       g_variant_unref(alarm_array);
+
+       SECURE_LOGD("Leave");
        return ALARMMGR_RESULT_SUCCESS;
 }
 
@@ -1268,26 +1332,9 @@ EXPORT_API int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm)
                return ERR_ALARM_INVALID_PARAM;
        }
 
-       if (!_send_alarm_get_info(alarm_context, alarm_id, alarm_info,
-                                 &error_code))
-               return error_code;
-
-       return ALARMMGR_RESULT_SUCCESS;
-}
-
-EXPORT_API int alarmmgr_power_on(bool on_off)
-{
-       int error_code;
-       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_on() is called\n");
-
-#ifdef __ALARM_BOOT
-       if (!_send_alarm_power_on(alarm_context, on_off, &error_code))
+       if (!_send_alarm_get_info(alarm_context, alarm_id, alarm_info, &error_code)) {
                return error_code;
-#else
-       ALARM_MGR_LOG_PRINT("[alarm-lib]:ALARM_BOOT feature is not supported. "
-                           "so we return false.\n");
-       return ERR_ALARM_SYSTEM_FAIL;
-#endif
+       }
 
        return ALARMMGR_RESULT_SUCCESS;
 }
@@ -1354,16 +1401,15 @@ int alarmmgr_create(alarm_info_t *alarm_info, char *destination,
 int alarmmgr_get_number_of_ids(int *num_of_ids)
 {
        int error_code;
-       ALARM_MGR_LOG_PRINT("[alarm-lib]:"
-                           "alarm_get_number_of_ids() is called\n");
+       ALARM_MGR_LOG_PRINT("[alarm-lib]: alarm_get_number_of_ids() is called.");
 
        if (num_of_ids == NULL) {
                return ERR_ALARM_INVALID_PARAM;
        }
        ALARM_MGR_LOG_PRINT("call alarm_get_number_of_ids\n");
-       if (!_send_alarm_get_number_of_ids(alarm_context, num_of_ids,
-                                          &error_code))
+       if (!_send_alarm_get_number_of_ids(alarm_context, num_of_ids, &error_code)) {
                return error_code;
+       }
 
        return ALARMMGR_RESULT_SUCCESS;
 }
@@ -1372,7 +1418,7 @@ int alarmmgr_get_list_of_ids(int maxnum_of_ids, alarm_id_t *alarm_id,
                             int *num_of_ids)
 {
        int error_code;
-       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_list_of_ids() is called\n");
+       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_list_of_ids() is called.");
 
        if (maxnum_of_ids < 0 || alarm_id == NULL || num_of_ids == NULL) {
                return ERR_ALARM_INVALID_PARAM;
@@ -1384,8 +1430,9 @@ int alarmmgr_get_list_of_ids(int maxnum_of_ids, alarm_id_t *alarm_id,
        }
 
        if (!_send_alarm_get_list_of_ids
-           (alarm_context, maxnum_of_ids, alarm_id, num_of_ids, &error_code))
+           (alarm_context, maxnum_of_ids, alarm_id, num_of_ids, &error_code)) {
                return error_code;
+       }
 
        return ALARMMGR_RESULT_SUCCESS;
 }
@@ -1393,15 +1440,32 @@ int alarmmgr_get_list_of_ids(int maxnum_of_ids, alarm_id_t *alarm_id,
 EXPORT_API int alarmmgr_get_next_duetime(alarm_id_t alarm_id, time_t* duetime)
 {
        int error_code;
-       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_next_duetime() is called\n");
+       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_next_duetime() is called.");
 
        if (duetime == NULL) {
                return ERR_ALARM_INVALID_PARAM;
        }
 
-       if (!_send_alarm_get_next_duetime
-               (alarm_context, alarm_id, duetime, &error_code))
+       if (!_send_alarm_get_next_duetime(alarm_context, alarm_id, duetime, &error_code)) {
+               return error_code;
+       }
+
+       return ALARMMGR_RESULT_SUCCESS;
+}
+
+EXPORT_API int alarmmgr_get_all_info(char **db_path)
+{
+       int error_code;
+       ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_all_info() is called.");
+
+       if (db_path == NULL) {
+               return ERR_ALARM_INVALID_PARAM;
+       }
+
+       if (!_send_alarm_get_all_info(alarm_context, db_path, &error_code)) {
                return error_code;
+       }
 
+       ALARM_MGR_LOG_PRINT("[alarm-lib]: successfully save info in %s.", *db_path);
        return ALARMMGR_RESULT_SUCCESS;
 }
diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2d27737
--- /dev/null
@@ -0,0 +1,6 @@
+# Test executable
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_CFLAGS} -fpie")
+
+add_executable(alarmmgr_get_all_info alarmmgr_get_all_info.c)
+target_link_libraries(alarmmgr_get_all_info alarm ${pkgs_LDFLAGS} "-pie")
+INSTALL(TARGETS alarmmgr_get_all_info DESTINATION bin)
diff --git a/tool/alarmmgr_get_all_info.c b/tool/alarmmgr_get_all_info.c
new file mode 100644 (file)
index 0000000..fe9b438
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  alarm-manager
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include<dlog.h>
+#include<stdio.h>
+#include<stdlib.h>
+#include<glib.h>
+
+#include "alarm.h"
+
+extern int alarmmgr_get_all_info(char **db_path);
+
+int main()
+{
+       printf("=== Hi :) I will save info of all registered alarms in /tmp/alarmmgr_{datetime}.db\n");
+
+       int ret = alarmmgr_init("alarmmgr_tool");
+       if (ret != ALARMMGR_RESULT_SUCCESS)
+       {
+               LOGE("alarmmgr_init() is failed. ret = %d", ret);
+               printf("=== Failed to get all alarms's info :(\n");
+       }
+
+       char *db_path = NULL;
+       ret = alarmmgr_get_all_info(&db_path);
+       if (ret != ALARMMGR_RESULT_SUCCESS)
+       {
+               LOGE("alarmmgr_get_all_info() is failed. ret = %d", ret);
+               printf("=== Failed to get all alarms's info :(\n");
+       }
+       else
+       {
+               LOGE("Getting all alarm's info is done successfully.");
+               printf("=== Success :)\n    Please check %s\n", db_path);
+       }
+
+       if (db_path)
+       {
+               free(db_path);
+       }
+
+       return 0;
+}