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/utils/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 PkgQueryInterface pkg_query(pkgid, uid);
68 if (pkg_query.IsGlobalPackage()) {
69 uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
70 is_readonly = pkg_query.IsReadonlyPackage();
72 bf::path xml_path = bf::path(getUserManifestPath(uid, is_readonly))
73 / bf::path(pkgid.c_str());
79 manifest_x* PkgmgrGenerateManifestInfoFromDB(const std::string &pkgid,
81 pkgmgrinfo_appinfo_filter_h filter;
82 if (pkgmgrinfo_appinfo_filter_create(&filter))
85 if (pkgmgrinfo_appinfo_filter_add_string(filter,
86 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid.c_str())) {
87 pkgmgrinfo_appinfo_filter_destroy(filter);
91 manifest_x* mfx = static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
93 pkgmgrinfo_appinfo_filter_destroy(filter);
94 LOG(ERROR) << "Out of memory";
97 if (pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(filter,
98 PkgmgrAppInfoCallback,
100 pkgmgr_parser_free_manifest_xml(mfx);
101 pkgmgrinfo_appinfo_filter_destroy(filter);
104 mfx->package = strdup(pkgid.c_str());
106 pkgmgrinfo_appinfo_filter_destroy(filter);
111 } // namespace common_installer