diff options
-rw-r--r-- | parser/widget_plugin_parser_db.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/parser/widget_plugin_parser_db.c b/parser/widget_plugin_parser_db.c index 2173b64..e186711 100644 --- a/parser/widget_plugin_parser_db.c +++ b/parser/widget_plugin_parser_db.c @@ -24,12 +24,15 @@ #include <dlog.h> #include <tzplatform_config.h> +#include <pkgmgr-info.h> #include <pkgmgr_installer_info.h> #include "widget_plugin_parser_internal.h" static int target_uid_initialized; static uid_t target_uid; +static int root_path_initialized; +static char root_path[PATH_MAX]; static uid_t __get_target_uid(void) { @@ -55,20 +58,32 @@ static int _bind_text(sqlite3_stmt *stmt, int idx, const char *text) static const char *_get_root_path(const char *pkgid) { - const char *path; + pkgmgrinfo_pkginfo_h pkginfo; + char *path = NULL; uid_t uid = __get_target_uid(); + int ret; + + if (root_path_initialized) + return root_path; + + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo); + if (ret != PMINFO_R_OK) { + LOGE("Failed to get pkginfo - %d(%s)", ret, pkgid); + return NULL; + } - if (uid == 0) { - path = tzplatform_mkpath(TZ_SYS_RO_APP, pkgid); - } else if (uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) { - path = tzplatform_mkpath(TZ_SYS_RW_APP, pkgid); - } else { - tzplatform_set_user(uid); - path = tzplatform_mkpath(TZ_USER_APP, pkgid); - tzplatform_reset_user(); + ret = pkgmgrinfo_pkginfo_get_root_path(pkginfo, &path); + if (ret != PMINFO_R_OK) { + LOGE("Failed to get root path - %d(%s)", ret, pkgid); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo); + return NULL; } - return path; + snprintf(root_path, sizeof(root_path), "%s", path); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo); + root_path_initialized = 1; + + return root_path; } static int _insert_support_size(sqlite3 *db, const char *pkgid, @@ -97,12 +112,13 @@ static int _insert_support_size(sqlite3 *db, const char *pkgid, _bind_text(stmt, idx++, classid); /* adjust preview image path */ if (size->preview != NULL) { - if (size->preview[0] == '/') + if (size->preview[0] == '/') { snprintf(buf, sizeof(buf), "%s", size->preview); - else + } else { snprintf(buf, sizeof(buf), "%s/shared/res/%s", _get_root_path(pkgid), size->preview); + } _bind_text(stmt, idx++, buf); } else { _bind_text(stmt, idx++, NULL); @@ -194,11 +210,12 @@ static int _insert_icon(sqlite3 *db, const char *pkgid, _bind_text(stmt, idx++, classid); _bind_text(stmt, idx++, icon->lang); /* adjust icon path */ - if (icon->icon[0] == '/') + if (icon->icon[0] == '/') { snprintf(buf, sizeof(buf), "%s", icon->icon); - else + } else { snprintf(buf, sizeof(buf), "%s/shared/res/%s", _get_root_path(pkgid), icon->icon); + } _bind_text(stmt, idx++, buf); ret = sqlite3_step(stmt); |