1 // Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/utils/manifest_util.h"
7 #include <manifest_parser/utils/logging.h>
8 #include <pkgmgr/pkgmgr_parser.h>
9 #include <pkgmgr-info.h>
10 #include <tzplatform_config.h>
12 #include <boost/filesystem/path.hpp>
15 #include "common/pkgmgr_query.h"
17 namespace bf = boost::filesystem;
21 int PkgmgrAppInfoCallback(const pkgmgrinfo_appinfo_h handle,
23 manifest_x* mfx = static_cast<manifest_x*>(user_data);
25 char* app_id = nullptr;
26 if (pkgmgrinfo_appinfo_get_appid(handle, &app_id))
27 return PMINFO_R_ERROR;
29 char* icon_text = nullptr;
30 if (pkgmgrinfo_appinfo_get_icon(handle, &icon_text))
31 LOG(INFO) << "No Icon for " << app_id;
33 if (!mfx->root_path) {
34 char *root_path = nullptr;
35 if (pkgmgrinfo_appinfo_get_root_path(handle, &root_path))
36 return PMINFO_R_ERROR;
37 mfx->root_path = strdup(root_path);
40 application_x* application =
41 static_cast<application_x*>(calloc(1, sizeof(application_x)));
43 return PMINFO_R_ERROR;
46 icon_x* icon = static_cast<icon_x*>(calloc(1, sizeof(icon_x)));
49 return PMINFO_R_ERROR;
51 icon->text = strdup(icon_text);
52 application->icon = g_list_append(application->icon, icon);
54 application->appid = strdup(app_id);
55 mfx->application = g_list_append(mfx->application, application);
62 namespace common_installer {
64 bf::path GetManifestLocation(const std::string& pkgid,
67 if (QueryIsGlobalPackage(pkgid.c_str(), uid)) {
68 uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
69 is_readonly = QueryIsReadonlyPackage(pkgid.c_str(), uid);
71 bf::path xml_path = bf::path(getUserManifestPath(uid, is_readonly))
72 / bf::path(pkgid.c_str());
78 int PkgmgrGenerateManifestInfoFromDB(manifest_x* mfx,
79 const std::string &pkgid,
81 pkgmgrinfo_appinfo_filter_h filter;
82 mfx->package = strdup(pkgid.c_str());
84 if (pkgmgrinfo_appinfo_filter_create(&filter))
85 return PMINFO_R_ERROR;
87 if (pkgmgrinfo_appinfo_filter_add_string(filter,
88 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid.c_str())) {
89 pkgmgrinfo_appinfo_filter_destroy(filter);
90 return PMINFO_R_ERROR;
93 if (pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(filter,
94 PkgmgrAppInfoCallback,
96 pkgmgrinfo_appinfo_filter_destroy(filter);
97 return PMINFO_R_ERROR;
100 pkgmgrinfo_appinfo_filter_destroy(filter);
105 } // namespace common_installer