Change the processing slot for cleardata/clearcache
[platform/core/appfw/pkgmgr-server.git] / src / request.c
index 9acbed0..ee0bfae 100644 (file)
@@ -4,11 +4,15 @@
 
 #include <glib.h>
 #include <gio/gio.h>
+#include <gum/gum-user.h>
+#include <gum/common/gum-user-types.h>
 
-#include "pm-queue.h"
+#include "queue.h"
 #include "pkgmgr-server.h"
 #include "package-manager.h"
 
+#define RETRY_MAX 5
+#define RETRY_WAIT_USEC (1000000 / 2) /* 0.5 sec */
 #define PKGMGR_DBUS_SERVICE "org.tizen.pkgmgr"
 #define PKGMGR_DBUS_OBJECT_PATH "/org/tizen/pkgmgr"
 
@@ -25,36 +29,42 @@ static const char instropection_xml[] =
        "    </method>"
        "    <method name='reinstall'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
-       "    <method name='uninstall'>"
+       "    <method name='mount_install'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='pkgtype' direction='in'/>"
+       "      <arg type='s' name='pkgpath' direction='in'/>"
+       "      <arg type='as' name='args' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='s' name='reqkey' direction='out'/>"
+       "    </method>"
+       "    <method name='uninstall'>"
+       "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
        "    <method name='move'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='movetype' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
-       "    <method name='enable_pkg'>"
+       "    <method name='enable_pkgs'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
-       "      <arg type='s' name='pkgid' direction='in'/>"
+       "      <arg type='as' name='pkgids' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
-       "    <method name='disable_pkg'>"
+       "    <method name='disable_pkgs'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
-       "      <arg type='s' name='pkgid' direction='in'/>"
+       "      <arg type='as' name='pkgids' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
        "    <method name='enable_app'>"
        "      <arg type='u' name='uid' direction='in'/>"
@@ -68,6 +78,18 @@ static const char instropection_xml[] =
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
+       "    <method name='enable_apps'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='as' name='appids' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='s' name='reqkey' direction='out'/>"
+       "    </method>"
+       "    <method name='disable_apps'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='as' name='appids' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='s' name='reqkey' direction='out'/>"
+       "    </method>"
        "    <method name='enable_global_app_for_uid'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='appid' direction='in'/>"
@@ -87,9 +109,15 @@ static const char instropection_xml[] =
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
+       "    <method name='getsize_sync'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='pkgid' direction='in'/>"
+       "      <arg type='i' name='get_type' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='x' name='size_info' direction='out'/>"
+       "    </method>"
        "    <method name='cleardata'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
@@ -102,11 +130,13 @@ static const char instropection_xml[] =
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='i' name='pid' direction='out'/>"
        "    </method>"
        "    <method name='check'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
+       "      <arg type='i' name='pid' direction='out'/>"
        "    </method>"
        "    <method name='generate_license_request'>"
        "      <arg type='s' name='resp_data' direction='in'/>"
@@ -123,30 +153,43 @@ static const char instropection_xml[] =
        "      <arg type='s' name='decrypted_file_path' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
-       "    <method name='add_blacklist'>"
+       "    <method name='enable_app_splash_screen'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='appid' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "    </method>"
+       "    <method name='disable_app_splash_screen'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='appid' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "    </method>"
+       "    <method name='set_restriction_mode'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
+       "      <arg type='i' name='mode' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
-       "    <method name='remove_blacklist'>"
+       "    <method name='unset_restriction_mode'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
+       "      <arg type='i' name='mode' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
-       "    <method name='check_blacklist'>"
+       "    <method name='get_restriction_mode'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='result' direction='out'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
-       "    <method name='enable_app_splash_screen'>"
+       "    <method name='set_app_label'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='appid' direction='in'/>"
+       "      <arg type='s' name='label' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
-       "    <method name='disable_app_splash_screen'>"
+       "    <method name='migrate_external_image'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='appid' direction='in'/>"
+       "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
        "  </interface>"
@@ -171,7 +214,7 @@ static char *__generate_reqkey(const char *pkgid)
        size = strlen(pkgid) + strlen(timestr) + 2;
        str_req_key = (char *)calloc(size, sizeof(char));
        if (str_req_key == NULL) {
-               DBG("calloc failed");
+               ERR("calloc failed");
                return NULL;
        }
        snprintf(str_req_key, size, "%s_%s", pkgid, timestr);
@@ -179,12 +222,90 @@ static char *__generate_reqkey(const char *pkgid)
        return str_req_key;
 }
 
