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 <wgt_manifest_handlers/application_manifest_constants.h>
21 #include <wgt_manifest_handlers/widget_config_parser.h>
22 #include <app_manager.h>
23 #include <app_common.h>
27 #include "common/file_utils.h"
28 #include "common/logger.h"
29 #include "common/profiler.h"
35 const char* kPathSeparator = "/";
36 const char* kConfigXml = "config.xml";
37 const char* kWgtPath = "wgt";
39 #ifdef IME_FEATURE_SUPPORT
40 const char* kImeCategory = "http://tizen.org/category/ime";
41 #endif // IME_FEATURE_SUPPORT
42 #ifdef WATCH_FACE_FEATURE_SUPPORT
43 const char* kIdleClockCategory = "com.samsung.wmanager.WATCH_CLOCK";
44 const char* kWearableClockCategory = "http://tizen.org/category/wearable_clock";
45 #endif // WATCH_FACE_FEATURE_SUPPORT
49 ApplicationData::ApplicationData(const std::string& appid)
53 char* res_path = app_get_resource_path();
54 if (res_path != NULL) {
55 application_path_ = std::string(res_path) + kWgtPath + kPathSeparator;
60 ApplicationData::~ApplicationData() {}
62 std::shared_ptr<const wgt::parse::AppControlInfoList>
63 ApplicationData::app_control_info_list() const {
64 return app_control_info_list_;
67 std::shared_ptr<const wgt::parse::CategoryInfoList>
68 ApplicationData::category_info_list() const {
69 return category_info_list_;
72 std::shared_ptr<const wgt::parse::MetaDataInfo>
73 ApplicationData::meta_data_info() const {
74 return meta_data_info_;
77 std::shared_ptr<const wgt::parse::AllowedNavigationInfo>
78 ApplicationData::allowed_navigation_info() const {
79 return allowed_navigation_info_;
82 std::shared_ptr<const wgt::parse::PermissionsInfo>
83 ApplicationData::permissions_info() const {
84 return permissions_info_;
87 std::shared_ptr<const wgt::parse::SettingInfo>
88 ApplicationData::setting_info() const {
92 std::shared_ptr<const wgt::parse::LaunchScreenInfo>
93 ApplicationData::splash_screen_info() const {
94 return splash_screen_info_;
97 std::shared_ptr<const wgt::parse::TizenApplicationInfo>
98 ApplicationData::tizen_application_info() const {
99 return tizen_application_info_;
102 std::shared_ptr<const wgt::parse::WidgetInfo>
103 ApplicationData::widget_info() const {
107 std::shared_ptr<const wgt::parse::ContentInfo>
108 ApplicationData::content_info() const {
109 return content_info_;
112 std::shared_ptr<const wgt::parse::WarpInfo>
113 ApplicationData::warp_info() const {
117 std::shared_ptr<const wgt::parse::CSPInfo>
118 ApplicationData::csp_info() const {
122 std::shared_ptr<const wgt::parse::CSPInfo>
123 ApplicationData::csp_report_info() const {
124 return csp_report_info_;
127 const std::string ApplicationData::pkg_id() const {
128 if (pkg_id_.empty()) {
130 int ret = app_info_create(app_id_.c_str(), &app_info);
131 if (ret == APP_MANAGER_ERROR_NONE) {
133 ret = app_info_get_package(app_info, &pkg);
134 if (ret == APP_MANAGER_ERROR_NONE && pkg != NULL) {
138 app_info_destroy(app_info);
144 ApplicationData::AppType ApplicationData::GetAppType() {
145 if (category_info_list_) {
146 auto category_list = category_info_list_->categories;
147 auto it = category_list.begin();
148 auto end = category_list.end();
149 for (; it != end; ++it) {
150 #ifdef IME_FEATURE_SUPPORT
151 if (*it == kImeCategory) {
154 #endif // IME_FEATURE_SUPPORT
155 #ifdef WATCH_FACE_FEATURE_SUPPORT
156 if (*it == kIdleClockCategory || *it == kWearableClockCategory) {
159 #endif // WATCH_FACE_FEATURE_SUPPORT
165 bool ApplicationData::LoadManifestData() {
172 std::string config_xml_path(application_path_ + kConfigXml);
173 if (!utils::Exists(config_xml_path)) {
174 LOGGER(ERROR) << "Failed to load manifest data : No such file '"
175 << config_xml_path << "'.";
179 std::unique_ptr<wgt::parse::WidgetConfigParser> widget_config_parser;
180 widget_config_parser.reset(new wgt::parse::WidgetConfigParser());
181 if (!widget_config_parser->ParseManifest(config_xml_path)) {
182 LOGGER(ERROR) << "Failed to load widget config parser data: "
183 << widget_config_parser->GetErrorMessage();
187 app_control_info_list_ =
188 std::static_pointer_cast<const wgt::parse::AppControlInfoList>(
189 widget_config_parser->GetManifestData(
190 wgt::parse::AppControlInfo::Key()));
192 category_info_list_ =
193 std::static_pointer_cast<const wgt::parse::CategoryInfoList>(
194 widget_config_parser->GetManifestData(
195 wgt::parse::CategoryInfoList::Key()));
198 std::static_pointer_cast<const wgt::parse::MetaDataInfo>(
199 widget_config_parser->GetManifestData(
200 wgt::parse::MetaDataInfo::Key()));
202 allowed_navigation_info_ =
203 std::static_pointer_cast<const wgt::parse::AllowedNavigationInfo>(
204 widget_config_parser->GetManifestData(
205 wgt::parse::AllowedNavigationInfo::Key()));
208 std::static_pointer_cast<const wgt::parse::PermissionsInfo>(
209 widget_config_parser->GetManifestData(
210 wgt::parse::PermissionsInfo::Key()));
213 std::static_pointer_cast<const wgt::parse::SettingInfo>(
214 widget_config_parser->GetManifestData(
215 wgt::parse::SettingInfo::Key()));
217 splash_screen_info_ =
218 std::static_pointer_cast<const wgt::parse::LaunchScreenInfo>(
219 widget_config_parser->GetManifestData(
220 wgt::parse::LaunchScreenInfo::Key()));
222 tizen_application_info_ =
223 std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
224 widget_config_parser->GetManifestData(
225 wgt::parse::TizenApplicationInfo::Key()));
228 std::static_pointer_cast<const wgt::parse::WidgetInfo>(
229 widget_config_parser->GetManifestData(
230 wgt::parse::WidgetInfo::Key()));
233 std::static_pointer_cast<const wgt::parse::ContentInfo>(
234 widget_config_parser->GetManifestData(
235 wgt::parse::ContentInfo::Key()));
238 std::static_pointer_cast<const wgt::parse::WarpInfo>(
239 widget_config_parser->GetManifestData(
240 wgt::parse::WarpInfo::Key()));
243 std::static_pointer_cast<const wgt::parse::CSPInfo>(
244 widget_config_parser->GetManifestData(
245 wgt::parse::CSPInfo::Key()));
248 std::static_pointer_cast<const wgt::parse::CSPInfo>(
249 widget_config_parser->GetManifestData(
250 wgt::parse::CSPInfo::Report_only_key()));
252 // Set default empty object
253 if (widget_info_.get() == NULL) {
254 widget_info_.reset(new wgt::parse::WidgetInfo);
256 if (setting_info_.get() == NULL) {
257 setting_info_.reset(new wgt::parse::SettingInfo);
260 app_type_ = GetAppType();
267 ApplicationDataManager* ApplicationDataManager::GetInstance() {
268 static ApplicationDataManager self;
272 ApplicationDataManager::ApplicationDataManager() {
275 ApplicationDataManager::~ApplicationDataManager() {
278 ApplicationData* ApplicationDataManager::GetApplicationData(
279 const std::string& appid) {
280 auto it = cache_.find(appid);
281 if (it == cache_.end()) {
282 cache_[appid].reset(new ApplicationData(appid));
284 return cache_[appid].get();
287 } // namespace common