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>
30 #include <FBaseErrorDefine.h>
32 #include <FIoDirectory.h>
33 #include <FAppPkgPackageAppInfo.h>
34 #include <FAppPkgPackageInfo.h>
35 #include <FBase_StringConverter.h>
36 #include <FSecCryptoSha2Hash.h>
38 #include <FAppPkg_PackageManagerImpl.h>
39 #include <FAppPkg_PackageInfoImpl.h>
40 #include <FAppPkg_PackageAppInfoImpl.h>
42 #include "InstallerDefs.h"
43 #include "InstallerUtil.h"
44 #include "InstallerManager.h"
45 #include "SmackManager.h"
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Base::Utility;
50 using namespace Tizen::App;
51 using namespace Tizen::App::Package;
52 using namespace Tizen::Io;
53 using namespace Tizen::Security::Crypto;
55 InstallerUtil::InstallerUtil(void)
59 InstallerUtil::~InstallerUtil(void)
64 InstallerUtil::Remove(const Tizen::Base::String& filePath)
70 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
71 TryReturn(pFilePath, false, "pFilePath is null");
73 err = lstat(pFilePath.get(), &fileinfo);
76 AppLog("Remove(): [%s] - %s[errno(%d)]: skip", pFilePath.get(), strerror(errno), errno);
80 if (S_ISLNK(fileinfo.st_mode))
82 AppLog("Remove(): symlink=[%s]", pFilePath.get());
83 err = unlink(pFilePath.get());
84 TryReturn(err >= 0, false, "unlink() failed(%s), file=[%s]", strerror(errno), pFilePath.get());
86 else if (S_ISDIR(fileinfo.st_mode))
88 AppLog("Remove(): directory=[%ls]", filePath.GetPointer());
89 r = Directory::Remove(filePath, true);
90 TryReturn(!IsFailed(r), false, "Directory::Remove() failed, filePath=%ls", filePath.GetPointer());
94 AppLog("Remove(): file=[%ls]", filePath.GetPointer());
95 r = File::Remove(filePath);
96 TryReturn(!IsFailed(r), false, "File::Remove() failed, filePath=%ls", filePath.GetPointer());
103 InstallerUtil::Copy(const String& srcFilePath, const String& destFilePath)
107 result r = E_SUCCESS;
109 // AppLog("+ Copy(): src=[%ls], dest=[%ls]", srcFilePath.GetPointer(), destFilePath.GetPointer());
114 std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]);
115 TryReturn(pBuf, false, "pBuf is null");
117 r = srcFile.Construct(srcFilePath, L"r");
118 TryReturn(!IsFailed(r), false, "srcFile.Construct is failed");
120 r = destFile.Construct(destFilePath, L"w");
121 TryReturn(!IsFailed(r), false, "destFile.Construct is failed");
125 readBytes = srcFile.Read(pBuf.get(), bufSize);
128 r = destFile.Write(pBuf.get(), readBytes);
129 TryReturn(!IsFailed(r), false, "destFile.Write is failed");
132 while (readBytes > 0);
138 InstallerUtil::CopyDirectory(const String& srcFilePath, const String& destFilePath)
140 result r = E_SUCCESS;
143 res = File::IsFileExist(srcFilePath);
146 AppLog("CopyDirectory(): src=[%ls]: skip", srcFilePath.GetPointer());
150 std::unique_ptr<Directory> pDir(new (std::nothrow) Directory);
151 TryReturn(pDir, false, "pDir is null.");
153 r = pDir->Construct(srcFilePath);
154 TryReturn(!IsFailed(r), false, "pDir->Construct() failed, srcFilePath=[%ls].", srcFilePath.GetPointer());
156 std::unique_ptr<DirEnumerator> pDirEnum(pDir->ReadN());
157 TryReturn(pDirEnum, false, "pDirEnum is null.");
159 while (pDirEnum->MoveNext() == E_SUCCESS)
161 DirEntry entry = pDirEnum->GetCurrentDirEntry();
163 String entryName = entry.GetName();
164 String srcEntryDir = srcFilePath;
166 srcEntryDir += entryName;
168 if (entryName == L"." || entryName == L"..")
173 // if file or directory is symbolic link, skip this.
174 if (InstallerUtil::IsSymlink(srcEntryDir) == true)
179 String destEntryDir = destFilePath;
180 destEntryDir += L"/";
181 destEntryDir += entryName;
183 if (entry.IsDirectory() == false)
186 Directory::Create(destFilePath, true);
187 InstallerUtil::Copy(srcEntryDir, destEntryDir);
191 Directory::Create(destEntryDir, true);
192 CopyDirectory(srcEntryDir, destEntryDir);
196 AppLog("CopyDirectory(): src=[%ls], dest=[%ls]", srcFilePath.GetPointer(), destFilePath.GetPointer());
201 InstallerUtil::IsSymlink(const Tizen::Base::String& filePath)
204 struct stat fileinfo;
206 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
207 TryReturn(pFilePath, false, "pFilePath is null");
209 err = lstat(pFilePath.get(), &fileinfo);
210 TryReturn(err >= 0, false, "lstat() failed(%s), file=[%s]", strerror(errno), pFilePath.get());
212 if (S_ISLNK(fileinfo.st_mode))
221 InstallerUtil::GetRealPath(const String& filePath, String& realPath)
223 char* pRealPath = null;
225 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
226 TryReturn(pFilePath, false, "pFilePath is null");
228 char tmpPath[PATH_MAX] = {0};
229 pRealPath = realpath(pFilePath.get(), tmpPath);
230 TryReturn(pRealPath, false, "pRealPath is null");
234 AppLog("GetRealPath(): path=[%ls], realPath=[%ls]", filePath.GetPointer(), realPath.GetPointer());
240 InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath)
245 res = File::IsFileExist(oldPath);
248 AppLog("CreateSymlink(): oldPath=[%ls] not found", oldPath.GetPointer());
252 std::unique_ptr<char[]> pOldPath(_StringConverter::CopyToCharArrayN(oldPath));
253 TryReturn(pOldPath, false, "pOldPath is null");
255 std::unique_ptr<char[]> pNewPath(_StringConverter::CopyToCharArrayN(newPath));
256 TryReturn(pNewPath, false, "pNewPath is null");
258 err = symlink(pOldPath.get(), pNewPath.get());
259 TryReturn(err == 0, false, "symlink() is failed(%s), oldpath=[%s], newpath=[%s]", strerror(errno), pOldPath.get(), pNewPath.get());
261 SmackManager smackManager;
262 smackManager.AddLabelDir(L"_", 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));
1058 TryReturn(pPackageInfo, false, "GetPackageInfoN() failed.");
1060 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1061 TryReturn(pPackageInfoImpl, false, "GetInstance() failed.");
1063 std::unique_ptr< IList > pPackageAppList(pPackageInfoImpl->GetPackageAppInfoListN());
1064 TryReturn(pPackageAppList, false, "GetPackageAppInfoListN() failed.");
1066 for (int i = 0; i < pPackageAppList->GetCount(); i++)
1068 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppList->GetAt(i));
1069 TryReturn(pPackageAppInfo, false, "pPackageAppList->GetAt(%d) failed.", i);
1071 AppId appId = pPackageAppInfo->GetAppId();
1072 TerminateApp(appId);
1079 InstallerUtil::IsUninstallable(const PackageId& packageId)
1083 std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId));
1084 TryReturn(pPackageInfo, false, "GetPackageInfoN() failed.");
1086 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1087 TryReturn(pPackageInfoImpl, false, "GetInstance() failed.");
1089 res = pPackageInfoImpl->IsUninstallable();
1091 AppLog("packageId[%ls]: Uninstallable = [%s]", packageId.GetPointer(), res?"true":"false");
1097 InstallerUtil::IsCscPackage(const PackageId& packageId, String& cscInfo)
1102 pkgmgrinfo_pkginfo_h handle = null;
1104 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
1105 TryReturn(pPackageId, false, "pPackageId is null.");
1107 result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &handle);
1108 TryReturn(result == PMINFO_R_OK, false, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
1110 result = pkgmgrinfo_pkginfo_get_csc_path(handle, &pPath);
1111 TryReturn(result == PMINFO_R_OK, false, "pkgmgrinfo_pkginfo_get_csc_path() failed. result=[%d], package=[%s]", result, pPackageId.get());
1113 AppLog("csc_path = [%s]", pPath);
1117 if (cscInfo.IsEmpty() == false)
1120 AppLog("packageId[%ls]: cscInfo = [%ls]", packageId.GetPointer(), cscInfo.GetPointer());
1125 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1132 InstallerUtil::IsDefaultExternalStorage()
1136 int mmcStatus = VCONFKEY_SYSMAN_MMC_REMOVED;
1138 res = vconf_get_int("db/setting/default_memory/download", &storage);
1139 TryReturn(res == 0, false, "vconf_get_int(db/setting/default_memory/download) failed.");
1141 AppLog("Storage = [%d]", storage);
1145 res = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmcStatus);
1146 TryReturn(res == 0, false, "vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS) failed.");
1148 if ((mmcStatus == VCONFKEY_SYSMAN_MMC_REMOVED) || (mmcStatus == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED))
1150 AppLog("mmcStatus is MMC_REMOVED or NOT_MOUNTED.");
1154 AppLog("mmcStatus is MMC_MOUNTED.");