-static int __handle_request_install(uid_t uid,
+static int __is_admin_user(uid_t uid)
+{
+       GumUser *guser;
+       GumUserType ut = GUM_USERTYPE_NONE;
+       int retry_cnt = 0;
+
+       do {
+               guser = gum_user_get_sync(uid, FALSE);
+               if (guser == NULL) {
+                       ERR("cannot get user information from gumd, retry");
+                       retry_cnt++;
+                       usleep(RETRY_WAIT_USEC);
+                       continue;
+               }
+               break;
+       } while (retry_cnt <= RETRY_MAX);
+
+       if (guser == NULL) {
+               ERR("cannot get user information from gumd, failed");
+               return -1;
+       }
+
+       g_object_get(G_OBJECT(guser), "usertype", &ut, NULL);
+       if (ut == GUM_USERTYPE_NONE) {
+               ERR("cannot get user type");
+               g_object_unref(guser);
+               return -1;
+       } else if (ut != GUM_USERTYPE_ADMIN) {
+               g_object_unref(guser);
+               return 0;
+       }
+
+       g_object_unref(guser);
+
+       return 1;
+}
+
+static int __check_caller_permission(uid_t uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       GVariant *v;
+       uid_t target_uid;
+       int is_admin;
+
+       if (uid < REGULAR_USER)
+               return 0;
+
+       v = g_variant_get_child_value(parameters, 0);
+       if (v == NULL) {
+               g_dbus_method_invocation_return_error_literal(invocation,
+                               G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+                               "Internal error.");
+               return -1;
+       }
+
+       target_uid = g_variant_get_uint32(v);
+       g_variant_unref(v);
+       if (uid == target_uid)
+               return 0;
+
+       is_admin = __is_admin_user(uid);
+       if (is_admin == -1) {
+               g_dbus_method_invocation_return_error_literal(invocation,
+                               G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
+                               "Internal error.");
+               return -1;
+       } else if (is_admin == 0) {
+               g_dbus_method_invocation_return_error_literal(invocation,
+                               G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED,
+                               "Non-admin user cannot request operation to "
+                               "other users.");
+               return -1;
+       }
+
+       return 0;
+}
+
+static int __handle_request_install(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype = NULL;
-       char *pkgpath = NULL;
+       char *arg_pkgtype = NULL;
+       const char *pkgtype;
+       const char *pkgpath = NULL;
        char *args = NULL;
        char *reqkey = NULL;
        gchar **tmp_args = NULL;
@@ -193,8 +314,10 @@ static int __handle_request_install(uid_t uid,
        GVariant *value;
        int i = 0;
        int len = 0;
+       size_t s = 0;
 
-       g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath, &value);
+       g_variant_get(parameters, "(u&s&s@as)", &target_uid, &arg_pkgtype,
+                       &pkgpath, &value);
        tmp_args = (gchar **)g_variant_get_strv(value, &args_count);
 
        for (i = 0; i < args_count; i++)
@@ -203,24 +326,33 @@ static int __handle_request_install(uid_t uid,
        args = (char *)calloc(len, sizeof(char));
        if (args == NULL) {
                ERR("calloc failed");
-               ret =  -1;
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               ret = -1;
                goto catch;
        }
 
        for (i = 0; i < args_count; i++) {
-               strncat(args, tmp_args[i], strlen(tmp_args[i]));
-               if (i != args_count - 1)
-                       strncat(args, " ", strlen(" "));
+               strncat(args, tmp_args[i], len - s - 1);
+               s += strlen(tmp_args[i]);
+               if (i != args_count - 1) {
+                       strncat(args, " ", len - s - 1);
+                       s += strlen(" ");
+               }
        }
 
-       if (target_uid == (uid_t)-1 || pkgtype == NULL) {
+       if (target_uid == (uid_t)-1 || pkgpath == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                ret = -1;
                goto catch;
        }
 
-       if (pkgpath == NULL) {
+       pkgpath = _get_adjusted_pkgpath(pkgpath, caller_uid);
+       pkgtype = _get_pkgtype_from_file(pkgpath);
+       if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype))
+               pkgtype = (const char *)arg_pkgtype;
+       if (pkgtype == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                ret = -1;
@@ -229,12 +361,14 @@ static int __handle_request_install(uid_t uid,
 
        reqkey = __generate_reqkey(pkgpath);
        if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                ret = -1;
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_INSTALL, pkgtype,
-                               pkgpath, args)) {
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_INSTALL,
+                               pkgtype, pkgpath, args)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -253,167 +387,438 @@ catch:
        if (args)
                free(args);
 
+       if (tmp_args)
+               g_free(tmp_args);
+
+       return ret;
+}
+
+static int __handle_request_mount_install(uid_t caller_uid,
+       GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *arg_pkgtype = NULL;
+       const char *pkgtype;
+       const char *pkgpath = NULL;
+       char *args = NULL;
+       char *reqkey = NULL;
+       gchar **tmp_args = NULL;
+       gsize args_count;
+       int ret = -1;
+       GVariant *value;
+       int i = 0;
+       int len = 0;
+       size_t s = 0;
+
+       g_variant_get(parameters, "(u&s&s@as)", &target_uid, &arg_pkgtype,
+                       &pkgpath, &value);
+       tmp_args = (gchar **)g_variant_get_strv(value, &args_count);
+
+       for (i = 0; i < args_count; i++)
+               len = len + strlen(tmp_args[i]) + 1;
+
+       args = (char *)calloc(len, sizeof(char));
+       if (args == NULL) {
+               ERR("calloc failed");
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               ret = -1;
+               goto catch;
+       }
+
+       for (i = 0; i < args_count; i++) {
+               strncat(args, tmp_args[i], len - s - 1);
+               s += strlen(tmp_args[i]);
+               if (i != args_count - 1) {
+                       strncat(args, " ", len - s - 1);
+                       s += strlen(" ");
+               }
+       }
+
+       if (target_uid == (uid_t)-1 || pkgpath == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
+               ret = -1;
+               goto catch;
+       }
+
+       pkgpath = _get_adjusted_pkgpath(pkgpath, caller_uid);
+       pkgtype = _get_pkgtype_from_file(pkgpath);
+       if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype))
+               pkgtype = (const char *)arg_pkgtype;
+       if (pkgtype == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
+               ret = -1;
+               goto catch;
+       }
+
+       reqkey = __generate_reqkey(pkgpath);
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               ret = -1;
+               goto catch;
+       }
+
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_MOUNT_INSTALL,
+                               pkgtype, pkgpath, args)) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
+               ret = -1;
+               goto catch;
+       }
+
+       g_dbus_method_invocation_return_value(invocation,
+                       g_variant_new("(is)", PKGMGR_R_OK, reqkey));
+       ret = 0;
+
+catch:
+       if (reqkey)
+               free(reqkey);
+
+       if (args)
+               free(args);
+
+       if (tmp_args)
+               g_free(tmp_args);
+
        return ret;
 }
 
