Return no such pkg error when failed to get pkgtype
[platform/core/appfw/pkgmgr-server.git] / src / request.c
index 7345026..4db0f6d 100644 (file)
@@ -11,6 +11,8 @@
 #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"
 
@@ -27,7 +29,6 @@ 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'/>"
@@ -42,14 +43,12 @@ static const char instropection_xml[] =
        "    </method>"
        "    <method name='uninstall'>"
        "      <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='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'/>"
@@ -57,14 +56,12 @@ static const char instropection_xml[] =
        "    </method>"
        "    <method name='enable_pkgs'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' 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_pkgs'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='as' name='pkgids' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
@@ -102,7 +99,6 @@ static const char instropection_xml[] =
        "    </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>"
@@ -166,6 +162,12 @@ static const char instropection_xml[] =
        "      <arg type='i' name='result' direction='out'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
+       "    <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>"
        "  </interface>"
        "</node>";
 static GDBusNodeInfo *instropection_data;
@@ -200,10 +202,21 @@ 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);
 
-       guser = gum_user_get_sync(uid, FALSE);
        if (guser == NULL) {
-               ERR("cannot get user information from gumd");
+               ERR("cannot get user information from gumd, failed");
                return -1;
        }
 
@@ -222,7 +235,6 @@ static int __is_admin_user(uid_t uid)
        return 1;
 }
 
