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 ConfigurationManager.cpp
19 * @brief This is the implementation file for %ConfigurationManager class.
25 #include <unique_ptr.h>
27 #include <pkgmgr_parser.h>
28 #include <pkgmgr_installer.h>
29 #include <pkgmgr-info.h>
30 #include <app2ext_interface.h>
32 #include <FBaseUtilStringUtil.h>
34 #include <FIoDirectory.h>
35 #include <FSecCertX509CertificatePath.h>
37 #include <FBase_StringConverter.h>
39 #include "ConfigurationManager.h"
40 #include "ManifestGenerator.h"
41 #include "InstallerUtil.h"
42 #include "SmackManager.h"
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46 using namespace Tizen::Base::Utility;
47 using namespace Tizen::Security::Cert;
48 using namespace Tizen::App;
49 using namespace Tizen::Io;
51 ConfigurationManager::ConfigurationManager(void)
55 ConfigurationManager::~ConfigurationManager(void)
60 ConfigurationManager::CreateFile(InstallationContext* pContext)
65 rootPath = pContext->__rootPath;
68 apiVersion = pContext->__apiVersion;
69 String versionInfoFile;
70 versionInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), VERSION_INFO_FILE);
71 InstallerUtil::CreateInfoFile(versionInfoFile, &apiVersion);
73 if (pContext->__isOspCompat == true)
75 AppLog("[OspCompat] is detected");
77 String compatInfoFile;
78 compatInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), COMPAT_INFO_FILE);
79 InstallerUtil::CreateInfoFile(compatInfoFile, null);
82 String webServicePrivilege(TIZEN_PRIVILEGE_WEB_SERVICE);
83 if (FindPrivilege(pContext, webServicePrivilege) == true)
85 AppLog("WEB_SERVICE privilege is detected. rootPath=[%ls]", rootPath.GetPointer());
87 String webServiceInfoFile;
88 webServiceInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), WEBSERVICE_INFO_FILE);
89 InstallerUtil::CreateInfoFile(webServiceInfoFile, null);
92 IListT<AppData*>* pAppDataList = pContext->__pAppDataList;
93 TryReturn(pAppDataList, false, "pAppDataList is null");
95 for (int i = 0 ; i < pAppDataList->GetCount(); i++)
97 AppData* pAppData = null;
98 pAppDataList->GetAt(i, pAppData);
99 TryReturn(pAppData, false, "pAppData is null");
101 String appName = pAppData->__name;
102 String appType = pAppData->__type;
103 AppId appId = pAppData->__appId;
106 binaryPath.Format(1024, L"%ls%ls/%ls", rootPath.GetPointer(), DIR_BIN, appName.GetPointer());
108 if (File::IsFileExist(binaryPath) == true)
110 InstallerUtil::Remove(binaryPath);
113 if (appType == L"UiApp")
115 //err = symlink(UIAPP_LOADER_PATH, pBinaryPath);
117 AppLog("copy ui app loader");
118 InstallerUtil::Copy(UIAPP_LOADER_PATH, binaryPath);
120 HashMap* pFeatureList = pAppData->__pFeatureList;
121 TryReturn(pFeatureList, false, "pFeatureList is null");
123 String coordinateSystem;
124 String baseScreenSize;
125 String logicalCoordinate;
127 std::unique_ptr< IMapEnumerator > pEnum(pFeatureList->GetMapEnumeratorN());
128 TryReturn(pEnum, false, "GetMapEnumeratorN() failed. [%s]", GetErrorMessage(GetLastResult()));
130 while (pEnum->MoveNext() == E_SUCCESS)
132 String* pKey = static_cast< String* > (pEnum->GetKey());
133 TryReturn(pEnum, false, "GetKey() failed. [%s]", GetErrorMessage(GetLastResult()));
135 String* pValue = static_cast< String* > (pEnum->GetValue());
136 TryReturn(pEnum, false, "GetValue() failed. [%s]", GetErrorMessage(GetLastResult()));
138 if ((*pKey) == L"CoordinateSystem")
140 coordinateSystem = (*pValue);
143 if ((*pKey) == L"BaseScreenSize")
145 baseScreenSize = (*pValue);
148 if ((*pKey) == L"LogicalCoordinate")
150 logicalCoordinate = (*pValue);
154 String uiScalability;
155 uiScalability.Format(1024, UISCALABILITY_INFO, coordinateSystem.GetPointer(), baseScreenSize.GetPointer(), logicalCoordinate.GetPointer());
157 String uiScalabilityInfoFile;
158 uiScalabilityInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), UISCALABILITY_INFO_FILE);
160 InstallerUtil::CreateInfoFile(uiScalabilityInfoFile, &uiScalability);
162 int categoryType = pAppData->__feature;
163 if (categoryType != CATEGORY_TYPE_NONE)
165 String category = InstallerUtil::GetCategory(categoryType);
166 category.ToLowerCase();
168 int type = _Aul::GetAppType(category);
170 if (category == L"ime")
172 CreateImeSymlink(binaryPath, appId);
176 typeInfo.Format(1024, L"%d", type);
179 typeInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), TYPE_INFO_FILE);
181 InstallerUtil::CreateInfoFile(typeInfoFile, &typeInfo);
184 else if (appType == L"ServiceApp")
186 if (pContext->__isPreloaded == true || pAppData->__isSystemService == true)
188 AppLog("copy system service loader");
189 InstallerUtil::Copy(SYSTEMSERIVCE_LOADER_PATH, binaryPath);
193 AppLog("copy service app loader");
194 InstallerUtil::Copy(SERVICEAPP_LOADER_PATH, binaryPath);
198 InstallerUtil::ChangeMode(binaryPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
201 ArrayList* pContentDataList = pContext->GetContentDataList();
202 if (pContentDataList)
204 int contentCount = pContentDataList->GetCount();
205 for (int i = 0 ; i < contentCount; i++)
207 ContentData* pContentData = static_cast<ContentData*>(pContentDataList->GetAt(i));
210 String contentId = pContentData->GetContentId();
211 String oldPath = rootPath + DIR_CONTENTS + L"/" + contentId;
213 if (File::IsFileExist(SLP_FONT_PATH) == false)
215 Directory::Create(SLP_FONT_PATH, false);
216 InstallerUtil::ChangeMode(SLP_FONT_PATH, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
219 String newPath = SLP_FONT_PATH;
220 newPath += L"/" + pContext->__packageId;
221 Directory::Create(newPath, false);
222 InstallerUtil::ChangeMode(newPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
225 newPath += contentId;
226 InstallerUtil::CreateSymlink(oldPath, newPath);
231 bool firstPreloadedUpdate = false;
234 roXmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, pContext->__packageId.GetPointer());
237 rwXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, pContext->__packageId.GetPointer());
239 if (pContext->__isPreloaded == true)
241 pContext->__coreXmlPath = roXmlPath;
245 pContext->__coreXmlPath = rwXmlPath;
246 if ((File::IsFileExist(roXmlPath) == true) && (File::IsFileExist(rwXmlPath) == false))
248 AppLog("First preloaded app update");
249 firstPreloadedUpdate = true;
253 std::unique_ptr<char[]> pXmlPath(_StringConverter::CopyToCharArrayN(pContext->__coreXmlPath));
254 TryReturn(pXmlPath != null, false, "pXmlPath is null");
256 if (pContext->__isHybridService == true)
258 String webXmlPath = pXmlPath.get();
259 webXmlPath += L".wgt";
260 InstallerUtil::Copy(pXmlPath.get(), webXmlPath);
262 AppLog("pkgmgr_parser_parse_manifest_for_uninstallation(%s) - START", pXmlPath.get());
263 pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath.get(), null);
264 AppLog("pkgmgr_parser_parse_manifest_for_uninstallation() - END");
265 CreateCoreXmlFile(pContext);
267 String serviceXmlPath = pXmlPath.get();
268 serviceXmlPath += L".tpk";
269 InstallerUtil::Copy(pXmlPath.get(), serviceXmlPath);
270 InstallerUtil::Remove(pXmlPath.get());
272 MergeToSystemXmlFile(pXmlPath.get(), webXmlPath, serviceXmlPath);
273 InstallerUtil::Remove(webXmlPath);
274 InstallerUtil::Remove(serviceXmlPath);
279 AppLog("pkgmgr_parser_parse_manifest_for_uninstallation() - START");
280 if (firstPreloadedUpdate == false)
282 AppLog(" - uninstall path=[%s]", pXmlPath.get());
283 pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath.get(), null);
287 std::unique_ptr<char[]> pRoXmlPath(_StringConverter::CopyToCharArrayN(roXmlPath));
288 AppLog(" - uninstall path=[%s]", pRoXmlPath.get());
289 pkgmgr_parser_parse_manifest_for_uninstallation(pRoXmlPath.get(), null);
292 AppLog("pkgmgr_parser_parse_manifest_for_uninstallation() - END");
295 CreateCoreXmlFile(pContext);
298 AppLog("------------------------------------------");
299 AppLog("sync() - START");
301 AppLog("sync() - END");
302 AppLog("------------------------------------------");
304 err = pkgmgr_parser_check_manifest_validation(pXmlPath.get());
305 TryReturn(err == 0, false, "pkgmgr_parser_check_manifest_validation() is failed. error = [%d][%s]", err, pXmlPath.get());
311 ConfigurationManager::RemoveFile(InstallationContext* pContext)
313 if (pContext->__isPreloaded == true)
315 pContext->__coreXmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, pContext->__packageId.GetPointer());
319 pContext->__coreXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, pContext->__packageId.GetPointer());
322 std::unique_ptr<char[]> pXmlPath(_StringConverter::CopyToCharArrayN(pContext->__coreXmlPath));
323 TryReturn(pXmlPath != null, false, "pXmlPath is null");
325 if (pContext->__isHybridService == true)
327 AppLog("Uninstallation for HybridService - skip");
332 AppLog("pkgmgr_parser_parse_manifest_for_uninstallation(%s) START", pXmlPath.get());
333 if (pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath.get(), null) != 0)
335 AppLog("pkgmgr_parser_parse_manifest_for_uninstallation() is failed.[%s]", pXmlPath.get());
337 AppLog("pkgmgr_parser_parse_manifest_for_uninstallation() END");
339 InstallerUtil::Remove(pXmlPath.get());
346 ConfigurationManager::PostInstall(InstallationContext* pContext, bool error) const
348 app2ext_handle* pHandle = (app2ext_handle*)pContext->__pApp2ExtHandle;
350 PackageId packageId = pContext->__packageId;
351 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
352 TryReturn(pPackageId, false, "pPackageId is null.");
356 RegisterCoreXmlFile(pContext);
358 SmackManager smackManager;
359 smackManager.Construct(pContext);
360 smackManager.EnablePermissions(packageId);
367 pHandle->interface.post_install(pPackageId.get(), APP2EXT_STATUS_FAILED);
368 AppLog("[app2sd] post_install(%s, APP2EXT_STATUS_FAILED)", pPackageId.get());
372 pHandle->interface.post_install(pPackageId.get(), APP2EXT_STATUS_SUCCESS);
373 AppLog("[app2sd] post_install(%s, APP2EXT_STATUS_SUCCESS)", pPackageId.get());
376 app2ext_deinit(pHandle);
383 ConfigurationManager::PostUninstall(InstallationContext* pContext) const
385 app2ext_handle* pHandle = (app2ext_handle*)pContext->__pApp2ExtHandle;
387 PackageId packageId = pContext->__packageId;
388 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
389 TryReturn(pPackageId, false, "pPackageId is null.");
393 pHandle->interface.post_uninstall(pPackageId.get());
394 AppLog("[app2sd] post_uninstall(%s)", pPackageId.get());
396 app2ext_deinit(pHandle);
399 SmackManager smackManager;
400 smackManager.Construct(pContext);
401 smackManager.RevokePermissions(packageId);
407 ConfigurationManager::CreateCoreXmlFile(InstallationContext* pContext) const
409 AppLog("------------------------------------------");
410 AppLog("CreateCoreXmlFile() - START");
413 ManifestGenerator manifestGenerator;
414 manifestGenerator.Construct(pContext);
415 ret = manifestGenerator.Write();
419 AppLog("manifestGenerator.Write() is failed.");
421 AppLog("CreateCoreXmlFile() - END");
422 AppLog("------------------------------------------");
428 ConfigurationManager::RegisterCoreXmlFile(InstallationContext* pContext) const
430 if (pContext->__isHybridService == true)
432 AppLog("HybridService is skipped.");
436 std::unique_ptr<char[]> pXmlPath(_StringConverter::CopyToCharArrayN(pContext->__coreXmlPath));
437 TryReturn(pXmlPath != null, false, "pXmlPath is null.");
441 if (pContext->__isCsc == true)
443 char* pUpdateTag[3] = {null, };
445 String preload("preload=true");
446 String removable("removable=");
447 if (pContext->__isUninstallable == false)
449 removable.Append("false");
453 removable.Append("true");
456 std::unique_ptr<char[]> pPreload(_StringConverter::CopyToCharArrayN(preload));
457 TryReturn(pPreload, false, "pPreload is null.");
459 std::unique_ptr<char[]> pRemovable(_StringConverter::CopyToCharArrayN(removable));
460 TryReturn(pRemovable, false, "pRemovable is null.");
462 pUpdateTag[0] = pPreload.get();
463 pUpdateTag[1] = pRemovable.get();
464 pUpdateTag[2] = null;
466 for (int i = 0; pUpdateTag[i] != null; i++)
468 AppLog("pUpdateTag[%d] = [%s]", i, pUpdateTag[i]);
471 AppLog("pkgmgr_parser_parse_manifest_for_installation(%s) - START", pXmlPath.get());
472 err = pkgmgr_parser_parse_manifest_for_installation(pXmlPath.get(), pUpdateTag);
473 TryReturn(err == 0, false, "pkgmgr_parser_parse_manifest_for_installation() is failed. error = [%d][%s]", err, pXmlPath.get());
475 AppLog("pkgmgr_parser_parse_manifest_for_installation() - END");
479 if (pContext->__isUpdated == true)
481 AppLog("pkgmgr_parser_parse_manifest_for_upgrade(%s) - START", pXmlPath.get());
482 err = pkgmgr_parser_parse_manifest_for_upgrade(pXmlPath.get(), null);
483 TryReturn(err == 0, false, "pkgmgr_parser_parse_manifest_for_upgrade() is failed. error = [%d][%s]", err, pXmlPath.get());
485 AppLog("pkgmgr_parser_parse_manifest_for_upgrade() - END");
489 AppLog("pkgmgr_parser_parse_manifest_for_installation(%s) - START", pXmlPath.get());
490 err = pkgmgr_parser_parse_manifest_for_installation(pXmlPath.get(), null);
491 TryReturn(err == 0, false, "pkgmgr_parser_parse_manifest_for_installation() is failed. error = [%d][%s]", err, pXmlPath.get());
493 AppLog("pkgmgr_parser_parse_manifest_for_installation() - END");
501 //ConfigurationManager::CreateHybridServiceDesktopFile(InstallationContext* pContext)
503 // AppLog("HybridServiceDesktopFile - START");
506 // _PackageInfoImpl *pPackageInfoImpl = pContext->GetPackageInfoImpl();
507 // _PackageAppInfoImpl* pAppInfoImpl = null;
508 // ArrayList* pAppList = null;
509 // pAppList = pPackageInfoImpl->GetAppInfoList();
511 // for (int i = 0 ; i < pAppList->GetCount(); i++)
513 // pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i));
518 // name.Format(1024, L"%ls", pPackageInfoImpl->GetAppName().GetPointer());
520 // String binaryPath;
521 // binaryPath.Format(1024, L"%ls%ls/%ls", pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_BIN, pAppInfoImpl->GetName().GetPointer());
524 // iconPath.Format(1024, L"%ls%ls/%ls", pPackageInfoImpl->GetAppRootPath().GetPointer(), DIR_ICONS, pAppInfoImpl->GetMainmenuIcon().GetPointer());
527 // version.Format(1024, L"%ls", pPackageInfoImpl->GetVersion().GetPointer());
530 // desktop.Format(1024, L"[Desktop Entry]\n"
532 // "Name[en_GB]=%ls\n"
533 // "Type=Application\n"
537 // "NoDisplay=true\n"
538 // "X-TIZEN-TaskManage=False\n"
539 // "X-TIZEN-PackageType=tpk\n",
540 // name.GetPointer(), name.GetPointer(), binaryPath.GetPointer(), iconPath.GetPointer(), version.GetPointer());
542 // String desktopPath;
543 // desktopPath.Format(1024, L"/opt/share/applications/%ls.desktop", pAppInfoImpl->GetPackageName().GetPointer());
545 // if (File::IsFileExist(desktopPath) == true)
547 // AppLog("removing desktop filePath=[%ls]", desktopPath.GetPointer());
548 // InstallerUtil::Remove(desktopPath);
551 // InstallerUtil::CreateInfoFile(desktopPath, &desktop);
555 // AppLog("HybridServiceDesktopFile - END");
561 ConfigurationManager::MergeToSystemXmlFile(const String& systemXmlPath, const String& webXmlPath, const String& serviceXmlPath)
563 result r = E_SUCCESS;
565 FileAttributes webXmlAttr;
566 r = File::GetAttributes(webXmlPath, webXmlAttr);
567 TryReturn(!IsFailed(r), false, "File::GetAttributes() failed, webXmlPath=%ls", webXmlPath.GetPointer());
569 FileAttributes serviceAttr;
570 r = File::GetAttributes(serviceXmlPath, serviceAttr);
571 TryReturn(!IsFailed(r), false, "File::GetAttributes() failed, serviceXmlPath=%ls", serviceXmlPath.GetPointer());
573 long long webXmlFileSize = webXmlAttr.GetFileSize();
574 long long serviceXmlFileSize = serviceAttr.GetFileSize();
575 long long mergedSize = webXmlFileSize + serviceXmlFileSize;
578 r = webXml.Construct(webXmlPath, L"r");
579 TryReturn(!IsFailed(r), false, "webXmlPath.Construct is failed");
581 std::unique_ptr<char[]> pMergedBuf(new (std::nothrow) char[mergedSize + 1]);
582 TryReturn(pMergedBuf, false, "pMergedBuf is null");
583 memset(pMergedBuf.get(), 0, mergedSize + 1);
585 int readBytes = webXml.Read(pMergedBuf.get(), webXmlFileSize);
586 TryReturn(readBytes >= 0, false, "webXml.Read is failed");
589 r = serviceXml.Construct(serviceXmlPath, L"r");
590 TryReturn(!IsFailed(r), false, "serviceXmlPath.Construct is failed");
592 std::unique_ptr<char[]> pServiceBuf(new (std::nothrow) char[serviceXmlFileSize + 1]);
593 TryReturn(pServiceBuf, false, "pServiceBuf is null");
594 memset(pServiceBuf.get(), 0, serviceXmlFileSize + 1);
596 readBytes = serviceXml.Read(pServiceBuf.get(), serviceXmlFileSize);
597 TryReturn(readBytes >= 0, false, "serviceXml.Read is failed");
599 char* pManifestTag = strcasestr(pMergedBuf.get(), "</manifest>");
600 TryReturn(pManifestTag, false, "pManifestTag is null");
602 char* pAppTagStart = strcasestr(pServiceBuf.get(), "<ui-application");
603 TryReturn(pAppTagStart, false, "pAppTagStart is null");
605 char* pAppTagEnd = strcasestr(pServiceBuf.get(), "</ui-application>");
606 TryReturn(pAppTagEnd, false, "pAppTagEnd is null");
608 int serviceAppLen = pAppTagEnd - pAppTagStart + strlen("</ui-application>");
610 memcpy(pManifestTag, pAppTagStart, serviceAppLen);
612 char* pManifestEndTag = pManifestTag + serviceAppLen;
613 strcpy(pManifestEndTag, "\n</manifest>");
615 int fileSize = pManifestEndTag - pMergedBuf.get() + strlen("\n</manifest>");
617 AppLog("[0] File Size = [%d]", fileSize);
619 if (strcasestr(pServiceBuf.get(), "</privileges>") != null)
621 AppLog("Privileges are detected in service app.");
622 MergePrivileges(pMergedBuf.get(), pServiceBuf.get(), fileSize);
626 AppLog("No privileges are detected in service app.");
628 AppLog("[1] File Size = [%d]", fileSize);
630 MergeAppWidgets(pMergedBuf.get(), pServiceBuf.get(), fileSize);
631 AppLog("[2] File Size = [%d]", fileSize);
633 MergeAccounts(pMergedBuf.get(), pServiceBuf.get(), fileSize);
634 AppLog("[3] File Size = [%d]", fileSize);
636 MergeNotifications(pMergedBuf.get(), pServiceBuf.get(), fileSize);
637 AppLog("[4] File Size = [%d]", fileSize);
639 MergeIme(pMergedBuf.get(), pServiceBuf.get(), fileSize);
640 AppLog("[5] File Size = [%d]", fileSize);
643 r = systemXml.Construct(systemXmlPath, L"w");
644 TryReturn(!IsFailed(r), false, "systemXmlPath.Construct() is failed.");
646 r = systemXml.Write(pMergedBuf.get(), fileSize);
647 TryReturn(!IsFailed(r), false, "systemXmlPath.Write() is failed.");
649 AppLog("pMergedBuf.get()=0x%0x, length=%d", (unsigned int)pMergedBuf.get(), fileSize);
650 InstallerUtil::DumpLogData(pMergedBuf.get(), fileSize);
656 ConfigurationManager::MergePrivileges(char* pMergedBuf, char* pServiceBuf, int& fileSize)
658 char* pMergedPrivilegeDetected = strcasestr(pMergedBuf, "</privileges>");
659 char* pMergedPoint = null;
660 char* pServicePrivilegeStart = null;
661 char* pServicePrivilegeEnd = null;
662 int privilegeLen = 0;
663 int serviceBufLen = strlen(pServiceBuf);
664 std::unique_ptr<char[]> pSelectedPrivBuf(new char[serviceBufLen + 1]);
665 memset(pSelectedPrivBuf.get(), 0, serviceBufLen + 1);
667 if (pMergedPrivilegeDetected == null)
669 AppLog("No privileges are detected in web app.");
671 pServicePrivilegeStart = strcasestr(pServiceBuf, "<privileges>");
672 pServicePrivilegeEnd = strcasestr(pServiceBuf, "</privileges>");
674 privilegeLen = pServicePrivilegeEnd - pServicePrivilegeStart + strlen("</privileges>");
675 pMergedPoint = strcasestr(pMergedBuf, "<ui-application");
677 AppLog("Inserted privileges of service app");
678 InstallerUtil::DumpLogData(pServicePrivilegeStart, privilegeLen);
682 AppLog("Privileges are detected in web app.");
684 pServicePrivilegeStart = strcasestr(pServiceBuf, "<privilege>");
685 pServicePrivilegeEnd = strcasestr(pServiceBuf, "</privileges>");
687 privilegeLen = pServicePrivilegeEnd - pServicePrivilegeStart;
688 pMergedPoint = strcasestr(pMergedBuf, "</privileges>");
690 AppLog("Original privileges of service app");
691 InstallerUtil::DumpLogData(pServicePrivilegeStart, privilegeLen);
693 std::unique_ptr<char[]> pPrivBuf(new char[privilegeLen + 1]);
694 memset(pPrivBuf.get(), 0, privilegeLen + 1);
695 strncpy(pPrivBuf.get(), pServicePrivilegeStart, privilegeLen);
697 char* pEachPrivStart = pPrivBuf.get();
698 char* pEachPrivEnd = null;
700 char eachPrivBuf[512] = {0};
702 while (pEachPrivStart && (pEachPrivStart < pPrivBuf.get() + privilegeLen))
704 pEachPrivEnd = strcasestr(pEachPrivStart, "</privilege>");
705 eachPrivLen = pEachPrivEnd - pEachPrivStart + strlen("</privilege>");
706 if ((pEachPrivEnd > 0) && (eachPrivLen > 0))
708 memset(eachPrivBuf, 0, sizeof(eachPrivBuf));
709 memcpy(eachPrivBuf, pEachPrivStart, eachPrivLen);
710 AppLog("[%s]", eachPrivBuf);
712 if (strcasestr(pMergedBuf, eachPrivBuf) == 0)
714 strncat(pSelectedPrivBuf.get(), eachPrivBuf, serviceBufLen);
718 AppLog("This privilege is discarded, [%s]", eachPrivBuf);
723 AppLog("End of privileges merging.");
727 pEachPrivStart = strcasestr(pEachPrivEnd, "<privilege>");
730 pServicePrivilegeStart = pSelectedPrivBuf.get();
731 privilegeLen = strlen(pServicePrivilegeStart);
733 AppLog("Filtered privileges of service app");
734 InstallerUtil::DumpLogData(pServicePrivilegeStart, privilegeLen);
737 if ((pMergedPoint > 0) && (pServicePrivilegeStart > 0) && (privilegeLen > 0))
739 int lastPartLen = fileSize - (pMergedPoint - pMergedBuf);
740 std::unique_ptr<char[]> pLastPartBuf(new (std::nothrow) char[fileSize + 1]);
741 memset(pLastPartBuf.get(), 0, fileSize + 1);
745 memcpy(pLastPartBuf.get(), pMergedPoint, lastPartLen);
747 AppLog("Last part of merged xml for backup");
748 InstallerUtil::DumpLogData(pLastPartBuf.get(), lastPartLen);
750 memcpy(pMergedPoint, pServicePrivilegeStart, privilegeLen);
752 memcpy(pMergedPoint + privilegeLen, pLastPartBuf.get(), lastPartLen);
753 fileSize += privilegeLen;
761 ConfigurationManager::MergeAppWidgets(char* pMergedBuf, char* pServiceBuf, int& fileSize)
763 TryReturn(pMergedBuf, false, "pMergedBuf is null.");
764 TryReturn(pServiceBuf, false, "pServiceBuf is null.");
765 TryReturn(fileSize > 0, false, "fileSize is invalid.");
767 if (strcasestr(pServiceBuf, "</livebox>") == null)
769 AppLog("<livebox> is NOT detected in service app.");
773 AppLog("<livebox> is detected in service app.");
774 MergeTags(pMergedBuf, pServiceBuf, fileSize, "<livebox", "</livebox>");
780 ConfigurationManager::MergeAccounts(char* pMergedBuf, char* pServiceBuf, int& fileSize)
782 TryReturn(pMergedBuf, false, "pMergedBuf is null.");
783 TryReturn(pServiceBuf, false, "pServiceBuf is null.");
784 TryReturn(fileSize > 0, false, "fileSize is invalid.");
786 if (strcasestr(pServiceBuf, "</account>") == null)
788 AppLog("<account> is NOT detected in service app.");
792 AppLog("<account> is detected in service app.");
793 MergeTags(pMergedBuf, pServiceBuf, fileSize, "<account", "</account>");
799 ConfigurationManager::MergeNotifications(char* pMergedBuf, char* pServiceBuf, int& fileSize)
801 TryReturn(pMergedBuf, false, "pMergedBuf is null.");
802 TryReturn(pServiceBuf, false, "pServiceBuf is null.");
803 TryReturn(fileSize > 0, false, "fileSize is invalid.");
805 if (strcasestr(pServiceBuf, "</notifications>") == null)
807 AppLog("<notifications> is NOT detected in service app.");
811 AppLog("<notifications> is detected in service app.");
812 MergeTags(pMergedBuf, pServiceBuf, fileSize, "<notifications", "</notifications>");
818 ConfigurationManager::MergeIme(char* pMergedBuf, char* pServiceBuf, int& fileSize)
820 TryReturn(pMergedBuf, false, "pMergedBuf is null.");
821 TryReturn(pServiceBuf, false, "pServiceBuf is null.");
822 TryReturn(fileSize > 0, false, "fileSize is invalid.");
824 if (strcasestr(pServiceBuf, "</ime>") == null)
826 AppLog("<ime> is NOT detected in service app.");
830 AppLog("<ime> is detected in service app.");
831 MergeTags(pMergedBuf, pServiceBuf, fileSize, "<ime", "</ime>");
837 ConfigurationManager::MergeTags(char* pMergedBuf, char* pServiceBuf, int& fileSize, const char* pStartTag, const char* pEndTag)
845 AppLog("pServiceBuf = [0x%08x]", pServiceBuf);
846 GetPart(pServiceBuf, pStartTag, pEndTag, &pBuf, &length, &pNext);
849 MergeTo(pMergedBuf, fileSize, "</manifest>", pBuf, length);
856 while (pServiceBuf > 0);
862 ConfigurationManager::GetPart(const char* pStartPoint, const char* pStartTag, const char* pEndTag, char** ppBuf, int* pLength, char** ppNext)
864 TryReturn(pStartPoint, false, "pStartPoint is null.");
865 TryReturn(pStartTag, false, "pStartTag is null.");
866 TryReturn(pEndTag, false, "pEndTag is null.");
867 TryReturn(ppBuf, false, "ppBuf is null.");
868 TryReturn(pLength, false, "pLength is null.");
869 TryReturn(ppNext, false, "ppNext is null.");
871 const char* pStartBufPoint = strcasestr(pStartPoint, pStartTag);
872 TryReturn(pStartBufPoint, false, "pStartBufPoint is null.");
874 const char* pEndBufPoint = strcasestr(pStartBufPoint, pEndTag);
875 TryReturn(pEndBufPoint, false, "pEndBufPoint is null.");
877 int len = pEndBufPoint - pStartBufPoint + strlen(pEndTag);
878 TryReturn(len > 0, false, "len is invalid.");
881 pBuf = new char[len + 1];
882 TryReturn(pBuf, false, "pBuf is null.");
883 memset(pBuf, 0, len + 1);
884 memcpy(pBuf, pStartBufPoint, len);
886 AppLog("Extracted Part, len = [%d]", len);
887 InstallerUtil::DumpLogData(pBuf, len);
891 *ppNext = (char *)pEndBufPoint;
897 ConfigurationManager::MergeTo(const char* pMergedBuf, int& fileSize, const char* pTag, const char* pBuf, int length)
899 TryReturn(pMergedBuf, false, "pMergedBuf is null.");
900 TryReturn(fileSize > 0, false, "fileSize is invalid.");
901 TryReturn(pTag, false, "pTag is null.");
902 TryReturn(pBuf, false, "pBuf is null.");
903 TryReturn(length > 0, false, "length is invalid.");
905 char* pMergedPoint = null;
906 pMergedPoint = (char *)strcasestr(pMergedBuf, pTag);
907 TryReturn(pMergedPoint > 0, true, "pTag is not found, pTag=[%s]", pTag);
909 int lastPartLen = fileSize - (pMergedPoint - pMergedBuf);
910 std::unique_ptr<char[]> pLastPartBuf(new (std::nothrow) char[fileSize + 1]);
911 memset(pLastPartBuf.get(), 0, fileSize + 1);
915 memcpy(pLastPartBuf.get(), pMergedPoint, lastPartLen);
917 AppLog("Last part of merged xml for backup");
918 InstallerUtil::DumpLogData(pLastPartBuf.get(), lastPartLen);
920 memcpy(pMergedPoint, pBuf, length);
921 memcpy(pMergedPoint + length, pLastPartBuf.get(), lastPartLen);
929 ConfigurationManager::CreateImeSymlink(const String& binaryPath, const String& appId)
933 const char* pExePath = null;
934 const char* pSymlinkPath = null;
936 Directory::Create(IME_PATH, true);
939 exePath.Format(1024, L"%ls.exe", binaryPath.GetPointer());
942 symlinkPath.Format(1024, L"%s/%ls.so", IME_PATH, appId.GetPointer());
944 pExePath = _StringConverter::CopyToCharArrayN(exePath);
945 TryCatch(pExePath, res = false, "pExePath is null");
947 pSymlinkPath = _StringConverter::CopyToCharArrayN(symlinkPath);
948 TryCatch(pSymlinkPath, res = false, "pSymlinkPath is null");
950 err = symlink(pExePath, pSymlinkPath);
952 AppLog("[%s] -> [%s]", pSymlinkPath, pExePath);
956 delete[] pSymlinkPath;
962 ConfigurationManager::FindPrivilege(InstallationContext* pContext, const String& privilege) const
964 TryReturn(pContext, false, "pContext is null.");
967 const ArrayList* pPrivilegeList = pContext->GetPrivilegeList();
971 if (pPrivilegeList->Contains(privilege) == true)
973 AppLog("Privilege = [%ls]", privilege.GetPointer());