-static int __handle_request_reinstall(uid_t uid,
+static int __handle_request_reinstall(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype = NULL;
+       char *pkgtype;
        char *pkgid = NULL;
        char *reqkey;
 
-       g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid);
-       if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) {
+       g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
+       if (target_uid == (uid_t)-1 || pkgid == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                return -1;
        }
 
+       pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
+       if (pkgtype == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOPKG, ""));
+               return -1;
+       }
+
        reqkey = __generate_reqkey(pkgid);
-       if (reqkey == NULL)
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               free(pkgtype);
                return -1;
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_REINSTALL, pkgtype,
-                               pkgid, "")) {
+       }
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_REINSTALL,
+                               pkgtype, pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
+               free(pkgtype);
                return -1;
        }
 
        g_dbus_method_invocation_return_value(invocation,
                        g_variant_new("(is)", PKGMGR_R_OK, reqkey));
        free(reqkey);
+       free(pkgtype);
 
        return 0;
 }
 
-static int __handle_request_uninstall(uid_t uid,
+static int __handle_request_uninstall(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype = NULL;
+       char *pkgtype;
        char *pkgid = NULL;
        char *reqkey;
 
-       g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid);
-       if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) {
+       g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
+       if (target_uid == (uid_t)-1 || pkgid == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                return -1;
        }
 
+       pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
+       if (pkgtype == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOPKG, ""));
+               return -1;
+       }
+
        reqkey = __generate_reqkey(pkgid);
-       if (reqkey == NULL)
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               free(pkgtype);
                return -1;
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_UNINSTALL, pkgtype,
-                               pkgid, "")) {
+       }
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_UNINSTALL,
+                               pkgtype, pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
+               free(pkgtype);
                return -1;
        }
 
        g_dbus_method_invocation_return_value(invocation,
                        g_variant_new("(is)", PKGMGR_R_OK, reqkey));
        free(reqkey);
+       free(pkgtype);
 
        return 0;
 }
 
-static int __handle_request_move(uid_t uid,
+static int __handle_request_move(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype = NULL;
+       char *pkgtype;
        char *pkgid = NULL;
        char *reqkey;
        int move_type = -1;
        char buf[4] = { '\0' };
 
-       g_variant_get(parameters, "(u&s&si)", &target_uid, &pkgtype, &pkgid, &move_type);
-       if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) {
+       g_variant_get(parameters, "(u&si)", &target_uid, &pkgid, &move_type);
+       if (target_uid == (uid_t)-1 || pkgid == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
+               return -1;
+       }
+
+       pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
+       if (pkgtype == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOPKG, ""));
                return -1;
        }
 
        reqkey = __generate_reqkey(pkgid);
-       if (reqkey == NULL)
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               free(pkgtype);
                return -1;
+       }
 
        snprintf(buf, sizeof(buf), "%d", move_type);
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOVE, pkgtype,
-                               pkgid, buf)) {
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_MOVE,
+                               pkgtype, pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+                               g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
+               free(pkgtype);
                return -1;
        }
 
        g_dbus_method_invocation_return_value(invocation,
-                       g_variant_new("(i)", PKGMGR_R_OK));
+                       g_variant_new("(is)", PKGMGR_R_OK, reqkey));
        free(reqkey);
+       free(pkgtype);
 
        return 0;
 }
 
-static int __handle_request_enable_pkg(uid_t uid,
+static int __handle_request_enable_pkgs(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype = NULL;
-       char *pkgid = NULL;
+       char *pkgtype;
+       char *pkgid;
+       char *reqkey;
+       GVariantIter *iter;
 
-       g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid);
-       if (target_uid == (uid_t)-1 || pkgid == NULL) {
+       g_variant_get(parameters, "(uas)", &target_uid, &iter);
+       if (target_uid == (uid_t)-1 || iter == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_ENABLE_PKG, pkgtype,
-                               pkgid, "")) {
+       reqkey = __generate_reqkey("enable_pkgs");
+       if (reqkey == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                return -1;
        }
 
+       while (g_variant_iter_next(iter, "&s", &pkgid)) {
+               pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
+               if (pkgtype == NULL) {
+                       g_dbus_method_invocation_return_value(invocation,
+                                       g_variant_new("(is)",
+                                               PKGMGR_R_ENOPKG, ""));
+                       free(reqkey);
+                       return -1;
+               }
+               if (_push_queue(target_uid, caller_uid, reqkey,
+                                       REQUEST_TYPE_ENABLE_PKG,
+                                       pkgtype, pkgid, NULL)) {
+                       g_dbus_method_invocation_return_value(invocation,
+                                       g_variant_new("(is)",
+                                               PKGMGR_R_ESYSTEM, ""));
+                       free(pkgtype);
+                       free(reqkey);
+                       return -1;
+               }
+               free(pkgtype);
+       }
+
        g_dbus_method_invocation_return_value(invocation,
-                       g_variant_new("(i)", PKGMGR_R_OK));
+                       g_variant_new("(is)", PKGMGR_R_OK, reqkey));
+       free(reqkey);
 
        return 0;
 }
 
