2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "common/application_data.h"
19 #include <package_manager.h>
20 #include <manifest_parser/manifest_parser.h>
21 #include <manifest_parser/manifest_handler.h>
25 #include "common/logger.h"
26 #include "common/file_utils.h"
32 const char* kPathSeparator = "/";
33 const char* kConfigXml = "config.xml";
35 static std::string GetPackageIdByAppId(const std::string& appid) {
37 package_manager_get_package_id_by_app_id(appid.c_str(), &pkgid);
39 std::unique_ptr<char, decltype(std::free)*>
40 pkgid_ptr {pkgid, std::free};
43 return std::string(pkgid_ptr.get());
49 static std::string GetPackageRootPath(const std::string& pkgid) {
50 package_info_h pkg_info = NULL;
51 if (package_manager_get_package_info(
52 pkgid.c_str(), &pkg_info) != PACKAGE_MANAGER_ERROR_NONE) {
56 char* pkg_root_path = NULL;
57 package_info_get_root_path(pkg_info, &pkg_root_path);
59 std::unique_ptr<char, decltype(std::free)*>
60 path_ptr {pkg_root_path, std::free};
62 package_info_destroy(pkg_info);
64 if (pkg_root_path != NULL) {
65 return std::string(path_ptr.get());
73 ApplicationData::ApplicationData(const std::string& appid) : app_id_(appid) {
74 pkg_id_ = GetPackageIdByAppId(appid);
76 if (!pkg_id_.empty()) {
77 application_path_ = GetPackageRootPath(pkg_id_) + kPathSeparator +
78 appid + kPathSeparator;
82 ApplicationData::~ApplicationData() {}
84 std::shared_ptr<const wgt::parse::AppControlInfoList>
85 ApplicationData::app_control_info_list() const {
86 return app_control_info_list_;
89 std::shared_ptr<const wgt::parse::CategoryInfoList>
90 ApplicationData::category_info_list() const {
91 return category_info_list_;
94 std::shared_ptr<const wgt::parse::MetaDataInfo>
95 ApplicationData::meta_data_info() const {
96 return meta_data_info_;
99 std::shared_ptr<const wgt::parse::AllowedNavigationInfo>
100 ApplicationData::allowed_navigation_info() const {
101 return allowed_navigation_info_;
104 std::shared_ptr<const wgt::parse::PermissionsInfo>
105 ApplicationData::permissions_info() const {
106 return permissions_info_;
109 std::shared_ptr<const wgt::parse::SettingInfo>
110 ApplicationData::setting_info() const {
111 return setting_info_;
114 std::shared_ptr<const wgt::parse::SplashScreenInfo>
115 ApplicationData::splash_screen_info() const {
116 return splash_screen_info_;
119 std::shared_ptr<const wgt::parse::TizenApplicationInfo>
120 ApplicationData::tizen_application_info() const {
121 return tizen_application_info_;
124 std::shared_ptr<const wgt::parse::WidgetInfo>
125 ApplicationData::widget_info() const {
129 std::shared_ptr<const wgt::parse::ContentInfo>
130 ApplicationData::content_info() const {
131 return content_info_;
135 bool ApplicationData::LoadManifestData() {
136 std::string config_xml_path(application_path_ + kConfigXml);
137 if (!utils::Exists(config_xml_path)) {
138 LOGGER(ERROR) << "Failed to load manifest data. : No such file '"
139 << config_xml_path << "'.";
143 enum ManifestHandlerType {
144 APP_CONTROL_HANDLER = 0,
150 SPLASH_SCREEN_HANDLER,
151 TIZEN_APPLICATION_HANDLER,
156 std::vector<parser::ManifestHandler*> handlers = {
157 new wgt::parse::AppControlHandler, // APP_CONTROL_HANDLER
158 new wgt::parse::CategoryHandler, // CATEGORY_HANDLER
159 new wgt::parse::MetaDataHandler, // META_DATA_HANDLER
160 new wgt::parse::NavigationHandler, // NAVIGATION_HANDLER
161 new wgt::parse::PermissionsHandler, // PERMISSIONS_HANDLER
162 new wgt::parse::SettingHandler, // SETTING_HANDLER
163 new wgt::parse::SplashScreenHandler, // SPLASH_SCREEN_HANDLER
164 new wgt::parse::TizenApplicationHandler, // TIZEN_APPLICATION_HANDLER
165 new wgt::parse::WidgetHandler, // WIDGET_HANDLER
166 new wgt::parse::ContentHandler // CONTENT_HANDLER
169 std::unique_ptr<parser::ManifestHandlerRegistry> registry;
170 registry.reset(new parser::ManifestHandlerRegistry(handlers));
172 parser::ManifestParser manifest_parser(std::move(registry));
173 if (!manifest_parser.ParseManifest(config_xml_path)) {
174 for (auto iter = handlers.begin(); iter != handlers.end(); ++iter) {
177 LOGGER(ERROR) << "Failed to load manifest data : "
178 << manifest_parser.GetErrorMessage();
182 app_control_info_list_ =
183 std::static_pointer_cast<const wgt::parse::AppControlInfoList>(
184 manifest_parser.GetManifestData(
185 handlers[ManifestHandlerType::APP_CONTROL_HANDLER]->Key()));
187 category_info_list_ =
188 std::static_pointer_cast<const wgt::parse::CategoryInfoList>(
189 manifest_parser.GetManifestData(
190 handlers[ManifestHandlerType::CATEGORY_HANDLER]->Key()));
193 std::static_pointer_cast<const wgt::parse::MetaDataInfo>(
194 manifest_parser.GetManifestData(
195 handlers[ManifestHandlerType::META_DATA_HANDLER]->Key()));
197 allowed_navigation_info_ =
198 std::static_pointer_cast<const wgt::parse::AllowedNavigationInfo>(
199 manifest_parser.GetManifestData(
200 handlers[ManifestHandlerType::NAVIGATION_HANDLER]->Key()));
203 std::static_pointer_cast<const wgt::parse::PermissionsInfo>(
204 manifest_parser.GetManifestData(
205 handlers[ManifestHandlerType::PERMISSIONS_HANDLER]->Key()));
208 std::static_pointer_cast<const wgt::parse::SettingInfo>(
209 manifest_parser.GetManifestData(
210 handlers[ManifestHandlerType::SETTING_HANDLER]->Key()));
212 splash_screen_info_ =
213 std::static_pointer_cast<const wgt::parse::SplashScreenInfo>(
214 manifest_parser.GetManifestData(
215 handlers[ManifestHandlerType::SPLASH_SCREEN_HANDLER]->Key()));
217 tizen_application_info_ =
218 std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
219 manifest_parser.GetManifestData(
220 handlers[ManifestHandlerType::TIZEN_APPLICATION_HANDLER]->Key()));
223 std::static_pointer_cast<const wgt::parse::WidgetInfo>(
224 manifest_parser.GetManifestData(
225 handlers[ManifestHandlerType::WIDGET_HANDLER]->Key()));
228 std::static_pointer_cast<const wgt::parse::ContentInfo>(
229 manifest_parser.GetManifestData(
230 handlers[ManifestHandlerType::CONTENT_HANDLER]->Key()));
232 for (auto iter = handlers.begin(); iter != handlers.end(); ++iter) {
236 // Set default empty object
237 if (widget_info_.get() == NULL) {
238 widget_info_.reset(new wgt::parse::WidgetInfo);
240 if (setting_info_.get() == NULL) {
241 setting_info_.reset(new wgt::parse::SettingInfo);