1 // Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "common/application_data.h"
7 #include <package_manager.h>
8 #include <manifest_parser/manifest_parser.h>
9 #include <manifest_parser/manifest_handler.h>
13 #include "common/logger.h"
14 #include "common/file_utils.h"
20 const char* kPathSeparator = "/";
21 const char* kConfigXml = "config.xml";
23 static std::string GetPackageIdByAppId(const std::string& appid) {
25 package_manager_get_package_id_by_app_id(appid.c_str(), &pkgid);
27 std::unique_ptr<char, decltype(std::free)*>
28 pkgid_ptr {pkgid, std::free};
31 return std::string(pkgid_ptr.get());
37 static std::string GetPackageRootPath(const std::string& pkgid) {
38 package_info_h pkg_info = NULL;
39 if (package_manager_get_package_info(
40 pkgid.c_str(), &pkg_info) != PACKAGE_MANAGER_ERROR_NONE) {
44 char* pkg_root_path = NULL;
45 package_info_get_root_path(pkg_info, &pkg_root_path);
47 std::unique_ptr<char, decltype(std::free)*>
48 path_ptr {pkg_root_path, std::free};
50 package_info_destroy(pkg_info);
52 if (pkg_root_path != NULL) {
53 return std::string(path_ptr.get());
61 ApplicationData::ApplicationData(const std::string& appid) : app_id_(appid) {
62 pkg_id_ = GetPackageIdByAppId(appid);
64 if (!pkg_id_.empty()) {
65 application_path_ = GetPackageRootPath(pkg_id_) + kPathSeparator +
66 appid + kPathSeparator;
70 ApplicationData::~ApplicationData() {}
72 std::shared_ptr<const wgt::parse::AppControlInfoList>
73 ApplicationData::app_control_info_list() const {
74 return app_control_info_list_;
77 std::shared_ptr<const wgt::parse::CategoryInfoList>
78 ApplicationData::category_info_list() const {
79 return category_info_list_;
82 std::shared_ptr<const wgt::parse::MetaDataInfo>
83 ApplicationData::meta_data_info() const {
84 return meta_data_info_;
87 std::shared_ptr<const wgt::parse::AllowedNavigationInfo>
88 ApplicationData::allowed_navigation_info() const {
89 return allowed_navigation_info_;
92 std::shared_ptr<const wgt::parse::PermissionsInfo>
93 ApplicationData::permissions_info() const {
94 return permissions_info_;
97 std::shared_ptr<const wgt::parse::SettingInfo>
98 ApplicationData::setting_info() const {
102 std::shared_ptr<const wgt::parse::SplashScreenInfo>
103 ApplicationData::splash_screen_info() const {
104 return splash_screen_info_;
107 std::shared_ptr<const wgt::parse::TizenApplicationInfo>
108 ApplicationData::tizen_application_info() const {
109 return tizen_application_info_;
112 std::shared_ptr<const wgt::parse::WidgetInfo>
113 ApplicationData::widget_info() const {
117 std::shared_ptr<const wgt::parse::ContentInfo>
118 ApplicationData::content_info() const {
119 return content_info_;
123 bool ApplicationData::LoadManifestData() {
124 std::string config_xml_path(application_path_ + kConfigXml);
125 if (!utils::Exists(config_xml_path)) {
126 LOGGER(ERROR) << "Failed to load manifest data. : No such file '"
127 << config_xml_path << "'.";
131 enum ManifestHandlerType {
132 APP_CONTROL_HANDLER = 0,
138 SPLASH_SCREEN_HANDLER,
139 TIZEN_APPLICATION_HANDLER,
144 std::vector<parser::ManifestHandler*> handlers = {
145 new wgt::parse::AppControlHandler, // APP_CONTROL_HANDLER
146 new wgt::parse::CategoryHandler, // CATEGORY_HANDLER
147 new wgt::parse::MetaDataHandler, // META_DATA_HANDLER
148 new wgt::parse::NavigationHandler, // NAVIGATION_HANDLER
149 new wgt::parse::PermissionsHandler, // PERMISSIONS_HANDLER
150 new wgt::parse::SettingHandler, // SETTING_HANDLER
151 new wgt::parse::SplashScreenHandler, // SPLASH_SCREEN_HANDLER
152 new wgt::parse::TizenApplicationHandler, // TIZEN_APPLICATION_HANDLER
153 new wgt::parse::WidgetHandler, // WIDGET_HANDLER
154 new wgt::parse::ContentHandler // CONTENT_HANDLER
157 std::unique_ptr<parser::ManifestHandlerRegistry> registry;
158 registry.reset(new parser::ManifestHandlerRegistry(handlers));
160 parser::ManifestParser manifest_parser(std::move(registry));
161 if (!manifest_parser.ParseManifest(config_xml_path)) {
162 for (auto iter = handlers.begin(); iter != handlers.end(); ++iter) {
165 LOGGER(ERROR) << "Failed to load manifest data : "
166 << manifest_parser.GetErrorMessage();
170 app_control_info_list_ =
171 std::static_pointer_cast<const wgt::parse::AppControlInfoList>(
172 manifest_parser.GetManifestData(
173 handlers[ManifestHandlerType::APP_CONTROL_HANDLER]->Key()));
175 category_info_list_ =
176 std::static_pointer_cast<const wgt::parse::CategoryInfoList>(
177 manifest_parser.GetManifestData(
178 handlers[ManifestHandlerType::CATEGORY_HANDLER]->Key()));
181 std::static_pointer_cast<const wgt::parse::MetaDataInfo>(
182 manifest_parser.GetManifestData(
183 handlers[ManifestHandlerType::META_DATA_HANDLER]->Key()));
185 allowed_navigation_info_ =
186 std::static_pointer_cast<const wgt::parse::AllowedNavigationInfo>(
187 manifest_parser.GetManifestData(
188 handlers[ManifestHandlerType::NAVIGATION_HANDLER]->Key()));
191 std::static_pointer_cast<const wgt::parse::PermissionsInfo>(
192 manifest_parser.GetManifestData(
193 handlers[ManifestHandlerType::PERMISSIONS_HANDLER]->Key()));
196 std::static_pointer_cast<const wgt::parse::SettingInfo>(
197 manifest_parser.GetManifestData(
198 handlers[ManifestHandlerType::SETTING_HANDLER]->Key()));
200 splash_screen_info_ =
201 std::static_pointer_cast<const wgt::parse::SplashScreenInfo>(
202 manifest_parser.GetManifestData(
203 handlers[ManifestHandlerType::SPLASH_SCREEN_HANDLER]->Key()));
205 tizen_application_info_ =
206 std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
207 manifest_parser.GetManifestData(
208 handlers[ManifestHandlerType::TIZEN_APPLICATION_HANDLER]->Key()));
211 std::static_pointer_cast<const wgt::parse::WidgetInfo>(
212 manifest_parser.GetManifestData(
213 handlers[ManifestHandlerType::WIDGET_HANDLER]->Key()));
216 std::static_pointer_cast<const wgt::parse::ContentInfo>(
217 manifest_parser.GetManifestData(
218 handlers[ManifestHandlerType::CONTENT_HANDLER]->Key()));
220 for (auto iter = handlers.begin(); iter != handlers.end(); ++iter) {
224 // Set default empty object
225 if (widget_info_.get() == NULL) {
226 widget_info_.reset(new wgt::parse::WidgetInfo);
228 if (setting_info_.get() == NULL) {
229 setting_info_.reset(new wgt::parse::SettingInfo);