-static int __handle_request_disable_pkg(uid_t uid,
+static int __handle_request_disable_pkgs(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype = NULL;
-       char *pkgid = NULL;
+       char *pkgtype;
+       char *pkgid;
+       char *reqkey;
+       GVariantIter *iter;
 
-       g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid);
-       if (target_uid == (uid_t)-1 || pkgid == NULL) {
+       g_variant_get(parameters, "(uas)", &target_uid, &iter);
+       if (target_uid == (uid_t)-1 || iter == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_DISABLE_PKG, pkgtype,
-                               pkgid, "")) {
+       reqkey = __generate_reqkey("disable_pkgs");
+       if (reqkey == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                return -1;
        }
 
+       while (g_variant_iter_next(iter, "&s", &pkgid)) {
+               pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
+               if (pkgtype == NULL) {
+                       g_dbus_method_invocation_return_value(invocation,
+                                       g_variant_new("(is)",
+                                               PKGMGR_R_ENOPKG, ""));
+                       free(reqkey);
+                       return -1;
+               }
+               if (_push_queue(target_uid, caller_uid, reqkey,
+                                       REQUEST_TYPE_DISABLE_PKG,
+                                       pkgtype, pkgid, NULL)) {
+                       g_dbus_method_invocation_return_value(invocation,
+                                       g_variant_new("(is)",
+                                               PKGMGR_R_ESYSTEM, ""));
+                       free(pkgtype);
+                       free(reqkey);
+                       return -1;
+               }
+               free(pkgtype);
+       }
+
        g_dbus_method_invocation_return_value(invocation,
-                       g_variant_new("(i)", PKGMGR_R_OK));
+                       g_variant_new("(is)", PKGMGR_R_OK, reqkey));
+       free(reqkey);
+
+       return 0;
+}
+
+static int __handle_request_enable_apps(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *appid;
+       char *reqkey;
+       char buf[MAX_PKG_ARGS_LEN];
+       GVariantIter *iter;
+
+       g_variant_get(parameters, "(uas)", &target_uid, &iter);
+       if (target_uid == (uid_t)-1 || iter == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey("enable_apps");
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               return -1;
+       }
+
+       while (g_variant_iter_next(iter, "&s", &appid)) {
+               if (_push_queue(target_uid, caller_uid, reqkey,
+                                       REQUEST_TYPE_ENABLE_APP,
+                                       "default", appid, buf)) {
+                       g_dbus_method_invocation_return_value(invocation,
+                                       g_variant_new("(is)",
+                                               PKGMGR_R_ESYSTEM, ""));
+                       free(reqkey);
+                       return -1;
+               }
+       }
+
+       g_dbus_method_invocation_return_value(invocation,
+               g_variant_new("(is)", PKGMGR_R_OK, reqkey));
+
+       free(reqkey);
+       return 0;
+}
+
+static int __handle_request_disable_apps(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *appid;
+       char *reqkey;
+       char buf[MAX_PKG_ARGS_LEN];
+       GVariantIter *iter;
+
+       g_variant_get(parameters, "(uas)", &target_uid, &iter);
+       if (target_uid == (uid_t)-1 || iter == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
+               return -1;
+       }
 
+       reqkey = __generate_reqkey("disable_apps");
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               return -1;
+       }
+
+       while (g_variant_iter_next(iter, "&s", &appid)) {
+               if (_push_queue(target_uid, caller_uid, reqkey,
+                                       REQUEST_TYPE_DISABLE_APP,
+                                       "default", appid, buf)) {
+                       g_dbus_method_invocation_return_value(invocation,
+                                       g_variant_new("(is)",
+                                               PKGMGR_R_ESYSTEM, ""));
+                       free(reqkey);
+                       return -1;
+               }
+       }
+
+       g_dbus_method_invocation_return_value(invocation,
+               g_variant_new("(is)", PKGMGR_R_OK, reqkey));
+
+       free(reqkey);
        return 0;
+
 }
 
