Fix StepParse for tizen:service icon
[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/backup_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 }
86
87 template<typename T>
88 void AppendLabel(T* root, const std::string& label,
89                  const std::string& locale) {
90   label_x* label_item = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
91   label_item->name = strdup(label.c_str());
92   label_item->text = strdup(label.c_str());
93   label_item->lang = !locale.empty() ?
94       strdup(locale.c_str()) : strdup(DEFAULT_LOCALE);
95   root->label = g_list_append(root->label, label_item);
96 }
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   std::shared_ptr<const wgt::parse::TizenApplicationInfo> app_info =
150       std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
151           parser_->GetManifestData(app_keys::kTizenApplicationKey));
152   if (!app_info) {
153     LOG(ERROR) << "Application info manifest data has not been found.";
154     return false;
155   }
156   std::shared_ptr<const wgt::parse::ApplicationIconsInfo> icons_info =
157       std::static_pointer_cast<const wgt::parse::ApplicationIconsInfo>(
158           parser_->GetManifestData(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   std::shared_ptr<const wgt::parse::WidgetInfo> wgt_info =
174       std::static_pointer_cast<const wgt::parse::WidgetInfo>(
175           parser_->GetManifestData(app_keys::kWidgetKey));
176   if (!wgt_info.get()) {
177     LOG(ERROR) << "Widget info manifest data has not been found.";
178     return false;
179   }
180
181   const std::string& version = wgt_info->version();
182
183   manifest->ns = strdup(kTizenPackageXmlNamespace);
184   manifest->version = strdup(GetPackageVersion(version).c_str());
185
186   for (auto& item : wgt_info->description_set()) {
187     description_x* description = reinterpret_cast<description_x*>
188         (calloc(1, sizeof(description_x)));
189     description->text = strdup(item.second.c_str());
190     description->lang = !item.first.empty() ?
191         strdup(item.first.c_str()) : strdup(DEFAULT_LOCALE);
192     manifest->description = g_list_append(manifest->description, description);
193   }
194
195   for (auto& item : wgt_info->name_set()) {
196     AppendLabel(manifest, item.second, item.first);
197   }
198
199   manifest->type = strdup("wgt");
200   manifest->appsetting = strdup("false");
201   manifest->nodisplay_setting = strdup("false");
202   manifest->preload = strdup("false");
203   manifest->installed_storage = strdup("installed_internal");
204
205   // For wgt package use the long name
206   for (auto& item : wgt_info->name_set()) {
207     application_x* app =
208         reinterpret_cast<application_x*>(manifest->application->data);
209     AppendLabel(app, item.second, item.first);
210   }
211
212   author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
213   if (!wgt_info->author().empty())
214     author->text = strdup(wgt_info->author().c_str());
215   if (!wgt_info->author_email().empty())
216     author->email = strdup(wgt_info->author_email().c_str());
217   if (!wgt_info->author_href().empty())
218     author->href = strdup(wgt_info->author_href().c_str());
219   author->lang = strdup(DEFAULT_LOCALE);
220   manifest->author = g_list_append(manifest->author, author);
221
222   std::shared_ptr<const wgt::parse::SettingInfo> settings_info =
223       std::static_pointer_cast<const wgt::parse::SettingInfo>(
224           parser_->GetManifestData(
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   std::shared_ptr<const wgt::parse::TizenApplicationInfo> app_info =
250       std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
251           parser_->GetManifestData(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   std::shared_ptr<const wgt::parse::CategoryInfoList> category_info =
259       std::static_pointer_cast<const wgt::parse::CategoryInfoList>(
260           parser_->GetManifestData(app_keys::kTizenCategoryKey));
261   if (category_info) {
262     has_watch_catergory = std::find_if(category_info->categories.begin(),
263                                        category_info->categories.end(),
264                                        [](const std::string& category) {
265       return category == kCategoryWearableClock ||
266              category == kCategoryWatchClock;
267     }) != category_info->categories.end();
268     has_ime = std::find(category_info->categories.begin(),
269                                        category_info->categories.end(),
270                                        kImeCategoryName)
271         != category_info->categories.end();
272   }
273
274   // application data
275   application_x* application = reinterpret_cast<application_x*>(
276       calloc(1, sizeof(application_x)));
277   application->component_type =
278       has_watch_catergory ? strdup("watchapp") : strdup("uiapp");
279   application->mainapp = strdup("true");
280   application->multiple = strdup("false");
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   manifest->application = g_list_append(manifest->application, application);
308
309   manifest->package = strdup(app_info->package().c_str());
310   manifest->mainapp_id = strdup(app_info->id().c_str());
311   return true;
312 }
313
314 bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) {
315   std::shared_ptr<const wgt::parse::ServiceList> service_list =
316       std::static_pointer_cast<const wgt::parse::ServiceList>(
317           parser_->GetManifestData(app_keys::kTizenServiceKey));
318   if (!service_list)
319     return true;
320   for (auto& service_info : service_list->services) {
321     application_x* application = reinterpret_cast<application_x*>
322         (calloc(1, sizeof(application_x)));
323     application->component_type = strdup("svcapp");
324     application->mainapp = strdup("false");
325     application->multiple = 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   std::shared_ptr<const wgt::parse::AppWidgetInfo> appwidget_info =
377       std::static_pointer_cast<const wgt::parse::AppWidgetInfo>(
378           parser_->GetManifestData(
379               wgt::application_widget_keys::kTizenAppWidgetFullKey));
380   if (!appwidget_info)
381     return true;
382   for (auto& app_widget : appwidget_info->app_widgets()) {
383     application_x* application = reinterpret_cast<application_x*>
384         (calloc(1, sizeof(application_x)));
385     application->component_type = strdup("widgetapp");
386     application->mainapp = strdup("false");
387     application->multiple = strdup("false");
388     application->appid = strdup(app_widget.id.c_str());
389     application->exec =
390         strdup((context_->root_application_path.get() / manifest->package
391                 / "bin" / application->appid).c_str());
392     application->type = strdup("webapp");
393     application->nodisplay = strdup("false");
394     application->taskmanage = strdup("false");
395     SetApplicationXDefaults(application);
396     application->ambient_support = strdup("false");
397     application->package = strdup(manifest->package);
398
399     if (!app_widget.label.default_value.empty()) {
400       AppendLabel(application, app_widget.label.default_value, std::string());
401     }
402
403     for (auto& pair : app_widget.label.lang_value_map) {
404       AppendLabel(application, pair.second, pair.first);
405     }
406
407     if (!app_widget.icon_src.empty()) {
408       icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
409       icon->text = strdup(app_widget.icon_src.c_str());
410       icon->lang = strdup(DEFAULT_LOCALE);
411       application->icon = g_list_append(application->icon, icon);
412     }
413
414     manifest->application = g_list_append(manifest->application, application);
415   }
416   return true;
417 }
418
419
420 bool StepParse::FillBackgroundCategoryInfo(manifest_x* manifest) {
421   auto manifest_data = parser_->GetManifestData(
422       app_keys::kTizenBackgroundCategoryKey);
423   std::shared_ptr<const wgt::parse::BackgroundCategoryInfoList> bc_list =
424       std::static_pointer_cast<const wgt::parse::BackgroundCategoryInfoList>(
425           manifest_data);
426
427   if (!bc_list)
428     return true;
429
430   application_x* app =
431       reinterpret_cast<application_x*>(manifest->application->data);
432
433   for (auto& background_category : bc_list->background_categories) {
434     app->background_category = g_list_append(
435         app->background_category, strdup(background_category.value().c_str()));
436   }
437
438   return true;
439 }
440
441 bool StepParse::FillAppControl(manifest_x* manifest) {
442   std::shared_ptr<const wgt::parse::AppControlInfoList> app_info_list =
443       std::static_pointer_cast<const wgt::parse::AppControlInfoList>(
444           parser_->GetManifestData(app_keys::kTizenApplicationAppControlsKey));
445
446   application_x* app =
447       reinterpret_cast<application_x*>(manifest->application->data);
448   if (app_info_list) {
449     for (const auto& control : app_info_list->controls) {
450       appcontrol_x* app_control =
451           static_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
452       app_control->operation = strdup(control.operation().c_str());
453       app_control->mime = strdup(control.mime().c_str());
454       app_control->uri = strdup(control.uri().c_str());
455       app->appcontrol = g_list_append(app->appcontrol, app_control);
456     }
457   }
458   return true;
459 }
460
461 bool StepParse::FillPrivileges(manifest_x* manifest) {
462   std::shared_ptr<const wgt::parse::PermissionsInfo> perm_info =
463       std::static_pointer_cast<const wgt::parse::PermissionsInfo>(
464           parser_->GetManifestData(app_keys::kTizenPermissionsKey));
465   std::set<std::string> privileges;
466   if (perm_info)
467     privileges = ExtractPrivileges(perm_info);
468
469   for (auto& priv : privileges) {
470     manifest->privileges =
471         g_list_append(manifest->privileges, strdup(priv.c_str()));
472   }
473   return true;
474 }
475
476 bool StepParse::FillCategories(manifest_x* manifest) {
477   std::shared_ptr<const wgt::parse::CategoryInfoList> category_info =
478       std::static_pointer_cast<const wgt::parse::CategoryInfoList>(
479           parser_->GetManifestData(app_keys::kTizenCategoryKey));
480   if (!category_info)
481     return true;
482
483   application_x* app =
484       reinterpret_cast<application_x*>(manifest->application->data);
485   // there is one app atm
486   for (auto& category : category_info->categories) {
487     app->category = g_list_append(app->category, strdup(category.c_str()));
488   }
489   return true;
490 }
491
492 bool StepParse::FillMetadata(manifest_x* manifest) {
493   std::shared_ptr<const wgt::parse::MetaDataInfo> meta_info =
494       std::static_pointer_cast<const wgt::parse::MetaDataInfo>(
495           parser_->GetManifestData(app_keys::kTizenMetaDataKey));
496   if (!meta_info)
497     return true;
498
499   for (application_x* app : GListRange<application_x*>(manifest->application)) {
500     app->metadata = GenerateMetadataListX(*meta_info);
501   }
502   return true;
503 }
504
505 bool StepParse::FillAppWidget() {
506   // This is needed to store preview icons which are not saved into manifest_x
507   WgtBackendData* backend_data =
508       static_cast<WgtBackendData*>(context_->backend_data.get());
509
510   std::shared_ptr<const wgt::parse::AppWidgetInfo> appwidget_info =
511       std::static_pointer_cast<const wgt::parse::AppWidgetInfo>(
512           parser_->GetManifestData(
513               wgt::application_widget_keys::kTizenAppWidgetFullKey));
514   if (appwidget_info)
515     backend_data->appwidgets.set(*appwidget_info);
516   return true;
517 }
518
519 bool StepParse::FillAccounts(manifest_x* manifest) {
520   std::shared_ptr<const wgt::parse::AccountInfo> account_info =
521       std::static_pointer_cast<const wgt::parse::AccountInfo>(
522           parser_->GetManifestData(app_keys::kAccountKey));
523   if (!account_info)
524     return true;
525   common_installer::AccountInfo info;
526   for (auto& account : account_info->accounts()) {
527     common_installer::SingleAccountInfo single_info;
528     single_info.capabilities = account.capabilities;
529     single_info.icon_paths = account.icon_paths;
530     single_info.multiple_account_support = account.multiple_account_support;
531     single_info.names = account.names;
532     // wgt can contain only one app so this assumes mainapp_id is valid here
533     single_info.appid = manifest->mainapp_id;
534     info.set_account(single_info);
535   }
536   context_->manifest_plugins_data.get().account_info.set(info);
537   return true;
538 }
539
540 bool StepParse::FillImeInfo() {
541   const auto ime_info = std::static_pointer_cast<const wgt::parse::ImeInfo>(
542       parser_->GetManifestData(app_keys::kTizenImeKey));
543   if (!ime_info)
544     return true;
545
546   common_installer::ImeInfo info;
547   info.setUuid(ime_info->uuid());
548
549   const auto &languages = ime_info->languages();
550   for (const auto &language : languages)
551     info.AddLanguage(language);
552
553   context_->manifest_plugins_data.get().ime_info.set(std::move(info));
554   return true;
555 }
556
557 bool StepParse::FillExtraManifestInfo(manifest_x* manifest) {
558   return FillAccounts(manifest) && FillImeInfo() && FillAppWidget();
559 }
560
561 bool StepParse::FillManifestX(manifest_x* manifest) {
562   if (!FillIconPaths(manifest))
563     return false;
564   if (!FillMainApplicationInfo(manifest))
565     return false;
566   if (!FillWidgetInfo(manifest))
567     return false;
568   if (!FillInstallationInfo(manifest))
569     return false;
570   if (!FillPrivileges(manifest))
571     return false;
572   if (!FillAppControl(manifest))
573     return false;
574   if (!FillCategories(manifest))
575     return false;
576   if (!FillMetadata(manifest))
577     return false;
578   // TODO(t.iwanek): fix adding ui application element
579   // for now adding application service is added here because rest of code
580   // assumes that there is one application at manifest->application
581   // so this must execute last. Don't move it above any item
582   if (!FillServiceApplicationInfo(manifest))
583     return false;
584   if (!FillWidgetApplicationInfo(manifest))
585     return false;
586   if (!FillBackgroundCategoryInfo(manifest))
587     return false;
588   if (!FillExtraManifestInfo(manifest))
589     return false;
590   return true;
591 }
592
593 bool StepParse::LocateConfigFile() {
594   switch (config_location_) {
595     case ConfigLocation::PACKAGE:
596       return StepParse::Check(context_->unpacked_dir_path.get());
597     case ConfigLocation::INSTALLED:
598       return StepParse::Check(context_->pkg_path.get() / kResWgt);
599     case ConfigLocation::RECOVERY:
600       if (StepParse::Check(common_installer::GetBackupPathForPackagePath(
601           context_->root_application_path.get()
602               / context_->pkgid.get()) / kResWgt))
603         return true;
604       if (StepParse::Check(
605           context_->root_application_path.get()
606               / context_->pkgid.get() / kResWgt))
607         return true;
608       return false;
609     case ConfigLocation::RESOURCE_WGT:
610       return StepParse::Check(context_->unpacked_dir_path.get() / kResWgt);
611     default:
612       LOG(ERROR) << "Unknown config location";
613       return false;
614   }
615 }
616
617 common_installer::Step::Status StepParse::process() {
618   if (!LocateConfigFile()) {
619     LOG(ERROR) << "No config.xml";
620     return common_installer::Step::Status::MANIFEST_NOT_FOUND;
621   }
622
623   parser_.reset(new wgt::parse::WidgetConfigParser());
624   if (!parser_->ParseManifest(config_)) {
625     LOG(ERROR) << "[Parse] Parse failed. " <<  parser_->GetErrorMessage();
626     return common_installer::Step::Status::PARSE_ERROR;
627   }
628   if (check_start_file_) {
629     if (!parser_->HasValidStartFile()) {
630       LOG(ERROR) << parser_->GetErrorMessage();
631       return common_installer::Step::Status::PARSE_ERROR;
632     }
633     if (!parser_->HasValidServicesStartFiles()) {
634       LOG(ERROR) << parser_->GetErrorMessage();
635       return common_installer::Step::Status::PARSE_ERROR;
636     }
637   }
638
639   manifest_x* manifest =
640       static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
641   if (!FillManifestX(manifest)) {
642     LOG(ERROR) << "[Parse] Storing manifest_x failed. "
643                <<  parser_->GetErrorMessage();
644     return common_installer::Step::Status::PARSE_ERROR;
645   }
646
647   // Copy data from ManifestData to InstallerContext
648   std::shared_ptr<const wgt::parse::TizenApplicationInfo> info =
649       std::static_pointer_cast<const wgt::parse::TizenApplicationInfo>(
650           parser_->GetManifestData(
651               wgt::application_widget_keys::kTizenApplicationKey));
652   std::shared_ptr<const wgt::parse::WidgetInfo> wgt_info =
653       std::static_pointer_cast<const wgt::parse::WidgetInfo>(
654           parser_->GetManifestData(
655               wgt::application_widget_keys::kTizenWidgetKey));
656
657   std::string name;
658   const auto& name_set = wgt_info->name_set();
659   if (name_set.find("") != name_set.end())
660     name = name_set.find("")->second;
661   if (name_set.begin() != name_set.end())
662     name = name_set.begin()->second;
663
664   std::string short_name;
665   const auto& short_name_set = wgt_info->short_name_set();
666   if (short_name_set.find("") != short_name_set.end())
667     short_name = short_name_set.find("")->second;
668   if (short_name_set.begin() != short_name_set.end())
669     short_name = short_name_set.begin()->second;
670
671   const std::string& package_version = wgt_info->version();
672   const std::string& required_api_version = info->required_version();
673
674   manifest->api_version = strdup(required_api_version.c_str());
675
676   context_->pkgid.set(manifest->package);
677
678   // write pkgid for recovery file
679   if (context_->recovery_info.get().recovery_file) {
680     context_->recovery_info.get().recovery_file->set_pkgid(manifest->package);
681     context_->recovery_info.get().recovery_file->WriteAndCommitFileContent();
682   }
683
684   std::shared_ptr<const wgt::parse::PermissionsInfo> perm_info =
685       std::static_pointer_cast<const wgt::parse::PermissionsInfo>(
686           parser_->GetManifestData(
687               wgt::application_widget_keys::kTizenPermissionsKey));
688   parser::PermissionSet permissions;
689   if (perm_info)
690      permissions = perm_info->GetAPIPermissions();
691
692   WgtBackendData* backend_data =
693       static_cast<WgtBackendData*>(context_->backend_data.get());
694
695   std::shared_ptr<const wgt::parse::SettingInfo> settings_info =
696       std::static_pointer_cast<const wgt::parse::SettingInfo>(
697           parser_->GetManifestData(
698               wgt::application_widget_keys::kTizenSettingKey));
699   if (settings_info)
700     backend_data->settings.set(*settings_info);
701
702   LOG(DEBUG) << " Read data -[ ";
703   LOG(DEBUG) << "App id: " << info->id();
704   LOG(DEBUG) << "  package     = " <<  info->package();
705   LOG(DEBUG) << "  id          = " <<  info->id();
706   LOG(DEBUG) << "  name        = " <<  name;
707   LOG(DEBUG) << "  short_name  = " <<  short_name;
708   LOG(DEBUG) << "  aplication version     = " <<  package_version;
709   LOG(DEBUG) << "  api_version = " <<  info->required_version();
710   LOG(DEBUG) << "  launch_mode = " <<  info->launch_mode();
711   LOG(DEBUG) << "  privileges -[";
712   for (const auto& p : permissions) {
713     LOG(DEBUG) << "    " << p;
714   }
715   LOG(DEBUG) << "  ]-";
716   LOG(DEBUG) << "]-";
717
718   // TODO(t.iwanek): In delta mode this step is running two times
719   if (context_->manifest_data.get())
720     pkgmgr_parser_free_manifest_xml(context_->manifest_data.get());
721
722   context_->manifest_data.set(manifest);
723   return common_installer::Step::Status::OK;
724 }
725
726 bool StepParse::Check(const boost::filesystem::path& widget_path) {
727   boost::filesystem::path config = widget_path / "config.xml";
728
729   LOG(DEBUG) << "config.xml path: " << config;
730
731   if (!boost::filesystem::exists(config))
732     return false;
733
734   config_ = config;
735   return true;
736 }
737
738 }  // namespace configuration
739 }  // namespace wgt