Refactoring StepParse
[platform/core/appfw/wgt-backend.git] / src / wgt / step / configuration / step_parse.cc
1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a apache 2.0 license that can be
4 // found in the LICENSE file.
5
6 #include "wgt/step/configuration/step_parse.h"
7
8 #include <boost/filesystem/path.hpp>
9
10 #include <common/app_installer.h>
11 #include <common/paths.h>
12 #include <common/installer_context.h>
13 #include <common/step/step.h>
14 #include <common/utils/glist_range.h>
15 #include <manifest_parser/utils/version_number.h>
16 #include <wgt_manifest_handlers/account_handler.h>
17 #include <wgt_manifest_handlers/app_control_handler.h>
18 #include <wgt_manifest_handlers/application_icons_handler.h>
19 #include <wgt_manifest_handlers/application_manifest_constants.h>
20 #include <wgt_manifest_handlers/background_category_handler.h>
21 #include <wgt_manifest_handlers/category_handler.h>
22 #include <wgt_manifest_handlers/content_handler.h>
23 #include <wgt_manifest_handlers/metadata_handler.h>
24 #include <wgt_manifest_handlers/service_handler.h>
25 #include <wgt_manifest_handlers/setting_handler.h>
26 #include <wgt_manifest_handlers/tizen_application_handler.h>
27 #include <wgt_manifest_handlers/widget_handler.h>
28 #include <wgt_manifest_handlers/ime_handler.h>
29
30 #include <pkgmgr/pkgmgr_parser.h>
31
32 #include <string.h>
33
34 #include <chrono>
35 #include <cstdio>
36 #include <cstdlib>
37 #include <memory>
38 #include <set>
39 #include <string>
40 #include <vector>
41
42 #include "wgt/wgt_backend_data.h"
43
44 namespace bf = boost::filesystem;
45
46 namespace {
47
48 const char kCategoryWearableClock[] =
49     "http://tizen.org/category/wearable_clock";
50 const char kCategoryWatchClock[] = "com.samsung.wmanager.WATCH_CLOCK";
51
52 const std::string kManifestVersion = "1.0.0";
53 const char kTizenPackageXmlNamespace[] = "http://tizen.org/ns/packages";
54 const char kImeCategoryName[] = "http://tizen.org/category/ime";
55
56 const char kResWgt[] = "res/wgt";
57
58 GList* GenerateMetadataListX(const wgt::parse::MetaDataInfo& meta_info) {
59   GList* list = nullptr;
60   for (auto& meta : meta_info.metadata()) {
61     metadata_x* new_meta =
62         static_cast<metadata_x*>(calloc(1, sizeof(metadata_x)));
63     new_meta->key = strdup(meta.first.c_str());
64     if (!meta.second.empty())
65       new_meta->value = strdup(meta.second.c_str());
66     list = g_list_append(list, new_meta);
67   }
68   return list;
69 }
70
71 void SetApplicationXDefaults(application_x* application) {
72   application->effectimage_type = strdup("image");
73   application->enabled = strdup("true");
74   application->guestmode_visibility = strdup("true");
75   application->hwacceleration = strdup("default");
76   application->indicatordisplay = strdup("true");
77   application->launchcondition = strdup("false");
78   application->permission_type = strdup("normal");
79   application->process_pool = strdup("false");
80   application->recentimage = strdup("false");
81   application->screenreader = strdup("use-system-setting");
82   application->submode = strdup("false");
83   application->support_disable = strdup("false");
84   application->ui_gadget = strdup("false");
85   application->multiple = strdup("false");
86 }
87
88 template<typename T>
89 void AppendLabel(T* root, const std::string& label,
90                  const std::string& locale) {
91   label_x* label_item = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
92   label_item->name = strdup(label.c_str());
93   label_item->text = strdup(label.c_str());
94   label_item->lang = !locale.empty() ?
95       strdup(locale.c_str()) : strdup(DEFAULT_LOCALE);
96   root->label = g_list_append(root->label, label_item);
97 }
98 }  // namespace
99
100 namespace wgt {
101 namespace configuration {
102
103 namespace app_keys = wgt::application_widget_keys;
104 namespace sc = std::chrono;
105
106 StepParse::StepParse(common_installer::InstallerContext* context,
107                      ConfigLocation config_location,
108                      bool check_start_file)
109     : Step(context),
110       config_location_(config_location),
111       check_start_file_(check_start_file) {
112 }
113
114 std::set<std::string> StepParse::ExtractPrivileges(
115     std::shared_ptr<const wgt::parse::PermissionsInfo> perm_info) const {
116   return perm_info->GetAPIPermissions();
117 }
118
119 std::string StepParse::GetPackageVersion(
120      const std::string& manifest_version) {
121   if (manifest_version.empty()) {
122     return kManifestVersion;
123   }
124   std::string version = manifest_version.substr(0,
125       manifest_version.find_first_not_of("1234567890."));
126
127   utils::VersionNumber version_number(version);
128
129   if (!version_number.IsValidTizenPackageVersion()) {
130     LOG(WARNING) << "Version number: " << manifest_version
131                  << " is not valid version number for tizen package. "
132                  << "Default value will be used.";
133     return kManifestVersion;
134   }
135
136   return version_number.ToString();
137 }
138
139 bool StepParse::FillInstallationInfo(manifest_x* manifest) {
140   manifest->root_path = strdup(
141       (context_->root_application_path.get() / manifest->package).c_str());
142   manifest->installed_time =
143       strdup(std::to_string(sc::system_clock::to_time_t(
144           sc::system_clock::now())).c_str());
145   return true;
146 }
147
148 bool StepParse::FillIconPaths(manifest_x* manifest) {
149   auto app_info =
150       GetManifestDataForKey<const wgt::parse::TizenApplicationInfo>(
151              app_keys::kTizenApplicationKey);
152   if (!app_info) {
153     LOG(ERROR) << "Application info manifest data has not been found.";
154     return false;
155   }
156   auto icons_info =
157       GetManifestDataForKey<const wgt::parse::ApplicationIconsInfo>(
158              app_keys::kIconsKey);
159   if (icons_info.get()) {
160     for (auto& application_icon : icons_info->icons()) {
161       icon_x* icon = reinterpret_cast<icon_x*> (calloc(1, sizeof(icon_x)));
162       bf::path icon_path = context_->root_application_path.get()
163           / app_info->package() / "res" / "wgt" / application_icon.path();
164       icon->text = strdup(icon_path.c_str());
165       icon->lang = strdup(DEFAULT_LOCALE);
166       manifest->icon = g_list_append(manifest->icon, icon);
167     }
168   }
169   return true;
170 }
171
172 bool StepParse::FillWidgetInfo(manifest_x* manifest) {
173   auto wgt_info =
174       GetManifestDataForKey<const wgt::parse::WidgetInfo>(
175              app_keys::kWidgetKey);
176
177   if (!wgt_info.get()) {
178     LOG(ERROR) << "Widget info manifest data has not been found.";
179     return false;
180   }
181
182   const std::string& version = wgt_info->version();
183
184   manifest->ns = strdup(kTizenPackageXmlNamespace);
185   manifest->version = strdup(GetPackageVersion(version).c_str());
186
187   for (auto& item : wgt_info->description_set()) {
188     description_x* description = reinterpret_cast<description_x*>
189         (calloc(1, sizeof(description_x)));
190     description->text = strdup(item.second.c_str());
191     description->lang = !item.first.empty() ?
192         strdup(item.first.c_str()) : strdup(DEFAULT_LOCALE);
193     manifest->description = g_list_append(manifest->description, description);
194   }
195
196   for (auto& item : wgt_info->name_set()) {
197     AppendLabel(manifest, item.second, item.first);
198   }
199
200   manifest->type = strdup("wgt");
201   manifest->appsetting = strdup("false");
202   manifest->nodisplay_setting = strdup("false");
203   manifest->preload = strdup("false");
204   manifest->installed_storage = strdup("installed_internal");
205
206   // For wgt package use the long name
207   application_x* app =
208       reinterpret_cast<application_x*>(manifest->application->data);
209   for (auto& item : wgt_info->name_set()) {
210     AppendLabel(app, item.second, item.first);
211   }
212
213   author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
214   if (!wgt_info->author().empty())
215     author->text = strdup(wgt_info->author().c_str());
216   if (!wgt_info->author_email().empty())
217     author->email = strdup(wgt_info->author_email().c_str());
218   if (!wgt_info->author_href().empty())
219     author->href = strdup(wgt_info->author_href().c_str());
220   author->lang = strdup(DEFAULT_LOCALE);
221   manifest->author = g_list_append(manifest->author, author);
222
223   auto settings_info =
224       GetManifestDataForKey<const wgt::parse::SettingInfo>(
225              wgt::application_widget_keys::kTizenSettingKey);
226   if (settings_info) {
227     switch (settings_info->install_location()) {
228     case wgt::parse::SettingInfo::InstallLocation::AUTO: {
229       manifest->installlocation = strdup("auto");
230       break;
231     }
232     case wgt::parse::SettingInfo::InstallLocation::INTERNAL: {
233       manifest->installlocation = strdup("internal-only");
234       break;
235     }
236     case wgt::parse::SettingInfo::InstallLocation::EXTERNAL: {
237       manifest->installlocation = strdup("prefer-external");
238       break;
239     }
240     }
241   } else {
242     manifest->installlocation = strdup("auto");
243   }
244
245   return true;
246 }
247
248 bool StepParse::FillMainApplicationInfo(manifest_x* manifest) {
249   auto app_info =
250       GetManifestDataForKey<const wgt::parse::TizenApplicationInfo>(
251              app_keys::kTizenApplicationKey);
252   if (!app_info) {
253     LOG(ERROR) << "Application info manifest data has not been found.";
254     return false;
255   }
256   bool has_watch_catergory = false;
257   bool has_ime = false;
258   auto category_info =
259       GetManifestDataForKey<const wgt::parse::CategoryInfoList>(
260              app_keys::kTizenCategoryKey);
261
262   if (category_info) {
263     has_watch_catergory = std::find_if(category_info->categories.begin(),
264                                        category_info->categories.end(),
265                                        [](const std::string& category) {
266       return category == kCategoryWearableClock ||
267              category == kCategoryWatchClock;
268     }) != category_info->categories.end();
269     has_ime = std::find(category_info->categories.begin(),
270                                        category_info->categories.end(),
271                                        kImeCategoryName)
272         != category_info->categories.end();
273   }
274
275   // application data
276   application_x* application = reinterpret_cast<application_x*>(
277       calloc(1, sizeof(application_x)));
278   application->component_type =
279       has_watch_catergory ? strdup("watchapp") : strdup("uiapp");
280   application->mainapp = strdup("true");
281   application->appid = strdup(app_info->id().c_str());
282   application->nodisplay = has_ime ? strdup("true") : strdup("false");
283   application->taskmanage = has_ime ? strdup("false") : strdup("true");
284   SetApplicationXDefaults(application);
285   if (has_watch_catergory)
286     application->ambient_support =
287         strdup(app_info->ambient_support() ? "true" : "false");
288   else
289     application->ambient_support = strdup("false");
290   application->package = strdup(app_info->package().c_str());
291
292   application->exec =
293       strdup((context_->root_application_path.get() / app_info->package()
294               / "bin" / application->appid).c_str());
295   application->type = strdup("webapp");
296   application->onboot = strdup("false");
297   application->autorestart = strdup("false");
298
299   application->launch_mode = strdup(app_info->launch_mode().c_str());
300   if (manifest->icon) {
301     icon_x* icon = reinterpret_cast<icon_x*>(manifest->icon->data);
302     icon_x* app_icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
303     app_icon->text = strdup(icon->text);
304     app_icon->lang = strdup(icon->lang);
305     application->icon = g_list_append(application->icon, app_icon);
306   }
307   // guarantees that the main app will be at the begining of the list
308   manifest->application = g_list_insert(manifest->application, application, 0);
309
310   manifest->package = strdup(app_info->package().c_str());
311   manifest->mainapp_id = strdup(app_info->id().c_str());
312   return true;
313 }
314
315 bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) {
316   auto service_list =
317       GetManifestDataForKey<const wgt::parse::ServiceList>(
318              app_keys::kTizenServiceKey);
319   if (!service_list)
320     return true;
321   for (auto& service_info : service_list->services) {
322     application_x* application = reinterpret_cast<application_x*>
323         (calloc(1, sizeof(application_x)));
324     application->component_type = strdup("svcapp");
325     application->mainapp = strdup("false");
326     application->appid = strdup(service_info.id().c_str());
327     application->exec =
328         strdup((context_->root_application_path.get() / manifest->package
329                 / "bin" / application->appid).c_str());
330     application->type = strdup("webapp");
331     application->onboot =
332         service_info.on_boot() ? strdup("true") : strdup("false");
333     application->autorestart =
334         service_info.auto_restart() ? strdup("true") : strdup("false");
335     application->nodisplay = strdup("false");
336     application->taskmanage = strdup("true");
337     SetApplicationXDefaults(application);
338     application->ambient_support = strdup("false");
339     application->package = strdup(manifest->package);
340
341     for (auto& pair : service_info.names()) {
342       AppendLabel(application, pair.second, pair.first);
343     }
344
345     if (!service_info.icon().empty()) {
346       bf::path icon_path = context_->root_application_path.get()
347           / manifest->package / "res" / "wgt" / service_info.icon();
348       icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
349       icon->text = strdup(icon_path.c_str());
350       icon->lang = strdup(DEFAULT_LOCALE);
351       application->icon = g_list_append(application->icon, icon);
352     }
353
354     // TODO(t.iwanek): what about description, how is it different from name?
355
356     for (auto& category : service_info.categories()) {
357       application->category = g_list_append(application->category,
358                                             strdup(category.c_str()));
359     }
360
361     for (auto& pair : service_info.metadata_set()) {
362       metadata_x* item = reinterpret_cast<metadata_x*>(
363           calloc(1, sizeof(metadata_x)));
364       item->key = strdup(pair.first.c_str());
365       if (!pair.second.empty())
366         item->value = strdup(pair.second.c_str());
367       application->metadata = g_list_append(application->metadata, item);
368     }
369
370     manifest->application = g_list_append(manifest->application, application);
371   }
372   return true;
373 }
374
375 bool StepParse::FillWidgetApplicationInfo(manifest_x* manifest) {
376   auto appwidget_info =
377       GetManifestDataForKey<const wgt::parse::AppWidgetInfo>(
378              wgt::application_widget_keys::kTizenAppWidgetFullKey);
379   if (!appwidget_info)
380     return true;
381   for (auto& app_widget : appwidget_info->app_widgets()) {
382     application_x* application = reinterpret_cast<application_x*>
383         (calloc(1, sizeof(application_x)));
384     application->component_type = strdup("widgetapp");
385     application->mainapp = strdup("false");
386     application->appid = strdup(app_widget.id.c_str());
387     application->exec =
388         strdup((context_->root_application_path.get() / manifest->package
389                 / "bin" / application->appid).c_str());
390     application->type = strdup("webapp");
391     application->nodisplay = strdup("false");
392     application->taskmanage = strdup("false");
393     SetApplicationXDefaults(application);
394     application->ambient_support = strdup("false");
395     application->package = strdup(manifest->package);
396
397     if (!app_widget.label.default_value.empty()) {
398       AppendLabel(application, app_widget.label.default_value, std::string());
399     }
400
401     for (auto& pair : app_widget.label.lang_value_map) {
402       AppendLabel(application, pair.second, pair.first);
403     }
404
405     if (!app_widget.icon_src.empty()) {
406       icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
407       icon->text = strdup(app_widget.icon_src.c_str());
408       icon->lang = strdup(DEFAULT_LOCALE);
409       application->icon = g_list_append(application->icon, icon);
410     }
411
412     manifest->application = g_list_append(manifest->application, application);
413   }
414   return true;
415 }
416
417
418 bool StepParse::FillBackgroundCategoryInfo(manifest_x* manifest) {
419   auto manifest_data = parser_->GetManifestData(
420       app_keys::kTizenBackgroundCategoryKey);
421   std::shared_ptr<const wgt::parse::BackgroundCategoryInfoList> bc_list =
422       std::static_pointer_cast<const wgt::parse::BackgroundCategoryInfoList>(
423           manifest_data);
424
425   if (!bc_list)
426     return true;
427
428   application_x* app =
429       reinterpret_cast<application_x*>(manifest->application->data);
430
431   for (auto& background_category : bc_list->background_categories) {
432     app->background_category = g_list_append(
433         app->background_category, strdup(background_category.value().c_str()));
434   }
435
436   return true;
437 }
438
439 bool StepParse::FillAppControl(manifest_x* manifest) {
440   auto app_info_list =
441       GetManifestDataForKey<const wgt::parse::AppControlInfoList>(
442              app_keys::kTizenApplicationAppControlsKey);
443
444   application_x* app =
445       reinterpret_cast<application_x*>(manifest->application->data);
446   if (app_info_list) {
447     for (const auto& control : app_info_list->controls) {
448       appcontrol_x* app_control =
449           static_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
450       app_control->operation = strdup(control.operation().c_str());
451       app_control->mime = strdup(control.mime().c_str());
452       app_control->uri = strdup(control.uri().c_str());
453       app->appcontrol = g_list_append(app->appcontrol, app_control);
454     }
455   }
456   return true;
457 }
458
459 bool StepParse::FillPrivileges(manifest_x* manifest) {
460   auto perm_info =
461       GetManifestDataForKey<const wgt::parse::PermissionsInfo>(
462              app_keys::kTizenPermissionsKey);
463   std::set<std::string> privileges;
464   if (perm_info)
465     privileges = ExtractPrivileges(perm_info);
466
467   for (auto& priv : privileges) {
468     manifest->privileges =
469         g_list_append(manifest->privileges, strdup(priv.c_str()));
470   }
471   return true;
472 }
473
474 bool StepParse::FillCategories(manifest_x* manifest) {
475   auto category_info =
476       GetManifestDataForKey<const wgt::parse::CategoryInfoList>(
477              app_keys::kTizenCategoryKey);
478   if (!category_info)
479     return true;
480
481   application_x* app =
482       reinterpret_cast<application_x*>(manifest->application->data);
483   // there is one app atm
484   for (auto& category : category_info->categories) {
485     app->category = g_list_append(app->category, strdup(category.c_str()));
486   }
487   return true;
488 }
489
490 bool StepParse::FillMetadata(manifest_x* manifest) {
491   auto meta_info =
492       GetManifestDataForKey<const wgt::parse::MetaDataInfo>(
493              app_keys::kTizenMetaDataKey);
494   if (!meta_info)
495     return true;
496
497   for (application_x* app : GListRange<application_x*>(manifest->application)) {
498     app->metadata = GenerateMetadataListX(*meta_info);
499   }
500   return true;
501 }
502
503 bool StepParse::FillAppWidget() {
504   // This is needed to store preview icons which are not saved into manifest_x
505   WgtBackendData* backend_data =
506       static_cast<WgtBackendData*>(context_->backend_data.get());
507
508   auto appwidget_info =
509       GetManifestDataForKey<const wgt::parse::AppWidgetInfo>(
510              wgt::application_widget_keys::kTizenAppWidgetFullKey);
511   if (appwidget_info)
512     backend_data->appwidgets.set(*appwidget_info);
513   return true;
514 }
515
516 bool StepParse::FillAccounts(manifest_x* manifest) {
517   auto account_info =
518       GetManifestDataForKey<const wgt::parse::AccountInfo>(
519              app_keys::kAccountKey);
520   if (!account_info)
521     return true;
522   common_installer::AccountInfo info;
523   for (auto& account : account_info->accounts()) {
524     common_installer::SingleAccountInfo single_info;
525     single_info.capabilities = account.capabilities;
526     single_info.icon_paths = account.icon_paths;
527     single_info.multiple_account_support = account.multiple_account_support;
528     single_info.names = account.names;
529     // wgt can contain only one app so this assumes mainapp_id is valid here
530     single_info.appid = manifest->mainapp_id;
531     info.set_account(single_info);
532   }
533   context_->manifest_plugins_data.get().account_info.set(info);
534   return true;
535 }
536
537 bool StepParse::FillImeInfo() {
538   auto ime_info =
539       GetManifestDataForKey<const wgt::parse::ImeInfo>(
540              app_keys::kAccountKey);
541   if (!ime_info)
542     return true;
543
544   common_installer::ImeInfo info;
545   info.setUuid(ime_info->uuid());
546
547   const auto &languages = ime_info->languages();
548   for (const auto &language : languages)
549     info.AddLanguage(language);
550
551   context_->manifest_plugins_data.get().ime_info.set(std::move(info));
552   return true;
553 }
554
555 bool StepParse::FillExtraManifestInfo(manifest_x* manifest) {
556   return FillAccounts(manifest) && FillImeInfo() && FillAppWidget();
557 }
558
559 bool StepParse::FillManifestX(manifest_x* manifest) {
560   if (!FillIconPaths(manifest))
561     return false;
562   if (!FillMainApplicationInfo(manifest))
563     return false;
564   if (!FillWidgetInfo(manifest))
565     return false;
566   if (!FillInstallationInfo(manifest))
567     return false;
568   if (!FillPrivileges(manifest))
569     return false;
570   if (!FillAppControl(manifest))
571     return false;
572   if (!FillCategories(manifest))
573     return false;
574   if (!FillMetadata(manifest))
575     return false;
576   // TODO(t.iwanek): fix adding ui application element
577   // for now adding application service is added here because rest of code
578   // assumes that there is one application at manifest->application
579   // so this must execute last. Don't move it above any item
580   if (!FillServiceApplicationInfo(manifest))
581     return false;
582   if (!FillWidgetApplicationInfo(manifest))
583     return false;
584   if (!FillBackgroundCategoryInfo(manifest))
585     return false;
586   if (!FillExtraManifestInfo(manifest))
587     return false;
588   return true;
589 }
590
591 bool StepParse::LocateConfigFile() {
592   switch (config_location_) {
593     case ConfigLocation::PACKAGE:
594       return StepParse::Check(context_->unpacked_dir_path.get());
595     case ConfigLocation::INSTALLED:
596       return StepParse::Check(context_->pkg_path.get() / kResWgt);
597     case ConfigLocation::RECOVERY:
598       if (StepParse::Check(common_installer::GetBackupPathForPackagePath(
599           context_->root_application_path.get()
600               / context_->pkgid.get()) / kResWgt))
601         return true;
602       if (StepParse::Check(
603           context_->root_application_path.get()
604               / context_->pkgid.get() / kResWgt))
605         return true;
606       return false;
607     case ConfigLocation::RESOURCE_WGT:
608       return StepParse::Check(context_->unpacked_dir_path.get() / kResWgt);
609     default:
610       LOG(ERROR) << "Unknown config location";
611       return false;
612   }
613 }
614
615 common_installer::Step::Status StepParse::process() {
616   if (!LocateConfigFile()) {
617     LOG(ERROR) << "No config.xml";
618     return common_installer::Step::Status::MANIFEST_NOT_FOUND;
619   }
620
621   parser_.reset(new wgt::parse::WidgetConfigParser());
622   if (!parser_->ParseManifest(config_)) {
623     LOG(ERROR) << "[Parse] Parse failed. " <<  parser_->GetErrorMessage();
624     return common_installer::Step::Status::PARSE_ERROR;
625   }
626   if (check_start_file_) {
627     if (!parser_->HasValidStartFile()) {
628       LOG(ERROR) << parser_->GetErrorMessage();
629       return common_installer::Step::Status::PARSE_ERROR;
630     }
631     if (!parser_->HasValidServicesStartFiles()) {
632       LOG(ERROR) << parser_->GetErrorMessage();
633       return common_installer::Step::Status::PARSE_ERROR;
634     }
635   }
636
637   manifest_x* manifest =
638       static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
639   if (!FillManifestX(manifest)) {
640     LOG(ERROR) << "[Parse] Storing manifest_x failed. "
641                <<  parser_->GetErrorMessage();
642     return common_installer::Step::Status::PARSE_ERROR;
643   }
644
645   // Copy data from ManifestData to InstallerContext
646   auto info =
647       GetManifestDataForKey<const wgt::parse::TizenApplicationInfo>(
648               wgt::application_widget_keys::kTizenApplicationKey);
649   auto wgt_info =
650       GetManifestDataForKey<const wgt::parse::WidgetInfo>(
651               wgt::application_widget_keys::kTizenWidgetKey);
652
653   std::string name;
654   const auto& name_set = wgt_info->name_set();
655   if (name_set.find("") != name_set.end())
656     name = name_set.find("")->second;
657   if (name_set.begin() != name_set.end())
658     name = name_set.begin()->second;
659
660   std::string short_name;
661   const auto& short_name_set = wgt_info->short_name_set();
662   if (short_name_set.find("") != short_name_set.end())
663     short_name = short_name_set.find("")->second;
664   if (short_name_set.begin() != short_name_set.end())
665     short_name = short_name_set.begin()->second;
666
667   const std::string& package_version = wgt_info->version();
668   const std::string& required_api_version = info->required_version();
669
670   manifest->api_version = strdup(required_api_version.c_str());
671
672   context_->pkgid.set(manifest->package);
673
674   // write pkgid for recovery file
675   if (context_->recovery_info.get().recovery_file) {
676     context_->recovery_info.get().recovery_file->set_pkgid(manifest->package);
677     context_->recovery_info.get().recovery_file->WriteAndCommitFileContent();
678   }
679
680   auto perm_info =
681       GetManifestDataForKey<const wgt::parse::PermissionsInfo>(
682               wgt::application_widget_keys::kTizenPermissionsKey);
683   parser::PermissionSet permissions;
684   if (perm_info)
685      permissions = perm_info->GetAPIPermissions();
686
687   WgtBackendData* backend_data =
688       static_cast<WgtBackendData*>(context_->backend_data.get());
689
690   auto settings_info =
691       GetManifestDataForKey<const wgt::parse::SettingInfo>(
692               wgt::application_widget_keys::kTizenSettingKey);
693   if (settings_info)
694     backend_data->settings.set(*settings_info);
695
696   LOG(DEBUG) << " Read data -[ ";
697   LOG(DEBUG) << "App id: " << info->id();
698   LOG(DEBUG) << "  package     = " <<  info->package();
699   LOG(DEBUG) << "  id          = " <<  info->id();
700   LOG(DEBUG) << "  name        = " <<  name;
701   LOG(DEBUG) << "  short_name  = " <<  short_name;
702   LOG(DEBUG) << "  aplication version     = " <<  package_version;
703   LOG(DEBUG) << "  api_version = " <<  info->required_version();
704   LOG(DEBUG) << "  launch_mode = " <<  info->launch_mode();
705   LOG(DEBUG) << "  privileges -[";
706   for (const auto& p : permissions) {
707     LOG(DEBUG) << "    " << p;
708   }
709   LOG(DEBUG) << "  ]-";
710   LOG(DEBUG) << "]-";
711
712   // TODO(t.iwanek): In delta mode this step is running two times
713   if (context_->manifest_data.get())
714     pkgmgr_parser_free_manifest_xml(context_->manifest_data.get());
715
716   context_->manifest_data.set(manifest);
717   return common_installer::Step::Status::OK;
718 }
719
720 bool StepParse::Check(const boost::filesystem::path& widget_path) {
721   boost::filesystem::path config = widget_path / "config.xml";
722
723   LOG(DEBUG) << "config.xml path: " << config;
724
725   if (!boost::filesystem::exists(config))
726     return false;
727
728   config_ = config;
729   return true;
730 }
731
732 }  // namespace configuration
733 }  // namespace wgt