-static int __handle_request_enable_app(uid_t uid,
+static int __handle_request_enable_app(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
@@ -430,12 +835,15 @@ static int __handle_request_enable_app(uid_t uid,
 
        reqkey = __generate_reqkey(appid);
        if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                ret = -1;
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_APP, "default",
-                               appid, "")) {
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_ENABLE_APP, "default",
+                               appid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -448,13 +856,13 @@ static int __handle_request_enable_app(uid_t uid,
        ret = 0;
 
 catch:
-       if(reqkey)
+       if (reqkey)
                free(reqkey);
 
        return ret;
 }
 
-static int __handle_request_disable_app(uid_t uid,
+static int __handle_request_disable_app(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
@@ -471,12 +879,15 @@ static int __handle_request_disable_app(uid_t uid,
 
        reqkey = __generate_reqkey(appid);
        if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                ret = -1;
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_APP, "default",
-                               appid, "")) {
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_DISABLE_APP, "default",
+                               appid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -495,7 +906,7 @@ catch:
        return ret;
 }
 
-static int __handle_request_enable_global_app_for_uid(uid_t uid,
+static int __handle_request_enable_global_app_for_uid(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
@@ -512,12 +923,15 @@ static int __handle_request_enable_global_app_for_uid(uid_t uid,
 
        reqkey = __generate_reqkey(appid);
        if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                ret = -1;
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, "default",
-                               appid, "")) {
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID,
+                               "default", appid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -536,7 +950,7 @@ catch:
        return ret;
 }
 
-static int __handle_request_disable_global_app_for_uid(uid_t uid,
+static int __handle_request_disable_global_app_for_uid(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
@@ -553,12 +967,15 @@ static int __handle_request_disable_global_app_for_uid(uid_t uid,
 
        reqkey = __generate_reqkey(appid);
        if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                ret = -1;
                goto catch;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, "default",
-                               appid, "")) {
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID,
+                               "default", appid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -577,7 +994,7 @@ catch:
        return ret;
 }
 
-static int __handle_request_getsize(uid_t uid,
+static int __handle_request_getsize(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
@@ -594,12 +1011,15 @@ static int __handle_request_getsize(uid_t uid,
        }
 
        reqkey = __generate_reqkey(pkgid);
-       if (reqkey == NULL)
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                return -1;
+       }
 
        snprintf(buf, sizeof(buf), "%d", get_type);
-       if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_GETSIZE, "pkgtool",
-                               pkgid, buf)) {
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_GETSIZE,
+                               "pkgtool", pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
@@ -613,38 +1033,51 @@ static int __handle_request_getsize(uid_t uid,
        return 0;
 }
 
-static int __handle_request_cleardata(uid_t uid,
+static int __handle_request_getsize_sync(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype = NULL;
        char *pkgid = NULL;
+       int get_type = -1;
+       char *reqkey;
+       char buf[4];
 
-       g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid);
-       if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) {
+       g_variant_get(parameters, "(u&si)", &target_uid, &pkgid, &get_type);
+       if (target_uid == (uid_t)-1 || pkgid == NULL || get_type == -1) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARDATA, "pkgtool",
-                               pkgid, "")) {
+       reqkey = __generate_reqkey(pkgid);
+       if (reqkey == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
                return -1;
        }
 
-       g_dbus_method_invocation_return_value(invocation,
-                       g_variant_new("(i)", PKGMGR_R_OK));
+       snprintf(buf, sizeof(buf), "%d", get_type);
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_GETSIZE_SYNC,
+                               "pkgtool", pkgid, buf)) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
+               free(reqkey);
+               return -1;
+       }
+
+       if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+                               (gpointer)invocation))
+               ERR("reqkey already exists");
 
        return 0;
 }
 
