2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file ManifestGenerator.cpp
19 * @brief This is the implementation file for %ManifestGenerator class.
24 #include <FLclLocale.h>
26 #include <FAppPkg_PackageInfoImpl.h>
29 #include "ManifestGenerator.h"
30 #include "InstallerUtil.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::App;
35 using namespace Tizen::App::Package;
36 using namespace Tizen::Locales;
37 using namespace Tizen::Io;
39 ManifestGenerator::ManifestGenerator(void)
41 ,__pPackageInfoImpl(null)
46 ManifestGenerator::~ManifestGenerator(void)
53 ManifestGenerator::Construct(InstallationContext* pContext)
55 __pContext = pContext;
56 __pPackageInfoImpl = pContext->GetPackageInfoImpl();
58 __pWriter = new (std::nothrow) XmlWriter;
59 TryReturn(__pWriter, false, "[osp-installer] __pWriter is null.");
65 ManifestGenerator::Write()
67 //bool preload = false; //__pContext->IsPreloaded();
71 _PackageInfoImpl *pPackageInfoImpl = null;
72 pPackageInfoImpl = __pContext->GetPackageInfoImpl();
73 TryReturn(pPackageInfoImpl, false, "[osp-installer] pPackageInfoImpl is null.");
75 //if (preload == true)
77 // xmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, __pContext->GetAppId().GetPointer());
78 // location = L"internal-only";
82 xmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, __pContext->GetAppId().GetPointer());
86 package = __pContext->GetAppId();
88 __pWriter->Construct(xmlPath);
90 __pWriter->StartElement("manifest");
91 __pWriter->WriteAttribute("xmlns", "http://tizen.org/ns/packages");
92 __pWriter->WriteAttribute("package", package);
93 __pWriter->WriteAttribute("type", "tpk");
94 __pWriter->WriteAttribute("version", pPackageInfoImpl->GetAppVersion());
95 __pWriter->WriteAttribute("install-location", location);
97 __pWriter->StartElement("label");
98 __pWriter->WriteString(pPackageInfoImpl->GetAppName());
99 __pWriter->EndElement();
101 __pWriter->StartElement("author");
102 __pWriter->EndElement();
104 __pWriter->StartElement("description");
105 __pWriter->WriteString(pPackageInfoImpl->GetAppDescription());
106 __pWriter->EndElement();
108 _PackageAppInfoImpl* pAppInfoImpl = null;
109 ArrayList* pAppList = null;
110 pAppList = pPackageInfoImpl->GetAppInfoList();
111 int appCount = pAppList->GetCount();
112 AppLogTag(OSP_INSTALLER, "Write(): appCount=%d", appCount);
114 for (int i = 0 ; i < appCount; i++)
116 pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i));
119 WriteApp(i, pAppInfoImpl);
123 if (__pContext->__isSubMode == true)
125 AppLogTag(OSP_INSTALLER, "Write(): __pContext->__isSubMode is detected");
126 WriteSubModeApp(appCount);
129 __pWriter->EndElement();
135 ManifestGenerator::FindFeatureValue(ArrayList* pFeatureList, const String& feature, const String& value) const
137 TryReturn(pFeatureList, false, "[osp-installer] pFeatureList is null.");
139 _AppFeatureInfoImpl* pFeature = null;
141 for (int i = 0 ; i < pFeatureList->GetCount(); i++)
143 pFeature = dynamic_cast<_AppFeatureInfoImpl*>(pFeatureList->GetAt(i));
146 if ((pFeature->GetName() == feature) && (pFeature->GetValue() == value))
148 AppLogTag(OSP_INSTALLER, "Find - feature=[%ls], value=[%ls]", feature.GetPointer(), value.GetPointer());
158 ManifestGenerator::GetGlFrameValue(ArrayList* pFeatureList) const
160 if (pFeatureList == null)
162 return "use-system-setting";
165 _AppFeatureInfoImpl* pFeature = null;
166 for (int i = 0 ; i < pFeatureList->GetCount(); i++)
168 pFeature = dynamic_cast<_AppFeatureInfoImpl*>(pFeatureList->GetAt(i));
169 if (pFeature == null)
171 return "use-system-setting";
174 if (pFeature->GetName() == L"HwAcceleration" || pFeature->GetName() == L"GlFrame")
176 String value = pFeature->GetValue();
181 else if (value == L"Off")
188 return "use-system-setting";
192 ManifestGenerator::WriteLanguageValue(IMap* pList, const String& element) const
194 TryReturn(pList, false, "[osp-installer] pNameList is null.");
196 IMapEnumerator* pMapEnum = pList->GetMapEnumeratorN();
197 while (pMapEnum->MoveNext() == E_SUCCESS)
199 String* pLanguage = null;
200 String* pValue = null;
201 String threeLetterCode;
205 pLanguage = static_cast<String*> (pMapEnum->GetKey());
206 pValue = static_cast<String*> (pMapEnum->GetValue());
208 pLanguage->SubString(0, 3, threeLetterCode);
209 pLanguage->SubString(4, 2, countryCode);
211 LanguageCode code = Locale::StringToLanguageCode(threeLetterCode);
212 String twoLetterLanguage = Locale::LanguageCodeToTwoLetterLanguageCodeString(code);
214 launguage = twoLetterLanguage + L"-" + countryCode;
215 launguage.ToLowerCase();
217 if (((*pLanguage) == L"eng-GB") || ((*pLanguage) == L"eng-US"))
219 __pWriter->StartElement(element);
220 __pWriter->WriteString(*pValue);
221 __pWriter->EndElement();
224 __pWriter->StartElement(element);
225 __pWriter->WriteAttribute("xml:lang", launguage);
226 __pWriter->WriteString(*pValue);
227 __pWriter->EndElement();
235 ManifestGenerator::WriteLiveboxes(_PackageAppInfoImpl* pAppInfoImpl) const
237 TryReturn(__pContext, false, "[osp-installer] __pContext is null.");
238 TryReturn(__pWriter, false, "[osp-installer] __pWriter is null.");
240 ArrayList* pLiveboxList = __pContext->GetLiveBoxList();
241 _PackageInfoImpl* pPackageInfoImpl = __pContext->GetPackageInfoImpl();
242 String label("label");
244 if (pLiveboxList == null)
249 for (int j = 0 ; j < pLiveboxList->GetCount(); j++)
251 LiveboxInfo* pLiveboxInfo = dynamic_cast<LiveboxInfo*>(pLiveboxList->GetAt(j));
252 if (pLiveboxInfo == null)
254 AppLogTag(OSP_INSTALLER, "pLiveboxInfo is null [%d]", j);
258 long long updatePeriod = pLiveboxInfo->GetUpdatePeriod();
259 String period = LongLong::ToString(updatePeriod/1000);
260 IMap* pLiveboxNameList = pLiveboxInfo->GetNameList();
261 ArrayList* pSizeList = pLiveboxInfo->GetSizeList();
262 String popupEnabled = pLiveboxInfo->GetPopupEnabled();
264 __pWriter->StartElement("livebox");
266 __pWriter->WriteAttribute("appid", pAppInfoImpl->GetPackageName() + "." + pLiveboxInfo->GetName() );
267 __pWriter->WriteAttribute("period", period);
268 __pWriter->WriteAttribute("pinup", "false");
269 __pWriter->WriteAttribute("primary", "true");
270 __pWriter->WriteAttribute("auto_launch", "false");
271 __pWriter->WriteAttribute("abi", "osp");
273 WriteLanguageValue(pLiveboxNameList, label);
275 if (pLiveboxInfo->GetIcon().IsEmpty() == false)
278 liveboxIcon.Format(1024, L"%ls%ls/%ls", pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_SHARED_RES, pLiveboxInfo->GetIcon().GetPointer());
280 __pWriter->StartElement("icon");
281 __pWriter->WriteString(liveboxIcon);
282 __pWriter->EndElement();
287 __pWriter->StartElement("box");
288 __pWriter->WriteAttribute("type", "buffer");
290 for (int k = 0 ; k < pSizeList->GetCount(); k++)
292 String* pSize = dynamic_cast<String*>(pSizeList->GetAt(k));
295 AppLogTag(OSP_INSTALLER, "pSize is null [%d]", k);
299 __pWriter->StartElement("size");
300 __pWriter->WriteString(*pSize);
301 __pWriter->EndElement();
303 __pWriter->EndElement();
306 popupEnabled.ToLowerCase();
307 if (popupEnabled == L"true")
309 __pWriter->StartElement("pd");
310 __pWriter->WriteAttribute("type", "buffer");
312 __pWriter->StartElement("size");
313 __pWriter->WriteString("720x250");
314 __pWriter->EndElement();
316 __pWriter->EndElement();
318 __pWriter->EndElement();
325 ManifestGenerator::WriteAppControl(_PackageAppInfoImpl* pAppInfoImpl) const
327 TryReturn(pAppInfoImpl, false, "[osp-installer] pAppInfoImpl is null.");
329 ArrayList* pAppControlImplList = pAppInfoImpl->GetAppControlList();
330 TryReturn(pAppControlImplList, false, "[osp-installer] pAppControlImplList is null.");
332 _AppControlInfoImpl* pAppControl = dynamic_cast<_AppControlInfoImpl*>(pAppControlImplList->GetAt(0));
333 TryReturn(pAppControl, false, "[osp-installer] pAppControl is null.");
335 ArrayList* pCapabilityList = pAppControl->GetCapabilityList();
336 TryReturn(pCapabilityList, false, "[osp-installer] pCapabilityList is null.");
338 int capaCount = pCapabilityList->GetCount();
339 for (int capaIndex = 0 ; capaIndex < capaCount; capaIndex++)
341 _AppControlCapabilityInfoImpl* pCapability = dynamic_cast<_AppControlCapabilityInfoImpl*>(pCapabilityList->GetAt(capaIndex));
342 if (pCapability == null) continue;
344 String operationId = pCapability->GetOperationId();
346 ArrayList* pResolutionList = pCapability->GetResolutionList();
347 int resCount = pResolutionList->GetCount();
351 __pWriter->StartElement("application-service");
352 __pWriter->StartElement("operation");
353 __pWriter->WriteAttribute("name", operationId);
354 __pWriter->EndElement();
355 __pWriter->EndElement();
359 for (int resIndex = 0 ; resIndex < resCount; resIndex++)
361 __pWriter->StartElement("application-service");
362 __pWriter->StartElement("operation");
363 __pWriter->WriteAttribute("name", operationId);
364 __pWriter->EndElement();
366 _AppControlResolutionInfoImpl* pResolution = dynamic_cast <_AppControlResolutionInfoImpl*>(pResolutionList->GetAt(resIndex));
367 if (pResolution == null) continue;
369 String* pUriScheme = pResolution->GetUriScheme();
370 if (pUriScheme && pUriScheme->IsEmpty() == false)
372 __pWriter->StartElement("uri");
373 __pWriter->WriteAttribute("name", *pUriScheme);
374 __pWriter->EndElement();
377 String* pMimeType = pResolution->GetMimeType();
378 if (pMimeType && pMimeType->IsEmpty() == false)
380 __pWriter->StartElement("mime");
381 __pWriter->WriteAttribute("name", *pMimeType);
382 __pWriter->EndElement();
385 __pWriter->EndElement();
393 ManifestGenerator::WriteCategory(int index) const
395 IListT<AppData*>* pAppDataList = __pContext->__pAppDataList;
396 TryReturn(pAppDataList, true, "[osp-installer] pAppDataList is null");
398 AppData* pAppData = null;
399 pAppDataList->GetAt(index, pAppData);
400 TryReturn(pAppData, true, "[osp-installer] pAppData is null");
402 IListT<String*>* pCategoryList = pAppData->__pCategoryList;
403 TryReturn(pCategoryList, true, "[osp-installer] pCategoryList is null");
405 for (int i = 0; i < pCategoryList->GetCount(); i++)
408 pCategoryList->GetAt(i, pStr);
409 TryReturn(pStr, false, "[osp-installer] pStr is null");
411 AppLogTag(OSP_INSTALLER, "WriteCategory(): Category String=[%ls]", pStr->GetPointer());
413 __pWriter->StartElement("category");
414 __pWriter->WriteAttribute("name", *pStr);
415 __pWriter->EndElement();
422 ManifestGenerator::FindCategory(int index, const String& category) const
424 result r = E_SUCCESS;
426 IListT<AppData*>* pAppDataList = __pContext->__pAppDataList;
427 TryReturn(pAppDataList, false, "[osp-installer] pAppDataList is null");
429 AppData* pAppData = null;
430 r = pAppDataList->GetAt(index, pAppData);
431 TryReturn(pAppData, false, "[osp-installer] pAppData is null");
433 IListT<String*>* pCategoryList = pAppData->__pCategoryList;
434 TryReturn(pCategoryList, false, "[osp-installer] pCategoryList is null");
436 for (int i = 0; i < pCategoryList->GetCount(); i++)
439 pCategoryList->GetAt(i, pStr);
440 TryReturn(pStr, false, "[osp-installer] pStr is null");
442 if (*pStr == category)
444 AppLogTag(OSP_INSTALLER, "FindCategory(): Category is found=[%ls]", pStr->GetPointer());
454 ManifestGenerator::WriteApp(int index, Tizen::App::Package::_PackageAppInfoImpl* pAppInfoImpl)
456 _PackageInfoImpl *pPackageInfoImpl = null;
457 pPackageInfoImpl = __pContext->GetPackageInfoImpl();
459 IMap* pNameList = pAppInfoImpl->GetNameList();
460 String label("label");
461 String type("c++app");
463 binaryPath.Format(1024, L"%ls%ls/%ls", pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_BIN, pAppInfoImpl->GetName().GetPointer());
465 if (pAppInfoImpl->GetDefault() == L"True")
467 WriteLanguageValue(pNameList, label);
469 if (pAppInfoImpl->GetMainmenuIcon().IsEmpty() == false)
472 iconPath.Format(1024, L"%ls%ls/%ls", pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_SHARED_RES, pAppInfoImpl->GetMainmenuIcon().GetPointer());
474 __pWriter->StartElement("icon");
475 __pWriter->WriteString(iconPath);
476 __pWriter->EndElement();
480 String nodisplay("true");
481 String taskmanage("false");
484 if (pAppInfoImpl->GetType() == L"UiApp")
486 taskmanage = L"true";
488 if (pAppInfoImpl->IsMainmenuVisible() == true)
490 nodisplay = L"false";
497 if (FindCategory(index, "http://tizen.org/category/ime") == true)
499 AppLogTag(OSP_INSTALLER, "Write(): [http://tizen.org/category/ime] is detected. taskmanage=false, nodisplay=true");
500 taskmanage = L"false";
505 ArrayList* pFeatureList = pAppInfoImpl->GetAppFeatureList();
506 String glFrame = GetGlFrameValue(pFeatureList);
508 __pWriter->StartElement("ui-application");
509 __pWriter->WriteAttribute("appid", pAppInfoImpl->GetPackageName());
510 __pWriter->WriteAttribute("exec", binaryPath);
511 __pWriter->WriteAttribute("nodisplay", nodisplay);
512 __pWriter->WriteAttribute("taskmanage", taskmanage);
513 __pWriter->WriteAttribute("multiple", "false");
514 __pWriter->WriteAttribute("type", type);
515 __pWriter->WriteAttribute("hw-acceleration", glFrame);
517 WriteCategory(index);
520 if (pAppInfoImpl->GetType() == L"UiApp")
524 if (pAppInfoImpl->IsMainmenuVisible() == true)
533 __pWriter->StartElement("ui-application");
534 __pWriter->WriteAttribute("appid", pAppInfoImpl->GetPackageName());
535 __pWriter->WriteAttribute("exec", binaryPath);
536 __pWriter->WriteAttribute("nodisplay", nodisplay);
537 __pWriter->WriteAttribute("taskmanage", "true");
538 __pWriter->WriteAttribute("multiple", "false");
539 __pWriter->WriteAttribute("type", type);
541 else if (pAppInfoImpl->GetType() == L"ServiceApp")
543 ArrayList* pFeatureList = pAppInfoImpl->GetAppFeatureList();
544 String onBoot("false");
545 String autoRestart("false");
547 if (FindFeatureValue(pFeatureList, "LaunchOnBoot", "True") == true)
552 if (FindFeatureValue(pFeatureList, "AutoRestart", "True") == true)
554 autoRestart = L"true";
557 __pWriter->StartElement("service-application");
558 __pWriter->WriteAttribute("appid", pAppInfoImpl->GetPackageName());
559 __pWriter->WriteAttribute("exec", binaryPath);
560 __pWriter->WriteAttribute("type", type);
561 __pWriter->WriteAttribute("on-boot", onBoot);
562 __pWriter->WriteAttribute("auto-restart", autoRestart);
566 AppLogTag(OSP_INSTALLER, "Type is invalid! [%ls]", pAppInfoImpl->GetType().GetPointer());
571 WriteLanguageValue(pNameList, label);
573 if (pAppInfoImpl->GetMainmenuIcon().IsEmpty() == false)
576 iconPath.Format(1024, L"%ls%ls/%ls", pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_SHARED_RES, pAppInfoImpl->GetMainmenuIcon().GetPointer());
578 __pWriter->StartElement("icon");
579 __pWriter->WriteString(iconPath);
580 __pWriter->EndElement();
583 WriteAppControl(pAppInfoImpl);
584 WriteAppControl(index);
586 __pWriter->EndElement();
588 if (pAppInfoImpl->GetType() == L"ServiceApp")
590 WriteLiveboxes(pAppInfoImpl);
597 ManifestGenerator::WriteSubModeApp(int index)
599 _PackageInfoImpl *pPackageInfoImpl = null;
600 pPackageInfoImpl = __pContext->GetPackageInfoImpl();
603 binaryPath.Format(1024, L"%ls%ls/%ls", pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_BIN, SUB_MODE_APPCONTROL_NAME);
605 String binaryExecPath = binaryPath + ".exe";
607 InstallerUtil::Copy(UIAPP_LOADER_PATH, binaryExecPath);
608 InstallerUtil::ChangeMode(binaryExecPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
610 if (File::IsFileExist(binaryPath) == true)
612 InstallerUtil::Remove(binaryPath);
615 InstallerUtil::CreateSymlink(binaryExecPath, binaryPath);
617 IListT<AppData*>* pAppDataList = __pContext->__pAppDataList;
618 TryReturn(pAppDataList, false, "[osp-installer] pAppDataList is null");
620 AppLogTag(OSP_INSTALLER, "WriteSubModeApp(): appCount=%d", pAppDataList->GetCount());
622 AppData* pAppData = null;
623 pAppDataList->GetAt(index, pAppData);
624 TryReturn(pAppData, false, "[osp-installer] pAppData is null");
626 PackageId packageId = __pContext->GetAppId();
627 AppId appId = packageId + L"." + SUB_MODE_APPCONTROL_NAME;
629 __pWriter->StartElement("ui-application");
630 __pWriter->WriteAttribute("appid", appId);
631 __pWriter->WriteAttribute("exec", binaryPath);
632 __pWriter->WriteAttribute("nodisplay", "true");
633 __pWriter->WriteAttribute("taskmanage", "false");
634 __pWriter->WriteAttribute("multiple", "true");
635 __pWriter->WriteAttribute("type", "c++app");
637 WriteAppControl(index);
639 __pWriter->EndElement(); // end of "ui-application"
645 ManifestGenerator::WriteAppControl(int index)
647 IListT<AppData*>* pAppDataList = __pContext->__pAppDataList;
648 TryReturn(pAppDataList, false, "[osp-installer] pAppDataList is null");
650 AppData* pAppData = null;
651 pAppDataList->GetAt(index, pAppData);
652 TryReturn(pAppData, false, "[osp-installer] pAppData is null");
654 if (pAppData->__pAppControlData)
656 if (pAppData->__pAppControlData->__pOperationDataList)
658 int operationCount = pAppData->__pAppControlData->__pOperationDataList->GetCount();
660 for (int i = 0; i < operationCount; i++)
662 OperationData* pOperationData = null;
663 pAppData->__pAppControlData->__pOperationDataList->GetAt(i, pOperationData);
665 if (pOperationData == null) continue;
667 __pWriter->StartElement("application-service");
668 __pWriter->StartElement("operation");
669 __pWriter->WriteAttribute("name", pOperationData->__id);
670 __pWriter->EndElement(); // end of "operation"
672 if (pOperationData->__uri.IsEmpty() == false)
674 __pWriter->StartElement("uri");
675 __pWriter->WriteAttribute("name", pOperationData->__uri);
676 __pWriter->EndElement();
679 if (pOperationData->__mimeType.IsEmpty() == false)
681 __pWriter->StartElement("mime");
682 __pWriter->WriteAttribute("name", pOperationData->__mimeType);
683 __pWriter->EndElement();
686 __pWriter->EndElement(); // end of ""application-service""