Add new implementation for pkg update info 67/122067/17
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 30 Mar 2017 05:30:40 +0000 (14:30 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 19 Apr 2017 04:59:36 +0000 (21:59 -0700)
- New implementation for pkg update info register/unregister

Related changes:
[slp-pkgmgr] : https://review.tizen.org/gerrit/122068
[pkgmgr-info] : https://review.tizen.org/gerrit/121964

Change-Id: I7d62b8618575e01f3393b0e378ccdfc745689ede
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
include/pkgmgr-server.h
include/queue.h
org.tizen.pkgmgr.conf
src/pkgmgr-server.c
src/queue.c
src/request.c
src/util.c

index 7b2fe5a..488fb3a 100644 (file)
@@ -62,6 +62,9 @@ enum request_type {
        REQUEST_TYPE_MOVE,
        REQUEST_TYPE_ENABLE_PKG,
        REQUEST_TYPE_DISABLE_PKG,
+       REQUEST_TYPE_REGISTER_PKG_UPDATE_INFO,
+       REQUEST_TYPE_UNREGISTER_PKG_UPDATE_INFO,
+       REQUEST_TYPE_UNREGISTER_ALL_PKG_UPDATE_INFO,
        REQUEST_TYPE_ENABLE_APP,
        REQUEST_TYPE_DISABLE_APP,
        REQUEST_TYPE_GETSIZE,
@@ -98,5 +101,6 @@ int _get_restriction_mode(uid_t uid, const char *pkgid, int *mode);
 const char *_get_pkgtype_from_file(const char *file_path);
 char *_get_pkgtype_from_pkgid(const char *pkgid, uid_t uid);
 const char *_get_adjusted_pkgpath(const char *org_file_path, uid_t caller_uid);
+int __is_admin_user(uid_t uid);
 
 #endif/*  _PKGMGR_SERVER_H_ */
index d89d78c..7d76a09 100644 (file)
@@ -38,12 +38,13 @@ struct backend_job {
        char *backend_type;
        char *backend_path;
        struct job_extra_info *extra;
+       void *extra_data;
 };
 
 int _is_queue_empty(int pos);
 int _push_queue(uid_t target_uid, uid_t caller_uid, const char *req_id,
                int req_type, const char *queue_type, const char *pkgid,
-               const char *args);
+               const char *args, void *extra_data);
 struct backend_job *_pop_queue(int pos);
 void _free_backend_job(struct backend_job *job);
 int _init_backend_queue(void);
index 306f578..23abd84 100644 (file)
@@ -44,5 +44,8 @@
                <check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="enable_global_app_for_uid" privilege="http://tizen.org/privilege/packagemanager.admin"/>
                <check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="disable_global_app_for_uid" privilege="http://tizen.org/privilege/packagemanager.admin"/>
                <check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="migrate_external_image" privilege="http://tizen.org/privilege/packagemanager.admin"/>
+               <check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="register_pkg_updateinfo" privilege="http://tizen.org/privilege/packagemanager.admin"/>
+               <check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="unregister_pkg_updateinfo" privilege="http://tizen.org/privilege/packagemanager.admin"/>
+               <check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="unregister_all_pkg_updateinfo" privilege="http://tizen.org/privilege/packagemanager.admin"/>
        </policy>
 </busconfig>
index a5691eb..82cb5d5 100644 (file)
@@ -912,6 +912,71 @@ static int __process_disable_pkg(struct backend_job *job)
        return pid;
 }
 