-static int __handle_request_clearcache(uid_t uid,
+static int __handle_request_cleardata(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
        char *pkgid = NULL;
+       char *pkgtype;
 
        g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
        if (target_uid == (uid_t)-1 || pkgid == NULL) {
@@ -653,8 +1086,15 @@ static int __handle_request_clearcache(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARCACHE,
-                               "pkgtool",  pkgid, "")) {
+       pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
+       if (pkgtype == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOPKG, ""));
+               return -1;
+       }
+
+       if (_push_queue(target_uid, caller_uid, NULL, REQUEST_TYPE_CLEARDATA,
+                               pkgtype, pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                return -1;
@@ -666,11 +1106,12 @@ static int __handle_request_clearcache(uid_t uid,
        return 0;
 }
 
-static int __handle_request_kill(uid_t uid,
+static int __handle_request_clearcache(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
        char *pkgid = NULL;
+       char *pkgtype;
 
        g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
        if (target_uid == (uid_t)-1 || pkgid == NULL) {
@@ -679,8 +1120,18 @@ static int __handle_request_kill(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_KILL, "default",
-                               pkgid, "")) {
+       if (strcmp(PKG_CLEAR_ALL_CACHE, pkgid) == 0)
+               pkgtype = strdup("pkgtool");
+       else
+               pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
+       if (pkgtype == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOPKG, ""));
+               return -1;
+       }
+
+       if (_push_queue(target_uid, caller_uid, NULL, REQUEST_TYPE_CLEARCACHE,
+                               pkgtype,  pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                return -1;
@@ -692,33 +1143,79 @@ static int __handle_request_kill(uid_t uid,
        return 0;
 }
 
-static int __handle_request_check(uid_t uid,
+static int __handle_request_kill(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
        char *pkgid = NULL;
+       char *reqkey = NULL;
 
        g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
        if (target_uid == (uid_t)-1 || pkgid == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+                               g_variant_new("(ii)", PKGMGR_R_ECOMM, 0));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey(pkgid);
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CHECK, "default",
-                               pkgid, "")) {
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_KILL,
+                               "default", pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+                               g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0));
+               free(reqkey);
                return -1;
        }
 
-       g_dbus_method_invocation_return_value(invocation,
-                       g_variant_new("(i)", PKGMGR_R_OK));
+       if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+                               (gpointer)invocation))
+               ERR("reqkey already exists");
 
        return 0;
 }
 
-static int __handle_request_generate_license_request(uid_t uid,
+static int __handle_request_check(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *pkgid = NULL;
+       char *reqkey = NULL;
+
+       g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
+       if (target_uid == (uid_t)-1 || pkgid == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(ii)", PKGMGR_R_ECOMM, 0));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey(pkgid);
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0));
+               return -1;
+       }
+
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_CHECK,
+                               "default", pkgid, NULL)) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0));
+               free(reqkey);
+               return -1;
+       }
+
+       if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+                               (gpointer)invocation))
+               ERR("reqkey already exists");
+
+       return 0;
+}
+
+static int __handle_request_generate_license_request(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        char *reqkey;
@@ -739,9 +1236,9 @@ static int __handle_request_generate_license_request(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(uid, reqkey,
-                               PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST,
-                               "default", "", resp_data)) {
+       if (_push_queue(caller_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_GENERATE_LICENSE_REQUEST,
+                               "default", NULL, resp_data)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(iss)", PKGMGR_R_ESYSTEM, "",
                                        ""));
@@ -756,7 +1253,7 @@ static int __handle_request_generate_license_request(uid_t uid,
        return 0;
 }
 
-static int __handle_request_register_license(uid_t uid,
+static int __handle_request_register_license(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        char *reqkey;
@@ -776,8 +1273,9 @@ static int __handle_request_register_license(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(uid, reqkey, PKGMGR_REQUEST_TYPE_REGISTER_LICENSE,
-                               "default", "", resp_data)) {
+       if (_push_queue(caller_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_REGISTER_LICENSE,
+                               "default", NULL, resp_data)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -791,7 +1289,7 @@ static int __handle_request_register_license(uid_t uid,
        return 0;
 }
 
-static int __handle_request_decrypt_package(uid_t uid,
+static int __handle_request_decrypt_package(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        char *reqkey;
@@ -813,8 +1311,10 @@ static int __handle_request_decrypt_package(uid_t uid,
                return -1;
        }
 
-       if (_pm_queue_push(uid, reqkey, PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE,
-                               "default", drm_file_path, decrypted_file_path)) {
+       if (_push_queue(caller_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_DECRYPT_PACKAGE,
+                               "default", drm_file_path,
+                               decrypted_file_path)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -828,30 +1328,89 @@ static int __handle_request_decrypt_package(uid_t uid,
        return 0;
 }
 
-static int __handle_request_add_blacklist(uid_t uid,
-               GDBusMethodInvocation *invocation, GVariant *parameters)
+static int __update_app_splash_screen(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters,
+               int req_type)
 {
        uid_t target_uid = (uid_t)-1;
+       char *appid = NULL;
        char *reqkey;
+
+       g_variant_get(parameters, "(u&s)", &target_uid, &appid);
+       if (target_uid == (uid_t)-1 || appid == NULL) {
+               ERR("target_uid: %d, appid: %s", target_uid, appid);
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey(appid);
+       if (reqkey == NULL) {
+               ERR("Failed to generate request key");
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               return -1;
+       }
+
+       if (_push_queue(target_uid, caller_uid, reqkey, req_type, "default",
+                               appid, NULL)) {
+               ERR("Failed to push request");
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+               free(reqkey);
+               return -1;
+       }
+
+       g_dbus_method_invocation_return_value(invocation,
+                       g_variant_new("(i)", PKGMGR_R_OK));
+
+       if (reqkey)
+               free(reqkey);
+
+       return 0;
+}
+
+static int __handle_request_enable_app_splash_screen(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       return __update_app_splash_screen(caller_uid, invocation, parameters,
+                       REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN);
+}
+
+static int __handle_request_disable_app_splash_screen(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       return __update_app_splash_screen(caller_uid, invocation, parameters,
+                       REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN);
+}
+
+static int __handle_request_set_restriction_mode(uid_t caller_uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
        char *pkgid = NULL;
+       char *reqkey;
+       int mode = -1;
+       char buf[4];
 
-       g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
-       if (target_uid == (uid_t)-1 || pkgid == NULL) {
+       g_variant_get(parameters, "(usi)", &target_uid, &pkgid, &mode);
+       if (target_uid == (uid_t)-1 || pkgid == NULL || mode < 0) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ECOMM));
                return -1;
        }
 
-       reqkey = __generate_reqkey("blacklist");
+       reqkey = __generate_reqkey("restriction");
        if (reqkey == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ENOMEM));
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, reqkey,
-                               PKGMGR_REQUEST_TYPE_ADD_BLACKLIST,
-                               "default",  pkgid, "")) {
+       snprintf(buf, sizeof(buf), "%d", mode);
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_SET_RESTRICTION_MODE,
+                               "default", pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -865,30 +1424,33 @@ static int __handle_request_add_blacklist(uid_t uid,
        return 0;
 }
 
-static int __handle_request_remove_blacklist(uid_t uid,
+static int __handle_request_unset_restriction_mode(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *reqkey;
        char *pkgid = NULL;
+       char *reqkey;
+       int mode = -1;
+       char buf[4];
 
-       g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
-       if (target_uid == (uid_t)-1 || pkgid == NULL) {
+       g_variant_get(parameters, "(usi)", &target_uid, &pkgid, &mode);
+       if (target_uid == (uid_t)-1 || pkgid == NULL || mode < 0) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ECOMM));
                return -1;
        }
 
-       reqkey = __generate_reqkey("blacklist");
+       reqkey = __generate_reqkey("restriction");
        if (reqkey == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ENOMEM));
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, reqkey,
-                               PKGMGR_REQUEST_TYPE_REMOVE_BLACKLIST,
-                               "default", pkgid, "")) {
+       snprintf(buf, sizeof(buf), "%d", mode);
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_UNSET_RESTRICTION_MODE,
+                               "default", pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -902,32 +1464,32 @@ static int __handle_request_remove_blacklist(uid_t uid,
        return 0;
 }
 
-static int __handle_request_check_blacklist(uid_t uid,
+static int __handle_request_get_restriction_mode(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *reqkey;
        char *pkgid = NULL;
+       char *reqkey;
 
-       g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
+       g_variant_get(parameters, "(us)", &target_uid, &pkgid);
        if (target_uid == (uid_t)-1 || pkgid == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(ii)", PKGMGR_R_ECOMM, -1));
+                               g_variant_new("(i)", PKGMGR_R_ECOMM));
                return -1;
        }
 
-       reqkey = __generate_reqkey("blacklist");
+       reqkey = __generate_reqkey("restriction");
        if (reqkey == NULL) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(ii)", PKGMGR_R_ENOMEM, -1));
+                               g_variant_new("(ii)", -1, PKGMGR_R_ENOMEM));
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, reqkey,
-                               PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST,
-                               "default", pkgid, "")) {
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                               REQUEST_TYPE_GET_RESTRICTION_MODE,
+                               "default", pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
-                               g_variant_new("(ii)", PKGMGR_R_ESYSTEM, -1));
+                               g_variant_new("(ii)", -1, PKGMGR_R_ESYSTEM));
                free(reqkey);
                return -1;
        }
@@ -939,59 +1501,91 @@ static int __handle_request_check_blacklist(uid_t uid,
        return 0;
 }
 
-
-static int __update_app_splash_screen(uid_t uid,
-               GDBusMethodInvocation *invocation, GVariant *parameters,
-               int req_type)
+static int __handle_request_set_app_label(uid_t uid,
+               GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
        char *appid = NULL;
+       char *label = NULL;
        char *reqkey;
 
-       g_variant_get(parameters, "(u&s)", &target_uid, &appid);
-       if (target_uid == (uid_t)-1 || appid == NULL) {
-               ERR("target_uid: %d, appid: %s", target_uid, appid);
+       g_variant_get(parameters, "(uss)", &target_uid, &appid, &label);
+       if (target_uid == (uid_t)-1 || appid == NULL || label == NULL) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ECOMM));
                return -1;
        }
 
