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