65c52d52b771971aabf0cd2a014190c3b834730d
[platform/framework/native/installer.git] / src / XmlHandler / ManifestHandler.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        ManifestHandler.cpp
19  * @brief       This is the implementation file for %ManifestHandler class.
20  */
21
22 #include <FIoFile.h>
23 #include <FSys_SystemInfoImpl.h>
24 #include <FBase_StringConverter.h>
25
26 #include "ManifestHandler.h"
27 #include "PrivilegeHandler.h"
28 #include "InstallerUtil.h"
29 #include "ManifestLiveboxesParser.h"
30 #include "ManifestAccountsParser.h"
31 #include "ManifestAppControlsParser.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::App;
37 using namespace Tizen::Io;
38 using namespace Tizen::System;
39
40 ManifestHandler::ManifestHandler(void)
41 :__pContext(null)
42 ,__pPrivilegeList(null)
43 ,__pContentDataList(null)
44 ,__pAppControlInfoImpl(null)
45 ,__pAppControlCapabilityInfoImpl(null)
46 ,__pAppControlResolutionInfoImpl(null)
47 ,__pDataControlInfo(null)
48 ,__pDataControlType(null)
49 ,__pContentData(null)
50 ,__pDefaultIconType(null)
51 ,__isDefaultMainmenu(false)
52 ,__isDefaultSetting(false)
53 ,__isDefaultTicker(false)
54 ,__isDefaultQuickpanel(false)
55 ,__isDefaultLaunchImage(false)
56 ,__isDefaultName(false)
57 ,__isDefaultAppDetected(false)
58 ,__pAppData(null)
59 ,__isParserMode(false)
60 ,__pParser(null)
61 {
62 }
63
64 ManifestHandler::~ManifestHandler(void)
65 {
66         delete[] __pDefaultIconType;
67         __pDefaultIconType = null;
68 }
69
70 bool
71 ManifestHandler::Construct(InstallationContext* pContext)
72 {
73         __pContext = pContext;
74
75         return true;
76 }
77
78 InstallationContext*
79 ManifestHandler::GetContext(void)
80 {
81         return __pContext;
82 }
83
84 bool
85 ManifestHandler::Parse(const char *pFilepath)
86 {
87         return ParseDocument(pFilepath);
88 }
89
90 bool
91 ManifestHandler::OnStartElement(const char *pName)
92 {
93         TryReturn(pName, true, "pName is null.");
94
95         bool status = true;
96
97         if (__isParserMode == true)
98         {
99                 TryReturn(__pParser, false, "__pParser is null");
100                 return __pParser->OnStartElement(pName);
101         }
102
103         if (strcasecmp(pName, "Manifest") == 0)
104         {
105                 AppLog("------------------------------------------");
106                 AppLog("manifest.xml");
107                 AppLog("------------------------------------------");
108                 AppLog("<%s>", pName);
109         }
110         else if (strcasecmp(pName, "Apps") == 0)
111         {
112                 AppLog("<%s>", pName);
113         }
114         else if (strcasecmp(pName, "UiApp") == 0)
115         {
116                 status = OnUiAppStartElement();
117         }
118         else if (strcasecmp(pName, "ServiceApp") == 0)
119         {
120                 status = OnServiceAppStartElement();
121         }
122         else if (strcasecmp(pName, "DataControl") == 0)
123         {
124                 status = OnDataControlStartElement();
125         }
126         else if (strcasecmp(pName, "Privileges") == 0)
127         {
128                 status = OnPrivilegesStartElement();
129         }
130         else if (strcasecmp(pName, "UiScalability") == 0)
131         {
132                 status = OnUiScalabilityStartElement();
133         }
134         else if (strcasecmp(pName, "UiTheme") == 0)
135         {
136                 status = OnUiThemeStartElement();
137         }
138         else if (strcasecmp(pName, "Icons") == 0)
139         {
140                 status = OnIconsStartElement();
141         }
142         else if (strcasecmp(pName, "Contents") == 0)
143         {
144                 status = OnContentsStartElement();
145         }
146         else if (strcasecmp(pName, "Content") == 0)
147         {
148                 status = OnContentStartElement();
149         }
150         else if ((strcasecmp(pName, "Liveboxes") == 0) || strcasecmp(pName, "AppWidgets") == 0)
151         {
152                 status = OnLiveboxesStartElement(pName);
153         }
154         else if (strcasecmp(pName, "Accounts") == 0)
155         {
156                 status = OnAccountsStartElement(pName);
157         }
158         else if (strcasecmp(pName, "AppControls") == 0)
159         {
160                 status = OnAppControlsStartElement(pName);
161         }
162         else if (strcasecmp(pName, "Permission") == 0)
163         {
164                 status = OnPermissionStartElement(pName);
165         }
166
167         if (!status)
168         {
169                 __isParserMode = false;
170                 return false;
171         }
172
173         return true;
174 }
175
176 bool
177 ManifestHandler::OnEndElement(const char *pName)
178 {
179         TryReturn(pName, true, "pName is null.");
180
181         bool status = true;
182
183         if (__isParserMode == true)
184         {
185                 TryReturn(__pParser, false, "__pParser is null");
186                 __pParser->OnEndElement(pName);
187
188                 if ((strcasecmp(pName, "Liveboxes") == 0) || strcasecmp(pName, "AppWidgets") == 0)
189                 {
190                         status = OnLiveboxesEndElement();
191                 }
192                 else if (strcasecmp(pName, "Accounts") == 0)
193                 {
194                         status = OnAccountsEndElement();
195                 }
196                 else if (strcasecmp(pName, "AppControls") == 0)
197                 {
198                         status = OnAppControlsEndElement();
199                 }
200
201                 return status;
202         }
203
204         if (strcasecmp(pName, "Privileges") == 0)
205         {
206                 status = OnPrivilegesEndElement();
207         }
208         else if (strcasecmp(pName, "UiApp") == 0)
209         {
210                 status = OnUiAppEndElement();
211         }
212         else if (strcasecmp(pName, "ServiceApp") == 0)
213         {
214                 status = OnServiceAppEndElement();
215         }
216         else if (strcasecmp(pName, "DataControl") == 0)
217         {
218                 status = OnDataControlEndElement();
219         }
220         else if (strcasecmp(pName, "DataControlType") == 0)
221         {
222                 status = OnDataControlTypeEndElement();
223         }
224         else if (strcasecmp(pName, "Apps") == 0)
225         {
226                 status = OnAppsEndElement();
227         }
228         else if (strcasecmp(pName, "UiScalability") == 0)
229         {
230                 AppLog("</%s>", pName);
231         }
232         else if (strcasecmp(pName, "Icons") == 0)
233         {
234                 status = OnIconsEndElement();
235         }
236         else if (strcasecmp(pName, "Contents") == 0)
237         {
238                 status = OnContentsEndElement();
239         }
240         else if (strcasecmp(pName, "Content") == 0)
241         {
242                 status = OnContentEndElement();
243         }
244         else if (strcasecmp(pName, "Manifest") == 0)
245         {
246                 status = OnManifestEndElement();
247         }
248
249         if (!status)
250         {
251                 return false;
252         }
253
254         return true;
255 }
256
257 bool
258 ManifestHandler::OnCharacters(const char *pCharacters)
259 {
260         bool status = true;
261
262         if (__isParserMode == true)
263         {
264                 TryReturn(__pParser, false, "__pParser is null");
265                 return __pParser->OnCharacters(pCharacters);
266         }
267
268         char *pName = GetElementName();
269         TryReturn(pName, false, "pName is null.");
270
271         if (strcasecmp(pName, "Id") == 0)
272         {
273                 status = OnIdValue(pCharacters);
274         }
275         else if (strcasecmp(pName, "Version") == 0)
276         {
277                 status = OnVersionValue(pCharacters);
278         }
279         else if (strcasecmp(pName, "Type") == 0)
280         {
281                 status = OnTypeValue(pCharacters);
282         }
283         else if (strcasecmp(pName, "Url") == 0)
284         {
285                 status = OnUrlValue(pCharacters);
286         }
287         else if (strcasecmp(pName, "ApiVersion") == 0)
288         {
289                 status = OnApiVersionValue(pCharacters);
290         }
291         else if (strcasecmp(pName, "Privilege") == 0)
292         {
293                 status = OnPrivilegeValue(pCharacters);
294         }
295         else if (strcasecmp(pName, "Name") == 0)
296         {
297                 status = OnNameValue(pCharacters);
298         }
299         else if (strcasecmp(pName, "DisplayName") == 0)
300         {
301                 status = OnNameValue(pCharacters);
302         }
303         else if (strcasecmp(pName, "Author") == 0)
304         {
305                 status = OnAuthorValue(pCharacters);
306         }
307         else if (strcasecmp(pName, "Description") == 0)
308         {
309                 status = OnDescriptionValue(pCharacters);
310         }
311         else if (strcasecmp(pName, "Icon") == 0)
312         {
313                 status = OnIconValue(pCharacters);
314         }
315         else if (strcasecmp(pName, "DataControlType") == 0)
316         {
317                 status = OnDataControlTypeValue(pCharacters);
318         }
319         else if (strcasecmp(pName, "Condition") == 0)
320         {
321                 status = OnConditionValue(pCharacters);
322         }
323         else if (strcasecmp(pName, "Notification") == 0)
324         {
325                 status = OnNotificationValue(pCharacters);
326         }
327         else if (strcasecmp(pName, "InstallationLocation") == 0)
328         {
329                 status = OnInstallationLocationValue(pCharacters);
330         }
331         else if (strcasecmp(pName, "Category") == 0)
332         {
333                 status = OnCategoryValue(pCharacters);
334         }
335         else if (strcasecmp(pName, "Metadata") == 0)
336         {
337                 status = OnMetadataValue(pCharacters);
338         }
339
340         if (!status)
341         {
342                 return false;
343         }
344
345         return true;
346 }
347
348 bool
349 ManifestHandler::OnPrivilegesStartElement(void)
350 {
351         __pPrivilegeList = new (std::nothrow) ArrayList;
352         TryReturn(__pPrivilegeList, false, "__pPrivilegeList is null");
353
354         AppLog("<Privileges>");
355
356         return true;
357 }
358
359 bool
360 ManifestHandler::OnUiAppStartElement(void)
361 {
362         __pAppData = new (std::nothrow) AppData;
363         TryReturn(__pAppData, false, "__pAppData is null");
364
365         InstallerError error = __pAppData->Construct();
366         TryReturn(error == INSTALLER_ERROR_NONE, false, "pAppData->Construct() failed.");
367
368         AppLog("<UiApp>");
369
370         XmlAttribute *pAttr = GetAttribute();
371         TryReturn(pAttr, true, "pAttr is null");
372
373         ParseAppAttribute(pAttr, true);
374
375         return true;
376 }
377
378 bool
379 ManifestHandler::OnServiceAppStartElement(void)
380 {
381         __pAppData = new (std::nothrow) AppData;
382         TryReturn(__pAppData, false, "__pAppData is null");
383
384         InstallerError error = __pAppData->Construct();
385         TryReturn(error == INSTALLER_ERROR_NONE, false, "pAppData->Construct() failed.");
386
387         AppLog("<ServiceApp>");
388
389         XmlAttribute *pAttr = GetAttribute();
390         TryReturn(pAttr, true, "pAttr is null");
391
392         ParseAppAttribute(pAttr, false);
393
394         return true;
395 }
396
397 bool
398 ManifestHandler::OnIconsStartElement(void)
399 {
400         result r = E_SUCCESS;
401         int width = 0;
402         String defaultIconType;
403
404         AppLog("<Icons>");
405
406         r = _SystemInfoImpl::GetSysInfo(L"ScreenWidth", width);
407         if (IsFailed(r))
408         {
409                 defaultIconType = L"Xhigh";
410         }
411         else
412         {
413                 if (width == 480)
414                 {
415                         defaultIconType = L"High";
416                 }
417                 else
418                 {
419                         defaultIconType = L"Xhigh";
420                 }
421         }
422
423         AppLog("ScreenWidth = [%d]", width);
424
425         __pDefaultIconType = _StringConverter::CopyToCharArrayN(defaultIconType);
426         TryReturn(__pDefaultIconType, false, "__pDefaultIconType is null.");
427
428         AppLog("DefaultIconType = [%s]", __pDefaultIconType);
429
430         return true;
431 }
432
433 bool
434 ManifestHandler::OnUiScalabilityStartElement(void)
435 {
436         XmlAttribute *pAttr = null;
437         char* pCoordinateSystem = null;
438         char* pBaseScreenSize = null;
439         char* pLogicalCoordinate = null;
440
441         AppLog("<UiScalability>");
442
443         pAttr = GetAttribute();
444         TryReturn(pAttr, true, "pAttr is null");
445
446         pCoordinateSystem = pAttr->Find("CoordinateSystem");
447         if (pCoordinateSystem)
448         {
449                 String* pKey = new (std::nothrow) String("CoordinateSystem");
450                 TryReturn(pKey, false, "pKey is null");
451                 String* pValue = new (std::nothrow) String(pCoordinateSystem);
452                 TryReturn(pValue, false, "pValue is null");
453
454                 __pAppData->__pFeatureList->Add(pKey, pValue);
455                 AppLog("<CoordinateSystem=%s>", pCoordinateSystem);
456         }
457
458         pBaseScreenSize = pAttr->Find("BaseScreenSize");
459         if (pBaseScreenSize)
460         {
461                 String* pKey = new (std::nothrow) String("BaseScreenSize");
462                 TryReturn(pKey, false, "pKey is null");
463                 String* pValue = new (std::nothrow) String(pBaseScreenSize);
464                 TryReturn(pValue, false, "pValue is null");
465
466                 __pAppData->__pFeatureList->Add(pKey, pValue);
467                 AppLog("<BaseScreenSize=%s>", pBaseScreenSize);
468         }
469
470         pLogicalCoordinate = pAttr->Find("LogicalCoordinate");
471         if (pLogicalCoordinate)
472         {
473                 String* pKey = new (std::nothrow) String("LogicalCoordinate");
474                 TryReturn(pKey, false, "pKey is null");
475                 String* pValue = new (std::nothrow) String(pLogicalCoordinate);
476                 TryReturn(pValue, false, "pValue is null");
477
478                 __pAppData->__pFeatureList->Add(pKey, pValue);
479                 AppLog("<LogicalCoordinate=%s>", pLogicalCoordinate);
480         }
481
482         return true;
483 }
484
485 bool
486 ManifestHandler::OnUiThemeStartElement(void)
487 {
488         XmlAttribute *pAttr = null;
489         char *pSystemTheme = null;
490         char *pUserDefinedTheme = null;
491
492         AppLog("<UiTheme>");
493
494         pAttr = GetAttribute();
495         TryReturn(pAttr, true, "pAttr is null");
496
497         pSystemTheme = pAttr->Find("SystemTheme");
498         if (pSystemTheme)
499         {
500                 String* pKey = new (std::nothrow) String("SystemTheme");
501                 TryReturn(pKey, false, "pKey is null");
502                 String* pValue = new (std::nothrow) String(pSystemTheme);
503                 TryReturn(pValue, false, "pValue is null");
504
505                 __pAppData->__pFeatureList->Add(pKey, pValue);
506                 AppLog("<SystemTheme=%s>", pSystemTheme);
507         }
508
509         pUserDefinedTheme = pAttr->Find("UserDefinedTheme");
510         if (pUserDefinedTheme)
511         {
512                 String* pKey = new (std::nothrow) String("UserDefinedTheme");
513                 TryReturn(pKey, false, "pKey is null");
514                 String* pValue = new (std::nothrow) String(pUserDefinedTheme);
515                 TryReturn(pValue, false, "pValue is null");
516
517                 __pAppData->__pFeatureList->Add(pKey, pValue);
518                 AppLog("<UserDefinedTheme=%s>", pUserDefinedTheme);
519         }
520
521         return true;
522 }
523
524 bool
525 ManifestHandler::OnDataControlStartElement(void)
526 {
527         XmlAttribute* pAttr = null;
528         char* pProviderId = null;
529
530         pAttr = GetAttribute();
531         TryReturn(pAttr, true, "pAttr is null");
532
533         pProviderId = pAttr->Find("ProviderId");
534         TryReturn(pProviderId, true, "pProviderId is null");
535
536         __pDataControlInfo = new (std::nothrow) DataControlInfo;
537         TryReturn(__pDataControlInfo, false, "__pDataControlInfo is null");
538
539         __pDataControlInfo->__providerId = pProviderId;
540
541         AppLog("<DataControl ProviderId=\"%s\">", pProviderId);
542
543         return true;
544 }
545
546 bool
547 ManifestHandler::OnContentsStartElement(void)
548 {
549         __pContentDataList = new (std::nothrow) ArrayList;
550         TryReturn(__pContentDataList, false, "__pContentDataList is null");
551
552         AppLog("<Contents>");
553
554         return true;
555 }
556
557 bool
558 ManifestHandler::OnContentStartElement(void)
559 {
560         TryReturn(__pContentData == null, false, "__pContentData is not null");
561
562         XmlAttribute *pAttr = null;
563         char *pDefault = null;
564
565         __pContentData = new (std::nothrow) ContentData;
566         TryReturn(__pContentData, false, "__pContentData is null");
567
568         pAttr = GetAttribute();
569         TryReturn(pAttr, true, "pAttr is null");
570
571         char* pId = pAttr->Find("Id");
572         if (pId)
573         {
574                 __pContentData->SetContentId(pId);
575         }
576
577         char* pEntryName = pAttr->Find("EntryName");
578         if (pEntryName)
579         {
580                 __pContentData->SetContentId(pEntryName);
581         }
582
583         pDefault = pAttr->Find("Default");
584         if (pDefault)
585         {
586                 if (strcasecmp(pDefault, "True") == 0)
587                 {
588                         __isDefaultAppDetected = true;
589                 }
590         }
591
592         AppLog("<Content Id=\"%s\" EntryName=\"%s\">", pId, pEntryName);
593
594         return true;
595 }
596
597 bool
598 ManifestHandler::OnLiveboxesStartElement(const char *pName)
599 {
600         __pParser = new (std::nothrow) ManifestLiveboxesParser;
601         TryReturn(__pParser, false, "__pParser is null");
602
603         __isParserMode = true;
604         AppLog("------------------------------------------");
605         __pParser->Construct(this);
606
607         return __pParser->OnStartElement(pName);
608 }
609
610 bool
611 ManifestHandler::OnAccountsStartElement(const char *pName)
612 {
613         __pParser = new (std::nothrow) ManifestAccountsParser;
614         TryReturn(__pParser, false, "__pParser is null");
615
616         __isParserMode = true;
617         AppLog("------------------------------------------");
618         __pParser->Construct(this);
619
620         return __pParser->OnStartElement(pName);
621 }
622
623 bool
624 ManifestHandler::OnAppControlsStartElement(const char *pName)
625 {
626         __pParser = new (std::nothrow) ManifestAppControlsParser;
627         TryReturn(__pParser, false, "__pParser is null");
628
629         __isParserMode = true;
630         AppLog("------------------------------------------");
631         __pParser->Construct(this);
632
633         return __pParser->OnStartElement(pName);
634 }
635
636 bool
637 ManifestHandler::OnPermissionStartElement(const char* pName)
638 {
639         XmlAttribute* pAttr = null;
640         char* pType = null;
641
642         pAttr = GetAttribute();
643         TryReturn(pAttr, true, "pAttr is null.");
644
645         pType = pAttr->Find("Type");
646         TryReturn(pType, true, "pType is null.");
647
648         if (__pAppData->__permissionType.IsEmpty() == true)
649         {
650                 __pAppData->__permissionType = pType;
651         }
652         else
653         {
654                 String type = pType;
655                 if (__pAppData->__permissionType.Equals(type, true) == false)
656                 {
657                         AppLog("Invalid Permission Type [%ls][%ls]", __pAppData->__permissionType.GetPointer(), type.GetPointer());
658                         return false;
659                 }
660         }
661
662         AppLog("<Permission Type=\"%s\">", pType);
663
664         return true;
665 }
666
667 bool
668 ManifestHandler::OnPrivilegesEndElement(void)
669 {
670         if (__pContext->__isVerificationMode == false)
671         {
672                 AppLog("no signature file[%ls]", __pContext->GetSignatureXmlPath().GetPointer());
673
674                 result r = E_SUCCESS;
675                 String privileges;
676                 String hmacPrivileges;
677                 ArrayList stringPrivilegeList;
678                 stringPrivilegeList.Construct(125);
679                 PackageId packageId = __pContext->__packageId;
680
681                 if (__pPrivilegeList != null)
682                 {
683                         r = PrivilegeHandler::GenerateCipherPrivilege(packageId, *__pPrivilegeList, privileges, hmacPrivileges, stringPrivilegeList);
684                         TryReturn(!IsFailed(r), false, "privMgr.GeneratePrivilegeString() failed");
685                 }
686
687                 __pContext->__privileges = privileges;
688                 __pContext->__hmacPrivileges = hmacPrivileges;
689                 __pContext->__pStringPrivilegeList = new ArrayList;
690                 __pContext->__pStringPrivilegeList->Construct(stringPrivilegeList);
691         }
692
693         __pContext->SetPrivilegeList(__pPrivilegeList);
694
695         AppLog("</Privileges>");
696
697         return true;
698 }
699
700 bool
701 ManifestHandler::OnUiAppEndElement(void)
702 {
703         if (__pAppData->__isSubMode == true)
704         {
705                 __pAppData->__pSubModeAppControlDataList = __pAppData->__pAppControlDataList;
706                 __pAppData->__pAppControlDataList = null;
707                 __pAppData->__subModeAppName = __pAppData->__name;
708         }
709
710         __isDefaultName = false;
711
712         __pContext->__pAppDataList->Add(__pAppData);
713         __pAppData = null;
714
715         AppLog("</UiApp>");
716
717         return true;
718 }
719
720 bool
721 ManifestHandler::OnServiceAppEndElement(void)
722 {
723         if (__pAppData->__isSubMode == true)
724         {
725                 __pAppData->__pSubModeAppControlDataList = __pAppData->__pAppControlDataList;
726                 __pAppData->__pAppControlDataList = null;
727                 __pAppData->__subModeAppName = __pAppData->__name;
728         }
729
730         __isDefaultName = false;
731
732         __pContext->__pAppDataList->Add(__pAppData);
733         __pAppData = null;
734
735         AppLog("</ServiceApp>");
736
737         return true;
738 }
739
740 bool
741 ManifestHandler::OnAppsEndElement(void)
742 {
743         AppLog("</Apps>");
744
745         return true;
746 }
747
748 bool
749 ManifestHandler::OnIconsEndElement(void)
750 {
751         AppLog("</Icons>");
752
753         return true;
754 }
755
756 bool
757 ManifestHandler::OnDataControlEndElement(void)
758 {
759         __pAppData->__pDataControlList->Add(__pDataControlInfo);
760         __pDataControlInfo = null;
761         AppLog("</DataControl>");
762
763         return true;
764 }
765
766 bool
767 ManifestHandler::OnDataControlTypeEndElement(void)
768 {
769         __pDataControlInfo->__pControlTypeList->Add(__pDataControlType);
770         __pDataControlType = null;
771         AppLog("</DataControlType>");
772
773         return true;
774 }
775
776 bool
777 ManifestHandler::OnContentsEndElement(void)
778 {
779         __pContext->SetContentDataList(__pContentDataList);
780         __pContentDataList = null;
781         AppLog("</Contents>");
782
783         return true;
784 }
785
786 bool
787 ManifestHandler::OnContentEndElement(void)
788 {
789         __pContentDataList->Add(*__pContentData);
790         __pContentData = null;
791         AppLog("</Content>");
792
793         return true;
794 }
795
796 bool
797 ManifestHandler::OnLiveboxesEndElement(void)
798 {
799         delete __pParser;
800         __isParserMode = false;
801         AppLog("------------------------------------------");
802
803         return true;
804 }
805
806 bool
807 ManifestHandler::OnAccountsEndElement(void)
808 {
809         delete __pParser;
810         __isParserMode = false;
811         AppLog("------------------------------------------");
812
813         return true;
814 }
815
816 bool
817 ManifestHandler::OnAppControlsEndElement(void)
818 {
819         delete __pParser;
820         __isParserMode = false;
821         AppLog("------------------------------------------");
822
823         return true;
824 }
825
826 bool
827 ManifestHandler::OnManifestEndElement(void)
828 {
829         TryReturn(__isDefaultAppDetected, false, "[osp-installer][Error] Main tag is not detected...");
830         AppLog("</Manifest>");
831
832         return true;
833 }
834
835 bool
836 ManifestHandler::OnIdValue(const char *pCharacters)
837 {
838         AppLog("<Id>%s</Id>", pCharacters);
839         __pContext->__packageId = pCharacters;
840
841         return true;
842 }
843
844 bool
845 ManifestHandler::OnVersionValue(const char *pCharacters)
846 {
847         AppLog("<Version>%s</Version>", pCharacters);
848         __pContext->__version = pCharacters;
849
850         return true;
851 }
852
853 bool
854 ManifestHandler::OnTypeValue(const char *pCharacters)
855 {
856         AppLog("<Type>%s</Type>", pCharacters);
857
858         if (strcasecmp(pCharacters, "Contents") == 0)
859         {
860                 __pContext->__apiVersion = L"3.0";
861         }
862
863         return true;
864 }
865
866 bool
867 ManifestHandler::OnAuthorValue(const char *pCharacters)
868 {
869         AppLog("<Author>%s</Author>", pCharacters);
870         __pContext->__author = pCharacters;
871
872         return true;
873 }
874
875 bool
876 ManifestHandler::OnUrlValue(const char *pCharacters)
877 {
878         __pContext->__url = pCharacters;
879         AppLog("<Url>%s</Url>", pCharacters);
880
881         return true;
882 }
883
884 bool
885 ManifestHandler::OnApiVersionValue(const char *pCharacters)
886 {
887         __pContext->__apiVersion = pCharacters;
888         AppLog("<ApiVersion>%s</ApiVersion>", pCharacters);
889
890         XmlAttribute *pAttr = GetAttribute();
891         if (pAttr)
892         {
893                 char* pOspCompat = pAttr->Find("OspCompat");
894                 if (pOspCompat)
895                 {
896                         AppLog(" - OspCompat=%s", pOspCompat);
897                         __pContext->__isOspCompat = true;
898                 }
899         }
900
901         return true;
902 }
903
904 bool
905 ManifestHandler::OnPrivilegeValue(const char *pCharacters)
906 {
907         __pPrivilegeList->Add(*new (std::nothrow) String(pCharacters));
908         AppLog("<Privilege>%s</Privilege>", pCharacters);
909
910         return true;
911 }
912
913 bool
914 ManifestHandler::OnIconValue(const char *pCharacters)
915 {
916         AppLog("<Icon>%s</Icon>", pCharacters);
917
918         XmlAttribute* pAttr = GetAttribute();
919         TryReturn(pAttr, true, "pAttr is null");
920
921         char* pSection = pAttr->Find("Section");
922         TryReturn(pSection, true, "pSection is null");
923         AppLog(" - Section=%s", pSection);
924
925         TryReturn(__pDefaultIconType, false, "__pDefaultIconType is null");
926
927         String iconRelPath;
928         char* pType = pAttr->Find("Type");
929         if (pType == null)
930         {
931                 AppLog("__pDefaultIconType=%s", __pDefaultIconType);
932                 if (strcasecmp(__pDefaultIconType, "Xhigh") == 0)
933                 {
934                         iconRelPath.Format(1024, L"screen-density-xhigh/%s", pCharacters);
935                 }
936                 else if (strcasecmp(__pDefaultIconType, "High") == 0)
937                 {
938                         iconRelPath.Format(1024, L"screen-density-high/%s", pCharacters);
939                 }
940                 else
941                 {
942                         TryReturn(0, false, "Invalid __pDefaultIconType[%s]", __pDefaultIconType);
943                 }
944         }
945         else    // legacy
946         {
947                 AppLog(" - Type=%s", pType);
948                 if (strcasecmp(pType, "Xhigh") == 0)
949                 {
950                         iconRelPath.Format(1024, L"screen-density-xhigh/%s", pCharacters);
951                 }
952                 else if (strcasecmp(pType, "High") == 0)
953                 {
954                         iconRelPath.Format(1024, L"screen-density-high/%s", pCharacters);
955                 }
956                 else
957                 {
958                         TryReturn(0, false, "Invalid IconType [%s]", __pDefaultIconType);
959                 }
960         }
961
962         if (FindElement("Content") == true)
963         {
964                 TryReturn(__pContentData, false, "__pContentData is null");
965                 __pContentData->SetIcon(iconRelPath);
966         }
967         else
968         {
969                 if (pType == null)
970                 {
971                         if (strcasecmp(pSection, "MainMenu") == 0)
972                         {
973                                 __pAppData->__mainmenuIcon = iconRelPath;
974                         }
975                         else if (strcasecmp(pSection, "Setting") == 0)
976                         {
977                                 __pAppData->__settingIcon = iconRelPath;
978                         }
979                         else if (strcasecmp(pSection, "Notification") == 0)
980                         {
981                                 __pAppData->__notificationIcon = iconRelPath;
982                         }
983                 }
984                 else    // legacy
985                 {
986                         if (strcasecmp(pSection, "MainMenu") == 0)
987                         {
988                                 if (__isDefaultMainmenu == false)
989                                 {
990                                         __pAppData->__mainmenuIcon = iconRelPath;
991                                 }
992
993                                 if (strcasecmp(pType, __pDefaultIconType) == 0)
994                                 {
995                                         __isDefaultMainmenu = true;
996                                 }
997                         }
998                         else if (strcasecmp(pSection, "Setting") == 0)
999                         {
1000                                 if (__isDefaultSetting == false)
1001                                 {
1002                                         __pAppData->__settingIcon = iconRelPath;
1003                                 }
1004
1005                                 if (strcasecmp(pType, __pDefaultIconType) == 0)
1006                                 {
1007                                         __isDefaultSetting = true;
1008                                 }
1009                         }
1010                         else if (strcasecmp(pSection, "Notification") == 0)
1011                         {
1012                                 if (__isDefaultQuickpanel == false)
1013                                 {
1014                                         __pAppData->__notificationIcon = iconRelPath;
1015                                 }
1016
1017                                 if (strcasecmp(pType, __pDefaultIconType) == 0)
1018                                 {
1019                                         __isDefaultQuickpanel = true;
1020                                 }
1021                         }
1022                 }
1023         }
1024
1025         return true;
1026 }
1027
1028 bool
1029 ManifestHandler::OnNameValue(const char *pCharacters)
1030 {
1031         XmlAttribute* pAttr = 0;
1032         char* pAttrValue = 0;
1033
1034         pAttr = GetAttribute();
1035         TryReturn(pAttr, true, "pAttr is null");
1036
1037         pAttrValue = pAttr->Find("Locale");
1038         TryReturn(pAttrValue, true, "pAttrValue is null");
1039
1040         if (FindElement("Content") == true)
1041         {
1042                 TryReturn(__pContentData, false, "__pContentData is null");
1043
1044                 String* pValue = new (std::nothrow) String;
1045                 StringUtil::Utf8ToString(pCharacters, *pValue);
1046                 __pContentData->AddName(*(new (std::nothrow) String(pAttrValue)), *pValue);
1047         }
1048         else
1049         {
1050                 if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0)
1051                 {
1052                         if (__isDefaultName == true)
1053                         {
1054                                 __pContext->__displayName = pCharacters;
1055                         }
1056                 }
1057
1058                 String* pValue = new (std::nothrow) String;
1059                 StringUtil::Utf8ToString(pCharacters, *pValue);
1060
1061                 __pAppData->__pNameList->Add((new (std::nothrow) String(pAttrValue)), pValue);
1062         }
1063
1064         AppLog("<DisplayName Locale=\"%s\">%s</DisplayName>", pAttrValue, pCharacters);
1065
1066         return true;
1067 }
1068
1069 bool
1070 ManifestHandler::OnDescriptionValue(const char *pCharacters)
1071 {
1072         XmlAttribute *pAttr = 0;
1073         char *pAttrValue = 0;
1074
1075         pAttr = GetAttribute();
1076         TryReturn(pAttr, true, "pAttr is null");
1077
1078         pAttrValue = pAttr->Find("Locale");
1079         TryReturn(pAttrValue, true, "pAttrValue is null");
1080
1081         if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0)
1082         {
1083                 __pContext->__description = pCharacters;
1084         }
1085
1086         AppLog("<Description Locale=\"%s\">%s</Description>", pAttrValue, pCharacters);
1087
1088         return true;
1089 }
1090
1091 bool
1092 ManifestHandler::OnDataControlTypeValue(const char *pCharacters)
1093 {
1094         XmlAttribute* pAttr = null;
1095         char* pAccessValue = null;
1096
1097         pAttr = GetAttribute();
1098         TryReturn(pAttr, true, "pAttr is null");
1099
1100         pAccessValue = pAttr->Find("Access");
1101         TryReturn(pAccessValue, true, "pAccessValue is null");
1102
1103         __pDataControlType = new (std::nothrow) DataControlType;
1104         TryReturn(__pDataControlType, false, "__pDataControlType is null");
1105
1106         __pDataControlType->__type = pCharacters;
1107         __pDataControlType->__access = pAccessValue;
1108
1109         AppLog("<DataControlType Access=\"%s\", Type=\"%s\">", pAccessValue, pCharacters);
1110
1111         return true;
1112 }
1113
1114 bool
1115 ManifestHandler::OnConditionValue(const char *pCharacters)
1116 {
1117         XmlAttribute *pAttr = null;
1118         char *pName = null;
1119
1120         pAttr = GetAttribute();
1121         TryReturn(pAttr, true, "pAttr is null");
1122
1123         pName = pAttr->Find("Name");
1124         TryReturn(pName, true, "pName is null");
1125
1126         String* pKey = new (std::nothrow) String(pName);
1127         TryReturn(pKey, false, "pKey is null");
1128         String* pValue = new (std::nothrow) String(pCharacters);
1129         TryReturn(pValue, false, "pValue is null");
1130
1131         __pAppData->__pLaunchConditionList->Add(pKey, pValue);
1132         AppLog("<LaunchCondition Name=\"%s\", Value=\"%s\">", pName, pCharacters);
1133
1134         return true;
1135 }
1136
1137 bool
1138 ManifestHandler::OnNotificationValue(const char *pCharacters)
1139 {
1140         XmlAttribute *pAttr = null;
1141         const char *pName = null;
1142
1143         pAttr = GetAttribute();
1144         TryReturn(pAttr, true, "pAttr is null.");
1145
1146         pName = pAttr->Find("Name");
1147         TryReturn(pName, true, "pName is null.");
1148
1149         if (strcasecmp(pName, "Ticker") == 0)
1150         {
1151                 pName = "Notification";
1152         }
1153         else if (strcasecmp(pName, "Notification") == 0 || strcasecmp(pName, "Sounds") == 0
1154                         || strcasecmp(pName, "Badge") == 0 || strcasecmp(pName, "Contents") == 0)
1155         {
1156                 // known notification attributes
1157         }
1158         else
1159         {
1160                 TryReturn(0, true, "Unknown notification attributes=%s", pCharacters);
1161         }
1162
1163         String* pKey = new (std::nothrow) String(pName);
1164         TryReturn(pKey, false, "pKey is null.");
1165
1166         String* pValue = new (std::nothrow) String(pCharacters);
1167         TryReturn(pValue, false, "pValue is null.");
1168
1169         pKey->ToLowerCase();
1170         pValue->ToLowerCase();
1171
1172         __pAppData->__pNotificationMap->Add(pKey, pValue);
1173         AppLog("<Notification Name=\"%s\", Value=\"%s\">", pName, pCharacters);
1174
1175         return true;
1176 }
1177
1178 bool
1179 ManifestHandler::OnInstallationLocationValue(const char *pCharacters)
1180 {
1181         AppLog("<InstallationLocation>%s</InstallationLocation>", pCharacters);
1182
1183         if ((strcasecmp(pCharacters, "UserPreferred") == 0) &&
1184                         (File::IsFileExist(DIR_MEMORYCARD_INSTALLATION) == true))
1185         {
1186                 AppLog("INSTALLATION_STORAGE = [EXTERNAL]");
1187                 __pContext->__storage = INSTALLATION_STORAGE_EXTERNAL;
1188         }
1189
1190         return true;
1191 }
1192
1193 bool
1194 ManifestHandler::OnCategoryValue(const char *pCharacters)
1195 {
1196         TryReturn(__pAppData, false, "__pAppData is null");
1197
1198         __pAppData->__pCategoryList->Add(new (std::nothrow) String(pCharacters));
1199
1200         if (strcasecmp(pCharacters, TIZEN_CATEGORY_IME) == 0)
1201         {
1202                 __pAppData->__feature = CATEGORY_TYPE_IME;
1203         }
1204
1205         return true;
1206 }
1207
1208 bool
1209 ManifestHandler::OnMetadataValue(const char* pCharacters)
1210 {
1211         TryReturn(__pAppData, false, "__pAppData is null");
1212
1213         XmlAttribute* pAttr = null;
1214         char* pKey = null;
1215
1216         pAttr = GetAttribute();
1217         TryReturn(pAttr, true, "pAttr is null.");
1218
1219         pKey = pAttr->Find("Key");
1220         TryReturn(pKey, true, "pKey is null.");
1221
1222         __pAppData->__pMetadataMap->Add(*(new (std::nothrow) String(pKey)), *(new (std::nothrow) String(pCharacters)));
1223
1224         AppLog("<Metadata Key=\"%s\">%s</Metadata>", pKey, pCharacters);
1225
1226         return true;
1227 }
1228
1229 bool
1230 ManifestHandler::FindElement(const char *pName)
1231 {
1232         bool res = false;
1233         Tizen::Base::Collection::IEnumerator* pEnum = GetElementEnumeratorN();
1234
1235         if (pEnum)
1236         {
1237                 while(pEnum->MoveNext() == E_SUCCESS)
1238                 {
1239                         String* pStr = static_cast<String*>(pEnum->GetCurrent());
1240                         if (pStr)
1241                         {
1242                                 if (pStr->Equals(pName, false) == true)
1243                                 {
1244                                         AppLog("[%s] is matched.", pName);
1245                                         res = true;
1246                                         break;
1247                                 }
1248                         }
1249                 }
1250
1251                 delete pEnum;
1252         }
1253
1254         return res;
1255 }
1256
1257 bool
1258 ManifestHandler::AddAppFeature(const Tizen::Base::String& name, const Tizen::Base::String& value)
1259 {
1260         String* pKey = new (std::nothrow) String(name);
1261         TryReturn(pKey, false, "pKey is null");
1262         String* pValue = new (std::nothrow) String(value);
1263         TryReturn(pValue, false, "pValue is null");
1264
1265         __pAppData->__pFeatureList->Add(pKey, pValue);
1266         return true;
1267 }
1268
1269 bool
1270 ManifestHandler::ParseAppAttribute(XmlAttribute* pAttr, bool isUiApp)
1271 {
1272         char* pName = pAttr->Find("Name");
1273         if (pName == null)
1274         {
1275                 pName = pAttr->Find("ExecutableName");
1276         }
1277
1278         if (pName)
1279         {
1280                 AppLog(" - Name=%s", pName);
1281                 __pAppData->__name = pName;
1282                 __pAppData->__appId = __pContext->__packageId + L"." + pName;
1283         }
1284
1285         char* pMain = pAttr->Find("Main");
1286         if (pMain == null)
1287         {
1288                 pMain = pAttr->Find("Default");
1289         }
1290
1291         if (pMain)
1292         {
1293                 AppLog(" - Main=%s", pMain);
1294                 __pAppData->__main = pMain;
1295
1296                 if (strcasecmp(pMain, "True") == 0)
1297                 {
1298                         __isDefaultName = true;
1299                         __isDefaultAppDetected = true;
1300                         __pContext->__mainAppName = pName;
1301                 }
1302         }
1303         else
1304         {
1305                 __pAppData->__main = L"False";
1306         }
1307
1308         char* pRecent = pAttr->Find("LaunchingHistoryVisible");
1309         if (pRecent)
1310         {
1311                 AppLog(" - LaunchingHistoryVisible=%s", pRecent);
1312                 __pAppData->__launchingHistoryVisible = pRecent;
1313         }
1314
1315         char* pHwAcceleration = pAttr->Find("HwAcceleration");
1316         if (pHwAcceleration)
1317         {
1318                 AddAppFeature("HwAcceleration", pHwAcceleration);
1319                 AppLog(" - HwAcceleration=%s", pHwAcceleration);
1320         }
1321         else
1322         {
1323                 char* pGlFrame = pAttr->Find("GlFrame");
1324                 if (pGlFrame)
1325                 {
1326                         AddAppFeature("GlFrame", pGlFrame);
1327                         AppLog(" - GlFrame=%s", pGlFrame);
1328                 }
1329         }
1330
1331         char* pCategory = pAttr->Find("Category");
1332         if (pCategory)
1333         {
1334                 AppLog(" - Category=%s", pCategory);
1335
1336                 if (strcasecmp(pCategory, "home-screen") == 0)
1337                 {
1338                         __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_HOMESCREEN));
1339                 }
1340                 else if (strcasecmp(pCategory, "lock-screen") == 0)
1341                 {
1342                         __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_LOCKSCREEN));
1343                 }
1344                 else if (strcasecmp(pCategory, "Ime") == 0)
1345                 {
1346                         __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_IME));
1347                 }
1348
1349                 int categoryType = InstallerUtil::GetCategoryType(pCategory);
1350                 __pAppData->__feature = categoryType;
1351         }
1352
1353         char* pSubMode = pAttr->Find("SubMode");
1354         if (pSubMode)
1355         {
1356                 if (strcasecmp(pSubMode, "True") == 0)
1357                 {
1358                         __pAppData->__isSubMode = true;
1359                         AppLog(" - SubMode=%s", pSubMode);
1360                 }
1361         }
1362
1363         if (isUiApp == true)
1364         {
1365                 __pAppData->__type = L"UiApp";
1366
1367                 char* pMenuIconVisible = pAttr->Find("MenuIconVisible");
1368                 if (pMenuIconVisible == null)
1369                 {
1370                         pMenuIconVisible = pAttr->Find("MainmenuVisible");
1371                 }
1372
1373                 if (pMenuIconVisible)
1374                 {
1375                         if (strcasecmp(pMenuIconVisible, "True") == 0)
1376                         {
1377                                 __pAppData->__mainmenuVisible = true;
1378                         }
1379                         else
1380                         {
1381                                 __pAppData->__mainmenuVisible = false;
1382                         }
1383
1384                         AddAppFeature("MenuIconVisible", pMenuIconVisible);
1385                         AppLog(" - MenuIconVisible=%s", pMenuIconVisible);
1386                 }
1387         }
1388         else
1389         {
1390                 __pAppData->__type = L"ServiceApp";
1391                 __pAppData->__mainmenuVisible = false;
1392
1393                 char *pUseUi = pAttr->Find("UseUi");
1394                 if (pUseUi)
1395                 {
1396                         AddAppFeature("UseUi", pUseUi);
1397                         AppLog(" - UseUi=%s", pUseUi);
1398                 }
1399
1400                 char *pLifeDuration = pAttr->Find("LifeDuration");
1401                 if (pLifeDuration)
1402                 {
1403                         AddAppFeature("LifeDuration", pLifeDuration);
1404                         AppLog(" - LifeDuration=%s", pLifeDuration);
1405                 }
1406
1407                 char *pLaunchOnBoot = pAttr->Find("LaunchOnBoot");
1408                 if (pLaunchOnBoot)
1409                 {
1410                         AddAppFeature("LaunchOnBoot", pLaunchOnBoot);
1411                         AppLog(" - LaunchOnBoot=%s", pLaunchOnBoot);
1412                 }
1413
1414                 char *pAutoRestart = pAttr->Find("AutoRestart");
1415                 if (pAutoRestart)
1416                 {
1417                         AddAppFeature("AutoRestart", pAutoRestart);
1418                         AppLog(" - AutoRestart=%s", pAutoRestart);
1419                 }
1420
1421                 char *pSystemService = pAttr->Find("SystemService");
1422                 if (pSystemService)
1423                 {
1424                         if (strcasecmp(pSystemService, "True") == 0)
1425                         {
1426                                 __pAppData->__isSystemService = true;
1427                                 AppLog(" - SystemService=%s", pSystemService);
1428                         }
1429                 }
1430         }
1431
1432         AppLog(" - appId=%ls", __pAppData->__appId.GetPointer());
1433
1434         return true;
1435 }
1436
1437 AppData*
1438 ManifestHandler::GetAppData(void)
1439 {
1440         return __pAppData;
1441 }
1442
1443 char*
1444 ManifestHandler::GetDefaultIconType(void)
1445 {
1446         return __pDefaultIconType;
1447 }
1448