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 <FIoRegistry.h>
34 #include <FAppPkgPackageAppInfo.h>
35 #include <FAppPkgPackageInfo.h>
36 #include <FBase_StringConverter.h>
37 #include <FSecCryptoSha2Hash.h>
39 #include <FAppPkg_PackageManagerImpl.h>
40 #include <FAppPkg_PackageInfoImpl.h>
41 #include <FAppPkg_PackageAppInfoImpl.h>
43 #include "InstallerDefs.h"
44 #include "InstallerUtil.h"
45 #include "InstallerManager.h"
46 #include "SmackManager.h"
48 using namespace Tizen::Base;
49 using namespace Tizen::Base::Collection;
50 using namespace Tizen::Base::Utility;
51 using namespace Tizen::App;
52 using namespace Tizen::App::Package;
53 using namespace Tizen::Io;
54 using namespace Tizen::Security::Crypto;
56 InstallerUtil::InstallerUtil(void)
60 InstallerUtil::~InstallerUtil(void)
65 InstallerUtil::Remove(const Tizen::Base::String& filePath)
71 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
72 TryReturn(pFilePath, false, "pFilePath is null");
74 err = lstat(pFilePath.get(), &fileinfo);
77 AppLog("Remove(): skip, path=[%s][%s](%d)", pFilePath.get(), strerror(errno), errno);
81 if (S_ISLNK(fileinfo.st_mode))
83 AppLog("Remove(): symlink=[%s]", pFilePath.get());
84 err = unlink(pFilePath.get());
85 TryReturn(err >= 0, false, "unlink() failed(%s), file=[%s]", strerror(errno), pFilePath.get());
87 else if (S_ISDIR(fileinfo.st_mode))
89 AppLog("Remove(): directory=[%ls]", filePath.GetPointer());
90 r = Directory::Remove(filePath, true);
91 TryReturn(!IsFailed(r), false, "Directory::Remove() failed, filePath=%ls", filePath.GetPointer());
95 AppLog("Remove(): file=[%ls]", filePath.GetPointer());
96 r = File::Remove(filePath);
97 TryReturn(!IsFailed(r), false, "File::Remove() failed, filePath=%ls", filePath.GetPointer());
104 InstallerUtil::Copy(const String& srcFilePath, const String& destFilePath)
108 result r = E_SUCCESS;
110 // AppLog("+ Copy(): src=[%ls], dest=[%ls]", srcFilePath.GetPointer(), destFilePath.GetPointer());
115 std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]);
116 TryReturn(pBuf, false, "pBuf is null");
118 r = srcFile.Construct(srcFilePath, L"r");
119 TryReturn(!IsFailed(r), false, "srcFile.Construct is failed");
121 r = destFile.Construct(destFilePath, L"w");
122 TryReturn(!IsFailed(r), false, "destFile.Construct is failed");
126 readBytes = srcFile.Read(pBuf.get(), bufSize);
129 r = destFile.Write(pBuf.get(), readBytes);
130 TryReturn(!IsFailed(r), false, "destFile.Write is failed");
133 while (readBytes > 0);
139 InstallerUtil::CopyDirectory(const String& srcFilePath, const String& destFilePath)
141 result r = E_SUCCESS;
144 res = File::IsFileExist(srcFilePath);
147 AppLog("CopyDirectory(): src=[%ls]: skip", srcFilePath.GetPointer());
151 std::unique_ptr<Directory> pDir(new (std::nothrow) Directory);
152 TryReturn(pDir, false, "pDir is null.");
154 r = pDir->Construct(srcFilePath);
155 TryReturn(!IsFailed(r), false, "pDir->Construct() failed, srcFilePath=[%ls].", srcFilePath.GetPointer());
157 std::unique_ptr<DirEnumerator> pDirEnum(pDir->ReadN());
158 TryReturn(pDirEnum, false, "pDirEnum is null.");
160 while (pDirEnum->MoveNext() == E_SUCCESS)
162 DirEntry entry = pDirEnum->GetCurrentDirEntry();
164 String entryName = entry.GetName();
165 String srcEntryDir = srcFilePath;
167 srcEntryDir += entryName;
169 if (entryName == L"." || entryName == L"..")
174 // if file or directory is symbolic link, skip this.
175 if (InstallerUtil::IsSymlink(srcEntryDir) == true)
180 String destEntryDir = destFilePath;
181 destEntryDir += L"/";
182 destEntryDir += entryName;
184 if (entry.IsDirectory() == false)
187 Directory::Create(destFilePath, true);
188 InstallerUtil::Copy(srcEntryDir, destEntryDir);
192 Directory::Create(destEntryDir, true);
193 CopyDirectory(srcEntryDir, destEntryDir);
197 AppLog("CopyDirectory(): src=[%ls], dest=[%ls]", srcFilePath.GetPointer(), destFilePath.GetPointer());
202 InstallerUtil::IsSymlink(const Tizen::Base::String& filePath)
205 struct stat fileinfo;
207 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
208 TryReturn(pFilePath, false, "pFilePath is null");
210 err = lstat(pFilePath.get(), &fileinfo);
211 TryReturn(err >= 0, false, "lstat() failed(%s), file=[%s]", strerror(errno), pFilePath.get());
213 if (S_ISLNK(fileinfo.st_mode))
222 InstallerUtil::GetRealPath(const String& filePath, String& realPath)
224 char* pRealPath = null;
226 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
227 TryReturn(pFilePath, false, "pFilePath is null");
229 char tmpPath[PATH_MAX] = {0};
230 pRealPath = realpath(pFilePath.get(), tmpPath);
231 TryReturn(pRealPath, false, "pRealPath is null");
235 AppLog("GetRealPath(): path=[%ls], realPath=[%ls]", filePath.GetPointer(), realPath.GetPointer());
241 InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath, bool SmackLabelToRealPath)
246 res = File::IsFileExist(oldPath);
249 AppLog("CreateSymlink(): oldPath=[%ls] not found.", oldPath.GetPointer());
253 res = File::IsFileExist(newPath);
256 AppLog("CreateSymlink(): newPath=[%ls] is alreay exist.", oldPath.GetPointer());
260 std::unique_ptr<char[]> pOldPath(_StringConverter::CopyToCharArrayN(oldPath));
261 TryReturn(pOldPath, false, "pOldPath is null");
263 std::unique_ptr<char[]> pNewPath(_StringConverter::CopyToCharArrayN(newPath));
264 TryReturn(pNewPath, false, "pNewPath is null");
266 err = symlink(pOldPath.get(), pNewPath.get());
267 TryReturn(err == 0, false, "symlink() is failed(%s), oldpath=[%s], newpath=[%s]", strerror(errno), pOldPath.get(), pNewPath.get());
269 SmackManager smackManager;
272 if (SmackLabelToRealPath == true)
274 smackManager.AddLabelDir(label, newPath);
278 smackManager.AddLabelSymlink(label, newPath);
281 AppLog("CreateSymlink(): [%ls] -> [%ls]", newPath.GetPointer(), oldPath.GetPointer());
287 InstallerUtil::ChangeMode(const String& filePath, int mode)
291 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
292 TryReturn(pFilePath, false, "pFilePath is null");
294 err = chmod(pFilePath.get(), mode);
295 TryReturn(err == 0, false, "chmod() is failed(%s), file=[%s], mode=[%o]", strerror(errno), pFilePath.get(), mode);
301 InstallerUtil::ChangeOwner(const String& filePath)
305 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
306 TryReturn(pFilePath, false, "pFilePath is null");
308 err = chown(pFilePath.get(), APP_OWNER_ID, APP_GROUP_ID);
309 TryReturn(err == 0, false, "chown() is failed(%s), file=[%s]", strerror(errno), pFilePath.get());
315 InstallerUtil::ChangeDirectoryPermission(const String& file, int mode, bool appOwner)
317 result r = E_SUCCESS;
320 res = File::IsFileExist(file);
323 AppLog("path=[%ls]: skip", file.GetPointer());
327 std::unique_ptr<Directory> pDir(new (std::nothrow) Directory);
328 TryReturn(pDir, false, "pDir is null.");
330 r = pDir->Construct(file);
331 TryReturn(!IsFailed(r), false, "pDir->Construct() failed, file=[%ls]", file.GetPointer());
333 std::unique_ptr<DirEnumerator> pDirEnum(pDir->ReadN());
334 TryReturn(pDirEnum, false, "pDirEnum is null.");
336 while (pDirEnum->MoveNext() == E_SUCCESS)
338 DirEntry entry = pDirEnum->GetCurrentDirEntry();
339 String entryName = entry.GetName();
340 if (entryName.IsEmpty() == true)
342 AppLog("entryName is empty.", entryName.GetPointer());
346 String entryDir = file;
348 entryDir += entryName;
350 if (entryName == L".")
352 if (appOwner == true)
354 InstallerUtil::ChangeOwner(entryDir);
356 InstallerUtil::ChangeMode(entryDir, mode | PERM_EXECUTE);
359 else if (entryName == L"..")
364 if (entry.IsDirectory() == false)
366 if (appOwner == true)
368 InstallerUtil::ChangeOwner(entryDir);
370 InstallerUtil::ChangeMode(entryDir, mode);
374 ChangeDirectoryPermission(entryDir, mode, appOwner);
375 if (appOwner == true)
377 InstallerUtil::ChangeOwner(entryDir);
379 InstallerUtil::ChangeMode(entryDir, mode | PERM_EXECUTE);
383 AppLog("path=[%ls], mode=[%04o], appOwner=[%s]",
384 file.GetPointer(), mode, appOwner?"true":"false");
390 InstallerUtil::IsDrmFile(const String& path)
393 void* pHandle = null;
394 char* pErrorMsg = null;
395 int (*drm_oem_sapps_is_drm_file)(const char* pDcfPath, int dcfPathLen);
397 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(path));
398 TryReturn(pFilePath, false, "pFilePath is null.");
400 pHandle = dlopen("/usr/lib/libdrm-service-core-sapps.so.0", RTLD_LAZY | RTLD_GLOBAL);
403 AppLog("dlopen() failed. [%ls][%s]", path.GetPointer(), dlerror());
407 drm_oem_sapps_is_drm_file = reinterpret_cast <int (*)(const char*, int)>(dlsym(pHandle, "drm_oem_sapps_is_drm_file"));
408 pErrorMsg = dlerror();
409 if ((pErrorMsg != null) || (drm_oem_sapps_is_drm_file == null))
411 AppLog("dlsym() failed. [%ls][%s]", path.GetPointer(), pErrorMsg);
416 AppLog("[drm] drm_oem_sapps_is_drm_file(%s, %d)", pFilePath.get(), strlen(pFilePath.get()));
417 ret = drm_oem_sapps_is_drm_file(pFilePath.get(), strlen(pFilePath.get()));
418 AppLog("[drm] drm_oem_sapps_is_drm_file(), result = [%d]", ret);
424 AppLog("file[%ls] is DRM file.", path.GetPointer());
434 InstallerUtil::DecryptPackage(const String& path, const String& decryptedPath)
437 void* pHandle = null;
438 char* pErrorMsg = null;
439 int (*drm_oem_sapps_decrypt_package)(const char* pDcfPath, int dcfPathLen, const char* pDecryptedFile, int decryptedFileLen);
441 std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(path));
442 TryReturn(pFilePath, false, "pFilePath is null.");
444 std::unique_ptr<char[]> pDecryptedPath(_StringConverter::CopyToCharArrayN(decryptedPath));
445 TryReturn(pDecryptedPath, false, "pDecryptedPath is null.");
447 pHandle = dlopen("/usr/lib/libdrm-service-core-sapps.so.0", RTLD_LAZY | RTLD_GLOBAL);
450 AppLog("dlopen() failed. [%ls][%s]", path.GetPointer(), dlerror());
454 drm_oem_sapps_decrypt_package = reinterpret_cast <int (*)(const char*, int, const char*, int)>(dlsym(pHandle, "drm_oem_sapps_decrypt_package"));
455 pErrorMsg = dlerror();
456 if ((pErrorMsg != null) || (drm_oem_sapps_decrypt_package == null))
458 AppLog("dlsym() failed. [%ls][%s]", path.GetPointer(), pErrorMsg);
463 AppLog("[drm] drm_oem_sapps_decrypt_package(%s, %d, %s, %d)", pFilePath.get(), strlen(pFilePath.get()), pDecryptedPath.get(), strlen(pDecryptedPath.get()));
464 ret = drm_oem_sapps_decrypt_package(pFilePath.get(), strlen(pFilePath.get()), pDecryptedPath.get(), strlen(pDecryptedPath.get()));
465 AppLog("[drm] drm_oem_sapps_decrypt_package(), result = [%d]", ret);
471 AppLog("[%ls] -> [%ls] is decrypted.", path.GetPointer(), decryptedPath.GetPointer());
481 InstallerUtil::GetCategory(int categoryType)
485 if (categoryType == CATEGORY_TYPE_IME)
489 else if (categoryType == CATEGORY_TYPE_HOME_SCREEN)
491 category = L"home-screen";
493 else if (categoryType == CATEGORY_TYPE_LOCK_SCREEN)
495 category = L"lock-screen";
502 InstallerUtil::GetCategoryType(char* pCategory)
504 CategoryType category = CATEGORY_TYPE_NONE;
506 if (strcasecmp(pCategory, "Ime") == 0)
508 category = CATEGORY_TYPE_IME;
510 else if (strcasecmp(pCategory, "home-screen") == 0)
512 category = CATEGORY_TYPE_HOME_SCREEN;
514 else if (strcasecmp(pCategory, "lock-screen") == 0)
516 category = CATEGORY_TYPE_LOCK_SCREEN;
523 InstallerUtil::CreateSymlinkForAppDirectory(const String& inPath, String& outPath)
527 int length = inPath.GetLength();
528 inPath.SubString(length - PACKAGE_ID_LENGTH, PACKAGE_ID_LENGTH, appId);
531 newPath = PATH_OPT_APPS;
535 if (inPath != newPath)
537 InstallerUtil::CreateSymlink(inPath, newPath);
541 AppLog("CreateSymlinkForAppDirectory(): output path=[%ls]", outPath.GetPointer());
547 InstallerUtil::CreateInfoFile(const String& filePath, const String* pContext)
549 result r = E_SUCCESS;
552 r = file.Construct(filePath, "w");
553 TryReturn(!IsFailed(r), false, "file.Construct() failed, filePath=[%ls]", filePath.GetPointer());
555 AppLog("------------------------------------------");
556 AppLog("CreateInfoFile(), filePath = [%ls]", filePath.GetPointer());
560 r = file.Write(*pContext);
561 TryReturn(!IsFailed(r), false, "file.Write() failed, filePath=[%ls]", filePath.GetPointer());
562 AppLog("string = [%ls]", pContext->GetPointer());
564 AppLog("------------------------------------------");
570 InstallerUtil::DumpLog(const char* pBuf)
572 TryReturn(pBuf, false, "pBuf is null");
574 char temp[4096] = {0};
575 int bufLen = strlen(pBuf);
576 strncpy(temp, pBuf, sizeof(temp)-1);
578 char* pStart = &temp[0];
580 for (int i = 0; i < bufLen; i++)
585 AppLog("%s", pStart);
586 pStart = temp + i + 1;
593 #define LOG_PRINT_LINE_MAX 20
594 #define LOG_BUFFER_COUNT_MAX 4096
596 InstallerUtil::DumpLogData(char *pData, int dataLen)
598 const char *szData = (const char*)pData;
600 int i = 0, j = 0, idx = 0, idx2 = 0, high = 0, low = 0, temp = 0;
602 char buf[LOG_PRINT_LINE_MAX + 2] = {0};
603 char buf2[(LOG_PRINT_LINE_MAX + 2) * 3] = {0};
604 char buf_out[sizeof(buf) + sizeof(buf2) + 1] = {0};
607 if (dataLen > LOG_BUFFER_COUNT_MAX)
609 dataLen = LOG_BUFFER_COUNT_MAX;
612 // 16 characters by 20 line are proper. // too many logs decrease performance.
613 // if (dataLen > 16*20)
616 AppLog("------------------------------------------");
618 while (i < (int)dataLen)
622 /* make ascii table */
623 if (ch >= 32 && ch <= 128)
631 high = (ch & 0xf0)>>4;
634 buf2[idx2++] = LogChangeHexToStr(high);
635 buf2[idx2++] = LogChangeHexToStr(low);
638 if (idx >= LOG_PRINT_LINE_MAX)
640 memcpy(buf_out, buf2, idx2);
642 buf_out[idx2++] = ' ';
643 buf_out[idx2++] = ' ';
645 memcpy(buf_out + idx2, buf, idx);
646 buf_out[idx2+idx] = '\0';
651 AppLog("%s\n", buf_out);
660 memcpy(buf_out, buf2, idx2);
663 for (j = 0; j < (LOG_PRINT_LINE_MAX * 3) - temp; j++)
665 buf_out[idx2++] = ' ';
668 buf_out[idx2++] = ' ';
669 buf_out[idx2++] = ' ';
671 memcpy(buf_out+idx2, buf, idx);
672 buf_out[idx2+idx] = '\0';
674 AppLog("%s\n", buf_out);
677 AppLog("------------------------------------------");
683 InstallerUtil::LogChangeHexToStr(int hex)
687 const static char hexValues[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 0};
690 if (hex >= 0 && hex <= 0x0F)
696 AppLog("LogChangeHexToStr: Error! [Hex Val: %d]\n", hex);
703 InstallerUtil::CreateLog(const String& logFile)
707 result r = file.Construct(logFile, "w");
717 InstallerUtil::AppendLog(const char* pFunction, int lineNumber, bool fatal, const char* pFormat, ...)
721 InstallerManager *pManager = InstallerManager::GetInstance();
722 if (pManager == null)
727 if (pManager->IsFileLogOn() == false)
732 String logFile = pManager->GetLogFilePath();
733 result r = file.Construct(logFile, "a");
740 va_start(args, pFormat);
741 const int bufSize = 1024;
742 char logs[bufSize+1] = {0};
743 char logs2[bufSize+1] = {0};
746 snprintf(logs, bufSize, " | %s (%d). > %s", (char*)pFunction, lineNumber, pFormat);
750 snprintf(logs, bufSize, "[TRY]| %s (%d). > %s", (char*)pFunction, lineNumber, pFormat);
753 vsnprintf(logs2, bufSize, logs, args);
754 int length = strlen(logs2);
755 logs2[length] = '\n';
757 r = file.Write(logs2, length+1);
764 if (pManager->IsHistoryFileLogOn() == true)
767 String historyLogFilePath = pManager->GetHistoryLogFilePath();
768 r = historyLogFile.Construct(historyLogFilePath, "a");
771 r = historyLogFile.Write(logs2, length+1);
785 InstallerUtil::PrintLog(const String& logFile)
787 InstallerManager *pManager = InstallerManager::GetInstance();
788 if (pManager == null)
793 if (pManager->IsFileLogOn() == false)
799 FileAttributes attribute;
801 result r = File::GetAttributes(logFile, attribute);
808 std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]);
814 r = file.Construct(logFile, "r");
823 memset(pBuf.get(), 0, bufSize);
824 readBytes = file.Read(pBuf.get(), bufSize);
827 fprintf(stderr, "%s", pBuf.get());
830 while (readBytes > 0);
836 InstallerUtil::GetRdsList(const PackageId& packageId, IList* pDeletedList, IList* pAddedList, IList* pModifiedList)
840 char rdsFilePath[1024] = {0};
841 char buffer[1024] = {0};
842 InstallerRdsState state = INSTALLER_RDS_STATE_NONE;
844 snprintf(rdsFilePath, sizeof(rdsFilePath), "%s/%ls/%s", DIR_APPLICATIONS_TMP, packageId.GetPointer(), INSTALLER_RDS_FILE_NAME);
846 fp = fopen(rdsFilePath, "r");
847 TryReturn(fp, false, "fp is null.");
848 AppLog(".rds_delta file");
851 while (fgets(buffer, sizeof(buffer), fp) != null)
853 bool isMetadata = false;
855 if (buffer[0] == '#')
857 if (strcasestr(buffer, INSTALLER_RDS_DELETE_STR))
859 state = INSTALLER_RDS_STATE_DELETE;
861 else if (strcasestr(buffer, INSTALLER_RDS_ADD_STR))
863 state = INSTALLER_RDS_STATE_ADD;
865 else if (strcasestr(buffer, INSTALLER_RDS_MODIFY_STR))
867 state = INSTALLER_RDS_STATE_MODIFY;
873 if (state == INSTALLER_RDS_STATE_NONE)
875 AppLog("Unknown RDS State, INSTALLER_RDS_STATE_NONE");
879 std::unique_ptr<String> pStr(new (std::nothrow) String(buffer));
880 TryCatch(pStr, res = false, "pStr is null.");
881 TryCatch(pStr->IsEmpty() == false, res = false, "pStr is empty.");
884 AppLog(".rds_delta: line(%03d)=[%ls]", line, pStr->GetPointer());
887 if (isMetadata == true)
890 if (state == INSTALLER_RDS_STATE_DELETE)
892 pDeletedList->Add(pStr.release());
894 else if (state == INSTALLER_RDS_STATE_ADD)
896 pAddedList->Add(pStr.release());
898 else if (state == INSTALLER_RDS_STATE_MODIFY)
900 pModifiedList->Add(pStr.release());
903 memset(buffer, 0, sizeof(buffer));
912 InstallerUtil::GetInstallerOperationString(int operation)
914 if (operation == INSTALLER_OPERATION_INSTALL)
918 else if (operation == INSTALLER_OPERATION_UNINSTALL)
922 else if (operation == INSTALLER_OPERATION_REINSTALL)
931 InstallerUtil::GetFileDigest(const String& filePath, String& digestValue)
933 const int bufSize = 64*1024;
935 result r = E_SUCCESS;
938 std::unique_ptr<Sha2Hash> pHash(new (std::nothrow) Sha2Hash());
940 r = pHash->SetAlgorithm("SHA2/256");
941 TryReturn(!IsFailed(r), false, "pHash->SetAlgorithm() is failed.");
943 r = pHash->Initialize();
944 TryReturn(!IsFailed(r), false, "pHash->Initialize() is failed.");
946 std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]);
947 TryReturn(pBuf, false, "pBuf is null");
949 r = file.Construct(filePath, L"r");
950 TryReturn(!IsFailed(r), false, "file.Construct() is failed.");
954 readBytes = file.Read(pBuf.get(), bufSize);
955 AppLog("readBytes for Hash=[%d]", readBytes);
960 r = buffer.Construct((const byte*)pBuf.get(), 0, readBytes, bufSize);
961 TryReturn(!IsFailed(r), false, "buffer.Construct() is failed.");
963 r = pHash->Update(buffer);
964 TryReturn(!IsFailed(r), false, "pHash->Update() is failed.");
967 while (readBytes > 0);
969 std::unique_ptr<ByteBuffer> pResultBuf(pHash->FinalizeN());
970 TryReturn(pResultBuf, false, "pResultBuf is null.");
972 r = StringUtil::EncodeToBase64String(*pResultBuf, digestValue);
973 TryReturn(!IsFailed(r), false, "EncodeToBase64String() is failed.");
979 InstallerUtil::ParseN(const String& str, const String& tokenDelimiter)
981 TryReturn(str.IsEmpty() == false, null, "str is empty.");
982 TryReturn(tokenDelimiter.IsEmpty() == false, null, "tokenDelimiter is empty.");
984 std::unique_ptr< HashMap > pMap(new (std::nothrow) HashMap);
985 TryReturn(pMap, null, "pMap is null.");
987 result r = pMap->Construct();
988 TryReturn(!IsFailed(r), null, "pMap->Construct() is failed.");
990 StringTokenizer strTok(str, tokenDelimiter);
991 while(strTok.HasMoreTokens() == true)
994 r = strTok.GetNextToken(token);
995 TryReturn(!IsFailed(r), null, "strTok.GetNextToken() is failed.");
997 AppLog("token = [%ls]", token.GetPointer());
999 StringTokenizer infoTok(token, L"=");
1001 if (infoTok.GetTokenCount() != 2)
1003 AppLog("'=' is not existed.");
1007 std::unique_ptr< String > pKey(new (std::nothrow) String);
1008 r = infoTok.GetNextToken(*pKey);
1009 TryReturn(!IsFailed(r), null, "infoTok.GetNextToken(*pKey) is failed.");
1010 AppLog(" - key = [%ls]", pKey->GetPointer());
1012 std::unique_ptr< String > pValue(new (std::nothrow) String);
1013 r = infoTok.GetNextToken(*pValue);
1014 TryReturn(!IsFailed(r), null, "infoTok.GetNextToken(*pValue) is failed.");
1015 AppLog(" - value = [%ls]", pValue->GetPointer());
1017 r = pMap->Add(pKey.release(), pValue.release());
1018 TryReturn(!IsFailed(r), null, "pMap->Add() is failed.");
1021 if (pMap->GetCount() <= 0)
1023 AppLog("pMap->GetCount() is invalid.");
1027 return pMap.release();
1031 InstallerUtil::TerminateApp(const AppId& appId)
1035 if (_Aul::IsRunning(appId) == true)
1037 AppLog("App(%ls) is running.", appId.GetPointer());
1039 result r = _Aul::TerminateApplication(appId);
1040 TryReturn(r == E_SUCCESS, false, "TerminateApplication() failed. [%ls]", appId.GetPointer());
1042 for (int j = 0; j < TERMINATE_RETRY_COUNT; j++)
1044 res = _Aul::IsRunning(appId);
1047 AppLog("App(%ls) is terminated.", appId.GetPointer());
1052 AppLog("App(%ls) is not terminated yet. wait count = [%d]", appId.GetPointer(), j);
1059 AppLog("App(%ls) can't be terminated.", appId.GetPointer());
1065 AppLog("App(%ls) is not running.", appId.GetPointer());
1072 InstallerUtil::TerminateApps(const PackageId& packageId)
1074 std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId));
1075 TryReturn(pPackageInfo, false, "GetPackageInfoN() failed.");
1077 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1078 TryReturn(pPackageInfoImpl, false, "GetInstance() failed.");
1080 std::unique_ptr< IList > pPackageAppList(pPackageInfoImpl->GetPackageAppInfoListN());
1081 TryReturn(pPackageAppList, false, "GetPackageAppInfoListN() failed.");
1083 for (int i = 0; i < pPackageAppList->GetCount(); i++)
1085 PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppList->GetAt(i));
1086 TryReturn(pPackageAppInfo, false, "pPackageAppList->GetAt(%d) failed.", i);
1088 AppId appId = pPackageAppInfo->GetAppId();
1089 TerminateApp(appId);
1096 InstallerUtil::IsUninstallable(const PackageId& packageId)
1100 std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId));
1101 TryReturn(pPackageInfo, false, "GetPackageInfoN() failed.");
1103 _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
1104 TryReturn(pPackageInfoImpl, false, "GetInstance() failed.");
1106 res = pPackageInfoImpl->IsUninstallable();
1108 AppLog("packageId[%ls]: Uninstallable = [%s]", packageId.GetPointer(), res?"true":"false");
1114 InstallerUtil::IsCscPackage(const PackageId& packageId, String& cscInfo)
1119 pkgmgrinfo_pkginfo_h handle = null;
1121 std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
1122 TryReturn(pPackageId, false, "pPackageId is null.");
1124 result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &handle);
1125 TryReturn(result == PMINFO_R_OK, false, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
1127 result = pkgmgrinfo_pkginfo_get_csc_path(handle, &pPath);
1128 TryReturn(result == PMINFO_R_OK, false, "pkgmgrinfo_pkginfo_get_csc_path() failed. result=[%d], package=[%s]", result, pPackageId.get());
1130 AppLog("csc_path = [%s]", pPath);
1134 if (cscInfo.IsEmpty() == false)
1137 AppLog("packageId[%ls]: cscInfo = [%ls]", packageId.GetPointer(), cscInfo.GetPointer());
1142 pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
1149 InstallerUtil::IsDefaultExternalStorage()
1153 int mmcStatus = VCONFKEY_SYSMAN_MMC_REMOVED;
1155 res = vconf_get_int("db/setting/default_memory/download", &storage);
1156 TryReturn(res == 0, false, "vconf_get_int(db/setting/default_memory/download) failed.");
1158 AppLog("Storage = [%d]", storage);
1162 res = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmcStatus);
1163 TryReturn(res == 0, false, "vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS) failed.");
1165 if ((mmcStatus == VCONFKEY_SYSMAN_MMC_REMOVED) || (mmcStatus == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED))
1167 AppLog("mmcStatus is MMC_REMOVED or NOT_MOUNTED.");
1171 AppLog("mmcStatus is MMC_MOUNTED.");
1180 InstallerUtil::IsSignatureVerificationEnabled()
1184 String section(L"feature");
1185 String entry(L"signature");
1188 r = reg.Construct(CONFIG_PATH, "r");
1189 TryReturn(!IsFailed(r), false, "CONFIG file is not found.");
1191 r = reg.GetValue(section, entry, value);
1192 TryReturn(!IsFailed(r), false, "GetValue is failed. entry = [%ls]", entry.GetPointer());
1194 AppLog("[%ls is %ls.]", entry.GetPointer(), value.GetPointer());