+static int __process_register_pkg_update_info(struct backend_job *job)
+{
+       int ret;
+
+       if (!job->extra_data) {
+               _return_value_to_caller(job->req_id,
+                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+               return -1;
+       }
+
+       ret = pkgmgr_parser_register_pkg_update_info_in_usr_db(
+                       (pkgmgrinfo_updateinfo_h)job->extra_data, job->target_uid);
+       if (ret == PMINFO_R_OK)
+               _return_value_to_caller(job->req_id,
+                               g_variant_new("(i)", PKGMGR_R_OK));
+       else
+               _return_value_to_caller(job->req_id,
+                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+
+       pkgmgrinfo_updateinfo_destroy(job->extra_data);
+       job->extra_data = NULL;
+
+       return ret;
+}
+
+static int __process_unregister_pkg_update_info(struct backend_job *job)
+{
+       int ret = pkgmgr_parser_unregister_pkg_update_info_in_usr_db
+                       (job->pkgid, job->target_uid);
+
+       if (ret == PMINFO_R_OK)
+               _return_value_to_caller(job->req_id,
+                               g_variant_new("(i)", PKGMGR_R_OK));
+       else
+               _return_value_to_caller(job->req_id,
+                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+       return ret;
+}
+
+static int __process_unregister_all_pkg_update_info(struct backend_job *job)
+{
+       int ret = pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(
+                       job->target_uid);
+
+       if (ret != PMINFO_R_OK) {
+               _return_value_to_caller(job->req_id,
+                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+               return ret;
+       }
+
+       if (__is_admin_user(job->caller_uid)) {
+               ret = pkgmgr_parser_unregister_all_pkg_update_info_in_usr_db(
+                               GLOBAL_USER);
+               if (ret != PMINFO_R_OK) {
+                       _return_value_to_caller(job->req_id,
+                                       g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+                       return ret;
+               }
+       }
+       _return_value_to_caller(job->req_id,
+                       g_variant_new("(i)", PKGMGR_R_OK));
+
+       return ret;
+}
+
 static int __process_enable_app(struct backend_job *job)
 {
        int ret = -1;
@@ -1574,6 +1639,18 @@ gboolean queue_job(void *data)
                        _send_fail_signal(job);
                __post_process(ret, x, job);
                break;
+       case REQUEST_TYPE_REGISTER_PKG_UPDATE_INFO:
+               ret = __process_register_pkg_update_info(job);
+               _free_backend_job(job);
+               break;
+       case REQUEST_TYPE_UNREGISTER_PKG_UPDATE_INFO:
+               ret = __process_unregister_pkg_update_info(job);
+               _free_backend_job(job);
+               break;
+       case REQUEST_TYPE_UNREGISTER_ALL_PKG_UPDATE_INFO:
+               ret = __process_unregister_all_pkg_update_info(job);
+               _free_backend_job(job);
+               break;
        case REQUEST_TYPE_ENABLE_APP:
                ret = __process_enable_app(job);
                _free_backend_job(job);
index 13617ab..e70e774 100644 (file)
@@ -86,7 +86,7 @@ struct backend_job *_pop_queue(int pos)
 
 int _push_queue(uid_t target_uid, uid_t caller_uid, const char *req_id,
                int req_type, const char *queue_type, const char *pkgid,
-               const char *args)
+               const char *args, void *extra_data)
 {
        struct backend_queue *queue;
        struct backend_job *job;
@@ -112,6 +112,8 @@ int _push_queue(uid_t target_uid, uid_t caller_uid, const char *req_id,
        job->backend_slot = queue->slot;
        job->backend_type = queue->type;
        job->backend_path = queue->path;
+       if (extra_data)
+               job->extra_data = extra_data;
 
        queue->job_list = g_list_append(queue->job_list, (gpointer)job);
 
@@ -185,6 +187,8 @@ void _free_backend_job(struct backend_job *job)
        free(job->pkgid);
        free(job->appid);
        free(job->args);
+       if (job->extra_data)
+               free(job->extra_data);
        free(job);
 }
 
index e625e2b..f1993ca 100644 (file)
@@ -4,15 +4,12 @@
 
 #include <glib.h>
 #include <gio/gio.h>
-#include <gum/gum-user.h>
-#include <gum/common/gum-user-types.h>
 
 #include "queue.h"
+#include "pkgmgr-info.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"
 
@@ -66,6 +63,22 @@ static const char instropection_xml[] =
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
+       "    <method name='register_pkg_update_info'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='pkgid' direction='in'/>"
+       "      <arg type='s' name='version' direction='in'/>"
+       "      <arg type='i' name='type' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "    </method>"
+       "    <method name='unregister_pkg_update_info'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='s' name='pkgid' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "    </method>"
+       "    <method name='unregister_all_pkg_update_info'>"
+       "      <arg type='u' name='uid' direction='in'/>"
+       "      <arg type='i' name='ret' direction='out'/>"
+       "    </method>"
        "    <method name='enable_app'>"
        "      <arg type='u' name='uid' direction='in'/>"
        "      <arg type='s' name='appid' direction='in'/>"
@@ -222,43 +235,6 @@ static char *__generate_reqkey(const char *pkgid)
        return str_req_key;
 }
 
-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)
 {
@@ -368,7 +344,7 @@ static int __handle_request_install(uid_t caller_uid,
        }
 
        if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_INSTALL,
-                               pkgtype, pkgpath, args)) {
+                               pkgtype, pkgpath, args, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -463,7 +439,7 @@ static int __handle_request_mount_install(uid_t caller_uid,
 
        if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_MOUNT_INSTALL,
-                               pkgtype, pkgpath, args)) {
+                               pkgtype, pkgpath, args, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -517,7 +493,7 @@ static int __handle_request_reinstall(uid_t caller_uid,
                return -1;
        }
        if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_REINSTALL,
-                               pkgtype, pkgid, NULL)) {
+                               pkgtype, pkgid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
@@ -563,7 +539,7 @@ static int __handle_request_uninstall(uid_t caller_uid,
                return -1;
        }
        if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_UNINSTALL,
-                               pkgtype, pkgid, NULL)) {
+                               pkgtype, pkgid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
@@ -613,7 +589,7 @@ static int __handle_request_move(uid_t caller_uid,
 
        snprintf(buf, sizeof(buf), "%d", move_type);
        if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_MOVE,
-                               pkgtype, pkgid, buf)) {
+                               pkgtype, pkgid, buf, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
@@ -663,7 +639,7 @@ static int __handle_request_enable_pkgs(uid_t caller_uid,
                }
                if (_push_queue(target_uid, caller_uid, reqkey,
                                        REQUEST_TYPE_ENABLE_PKG,
-                                       pkgtype, pkgid, NULL)) {
+                                       pkgtype, pkgid, NULL, NULL)) {
                        g_dbus_method_invocation_return_value(invocation,
                                        g_variant_new("(is)",
                                                PKGMGR_R_ESYSTEM, ""));
@@ -681,6 +657,207 @@ static int __handle_request_enable_pkgs(uid_t caller_uid,
        return 0;
 }
 
+static int __convert_updateinfo_type(const char *type, pkgmgrinfo_updateinfo_update_type *converted_type)
+{
+       if (type == NULL || converted_type == NULL)
+               return -1;
+
+       if (strncmp(type, PMINFO_UPDATEINFO_TYPE_NONE, strlen(PMINFO_UPDATEINFO_TYPE_NONE)) == 0)
+               *converted_type = PMINFO_UPDATEINFO_NONE;
+       else if (strncmp(type, PMINFO_UPDATEINFO_TYPE_FORCE, strlen(PMINFO_UPDATEINFO_TYPE_FORCE)) == 0)
+               *converted_type = PMINFO_UPDATEINFO_FORCE;
+       else if (strncmp(type, PMINFO_UPDATEINFO_TYPE_OPTIONAL, strlen(PMINFO_UPDATEINFO_TYPE_OPTIONAL)) == 0)
+               *converted_type = PMINFO_UPDATEINFO_OPTIONAL;
+       else
+               return -1;
+       return 0;
+}
+
+static int __handle_request_register_pkg_update_info(
+               uid_t caller_uid, GDBusMethodInvocation *invocation,
+               GVariant *parameters)
+{
+       char *reqkey;
+       char buf[MAX_PKG_ARGS_LEN];
+       int ret;
+       pkgmgrinfo_pkginfo_h pkg_info;
+       bool is_global_pkg;
+       pkgmgrinfo_updateinfo_h update_info;
+       pkgmgrinfo_updateinfo_update_type converted_type;
+       uid_t target_uid = (uid_t)-1;
+       gchar *pkgid = NULL;
+       gchar *version = NULL;
+
+       g_variant_get(parameters, "(ussi)", &target_uid, &pkgid, &version, &converted_type);
+
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, target_uid, &pkg_info);
+       if (ret != PMINFO_R_OK) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_EIO));
+               return -1;
+       }
+       ret = pkgmgrinfo_pkginfo_is_global(pkg_info, &is_global_pkg);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_EIO));
+               return -1;
+       }
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
+
+       /* return error if given pkg is global pkg but caller is not admin */
+       if (caller_uid >= REGULAR_USER && is_global_pkg
+                       && !__is_admin_user(caller_uid)) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_EPRIV));
+               return -1;
+       }
+
+       ret = pkgmgrinfo_updateinfo_create(&update_info);
+       if (ret != PMINFO_R_OK) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               return -1;
+       }
+
+       ret = pkgmgrinfo_updateinfo_set_pkgid(update_info, (char *)pkgid);
+       if (ret != PMINFO_R_OK) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               return -1;
+       }
+
+       ret = pkgmgrinfo_updateinfo_set_version(update_info, (char *)version);
+       if (ret != PMINFO_R_OK) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               return -1;
+       }
+
+       ret = pkgmgrinfo_updateinfo_set_type(update_info, converted_type);
+       if (ret != PMINFO_R_OK) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey("register_pkg_update_info");
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               return -1;
+       }
+
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                       REQUEST_TYPE_REGISTER_PKG_UPDATE_INFO, "default",
+                       NULL, buf, update_info))
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+
+       if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+                               (gpointer)invocation))
+               ERR("reqkey already exists");
+
+       return 0;
+}
+
+static int __handle_request_unregister_pkg_update_info(
+               uid_t caller_uid, GDBusMethodInvocation *invocation,
+               GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *pkgid = NULL;
+       char *reqkey;
+       pkgmgrinfo_pkginfo_h pkg_info;
+       bool is_global_pkg;
+       int ret;
+
+       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;
+       }
+
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, target_uid, &pkg_info);
+       if (ret != PMINFO_R_OK) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_EIO));
+               return -1;
+       }
+       ret = pkgmgrinfo_pkginfo_is_global(pkg_info, &is_global_pkg);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_EIO));
+               return -1;
+       }
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_info);
+
+       /* return error if given pkg is global pkg but caller is not admin */
+       if (caller_uid >= REGULAR_USER && is_global_pkg
+                       && !__is_admin_user(caller_uid)) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_EPRIV));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey("unregister_pkg_update_info");
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ENOMEM));
+               return -1;
+       }
+
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                       REQUEST_TYPE_UNREGISTER_PKG_UPDATE_INFO, "default",
+                       pkgid, NULL, NULL))
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(i)", PKGMGR_R_ESYSTEM));
+
+       if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+                               (gpointer)invocation))
+               ERR("reqkey already exists");
+
+
+       return 0;
+
+}
+
+static int __handle_request_unregister_all_pkg_update_info(
+               uid_t caller_uid, GDBusMethodInvocation *invocation,
+               GVariant *parameters)
+{
+       uid_t target_uid = (uid_t)-1;
+       char *reqkey;
+
+       g_variant_get(parameters, "(u)", &target_uid);
+       if (target_uid == (uid_t)-1) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ECOMM, ""));
+               return -1;
+       }
+
+       reqkey = __generate_reqkey("unregister_all_pkg_update_info");
+       if (reqkey == NULL) {
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ENOMEM, ""));
+               return -1;
+       }
+
+       if (_push_queue(target_uid, caller_uid, reqkey,
+                       REQUEST_TYPE_UNREGISTER_ALL_PKG_UPDATE_INFO, "default",
+                       NULL, NULL, NULL))
+               g_dbus_method_invocation_return_value(invocation,
+                               g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
+
+       if (!g_hash_table_insert(req_table, (gpointer)reqkey,
+                               (gpointer)invocation))
+               ERR("reqkey already exists");
+
+       return 0;
+}
+
 static int __handle_request_disable_pkgs(uid_t caller_uid,
                GDBusMethodInvocation *invocation, GVariant *parameters)
 {
@@ -715,7 +892,7 @@ static int __handle_request_disable_pkgs(uid_t caller_uid,
                }
                if (_push_queue(target_uid, caller_uid, reqkey,
                                        REQUEST_TYPE_DISABLE_PKG,
-                                       pkgtype, pkgid, NULL)) {
+                                       pkgtype, pkgid, NULL, NULL)) {
                        g_dbus_method_invocation_return_value(invocation,
                                        g_variant_new("(is)",
                                                PKGMGR_R_ESYSTEM, ""));
@@ -759,7 +936,7 @@ static int __handle_request_enable_apps(uid_t caller_uid,
        while (g_variant_iter_next(iter, "&s", &appid)) {
                if (_push_queue(target_uid, caller_uid, reqkey,
                                        REQUEST_TYPE_ENABLE_APP,
-                                       "default", appid, buf)) {
+                                       "default", appid, buf, NULL)) {
                        g_dbus_method_invocation_return_value(invocation,
                                        g_variant_new("(is)",
                                                PKGMGR_R_ESYSTEM, ""));
@@ -801,7 +978,7 @@ static int __handle_request_disable_apps(uid_t caller_uid,
        while (g_variant_iter_next(iter, "&s", &appid)) {
                if (_push_queue(target_uid, caller_uid, reqkey,
                                        REQUEST_TYPE_DISABLE_APP,
-                                       "default", appid, buf)) {
+                                       "default", appid, buf, NULL)) {
                        g_dbus_method_invocation_return_value(invocation,
                                        g_variant_new("(is)",
                                                PKGMGR_R_ESYSTEM, ""));
@@ -843,7 +1020,7 @@ static int __handle_request_enable_app(uid_t caller_uid,
 
        if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_ENABLE_APP, "default",
-                               appid, NULL)) {
+                               appid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -887,7 +1064,7 @@ static int __handle_request_disable_app(uid_t caller_uid,
 
        if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_DISABLE_APP, "default",
-                               appid, NULL)) {
+                               appid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -931,7 +1108,7 @@ static int __handle_request_enable_global_app_for_uid(uid_t caller_uid,
 
        if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID,
-                               "default", appid, NULL)) {
+                               "default", appid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -975,7 +1152,7 @@ static int __handle_request_disable_global_app_for_uid(uid_t caller_uid,
 
        if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID,
-                               "default", appid, NULL)) {
+                               "default", appid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                ret = -1;
@@ -1019,7 +1196,7 @@ static int __handle_request_getsize(uid_t caller_uid,
 
        snprintf(buf, sizeof(buf), "%d", get_type);
        if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_GETSIZE,
-                               "pkgtool", pkgid, buf)) {
+                               "pkgtool", pkgid, buf, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
@@ -1058,7 +1235,7 @@ static int __handle_request_getsize_sync(uid_t caller_uid,
 
        snprintf(buf, sizeof(buf), "%d", get_type);
        if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_GETSIZE_SYNC,
-                               "pkgtool", pkgid, buf)) {
+                               "pkgtool", pkgid, buf, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(is)", PKGMGR_R_ESYSTEM, ""));
                free(reqkey);
@@ -1094,7 +1271,7 @@ static int __handle_request_cleardata(uid_t caller_uid,
        }
 
        if (_push_queue(target_uid, caller_uid, NULL, REQUEST_TYPE_CLEARDATA,
-                               pkgtype, pkgid, NULL)) {
+                               pkgtype, pkgid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(pkgtype);
@@ -1133,7 +1310,7 @@ static int __handle_request_clearcache(uid_t caller_uid,
        }
 
        if (_push_queue(target_uid, caller_uid, NULL, REQUEST_TYPE_CLEARCACHE,
-                               pkgtype,  pkgid, NULL)) {
+                               pkgtype,  pkgid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(pkgtype);
@@ -1169,7 +1346,7 @@ static int __handle_request_kill(uid_t caller_uid,
        }
 
        if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_KILL,
-                               "default", pkgid, NULL)) {
+                               "default", pkgid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0));
                free(reqkey);
@@ -1205,7 +1382,7 @@ static int __handle_request_check(uid_t caller_uid,
        }
 
        if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_CHECK,
-                               "default", pkgid, NULL)) {
+                               "default", pkgid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0));
                free(reqkey);
@@ -1242,7 +1419,7 @@ static int __handle_request_generate_license_request(uid_t caller_uid,
 
        if (_push_queue(caller_uid, caller_uid, reqkey,
                                REQUEST_TYPE_GENERATE_LICENSE_REQUEST,
-                               "default", NULL, resp_data)) {
+                               "default", NULL, resp_data, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(iss)", PKGMGR_R_ESYSTEM, "",
                                        ""));
@@ -1279,7 +1456,7 @@ static int __handle_request_register_license(uid_t caller_uid,
 
        if (_push_queue(caller_uid, caller_uid, reqkey,
                                REQUEST_TYPE_REGISTER_LICENSE,
-                               "default", NULL, resp_data)) {
+                               "default", NULL, resp_data, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1318,7 +1495,7 @@ static int __handle_request_decrypt_package(uid_t caller_uid,
        if (_push_queue(caller_uid, caller_uid, reqkey,
                                REQUEST_TYPE_DECRYPT_PACKAGE,
                                "default", drm_file_path,
-                               decrypted_file_path)) {
+                               decrypted_file_path, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1357,7 +1534,7 @@ static int __update_app_splash_screen(uid_t caller_uid,
        }
 
        if (_push_queue(target_uid, caller_uid, reqkey, req_type, "default",
-                               appid, NULL)) {
+                               appid, NULL, NULL)) {
                ERR("Failed to push request");
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
@@ -1414,7 +1591,7 @@ static int __handle_request_set_restriction_mode(uid_t caller_uid,
        snprintf(buf, sizeof(buf), "%d", mode);
        if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_SET_RESTRICTION_MODE,
-                               "default", pkgid, buf)) {
+                               "default", pkgid, buf, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1454,7 +1631,7 @@ static int __handle_request_unset_restriction_mode(uid_t caller_uid,
        snprintf(buf, sizeof(buf), "%d", mode);
        if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_UNSET_RESTRICTION_MODE,
-                               "default", pkgid, buf)) {
+                               "default", pkgid, buf, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1491,7 +1668,7 @@ static int __handle_request_get_restriction_mode(uid_t caller_uid,
 
        if (_push_queue(target_uid, caller_uid, reqkey,
                                REQUEST_TYPE_GET_RESTRICTION_MODE,
-                               "default", pkgid, NULL)) {
+                               "default", pkgid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(ii)", -1, PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1529,7 +1706,7 @@ static int __handle_request_set_app_label(uid_t uid,
 
        if (_push_queue(target_uid, uid, reqkey,
                                REQUEST_TYPE_SET_APP_LABEL,
-                               "default", appid, label)) {
+                               "default", appid, label, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1575,7 +1752,7 @@ static int __handle_request_migrate_external_image(uid_t uid,
 
        if (_push_queue(target_uid, uid, reqkey,
                                REQUEST_TYPE_MIGRATE_EXTERNAL_IMAGE,
-                               pkgtype, pkgid, NULL)) {
+                               pkgtype, pkgid, NULL, NULL)) {
                g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", PKGMGR_R_ESYSTEM));
                free(reqkey);
@@ -1649,6 +1826,12 @@ static void __handle_method_call(GDBusConnection *connection,
                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, "register_pkg_update_info") == 0)
+               ret = __handle_request_register_pkg_update_info(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "unregister_pkg_update_info") == 0)
+               ret = __handle_request_unregister_pkg_update_info(uid, invocation, parameters);
+       else if (g_strcmp0(method_name, "unregister_all_pkg_update_info") == 0)
+               ret = __handle_request_unregister_all_pkg_update_info(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)
index 97799ac..a480626 100644 (file)
@@ -1,6 +1,8 @@
 #include <stdlib.h>
 #include <sys/types.h>
 
+#include <gum/gum-user.h>
+#include <gum/common/gum-user-types.h>
 #include <unzip.h>
 
 #include <tzplatform_config.h>
@@ -8,6 +10,9 @@
 
 #include "pkgmgr-server.h"
 
+#define RETRY_MAX 5
+#define RETRY_WAIT_USEC (1000000 / 2) /* 0.5 sec */
+
 struct manifest_and_type {
        const char *manifest;
        const char *type;
@@ -89,3 +94,40 @@ const char *_get_adjusted_pkgpath(const char *org_file_path, uid_t caller_uid)
 
        return file_path;
 }
+
+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;
+}