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