Tidy source code up slightly 60/210360/7
authorInkyun Kil <inkyun.kil@samsung.com>
Thu, 18 Jul 2019 08:25:33 +0000 (17:25 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Thu, 25 Jul 2019 00:09:13 +0000 (09:09 +0900)
- Remove needless code
- Tidy a function up
- Remove codes related to pid
- Change value of max appid length

Change-Id: If73cf2ad02e79cb3932757c98744b55a8a5e65c3
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
include/alarm-internal.h
lib/alarm-lib.c
server/alarm-manager-db.c
server/alarm-manager-schedule.c
server/alarm-manager-util.c
server/alarm-manager.c

index 4ce712a..7b79486 100755 (executable)
@@ -34,12 +34,12 @@ extern "C" {
 #define LOG_TAG "ALARM_MANAGER"
 
 #define MAX_BUNDLE_NAME_LEN 2048
-#define MAX_SERVICE_NAME_LEN 256
+#define MAX_SERVICE_NAME_LEN 512
 #define MAX_PKG_NAME_LEN MAX_SERVICE_NAME_LEN-8
-#define MAX_PKG_ID_LEN 256
+#define MAX_PKG_ID_LEN 512
+#define MAX_APP_ID_LEN 512
 #define MIN_INEXACT_INTERVAL 600
 #define REGULAR_UID_MIN 5000
-#define MAX_APP_ID 256
 
 typedef struct {
        GDBusConnection *connection;
@@ -108,7 +108,6 @@ typedef struct {
 
        alarm_id_t alarm_id;
        uid_t uid;
-       int pid;
        char *caller_pkgid;
        char *callee_pkgid;
        char *app_unique_name;
@@ -147,7 +146,6 @@ typedef struct {
        bool used;
        alarm_id_t alarm_id;
        uid_t uid;
-       int pid;
        __alarm_info_t *__alarm_info;
 } __scheduled_alarm_t;
 
index f708591..95a15a8 100755 (executable)
@@ -39,7 +39,7 @@
 #define EXPORT_API __attribute__ ((visibility("default")))
 #endif
 
-static char g_appid[MAX_APP_ID];
+static char g_appid[MAX_APP_ID_LEN];
 static int flag_appid_checked;
 
 static alarm_context_t alarm_context;
@@ -445,7 +445,7 @@ static int __compare_api_version(int *result, uid_t uid)
 {
        int ret = 0;
        pkgmgrinfo_pkginfo_h pkginfo = NULL;
-       char pkgid[512] = {0, };
+       char pkgid[MAX_PKG_ID_LEN] = {0, };
        char *pkg_version;
 
        if (aul_app_get_pkgid_bypid_for_uid(getpid(), pkgid, sizeof(pkgid), uid) != AUL_R_OK) {
index 5999469..52ee224 100644 (file)
 
 #include "alarm-manager-db.h"
 
-#define MAX_GCONF_PATH_LEN 256
-
 #define ALARMMGR_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".alarmmgr.db")
 #define QUERY_CREATE_TABLE_ALARMMGR "create table if not exists alarmmgr \
                                (alarm_id integer primary key,\
                                                start integer,\
                                                end integer,\
                                                uid integer,\
-                                               pid integer,\
                                                global integer,\
                                                is_disabled integer,\
                                                caller_pkgid text,\
@@ -94,17 +91,16 @@ 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, uid, pid, global, is_disabled, caller_pkgid, callee_pkgid, app_unique_name,\
+                       end, uid, global, is_disabled, caller_pkgid, callee_pkgid, app_unique_name,\
                        app_service_name, app_service_name_mod, bundle, noti_len, noti, year,\
                        month, day, hour, min, sec, msec, day_of_week, repeat,\
                        alarm_type, reserved_info, dst_service_name, dst_service_name_mod)\
-                       values (%d,%d,%d,%d,%d,%d,0,%Q,%Q,%Q,%Q,%Q,%Q,%d,%Q,%d,%d,%d,%d,%d,%d,%d,%d,%d,\
+                       values (%d,%d,%d,%d,%d,0,%Q,%Q,%Q,%Q,%Q,%Q,%d,%Q,%d,%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->uid,
-                       __alarm_info->pid,
                        __alarm_info->global,
                        CHECK_NULL_STRING(__alarm_info->caller_pkgid),
                        CHECK_NULL_STRING(__alarm_info->callee_pkgid),
@@ -148,7 +144,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,\
-                       uid=%d, pid=%d, global=%d, is_disabled=0, caller_pkgid=%Q, callee_pkgid=%Q, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\
+                       uid=%d, global=%d, is_disabled=0, caller_pkgid=%Q, callee_pkgid=%Q, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\
                        bundle=%Q, noti_len=%d, noti=%Q, year=%d, month=%d, day=%d, hour=%d, min=%d, sec=%d, msec=%d,\
                        day_of_week=%d, repeat=%d, alarm_type=%d,\
                        reserved_info=%d, dst_service_name=%Q, dst_service_name_mod=%Q\
@@ -156,7 +152,6 @@ bool _update_alarms(__alarm_info_t *__alarm_info)
                        (int)__alarm_info->start,
                        (int)__alarm_info->end,
                        __alarm_info->uid,
-                       __alarm_info->pid,
                        __alarm_info->global,
                        CHECK_NULL_STRING(__alarm_info->caller_pkgid),
                        CHECK_NULL_STRING(__alarm_info->callee_pkgid),
@@ -223,7 +218,7 @@ void _load_alarms_from_db()
        int is_disabled;
        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_unique_name[MAX_APP_ID_LEN] = {0,};
        char app_service_name[MAX_SERVICE_NAME_LEN] = {0,};
        char app_service_name_mod[MAX_SERVICE_NAME_LEN] = {0,};
        char dst_service_name[MAX_SERVICE_NAME_LEN] = {0,};
@@ -253,7 +248,6 @@ void _load_alarms_from_db()
                __alarm_info->start = sqlite3_column_int(stmt, col_idx++);
                __alarm_info->end = sqlite3_column_int(stmt, col_idx++);
                __alarm_info->uid = sqlite3_column_int(stmt, col_idx++);
-               __alarm_info->pid = sqlite3_column_int(stmt, col_idx++);
                __alarm_info->global = sqlite3_column_int(stmt, col_idx++);
                is_disabled = sqlite3_column_int(stmt, col_idx++);
 
@@ -262,7 +256,7 @@ void _load_alarms_from_db()
                strncpy(callee_pkgid, (const char *)sqlite3_column_text(stmt, col_idx++),
                        MAX_PKG_ID_LEN - 1);
                strncpy(app_unique_name, (const char *)sqlite3_column_text(stmt, col_idx++),
-                       MAX_SERVICE_NAME_LEN - 1);
+                       MAX_APP_ID_LEN - 1);
                strncpy(app_service_name, (const char *)sqlite3_column_text(stmt, col_idx++),
                        MAX_SERVICE_NAME_LEN - 1);
                strncpy(app_service_name_mod, (const char *)sqlite3_column_text(stmt, col_idx++),
@@ -330,7 +324,6 @@ int _get_db_path_for_all_info(uid_t uid, char** db_path)
                                                        duetime text,\
                                                        start_epoch integer,\
                                                        end_epoch integer,\
-                                                       pid integer,\
                                                        global integer,\
                                                        caller_pkgid text,\
                                                        callee_pkgid text,\
@@ -398,14 +391,13 @@ int _get_db_path_for_all_info(uid_t uid, char** db_path)
                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, global, 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,%d,%Q,%Q,%Q,%Q,%Q,%d,%d,%d)",
+                               end_epoch, global, 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,
                                (bool)entry->global,
                                CHECK_NULL_STRING(entry->caller_pkgid),
                                CHECK_NULL_STRING(entry->callee_pkgid),
index b1fb77d..8f20515 100644 (file)
@@ -65,12 +65,10 @@ bool _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info)
        alarm->used = true;
        alarm->alarm_id = __alarm_info->alarm_id;
        alarm->uid = __alarm_info->uid;
-       alarm->pid = __alarm_info->pid;
        alarm->__alarm_info = __alarm_info;
 
-       SECURE_LOGD("%s :alarm->uid =%d, alarm->pid =%d, app_service_name=%s\n",
-                       __FUNCTION__, alarm->uid, alarm->pid,
-                       alarm->__alarm_info->app_service_name);
+       SECURE_LOGD("%s :alarm->uid =%d, app_service_name=%s\n",
+                       __FUNCTION__, alarm->uid, alarm->__alarm_info->app_service_name);
 
        g_scheduled_alarm_list = g_slist_append(g_scheduled_alarm_list, alarm);
 
@@ -480,8 +478,8 @@ static bool __find_next_alarm_to_be_scheduled(time_t *min_due_time)
 
                double interval = 0;
 
-               SECURE_LOGD("alarm[%d] with duetime(%ld) at current(%ld) pid: (%d)\n",
-                               entry->alarm_id, due_time, current_time, entry->pid);
+               SECURE_LOGD("alarm[%d] with duetime(%ld) at current(%ld)\n",
+                               entry->alarm_id, due_time, current_time);
                if (due_time == 0)      /*0 means this alarm has been disabled*/ {
                        continue;
                }
index 08da094..ea0c43f 100755 (executable)
@@ -251,7 +251,7 @@ int _compare_api_version(int *result, int pid, uid_t uid)
 {
        int ret = 0;
        pkgmgrinfo_pkginfo_h pkginfo = NULL;
-       char pkgid[512] = {0, };
+       char pkgid[MAX_PKG_ID_LEN] = {0, };
        char *pkg_version;
 
        if (aul_app_get_pkgid_bypid_for_uid(pid, pkgid, sizeof(pkgid), uid) != AUL_R_OK) {
index 20be386..3d41f07 100755 (executable)
@@ -85,10 +85,22 @@ bool g_dummy_timer_is_set = FALSE;
 GSList *g_scheduled_alarm_list;
 GSList *g_expired_alarm_list;
 GSList *g_disabled_alarm_list;
+GHashTable *caller_appid_cache_table;
 
 bool is_time_changed = false; /* for calculating next duetime */
 static time_t periodic_alarm_standard_time = 0;
 
+struct running_info_t {
+       char *appid;
+       bool is_running;
+};
+
+typedef struct {
+       int pid;
+       bool is_app;
+       char *unique_name;
+} appid_cache_t;
+
 static long __get_proper_interval(long interval, int alarm_type);
 static void __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);
@@ -108,7 +120,7 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
                           long requested_interval, uid_t uid, int pid, char *bundle_data, int *error_code);
 
 static bool __alarm_delete(uid_t uid, alarm_id_t alarm_id, int *error_code);
-static bool __alarm_update(uid_t uid, int pid, alarm_id_t alarm_id,
+static bool __alarm_update(uid_t uid, alarm_id_t alarm_id,
                           alarm_info_t *alarm_info, int update_flag, int *error_code);
 static void __alarm_expired();
 static gboolean __alarm_handler_idle(gpointer user_data);
@@ -119,7 +131,6 @@ static void __initialize_scheduled_alarm_list();
 static bool __initialize_noti();
 
 void _release_alarm_info_t(__alarm_info_t *entry);
-bool __get_caller_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid);
 static notification_h __get_notification(guchar *data, int datalen);
 
 #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
@@ -129,44 +140,58 @@ static bool __save_module_log(const char *tag, const char *messgae);
 
 int __set_time(time_t _time);
 
-struct running_info_t {
-       int pid;
-       char *appid;
-       bool is_running;
-};
+static bool __get_caller_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid)
+{
+       char caller_appid[MAX_APP_ID_LEN] = {0,};
 
-struct filtered_alarm_app_s {
-       int is_ui_app;
-       uid_t uid;
-};
+       if (unique_name == NULL) {
+               ALARM_MGR_EXCEPTION_PRINT("unique_name should not be NULL.");
+               return false;
+       }
 
-GHashTable *appid_cache_table;
+       if (aul_app_get_appid_bypid_for_uid(pid, caller_appid,
+                               sizeof(caller_appid), uid) == AUL_R_OK) {
+               /* When a caller is an application, the unique name is appID. */
+               if (is_app)
+                       *is_app = true;
+               strncpy(unique_name, caller_appid, size - 1);
+       } else {
+               /* Otherwise, the unique name is /proc/pid/cmdline. */
+               char proc_file[MAX_APP_ID_LEN] = {0,};
+               char process_name[MAX_APP_ID_LEN] = {0,};
+               int fd = 0;
+               int i = 0;
 
-typedef struct {
-       int pid;
-       bool is_app;
-       char *unique_name;
-} appid_cache_t;
+               if (is_app)
+                       *is_app = false;
 
-struct alarm_manager_dbus_map {
-       const char *signal_name;
-       GCallback func;
-};
+               snprintf(proc_file, MAX_APP_ID_LEN, "/proc/%d/cmdline", pid);
 
-static bool __get_cached_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid)
-{
-       appid_cache_t *data = NULL;
-       data = (appid_cache_t *)g_hash_table_lookup(appid_cache_table, &pid);
-       if (data) {
-               snprintf(unique_name, MAX_APP_ID, "%s", data->unique_name);
-               if (is_app)
-                       *is_app = data->is_app;
-               ALARM_MGR_LOG_PRINT("Get cached unique_name: %s, pid:%d", unique_name, pid);
-               return true;
+               fd = open(proc_file, O_RDONLY);
+               if (fd < 0) {
+                       SECURE_LOGE("Caution!! pid(%d) seems to be killed.",
+                                       pid);
+                       return false;
+               } else {
+                       if (read(fd, process_name, sizeof(process_name) - 1) <= 0) {
+                               ALARM_MGR_EXCEPTION_PRINT("Unable to get the process name.");
+                               close(fd);
+                               return false;
+                       }
+                       close(fd);
+
+                       while (process_name[i] != '\0') {
+                               if (process_name[i] == ' ') {
+                                       process_name[i] = '\0';
+                                       break;
+                               }
+                               ++i;
+                       }
+                       strncpy(unique_name, process_name, size - 1);
+               }
        }
 
-       ALARM_MGR_LOG_PRINT("There is no cached unique_name for pid(%d)", pid);
-       return __get_caller_unique_name(pid, unique_name, size, is_app, uid);
+       return true;
 }
 
 gboolean __hash_table_remove_cb(gpointer key, gpointer value, gpointer user_data)
@@ -181,6 +206,43 @@ gboolean __hash_table_remove_cb(gpointer key, gpointer value, gpointer user_data
        return false;
 }
 
+static bool __get_cached_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid)
+{
+       appid_cache_t *data;
+       bool ret;
+       bool _is_app;
+
+       data = (appid_cache_t *)g_hash_table_lookup(caller_appid_cache_table, GINT_TO_POINTER(pid));
+       if (data) {
+               snprintf(unique_name, MAX_APP_ID_LEN, "%s", data->unique_name);
+               if (is_app)
+                       *is_app = data->is_app;
+               ALARM_MGR_LOG_PRINT("Get cached unique_name: %s, pid:%d", unique_name, pid);
+               return true;
+       }
+
+       ALARM_MGR_LOG_PRINT("There is no cached unique_name for pid(%d)", pid);
+
+       ret = __get_caller_unique_name(pid, unique_name, size, &_is_app, uid);
+       if (ret) {
+               g_hash_table_foreach_remove(caller_appid_cache_table, __hash_table_remove_cb, (gpointer)unique_name);
+               data = (appid_cache_t *)calloc(1, sizeof(appid_cache_t));
+               if (data) {
+                       data->unique_name = strdup(unique_name);
+                       data->is_app = _is_app;
+                       data->pid = pid;
+                       g_hash_table_insert(caller_appid_cache_table, GINT_TO_POINTER(data->pid), (gpointer)data);
+               }
+
+               if (is_app)
+                       *is_app = _is_app;
+
+               SECURE_LOGD("unique_name= %s", unique_name);
+       }
+
+       return ret;
+}
+
 void __hashtable_foreach_cb(gpointer key, gpointer value, gpointer user_data)
 {
        appid_cache_t *data = (appid_cache_t *)value;
@@ -699,7 +761,7 @@ static bool __alarm_update_due_time_of_all_items_in_list(double diff_time)
        return true;
 }
 
-static void __set_caller_info(bundle *b, int pid, uid_t uid,
+static void __set_caller_info(bundle *b, uid_t uid,
                const char *appid, const char *pkgid)
 {
        char buf[12];
@@ -724,7 +786,7 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
        time_t due_time;
        struct tm ts_ret;
        char due_time_r[100] = { 0 };
-       char app_name[512] = { 0 };
+       char app_name[MAX_APP_ID_LEN] = { 0 };
        bundle *b;
        const char *callee_appid = NULL;
        bundle_raw *b_data = NULL;
@@ -741,7 +803,6 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
        }
 
        __alarm_info->uid = uid;
-       __alarm_info->pid = pid;
        __alarm_info->alarm_id = -1;
        __alarm_info->requested_interval = requested_interval;
        __alarm_info->global = false;
@@ -763,8 +824,7 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
        __alarm_info->callee_pkgid = _get_pkgid_by_appid(callee_appid, uid);
 
        if (b && caller_is_app) {
-               __set_caller_info(b, pid, uid, app_name,
-                               __alarm_info->caller_pkgid);
+               __set_caller_info(b, uid, app_name, __alarm_info->caller_pkgid);
                bundle_del(b, AUL_K_REQUEST_TYPE);
                bundle_add(b, AUL_K_REQUEST_TYPE, "indirect-request");
        }
@@ -840,7 +900,7 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t
 {
        time_t current_time;
        time_t due_time;
-       char unique_name[MAX_APP_ID] = { 0 };
+       char unique_name[MAX_APP_ID_LEN] = { 0 };
        bool caller_is_app = false;
 
        __alarm_info_t *__alarm_info = NULL;
@@ -853,7 +913,6 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t
                return false;
        }
        __alarm_info->uid = uid;
-       __alarm_info->pid = pid;
        __alarm_info->alarm_id = -1;
        __alarm_info->method = method;
        __alarm_info->requested_interval = requested_interval;
@@ -992,7 +1051,7 @@ static bool __alarm_create_noti(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
        time_t due_time;
        struct tm ts_ret;
        char due_time_r[100] = { 0 };
-       char app_name[512] = { 0 };
+       char app_name[MAX_APP_ID_LEN] = { 0 };
        bool caller_is_app = false;
        char *new_noti_data = NULL;
 
@@ -1006,7 +1065,6 @@ static bool __alarm_create_noti(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
                return false;
        }
        __alarm_info->uid = uid;
-       __alarm_info->pid = pid;
        __alarm_info->alarm_id = -1;
        __alarm_info->requested_interval = requested_interval;
        __alarm_info->global = false;
@@ -1091,7 +1149,7 @@ static bool __alarm_create_noti(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
        return true;
 }
 
-static bool __alarm_update(uid_t uid, int pid, alarm_id_t alarm_id,
+static bool __alarm_update(uid_t uid, alarm_id_t alarm_id,
                           alarm_info_t *alarm_info, int update_flag, int *error_code)
 {
        time_t current_time;
@@ -1346,8 +1404,7 @@ static int __app_info_iter(const aul_app_info *info, void *data)
 {
        struct running_info_t *app_info = (struct running_info_t *)data;
 
-       if (app_info->pid == info->pid &&
-                       strcmp(app_info->appid, info->appid) == 0)
+       if (strcmp(app_info->appid, info->appid) == 0)
                app_info->is_running = true;
 
        return 0;
@@ -1502,7 +1559,6 @@ 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", destination_app_service_name, app_pid);
 
                        if (__alarm_info->dst_service_name == NULL) {
                                if (__alarm_info->app_service_name != NULL && strlen(__alarm_info->app_service_name) > 6)
@@ -1521,10 +1577,11 @@ static void __alarm_expired()
                         * This app is launched and owner of DBus connection is changed. and then, expiration noti is sent by DBus. */
                        app_info.is_running = false;
                        if (is_app) {
-                               app_info.pid = __alarm_info->pid;
                                app_info.appid = appid;
                                aul_app_get_all_running_app_info_for_uid(__app_info_iter,
                                                &app_info, __alarm_info->uid);
+
+                               SECURE_LOGD("[alarm-server]: destination_app_id :%s", appid);
                        }
 
                        if (is_app && !app_info.is_running) {
@@ -1568,9 +1625,7 @@ static void __alarm_expired()
                                /* Case #3. The process is alive or was killed && non-app type(daemon)
                                 * Expiration noti is sent by DBus. it makes the process alive. (dbus auto activation) */
                                ALARM_MGR_LOG_PRINT("before alarm_send_noti_to_application");
-                               ALARM_MGR_LOG_PRINT("WAKEUP pid: %d", __alarm_info->pid);
 
-                               aul_update_freezer_status(__alarm_info->pid, "wakeup");
                                _alarm_send_noti_to_application_by_dbus(destination_app_service_name,
                                                alarm_id, __alarm_info->alarm_info.msec, __alarm_info->uid); /* dbus auto activation */
                                ALARM_MGR_LOG_PRINT("after _alarm_send_noti_to_application_by_dbus");
@@ -1580,7 +1635,7 @@ static void __alarm_expired()
                ALARM_MGR_LOG_PRINT("alarm_id[%d] is expired.", alarm_id);
 
 #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
-               snprintf(log_message, sizeof(log_message), "alarmID: %d, pid: %d, duetime: %ld", alarm_id, app_pid, __alarm_info->due_time);
+               snprintf(log_message, sizeof(log_message), "alarmID: %d, duetime: %ld", alarm_id, __alarm_info->due_time);
                __save_module_log("EXPIRED", log_message);
 #endif
 
@@ -1789,6 +1844,7 @@ static int __on_app_uninstalled(uid_t target_uid, int req_id, const char *pkg_ty
 
                        const char *caller_pkgid = entry->caller_pkgid;
                        const char *callee_pkgid = entry->callee_pkgid;
+                       int pid = _get_pid_from_appid(entry->app_unique_name, entry->uid);
 
                        gs_iter = g_slist_next(gs_iter);
                        if ((caller_pkgid && strncmp(pkgid, caller_pkgid, strlen(pkgid)) == 0) ||
@@ -1802,8 +1858,8 @@ static int __on_app_uninstalled(uid_t target_uid, int req_id, const char *pkg_ty
                                                SECURE_LOGE("_delete_alarms() is failed. pkgid[%s], alarm_id[%d]", pkgid, entry->alarm_id);
                                }
 
-                               if (g_hash_table_remove(appid_cache_table, &entry->pid) == true)
-                                       ALARM_MGR_LOG_PRINT("Remove cachd data of pid[%d]", entry->pid);
+                               if (g_hash_table_remove(caller_appid_cache_table, GINT_TO_POINTER(pid)) == true)
+                                       ALARM_MGR_LOG_PRINT("Remove cachd data of pid[%d]", pid);
 
                                SECURE_LOGD("Remove pkgid[%s], alarm_id[%d]", pkgid, entry->alarm_id);
                                alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry);
@@ -1822,70 +1878,6 @@ static int __on_app_uninstalled(uid_t target_uid, int req_id, const char *pkg_ty
        return ALARMMGR_RESULT_SUCCESS;
 }
 
-bool __get_caller_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid)
-{
-       char caller_appid[256] = {0,};
-       appid_cache_t *entry;
-
-       if (unique_name == NULL) {
-               ALARM_MGR_EXCEPTION_PRINT("unique_name should not be NULL.");
-               return false;
-       }
-
-       if (aul_app_get_appid_bypid_for_uid(pid, caller_appid,
-                               sizeof(caller_appid), uid) == AUL_R_OK) {
-               /* When a caller is an application, the unique name is appID. */
-               if (is_app)
-                       *is_app = true;
-               strncpy(unique_name, caller_appid, size - 1);
-       } else {
-               /* Otherwise, the unique name is /proc/pid/cmdline. */
-               char proc_file[512] = {0,};
-               char process_name[512] = {0,};
-               int fd = 0;
-               int i = 0;
-
-               if (is_app)
-                       *is_app = false;
-
-               snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
-
-               fd = open(proc_file, O_RDONLY);
-               if (fd < 0) {
-                       SECURE_LOGE("Caution!! pid(%d) seems to be killed.",
-                                       pid);
-                       return false;
-               } else {
-                       if (read(fd, process_name, sizeof(process_name) - 1) <= 0) {
-                               ALARM_MGR_EXCEPTION_PRINT("Unable to get the process name.");
-                               close(fd);
-                               return false;
-                       }
-                       close(fd);
-
-                       while (process_name[i] != '\0') {
-                               if (process_name[i] == ' ') {
-                                       process_name[i] = '\0';
-                                       break;
-                               }
-                               ++i;
-                       }
-                       strncpy(unique_name, process_name, size - 1);
-               }
-       }
-
-       g_hash_table_foreach_remove(appid_cache_table, __hash_table_remove_cb, (gpointer)unique_name);
-       entry = (appid_cache_t *)calloc(1, sizeof(appid_cache_t));
-       if (entry) {
-               entry->unique_name = strdup(unique_name);
-               entry->is_app = is_app ? *is_app : false;
-               entry->pid = pid;
-               g_hash_table_insert(appid_cache_table, &entry->pid, (gpointer)entry);
-       }
-
-       SECURE_LOGD("unique_name= %s", unique_name);
-       return true;
-}
 
 #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
 static void __initialize_module_log(void)
@@ -2030,7 +2022,7 @@ void __reschedule_alarms_with_newtime(int cur_time, int new_time, double diff_ti
 static int __check_modifiable(uid_t uid, pid_t pid, int alarm_id)
 {
        bool caller_is_app = false;
-       char app_name[MAX_APP_ID] = { 0 };
+       char app_name[MAX_APP_ID_LEN] = { 0 };
        GSList *gs_iter = NULL;
        __alarm_info_t *entry = NULL;
        char *caller_pkgid = NULL;
@@ -2701,7 +2693,7 @@ int alarm_manager_alarm_delete(GVariant *parameters, uid_t uid, pid_t pid)
 int alarm_manager_alarm_delete_all(GVariant *parameters, uid_t uid, pid_t pid)
 {
        GSList *gs_iter = NULL;
-       char app_name[512] = { 0 };
+       char app_name[MAX_APP_ID_LEN] = { 0 };
        alarm_info_t *alarm_info = NULL;
        __alarm_info_t *entry = NULL;
        bool is_deleted = false;
@@ -2806,7 +2798,7 @@ int alarm_manager_alarm_update(GVariant *parameters, uid_t uid, pid_t pid)
        alarm_info.alarm_type = alarm_type;
        alarm_info.reserved_info = reserved_info;
 
-       if (!__alarm_update(uid, pid, alarm_id, &alarm_info,
+       if (!__alarm_update(uid, alarm_id, &alarm_info,
                                update_flag, &return_code)) {
                ALARM_MGR_EXCEPTION_PRINT("Unable to update the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code);
 #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
@@ -2830,7 +2822,7 @@ int alarm_manager_alarm_update(GVariant *parameters, uid_t uid, pid_t pid)
 int alarm_manager_alarm_get_number_of_ids(uid_t uid, pid_t pid, int *num_of_ids)
 {
        GSList *gs_iter = NULL;
-       char app_name[256] = { 0 };
+       char app_name[MAX_APP_ID_LEN] = { 0 };
        __alarm_info_t *entry = NULL;
        int _num_of_ids = 0;
 
@@ -2862,7 +2854,7 @@ int alarm_manager_alarm_get_list_of_ids(GVariant *parameters, uid_t uid,
                pid_t pid, GVariant **alarm_array, int *num_of_alarm)
 {
        GSList *gs_iter = NULL;
-       char app_name[512] = { 0 };
+       char app_name[MAX_APP_ID_LEN] = { 0 };
        __alarm_info_t *entry = NULL;
        int index = 0;
        int max_number_of_ids;
@@ -3304,8 +3296,8 @@ void _alarm_initialize()
        __initialize_alarm_list();
        __initialize_noti();
 
-       if (!appid_cache_table) {
-               appid_cache_table = g_hash_table_new_full(g_int_hash, g_int_equal,
+       if (!caller_appid_cache_table) {
+               caller_appid_cache_table = g_hash_table_new_full(g_int_hash, g_int_equal,
                                NULL, __free_cached_value);
        }
 }