From 81356499dbdc2a31c9ca777d2d2cf5e293458b81 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 28 Jan 2016 19:58:20 +0900 Subject: [PATCH] Implement app signal related with app disable/enable Changes applied at [pkgmgr-tool][pkgmgr-info][slp-pkgmgr][pkgmgr-server] Change-Id: I66521744e30a20da8c67135cef16da92dea2d41c Signed-off-by: Junghyun Yeon --- include/pkgmgr-server.h | 11 ++-- src/pkgmgr-server.c | 162 ++++++++++++++++++++++++++++++++++++++++++----- src/request.c | 164 +++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 295 insertions(+), 42 deletions(-) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 3b0c874..d4cadde 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -49,13 +49,15 @@ enum request_type { PKGMGR_REQUEST_TYPE_REINSTALL, PKGMGR_REQUEST_TYPE_UNINSTALL, PKGMGR_REQUEST_TYPE_MOVE, - PKGMGR_REQUEST_TYPE_ENABLE, - PKGMGR_REQUEST_TYPE_DISABLE, + PKGMGR_REQUEST_TYPE_ENABLE_PKG, + PKGMGR_REQUEST_TYPE_DISABLE_PKG, + PKGMGR_REQUEST_TYPE_ENABLE_APP, + PKGMGR_REQUEST_TYPE_DISABLE_APP, PKGMGR_REQUEST_TYPE_GETSIZE, PKGMGR_REQUEST_TYPE_CLEARDATA, PKGMGR_REQUEST_TYPE_CLEARCACHE, - PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP, - PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP, + PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, + PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, PKGMGR_REQUEST_TYPE_KILL, PKGMGR_REQUEST_TYPE_CHECK, PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST, @@ -72,6 +74,7 @@ typedef struct { uid_t uid; char pkg_type[MAX_PKG_TYPE_LEN]; char pkgid[MAX_PKG_NAME_LEN]; + char appid[MAX_PKG_NAME_LEN]; char args[MAX_PKG_ARGS_LEN]; } pm_dbus_msg; diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 1cf0ef5..230862a 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -203,6 +203,30 @@ static void __unset_recovery_mode(uid_t uid, char *pkgid, char *pkg_type) DBG("remove recovery_file[%s] fail\n", recovery_file); } +static void __send_app_signal(uid_t uid, const char *req_id, + const char *pkg_type, const char *pkgid, const char *appid, + const char *key, const char *val) +{ + pkgmgr_installer *pi; + + pi = pkgmgr_installer_new(); + if (!pi) { + DBG("Failure in creating the pkgmgr_installer object"); + return; + } + + if (pkgmgr_installer_set_request_type(pi,PKGMGR_REQ_ENABLE_DISABLE_APP)) + goto catch; + if (pkgmgr_installer_set_session_id(pi, req_id)) + goto catch; + pkgmgr_installer_send_app_signal(pi, pkg_type, pkgid, appid, key, val); + +catch: + pkgmgr_installer_free(pi); + + return; +} + static void send_fail_signal(char *pname, char *ptype, char *args) { DBG("send_fail_signal start\n"); @@ -705,6 +729,29 @@ static int __fork_and_exec_with_args(char **argv, uid_t uid) return pid; } +void __change_item_info(pm_dbus_msg *item, uid_t uid) +{ + int ret = 0; + char *pkgid = NULL; + pkgmgrinfo_appinfo_h handle = NULL; + + ret = pkgmgrinfo_appinfo_get_usr_appinfo(item->pkgid, uid, &handle); + if (ret != PMINFO_R_OK) + return; + + ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_destroy_appinfo(handle); + return; + } + + strncpy(item->appid, item->pkgid, sizeof(item->pkgid) - 1); + memset((item->pkgid),0,MAX_PKG_NAME_LEN); + strncpy(item->pkgid, pkgid, sizeof(item->pkgid) - 1); + + pkgmgrinfo_appinfo_destroy_appinfo(handle); +} + static int __process_install(pm_dbus_msg *item) { char *backend_cmd; @@ -798,28 +845,104 @@ static int __process_move(pm_dbus_msg *item) return pid; } -static int __process_enable(pm_dbus_msg *item) +static int __process_enable_pkg(pm_dbus_msg *item) { /* TODO */ return 0; } -static int __process_disable(pm_dbus_msg *item) +static int __process_disable_pkg(pm_dbus_msg *item) { /* TODO */ return 0; } -static int __process_enable_global_app(pm_dbus_msg *item) +static int __process_enable_app(pm_dbus_msg *item) { - pkgmgr_parser_update_global_app_disable_info_in_db(item->pkgid, item->uid, 0); - return 0; + int ret = -1; + + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, "start", "enable_app"); + + /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ + __change_item_info(item, item->uid); + if (strlen(item->appid) == 0) { + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, "end", "fail"); + return ret; + } + + ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 0); + if (ret != PMINFO_R_OK) + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->appid, "end", "fail"); + else + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->appid, "end", "ok"); + + return ret; } -static int __process_disable_global_app(pm_dbus_msg *item) +static int __process_disable_app(pm_dbus_msg *item) { - pkgmgr_parser_update_global_app_disable_info_in_db(item->pkgid, item->uid, 1); - return 0; + int ret = -1; + + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, "start", "disable_app"); + + /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ + __change_item_info(item, item->uid); + if (strlen(item->appid) == 0) { + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, "end", "fail"); + return ret; + } + + ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 1); + if (ret != PMINFO_R_OK) + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->appid, "end", "fail"); + else + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->appid, "end", "ok"); + + return ret; +} + +static int __process_enable_global_app_for_uid(pm_dbus_msg *item) +{ + int ret = -1; + + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, "start", "enable_global_app_for_uid"); + + /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ + __change_item_info(item, GLOBAL_USER); + if (strlen(item->appid) == 0) { + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, "end", "fail"); + return ret; + } + + ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 0); + if (ret != PMINFO_R_OK) + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->appid, "end", "fail"); + else + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->appid, "end", "ok"); + + return ret; +} + +static int __process_disable_global_app_for_uid(pm_dbus_msg *item) +{ + int ret = -1; + + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, "start", "disable_global_app_for_uid"); + + /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ + __change_item_info(item, GLOBAL_USER); + if (strlen(item->appid) == 0) { + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, "end", "fail"); + return ret; + } + + ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 1); + if (ret != PMINFO_R_OK) + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->appid, "end", "fail"); + else + __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->appid, "end", "ok"); + + return ret; } static int __process_getsize(pm_dbus_msg *item) @@ -1063,6 +1186,7 @@ gboolean queue_job(void *data) strncpy(ptr->pkgtype, item->pkg_type, MAX_PKG_TYPE_LEN-1); strncpy(ptr->pkgid, item->pkgid, MAX_PKG_NAME_LEN-1); strncpy(ptr->args, item->args, MAX_PKG_ARGS_LEN-1); + memset((item->appid),0,MAX_PKG_NAME_LEN); ptr->uid = item->uid; DBG("handle request type [%d]", ptr->pid, item->req_type); @@ -1087,11 +1211,17 @@ gboolean queue_job(void *data) __set_recovery_mode(item->uid, item->pkgid, item->pkg_type); ret = __process_move(item); break; - case PKGMGR_REQUEST_TYPE_ENABLE: - ret = __process_enable(item); + case PKGMGR_REQUEST_TYPE_ENABLE_PKG: + ret = __process_enable_pkg(item); + break; + case PKGMGR_REQUEST_TYPE_DISABLE_PKG: + ret = __process_disable_pkg(item); + break; + case PKGMGR_REQUEST_TYPE_ENABLE_APP: + ret = __process_enable_app(item); break; - case PKGMGR_REQUEST_TYPE_DISABLE: - ret = __process_disable(item); + case PKGMGR_REQUEST_TYPE_DISABLE_APP: + ret = __process_disable_app(item); break; case PKGMGR_REQUEST_TYPE_GETSIZE: __set_backend_busy(x); @@ -1105,11 +1235,11 @@ gboolean queue_job(void *data) __set_backend_busy(x); ret = __process_clearcache(item); break; - case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP: - ret = __process_enable_global_app(item); + case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: + ret = __process_enable_global_app_for_uid(item); break; - case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP: - ret = __process_disable_global_app(item); + case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: + ret = __process_disable_global_app_for_uid(item); break; case PKGMGR_REQUEST_TYPE_KILL: ret = __process_kill(item); diff --git a/src/request.c b/src/request.c index ba79911..8968807 100644 --- a/src/request.c +++ b/src/request.c @@ -56,21 +56,25 @@ static const char instropection_xml[] = " " " " " " + " " " " " " " " " " " " + " " " " - " " + " " " " " " " " + " " " " - " " + " " " " " " " " + " " " " " " " " @@ -337,7 +341,7 @@ static int __handle_request_move(uid_t uid, return 0; } -static int __handle_request_enable(uid_t uid, +static int __handle_request_enable_pkg(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -350,7 +354,7 @@ static int __handle_request_enable(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_ENABLE, "none", + if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_ENABLE_PKG, "pkg", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -363,7 +367,7 @@ static int __handle_request_enable(uid_t uid, return 0; } -static int __handle_request_disable(uid_t uid, +static int __handle_request_disable_pkg(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -376,7 +380,7 @@ static int __handle_request_disable(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_DISABLE, "none", + if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_DISABLE_PKG, "pkg", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -389,11 +393,13 @@ static int __handle_request_disable(uid_t uid, return 0; } -static int __handle_request_enable_global_app(uid_t uid, +static int __handle_request_enable_app(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; char *appid = NULL; + char *reqkey = NULL; + int ret = -1; g_variant_get(parameters, "(u&s)", &target_uid, &appid); if (target_uid == (uid_t)-1 || appid == NULL) { @@ -402,24 +408,80 @@ static int __handle_request_enable_global_app(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP, "none", + reqkey = __generate_reqkey(appid); + if (reqkey == NULL) { + ret = -1; + goto catch; + } + + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_APP, "app", appid, "")) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + 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); + + return ret; +} + +static int __handle_request_disable_app(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + uid_t target_uid = (uid_t)-1; + char *appid = NULL; + char *reqkey = NULL; + int ret = -1; + + g_variant_get(parameters, "(u&s)", &target_uid, &appid); + if (target_uid == (uid_t)-1 || appid == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ECOMM)); return -1; } + reqkey = __generate_reqkey(appid); + if (reqkey == NULL) { + ret = -1; + goto catch; + } + + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_APP, "app", + appid, "")) { + 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("(i)", PKGMGR_R_OK)); + g_variant_new("(is)", PKGMGR_R_OK, reqkey)); - return 0; + ret = 0; + +catch: + if (reqkey) + free(reqkey); + + return ret; } -static int __handle_request_disable_global_app(uid_t uid, +static int __handle_request_enable_global_app_for_uid(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; char *appid = NULL; + char *reqkey = NULL; + int ret = -1; g_variant_get(parameters, "(u&s)", &target_uid, &appid); if (target_uid == (uid_t)-1 || appid == NULL) { @@ -428,17 +490,71 @@ static int __handle_request_disable_global_app(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP, "none", + reqkey = __generate_reqkey(appid); + if (reqkey == NULL) { + ret = -1; + goto catch; + } + + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, "app", appid, "")) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + 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); + + return ret; +} + +static int __handle_request_disable_global_app_for_uid(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + uid_t target_uid = (uid_t)-1; + char *appid = NULL; + char *reqkey = NULL; + int ret = -1; + + g_variant_get(parameters, "(u&s)", &target_uid, &appid); + if (target_uid == (uid_t)-1 || appid == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ECOMM)); return -1; } + reqkey = __generate_reqkey(appid); + if (reqkey == NULL) { + ret = -1; + goto catch; + } + + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, "app", + appid, "")) { + 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("(i)", PKGMGR_R_OK)); + g_variant_new("(is)", PKGMGR_R_OK, reqkey)); - return 0; + ret = 0; + +catch: + if (reqkey) + free(reqkey); + + return ret; } static int __handle_request_getsize(uid_t uid, @@ -847,17 +963,21 @@ static void __handle_method_call(GDBusConnection *connection, 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(uid, invocation, parameters); + ret = __handle_request_enable_pkg(uid, invocation, parameters); else if (g_strcmp0(method_name, "disable") == 0) - ret = __handle_request_disable(uid, invocation, parameters); + ret = __handle_request_disable_pkg(uid, invocation, parameters); else if (g_strcmp0(method_name, "getsize") == 0) ret = __handle_request_getsize(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_global_app") == 0) - ret = __handle_request_enable_global_app(uid, invocation, parameters); - else if (g_strcmp0(method_name, "disable_global_app") == 0) - ret = __handle_request_disable_global_app(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_global_app_for_uid") == 0) + 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); else if (g_strcmp0(method_name, "kill") == 0) ret = __handle_request_kill(uid, invocation, parameters); else if (g_strcmp0(method_name, "check") == 0) -- 2.7.4