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;
263 smackManager.AddLabelDir(label, newPath);
265 AppLog("CreateSymlink(): [%ls] -> [%ls]", newPath.GetPointer(), oldPath.GetPointer());
271 InstallerUtil::ChangeMode(const String& filePath, int mode)
275 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
276 TryReturn(pFilePath, false, "pFilePath is null");
278 err = chmod(pFilePath.get(), mode);
279 TryReturn(err == 0, false, "chmod() is failed(%s), file=[%s], mode=[%o]", strerror(errno), pFilePath.get(), mode);
285 InstallerUtil::ChangeOwner(const String& filePath)
289 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
290 TryReturn(pFilePath, false, "pFilePath is null");
292 err = chown(pFilePath.get(), APP_OWNER_ID, APP_GROUP_ID);
293 TryReturn(err == 0, false, "chown() is failed(%s), file=[%s]", strerror(errno), pFilePath.get());
299 InstallerUtil::ChangeDirectoryPermission(const String& file, int mode, bool appOwner)
301 result r = E_SUCCESS;
304 res = File::IsFileExist(file);
307 AppLog("path=[%ls]: skip", file.GetPointer());
311 std::unique_ptr<Directory> pDir(new (std::nothrow) Directory);
312 TryReturn(pDir, false, "pDir is null.");
314 r = pDir->Construct(file);
315 TryReturn(!IsFailed(r), false, "pDir->Construct() failed, file=[%ls]", file.GetPointer());
317 std::unique_ptr<DirEnumerator> pDirEnum(pDir->ReadN());
318 TryReturn(pDirEnum, false, "pDirEnum is null.");
320 while (pDirEnum->MoveNext() == E_SUCCESS)
322 DirEntry entry = pDirEnum->GetCurrentDirEntry();
323 String entryName = entry.GetName();
324 if (entryName.IsEmpty() == true)
326 AppLog("entryName is empty.", entryName.GetPointer());
330 String entryDir = file;
332 entryDir += entryName;
334 if (entryName == L".")
336 if (appOwner == true)
338 InstallerUtil::ChangeOwner(entryDir);
340 InstallerUtil::ChangeMode(entryDir, mode | PERM_EXECUTE);
343 else if (entryName == L"..")
348 if (entry.IsDirectory() == false)
350 if (appOwner == true)
352 InstallerUtil::ChangeOwner(entryDir);
354 InstallerUtil::ChangeMode(entryDir, mode);
358 ChangeDirectoryPermission(entryDir, mode, appOwner);
359 if (appOwner == true)
361 InstallerUtil::ChangeOwner(entryDir);
363 InstallerUtil::ChangeMode(entryDir, mode | PERM_EXECUTE);
367 AppLog("path=[%ls], mode=[%04o], appOwner=[%s]",
368 file.GetPointer(), mode, appOwner?"true":"false");
374 InstallerUtil::IsDrmFile(const String& path)
377 void* pHandle = null;
378 char* pErrorMsg = null;
379 int (*drm_oem_sapps_is_drm_file)(const char* pDcfPath, int dcfPathLen);
381 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(path));
382 TryReturn(pFilePath, false, "pFilePath is null.");
384 pHandle = dlopen("/usr/lib/libdrm-service-core-sapps.so.0", RTLD_LAZY | RTLD_GLOBAL);
387 AppLog("dlopen() failed. [%ls][%s]", path.GetPointer(), dlerror());
391 drm_oem_sapps_is_drm_file = reinterpret_cast <int (*)(const char*, int)>(dlsym(pHandle, "drm_oem_sapps_is_drm_file"));
392 pErrorMsg = dlerror();
393 if ((pErrorMsg != null) || (drm_oem_sapps_is_drm_file == null))
395 AppLog("dlsym() failed. [%ls][%s]", path.GetPointer(), pErrorMsg);
400 AppLog("[drm] drm_oem_sapps_is_drm_file(%s, %d)", pFilePath.get(), strlen(pFilePath.get()));
401 ret = drm_oem_sapps_is_drm_file(pFilePath.get(), strlen(pFilePath.get()));
402 AppLog("[drm] drm_oem_sapps_is_drm_file(), result = [%d]", ret);
408 AppLog("file[%ls] is DRM file.", path.GetPointer());
418 InstallerUtil::DecryptPackage(const String& path, const String& decryptedPath)
421 void* pHandle = null;
422 char* pErrorMsg = null;
423 int (*drm_oem_sapps_decrypt_package)(const char* pDcfPath, int dcfPathLen, const char* pDecryptedFile, int decryptedFileLen);
425 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(path));
426 TryReturn(pFilePath, false, "pFilePath is null.");
428 std::unique_ptr<char[]> pDecryptedPath(_StringConverter::CopyToCharArrayN(decryptedPath));
429 TryReturn(pDecryptedPath, false, "pDecryptedPath is null.");
431 pHandle = dlopen("/usr/lib/libdrm-service-core-sapps.so.0", RTLD_LAZY | RTLD_GLOBAL);
434 AppLog("dlopen() failed. [%ls][%s]", path.GetPointer(), dlerror());
438 drm_oem_sapps_decrypt_package = reinterpret_cast <int (*)(const char*, int, const char*, int)>(dlsym(pHandle, "drm_oem_sapps_decrypt_package"));
439 pErrorMsg = dlerror();
440 if ((pErrorMsg != null) || (drm_oem_sapps_decrypt_package == null))
442 AppLog("dlsym() failed. [%ls][%s]", path.GetPointer(), pErrorMsg);
447 AppLog("[drm] drm_oem_sapps_decrypt_package(%s, %d, %s, %d)", pFilePath.get(), strlen(pFilePath.get()), pDecryptedPath.get(), strlen(pDecryptedPath.get()));
448 ret = drm_oem_sapps_decrypt_package(pFilePath.get(), strlen(pFilePath.get()), pDecryptedPath.get(), strlen(pDecryptedPath.get()));
449 AppLog("[drm] drm_oem_sapps_decrypt_package(), result = [%d]", ret);
455 AppLog("[%ls] -> [%ls] is decrypted.", path.GetPointer(), decryptedPath.GetPointer());
465 InstallerUtil::GetCategory(int categoryType)
469 if (categoryType == CATEGORY_TYPE_IME)
473 else if (categoryType == CATEGORY_TYPE_HOME_SCREEN)
475 category = L"home-screen";
477 else if (categoryType == CATEGORY_TYPE_LOCK_SCREEN)
479 category = L"lock-screen";
486 InstallerUtil::GetCategoryType(char* pCategory)
488 CategoryType category = CATEGORY_TYPE_NONE;
490 if (strcasecmp(pCategory, "Ime") == 0)
492 category = CATEGORY_TYPE_IME;
494 else if (strcasecmp(pCategory, "home-screen") == 0)
496 category = CATEGORY_TYPE_HOME_SCREEN;
498 else if (strcasecmp(pCategory, "lock-screen") == 0)
500 category = CATEGORY_TYPE_LOCK_SCREEN;
507 InstallerUtil::CreateSymlinkForAppDirectory(const String& inPath, String& outPath)
511 int length = inPath.GetLength();
512 inPath.SubString(length - PACKAGE_ID_LENGTH, PACKAGE_ID_LENGTH, appId);
515 newPath = PATH_OPT_APPS;
519 if (inPath != newPath)
521 InstallerUtil::CreateSymlink(inPath, newPath);
525 AppLog("CreateSymlinkForAppDirectory(): output path=[%ls]", outPath.GetPointer());
531 InstallerUtil::CreateInfoFile(const String& filePath, const String* pContext)
533 result r = E_SUCCESS;
536 r = file.Construct(filePath, "w");
537 TryReturn(!IsFailed(r), false, "file.Construct() failed, filePath=[%ls]", filePath.GetPointer());
539 AppLog("------------------------------------------");
540 AppLog("CreateInfoFile(), filePath = [%ls]", filePath.GetPointer());
544 r = file.Write(*pContext);
545 TryReturn(!IsFailed(r), false, "file.Write() failed, filePath=[%ls]", filePath.GetPointer());
546 AppLog("string = [%ls]", pContext->GetPointer());
548 AppLog("------------------------------------------");
554 InstallerUtil::DumpLog(const char* pBuf)
556 TryReturn(pBuf, false, "pBuf is null");
558 char temp[4096] = {0};
559 int bufLen = strlen(pBuf);
560 strncpy(temp, pBuf, sizeof(temp)-1);
562 char* pStart = &temp[0];
564 for (int i = 0; i < bufLen; i++)
569 AppLog("%s", pStart);
570 pStart = temp + i + 1;
577 #define LOG_PRINT_LINE_MAX 20
578 #define LOG_BUFFER_COUNT_MAX 4096
580 InstallerUtil::DumpLogData(char *pData, int dataLen)
582 const char *szData = (const char*)pData;
584 int i = 0, j = 0, idx = 0, idx2 = 0, high = 0, low = 0, temp = 0;
586 char buf[LOG_PRINT_LINE_MAX + 2] = {0};
587 char buf2[(LOG_PRINT_LINE_MAX + 2) * 3] = {0};
588 char buf_out[sizeof(buf) + sizeof(buf2) + 1] = {0};
591 if (dataLen > LOG_BUFFER_COUNT_MAX)
593 dataLen = LOG_BUFFER_COUNT_MAX;
596 // 16 characters by 20 line are proper. // too many logs decrease performance.
597 // if (dataLen > 16*20)
600 AppLog("------------------------------------------");
602 while (i < (int)dataLen)
606 /* make ascii table */
607 if (ch >= 32 && ch <= 128)
615 high = (ch & 0xf0)>>4;
618 buf2[idx2++] = LogChangeHexToStr(high);
619 buf2[idx2++] = LogChangeHexToStr(low);
622 if (idx >= LOG_PRINT_LINE_MAX)
624 memcpy(buf_out, buf2, idx2);
626 buf_out[idx2++] = ' ';
627 buf_out[idx2++] = ' ';
629 memcpy(buf_out + idx2, buf, idx);
630 buf_out[idx2+idx] = '\0';
635 AppLog("%s\n", buf_out);
644 memcpy(buf_out, buf2, idx2);
647 for (j = 0; j < (LOG_PRINT_LINE_MAX * 3) - temp; j++)
649 buf_out[idx2++] = ' ';
652 buf_out[idx2++] = ' ';
653 buf_out[idx2++] = ' ';
655 memcpy(buf_out+idx2, buf, idx);
656 buf_out[idx2+idx] = '\0';
658 AppLog("%s\n", buf_out);
661 AppLog("------------------------------------------");
667 InstallerUtil::LogChangeHexToStr(int hex)
671 const static char hexValues[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 0};
674 if (hex >= 0 && hex <= 0x0F)
680 AppLog("LogChangeHexToStr: Error! [Hex Val: %d]\n", hex);
687 InstallerUtil::CreateLog(const String& logFile)
691 result r = file.Construct(logFile, "w");
701 InstallerUtil::AppendLog(const char* pFunction, int lineNumber, bool fatal, const char* pFormat, ...)
705 InstallerManager *pManager = InstallerManager::GetInstance();
706 if (pManager == null)
711 if (pManager->IsFileLogOn() == false)
716 String logFile = pManager->GetLogFilePath();
717 result r = file.Construct(logFile, "a");
724 va_start(args, pFormat);
725 const int bufSize = 1024;
726 char logs[bufSize+1] = {0};
727 char logs2[bufSize+1] = {0};
730 snprintf(logs, bufSize, " | %s (%d). > %s", (char*)pFunction, lineNumber, pFormat);
734 snprintf(logs, bufSize, "[TRY]| %s (%d). > %s", (char*)pFunction, lineNumber, pFormat);
737 vsnprintf(logs2, bufSize, logs, args);
738 int length = strlen(logs2);
739 logs2[length] = '\n';
741 r = file.Write(logs2, length+1);
748 if (pManager->IsHistoryFileLogOn() == true)
751 String historyLogFilePath = pManager->GetHistoryLogFilePath();
752 r = historyLogFile.Construct(historyLogFilePath, "a");
755 r = historyLogFile.Write(logs2, length+1);
769 InstallerUtil::PrintLog(const String& logFile)
771 InstallerManager *pManager = InstallerManager::GetInstance();
772 if (pManager == null)
777 if (pManager->IsFileLogOn() == false)
783 FileAttributes attribute;
785 result r = File::GetAttributes(logFile, attribute);
792 std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]);
798 r = file.Construct(logFile, "r");
807 memset(pBuf.get(), 0, bufSize);
808 readBytes = file.Read(pBuf.get(), bufSize);
811 fprintf(stderr, "%s", pBuf.get());
814 while (readBytes > 0);
820 InstallerUtil::GetRdsList(const PackageId& packageId, IList* pDeletedList, IList* pAddedList, IList* pModifiedList)
824 char rdsFilePath[1024] = {0};
825 char buffer[1024] = {0};
826 InstallerRdsState state = INSTALLER_RDS_STATE_NONE;
828 snprintf(rdsFilePath, sizeof(rdsFilePath), "%s/%ls/%s", DIR_APPLICATIONS_TMP, packageId.GetPointer(), INSTALLER_RDS_FILE_NAME);
830 fp = fopen(rdsFilePath, "r");
831 TryReturn(fp, false, "fp is null.");
832 AppLog(".rds_delta file");
835 while (fgets(buffer, sizeof(buffer), fp) != null)
837 bool isMetadata = false;
839 if (buffer[0] == '#')
841 if (strcasestr(buffer, INSTALLER_RDS_DELETE_STR))
843 state = INSTALLER_RDS_STATE_DELETE;
845 else if (strcasestr(buffer, INSTALLER_RDS_ADD_STR))
847 state = INSTALLER_RDS_STATE_ADD;
849 else if (strcasestr(buffer, INSTALLER_RDS_MODIFY_STR))
851 state = INSTALLER_RDS_STATE_MODIFY;
857 if (state == INSTALLER_RDS_STATE_NONE)
859 AppLog("Unknown RDS State, INSTALLER_RDS_STATE_NONE");
863 std::unique_ptr<String> pStr(new (std::nothrow) String(buffer));
864 TryCatch(pStr, res = false, "pStr is null.");
865 TryCatch(pStr->IsEmpty() == false, res = false, "pStr is empty.");
868 AppLog(".rds_delta: line(%03d)=[%ls]", line, pStr->GetPointer());
871 if (isMetadata == true)
874 if (state == INSTALLER_RDS_STATE_DELETE)
876 pDeletedList->Add(pStr.release());
878 else if (state == INSTALLER_RDS_STATE_ADD)
880 pAddedList->Add(pStr.release());
882 else if (state == INSTALLER_RDS_STATE_MODIFY)
884 pModifiedList->Add(pStr.release());
887 memset(buffer, 0, sizeof(buffer));
896 InstallerUtil::GetInstallerOperationString(int operation)
898 if (operation == INSTALLER_OPERATION_INSTALL)
902 else if (operation == INSTALLER_OPERATION_UNINSTALL)
906 else if (operation == INSTALLER_OPERATION_REINSTALL)
915 InstallerUtil::GetFileDigest(const String& filePath, String& digestValue)
917 const int bufSize = 64*1024;
919 result r = E_SUCCESS;
922 std::unique_ptr<Sha2Hash> pHash(new (std::nothrow) Sha2Hash());
924 r = pHash->SetAlgorithm("SHA2/256");
925 TryReturn(!IsFailed(r), false, "pHash->SetAlgorithm() is failed.");
927 r = pHash->Initialize();
928 TryReturn(!IsFailed(r), false, "pHash->Initialize() is failed.");
930 std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]);
931 TryReturn(pBuf, false, "pBuf is null");
933 r = file.Construct(filePath, L"r");
934 TryReturn(!IsFailed(r), false, "file.Construct() is failed.");
938 readBytes = file.Read(pBuf.get(), bufSize);
939 AppLog("readBytes for Hash=[%d]", readBytes);
944 r = buffer.Construct((const byte*)pBuf.get(), 0, readBytes, bufSize);
945 TryReturn(!IsFailed(r), false, "buffer.Construct() is failed.");
947 r = pHash->Update(buffer);
948 TryReturn(!IsFailed(r), false, "pHash->Update() is failed.");
951 while (readBytes > 0);
953 std::unique_ptr<ByteBuffer> pResultBuf(pHash->FinalizeN());
954 TryReturn(pResultBuf, false, "pResultBuf is null.");
956 r = StringUtil::EncodeToBase64String(*pResultBuf, digestValue);
957 TryReturn(!IsFailed(r), false, "EncodeToBase64String() is failed.");
963 InstallerUtil::ParseN(const String& str, const String& tokenDelimiter)
965 TryReturn(str.IsEmpty() == false, null, "str is empty.");
966 TryReturn(tokenDelimiter.IsEmpty() == false, null, "tokenDelimiter is empty.");
968 std::unique_ptr< HashMap > pMap(new (std::nothrow) HashMap);
969 TryReturn(pMap, null, "pMap is null.");
971 result r = pMap->Construct();
972 TryReturn(!IsFailed(r), null, "pMap->Construct() is failed.");
974 StringTokenizer strTok(str, tokenDelimiter);
975 while(strTok.HasMoreTokens() == true)
978 r = strTok.GetNextToken(token);
979 TryReturn(!IsFailed(r), null, "strTok.GetNextToken() is failed.");
981 AppLog("token = [%ls]", token.GetPointer());
983 StringTokenizer infoTok(token, L"=");
985 if (infoTok.GetTokenCount() != 2)
987 AppLog("'=' is not existed.");
991 std::unique_ptr< String > pKey(new (std::nothrow) String);
992 r = infoTok.GetNextToken(*pKey);
993 TryReturn(!IsFailed(r), null, "infoTok.GetNextToken(*pKey) is failed.");
994 AppLog(" - key = [%ls]", pKey->GetPointer());
996 std::unique_ptr< String > pValue(new (std::nothrow) String);
997 r = infoTok.GetNextToken(*pValue);
998 TryReturn(!IsFailed(r), null, "infoTok.GetNextToken(*pValue) is failed.");
999 AppLog(" - value = [%ls]", pValue->GetPointer());
1001 r = pMap->Add(pKey.release(), pValue.release());
1002 TryReturn(!IsFailed(r), null, "pMap->Add() is failed.");
1005 if (pMap->GetCount() <= 0)
1007 AppLog("pMap->GetCount() is invalid.");
1011 return pMap.release();
1015 InstallerUtil::TerminateApp(const AppId& appId)
1019 if (_Aul::IsRunning(appId) == true)
1021 AppLog("App(%ls) is running.", appId.GetPointer());
1023 result r = _Aul::TerminateApplication(appId);
1024 TryReturn(r == E_SUCCESS, false, "TerminateApplication() failed. [%ls]", appId.GetPointer());
1026 for (int j = 0; j < TERMINATE_RETRY_COUNT; j++)
1028 res = _Aul::IsRunning(appId);
1031 AppLog("App(%ls) is terminated.", appId.GetPointer());
1036 AppLog("App(%ls) is not terminated yet. wait count = [%d]", appId.GetPointer(), j);
1043 AppLog("App(%ls) can't be terminated.", appId.GetPointer());
1049 AppLog("App(%ls) is not running.", appId.GetPointer());
1056 InstallerUtil::TerminateApps(const PackageId& packageId)
1058 std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId));
1059 TryReturn(pPackageInfo, false, "GetPackageInfoN() failed.");
1061 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1062 TryReturn(pPackageInfoImpl, false, "GetInstance() failed.");
1064 std::unique_ptr< IList > pPackageAppList(pPackageInfoImpl->GetPackageAppInfoListN());
1065 TryReturn(pPackageAppList, false, "GetPackageAppInfoListN() failed.");
1067 for (int i = 0; i < pPackageAppList->GetCount(); i++)
1069 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppList->GetAt(i));
1070 TryReturn(pPackageAppInfo, false, "pPackageAppList->GetAt(%d) failed.", i);
1072 AppId appId = pPackageAppInfo->GetAppId();
1073 TerminateApp(appId);
1080 InstallerUtil::IsUninstallable(const PackageId& packageId)
1084 std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId));
1085 TryReturn(pPackageInfo, false, "GetPackageInfoN() failed.");
1087 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1088 TryReturn(pPackageInfoImpl, false, "GetInstance() failed.");
1090 res = pPackageInfoImpl->IsUninstallable();
1092 AppLog("packageId[%ls]: Uninstallable = [%s]", packageId.GetPointer(), res?"true":"false");
1098 InstallerUtil::IsCscPackage(const PackageId& packageId, String& cscInfo)
1103 pkgmgrinfo_pkginfo_h handle = null;
1105 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
1106 TryReturn(pPackageId, false, "pPackageId is null.");
1108 result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &handle);
1109 TryReturn(result == PMINFO_R_OK, false, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
1111 result = pkgmgrinfo_pkginfo_get_csc_path(handle, &pPath);
1112 TryReturn(result == PMINFO_R_OK, false, "pkgmgrinfo_pkginfo_get_csc_path() failed. result=[%d], package=[%s]", result, pPackageId.get());
1114 AppLog("csc_path = [%s]", pPath);
1118 if (cscInfo.IsEmpty() == false)
1121 AppLog("packageId[%ls]: cscInfo = [%ls]", packageId.GetPointer(), cscInfo.GetPointer());
1126 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1133 InstallerUtil::IsDefaultExternalStorage()
1137 int mmcStatus = VCONFKEY_SYSMAN_MMC_REMOVED;
1139 res = vconf_get_int("db/setting/default_memory/download", &storage);
1140 TryReturn(res == 0, false, "vconf_get_int(db/setting/default_memory/download) failed.");
1142 AppLog("Storage = [%d]", storage);
1146 res = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmcStatus);
1147 TryReturn(res == 0, false, "vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS) failed.");
1149 if ((mmcStatus == VCONFKEY_SYSMAN_MMC_REMOVED) || (mmcStatus == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED))
1151 AppLog("mmcStatus is MMC_REMOVED or NOT_MOUNTED.");
1155 AppLog("mmcStatus is MMC_MOUNTED.");