Update AppWidegts tag
[framework/osp/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
336         if (!status)
337         {
338                 return false;
339         }
340
341         return true;
342 }
343
344 bool
345 ManifestHandler::OnPrivilegesStartElement(void)
346 {
347         __pPrivilegeList = new (std::nothrow) ArrayList;
348         TryReturn(__pPrivilegeList, false, "__pPrivilegeList is null");
349
350         AppLog("<Privileges>");
351
352         return true;
353 }
354
355 bool
356 ManifestHandler::OnUiAppStartElement(void)
357 {
358         __pAppData = new (std::nothrow) AppData;
359         TryReturn(__pAppData, false, "__pAppData is null");
360
361         InstallerError error = __pAppData->Construct();
362         TryReturn(error == INSTALLER_ERROR_NONE, false, "pAppData->Construct() failed.");
363
364         AppLog("<UiApp>");
365
366         XmlAttribute *pAttr = GetAttribute();
367         TryReturn(pAttr, true, "pAttr is null");
368
369         ParseAppAttribute(pAttr, true);
370
371         return true;
372 }
373
374 bool
375 ManifestHandler::OnServiceAppStartElement(void)
376 {
377         __pAppData = new (std::nothrow) AppData;
378         TryReturn(__pAppData, false, "__pAppData is null");
379
380         InstallerError error = __pAppData->Construct();
381         TryReturn(error == INSTALLER_ERROR_NONE, false, "pAppData->Construct() failed.");
382
383         AppLog("<ServiceApp>");
384
385         XmlAttribute *pAttr = GetAttribute();
386         TryReturn(pAttr, true, "pAttr is null");
387
388         ParseAppAttribute(pAttr, false);
389
390         return true;
391 }
392
393 bool
394 ManifestHandler::OnIconsStartElement(void)
395 {
396         result r = E_SUCCESS;
397         int width = 0;
398         String defaultIconType;
399
400         AppLog("<Icons>");
401
402         r = _SystemInfoImpl::GetSysInfo(L"ScreenWidth", width);
403         if (IsFailed(r))
404         {
405                 defaultIconType = L"Xhigh";
406         }
407         else
408         {
409                 if (width == 480)
410                 {
411                         defaultIconType = L"High";
412                 }
413                 else
414                 {
415                         defaultIconType = L"Xhigh";
416                 }
417         }
418
419         AppLog("ScreenWidth = [%d]", width);
420
421         __pDefaultIconType = _StringConverter::CopyToCharArrayN(defaultIconType);
422         TryReturn(__pDefaultIconType, false, "__pDefaultIconType is null.");
423
424         AppLog("DefaultIconType = [%s]", __pDefaultIconType);
425
426         return true;
427 }
428
429 bool
430 ManifestHandler::OnUiScalabilityStartElement(void)
431 {
432         XmlAttribute *pAttr = null;
433         char* pCoordinateSystem = null;
434         char* pBaseScreenSize = null;
435         char* pLogicalCoordinate = null;
436
437         AppLog("<UiScalability>");
438
439         pAttr = GetAttribute();
440         TryReturn(pAttr, true, "pAttr is null");
441
442         pCoordinateSystem = pAttr->Find("CoordinateSystem");
443         if (pCoordinateSystem)
444         {
445                 String* pKey = new (std::nothrow) String("CoordinateSystem");
446                 TryReturn(pKey, false, "pKey is null");
447                 String* pValue = new (std::nothrow) String(pCoordinateSystem);
448                 TryReturn(pValue, false, "pValue is null");
449
450                 __pAppData->__pFeatureList->Add(pKey, pValue);
451                 AppLog("<CoordinateSystem=%s>", pCoordinateSystem);
452         }
453
454         pBaseScreenSize = pAttr->Find("BaseScreenSize");
455         if (pBaseScreenSize)
456         {
457                 String* pKey = new (std::nothrow) String("BaseScreenSize");
458                 TryReturn(pKey, false, "pKey is null");
459                 String* pValue = new (std::nothrow) String(pBaseScreenSize);
460                 TryReturn(pValue, false, "pValue is null");
461
462                 __pAppData->__pFeatureList->Add(pKey, pValue);
463                 AppLog("<BaseScreenSize=%s>", pBaseScreenSize);
464         }
465
466         pLogicalCoordinate = pAttr->Find("LogicalCoordinate");
467         if (pLogicalCoordinate)
468         {
469                 String* pKey = new (std::nothrow) String("LogicalCoordinate");
470                 TryReturn(pKey, false, "pKey is null");
471                 String* pValue = new (std::nothrow) String(pLogicalCoordinate);
472                 TryReturn(pValue, false, "pValue is null");
473
474                 __pAppData->__pFeatureList->Add(pKey, pValue);
475                 AppLog("<LogicalCoordinate=%s>", pLogicalCoordinate);
476         }
477
478         return true;
479 }
480
481 bool
482 ManifestHandler::OnUiThemeStartElement(void)
483 {
484         XmlAttribute *pAttr = null;
485         char *pSystemTheme = null;
486         char *pUserDefinedTheme = null;
487
488         AppLog("<UiTheme>");
489
490         pAttr = GetAttribute();
491         TryReturn(pAttr, true, "pAttr is null");
492
493         pSystemTheme = pAttr->Find("SystemTheme");
494         if (pSystemTheme)
495         {
496                 String* pKey = new (std::nothrow) String("SystemTheme");
497                 TryReturn(pKey, false, "pKey is null");
498                 String* pValue = new (std::nothrow) String(pSystemTheme);
499                 TryReturn(pValue, false, "pValue is null");
500
501                 __pAppData->__pFeatureList->Add(pKey, pValue);
502                 AppLog("<SystemTheme=%s>", pSystemTheme);
503         }
504
505         pUserDefinedTheme = pAttr->Find("UserDefinedTheme");
506         if (pUserDefinedTheme)
507         {
508                 String* pKey = new (std::nothrow) String("UserDefinedTheme");
509                 TryReturn(pKey, false, "pKey is null");
510                 String* pValue = new (std::nothrow) String(pUserDefinedTheme);
511                 TryReturn(pValue, false, "pValue is null");
512
513                 __pAppData->__pFeatureList->Add(pKey, pValue);
514                 AppLog("<UserDefinedTheme=%s>", pUserDefinedTheme);
515         }
516
517         return true;
518 }
519
520 bool
521 ManifestHandler::OnDataControlStartElement(void)
522 {
523         XmlAttribute* pAttr = null;
524         char* pProviderId = null;
525
526         pAttr = GetAttribute();
527         TryReturn(pAttr, true, "pAttr is null");
528
529         pProviderId = pAttr->Find("ProviderId");
530         TryReturn(pProviderId, true, "pProviderId is null");
531
532         __pDataControlInfo = new (std::nothrow) DataControlInfo;
533         TryReturn(__pDataControlInfo, false, "__pDataControlInfo is null");
534
535         __pDataControlInfo->__providerId = pProviderId;
536
537         AppLog("<DataControl ProviderId=\"%s\">", pProviderId);
538
539         return true;
540 }
541
542 bool
543 ManifestHandler::OnContentsStartElement(void)
544 {
545         __pContentDataList = new (std::nothrow) ArrayList;
546         TryReturn(__pContentDataList, false, "__pContentDataList is null");
547
548         AppLog("<Contents>");
549
550         return true;
551 }
552
553 bool
554 ManifestHandler::OnContentStartElement(void)
555 {
556         TryReturn(__pContentData == null, false, "__pContentData is not null");
557
558         XmlAttribute *pAttr = null;
559         char *pDefault = null;
560
561         __pContentData = new (std::nothrow) ContentData;
562         TryReturn(__pContentData, false, "__pContentData is null");
563
564         pAttr = GetAttribute();
565         TryReturn(pAttr, true, "pAttr is null");
566
567         char* pId = pAttr->Find("Id");
568         if (pId)
569         {
570                 __pContentData->SetContentId(pId);
571         }
572
573         char* pEntryName = pAttr->Find("EntryName");
574         if (pEntryName)
575         {
576                 __pContentData->SetContentId(pEntryName);
577         }
578
579         pDefault = pAttr->Find("Default");
580         if (pDefault)
581         {
582                 if (strcasecmp(pDefault, "True") == 0)
583                 {
584                         __isDefaultAppDetected = true;
585                 }
586         }
587
588         AppLog("<Content Id=\"%s\" EntryName=\"%s\">", pId, pEntryName);
589
590         return true;
591 }
592
593 bool
594 ManifestHandler::OnLiveboxesStartElement(const char *pName)
595 {
596         __pParser = new (std::nothrow) ManifestLiveboxesParser;
597         TryReturn(__pParser, false, "__pParser is null");
598
599         __isParserMode = true;
600         AppLog("------------------------------------------");
601         __pParser->Construct(this);
602
603         return __pParser->OnStartElement(pName);
604 }
605
606 bool
607 ManifestHandler::OnAccountsStartElement(const char *pName)
608 {
609         __pParser = new (std::nothrow) ManifestAccountsParser;
610         TryReturn(__pParser, false, "__pParser is null");
611
612         __isParserMode = true;
613         AppLog("------------------------------------------");
614         __pParser->Construct(this);
615
616         return __pParser->OnStartElement(pName);
617 }
618
619 bool
620 ManifestHandler::OnAppControlsStartElement(const char *pName)
621 {
622         __pParser = new (std::nothrow) ManifestAppControlsParser;
623         TryReturn(__pParser, false, "__pParser is null");
624
625         __isParserMode = true;
626         AppLog("------------------------------------------");
627         __pParser->Construct(this);
628
629         return __pParser->OnStartElement(pName);
630 }
631
632 bool
633 ManifestHandler::OnPermissionStartElement(const char* pName)
634 {
635         XmlAttribute* pAttr = null;
636         char* pType = null;
637
638         pAttr = GetAttribute();
639         TryReturn(pAttr, true, "pAttr is null.");
640
641         pType = pAttr->Find("Type");
642         TryReturn(pType, true, "pType is null.");
643
644         if (__pAppData->__permissionType.IsEmpty() == true)
645         {
646                 __pAppData->__permissionType = pType;
647         }
648         else
649         {
650                 String type = pType;
651                 if (__pAppData->__permissionType.Equals(type, true) == false)
652                 {
653                         AppLog("Invalid Permission Type [%ls][%ls]", __pAppData->__permissionType.GetPointer(), type.GetPointer());
654                         return false;
655                 }
656         }
657
658         AppLog("<Permission Type=\"%s\">", pType);
659
660         return true;
661 }
662
663 bool
664 ManifestHandler::OnPrivilegesEndElement(void)
665 {
666         if (__pContext->__isVerificationMode == false)
667         {
668                 AppLog("no signature file[%ls]", __pContext->GetSignatureXmlPath().GetPointer());
669
670                 result r = E_SUCCESS;
671                 String privileges;
672                 String hmacPrivileges;
673                 ArrayList stringPrivilegeList;
674                 stringPrivilegeList.Construct(125);
675                 PackageId packageId = __pContext->__packageId;
676                 r = PrivilegeHandler::GenerateCipherPrivilege(packageId, *__pPrivilegeList, privileges, hmacPrivileges, stringPrivilegeList);
677                 TryReturn(!IsFailed(r), false, "privMgr.GeneratePrivilegeString() failed");
678
679                 __pContext->__privileges = privileges;
680                 __pContext->__hmacPrivileges = hmacPrivileges;
681                 __pContext->__pStringPrivilegeList = new ArrayList;
682                 __pContext->__pStringPrivilegeList->Construct(stringPrivilegeList);
683         }
684
685         __pContext->SetPrivilegeList(__pPrivilegeList);
686
687         AppLog("</Privileges>");
688
689         return true;
690 }
691
692 bool
693 ManifestHandler::OnUiAppEndElement(void)
694 {
695         if (__pAppData->__isSubMode == true)
696         {
697                 __pAppData->__pSubModeAppControlDataList = __pAppData->__pAppControlDataList;
698                 __pAppData->__pAppControlDataList = null;
699                 __pAppData->__subModeAppName = __pAppData->__name;
700         }
701
702         __isDefaultName = false;
703
704         __pContext->__pAppDataList->Add(__pAppData);
705         __pAppData = null;
706
707         AppLog("</UiApp>");
708
709         return true;
710 }
711
712 bool
713 ManifestHandler::OnServiceAppEndElement(void)
714 {
715         if (__pAppData->__isSubMode == true)
716         {
717                 __pAppData->__pSubModeAppControlDataList = __pAppData->__pAppControlDataList;
718                 __pAppData->__pAppControlDataList = null;
719                 __pAppData->__subModeAppName = __pAppData->__name;
720         }
721
722         __isDefaultName = false;
723
724         __pContext->__pAppDataList->Add(__pAppData);
725         __pAppData = null;
726
727         AppLog("</ServiceApp>");
728
729         return true;
730 }
731
732 bool
733 ManifestHandler::OnAppsEndElement(void)
734 {
735         AppLog("</Apps>");
736
737         return true;
738 }
739
740 bool
741 ManifestHandler::OnIconsEndElement(void)
742 {
743         AppLog("</Icons>");
744
745         return true;
746 }
747
748 bool
749 ManifestHandler::OnDataControlEndElement(void)
750 {
751         __pAppData->__pDataControlList->Add(__pDataControlInfo);
752         __pDataControlInfo = null;
753         AppLog("</DataControl>");
754
755         return true;
756 }
757
758 bool
759 ManifestHandler::OnDataControlTypeEndElement(void)
760 {
761         __pDataControlInfo->__pControlTypeList->Add(__pDataControlType);
762         __pDataControlType = null;
763         AppLog("</DataControlType>");
764
765         return true;
766 }
767
768 bool
769 ManifestHandler::OnContentsEndElement(void)
770 {
771         __pContext->SetContentDataList(__pContentDataList);
772         __pContentDataList = null;
773         AppLog("</Contents>");
774
775         return true;
776 }
777
778 bool
779 ManifestHandler::OnContentEndElement(void)
780 {
781         __pContentDataList->Add(*__pContentData);
782         __pContentData = null;
783         AppLog("</Content>");
784
785         return true;
786 }
787
788 bool
789 ManifestHandler::OnLiveboxesEndElement(void)
790 {
791         delete __pParser;
792         __isParserMode = false;
793         AppLog("------------------------------------------");
794
795         return true;
796 }
797
798 bool
799 ManifestHandler::OnAccountsEndElement(void)
800 {
801         delete __pParser;
802         __isParserMode = false;
803         AppLog("------------------------------------------");
804
805         return true;
806 }
807
808 bool
809 ManifestHandler::OnAppControlsEndElement(void)
810 {
811         delete __pParser;
812         __isParserMode = false;
813         AppLog("------------------------------------------");
814
815         return true;
816 }
817
818 bool
819 ManifestHandler::OnManifestEndElement(void)
820 {
821         TryReturn(__isDefaultAppDetected, false, "[osp-installer][Error] Main tag is not detected...");
822         AppLog("</Manifest>");
823
824         return true;
825 }
826
827 bool
828 ManifestHandler::OnIdValue(const char *pCharacters)
829 {
830         AppLog("<Id>%s</Id>", pCharacters);
831         __pContext->__packageId = pCharacters;
832
833         return true;
834 }
835
836 bool
837 ManifestHandler::OnVersionValue(const char *pCharacters)
838 {
839         AppLog("<Version>%s</Version>", pCharacters);
840         __pContext->__version = pCharacters;
841
842         return true;
843 }
844
845 bool
846 ManifestHandler::OnTypeValue(const char *pCharacters)
847 {
848         AppLog("<Type>%s</Type>", pCharacters);
849
850         if (strcasecmp(pCharacters, "Contents") == 0)
851         {
852                 __pContext->__apiVersion = L"3.0";
853         }
854
855         return true;
856 }
857
858 bool
859 ManifestHandler::OnAuthorValue(const char *pCharacters)
860 {
861         AppLog("<Author>%s</Author>", pCharacters);
862         __pContext->__author = pCharacters;
863
864         return true;
865 }
866
867 bool
868 ManifestHandler::OnUrlValue(const char *pCharacters)
869 {
870         __pContext->__url = pCharacters;
871         AppLog("<Url>%s</Url>", pCharacters);
872
873         return true;
874 }
875
876 bool
877 ManifestHandler::OnApiVersionValue(const char *pCharacters)
878 {
879         __pContext->__apiVersion = pCharacters;
880         AppLog("<ApiVersion>%s</ApiVersion>", pCharacters);
881
882         XmlAttribute *pAttr = GetAttribute();
883         if (pAttr)
884         {
885                 char* pOspCompat = pAttr->Find("OspCompat");
886                 if (pOspCompat)
887                 {
888                         AppLog(" - OspCompat=%s", pOspCompat);
889                         __pContext->__isOspCompat = true;
890                 }
891         }
892
893         return true;
894 }
895
896 bool
897 ManifestHandler::OnPrivilegeValue(const char *pCharacters)
898 {
899         __pPrivilegeList->Add(*new (std::nothrow) String(pCharacters));
900         AppLog("<Privilege>%s</Privilege>", pCharacters);
901
902         return true;
903 }
904
905 bool
906 ManifestHandler::OnIconValue(const char *pCharacters)
907 {
908         AppLog("<Icon>%s</Icon>", pCharacters);
909
910         XmlAttribute* pAttr = GetAttribute();
911         TryReturn(pAttr, true, "pAttr is null");
912
913         char* pSection = pAttr->Find("Section");
914         TryReturn(pSection, true, "pSection is null");
915         AppLog(" - Section=%s", pSection);
916
917         TryReturn(__pDefaultIconType, false, "__pDefaultIconType is null");
918
919         String iconRelPath;
920         char* pType = pAttr->Find("Type");
921         if (pType == null)
922         {
923                 AppLog("__pDefaultIconType=%s", __pDefaultIconType);
924                 if (strcasecmp(__pDefaultIconType, "Xhigh") == 0)
925                 {
926                         iconRelPath.Format(1024, L"screen-density-xhigh/%s", pCharacters);
927                 }
928                 else if (strcasecmp(__pDefaultIconType, "High") == 0)
929                 {
930                         iconRelPath.Format(1024, L"screen-density-high/%s", pCharacters);
931                 }
932                 else
933                 {
934                         TryReturn(0, false, "Invalid __pDefaultIconType[%s]", __pDefaultIconType);
935                 }
936         }
937         else    // legacy
938         {
939                 AppLog(" - Type=%s", pType);
940                 if (strcasecmp(pType, "Xhigh") == 0)
941                 {
942                         iconRelPath.Format(1024, L"screen-density-xhigh/%s", pCharacters);
943                 }
944                 else if (strcasecmp(pType, "High") == 0)
945                 {
946                         iconRelPath.Format(1024, L"screen-density-high/%s", pCharacters);
947                 }
948                 else
949                 {
950                         TryReturn(0, false, "Invalid IconType [%s]", __pDefaultIconType);
951                 }
952         }
953
954         if (FindElement("Content") == true)
955         {
956                 TryReturn(__pContentData, false, "__pContentData is null");
957                 __pContentData->SetIcon(iconRelPath);
958         }
959         else
960         {
961                 if (pType == null)
962                 {
963                         if (strcasecmp(pSection, "MainMenu") == 0)
964                         {
965                                 __pAppData->__mainmenuIcon = iconRelPath;
966                         }
967                         else if (strcasecmp(pSection, "Setting") == 0)
968                         {
969                                 __pAppData->__settingIcon = iconRelPath;
970                         }
971                         else if (strcasecmp(pSection, "Notification") == 0)
972                         {
973                                 __pAppData->__notificationIcon = iconRelPath;
974                         }
975                 }
976                 else    // legacy
977                 {
978                         if (strcasecmp(pSection, "MainMenu") == 0)
979                         {
980                                 if (__isDefaultMainmenu == false)
981                                 {
982                                         __pAppData->__mainmenuIcon = iconRelPath;
983                                 }
984
985                                 if (strcasecmp(pType, __pDefaultIconType) == 0)
986                                 {
987                                         __isDefaultMainmenu = true;
988                                 }
989                         }
990                         else if (strcasecmp(pSection, "Setting") == 0)
991                         {
992                                 if (__isDefaultSetting == false)
993                                 {
994                                         __pAppData->__settingIcon = iconRelPath;
995                                 }
996
997                                 if (strcasecmp(pType, __pDefaultIconType) == 0)
998                                 {
999                                         __isDefaultSetting = true;
1000                                 }
1001                         }
1002                         else if (strcasecmp(pSection, "Notification") == 0)
1003                         {
1004                                 if (__isDefaultQuickpanel == false)
1005                                 {
1006                                         __pAppData->__notificationIcon = iconRelPath;
1007                                 }
1008
1009                                 if (strcasecmp(pType, __pDefaultIconType) == 0)
1010                                 {
1011                                         __isDefaultQuickpanel = true;
1012                                 }
1013                         }
1014                 }
1015         }
1016
1017         return true;
1018 }
1019
1020 bool
1021 ManifestHandler::OnNameValue(const char *pCharacters)
1022 {
1023         XmlAttribute* pAttr = 0;
1024         char* pAttrValue = 0;
1025
1026         pAttr = GetAttribute();
1027         TryReturn(pAttr, true, "pAttr is null");
1028
1029         pAttrValue = pAttr->Find("Locale");
1030         TryReturn(pAttrValue, true, "pAttrValue is null");
1031
1032         if (FindElement("Content") == true)
1033         {
1034                 TryReturn(__pContentData, false, "__pContentData is null");
1035
1036                 String* pValue = new (std::nothrow) String;
1037                 StringUtil::Utf8ToString(pCharacters, *pValue);
1038                 __pContentData->AddName(*(new (std::nothrow) String(pAttrValue)), *pValue);
1039         }
1040         else
1041         {
1042                 if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0)
1043                 {
1044                         if (__isDefaultName == true)
1045                         {
1046                                 __pContext->__displayName = pCharacters;
1047                         }
1048                 }
1049
1050                 String* pValue = new (std::nothrow) String;
1051                 StringUtil::Utf8ToString(pCharacters, *pValue);
1052
1053                 __pAppData->__pNameList->Add((new (std::nothrow) String(pAttrValue)), pValue);
1054         }
1055
1056         AppLog("<DisplayName Locale=\"%s\">%s</DisplayName>", pAttrValue, pCharacters);
1057
1058         return true;
1059 }
1060
1061 bool
1062 ManifestHandler::OnDescriptionValue(const char *pCharacters)
1063 {
1064         XmlAttribute *pAttr = 0;
1065         char *pAttrValue = 0;
1066
1067         pAttr = GetAttribute();
1068         TryReturn(pAttr, true, "pAttr is null");
1069
1070         pAttrValue = pAttr->Find("Locale");
1071         TryReturn(pAttrValue, true, "pAttrValue is null");
1072
1073         if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0)
1074         {
1075                 __pContext->__description = pCharacters;
1076         }
1077
1078         AppLog("<Description Locale=\"%s\">%s</Description>", pAttrValue, pCharacters);
1079
1080         return true;
1081 }
1082
1083 bool
1084 ManifestHandler::OnDataControlTypeValue(const char *pCharacters)
1085 {
1086         XmlAttribute* pAttr = null;
1087         char* pAccessValue = null;
1088
1089         pAttr = GetAttribute();
1090         TryReturn(pAttr, true, "pAttr is null");
1091
1092         pAccessValue = pAttr->Find("Access");
1093         TryReturn(pAccessValue, true, "pAccessValue is null");
1094
1095         __pDataControlType = new (std::nothrow) DataControlType;
1096         TryReturn(__pDataControlType, false, "__pDataControlType is null");
1097
1098         __pDataControlType->__type = pCharacters;
1099         __pDataControlType->__access = pAccessValue;
1100
1101         AppLog("<DataControlType Access=\"%s\", Type=\"%s\">", pAccessValue, pCharacters);
1102
1103         return true;
1104 }
1105
1106 bool
1107 ManifestHandler::OnConditionValue(const char *pCharacters)
1108 {
1109         XmlAttribute *pAttr = null;
1110         char *pName = null;
1111
1112         pAttr = GetAttribute();
1113         TryReturn(pAttr, true, "pAttr is null");
1114
1115         pName = pAttr->Find("Name");
1116         TryReturn(pName, true, "pName is null");
1117
1118         String* pKey = new (std::nothrow) String(pName);
1119         TryReturn(pKey, false, "pKey is null");
1120         String* pValue = new (std::nothrow) String(pCharacters);
1121         TryReturn(pValue, false, "pValue is null");
1122
1123         __pAppData->__pLaunchConditionList->Add(pKey, pValue);
1124         AppLog("<LaunchCondition Name=\"%s\", Value=\"%s\">", pName, pCharacters);
1125
1126         return true;
1127 }
1128
1129 bool
1130 ManifestHandler::OnNotificationValue(const char *pCharacters)
1131 {
1132         XmlAttribute *pAttr = null;
1133         const char *pName = null;
1134
1135         pAttr = GetAttribute();
1136         TryReturn(pAttr, true, "pAttr is null.");
1137
1138         pName = pAttr->Find("Name");
1139         TryReturn(pName, true, "pName is null.");
1140
1141         if (strcasecmp(pName, "Ticker") == 0)
1142         {
1143                 pName = "Notification";
1144         }
1145         else if (strcasecmp(pName, "Notification") == 0 || strcasecmp(pName, "Sounds") == 0
1146                         || strcasecmp(pName, "Badge") == 0 || strcasecmp(pName, "Contents") == 0)
1147         {
1148                 // known notification attributes
1149         }
1150         else
1151         {
1152                 TryReturn(0, true, "Unknown notification attributes=%s", pCharacters);
1153         }
1154
1155         String* pKey = new (std::nothrow) String(pName);
1156         TryReturn(pKey, false, "pKey is null.");
1157
1158         String* pValue = new (std::nothrow) String(pCharacters);
1159         TryReturn(pValue, false, "pValue is null.");
1160
1161         pKey->ToLowerCase();
1162         pValue->ToLowerCase();
1163
1164         __pAppData->__pNotificationMap->Add(pKey, pValue);
1165         AppLog("<Notification Name=\"%s\", Value=\"%s\">", pName, pCharacters);
1166
1167         return true;
1168 }
1169
1170 bool
1171 ManifestHandler::OnInstallationLocationValue(const char *pCharacters)
1172 {
1173         AppLog("<InstallationLocation>%s</InstallationLocation>", pCharacters);
1174
1175         if ((strcasecmp(pCharacters, "UserPreferred") == 0) &&
1176                         (File::IsFileExist(DIR_MEMORYCARD_INSTALLATION) == true))
1177         {
1178                 AppLog("INSTALLATION_STORAGE = [EXTERNAL]");
1179                 __pContext->__storage = INSTALLATION_STORAGE_EXTERNAL;
1180         }
1181
1182         return true;
1183 }
1184
1185 bool
1186 ManifestHandler::OnCategoryValue(const char *pCharacters)
1187 {
1188         TryReturn(__pAppData, false, "__pAppData is null");
1189
1190         __pAppData->__pCategoryList->Add(new (std::nothrow) String(pCharacters));
1191
1192         if (strcasecmp(pCharacters, TIZEN_CATEGORY_IME) == 0)
1193         {
1194                 __pAppData->__feature = CATEGORY_TYPE_IME;
1195         }
1196
1197         return true;
1198 }
1199
1200 bool
1201 ManifestHandler::FindElement(const char *pName)
1202 {
1203         bool res = false;
1204         Tizen::Base::Collection::IEnumerator* pEnum = GetElementEnumeratorN();
1205
1206         if (pEnum)
1207         {
1208                 while(pEnum->MoveNext() == E_SUCCESS)
1209                 {
1210                         String* pStr = static_cast<String*>(pEnum->GetCurrent());
1211                         if (pStr)
1212                         {
1213                                 if (pStr->Equals(pName, false) == true)
1214                                 {
1215                                         AppLog("[%s] is matched.", pName);
1216                                         res = true;
1217                                         break;
1218                                 }
1219                         }
1220                 }
1221
1222                 delete pEnum;
1223         }
1224
1225         return res;
1226 }
1227
1228 bool
1229 ManifestHandler::AddAppFeature(const Tizen::Base::String& name, const Tizen::Base::String& value)
1230 {
1231         String* pKey = new (std::nothrow) String(name);
1232         TryReturn(pKey, false, "pKey is null");
1233         String* pValue = new (std::nothrow) String(value);
1234         TryReturn(pValue, false, "pValue is null");
1235
1236         __pAppData->__pFeatureList->Add(pKey, pValue);
1237         return true;
1238 }
1239
1240 bool
1241 ManifestHandler::ParseAppAttribute(XmlAttribute* pAttr, bool isUiApp)
1242 {
1243         char* pName = pAttr->Find("Name");
1244         if (pName == null)
1245         {
1246                 pName = pAttr->Find("ExecutableName");
1247         }
1248
1249         if (pName)
1250         {
1251                 AppLog(" - Name=%s", pName);
1252                 __pAppData->__name = pName;
1253                 __pAppData->__appId = __pContext->__packageId + L"." + pName;
1254         }
1255
1256         char* pMain = pAttr->Find("Main");
1257         if (pMain == null)
1258         {
1259                 pMain = pAttr->Find("Default");
1260         }
1261
1262         if (pMain)
1263         {
1264                 AppLog(" - Main=%s", pMain);
1265                 __pAppData->__main = pMain;
1266
1267                 if (strcasecmp(pMain, "True") == 0)
1268                 {
1269                         __isDefaultName = true;
1270                         __isDefaultAppDetected = true;
1271                         __pContext->__mainAppName = pName;
1272                 }
1273         }
1274         else
1275         {
1276                 __pAppData->__main = L"False";
1277         }
1278
1279         char* pRecent = pAttr->Find("LaunchingHistoryVisible");
1280         if (pRecent)
1281         {
1282                 AppLog(" - LaunchingHistoryVisible=%s", pRecent);
1283                 __pAppData->__launchingHistoryVisible = pRecent;
1284         }
1285
1286         char* pHwAcceleration = pAttr->Find("HwAcceleration");
1287         if (pHwAcceleration)
1288         {
1289                 AddAppFeature("HwAcceleration", pHwAcceleration);
1290                 AppLog(" - HwAcceleration=%s", pHwAcceleration);
1291         }
1292         else
1293         {
1294                 char* pGlFrame = pAttr->Find("GlFrame");
1295                 if (pGlFrame)
1296                 {
1297                         AddAppFeature("GlFrame", pGlFrame);
1298                         AppLog(" - GlFrame=%s", pGlFrame);
1299                 }
1300         }
1301
1302         char* pCategory = pAttr->Find("Category");
1303         if (pCategory)
1304         {
1305                 AppLog(" - Category=%s", pCategory);
1306
1307                 if (strcasecmp(pCategory, "home-screen") == 0)
1308                 {
1309                         __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_HOMESCREEN));
1310                 }
1311                 else if (strcasecmp(pCategory, "lock-screen") == 0)
1312                 {
1313                         __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_LOCKSCREEN));
1314                 }
1315                 else if (strcasecmp(pCategory, "Ime") == 0)
1316                 {
1317                         __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_IME));
1318                 }
1319
1320                 int categoryType = InstallerUtil::GetCategoryType(pCategory);
1321                 __pAppData->__feature = categoryType;
1322         }
1323
1324         char* pSubMode = pAttr->Find("SubMode");
1325         if (pSubMode)
1326         {
1327                 if (strcasecmp(pSubMode, "True") == 0)
1328                 {
1329                         __pAppData->__isSubMode = true;
1330                         AppLog(" - SubMode=%s", pSubMode);
1331                 }
1332         }
1333
1334         if (isUiApp == true)
1335         {
1336                 __pAppData->__type = L"UiApp";
1337
1338                 char* pMenuIconVisible = pAttr->Find("MenuIconVisible");
1339                 if (pMenuIconVisible == null)
1340                 {
1341                         pMenuIconVisible = pAttr->Find("MainmenuVisible");
1342                 }
1343
1344                 if (pMenuIconVisible)
1345                 {
1346                         if (strcasecmp(pMenuIconVisible, "True") == 0)
1347                         {
1348                                 __pAppData->__mainmenuVisible = true;
1349                         }
1350                         else
1351                         {
1352                                 __pAppData->__mainmenuVisible = false;
1353                         }
1354
1355                         AddAppFeature("MenuIconVisible", pMenuIconVisible);
1356                         AppLog(" - MenuIconVisible=%s", pMenuIconVisible);
1357                 }
1358         }
1359         else
1360         {
1361                 __pAppData->__type = L"ServiceApp";
1362                 __pAppData->__mainmenuVisible = false;
1363
1364                 char *pUseUi = pAttr->Find("UseUi");
1365                 if (pUseUi)
1366                 {
1367                         AddAppFeature("UseUi", pUseUi);
1368                         AppLog(" - UseUi=%s", pUseUi);
1369                 }
1370
1371                 char *pLifeDuration = pAttr->Find("LifeDuration");
1372                 if (pLifeDuration)
1373                 {
1374                         AddAppFeature("LifeDuration", pLifeDuration);
1375                         AppLog(" - LifeDuration=%s", pLifeDuration);
1376                 }
1377
1378                 char *pLaunchOnBoot = pAttr->Find("LaunchOnBoot");
1379                 if (pLaunchOnBoot)
1380                 {
1381                         AddAppFeature("LaunchOnBoot", pLaunchOnBoot);
1382                         AppLog(" - LaunchOnBoot=%s", pLaunchOnBoot);
1383                 }
1384
1385                 char *pAutoRestart = pAttr->Find("AutoRestart");
1386                 if (pAutoRestart)
1387                 {
1388                         AddAppFeature("AutoRestart", pAutoRestart);
1389                         AppLog(" - AutoRestart=%s", pAutoRestart);
1390                 }
1391
1392                 char *pSystemService = pAttr->Find("SystemService");
1393                 if (pSystemService)
1394                 {
1395                         if (strcasecmp(pSystemService, "True") == 0)
1396                         {
1397                                 __pAppData->__isSystemService = true;
1398                                 AppLog(" - SystemService=%s", pSystemService);
1399                         }
1400                 }
1401         }
1402
1403         AppLog(" - appId=%ls", __pAppData->__appId.GetPointer());
1404
1405         return true;
1406 }
1407
1408 AppData*
1409 ManifestHandler::GetAppData(void)
1410 {
1411         return __pAppData;
1412 }
1413
1414 char*
1415 ManifestHandler::GetDefaultIconType(void)
1416 {
1417         return __pDefaultIconType;
1418 }
1419