From 27eea18df5432997bbad39205ebc9e66654654e5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 10 Apr 2023 23:12:38 +0000 Subject: [PATCH] Modify app_info_create() function Before getting the appid by the alias appid, thie patch retrieves the app's own appid. IF the appids match, it optimizes performance by reducing IPC. Change-Id: I662780a14b5b8c0a96ea1bda1e76727410712f38 Signed-off-by: Hwankyu Jhun --- src/app_info.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/src/app_info.c b/src/app_info.c index e5177be..d5d6327 100644 --- a/src/app_info.c +++ b/src/app_info.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "app_info.h" @@ -39,6 +40,9 @@ #define SMACK_LABEL_LEN 255 +#undef REGULAR_UID_MIN +#define REGULAR_UID_MIN 5000 + struct app_info_s { char *app_id; pkgmgrinfo_appinfo_h pkg_app_info; @@ -72,6 +76,13 @@ typedef struct _foreach_res_control_ { void *user_data; } foreach_res_control_context_s; +typedef struct app_context_s { + char appid[256]; + bool initialized; +} app_context_t; + +static app_context_t __context; + static int app_info_convert_str_property(const char *property, char **converted_property) { if (property == NULL) @@ -347,6 +358,50 @@ out: return ret; } +static void __app_context_initialize(void) +{ + if (__context.initialized) + return; + + if (getuid() < REGULAR_UID_MIN) { + __context.initialized = true; + return; + } + + aul_app_get_appid_bypid(getpid(), __context.appid, + sizeof(__context.appid)); + __context.initialized = true; +} + +static int __app_info_create_by_alias_appid(const char *app_id, + app_info_h app_info) +{ + pkgmgrinfo_appinfo_h appinfo; + char *real_appid = NULL; + int ret; + + __app_context_initialize(); + if (__context.appid != NULL && !strcmp(__context.appid, app_id)) + return APP_MANAGER_ERROR_INVALID_PARAMETER; + + ret = aul_svc_get_appid_by_alias_appid(app_id, &real_appid); + if (ret != AUL_SVC_RET_OK || real_appid == NULL) + return APP_MANAGER_ERROR_INVALID_PARAMETER; + + /* LCOV_EXCL_START */ + ret = pkgmgrinfo_appinfo_get_usr_appinfo(real_appid, getuid(), + &appinfo); + free(real_appid); + if (ret != PMINFO_R_OK) + return APP_MANAGER_ERROR_INVALID_PARAMETER; + + app_info->app_id = strdup(app_id); + app_info->pkg_app_info = appinfo; + /* LCOV_EXCL_STOP */ + + return APP_MANAGER_ERROR_NONE; +} + API int app_info_create(const char *app_id, app_info_h *app_info) { pkgmgrinfo_pkginfo_h pkginfo = NULL; @@ -354,7 +409,6 @@ API int app_info_create(const char *app_id, app_info_h *app_info) app_info_h info = NULL; int retval = 0; char *main_appid = NULL; - char *real_appid = NULL; if (app_id == NULL || app_info == NULL) return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); @@ -363,20 +417,12 @@ API int app_info_create(const char *app_id, app_info_h *app_info) if (info == NULL) return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); /* LCOV_EXCL_LINE */ - if (aul_svc_get_appid_by_alias_appid(app_id, &real_appid) == - AUL_SVC_RET_OK && real_appid != NULL) { - /* LCOV_EXCL_START */ - retval = pkgmgrinfo_appinfo_get_usr_appinfo(real_appid, - getuid(), &appinfo); - free(real_appid); - if (!retval) { - info->app_id = strdup(app_id); - info->pkg_app_info = appinfo; - *app_info = info; - return APP_MANAGER_ERROR_NONE; - } - /* LCOV_EXCL_STOP */ + retval = __app_info_create_by_alias_appid(app_id, info); + if (retval == APP_MANAGER_ERROR_NONE) { + *app_info = info; + return APP_MANAGER_ERROR_NONE; } + retval = pkgmgrinfo_appinfo_get_usr_appinfo(app_id, getuid(), &appinfo); if (!retval) { info->app_id = strdup(app_id); -- 2.7.4