-       reqkey = __generate_reqkey(appid);
+       reqkey = __generate_reqkey("appid");
        if (reqkey == NULL) {
-               ERR("Failed to generate request key");
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
                return -1;
        }
 
-       if (_pm_queue_push(target_uid, reqkey, req_type, "default",
-                               appid, "")) {
-               ERR("Failed to push request");
+       if (_push_queue(target_uid, uid, reqkey,
+                               REQUEST_TYPE_SET_APP_LABEL,
+                               "default", appid, label)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
                return -1;
        }
 
-       g_dbus_method_invocation_return_value(invocation,
-                       g_variant_new("(i)", PKGMGR_R_OK));
-
-       if (reqkey)
-               free(reqkey);
+       if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+                               (gpointer)invocation))
+               ERR("reqkey already exists");
 
        return 0;
 }
 
-static int __handle_request_enable_app_splash_screen(uid_t uid,
+static int __handle_request_migrate_external_image(uid_t uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
-       return __update_app_splash_screen(uid, invocation, parameters,
-                       PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN);
-}
+       uid_t target_uid = (uid_t)-1;
+       char *pkgid = NULL;
+       char *pkgtype;
+       char *reqkey;
 
-static int __handle_request_disable_app_splash_screen(uid_t uid,
-               GDBusMethodInvocation *invocation, GVariant *parameters)
-{
-       return __update_app_splash_screen(uid, invocation, parameters,
-                       PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN);
+       g_variant_get(parameters, "(us)", &target_uid, &pkgid);
+       if (target_uid == (uid_t)-1 || pkgid == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ECOMM));
+               return -1;
+       }
+
+       pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid);
+       if (pkgtype == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOPKG));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey(pkgid);
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               free(pkgtype);
+               return -1;
+       }
+
+       if (_push_queue(target_uid, uid, reqkey,
+                               REQUEST_TYPE_MIGRATE_EXTERNAL_IMAGE,
+                               pkgtype, pkgid, NULL)) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+               free(reqkey);
+               free(pkgtype);
+               return -1;
+       }
+
+       g_dbus_method_invocation_return_value(invocation,
+                       g_variant_new("(i)", PKGMGR_R_OK));
+
+       free(reqkey);
+       free(pkgtype);
+
+       return 0;
 }
 
 static uid_t __get_caller_uid(GDBusConnection *connection, const char *name)
@@ -1012,6 +1606,7 @@ static uid_t __get_caller_uid(GDBusConnection *connection, const char *name)
        }
 
        g_variant_get(result, "(u)", &uid);
+       g_variant_unref(result);
 
        return uid;
 }
@@ -1030,8 +1625,14 @@ static void __handle_method_call(GDBusConnection *connection,
        if (uid == (uid_t)-1)
                return;
 
+       if (__check_caller_permission(uid, invocation, parameters))
+               return;
+
        if (g_strcmp0(method_name, "install") == 0)
                ret = __handle_request_install(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "mount_install") == 0)
