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 InstallerUtil.cpp
19 * @brief This is the implementation file for %InstallerUtil class.
27 #include <unique_ptr.h>
29 #include <FBaseErrorDefine.h>
31 #include <FIoDirectory.h>
32 #include <FAppPkgPackageAppInfo.h>
33 #include <FAppPkgPackageInfo.h>
34 #include <FBase_StringConverter.h>
35 #include <FSecCryptoSha2Hash.h>
37 #include <FAppPkg_PackageManagerImpl.h>
38 #include <FAppPkg_PackageInfoImpl.h>
39 #include <FAppPkg_PackageAppInfoImpl.h>
41 #include "InstallerDefs.h"
42 #include "InstallerUtil.h"
43 #include "InstallerManager.h"
44 #include "SmackManager.h"
46 using namespace Tizen::Base;
47 using namespace Tizen::Base::Collection;
48 using namespace Tizen::Base::Utility;
49 using namespace Tizen::App;
50 using namespace Tizen::App::Package;
51 using namespace Tizen::Io;
52 using namespace Tizen::Security::Crypto;
54 InstallerUtil::InstallerUtil(void)
58 InstallerUtil::~InstallerUtil(void)
63 InstallerUtil::Remove(const Tizen::Base::String& filePath)
69 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
70 TryReturn(pFilePath, false, "pFilePath is null");
72 err = lstat(pFilePath.get(), &fileinfo);
75 AppLog("Remove(): [%s] - %s[errno(%d)]: skip", pFilePath.get(), strerror(errno), errno);
79 if (S_ISLNK(fileinfo.st_mode))
81 AppLog("Remove(): symlink=[%s]", pFilePath.get());
82 err = unlink(pFilePath.get());
83 TryReturn(err >= 0, false, "unlink() failed(%s), file=[%s]", strerror(errno), pFilePath.get());
85 else if (S_ISDIR(fileinfo.st_mode))
87 AppLog("Remove(): directory=[%ls]", filePath.GetPointer());
88 r = Directory::Remove(filePath, true);
89 TryReturn(!IsFailed(r), false, "Directory::Remove() failed, filePath=%ls", filePath.GetPointer());
93 AppLog("Remove(): file=[%ls]", filePath.GetPointer());
94 r = File::Remove(filePath);
95 TryReturn(!IsFailed(r), false, "File::Remove() failed, filePath=%ls", filePath.GetPointer());
102 InstallerUtil::Copy(const String& srcFilePath, const String& destFilePath)
106 result r = E_SUCCESS;
108 // AppLog("+ Copy(): src=[%ls], dest=[%ls]", srcFilePath.GetPointer(), destFilePath.GetPointer());
113 std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]);
114 TryReturn(pBuf, false, "pBuf is null");
116 r = srcFile.Construct(srcFilePath, L"r");
117 TryReturn(!IsFailed(r), false, "srcFile.Construct is failed");
119 r = destFile.Construct(destFilePath, L"w");
120 TryReturn(!IsFailed(r), false, "destFile.Construct is failed");
124 readBytes = srcFile.Read(pBuf.get(), bufSize);
127 r = destFile.Write(pBuf.get(), readBytes);
128 TryReturn(!IsFailed(r), false, "destFile.Write is failed");
131 while (readBytes > 0);
137 InstallerUtil::CopyDirectory(const String& srcFilePath, const String& destFilePath)
139 result r = E_SUCCESS;
142 res = File::IsFileExist(srcFilePath);
145 AppLog("CopyDirectory(): src=[%ls]: skip", srcFilePath.GetPointer());
149 std::unique_ptr<Directory> pDir(new (std::nothrow) Directory);
150 TryReturn(pDir, false, "pDir is null.");
152 r = pDir->Construct(srcFilePath);
153 TryReturn(!IsFailed(r), false, "pDir->Construct() failed, srcFilePath=[%ls].", srcFilePath.GetPointer());
155 std::unique_ptr<DirEnumerator> pDirEnum(pDir->ReadN());
156 TryReturn(pDirEnum, false, "pDirEnum is null.");
158 while (pDirEnum->MoveNext() == E_SUCCESS)
160 DirEntry entry = pDirEnum->GetCurrentDirEntry();
162 String entryName = entry.GetName();
163 String srcEntryDir = srcFilePath;
165 srcEntryDir += entryName;
167 if (entryName == L"." || entryName == L"..")
172 // if file or directory is symbolic link, skip this.
173 if (InstallerUtil::IsSymlink(srcEntryDir) == true)
178 String destEntryDir = destFilePath;
179 destEntryDir += L"/";
180 destEntryDir += entryName;
182 if (entry.IsDirectory() == false)
185 Directory::Create(destFilePath, true);
186 InstallerUtil::Copy(srcEntryDir, destEntryDir);
190 Directory::Create(destEntryDir, true);
191 CopyDirectory(srcEntryDir, destEntryDir);
195 AppLog("CopyDirectory(): src=[%ls], dest=[%ls]", srcFilePath.GetPointer(), destFilePath.GetPointer());
200 InstallerUtil::IsSymlink(const Tizen::Base::String& filePath)
203 struct stat fileinfo;
205 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
206 TryReturn(pFilePath, false, "pFilePath is null");
208 err = lstat(pFilePath.get(), &fileinfo);
209 TryReturn(err >= 0, false, "lstat() failed(%s), file=[%s]", strerror(errno), pFilePath.get());
211 if (S_ISLNK(fileinfo.st_mode))
220 InstallerUtil::GetRealPath(const String& filePath, String& realPath)
222 char* pRealPath = null;
224 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
225 TryReturn(pFilePath, false, "pFilePath is null");
227 char tmpPath[PATH_MAX] = {0};
228 pRealPath = realpath(pFilePath.get(), tmpPath);
229 TryReturn(pRealPath, false, "pRealPath is null");
233 AppLog("GetRealPath(): path=[%ls], realPath=[%ls]", filePath.GetPointer(), realPath.GetPointer());
239 InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath)
244 res = File::IsFileExist(oldPath);
247 AppLog("CreateSymlink(): oldPath=[%ls] not found", oldPath.GetPointer());
251 std::unique_ptr<char[]> pOldPath(_StringConverter::CopyToCharArrayN(oldPath));
252 TryReturn(pOldPath, false, "pOldPath is null");
254 std::unique_ptr<char[]> pNewPath(_StringConverter::CopyToCharArrayN(newPath));
255 TryReturn(pNewPath, false, "pNewPath is null");
257 err = symlink(pOldPath.get(), pNewPath.get());
258 TryReturn(err == 0, false, "symlink() is failed(%s), oldpath=[%s], newpath=[%s]", strerror(errno), pOldPath.get(), pNewPath.get());
260 SmackManager smackManager;
262 smackManager.AddLabelDir(label, newPath);
264 AppLog("CreateSymlink(): [%ls] -> [%ls]", newPath.GetPointer(), oldPath.GetPointer());
270 InstallerUtil::ChangeMode(const String& filePath, int mode)
274 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
275 TryReturn(pFilePath, false, "pFilePath is null");
277 err = chmod(pFilePath.get(), mode);
278 TryReturn(err == 0, false, "chmod() is failed(%s), file=[%s], mode=[%o]", strerror(errno), pFilePath.get(), mode);
284 InstallerUtil::ChangeOwner(const String& filePath)
288 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
289 TryReturn(pFilePath, false, "pFilePath is null");
291 err = chown(pFilePath.get(), APP_OWNER_ID, APP_GROUP_ID);
292 TryReturn(err == 0, false, "chown() is failed(%s), file=[%s]", strerror(errno), pFilePath.get());
298 InstallerUtil::ChangeDirectoryPermission(const String& file, int mode, bool appOwner)
300 result r = E_SUCCESS;
303 res = File::IsFileExist(file);
306 AppLog("path=[%ls]: skip", file.GetPointer());
310 std::unique_ptr<Directory> pDir(new (std::nothrow) Directory);
311 TryReturn(pDir, false, "pDir is null.");
313 r = pDir->Construct(file);
314 TryReturn(!IsFailed(r), false, "pDir->Construct() failed, file=[%ls]", file.GetPointer());
316 std::unique_ptr<DirEnumerator> pDirEnum(pDir->ReadN());
317 TryReturn(pDirEnum, false, "pDirEnum is null.");
319 while (pDirEnum->MoveNext() == E_SUCCESS)
321 DirEntry entry = pDirEnum->GetCurrentDirEntry();
322 String entryName = entry.GetName();
323 if (entryName.IsEmpty() == true)
325 AppLog("entryName is empty.", entryName.GetPointer());
329 String entryDir = file;
331 entryDir += entryName;
333 if (entryName == L".")
335 if (appOwner == true)
337 InstallerUtil::ChangeOwner(entryDir);
339 InstallerUtil::ChangeMode(entryDir, mode | PERM_EXECUTE);
342 else if (entryName == L"..")
347 if (entry.IsDirectory() == false)
349 if (appOwner == true)
351 InstallerUtil::ChangeOwner(entryDir);
353 InstallerUtil::ChangeMode(entryDir, mode);
357 ChangeDirectoryPermission(entryDir, mode, appOwner);
358 if (appOwner == true)
360 InstallerUtil::ChangeOwner(entryDir);
362 InstallerUtil::ChangeMode(entryDir, mode | PERM_EXECUTE);
366 AppLog("path=[%ls], mode=[%04o], appOwner=[%s]",
367 file.GetPointer(), mode, appOwner?"true":"false");
373 InstallerUtil::IsDrmFile(const String& path)
376 void* pHandle = null;
377 char* pErrorMsg = null;
378 int (*drm_oem_sapps_is_drm_file)(const char* pDcfPath, int dcfPathLen);
380 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(path));
381 TryReturn(pFilePath, false, "pFilePath is null.");
383 pHandle = dlopen("/usr/lib/libdrm-service-core-sapps.so.0", RTLD_LAZY | RTLD_GLOBAL);
386 AppLog("dlopen() failed. [%ls][%s]", path.GetPointer(), dlerror());
390 drm_oem_sapps_is_drm_file = reinterpret_cast <int (*)(const char*, int)>(dlsym(pHandle, "drm_oem_sapps_is_drm_file"));
391 pErrorMsg = dlerror();
392 if ((pErrorMsg != null) || (drm_oem_sapps_is_drm_file == null))
394 AppLog("dlsym() failed. [%ls][%s]", path.GetPointer(), pErrorMsg);
399 AppLog("[drm] drm_oem_sapps_is_drm_file(%s, %d)", pFilePath.get(), strlen(pFilePath.get()));
400 ret = drm_oem_sapps_is_drm_file(pFilePath.get(), strlen(pFilePath.get()));
401 AppLog("[drm] drm_oem_sapps_is_drm_file(), result = [%d]", ret);
407 AppLog("file[%ls] is DRM file.", path.GetPointer());
417 InstallerUtil::DecryptPackage(const String& path, const String& decryptedPath)
420 void* pHandle = null;
421 char* pErrorMsg = null;
422 int (*drm_oem_sapps_decrypt_package)(const char* pDcfPath, int dcfPathLen, const char* pDecryptedFile, int decryptedFileLen);
424 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(path));
425 TryReturn(pFilePath, false, "pFilePath is null.");
427 std::unique_ptr<char[]> pDecryptedPath(_StringConverter::CopyToCharArrayN(decryptedPath));
428 TryReturn(pDecryptedPath, false, "pDecryptedPath is null.");
430 pHandle = dlopen("/usr/lib/libdrm-service-core-sapps.so.0", RTLD_LAZY | RTLD_GLOBAL);
433 AppLog("dlopen() failed. [%ls][%s]", path.GetPointer(), dlerror());
437 drm_oem_sapps_decrypt_package = reinterpret_cast <int (*)(const char*, int, const char*, int)>(dlsym(pHandle, "drm_oem_sapps_decrypt_package"));
438 pErrorMsg = dlerror();
439 if ((pErrorMsg != null) || (drm_oem_sapps_decrypt_package == null))
441 AppLog("dlsym() failed. [%ls][%s]", path.GetPointer(), pErrorMsg);
446 AppLog("[drm] drm_oem_sapps_decrypt_package(%s, %d, %s, %d)", pFilePath.get(), strlen(pFilePath.get()), pDecryptedPath.get(), strlen(pDecryptedPath.get()));
447 ret = drm_oem_sapps_decrypt_package(pFilePath.get(), strlen(pFilePath.get()), pDecryptedPath.get(), strlen(pDecryptedPath.get()));
448 AppLog("[drm] drm_oem_sapps_decrypt_package(), result = [%d]", ret);
454 AppLog("[%ls] -> [%ls] is decrypted.", path.GetPointer(), decryptedPath.GetPointer());
464 InstallerUtil::GetCategory(int categoryType)
468 if (categoryType == CATEGORY_TYPE_IME)
472 else if (categoryType == CATEGORY_TYPE_HOME_SCREEN)
474 category = L"home-screen";
476 else if (categoryType == CATEGORY_TYPE_LOCK_SCREEN)
478 category = L"lock-screen";
485 InstallerUtil::GetCategoryType(char* pCategory)
487 CategoryType category = CATEGORY_TYPE_NONE;
489 if (strcasecmp(pCategory, "Ime") == 0)
491 category = CATEGORY_TYPE_IME;
493 else if (strcasecmp(pCategory, "home-screen") == 0)
495 category = CATEGORY_TYPE_HOME_SCREEN;
497 else if (strcasecmp(pCategory, "lock-screen") == 0)
499 category = CATEGORY_TYPE_LOCK_SCREEN;
506 InstallerUtil::CreateSymlinkForAppDirectory(const String& inPath, String& outPath)
510 int length = inPath.GetLength();
511 inPath.SubString(length - PACKAGE_ID_LENGTH, PACKAGE_ID_LENGTH, appId);
514 newPath = PATH_OPT_APPS;
518 if (inPath != newPath)
520 InstallerUtil::CreateSymlink(inPath, newPath);
524 AppLog("CreateSymlinkForAppDirectory(): output path=[%ls]", outPath.GetPointer());
530 InstallerUtil::CreateInfoFile(const String& filePath, const String* pContext)
532 result r = E_SUCCESS;
535 r = file.Construct(filePath, "w");
536 TryReturn(!IsFailed(r), false, "file.Construct() failed, filePath=[%ls]", filePath.GetPointer());
538 AppLog("------------------------------------------");
539 AppLog("CreateInfoFile(), filePath = [%ls]", filePath.GetPointer());
543 r = file.Write(*pContext);
544 TryReturn(!IsFailed(r), false, "file.Write() failed, filePath=[%ls]", filePath.GetPointer());
545 AppLog("string = [%ls]", pContext->GetPointer());
547 AppLog("------------------------------------------");
553 InstallerUtil::DumpLog(const char* pBuf)
555 TryReturn(pBuf, false, "pBuf is null");
557 char temp[4096] = {0};
558 int bufLen = strlen(pBuf);
559 strncpy(temp, pBuf, sizeof(temp)-1);
561 char* pStart = &temp[0];
563 for (int i = 0; i < bufLen; i++)
568 AppLog("%s", pStart);
569 pStart = temp + i + 1;
576 #define LOG_PRINT_LINE_MAX 20
577 #define LOG_BUFFER_COUNT_MAX 4096
579 InstallerUtil::DumpLogData(char *pData, int dataLen)
581 const char *szData = (const char*)pData;
583 int i = 0, j = 0, idx = 0, idx2 = 0, high = 0, low = 0, temp = 0;
585 char buf[LOG_PRINT_LINE_MAX + 2] = {0};
586 char buf2[(LOG_PRINT_LINE_MAX + 2) * 3] = {0};
587 char buf_out[sizeof(buf) + sizeof(buf2) + 1] = {0};
590 if (dataLen > LOG_BUFFER_COUNT_MAX)
592 dataLen = LOG_BUFFER_COUNT_MAX;
595 // 16 characters by 20 line are proper. // too many logs decrease performance.
596 // if (dataLen > 16*20)
599 AppLog("------------------------------------------");
601 while (i < (int)dataLen)
605 /* make ascii table */
606 if (ch >= 32 && ch <= 128)
614 high = (ch & 0xf0)>>4;
617 buf2[idx2++] = LogChangeHexToStr(high);
618 buf2[idx2++] = LogChangeHexToStr(low);
621 if (idx >= LOG_PRINT_LINE_MAX)
623 memcpy(buf_out, buf2, idx2);
625 buf_out[idx2++] = ' ';
626 buf_out[idx2++] = ' ';
628 memcpy(buf_out + idx2, buf, idx);
629 buf_out[idx2+idx] = '\0';
634 AppLog("%s\n", buf_out);
643 memcpy(buf_out, buf2, idx2);
646 for (j = 0; j < (LOG_PRINT_LINE_MAX * 3) - temp; j++)
648 buf_out[idx2++] = ' ';
651 buf_out[idx2++] = ' ';
652 buf_out[idx2++] = ' ';
654 memcpy(buf_out+idx2, buf, idx);
655 buf_out[idx2+idx] = '\0';
657 AppLog("%s\n", buf_out);
660 AppLog("------------------------------------------");
666 InstallerUtil::LogChangeHexToStr(int hex)
670 const static char hexValues[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 0};
673 if (hex >= 0 && hex <= 0x0F)
679 AppLog("LogChangeHexToStr: Error! [Hex Val: %d]\n", hex);
686 InstallerUtil::CreateLog(const String& logFile)
690 result r = file.Construct(logFile, "w");
700 InstallerUtil::AppendLog(const char* pFunction, int lineNumber, bool fatal, const char* pFormat, ...)
704 InstallerManager *pManager = InstallerManager::GetInstance();
705 if (pManager == null)
710 if (pManager->IsFileLogOn() == false)
715 String logFile = pManager->GetLogFilePath();
716 result r = file.Construct(logFile, "a");
723 va_start(args, pFormat);
724 const int bufSize = 1024;
725 char logs[bufSize+1] = {0};
726 char logs2[bufSize+1] = {0};
729 snprintf(logs, bufSize, " | %s (%d). > %s", (char*)pFunction, lineNumber, pFormat);
733 snprintf(logs, bufSize, "[TRY]| %s (%d). > %s", (char*)pFunction, lineNumber, pFormat);
736 vsnprintf(logs2, bufSize, logs, args);
737 int length = strlen(logs2);
738 logs2[length] = '\n';
740 r = file.Write(logs2, length+1);
747 if (pManager->IsHistoryFileLogOn() == true)
750 String historyLogFilePath = pManager->GetHistoryLogFilePath();
751 r = historyLogFile.Construct(historyLogFilePath, "a");
754 r = historyLogFile.Write(logs2, length+1);
768 InstallerUtil::PrintLog(const String& logFile)
770 InstallerManager *pManager = InstallerManager::GetInstance();
771 if (pManager == null)
776 if (pManager->IsFileLogOn() == false)
782 FileAttributes attribute;
784 result r = File::GetAttributes(logFile, attribute);
791 std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]);
797 r = file.Construct(logFile, "r");
806 memset(pBuf.get(), 0, bufSize);
807 readBytes = file.Read(pBuf.get(), bufSize);
810 fprintf(stderr, "%s", pBuf.get());
813 while (readBytes > 0);
819 InstallerUtil::GetRdsList(const PackageId& packageId, IList* pDeletedList, IList* pAddedList, IList* pModifiedList)
823 char rdsFilePath[1024] = {0};
824 char buffer[1024] = {0};
825 InstallerRdsState state = INSTALLER_RDS_STATE_NONE;
827 snprintf(rdsFilePath, sizeof(rdsFilePath), "%s/%ls/%s", DIR_APPLICATIONS_TMP, packageId.GetPointer(), INSTALLER_RDS_FILE_NAME);
829 fp = fopen(rdsFilePath, "r");
830 TryReturn(fp, false, "fp is null.");
831 AppLog(".rds_delta file");
834 while (fgets(buffer, sizeof(buffer), fp) != null)
836 bool isMetadata = false;
838 if (buffer[0] == '#')
840 if (strcasestr(buffer, INSTALLER_RDS_DELETE_STR))
842 state = INSTALLER_RDS_STATE_DELETE;
844 else if (strcasestr(buffer, INSTALLER_RDS_ADD_STR))
846 state = INSTALLER_RDS_STATE_ADD;
848 else if (strcasestr(buffer, INSTALLER_RDS_MODIFY_STR))
850 state = INSTALLER_RDS_STATE_MODIFY;
856 if (state == INSTALLER_RDS_STATE_NONE)
858 AppLog("Unknown RDS State, INSTALLER_RDS_STATE_NONE");
862 std::unique_ptr<String> pStr(new (std::nothrow) String(buffer));
863 TryCatch(pStr, res = false, "pStr is null.");
864 TryCatch(pStr->IsEmpty() == false, res = false, "pStr is empty.");
867 AppLog(".rds_delta: line(%03d)=[%ls]", line, pStr->GetPointer());
870 if (isMetadata == true)
873 if (state == INSTALLER_RDS_STATE_DELETE)
875 pDeletedList->Add(pStr.release());
877 else if (state == INSTALLER_RDS_STATE_ADD)
879 pAddedList->Add(pStr.release());
881 else if (state == INSTALLER_RDS_STATE_MODIFY)
883 pModifiedList->Add(pStr.release());
886 memset(buffer, 0, sizeof(buffer));
895 InstallerUtil::GetInstallerOperationString(int operation)
897 if (operation == INSTALLER_OPERATION_INSTALL)
901 else if (operation == INSTALLER_OPERATION_UNINSTALL)
905 else if (operation == INSTALLER_OPERATION_REINSTALL)
914 InstallerUtil::GetFileDigest(const String& filePath, String& digestValue)
916 const int bufSize = 64*1024;
918 result r = E_SUCCESS;
921 std::unique_ptr<Sha2Hash> pHash(new (std::nothrow) Sha2Hash());
923 r = pHash->SetAlgorithm("SHA2/256");
924 TryReturn(!IsFailed(r), false, "pHash->SetAlgorithm() is failed.");
926 r = pHash->Initialize();
927 TryReturn(!IsFailed(r), false, "pHash->Initialize() is failed.");
929 std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]);
930 TryReturn(pBuf, false, "pBuf is null");
932 r = file.Construct(filePath, L"r");
933 TryReturn(!IsFailed(r), false, "file.Construct() is failed.");
937 readBytes = file.Read(pBuf.get(), bufSize);
938 AppLog("readBytes for Hash=[%d]", readBytes);
943 r = buffer.Construct((const byte*)pBuf.get(), 0, readBytes, bufSize);
944 TryReturn(!IsFailed(r), false, "buffer.Construct() is failed.");
946 r = pHash->Update(buffer);
947 TryReturn(!IsFailed(r), false, "pHash->Update() is failed.");
950 while (readBytes > 0);
952 std::unique_ptr<ByteBuffer> pResultBuf(pHash->FinalizeN());
953 TryReturn(pResultBuf, false, "pResultBuf is null.");
955 r = StringUtil::EncodeToBase64String(*pResultBuf, digestValue);
956 TryReturn(!IsFailed(r), false, "EncodeToBase64String() is failed.");
962 InstallerUtil::ParseN(const String& str, const String& tokenDelimiter)
964 TryReturn(str.IsEmpty() == false, null, "str is empty.");
965 TryReturn(tokenDelimiter.IsEmpty() == false, null, "tokenDelimiter is empty.");
967 std::unique_ptr< HashMap > pMap(new (std::nothrow) HashMap);
968 TryReturn(pMap, null, "pMap is null.");
970 result r = pMap->Construct();
971 TryReturn(!IsFailed(r), null, "pMap->Construct() is failed.");
973 StringTokenizer strTok(str, tokenDelimiter);
974 while(strTok.HasMoreTokens() == true)
977 r = strTok.GetNextToken(token);
978 TryReturn(!IsFailed(r), null, "strTok.GetNextToken() is failed.");
980 AppLog("token = [%ls]", token.GetPointer());
982 StringTokenizer infoTok(token, L"=");
984 if (infoTok.GetTokenCount() != 2)
986 AppLog("'=' is not existed.");
990 std::unique_ptr< String > pKey(new (std::nothrow) String);
991 r = infoTok.GetNextToken(*pKey);
992 TryReturn(!IsFailed(r), null, "infoTok.GetNextToken(*pKey) is failed.");
993 AppLog(" - key = [%ls]", pKey->GetPointer());
995 std::unique_ptr< String > pValue(new (std::nothrow) String);
996 r = infoTok.GetNextToken(*pValue);
997 TryReturn(!IsFailed(r), null, "infoTok.GetNextToken(*pValue) is failed.");
998 AppLog(" - value = [%ls]", pValue->GetPointer());
1000 r = pMap->Add(pKey.release(), pValue.release());
1001 TryReturn(!IsFailed(r), null, "pMap->Add() is failed.");
1004 if (pMap->GetCount() <= 0)
1006 AppLog("pMap->GetCount() is invalid.");
1010 return pMap.release();
1014 InstallerUtil::TerminateApp(const AppId& appId)
1018 if (_Aul::IsRunning(appId) == true)
1020 AppLog("App(%ls) is running.", appId.GetPointer());
1022 result r = _Aul::TerminateApplication(appId);
1023 TryReturn(r == E_SUCCESS, false, "TerminateApplication() failed. [%ls]", appId.GetPointer());
1025 for (int j = 0; j < TERMINATE_RETRY_COUNT; j++)
1027 res = _Aul::IsRunning(appId);
1030 AppLog("App(%ls) is terminated.", appId.GetPointer());
1035 AppLog("App(%ls) is not terminated yet. wait count = [%d]", appId.GetPointer(), j);
1042 AppLog("App(%ls) can't be terminated.", appId.GetPointer());
1048 AppLog("App(%ls) is not running.", appId.GetPointer());
1055 InstallerUtil::TerminateApps(const PackageId& packageId)
1057 std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId));
1059 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1060 TryReturn(pPackageInfoImpl, false, "GetInstance() failed.");
1062 std::unique_ptr< IList > pPackageAppList(pPackageInfoImpl->GetPackageAppInfoListN());
1063 TryReturn(pPackageAppList, false, "GetPackageAppInfoListN() failed.");
1065 for (int i = 0; i < pPackageAppList->GetCount(); i++)
1067 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppList->GetAt(i));
1068 TryReturn(pPackageAppInfo, false, "pPackageAppList->GetAt(%d) failed.", i);
1070 AppId appId = pPackageAppInfo->GetAppId();
1071 TerminateApp(appId);