diff options
-rwxr-xr-x | inc/InstallerDefs.h | 31 | ||||
-rwxr-xr-x | plugin/osp-installer-plugin.cpp | 11 | ||||
-rwxr-xr-x | src/Context/InstallationContext.h | 3 | ||||
-rwxr-xr-x | src/Installer/DirectoryInstaller.cpp | 2 | ||||
-rwxr-xr-x | src/Installer/PreloadedInstaller.cpp | 2 | ||||
-rwxr-xr-x | src/Manager/InstallerManager.cpp | 792 | ||||
-rwxr-xr-x | src/Manager/InstallerManager.h | 22 | ||||
-rwxr-xr-x | src/Step/DrmStep.cpp | 12 | ||||
-rwxr-xr-x | src/Step/LicenseStep.cpp | 4 | ||||
-rwxr-xr-x | src/Step/PackageCheckStep.cpp | 4 | ||||
-rwxr-xr-x | src/Step/SignatureStep.cpp | 4 | ||||
-rwxr-xr-x | src/Step/SystemCheckStep.cpp | 7 | ||||
-rwxr-xr-x | src/Step/UninstallStep.cpp | 4 | ||||
-rwxr-xr-x | src/Step/UnpackStep.cpp | 4 | ||||
-rwxr-xr-x | src/Util/InstallerUtil.cpp | 122 | ||||
-rwxr-xr-x | src/Util/InstallerUtil.h | 6 | ||||
-rwxr-xr-x | src/XmlHandler/ManifestHandler.cpp | 3 | ||||
-rwxr-xr-x | src/XmlHandler/PrivilegeHandler.cpp | 1 | ||||
-rwxr-xr-x | src/XmlHandler/SignatureHandler.cpp | 1 | ||||
-rwxr-xr-x | src/backend/backend.cpp | 87 |
20 files changed, 633 insertions, 489 deletions
diff --git a/inc/InstallerDefs.h b/inc/InstallerDefs.h index e9c3b1a..69d66b5 100755 --- a/inc/InstallerDefs.h +++ b/inc/InstallerDefs.h @@ -21,7 +21,9 @@ #ifndef _INSTALLER_DEFS_H_ #define _INSTALLER_DEFS_H_ -#define OSP_INSTALLER_VERSION "osp-installer version = 20130130.1" +#include "InstallerUtil.h" + +#define OSP_INSTALLER_VERSION "version=[20130130.1]" #define DIR_BIN L"/bin" #define DIR_INFO L"/info" @@ -75,7 +77,7 @@ #define APP_OWNER_ID 5000 #define APP_GROUP_ID 5000 -#define APPID_LENGTH 10 +#define PACKAGE_ID_LENGTH 10 #define APP_DIR_LENGTH 20 #define TEST_ARG_COUNT 1 @@ -107,8 +109,7 @@ static const int BLOCK_SIZE = 4096; #ifdef AppLog #undef AppLog #define AppLog(...) AppLogTagInternal(OSP_INSTALLER, " | ", 0, __VA_ARGS__); \ - fprintf(stderr, " | "); \ - fprintf(stderr, __VA_ARGS__);fprintf(stderr, "\n"); + InstallerUtil::AppendLog(__PRETTY_FUNCTION__, __LINE__, false, __VA_ARGS__); #endif #ifdef TryCatch @@ -117,10 +118,7 @@ static const int BLOCK_SIZE = 4096; if (!(condition)) { \ AppLogExceptionTag(OSP_INSTALLER, __VA_ARGS__); \ expr; \ - fprintf(stderr, " | "); \ - fprintf(stderr, "%s(%d)\n", (const char *)__PRETTY_FUNCTION__, __LINE__); \ - fprintf(stderr, " |--> "); \ - fprintf(stderr, __VA_ARGS__);fprintf(stderr, "\n"); \ + InstallerUtil::AppendLog(__PRETTY_FUNCTION__, __LINE__, true, __VA_ARGS__); \ goto CATCH; \ } \ else {;} @@ -131,10 +129,7 @@ static const int BLOCK_SIZE = 4096; #define TryReturn(condition, returnValue, ...) \ if (!(condition)) { \ AppLogExceptionTag(OSP_INSTALLER, __VA_ARGS__); \ - fprintf(stderr, " | "); \ - fprintf(stderr, "%s(%d)\n", (const char *)__PRETTY_FUNCTION__, __LINE__); \ - fprintf(stderr, " |--> "); \ - fprintf(stderr, __VA_ARGS__);fprintf(stderr, "\n"); \ + InstallerUtil::AppendLog(__PRETTY_FUNCTION__, __LINE__, true, __VA_ARGS__); \ return returnValue; \ } \ else {;} @@ -186,11 +181,15 @@ enum InstallerType }; -enum RequesterType +enum InstallerOption { - REQUESTER_TYPE_NORMAL, - REQUESTER_TYPE_IDE, - REQUESTER_TYPE_PRELOADED, + INSTALLER_OPTION_NONE = 0, + INSTALLER_OPTION_NORMAL = 1, + INSTALLER_OPTION_IDE = 2, + INSTALLER_OPTION_PRELOADED = 4, + INSTALLER_OPTION_HYBRID = 8, + INSTALLER_OPTION_NO_INPUT = 16, + INSTALLER_OPTION_FILELOG_ON = 32, }; diff --git a/plugin/osp-installer-plugin.cpp b/plugin/osp-installer-plugin.cpp index a923881..6d2d1ac 100755 --- a/plugin/osp-installer-plugin.cpp +++ b/plugin/osp-installer-plugin.cpp @@ -35,6 +35,7 @@ using namespace Tizen::Base; using namespace Tizen::Io; +using namespace Tizen::App; using namespace Tizen::App::Package; #ifdef __cplusplus @@ -57,7 +58,7 @@ static int pkg_plugin_pkg_is_installed(const char *pkg_name) { int err = PKG_SUCCESS; String packageName(pkg_name); - String packageId; + PackageId packageId; bool installed = true; AppLog("[libtpk] pkg_plugin_pkg_is_installed() is called"); @@ -68,11 +69,11 @@ static int pkg_plugin_pkg_is_installed(const char *pkg_name) if (packageName.Contains(PACKAGE_NAME_PREFIX_ORG) == true) { String prefixPackage(PACKAGE_NAME_PREFIX_ORG); - packageName.SubString(prefixPackage.GetLength(), APPID_LENGTH, packageId); + packageName.SubString(prefixPackage.GetLength(), PACKAGE_ID_LENGTH, packageId); } else { - packageName.SubString(0, APPID_LENGTH, packageId); + packageName.SubString(0, PACKAGE_ID_LENGTH, packageId); } installed = _PackageManagerImpl::GetInstance()->IsPackageInstalled(packageId); @@ -113,11 +114,11 @@ static int pkg_plugin_get_pkg_detail_info(const char *pkg_name, if (packageName.Contains(PACKAGE_NAME_PREFIX_ORG) == true) { String prefixPackage(PACKAGE_NAME_PREFIX_ORG); - packageName.SubString(prefixPackage.GetLength(), APPID_LENGTH, appId); + packageName.SubString(prefixPackage.GetLength(), PACKAGE_ID_LENGTH, appId); } else { - packageName.SubString(0, APPID_LENGTH, appId); + packageName.SubString(0, PACKAGE_ID_LENGTH, appId); } r = pkgInfoImpl.Construct(appId); diff --git a/src/Context/InstallationContext.h b/src/Context/InstallationContext.h index 6a8fa29..555f438 100755 --- a/src/Context/InstallationContext.h +++ b/src/Context/InstallationContext.h @@ -139,9 +139,10 @@ public: Tizen::Base::String __temporaryDir; Tizen::Base::String __installDir; Tizen::Base::String __workingDir; - Tizen::Base::String __packageId; + Tizen::App::PackageId __packageId; Tizen::Base::String __appVersion; Tizen::Base::String __appRootPath; + Tizen::Base::String __mainAppName; }; // InstallationContext diff --git a/src/Installer/DirectoryInstaller.cpp b/src/Installer/DirectoryInstaller.cpp index 4f89859..b0df3ff 100755 --- a/src/Installer/DirectoryInstaller.cpp +++ b/src/Installer/DirectoryInstaller.cpp @@ -173,7 +173,7 @@ DirectoryInstaller::RemoveInfoFiles(void) // check *.info file if (_FileImpl::GetFileExtension(entryDir) == FILE_EXT_INFO) { - AppLog("Request to delete info file = [%ls]\n", entryDir.GetPointer()); + AppLog("Request to delete info file = [%ls]", entryDir.GetPointer()); InstallerUtil::Remove(entryDir); } } diff --git a/src/Installer/PreloadedInstaller.cpp b/src/Installer/PreloadedInstaller.cpp index ef031b6..2b85ab0 100755 --- a/src/Installer/PreloadedInstaller.cpp +++ b/src/Installer/PreloadedInstaller.cpp @@ -53,7 +53,7 @@ PreloadedInstaller::OnInit(void) String prefix(PATH_USR_APPS); prefix += L"/"; - path.SubString(prefix.GetLength(), APPID_LENGTH, appId); + path.SubString(prefix.GetLength(), PACKAGE_ID_LENGTH, appId); String destRootPath(PATH_OPT_USR_APPS); destRootPath += L"/"; diff --git a/src/Manager/InstallerManager.cpp b/src/Manager/InstallerManager.cpp index 0ca92dc..467d8ef 100755 --- a/src/Manager/InstallerManager.cpp +++ b/src/Manager/InstallerManager.cpp @@ -21,6 +21,7 @@ #include <unistd.h> #include <unique_ptr.h> +#include <stdio.h> #include <app2ext_interface.h> @@ -56,6 +57,7 @@ InstallerManager::InstallerManager(void) ,__operation(INSTALLER_OPERATION_INSTALL) ,__startTick(0) ,__endTick(0) +,__isFileLogOn(false) { } @@ -81,20 +83,42 @@ InstallerManager::GetInstance() } InstallerError -InstallerManager::Construct(const String& path, InstallerOperation operation, RequesterType requesterType, bool hybridService) +InstallerManager::Construct(const String& path, InstallerOperation operation, InstallerOption option) { InstallerError error = INSTALLER_ERROR_NONE; InstallerType installerType = INSTALLER_TYPE_INSTALLER; result r = E_SUCCESS; String newPath = path; + Tizen::System::SystemTime::GetTicks(__startTick); + SetInstallerOperation(operation); + + if (option & INSTALLER_OPTION_FILELOG_ON) + { + r = Directory::Create(DIR_OSP_APPLICATIONS_TEMP, false); + if (!IsFailed(r)) + { + __logFilePath = DIR_OSP_APPLICATIONS_TEMP; + __logFilePath += L"/log.txt"; + InstallerUtil::CreateLog(__logFilePath); + + __isFileLogOn = true; + } + } + + AppLog("------------------------------------------"); + AppLog("InstallerManager"); + AppLog("------------------------------------------"); + AppLog(" # operation = [%s]", (operation == INSTALLER_OPERATION_INSTALL)?"Install":"Uninstall"); + AppLog(" # path = [%ls]", path.GetPointer()); + AppLog("------------------------------------------"); + __pContext = new InstallationContext(); TryReturn(__pContext, INSTALLER_ERROR_OUT_OF_MEMORY, "__pContext is null."); error = __pContext->Construct(); TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "__pContext->Construct() failed."); - // 1. operation if (operation == INSTALLER_OPERATION_INSTALL) { FileAttributes attr; @@ -138,8 +162,7 @@ InstallerManager::Construct(const String& path, InstallerOperation operation, Re __pContext->SetInstallerOperation(operation); - // 3. hybridService - if (hybridService == true) + if (option & INSTALLER_OPTION_HYBRID) { AppLog("Request to install HybridService app!"); __pContext->__isHybridService = true; @@ -320,359 +343,6 @@ InstallerManager::GetContext(void) } int -InstallerManager::Request(const String& path, InstallerOperation operation, RequesterType requesterType, bool hybridService) -{ - InstallationContext* pContext = null; - InstallerError errorType = INSTALLER_ERROR_NONE; - InstallerManager* pInstallManager = null; - PackageId packageId; - - if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true) - { - InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP); - } - - Tizen::System::SystemTime::GetTicks(__startTick); - - AppLog("------------------------------------------"); - AppLog("InstallerManager::Request"); - AppLog("------------------------------------------"); - AppLog(" # operation = [%s]", (operation == INSTALLER_OPERATION_INSTALL)?"Installation":"Uninstallation"); - AppLog(" # path = [%ls]", path.GetPointer()); - AppLog("------------------------------------------"); - - SetInstallerOperation(operation); - - pInstallManager = InstallerManager::GetInstance(); - TryCatch(pInstallManager, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pInstallManager is null."); - - errorType = pInstallManager->Construct(path, operation, requesterType, hybridService); - TryCatch(errorType == INSTALLER_ERROR_NONE, , "pInstallManager->Construct() failed."); - - errorType = pInstallManager->Activate(); - TryCatch(errorType == INSTALLER_ERROR_NONE, , "pInstallManager->Activate() failed."); - - pContext = pInstallManager->GetContext(); - TryCatch(pContext, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pContext is null."); - - packageId = pContext->GetId(); - SetId(packageId); - -CATCH: - if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true) - { - InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP); - } - - SetErrorType(errorType); - return errorType; -} - -int -InstallerManager::RequestRecursiveDirectory(const Tizen::Base::String& path, int& errorType) -{ - Directory* pDir = null; - DirEnumerator* pDirEnum = null; - result r = E_SUCCESS; - int res = false; - String appid; - InstallerError error = INSTALLER_ERROR_NONE; - int totalCount = 0; - int successCount = 0; - int failureCount = 0; - - pDir = new (std::nothrow) Directory; // Allocate %Directory instance - TryCatch(pDir, res = false, "pDir is null"); - - r = pDir->Construct(path); - TryCatch(!IsFailed(r), res = false, "pDir->Construct() failed, path = [%ls]", path.GetPointer()); - - pDirEnum = pDir->ReadN(); - TryCatch(pDirEnum, res = false, "pDirEnum is null"); - - while (pDirEnum->MoveNext() == E_SUCCESS) - { - DirEntry entry = pDirEnum->GetCurrentDirEntry(); - - String entryName = entry.GetName(); - String entryDir = path; - entryDir += L"/"; - entryDir += entryName; - - if (entryName == L"." || entryName == L"..") - { - continue; - } - - if (entry.IsDirectory() == false) - { - continue; - } - - const int entryLength = entryName.GetLength(); - if (entryLength == APPID_LENGTH) - { - // AppId - } - else if (entryLength == APP_DIR_LENGTH) - { - if (entryName.Contains(PACKAGE_NAME_PREFIX_ORG) == false) - { - AppLog(" - Not osp = [%ls]: prefix mismatch", entryDir.GetPointer()); - continue; - } - } - else - { - AppLog(" - Not osp = [%ls]: length(%d) mismatch", entryDir.GetPointer(), entryLength); - continue; - } - - String xmlFile; - xmlFile.Format(1024, L"%ls%ls", entryDir.GetPointer(), PACKAGE_XML_FILE); - - FileAttributes attr; - r = File::GetAttributes(xmlFile, attr); - if (IsFailed(r)) - { - AppLog(" - Not osp = [%ls]: No manifest.xml", entryDir.GetPointer()); - continue; - } - - totalCount++; - - AppLog("------------------------------------------"); - AppLog(" # Directory = [%ls]", entryDir.GetPointer()); - - errorType = Request(entryDir, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_PRELOADED); - if (errorType == 0) - { - successCount++; - } - else - { - failureCount++; - } - - PrintResult(); - - AppLog("------------------------------------------"); - } - - AppLog("------------------------------------------"); - AppLog("recursive directory installation"); - AppLog(" # totalCount = [%d]", totalCount); - AppLog(" # successCount = [%d]", successCount); - AppLog(" # failureCount = [%d]", failureCount); - -CATCH: - delete pDirEnum; - delete pDir; - return error; -} - -int -InstallerManager::RequestByCommand(int argc, char **argv) -{ - int mode = 0; - char buf[BUFSIZE] = {0}; - // String appId; - int errorType = 0; - bool output = false; - bool hybridService = false; - - AppLog(" # argc = [%d]", argc); - - for (int i = 0; i < argc; i++) - { - AppLog(" # argv[%d] = [%s]", i, argv[i]); - } - - ParseCommandArg(argc, argv, &mode, buf, &output); - - if (output == true) - { - AppLog("HybridService is detected in ParseCommandArg()"); - hybridService = true; - } - - switch (mode) - { - case INSTALLER_MODE_INSTALL: - { - AppLog("------------------------------------------"); - AppLog(" # Directory = [%s]", buf); - - errorType = Request(buf, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL, hybridService); - if (errorType != 0) - { - // in case of command, garbage directory is not deleted. - // RemoveGarbage(buf); - } - PrintResult(); - } - break; - - case INSTALLER_MODE_UNINSTALL: - { - AppLog("------------------------------------------"); - AppLog(" # Directory = [%s]", buf); - - errorType = Request(buf, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL, hybridService); - PrintResult(); - } - break; - - case INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL: - { - AppLog("------------------------------------------"); - - errorType = RequestRecursiveDirectory(buf, errorType); - } - break; - - default: - { - AppLog("__install_package_by_cmd, Invalid mode"); - } - break; - } - - AppLog("=========================================="); - - if (output == true) - { - AppLog("stdout is updated by errorType"); - fprintf(stdout, "%d", errorType); - } - - return errorType; -} - -int -InstallerManager::RequestMove(const PackageId& packageId, int moveType) -{ - result r = E_SUCCESS; - int res = 0; - InstallerError errorType = INSTALLER_ERROR_NONE; - app2ext_handle* pHandle = null; - app2ext_move_type location = APP2EXT_MOVE_TO_EXT; - GList* pDirectoryList = null; - Directory* pDir = null; - DirEnumerator* pDirEnum = null; - PackageInfo* pPackageInfo = null; - _PackageInfoImpl* pPackageInfoImpl = null; - String rootPath; - - std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId)); - TryReturn(pPackageId, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageId is null"); - - if (moveType == PM_MOVE_TO_INTERNAL) - { - location = APP2EXT_MOVE_TO_PHONE; - } - - pPackageInfo = _PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId); - TryCatch(pPackageInfo != null, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetPackageInfoN() failed"); - - pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo); - TryCatch(pPackageInfoImpl, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetInstance() failed"); - - rootPath = pPackageInfoImpl->GetAppRootPath(); - - pHandle = app2ext_init(APP2EXT_SD_CARD); - TryCatch(pHandle, errorType = INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed"); - - if (location == APP2EXT_MOVE_TO_PHONE) - { - res = pHandle->interface.enable(pPackageId.get()); - TryCatch(res == 0, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.eable() failed [%d]", res); - } - - pDir = new (std::nothrow) Directory; - TryCatch(pDir, errorType = INSTALLER_ERROR_OUT_OF_MEMORY, "pDir is null"); - - r = pDir->Construct(rootPath); - TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDir->Construct() failed, path = [%ls]", rootPath.GetPointer()); - - pDirEnum = pDir->ReadN(); - TryCatch(pDirEnum, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirEnum is null"); - - while (pDirEnum->MoveNext() == E_SUCCESS) - { - DirEntry entry = pDirEnum->GetCurrentDirEntry(); - - String entryName = entry.GetName(); - //String rootDirectory = rootPath; - //rootDirectory += L"/"; - //rootDirectory += entryName; - - if (entryName == L"." || entryName == L"..") - { - continue; - } - - int length = 0; - app2ext_dir_details* pDirDetails = null; - - pDirDetails = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details)); - TryCatch(pDirDetails, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirDetails is null"); - - length = entryName.GetLength(); - pDirDetails->name = (char*) calloc(1, (sizeof(char) * length) + 1); - snprintf(pDirDetails->name, length + 1, "%ls", entryName.GetPointer()); - - String bin(L"bin"); - String res(L"res"); - String icons(L"icons"); - - if (entryName.Contains(bin) || entryName.Contains(res) || entryName.Contains(icons)) - { - pDirDetails->type = APP2EXT_DIR_RO; - } - else - { - pDirDetails->type = APP2EXT_DIR_RW; - } - - AppLog("------------------------------------------"); - AppLog("# Root Directory = [%s], Type = [%d]", pDirDetails->name, pDirDetails->type); - - pDirectoryList = g_list_append(pDirectoryList, pDirDetails); - } - - res = pHandle->interface.move(pPackageId.get(), pDirectoryList, location); - TryCatch(res == 0, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.move() failed [%d]", res); - - app2ext_deinit(pHandle); - -CATCH: - if (pDirectoryList) - { - GList* pList = null; - app2ext_dir_details* pDirDetails = null; - - pList = g_list_first(pDirectoryList); - while (pList) - { - pDirDetails = (app2ext_dir_details*)pList->data; - if (pDirDetails && pDirDetails->name) - { - free(pDirDetails->name); - } - pList = g_list_next(pList); - } - g_list_free(pDirectoryList); - } - - delete pDirEnum; - delete pDir; - delete pPackageInfo; - - return errorType; -} - -int InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output) { const char* pOpts_str = "u:i:r:v"; @@ -803,6 +473,7 @@ InstallerManager::ReqeustByTest(void) Tizen::Io::FileAttributes attr; result r = E_SUCCESS; char readBuf[512] = {0}; + PackageId packageId; r = File::GetAttributes(L"/opt/apps/cmtamb4mtv/data/configuration", attr); TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_PACKAGE_NOT_FOUND, "file not found"); @@ -817,23 +488,23 @@ InstallerManager::ReqeustByTest(void) if (readBuf[0] == '+') { - errorType = Request(path, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL); + errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, packageId); } else if (readBuf[0] == '-') { - errorType = Request(path, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL); + errorType = InstallerManager::Request(path, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, packageId); } else if (readBuf[0] == '*') { - errorType = RequestRecursiveDirectory(path, errorType); + errorType = InstallerManager::RequestRecursiveDirectory(path, errorType); } else if (readBuf[0] == '>') { - errorType = RequestMove(path, PM_MOVE_TO_SDCARD); + errorType = InstallerManager::RequestMove(path, PM_MOVE_TO_SDCARD); } else if (readBuf[0] == '<') { - errorType = RequestMove(path, PM_MOVE_TO_INTERNAL); + errorType = InstallerManager::RequestMove(path, PM_MOVE_TO_INTERNAL); } } @@ -908,19 +579,42 @@ InstallerManager::PrintPackageInfo(const char* appId) void InstallerManager::PrintResult(void) { - String packageId = GetId(); int errorType = GetErrorType(); InstallerOperation operation = GetInstallerOperation(); Tizen::System::SystemTime::GetTicks(__endTick); + const char* pOperation = null; + (operation == INSTALLER_OPERATION_INSTALL)? (pOperation = "Install"): (pOperation = "Uninstall"); + + const wchar_t* pPackageId = L"Unknown"; + if (__pContext && !__pContext->GetId().IsEmpty()) + { + pPackageId = __pContext->GetId().GetPointer(); + } + + const wchar_t* pMainAppName = L"Unknown"; + if (__pContext && !__pContext->__mainAppName.IsEmpty()) + { + pMainAppName = __pContext->__mainAppName.GetPointer(); + } + + const char* pError = null; + (errorType == 0)?(pError = "Success"):(pError = "Failure"); + + int duration = (int)(__endTick - __startTick); + AppLog("=========================================="); - AppLog("%s Result", (operation == INSTALLER_OPERATION_INSTALL)?"Installation":"Uninstallation"); + AppLog(" # operation = %s", pOperation); AppLog(" # %s", OSP_INSTALLER_VERSION); - AppLog(" # PackageId = [%ls]", packageId.IsEmpty() ? L"Unknown" : packageId.GetPointer()); - AppLog(" # Result = [%s]", (errorType == 0)?"Success":"Failure"); - AppLog(" # Time = [%d]ms", (int)(__endTick-__startTick)); + AppLog(" # PackageId = [%ls]", pPackageId); + AppLog(" # MainApp = [%ls]", pMainAppName); + AppLog(" # Time = [%d]ms", duration); PrintError(errorType); + AppLog("=========================================="); + + fprintf(stderr, " ## osp-installer: operation=[%s] result=[%s(%03d)] package id=[%ls] main appname=[%ls] time=[%d]ms\n", + pOperation, pError, errorType, pPackageId, pMainAppName, duration); } void @@ -1049,3 +743,367 @@ InstallerManager::GetInstallerOperation(void) const { return __operation; } + +String +InstallerManager::GetLogFilePath() const +{ + return __logFilePath; +} + +bool +InstallerManager::IsFileLogOn() const +{ + return __isFileLogOn; +} + +int +InstallerManager::Request(const String& path, InstallerOperation operation, InstallerOption option, PackageId& packageId) +{ + InstallationContext* pContext = null; + InstallerError errorType = INSTALLER_ERROR_NONE; + InstallerManager* pInstallManager = null; + + if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true) + { + InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP); + } + pInstallManager = InstallerManager::GetInstance(); + TryCatch(pInstallManager, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pInstallManager is null."); + + errorType = pInstallManager->Construct(path, operation, option); + TryCatch(errorType == INSTALLER_ERROR_NONE, , "pInstallManager->Construct() failed."); + + errorType = pInstallManager->Activate(); + TryCatch(errorType == INSTALLER_ERROR_NONE, , "pInstallManager->Activate() failed."); + + pContext = pInstallManager->GetContext(); + TryCatch(pContext, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pInstallManager->GetContext failed."); + packageId = pContext->GetId(); + +CATCH: + pInstallManager->SetErrorType(errorType); + + if (pInstallManager) + { + if (!(option & INSTALLER_OPTION_NO_INPUT)) + { + pInstallManager->PrintResult(); + } + + if (errorType != INSTALLER_ERROR_NONE) + { + InstallerUtil::PrintLog(pInstallManager->GetLogFilePath()); + } + + pInstallManager->Release(); + } + + if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true) + { + InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP); + } + + return errorType; +} + +int +InstallerManager::RequestRecursiveDirectory(const Tizen::Base::String& path, int& errorType) +{ + Directory* pDir = null; + DirEnumerator* pDirEnum = null; + result r = E_SUCCESS; + int res = false; + String appid; + InstallerError error = INSTALLER_ERROR_NONE; + int totalCount = 0; + int successCount = 0; + int failureCount = 0; + PackageId packageId; + + pDir = new (std::nothrow) Directory; // Allocate %Directory instance + TryCatch(pDir, res = false, "pDir is null"); + + r = pDir->Construct(path); + TryCatch(!IsFailed(r), res = false, "pDir->Construct() failed, path = [%ls]", path.GetPointer()); + + pDirEnum = pDir->ReadN(); + TryCatch(pDirEnum, res = false, "pDirEnum is null"); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String entryDir = path; + entryDir += L"/"; + entryDir += entryName; + + if (entryName == L"." || entryName == L"..") + { + continue; + } + + if (entry.IsDirectory() == false) + { + continue; + } + + const int entryLength = entryName.GetLength(); + if (entryLength == PACKAGE_ID_LENGTH) + { + // PackageId + } + else if (entryLength == APP_DIR_LENGTH) + { + if (entryName.Contains(PACKAGE_NAME_PREFIX_ORG) == false) + { + AppLog(" - Not osp = [%ls]: prefix mismatch", entryDir.GetPointer()); + continue; + } + } + else + { + AppLog(" - Not osp = [%ls]: length(%d) mismatch", entryDir.GetPointer(), entryLength); + continue; + } + + String xmlFile; + xmlFile.Format(1024, L"%ls%ls", entryDir.GetPointer(), PACKAGE_XML_FILE); + + FileAttributes attr; + r = File::GetAttributes(xmlFile, attr); + if (IsFailed(r)) + { + AppLog(" - Not osp = [%ls]: No manifest.xml", entryDir.GetPointer()); + continue; + } + + totalCount++; + + AppLog("------------------------------------------"); + AppLog(" # Directory = [%ls]", entryDir.GetPointer()); + + errorType = Request(entryDir, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, packageId); + if (errorType == 0) + { + successCount++; + } + else + { + failureCount++; + } + + AppLog("------------------------------------------"); + } + + AppLog("------------------------------------------"); + AppLog("recursive directory installation"); + AppLog(" # totalCount = [%d]", totalCount); + AppLog(" # successCount = [%d]", successCount); + AppLog(" # failureCount = [%d]", failureCount); + +CATCH: + delete pDirEnum; + delete pDir; + return error; +} + +int +InstallerManager::RequestByCommand(int argc, char **argv) +{ + int mode = 0; + char buf[BUFSIZE] = {0}; + PackageId packageId; + int errorType = 0; + bool output = false; + InstallerOption option = INSTALLER_OPTION_NORMAL; + + AppLog(" # argc = [%d]", argc); + + for (int i = 0; i < argc; i++) + { + AppLog(" # argv[%d] = [%s]", i, argv[i]); + } + + InstallerManager::ParseCommandArg(argc, argv, &mode, buf, &output); + if (output == true) + { + AppLog("HybridService is detected in ParseCommandArg()"); + option = (InstallerOption)(option | INSTALLER_OPTION_HYBRID); + } + + switch (mode) + { + case INSTALLER_MODE_INSTALL: + { + AppLog("------------------------------------------"); + AppLog(" # Directory = [%s]", buf); + + option = (InstallerOption)(option | INSTALLER_OPTION_FILELOG_ON); + errorType = InstallerManager::Request(buf, INSTALLER_OPERATION_INSTALL, option, packageId); + if (errorType != 0) + { + // in case of command, garbage directory is not deleted. + // RemoveGarbage(buf); + } + } + break; + + case INSTALLER_MODE_UNINSTALL: + { + AppLog("------------------------------------------"); + AppLog(" # Directory = [%s]", buf); + + option = (InstallerOption)(option | INSTALLER_OPTION_FILELOG_ON); + errorType = InstallerManager::Request(buf, INSTALLER_OPERATION_UNINSTALL, option, packageId); + } + break; + + case INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL: + { + AppLog("------------------------------------------"); + + errorType = InstallerManager::RequestRecursiveDirectory(buf, errorType); + } + break; + + default: + { + AppLog("__install_package_by_cmd, Invalid mode"); + } + break; + } + + AppLog("=========================================="); + + if (output == true) + { + AppLog("stdout is updated by errorType"); + fprintf(stdout, "%d", errorType); + } + + return errorType; +} + +int +InstallerManager::RequestMove(const PackageId& packageId, int moveType) +{ + result r = E_SUCCESS; + int res = 0; + InstallerError errorType = INSTALLER_ERROR_NONE; + app2ext_handle* pHandle = null; + app2ext_move_type location = APP2EXT_MOVE_TO_EXT; + GList* pDirectoryList = null; + Directory* pDir = null; + DirEnumerator* pDirEnum = null; + PackageInfo* pPackageInfo = null; + _PackageInfoImpl* pPackageInfoImpl = null; + String rootPath; + + std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId)); + TryReturn(pPackageId, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageId is null"); + + if (moveType == PM_MOVE_TO_INTERNAL) + { + location = APP2EXT_MOVE_TO_PHONE; + } + + pPackageInfo = _PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId); + TryCatch(pPackageInfo != null, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetPackageInfoN() failed"); + + pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo); + TryCatch(pPackageInfoImpl, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetInstance() failed"); + + rootPath = pPackageInfoImpl->GetAppRootPath(); + + pHandle = app2ext_init(APP2EXT_SD_CARD); + TryCatch(pHandle, errorType = INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed"); + + if (location == APP2EXT_MOVE_TO_PHONE) + { + res = pHandle->interface.enable(pPackageId.get()); + } + + pDir = new (std::nothrow) Directory; + TryCatch(pDir, errorType = INSTALLER_ERROR_OUT_OF_MEMORY, "pDir is null"); + + r = pDir->Construct(rootPath); + TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDir->Construct() failed, path = [%ls]", rootPath.GetPointer()); + + pDirEnum = pDir->ReadN(); + TryCatch(pDirEnum, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirEnum is null"); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + //String rootDirectory = rootPath; + //rootDirectory += L"/"; + //rootDirectory += entryName; + + if (entryName == L"." || entryName == L"..") + { + continue; + } + + int length = 0; + app2ext_dir_details* pDirDetails = null; + + pDirDetails = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details)); + TryCatch(pDirDetails, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirDetails is null"); + + length = entryName.GetLength(); + pDirDetails->name = (char*) calloc(1, (sizeof(char) * length) + 1); + snprintf(pDirDetails->name, length + 1, "%ls", entryName.GetPointer()); + + String bin(L"bin"); + String res(L"res"); + String icons(L"icons"); + + if (entryName.Contains(bin) || entryName.Contains(res) || entryName.Contains(icons)) + { + pDirDetails->type = APP2EXT_DIR_RO; + } + else + { + pDirDetails->type = APP2EXT_DIR_RW; + } + + AppLog("------------------------------------------"); + AppLog("# Root Directory = [%s], Type = [%d]", pDirDetails->name, pDirDetails->type); + + pDirectoryList = g_list_append(pDirectoryList, pDirDetails); + } + + res = pHandle->interface.move(pPackageId.get(), pDirectoryList, location); + TryCatch(res == 0, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.move() failed [%d]", res); + + app2ext_deinit(pHandle); + +CATCH: + if (pDirectoryList) + { + GList* pList = null; + app2ext_dir_details* pDirDetails = null; + + pList = g_list_first(pDirectoryList); + while (pList) + { + pDirDetails = (app2ext_dir_details*)pList->data; + if (pDirDetails && pDirDetails->name) + { + free(pDirDetails->name); + } + pList = g_list_next(pList); + } + g_list_free(pDirectoryList); + } + + delete pDirEnum; + delete pDir; + delete pPackageInfo; + + return errorType; +} + diff --git a/src/Manager/InstallerManager.h b/src/Manager/InstallerManager.h index 9076d65..d8c95c8 100755 --- a/src/Manager/InstallerManager.h +++ b/src/Manager/InstallerManager.h @@ -38,21 +38,14 @@ class InstallerManager { public: InstallerManager(void); - InstallerError Construct(const Tizen::Base::String& path, InstallerOperation op, RequesterType requesterType, bool hybridService = false); + InstallerError Construct(const Tizen::Base::String& path, InstallerOperation op, InstallerOption option); virtual ~InstallerManager(void); static InstallerManager* GetInstance(void); void Release(void); - int Request(const Tizen::Base::String& path, InstallerOperation op, RequesterType requesterType, bool hybridService = false); - int RequestRecursiveDirectory(const Tizen::Base::String& path, int& errorType); - bool RemoveGarbage(const Tizen::Base::String& filePath); - int RequestByCommand(int argc, char **argv); - int ReqeustByTest(void); - int RequestMove(const Tizen::App::PackageId& packageId, int moveType); - void PrintPackageInfo(const char* appId); void PrintResult(void); void PrintError(int errorType); @@ -66,6 +59,15 @@ public: void SetInstallerOperation(InstallerOperation op); InstallerOperation GetInstallerOperation(void) const; + Tizen::Base::String GetLogFilePath() const; + bool IsFileLogOn() const; + + static int Request(const Tizen::Base::String& path, InstallerOperation operation, InstallerOption option, Tizen::Base::String& packageId); + static int RequestRecursiveDirectory(const Tizen::Base::String& path, int& errorType); + static int RequestByCommand(int argc, char **argv); + static int ReqeustByTest(void); + static int RequestMove(const Tizen::App::PackageId& packageId, int moveType); + private: InstallerManager(const InstallerManager& value); InstallerManager& operator =(const InstallerManager& source); @@ -86,7 +88,7 @@ private: Installer* CreateInstaller(InstallerType installerType); InstallationContext* GetContext(void); - int ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output); + static int ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output); private: static InstallerManager* __pInstallerManager; @@ -99,6 +101,8 @@ private: long long __startTick; long long __endTick; + Tizen::Base::String __logFilePath; + bool __isFileLogOn; }; // InstallerManager diff --git a/src/Step/DrmStep.cpp b/src/Step/DrmStep.cpp index b71e3d5..c6c1fe9 100755 --- a/src/Step/DrmStep.cpp +++ b/src/Step/DrmStep.cpp @@ -36,10 +36,6 @@ InstallerError DrmStep::Run(InstallationContext* pContext) { InstallerError error = INSTALLER_ERROR_NONE; - AppLog("------------------------------------------"); - AppLog(" DrmStep - START"); - AppLog("------------------------------------------"); - __pContext = pContext; while (true) @@ -47,27 +43,22 @@ DrmStep::Run(InstallationContext* pContext) switch (__state) { case STATE_DRM_CHECKING: - AppLog("[STATE_DRM_CHECKING]"); error = OnDrmChecking(); break; case STATE_DRM_PURCHASE_REQUEST: - AppLog("[STATE_DRM_PURCHASE_REQUEST]"); error = OnPurchaseRequest(); break; case STATE_DRM_LICENSE_REQUEST: - AppLog("[STATE_DRM_LICENSE_REQUEST]"); error = OnLicenseRequest(); break; case STATE_DRM_LICENSE_RESPONSE: - AppLog("[STATE_DRM_LICENSE_RESPONSE]"); error = OnLicenseResponse(); break; case STATE_DRM_DECRYPT: - AppLog("[STATE_DRM_DECRYPT]"); error = OnDecryptPackage(); break; @@ -87,9 +78,6 @@ DrmStep::Run(InstallationContext* pContext) if (__state > STATE_DONE) { - AppLog("------------------------------------------"); - AppLog(" DrmStep - END"); - AppLog("------------------------------------------"); break; } } diff --git a/src/Step/LicenseStep.cpp b/src/Step/LicenseStep.cpp index 8c95e7a..822561d 100755 --- a/src/Step/LicenseStep.cpp +++ b/src/Step/LicenseStep.cpp @@ -36,9 +36,7 @@ InstallerError LicenseStep::Run(InstallationContext* pContext) { InstallerError error = INSTALLER_ERROR_NONE; - AppLog("------------------------------------------"); AppLog(" LicenseStep - START"); - AppLog("------------------------------------------"); __pContext = pContext; @@ -67,9 +65,7 @@ LicenseStep::Run(InstallationContext* pContext) if (__state > STATE_DONE) { - AppLog("------------------------------------------"); AppLog(" LicenseStep - END"); - AppLog("------------------------------------------"); break; } } diff --git a/src/Step/PackageCheckStep.cpp b/src/Step/PackageCheckStep.cpp index 8b97d92..839be4c 100755 --- a/src/Step/PackageCheckStep.cpp +++ b/src/Step/PackageCheckStep.cpp @@ -44,9 +44,7 @@ InstallerError PackageCheckStep::Run(InstallationContext* pContext) { InstallerError error = INSTALLER_ERROR_NONE; - AppLog("------------------------------------------"); AppLog(" PackageCheckStep - START"); - AppLog("------------------------------------------"); __pContext = pContext; @@ -75,9 +73,7 @@ PackageCheckStep::Run(InstallationContext* pContext) if (__state > STATE_DONE) { - AppLog("------------------------------------------"); AppLog(" PackageCheckStep - END"); - AppLog("------------------------------------------"); break; } } diff --git a/src/Step/SignatureStep.cpp b/src/Step/SignatureStep.cpp index e039900..82f1dd2 100755 --- a/src/Step/SignatureStep.cpp +++ b/src/Step/SignatureStep.cpp @@ -49,9 +49,7 @@ InstallerError SignatureStep::Run(InstallationContext* pContext) { InstallerError error = INSTALLER_ERROR_NONE; - AppLog("------------------------------------------"); AppLog(" SignatureStep - START"); - AppLog("------------------------------------------"); __pContext = pContext; @@ -96,9 +94,7 @@ SignatureStep::Run(InstallationContext* pContext) if (__state > STATE_DONE) { - AppLog("------------------------------------------"); AppLog(" SignatureStep - END"); - AppLog("------------------------------------------"); break; } } diff --git a/src/Step/SystemCheckStep.cpp b/src/Step/SystemCheckStep.cpp index 131fb5b..462d1f0 100755 --- a/src/Step/SystemCheckStep.cpp +++ b/src/Step/SystemCheckStep.cpp @@ -37,10 +37,6 @@ SystemCheckStep::Run(InstallationContext* pContext) { InstallerError error = INSTALLER_ERROR_NONE; - AppLog("------------------------------------------"); - AppLog(" SystemCheckStep - START"); - AppLog("------------------------------------------"); - __pContext = pContext; while (true) @@ -74,9 +70,6 @@ SystemCheckStep::Run(InstallationContext* pContext) if (__state > STATE_DONE) { - AppLog("------------------------------------------"); - AppLog(" SystemCheckStep - END"); - AppLog("------------------------------------------"); break; } } diff --git a/src/Step/UninstallStep.cpp b/src/Step/UninstallStep.cpp index d3b28e5..02bf14c 100755 --- a/src/Step/UninstallStep.cpp +++ b/src/Step/UninstallStep.cpp @@ -53,9 +53,7 @@ InstallerError UninstallStep::Run(InstallationContext* pContext) { InstallerError error = INSTALLER_ERROR_NONE; - AppLog("------------------------------------------"); AppLog(" UninstallStep - START"); - AppLog("------------------------------------------"); __pContext = pContext; @@ -104,9 +102,7 @@ UninstallStep::Run(InstallationContext* pContext) if (__state > STATE_DONE) { - AppLog("------------------------------------------"); AppLog(" UninstallStep - END"); - AppLog("------------------------------------------"); break; } } diff --git a/src/Step/UnpackStep.cpp b/src/Step/UnpackStep.cpp index 668c015..5e9564a 100755 --- a/src/Step/UnpackStep.cpp +++ b/src/Step/UnpackStep.cpp @@ -73,9 +73,7 @@ InstallerError UnpackStep::Run(InstallationContext* pContext) { InstallerError error = INSTALLER_ERROR_NONE; - AppLog("------------------------------------------"); AppLog(" UnpackStep - START"); - AppLog("------------------------------------------"); __pContext = pContext; @@ -119,9 +117,7 @@ UnpackStep::Run(InstallationContext* pContext) if (__state > STATE_DONE) { - AppLog("------------------------------------------"); AppLog(" UnpackStep - END"); - AppLog("------------------------------------------"); break; } } diff --git a/src/Util/InstallerUtil.cpp b/src/Util/InstallerUtil.cpp index 2ee798f..d473130 100755 --- a/src/Util/InstallerUtil.cpp +++ b/src/Util/InstallerUtil.cpp @@ -24,6 +24,7 @@ #include <errno.h> #include <unistd.h> #include <unique_ptr.h> +#include <drm-oem-intel.h> #include <FBaseErrorDefine.h> #include <FIoFile.h> @@ -32,8 +33,7 @@ #include "InstallerDefs.h" #include "InstallerUtil.h" - -#include <drm-oem-intel.h> +#include "InstallerManager.h" using namespace Tizen::Base; using namespace Tizen::Base::Collection; @@ -423,7 +423,7 @@ InstallerUtil::GetCategory(int categoryType) return category; } -CategoryType +int InstallerUtil::GetCategoryType(char* pCategory) { CategoryType category = CATEGORY_TYPE_NONE; @@ -450,7 +450,7 @@ InstallerUtil::CreateSymlinkForAppDirectory(const String& inPath, String& outPat String appId; int length = inPath.GetLength(); - inPath.SubString(length - APPID_LENGTH, APPID_LENGTH, appId); + inPath.SubString(length - PACKAGE_ID_LENGTH, PACKAGE_ID_LENGTH, appId); String newPath; newPath = PATH_OPT_APPS; @@ -601,4 +601,118 @@ InstallerUtil::LogChangeHexToStr(int hex) return ch; } +bool +InstallerUtil::CreateLog(const String& logFile) +{ + File file; + + result r = file.Construct(logFile, "w"); + if (IsFailed(r)) + { + return false; + } + + return true; +} + +bool +InstallerUtil::AppendLog(const char* pFunction, int lineNumber, bool fatal, const char* pFormat, ...) +{ + File file; + InstallerManager *pManager = InstallerManager::GetInstance(); + if (pManager == null) + { + return false; + } + + if (pManager->IsFileLogOn() == false) + { + return true; + } + + String logFile = pManager->GetLogFilePath(); + result r = file.Construct(logFile, "a"); + if (IsFailed(r)) + { + return false; + } + + va_list args; + va_start(args, pFormat); + const int bufSize = 1024; + char logs[bufSize+1] = {0}; + char logs2[bufSize+1] = {0}; + if (fatal == false) + { + snprintf(logs, bufSize, " | %s (%d). > %s", (char*)pFunction, lineNumber, pFormat); + } + else + { + snprintf(logs, bufSize, "[TRY]| %s (%d). > %s", (char*)pFunction, lineNumber, pFormat); + } + + vsnprintf(logs2, bufSize, logs, args); + int length = strlen(logs2); + logs2[length] = '\n'; + + r = file.Write(logs2, length+1); + if (IsFailed(r)) + { + return false; + } + va_end(args); + + return true; +} + +bool +InstallerUtil::PrintLog(const String& logFile) +{ + InstallerManager *pManager = InstallerManager::GetInstance(); + if (pManager == null) + { + return false; + } + + if (pManager->IsFileLogOn() == false) + { + return true; + } + + File file; + FileAttributes attribute; + + result r = File::GetAttributes(logFile, attribute); + if (IsFailed(r)) + { + return false; + } + + int bufSize = 4096; + std::unique_ptr<char[]> pBuf(new (std::nothrow) char[bufSize]); + if (pBuf == null) + { + return false; + } + + r = file.Construct(logFile, "r"); + if (IsFailed(r)) + { + return false; + } + + int readBytes = 0; + do + { + memset(pBuf.get(), 0, bufSize); + readBytes = file.Read(pBuf.get(), bufSize); + if (readBytes > 0) + { + fprintf(stderr, "%s", pBuf.get()); + } + } + while (readBytes > 0); + + return true; +} diff --git a/src/Util/InstallerUtil.h b/src/Util/InstallerUtil.h index 4fac08a..a5521a0 100755 --- a/src/Util/InstallerUtil.h +++ b/src/Util/InstallerUtil.h @@ -57,13 +57,17 @@ public: static bool DecryptPackage(const Tizen::Base::String& packagePath); static Tizen::Base::String GetCategory(int categoryType); - static CategoryType GetCategoryType(char* pCategory); + static int GetCategoryType(char* pCategory); static bool CreateSymlinkForAppDirectory(const Tizen::Base::String& inPath, Tizen::Base::String& outPath); static bool DumpLog(const char* pBuf); static bool DumpLogData(char *pData, int dataLen); + static bool CreateLog(const Tizen::Base::String& logFile); + static bool AppendLog(const char* pFunction, int lineNumber, bool fatal, const char* pFormat, ...); + static bool PrintLog(const Tizen::Base::String& logFile); + private: static char LogChangeHexToStr(int hex); InstallerUtil(const InstallerUtil& value); diff --git a/src/XmlHandler/ManifestHandler.cpp b/src/XmlHandler/ManifestHandler.cpp index 3f400bd..9f58b52 100755 --- a/src/XmlHandler/ManifestHandler.cpp +++ b/src/XmlHandler/ManifestHandler.cpp @@ -1300,6 +1300,7 @@ ManifestHandler::ParseAppAttribute(XmlAttribute* pAttr, bool isUiApp) { __isDefaultName = true; __isDefaultAppDetected = true; + __pContext->__mainAppName = pName; } } else @@ -1341,7 +1342,7 @@ ManifestHandler::ParseAppAttribute(XmlAttribute* pAttr, bool isUiApp) __pAppData->__pCategoryList->Add(new (std::nothrow) String(TIZEN_CATEGORY_IME)); } - CategoryType categoryType = InstallerUtil::GetCategoryType(pCategory); + int categoryType = InstallerUtil::GetCategoryType(pCategory); __pPackageAppInfoImpl->SetAppFeature(categoryType); } diff --git a/src/XmlHandler/PrivilegeHandler.cpp b/src/XmlHandler/PrivilegeHandler.cpp index a8b0438..b1940ea 100755 --- a/src/XmlHandler/PrivilegeHandler.cpp +++ b/src/XmlHandler/PrivilegeHandler.cpp @@ -32,6 +32,7 @@ #include "InstallerDefs.h" #include "PrivilegeHandler.h" +#include "InstallerUtil.h" using namespace Tizen::App; using namespace Tizen::Base; diff --git a/src/XmlHandler/SignatureHandler.cpp b/src/XmlHandler/SignatureHandler.cpp index d43cb14..725cd20 100755 --- a/src/XmlHandler/SignatureHandler.cpp +++ b/src/XmlHandler/SignatureHandler.cpp @@ -20,6 +20,7 @@ */ #include "SignatureHandler.h" +#include "InstallerUtil.h" using namespace Tizen::Base; using namespace Tizen::Base::Collection; diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp index 9fa264a..1ea57a0 100755 --- a/src/backend/backend.cpp +++ b/src/backend/backend.cpp @@ -34,9 +34,10 @@ #include "InstallerUtil.h" using namespace Tizen::Base; +using namespace Tizen::App; extern "C" void Osp_Initialize(); -static bool __osp_installer_report_result(const String& appId, int errorType); +static bool __osp_installer_report_result(const Tizen::App::PackageId& packageId, int errorType); static pkgmgr_installer *_pi = null; @@ -47,28 +48,39 @@ main(int argc, char **argv) const char *pkg_info = NULL; char* pkg_path = NULL; String path; - String appId; + PackageId packageId; int errorType = 0; - InstallerManager manager; pkgmgr_installer *pi = null; int req_type = 0; Osp_Initialize(); - AppLog("--\n\n\n"); - AppLog("=========================================="); - AppLog(" # %s", OSP_INSTALLER_VERSION); - AppLog(" # argc = %d", argc); + char buf[1024]; + memset(buf, 0, sizeof(buf)); + for (int i = 0; i < argc; i++) + { + strcat(buf, argv[i]); + if (i != argc - 1) + { + strcat(buf, " "); + } + } + + int emul = 0; + +#ifdef _OSP_EMUL_ + emul = 1; +#endif + fprintf(stderr, " ## osp-installer: %s[%s] cmd=[%s]\n", OSP_INSTALLER_VERSION, emul?"Emulator":"Target", buf); if (argc == TEST_ARG_COUNT) { - errorType = manager.ReqeustByTest(); - manager.PrintResult(); + errorType = InstallerManager::ReqeustByTest(); goto CATCH; } else if (argc == COMMAND_ARG_COUNT) { - errorType = manager.RequestByCommand(argc, argv); + errorType = InstallerManager::RequestByCommand(argc, argv); goto CATCH; } @@ -93,12 +105,11 @@ main(int argc, char **argv) { case PKGMGR_REQ_INSTALL: { - errorType = manager.Request(path, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL); - appId = manager.GetId(); + errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, packageId); if (_pi != 0) { char resultBuf[128] = {0}; - snprintf(resultBuf, sizeof(resultBuf), "%ls", appId.GetPointer()); + snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer()); pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "start", "install"); } else @@ -111,33 +122,23 @@ main(int argc, char **argv) // manager.RemoveGarbage(path); // } - __osp_installer_report_result(appId, errorType); - manager.PrintResult(); + __osp_installer_report_result(packageId, errorType); } break; case PKGMGR_REQ_UNINSTALL: { - String requestAppId; + PackageId reqeustPackageId; - if (path.Contains(PACKAGE_NAME_PREFIX_ORG) == true) - { - String prefixPackage(PACKAGE_NAME_PREFIX_ORG); - path.SubString(prefixPackage.GetLength(), APPID_LENGTH, requestAppId); - } - else - { - path.SubString(0, APPID_LENGTH, requestAppId); - } + path.SubString(0, PACKAGE_ID_LENGTH, reqeustPackageId); - AppLog("requestAppId = %ls", requestAppId.GetPointer()); - ret = manager.Request(requestAppId, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL); - appId = manager.GetId(); + AppLog("reqeustPackageId = %ls", reqeustPackageId.GetPointer()); + ret = InstallerManager::Request(reqeustPackageId, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, packageId); if (_pi != 0) { char resultBuf[128] = {0}; - snprintf(resultBuf, sizeof(resultBuf), "%ls", appId.GetPointer()); + snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer()); pkgmgr_installer_send_signal(_pi, "tpk", resultBuf, "start", "uninstall"); } else @@ -145,8 +146,7 @@ main(int argc, char **argv) AppLog("_pi is null"); } - __osp_installer_report_result(appId, errorType); - manager.PrintResult(); + __osp_installer_report_result(packageId, errorType); } break; @@ -157,13 +157,12 @@ main(int argc, char **argv) int moveType = -1; moveType = pkgmgr_installer_get_move_type(_pi); - manager.RequestMove(path, moveType); + InstallerManager::RequestMove(path, moveType); } else { AppLog("_pi is null"); } - } break; @@ -178,6 +177,7 @@ main(int argc, char **argv) } CATCH: + return errorType; } @@ -191,6 +191,10 @@ __osp_installer_send_error(int errorType) { error = INSTALLER_ERROR_FATAL_ERROR; } + else + { + error = errorType; + } snprintf(errorMsg, sizeof(errorMsg) - 1, "%d", error); pkgmgr_installer_send_signal(_pi, "tpk", "", "error", errorMsg); @@ -199,7 +203,7 @@ __osp_installer_send_error(int errorType) } bool -__osp_installer_report_result(const String& appId, int errorType) +__osp_installer_report_result(const PackageId& packageId, int errorType) { int ret = 0; char resultBuf[128] = {0}; @@ -223,24 +227,19 @@ __osp_installer_report_result(const String& appId, int errorType) if (errorType == 0) { - if (appId.IsEmpty() == true) - { - snprintf(resultBuf, sizeof(resultBuf), "0000000000"); - } - else - { - snprintf(resultBuf, sizeof(resultBuf), "%ls", appId.GetPointer()); - } - pValue = "ok"; } else { - snprintf(resultBuf, sizeof(resultBuf), "0000000000"); pValue = "fail"; __osp_installer_send_error(errorType); } + if (packageId.IsEmpty() == false) + { + snprintf(resultBuf, sizeof(resultBuf), "%ls", packageId.GetPointer()); + } + ret = pkgmgr_installer_send_signal(_pi, pPkgType, resultBuf, pKey, pValue); AppLog("------------------------------------------"); AppLog("pkgmgr_installer_send_signal"); |