+               ret = __handle_request_mount_install(uid, invocation,
+                               parameters);
        else if (g_strcmp0(method_name, "reinstall") == 0)
                ret = __handle_request_reinstall(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "uninstall") == 0)
@@ -1040,22 +1641,30 @@ static void __handle_method_call(GDBusConnection *connection,
                ret = __handle_request_cleardata(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "move") == 0)
                ret = __handle_request_move(uid, invocation, parameters);
-       else if (g_strcmp0(method_name, "enable") == 0)
-               ret = __handle_request_enable_pkg(uid, invocation, parameters);
-       else if (g_strcmp0(method_name, "disable") == 0)
-               ret = __handle_request_disable_pkg(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "enable_pkgs") == 0)
+               ret = __handle_request_enable_pkgs(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "disable_pkgs") == 0)
+               ret = __handle_request_disable_pkgs(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "getsize") == 0)
                ret = __handle_request_getsize(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "getsize_sync") == 0)
+               ret = __handle_request_getsize_sync(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "clearcache") == 0)
                ret = __handle_request_clearcache(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "enable_app") == 0)
                ret = __handle_request_enable_app(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "disable_app") == 0)
                ret = __handle_request_disable_app(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "enable_apps") == 0)
+               ret = __handle_request_enable_apps(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "disable_apps") == 0)
+               ret = __handle_request_disable_apps(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "enable_global_app_for_uid") == 0)
-               ret = __handle_request_enable_global_app_for_uid(uid, invocation, parameters);
+               ret = __handle_request_enable_global_app_for_uid(uid,
+                               invocation, parameters);
        else if (g_strcmp0(method_name, "disable_global_app_for_uid") == 0)
-               ret = __handle_request_disable_global_app_for_uid(uid, invocation, parameters);
+               ret = __handle_request_disable_global_app_for_uid(uid,
+                               invocation, parameters);
        else if (g_strcmp0(method_name, "kill") == 0)
                ret = __handle_request_kill(uid, invocation, parameters);
        else if (g_strcmp0(method_name, "check") == 0)
@@ -1069,21 +1678,26 @@ static void __handle_method_call(GDBusConnection *connection,
        else if (g_strcmp0(method_name, "decrypt_package") == 0)
                ret = __handle_request_decrypt_package(uid, invocation,
                                parameters);
-       else if (g_strcmp0(method_name, "add_blacklist") == 0)
-               ret = __handle_request_add_blacklist(uid, invocation,
-                               parameters);
-       else if (g_strcmp0(method_name, "remove_blacklist") == 0)
-               ret = __handle_request_remove_blacklist(uid, invocation,
-                               parameters);
-       else if (g_strcmp0(method_name, "check_blacklist") == 0)
-               ret = __handle_request_check_blacklist(uid, invocation,
-                               parameters);
        else if (g_strcmp0(method_name, "disable_app_splash_screen") == 0)
                ret = __handle_request_disable_app_splash_screen(uid,
                                invocation, parameters);
        else if (g_strcmp0(method_name, "enable_app_splash_screen") == 0)
                ret = __handle_request_enable_app_splash_screen(uid,
                                invocation, parameters);
+       else if (g_strcmp0(method_name, "set_restriction_mode") == 0)
+               ret = __handle_request_set_restriction_mode(uid, invocation,
+                               parameters);
+       else if (g_strcmp0(method_name, "unset_restriction_mode") == 0)
+               ret = __handle_request_unset_restriction_mode(uid, invocation,
+                               parameters);
+       else if (g_strcmp0(method_name, "get_restriction_mode") == 0)
+               ret = __handle_request_get_restriction_mode(uid, invocation,
+                               parameters);
+       else if (g_strcmp0(method_name, "set_app_label") == 0)
+               ret = __handle_request_set_app_label(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "migrate_external_image") == 0)
+               ret = __handle_request_migrate_external_image(uid, invocation,
+                               parameters);
        else
                ret = -1;
 
@@ -1091,7 +1705,7 @@ static void __handle_method_call(GDBusConnection *connection,
                g_idle_add(queue_job, NULL);
 }
 
-int __return_value_to_caller(const char *req_key, GVariant *result)
+int _return_value_to_caller(const char *req_key, GVariant *result)
 {
        GDBusMethodInvocation *invocation;
 
@@ -1108,8 +1722,7 @@ int __return_value_to_caller(const char *req_key, GVariant *result)
        return 0;
 }
 
-static const GDBusInterfaceVTable interface_vtable =
-{
+static const GDBusInterfaceVTable interface_vtable = {
        __handle_method_call,
        NULL,
        NULL,
@@ -1145,9 +1758,10 @@ static void __on_name_lost(GDBusConnection *connection, const gchar *name,
        DBG("on name lost: %s", name);
 }
 
-int __init_request_handler(void)
+int _init_request_handler(void)
 {
-       instropection_data = g_dbus_node_info_new_for_xml(instropection_xml, NULL);
+       instropection_data = g_dbus_node_info_new_for_xml(instropection_xml,
+                       NULL);
 
        owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, PKGMGR_DBUS_SERVICE,
                        G_BUS_NAME_OWNER_FLAGS_NONE, __on_bus_acquired,
@@ -1161,7 +1775,7 @@ int __init_request_handler(void)
        return 0;
 }
 
-void __fini_request_handler(void)
+void _fini_request_handler(void)
 {
        g_hash_table_destroy(req_table);
        g_bus_unown_name(owner_id);