-#define REGULAR_USER 5000
 static int __check_caller_permission(uid_t uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
@@ -263,11 +275,12 @@ static int __check_caller_permission(uid_t uid,
        return 0;
 }
 
-static int __handle_request_install(uid_t uid,
+static int __handle_request_install(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype = NULL;
+       char *arg_pkgtype = NULL;
+       const char *pkgtype;
        char *pkgpath = NULL;
        char *args = NULL;
        char *reqkey = NULL;
@@ -278,8 +291,8 @@ static int __handle_request_install(uid_t uid,
        int i = 0;
        int len = 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++)
@@ -300,14 +313,17 @@ static int __handle_request_install(uid_t uid,
                        strncat(args, " ", 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) {
+       pkgtype = _get_pkgtype_from_file(pkgpath, caller_uid);
+       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;
@@ -322,8 +338,8 @@ static int __handle_request_install(uid_t uid,
                goto catch;
        }
 
-       if (_push_queue(target_uid, reqkey, 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;
@@ -342,14 +358,18 @@ catch:
        if (args)
                free(args);
 
+       if (tmp_args)
+               g_free(tmp_args);
+
        return ret;
 }
 
-static int __handle_request_mount_install(uid_t uid,
+static int __handle_request_mount_install(uid_t caller_uid,
        GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
-       char *pkgtype = NULL;
+       char *arg_pkgtype = NULL;
+       const char *pkgtype;
        char *pkgpath = NULL;
        char *args = NULL;
        char *reqkey = NULL;
@@ -360,8 +380,8 @@ static int __handle_request_mount_install(uid_t uid,
        int i = 0;
        int len = 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++)
@@ -382,14 +402,17 @@ static int __handle_request_mount_install(uid_t uid,
                        strncat(args, " ", 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) {
+       pkgtype = _get_pkgtype_from_file(pkgpath, caller_uid);
+       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;
@@ -404,7 +427,8 @@ static int __handle_request_mount_install(uid_t uid,
                goto catch;
        }
 
-       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_MOUNT_INSTALL,
+       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, ""));
@@ -423,133 +447,165 @@ catch:
        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) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               free(pkgtype);
                return -1;
        }
-       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_REINSTALL, pkgtype,
-                               pkgid, NULL)) {
+       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) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               free(pkgtype);
                return -1;
        }
-       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_UNINSTALL, pkgtype,
-                               pkgid, NULL)) {
+       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("(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) {
                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 (_push_queue(target_uid, reqkey, 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("(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_enable_pkgs(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 *pkgtype;
        char *pkgid;
        char *reqkey;
        GVariantIter *iter;
 
-       g_variant_get(parameters, "(u&sas)", &target_uid, &pkgtype, &iter);
-       if (target_uid == (uid_t)-1 || pkgtype == NULL || iter == 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("(is)", PKGMGR_R_ECOMM, ""));
                return -1;
@@ -563,14 +619,25 @@ static int __handle_request_enable_pkgs(uid_t uid,
        }
 
        while (g_variant_iter_next(iter, "&s", &pkgid)) {
-               if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_PKG,
+               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,
@@ -580,17 +647,17 @@ static int __handle_request_enable_pkgs(uid_t uid,
        return 0;
 }
 
-static int __handle_request_disable_pkgs(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 *pkgtype;
        char *pkgid;
        char *reqkey;
        GVariantIter *iter;
 
-       g_variant_get(parameters, "(u&sas)", &target_uid, &pkgtype, &iter);
-       if (target_uid == (uid_t)-1 || pkgtype == NULL || iter == 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("(is)", PKGMGR_R_ECOMM, ""));
                return -1;
@@ -604,14 +671,25 @@ static int __handle_request_disable_pkgs(uid_t uid,
        }
 
        while (g_variant_iter_next(iter, "&s", &pkgid)) {
-               if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_PKG,
+               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,
@@ -621,7 +699,7 @@ static int __handle_request_disable_pkgs(uid_t uid,
        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;
@@ -644,7 +722,8 @@ static int __handle_request_enable_app(uid_t uid,
                goto catch;
        }
 
-       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_APP, "default",
+       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, ""));
@@ -664,7 +743,7 @@ catch:
        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;
@@ -687,7 +766,8 @@ static int __handle_request_disable_app(uid_t uid,
                goto catch;
        }
 
-       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_APP, "default",
+       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, ""));
@@ -707,7 +787,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;
@@ -730,7 +810,7 @@ static int __handle_request_enable_global_app_for_uid(uid_t uid,
                goto catch;
        }
 
-       if (_push_queue(target_uid, reqkey,
+       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,
@@ -751,7 +831,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;
@@ -774,7 +854,7 @@ static int __handle_request_disable_global_app_for_uid(uid_t uid,
                goto catch;
        }
 
-       if (_push_queue(target_uid, reqkey,
+       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,
@@ -795,7 +875,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;
@@ -819,8 +899,8 @@ static int __handle_request_getsize(uid_t uid,
        }
 
        snprintf(buf, sizeof(buf), "%d", get_type);
-       if (_push_queue(target_uid, reqkey, 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);
@@ -834,33 +914,42 @@ static int __handle_request_getsize(uid_t uid,
        return 0;
 }
 
-static int __handle_request_cleardata(uid_t uid,
+static int __handle_request_cleardata(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 = NULL;
 
-       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("(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, reqkey, REQUEST_TYPE_CLEARDATA, pkgtype,
-                               pkgid, NULL)) {
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_CLEARDATA,
+                               pkgtype, pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
+               free(pkgtype);
                return -1;
        }
 
@@ -868,11 +957,12 @@ static int __handle_request_cleardata(uid_t uid,
                        g_variant_new("(i)", PKGMGR_R_OK));
 
        free(reqkey);
+       free(pkgtype);
 
        return 0;
 }
 
-static int __handle_request_clearcache(uid_t uid,
+static int __handle_request_clearcache(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
@@ -885,7 +975,7 @@ static int __handle_request_clearcache(uid_t uid,
                return -1;
        }
 
-       if (_push_queue(target_uid, NULL, REQUEST_TYPE_CLEARCACHE,
+       if (_push_queue(target_uid, caller_uid, NULL, REQUEST_TYPE_CLEARCACHE,
                                "pkgtool",  pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
@@ -898,7 +988,7 @@ static int __handle_request_clearcache(uid_t uid,
        return 0;
 }
 
-static int __handle_request_kill(uid_t uid,
+static int __handle_request_kill(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
@@ -919,7 +1009,7 @@ static int __handle_request_kill(uid_t uid,
                return -1;
        }
 
-       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_KILL,
+       if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_KILL,
                                "default", pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0));
@@ -934,7 +1024,7 @@ static int __handle_request_kill(uid_t uid,
        return 0;
 }
 
-static int __handle_request_check(uid_t uid,
+static int __handle_request_check(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
@@ -955,7 +1045,7 @@ static int __handle_request_check(uid_t uid,
                return -1;
        }
 
-       if (_push_queue(target_uid, reqkey, REQUEST_TYPE_CHECK,
+       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));
@@ -970,7 +1060,7 @@ static int __handle_request_check(uid_t uid,
        return 0;
 }
 
-static int __handle_request_generate_license_request(uid_t uid,
+static int __handle_request_generate_license_request(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        char *reqkey;
@@ -991,7 +1081,7 @@ static int __handle_request_generate_license_request(uid_t uid,
                return -1;
        }
 
-       if (_push_queue(uid, reqkey,
+       if (_push_queue(caller_uid, caller_uid, reqkey,
                                REQUEST_TYPE_GENERATE_LICENSE_REQUEST,
                                "default", NULL, resp_data)) {
                g_dbus_method_invocation_return_value(invocation,
@@ -1008,7 +1098,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;
@@ -1028,7 +1118,8 @@ static int __handle_request_register_license(uid_t uid,
                return -1;
        }
 
-       if (_push_queue(uid, reqkey, REQUEST_TYPE_REGISTER_LICENSE,
+       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));
@@ -1043,7 +1134,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;
@@ -1065,7 +1156,8 @@ static int __handle_request_decrypt_package(uid_t uid,
                return -1;
        }
 
-       if (_push_queue(uid, reqkey, REQUEST_TYPE_DECRYPT_PACKAGE,
+       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,
@@ -1081,7 +1173,7 @@ static int __handle_request_decrypt_package(uid_t uid,
        return 0;
 }
 
-static int __update_app_splash_screen(uid_t uid,
+static int __update_app_splash_screen(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters,
                int req_type)
 {
@@ -1105,7 +1197,7 @@ static int __update_app_splash_screen(uid_t uid,
                return -1;
        }
 
-       if (_push_queue(target_uid, reqkey, req_type, "default",
+       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,
@@ -1123,21 +1215,21 @@ static int __update_app_splash_screen(uid_t uid,
        return 0;
 }
 
-static int __handle_request_enable_app_splash_screen(uid_t uid,
+static int __handle_request_enable_app_splash_screen(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
-       return __update_app_splash_screen(uid, invocation, 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 uid,
+static int __handle_request_disable_app_splash_screen(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
-       return __update_app_splash_screen(uid, invocation, 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 uid,
+static int __handle_request_set_restriction_mode(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
        uid_t target_uid = (uid_t)-1;
@@ -1161,7 +1253,7 @@ static int __handle_request_set_restriction_mode(uid_t uid,
        }
 
        snprintf(buf, sizeof(buf), "%d", mode);
-       if (_push_queue(target_uid, reqkey,
+       if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_SET_RESTRICTION_MODE,
                                "default", pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
@@ -1177,7 +1269,7 @@ static int __handle_request_set_restriction_mode(uid_t uid,
        return 0;
 }
 
-static int __handle_request_unset_restriction_mode(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;
@@ -1201,7 +1293,7 @@ static int __handle_request_unset_restriction_mode(uid_t uid,
        }
 
        snprintf(buf, sizeof(buf), "%d", mode);
-       if (_push_queue(target_uid, reqkey,
+       if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_UNSET_RESTRICTION_MODE,
                                "default", pkgid, buf)) {
                g_dbus_method_invocation_return_value(invocation,
@@ -1217,7 +1309,7 @@ static int __handle_request_unset_restriction_mode(uid_t uid,
        return 0;
 }
 
-static int __handle_request_get_restriction_mode(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;
@@ -1238,7 +1330,7 @@ static int __handle_request_get_restriction_mode(uid_t uid,
                return -1;
        }
 
-       if (_push_queue(target_uid, reqkey,
+       if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_GET_RESTRICTION_MODE,
                                "default", pkgid, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
@@ -1254,6 +1346,44 @@ static int __handle_request_get_restriction_mode(uid_t uid,
        return 0;
 }
 
+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, "(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");
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               return -1;
+       }
+
+       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;
+       }
+
+       if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+                               (gpointer)invocation))
+               ERR("reqkey already exists");
+
+       return 0;
+}
+
 static uid_t __get_caller_uid(GDBusConnection *connection, const char *name)
 {
        GError *err = NULL;
@@ -1352,6 +1482,8 @@ static void __handle_method_call(GDBusConnection *connection,
        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
                ret = -1;