abae81c9cd430e423dfe68aa1a164aced93a4747
[platform/core/appfw/wgt-backend.git] / src / wgt / step / pkgmgr / step_generate_xml.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/pkgmgr/step_generate_xml.h"
7
8 #include <boost/filesystem/path.hpp>
9 #include <boost/system/error_code.hpp>
10
11 #include <common/utils/file_util.h>
12 #include <common/utils/glist_range.h>
13 #include <common/privileges.h>
14
15 #include <libxml/parser.h>
16 #include <libxml/xmlreader.h>
17 #include <pkgmgr-info.h>
18 #include <pkgmgr_parser.h>
19 #include <tzplatform_config.h>
20 #include <unistd.h>
21
22 #include <cassert>
23 #include <cstring>
24 #include <string>
25
26 #include "wgt/utils/wgt_backend_data.h"
27
28 namespace bs = boost::system;
29 namespace bf = boost::filesystem;
30
31 namespace {
32
33 const char kResWgt[] = "res/wgt";
34 const char kSharedRes[] = "shared/res";
35
36 void WriteUIApplicationAttributes(
37     xmlTextWriterPtr writer, application_x *app) {
38   if (app->taskmanage)
39     xmlTextWriterWriteAttribute(writer, BAD_CAST "taskmanage",
40         BAD_CAST app->taskmanage);
41   if (app->nodisplay)
42     xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay",
43         BAD_CAST app->nodisplay);
44   if (app->multiple)
45     xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple",
46         BAD_CAST app->multiple);
47   if (app->launch_mode && strlen(app->launch_mode))
48     xmlTextWriterWriteAttribute(writer, BAD_CAST "launch_mode",
49         BAD_CAST app->launch_mode);
50   if (app->ui_gadget && strlen(app->ui_gadget))
51     xmlTextWriterWriteAttribute(writer, BAD_CAST "ui-gadget",
52         BAD_CAST app->ui_gadget);
53   if (app->submode && strlen(app->submode))
54     xmlTextWriterWriteAttribute(writer, BAD_CAST "submode",
55         BAD_CAST app->submode);
56   if (app->submode_mainid && strlen(app->submode_mainid))
57     xmlTextWriterWriteAttribute(writer, BAD_CAST "submode-mainid",
58         BAD_CAST app->submode_mainid);
59   if (app->indicatordisplay && strlen(app->indicatordisplay))
60     xmlTextWriterWriteAttribute(writer, BAD_CAST "indicatordisplay",
61         BAD_CAST app->indicatordisplay);
62   if (app->portraitimg && strlen(app->portraitimg))
63     xmlTextWriterWriteAttribute(writer, BAD_CAST "portrait-effectimage",
64         BAD_CAST app->portraitimg);
65   if (app->landscapeimg && strlen(app->landscapeimg))
66     xmlTextWriterWriteAttribute(writer, BAD_CAST "landscape-effectimage",
67         BAD_CAST app->landscapeimg);
68   if (app->effectimage_type && strlen(app->effectimage_type))
69     xmlTextWriterWriteAttribute(writer, BAD_CAST "effectimage-type",
70         BAD_CAST app->effectimage_type);
71   if (app->hwacceleration && strlen(app->hwacceleration))
72     xmlTextWriterWriteAttribute(writer, BAD_CAST "hwacceleration",
73         BAD_CAST app->hwacceleration);
74 }
75
76 void WriteServiceApplicationAttributes(
77     xmlTextWriterPtr writer, application_x *app) {
78   xmlTextWriterWriteAttribute(writer, BAD_CAST "auto-restart",
79       BAD_CAST(app->autorestart ? app->autorestart : "false"));
80   xmlTextWriterWriteAttribute(writer, BAD_CAST "on-boot",
81       BAD_CAST(app->onboot ? app->onboot : "false"));
82   if (app->taskmanage)
83       xmlTextWriterWriteAttribute(writer, BAD_CAST "taskmanage",
84          BAD_CAST app->taskmanage);
85 }
86
87 bool WriteWidgetApplicationAttributesAndElements(
88     xmlTextWriterPtr writer, application_x *app,
89     const wgt::parse::AppWidgetInfo& widget_info,
90     const bf::path& shared_path) {
91   if (app->nodisplay)
92     xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay",
93         BAD_CAST app->nodisplay);
94   if (app->multiple)
95     xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple",
96         BAD_CAST app->multiple);
97   if (app->mainapp)
98     xmlTextWriterWriteAttribute(writer, BAD_CAST "main",
99         BAD_CAST app->mainapp);
100
101   auto& appwidgets = widget_info.app_widgets();
102   const auto& appwidget = std::find_if(appwidgets.begin(), appwidgets.end(),
103                                  [app](const wgt::parse::AppWidget& widget) {
104                                     return widget.id == app->appid;
105                                  });
106   if (appwidget == appwidgets.end())
107     return true;
108
109   // Add extra elements for wgt widget-application
110   if (!appwidget->update_period.empty()) {
111         xmlTextWriterWriteAttribute(writer, BAD_CAST "update-period", BAD_CAST
112             std::to_string(static_cast<int>(
113                     appwidget->update_period.front())).c_str());
114   }
115
116   xmlTextWriterWriteAttribute(writer, BAD_CAST "max-instance",
117       BAD_CAST std::to_string(appwidget->max_instance).c_str());
118
119   for (auto& size : appwidget->content_size) {
120     xmlTextWriterStartElement(writer, BAD_CAST "support-size");
121
122     std::string type = wgt::parse::AppWidgetSizeTypeToString(size.type);
123     if (!size.preview.empty()) {
124       std::string icon_name = shared_path.string() + "/"
125           + appwidget->id + "." + type + "." + "preview" +
126           bf::path(size.preview).extension().string();
127       xmlTextWriterWriteAttribute(writer, BAD_CAST "preview",
128           BAD_CAST icon_name.c_str());  // NOLINT
129     }
130
131     xmlTextWriterWriteAttribute(writer, BAD_CAST "frame",
132                                 BAD_CAST "true");
133     xmlTextWriterWriteString(writer,
134         BAD_CAST type.c_str());
135     xmlTextWriterEndElement(writer);
136   }
137
138   for (auto& pair : appwidget->metadata) {
139     xmlTextWriterStartElement(writer, BAD_CAST "metadata");
140     xmlTextWriterWriteAttribute(writer, BAD_CAST "key",
141                                 BAD_CAST pair.first.c_str());
142     if (!pair.second.empty())
143       xmlTextWriterWriteAttribute(writer, BAD_CAST "value",
144                                   BAD_CAST pair.second.c_str());
145     xmlTextWriterEndElement(writer);
146   }
147   return true;
148 }
149
150 void WriteWatchApplicationAttributes(
151     xmlTextWriterPtr writer, application_x* app) {
152   if (app->support_ambient)
153     xmlTextWriterWriteAttribute(writer, BAD_CAST "ambient-support",
154         BAD_CAST app->support_ambient);
155 }
156
157 }  // namespace
158
159 namespace wgt {
160 namespace pkgmgr {
161
162 common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml(
163     application_x* app, xmlTextWriterPtr writer, AppCompType type) {
164   xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", BAD_CAST app->appid);
165
166   // binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
167   bf::path exec_path = context_->GetPkgPath()
168       / bf::path("bin") / bf::path(app->appid);
169   xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
170                               BAD_CAST exec_path.string().c_str());
171   if (app->type)
172     xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST app->type);
173   else
174     xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST "capp");
175
176   if (app->process_pool && strlen(app->process_pool))
177     xmlTextWriterWriteAttribute(writer, BAD_CAST "process-pool",
178                                 BAD_CAST app->process_pool);
179   // app-specific attributes
180   switch (type) {
181   case AppCompType::UIAPP:
182     WriteUIApplicationAttributes(writer, app);
183     break;
184   case AppCompType::SVCAPP:
185     WriteServiceApplicationAttributes(writer, app);
186     break;
187   case AppCompType::WIDGETAPP:
188     if (!WriteWidgetApplicationAttributesAndElements(writer, app,
189         static_cast<WgtBackendData*>(
190             context_->backend_data.get())->appwidgets.get(),
191         context_->GetPkgPath() / "shared" / "res"))
192       return Status::MANIFEST_ERROR;
193     break;
194   case AppCompType::WATCHAPP:
195     WriteWatchApplicationAttributes(writer, app);
196     break;
197   }
198
199   for (label_x* label : GListRange<label_x*>(app->label)) {
200     if (label->name && strcmp(label->name, "") != 0) {
201       xmlTextWriterStartElement(writer, BAD_CAST "label");
202       if (label->lang && strcmp(DEFAULT_LOCALE, label->lang) != 0) {
203         xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
204                                     BAD_CAST label->lang);
205       }
206       xmlTextWriterWriteString(writer, BAD_CAST label->name);
207       xmlTextWriterEndElement(writer);
208     }
209   }
210
211   for (auto& icon : GListRange<icon_x*>(app->icon)) {
212     xmlTextWriterStartElement(writer, BAD_CAST "icon");
213     if (icon->lang && strcmp(DEFAULT_LOCALE, icon->lang) != 0) {
214       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
215                                   BAD_CAST icon->lang);
216     }
217     xmlTextWriterWriteString(writer, BAD_CAST icon->text);
218     xmlTextWriterEndElement(writer);
219   }
220
221   for (image_x* image : GListRange<image_x*>(app->image)) {
222     xmlTextWriterStartElement(writer, BAD_CAST "image");
223     if (image->lang && strcmp(DEFAULT_LOCALE, image->lang) != 0) {
224       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
225
226                                   BAD_CAST image->lang);
227     }
228     if (image->section)
229       xmlTextWriterWriteAttribute(writer, BAD_CAST "section",
230                                   BAD_CAST image->section);
231     xmlTextWriterEndElement(writer);
232   }
233
234   for (appcontrol_x* appc : GListRange<appcontrol_x*>(app->appcontrol)) {
235     xmlTextWriterStartElement(writer, BAD_CAST "app-control");
236
237     if (appc->operation) {
238       xmlTextWriterStartElement(writer, BAD_CAST "operation");
239       xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
240           BAD_CAST appc->operation);
241       xmlTextWriterEndElement(writer);
242     }
243
244     if (appc->uri) {
245       xmlTextWriterStartElement(writer, BAD_CAST "uri");
246       xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
247           BAD_CAST appc->uri);
248       xmlTextWriterEndElement(writer);
249     }
250
251     if (appc->mime) {
252       xmlTextWriterStartElement(writer, BAD_CAST "mime");
253       xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
254           BAD_CAST appc->mime);
255       xmlTextWriterEndElement(writer);
256     }
257
258     xmlTextWriterEndElement(writer);
259   }
260
261   for (datacontrol_x* datacontrol :
262        GListRange<datacontrol_x*>(app->datacontrol)) {
263     xmlTextWriterStartElement(writer, BAD_CAST "datacontrol");
264     if (datacontrol->access) {
265       xmlTextWriterWriteAttribute(writer, BAD_CAST "access",
266           BAD_CAST datacontrol->access);
267     }
268     if (datacontrol->providerid) {
269       xmlTextWriterWriteAttribute(writer, BAD_CAST "providerid",
270           BAD_CAST datacontrol->providerid);
271     }
272     if (datacontrol->type) {
273       xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
274           BAD_CAST datacontrol->type);
275     }
276     xmlTextWriterEndElement(writer);
277   }
278
279   for (metadata_x* meta : GListRange<metadata_x*>(app->metadata)) {
280     xmlTextWriterStartElement(writer, BAD_CAST "metadata");
281     xmlTextWriterWriteAttribute(writer, BAD_CAST "key",
282         BAD_CAST meta->key);
283     if (meta->value)
284       xmlTextWriterWriteAttribute(writer, BAD_CAST "value",
285           BAD_CAST meta->value);
286     xmlTextWriterEndElement(writer);
287   }
288
289   for (const char* category : GListRange<char*>(app->category)) {
290     xmlTextWriterStartElement(writer, BAD_CAST "category");
291     xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST category);
292     xmlTextWriterEndElement(writer);
293   }
294
295   for (const char* background_category : GListRange<char*>(
296       app->background_category)) {
297     xmlTextWriterStartElement(writer, BAD_CAST "background-category");
298     xmlTextWriterWriteAttribute(writer, BAD_CAST "value",
299         BAD_CAST background_category);
300     xmlTextWriterEndElement(writer);
301   }
302
303   return Step::Status::OK;
304 }
305
306 common_installer::Step::Status StepGenerateXml::undo() {
307   common_installer::RequestType req_type = context_->request_type.get();
308   if (req_type == common_installer::RequestType::ManifestDirectUpdate ||
309       req_type == common_installer::RequestType::ManifestPartialUpdate)
310     return Status::OK;
311   common_installer::RemoveAll(context_->xml_path.get());
312   return Status::OK;
313 }
314
315 common_installer::Step::Status StepGenerateXml::precheck() {
316   if (!context_->manifest_data.get()) {
317     LOG(ERROR) << "manifest_data attribute is empty";
318     return Step::Status::INVALID_VALUE;
319   }
320   if (context_->pkgid.get().empty()) {
321     LOG(ERROR) << "pkgid attribute is empty";
322     return Step::Status::PACKAGE_NOT_FOUND;
323   }
324
325   return Step::Status::OK;
326 }
327
328 common_installer::Step::Status StepGenerateXml::process() {
329   bf::path xml_path =
330       bf::path(getUserManifestPath(context_->uid.get(),
331                   context_->is_readonly_package.get()))
332       / bf::path(context_->pkgid.get());
333   xml_path += ".xml";
334   context_->xml_path.set(xml_path.string());
335
336   bs::error_code error;
337   if (!bf::exists(xml_path.parent_path(), error)) {
338     if (!common_installer::CreateDir(xml_path.parent_path())) {
339       LOG(ERROR) <<
340           "Directory for manifest xml is missing and cannot be created";
341       return Status::MANIFEST_ERROR;
342     }
343   }
344
345   xmlTextWriterPtr writer;
346   writer = xmlNewTextWriterFilename(context_->xml_path.get().c_str(), 0);
347   if (!writer) {
348     LOG(ERROR) << "Failed to create new file";
349     return Step::Status::MANIFEST_ERROR;
350   }
351
352   xmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr);
353   xmlTextWriterSetIndent(writer, 1);
354
355   Status status = GenerateManifestElement(writer);
356   if (status != Status::OK)
357     return status;
358
359   xmlTextWriterEndDocument(writer);
360   xmlFreeTextWriter(writer);
361
362   if (pkgmgr_parser_check_manifest_validation(
363       context_->xml_path.get().c_str()) != 0) {
364     LOG(ERROR) << "Manifest is not valid";
365     return Step::Status::MANIFEST_ERROR;
366   }
367
368   LOG(DEBUG) << "Successfully create manifest xml "
369       << context_->xml_path.get();
370   return Status::OK;
371 }
372
373 common_installer::Step::Status StepGenerateXml::GenerateManifestElement(
374         xmlTextWriterPtr writer) {
375   xmlTextWriterStartElement(writer, BAD_CAST "manifest");
376
377   GenerateManifestElementAttributes(writer);
378   GenerateLangLabels(writer);
379   GenerateAuthor(writer);
380   GenerateDescription(writer);
381   Status status = GenerateApplications(writer);
382   if (status != Status::OK)
383     return status;
384
385   GeneratePrivilege(writer);
386   GenerateProvidesAppDefinedPrivilege(writer);
387   GenerateAccount(writer);
388   GenerateIme(writer);
389   GenerateProfiles(writer);
390   GenerateShortcuts(writer);
391   GenerateTrustAnchor(writer);
392   xmlTextWriterEndElement(writer);
393   return Status::OK;
394 }
395
396 void StepGenerateXml::GenerateManifestElementAttributes(
397         xmlTextWriterPtr writer) {
398   xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns",
399       BAD_CAST "http://tizen.org/ns/packages");
400   xmlTextWriterWriteAttribute(writer, BAD_CAST "package",
401       BAD_CAST context_->manifest_data.get()->package);
402   xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
403       BAD_CAST context_->manifest_data.get()->type);
404   xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
405       BAD_CAST context_->manifest_data.get()->version);
406   xmlTextWriterWriteAttribute(writer, BAD_CAST "api-version",
407       BAD_CAST context_->manifest_data.get()->api_version);
408   xmlTextWriterWriteAttribute(writer, BAD_CAST "nodisplay-setting",
409       BAD_CAST context_->manifest_data.get()->nodisplay_setting);
410   if (context_->is_readonly_package.get()) {
411     xmlTextWriterWriteAttribute(writer, BAD_CAST "readonly", BAD_CAST "true");
412     xmlTextWriterWriteAttribute(writer, BAD_CAST "preload", BAD_CAST "true");
413   } else if (context_->is_preload_rw_package.get()) {
414     xmlTextWriterWriteAttribute(writer, BAD_CAST "preload", BAD_CAST "true");
415   }
416 }
417
418 void StepGenerateXml::GenerateLangLabels(xmlTextWriterPtr writer) {
419   for (label_x* label :
420        GListRange<label_x*>(context_->manifest_data.get()->label)) {
421     if (label->name && strcmp(label->name, "") != 0) {
422       xmlTextWriterStartElement(writer, BAD_CAST "label");
423       if (label->lang && strcmp(DEFAULT_LOCALE, label->lang) != 0) {
424       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
425                                     BAD_CAST label->lang);
426       }
427       xmlTextWriterWriteString(writer, BAD_CAST label->name);
428       xmlTextWriterEndElement(writer);
429     }
430   }
431 }
432
433 void StepGenerateXml::GenerateAuthor(xmlTextWriterPtr writer) {
434   for (author_x* author :
435        GListRange<author_x*>(context_->manifest_data.get()->author)) {
436     xmlTextWriterStartElement(writer, BAD_CAST "author");
437     if (author->email && strlen(author->email)) {
438       xmlTextWriterWriteAttribute(writer, BAD_CAST "email",
439                                   BAD_CAST author->email);
440     }
441     if (author->href && strlen(author->href)) {
442       xmlTextWriterWriteAttribute(writer, BAD_CAST "href",
443                                   BAD_CAST author->href);
444     }
445     xmlTextWriterWriteString(writer, BAD_CAST author->text);
446     xmlTextWriterEndElement(writer);
447   }
448 }
449
450 void StepGenerateXml::GenerateDescription(xmlTextWriterPtr writer) {
451   for (description_x* description :
452        GListRange<description_x*>(context_->manifest_data.get()->description)) {
453     xmlTextWriterStartElement(writer, BAD_CAST "description");
454     if (description->lang && strcmp(DEFAULT_LOCALE, description->lang) != 0) {
455       xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
456                                   BAD_CAST description->lang);
457     }
458     xmlTextWriterWriteString(writer, BAD_CAST description->text);
459     xmlTextWriterEndElement(writer);
460   }
461 }
462
463 common_installer::Step::Status StepGenerateXml::GenerateApplications(
464         xmlTextWriterPtr writer) {
465   for (application_x* app :
466        GListRange<application_x*>(context_->manifest_data.get()->application)) {
467     AppCompType type;
468     if (strcmp(app->component_type, "uiapp") == 0) {
469       type = AppCompType::UIAPP;
470       xmlTextWriterStartElement(writer, BAD_CAST "ui-application");
471     } else if (strcmp(app->component_type, "svcapp") == 0) {
472       type = AppCompType::SVCAPP;
473       xmlTextWriterStartElement(writer, BAD_CAST "service-application");
474     } else if (strcmp(app->component_type, "widgetapp") == 0) {
475       type = AppCompType::WIDGETAPP;
476       xmlTextWriterStartElement(writer, BAD_CAST "widget-application");
477     } else if (strcmp(app->component_type, "watchapp") == 0) {
478       type = AppCompType::WATCHAPP;
479       xmlTextWriterStartElement(writer, BAD_CAST "watch-application");
480     } else {
481       LOG(ERROR) << "Unknown application component_type";
482       xmlFreeTextWriter(writer);
483       return Status::ERROR;
484     }
485     Status status = GenerateApplicationCommonXml(app, writer, type);
486     if (status != Status::OK) {
487       xmlFreeTextWriter(writer);
488       return status;
489     }
490     xmlTextWriterEndElement(writer);
491   }
492   return Status::OK;
493 }
494
495 void StepGenerateXml::GeneratePrivilege(xmlTextWriterPtr writer) {
496   if (context_->manifest_data.get()->privileges) {
497     xmlTextWriterStartElement(writer, BAD_CAST "privileges");
498     for (privilege_x* priv :
499          GListRange<privilege_x*>(context_->manifest_data.get()->privileges)) {
500       xmlTextWriterStartElement(writer, BAD_CAST "privilege");
501       xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
502                                   BAD_CAST priv->type);
503       xmlTextWriterWriteString(writer, BAD_CAST priv->value);
504       xmlTextWriterEndElement(writer);
505     }
506     if (context_->manifest_data.get()->appdefined_privileges) {
507       for (appdefined_privilege_x* priv : GListRange<appdefined_privilege_x*>(
508            context_->manifest_data.get()->appdefined_privileges)) {
509         xmlTextWriterStartElement(writer, BAD_CAST "appdefined-privilege");
510         xmlTextWriterWriteAttribute(writer, BAD_CAST "license",
511                                     BAD_CAST priv->license);
512         xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
513                                     BAD_CAST priv->type);
514         xmlTextWriterWriteString(writer, BAD_CAST priv->value);
515         xmlTextWriterEndElement(writer);
516       }
517     }
518     xmlTextWriterEndElement(writer);
519   }
520 }
521
522 void StepGenerateXml::GenerateProvidesAppDefinedPrivilege(
523     xmlTextWriterPtr writer) {
524   if (context_->manifest_data.get()->provides_appdefined_privileges) {
525     xmlTextWriterStartElement(writer,
526                               BAD_CAST "provides-appdefined-privileges");
527     for (appdefined_privilege_x* priv : GListRange<appdefined_privilege_x*>(
528          context_->manifest_data.get()->provides_appdefined_privileges)) {
529       xmlTextWriterStartElement(writer, BAD_CAST "appdefined-privilege");
530       xmlTextWriterWriteAttribute(writer, BAD_CAST "license",
531                                   BAD_CAST priv->license);
532       xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
533                                   BAD_CAST priv->type);
534       xmlTextWriterWriteString(writer, BAD_CAST priv->value);
535       xmlTextWriterEndElement(writer);
536     }
537     xmlTextWriterEndElement(writer);
538   }
539 }
540
541 void StepGenerateXml::GenerateAccount(xmlTextWriterPtr writer) {
542   const auto& accounts =
543       context_->manifest_plugins_data.get().account_info.get().accounts();
544   if (!accounts.empty()) {
545     xmlTextWriterStartElement(writer, BAD_CAST "account");
546     // add account info
547     for (auto& account : accounts) {
548       xmlTextWriterStartElement(writer, BAD_CAST "account-provider");
549
550       xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
551                                   BAD_CAST account.appid.c_str());
552
553       if (!account.providerid.empty())
554         xmlTextWriterWriteAttribute(writer, BAD_CAST "providerid",
555                                     BAD_CAST account.providerid.c_str());
556
557       if (account.multiple_account_support)
558         xmlTextWriterWriteAttribute(writer,
559                                     BAD_CAST "multiple-accounts-support",
560                                     BAD_CAST "true");
561       else
562         xmlTextWriterWriteAttribute(writer,
563                                     BAD_CAST "multiple-accounts-support",
564                                     BAD_CAST "false");
565       for (auto& icon_pair : account.icon_paths) {
566         xmlTextWriterStartElement(writer, BAD_CAST "icon");
567         if (icon_pair.first == "AccountSmall")
568           xmlTextWriterWriteAttribute(writer, BAD_CAST "section",
569                                       BAD_CAST "account-small");
570         else
571           xmlTextWriterWriteAttribute(writer, BAD_CAST "section",
572                                       BAD_CAST "account");
573         xmlTextWriterWriteString(writer, BAD_CAST icon_pair.second.c_str());
574         xmlTextWriterEndElement(writer);
575       }
576
577       for (auto& name_pair : account.names) {
578         xmlTextWriterStartElement(writer, BAD_CAST "label");
579         if (!name_pair.second.empty())
580           xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
581                                       BAD_CAST name_pair.second.c_str());
582         xmlTextWriterWriteString(writer, BAD_CAST name_pair.first.c_str());
583         xmlTextWriterEndElement(writer);
584       }
585
586       for (auto& capability : account.capabilities) {
587         xmlTextWriterWriteFormatElement(writer, BAD_CAST "capability",
588           "%s", BAD_CAST capability.c_str());
589       }
590
591       xmlTextWriterEndElement(writer);
592     }
593     xmlTextWriterEndElement(writer);
594   }
595 }
596
597 void StepGenerateXml::GenerateIme(xmlTextWriterPtr writer) {
598   const auto& ime = context_->manifest_plugins_data.get().ime_info.get();
599   const auto& ime_uuid = ime.uuid();
600   if (!ime_uuid.empty()) {
601     xmlTextWriterStartElement(writer, BAD_CAST "ime");
602
603     GListRange<application_x*> app_range(
604         context_->manifest_data.get()->application);
605     if (!app_range.Empty()) {
606       // wgt app have ui-application as first application element.
607       // there may be service-applications but not as first element.
608       application_x* app = *app_range.begin();
609       xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
610                                   BAD_CAST app->appid);
611     }
612
613     xmlTextWriterStartElement(writer, BAD_CAST "uuid");
614     xmlTextWriterWriteString(writer, BAD_CAST ime_uuid.c_str());
615     xmlTextWriterEndElement(writer);
616
617     xmlTextWriterStartElement(writer, BAD_CAST "languages");
618
619     for (auto it = ime.LanguagesBegin(); it != ime.LanguagesEnd(); ++it) {
620       xmlTextWriterStartElement(writer, BAD_CAST "language");
621       xmlTextWriterWriteString(writer, BAD_CAST it->c_str());
622       xmlTextWriterEndElement(writer);
623     }
624
625     xmlTextWriterEndElement(writer);
626
627     xmlTextWriterEndElement(writer);
628   }
629 }
630
631 void StepGenerateXml::GenerateProfiles(xmlTextWriterPtr writer) {
632   for (const char* profile :
633        GListRange<char*>(context_->manifest_data.get()->deviceprofile)) {
634     xmlTextWriterStartElement(writer, BAD_CAST "profile");
635     xmlTextWriterWriteAttribute(writer, BAD_CAST "name",
636                                 BAD_CAST profile);
637     xmlTextWriterEndElement(writer);
638   }
639 }
640
641 void StepGenerateXml::GenerateShortcuts(xmlTextWriterPtr writer) {
642   const auto& shortcuts =
643       context_->manifest_plugins_data.get().shortcut_info.get();
644   if (!shortcuts.empty()) {
645     xmlTextWriterStartElement(writer, BAD_CAST "shortcut-list");
646     for (auto& shortcut : shortcuts) {
647       xmlTextWriterStartElement(writer, BAD_CAST "shortcut");
648       if (!shortcut.app_id.empty())
649         xmlTextWriterWriteAttribute(writer, BAD_CAST "appid",
650                                     BAD_CAST shortcut.app_id.c_str());
651       if (!shortcut.extra_data.empty())
652         xmlTextWriterWriteAttribute(writer, BAD_CAST "extra_data",
653                                     BAD_CAST shortcut.extra_data.c_str());
654       if (!shortcut.extra_key.empty())
655         xmlTextWriterWriteAttribute(writer, BAD_CAST "extra_key",
656                                     BAD_CAST shortcut.extra_key.c_str());
657       if (!shortcut.icon.empty()) {
658         xmlTextWriterStartElement(writer, BAD_CAST "icon");
659         xmlTextWriterWriteString(writer, BAD_CAST shortcut.icon.c_str());
660         xmlTextWriterEndElement(writer);
661       }
662       for (auto& label : shortcut.labels) {
663         xmlTextWriterStartElement(writer, BAD_CAST "label");
664         if (!label.first.empty())
665           xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
666                                       BAD_CAST label.first.c_str());
667         xmlTextWriterWriteString(writer, BAD_CAST label.second.c_str());
668         xmlTextWriterEndElement(writer);
669       }
670       xmlTextWriterEndElement(writer);
671     }
672     xmlTextWriterEndElement(writer);
673   }
674 }
675
676 void StepGenerateXml::GenerateTrustAnchor(xmlTextWriterPtr writer) {
677   if (!context_->manifest_data.get()->use_system_certs)
678     return;
679
680   xmlTextWriterStartElement(writer, BAD_CAST "trust-anchor");
681   xmlTextWriterWriteAttribute(writer, BAD_CAST "use-system-certs",
682       BAD_CAST context_->manifest_data.get()->use_system_certs);
683
684   xmlTextWriterEndElement(writer);
685 }
686
687 }  // namespace pkgmgr
688 }  // namespace wgt