From a2d1258815409e636a37d8b8eafbefa16b5ed2d5 Mon Sep 17 00:00:00 2001 From: Chandrakant Upadhyay Date: Mon, 12 May 2014 16:50:13 +0530 Subject: [PATCH] Osp-Installer merge changes from tizen_2.2 Change-Id: Ic21c74d20f2e460ebae43e596a10552ea92bd15a Signed-off-by: Chandrakant Upadhyay --- CMakeLists.txt | 1 + inc/InstallerDefs.h | 14 +- src/Context/InstallationContext.cpp | 1 + src/Context/InstallationContext.h | 1 + src/Installer/DirectoryInstaller.cpp | 12 +- src/Installer/HybridInstaller.cpp | 1357 ++++++++++++++++++++++++++++++++++ src/Installer/HybridInstaller.h | 89 +++ src/Installer/PreloadedInstaller.cpp | 2 +- src/Manager/CompatibilityManager.cpp | 137 ++-- src/Manager/ConfigurationManager.cpp | 144 ++-- src/Manager/ConfigurationManager.h | 9 +- src/Manager/InstallerManager.cpp | 346 ++++++--- src/Manager/InstallerManager.h | 7 +- src/Manager/PermissionManager.cpp | 2 + src/Manager/SignatureManager.cpp | 32 +- src/Manager/SmackManager.cpp | 26 +- src/Manager/SmackManager.h | 3 + src/Step/SystemCheckStep.cpp | 21 + src/Step/UninstallStep.cpp | 37 +- src/Step/UnpackStep.cpp | 2 + src/Util/InstallerUtil.cpp | 110 ++- src/Util/InstallerUtil.h | 6 +- src/backend/backend.cpp | 99 ++- 23 files changed, 2144 insertions(+), 314 deletions(-) create mode 100755 src/Installer/HybridInstaller.cpp create mode 100644 src/Installer/HybridInstaller.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b37b33a..8f37268 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ SET (${this_target}_SOURCE_FILES src/Installer/PackageInstaller.cpp src/Installer/PreloadedInstaller.cpp src/Installer/RestorationInstaller.cpp + src/Installer/HybridInstaller.cpp src/Manager/CompatibilityManager.cpp src/Manager/ConfigurationManager.cpp src/Manager/DatabaseManager.cpp diff --git a/inc/InstallerDefs.h b/inc/InstallerDefs.h index 7a42b8e..e45f94c 100755 --- a/inc/InstallerDefs.h +++ b/inc/InstallerDefs.h @@ -23,7 +23,7 @@ #include "InstallerUtil.h" -#define OSP_INSTALLER_VERSION "version=[20130828.2]" +#define OSP_INSTALLER_VERSION "version=[20131029.2]" #define DIR_BIN L"/bin" #define DIR_INFO L"/info" @@ -79,6 +79,7 @@ #define UIAPP_LOADER_PATH "/usr/lib/osp/osp-ui-app-loader" // UiApp #define SERVICEAPP_LOADER_PATH "/usr/lib/osp/osp-service-app-loader" // ServiceApp #define SYSTEMSERIVCE_LOADER_PATH "/usr/lib/osp/osp-system-service-loader" // System Service +#define EXEC_LOADER_PATH "/usr/lib/osp/osp-exec-loader" // Exec #define IME_PATH "/opt/apps/scim/lib/scim-1.0/1.4.0/Helper" #define SUB_MODE_APPCONTROL_NAME L"_AppControl" @@ -102,6 +103,8 @@ #define DIR_MEMORYCARD_OSP_APPLICATIONS L"/opt/storage/sdcard/apps" #define DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP L"/opt/storage/sdcard/apps/__@@osp_tmp@@__" +#define DIR_RECOVERY_TPK L"/opt/share/packages/.recovery/tpk" + #define PERM_BASE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) // 0644 #define PERM_EXECUTE (S_IXUSR | S_IXGRP | S_IXOTH) #define PERM_WRITE (S_IWUSR | S_IWGRP | S_IWOTH) @@ -128,6 +131,7 @@ #define METADATA_SPLASH_PORTRAIT L"http://developer.samsung.com/tizen/metadata/splash/portrait" #define METADATA_SPLASH_LANDSCAPE L"http://developer.samsung.com/tizen/metadata/splash/landscape" #define METADATA_DISABLE_SCREEN_READER L"http://developer.samsung.com/tizen/metadata/disablescreenreader" +#define METADATA_COMPATIBLE_MEMORY_LAYOUT L"http://developer.samsung.com/tizen/metadata/compatible_memory_layout" #define DIR_APPLICATIONS_TMP "/opt/usr/apps/tmp" @@ -309,6 +313,7 @@ enum INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL = 3, INSTALLER_MODE_REINSTALL = 4, INSTALLER_MODE_PARSE_CSC_STRING = 5, + INSTALLER_MODE_RECOVERY = 6, }; enum CategoryType @@ -370,4 +375,11 @@ enum PrivilegeLevel }; +enum ApiVisibility +{ + API_VISIBILITY_PUBLIC = 1, + API_VISIBILITY_PARTNER, + API_VISIBILITY_PLATFORM, + +}; #endif // _INSTALLER_DEFS_H_ diff --git a/src/Context/InstallationContext.cpp b/src/Context/InstallationContext.cpp index 1066c8f..dbbc8d6 100755 --- a/src/Context/InstallationContext.cpp +++ b/src/Context/InstallationContext.cpp @@ -58,6 +58,7 @@ InstallationContext::InstallationContext(void) ,__storage(INSTALLATION_STORAGE_NONE) ,__rootCertType(ROOT_CERTIFICATE_NONE) ,__privilegeLevel(PRIVILEGE_LEVEL_PUBLIC) +,__apiVisibility(_API_VISIBILITY_NONE) ,__pApp2ExtHandle(null) ,__pPrivilegeList(null) ,__pStringPrivilegeList(null) diff --git a/src/Context/InstallationContext.h b/src/Context/InstallationContext.h index 810b789..fb73f73 100755 --- a/src/Context/InstallationContext.h +++ b/src/Context/InstallationContext.h @@ -108,6 +108,7 @@ public: RootCertificateType __rootCertType; int __privilegeLevel; int __packageNameType; + int __apiVisibility; void* __pApp2ExtHandle; Tizen::Base::Collection::ArrayList* __pPrivilegeList; diff --git a/src/Installer/DirectoryInstaller.cpp b/src/Installer/DirectoryInstaller.cpp index 0a13956..b732e8e 100755 --- a/src/Installer/DirectoryInstaller.cpp +++ b/src/Installer/DirectoryInstaller.cpp @@ -72,16 +72,8 @@ DirectoryInstaller::OnInit(void) { InstallationContext* pContext = GetContext(); - if (pContext->__isHybridService == true) - { - AppLog("[VerifySignature] VerificationMode OFF"); - pContext->__isVerificationMode = false; - } - else - { - TryReturn(File::IsFileExist(pContext->GetAuthorSignatureXmlPath()) == true, INSTALLER_ERROR_PACKAGE_INVALID, "no author-signature.xml"); - TryReturn(File::IsFileExist(pContext->GetSignatureXmlPath()) == true, INSTALLER_ERROR_PACKAGE_INVALID, "no signature1.xml"); - } + TryReturn(File::IsFileExist(pContext->GetAuthorSignatureXmlPath()) == true, INSTALLER_ERROR_PACKAGE_INVALID, "no author-signature.xml"); + TryReturn(File::IsFileExist(pContext->GetSignatureXmlPath()) == true, INSTALLER_ERROR_PACKAGE_INVALID, "no signature1.xml"); String installPath = pContext->__installDir; diff --git a/src/Installer/HybridInstaller.cpp b/src/Installer/HybridInstaller.cpp new file mode 100755 index 0000000..f00b409 --- /dev/null +++ b/src/Installer/HybridInstaller.cpp @@ -0,0 +1,1357 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file HybridInstaller.cpp + * @brief This is the implementation file for %HybridInstaller class. + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "InstallerDefs.h" +#include "InstallerManager.h" +#include "HybridInstaller.h" +#include "InstallerUtil.h" + +#include "SystemCheckStep.h" +#include "ManifestXmlStep.h" +#include "UninstallStep.h" + +#include "DatabaseManager.h" +#include "SignatureManager.h" +#include "PermissionManager.h" +#include "SmackManager.h" +#include "CompatibilityManager.h" + +#include "ManifestGenerator.h" + +using namespace std; + +using namespace Tizen::Base; +using namespace Tizen::Io; +using namespace Tizen::App; +using namespace Tizen::App::Package; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; + + + +HybridInstaller::HybridInstaller(void) +:__pInstallationContext(null) +{ + + +} + +HybridInstaller::~HybridInstaller(void) +{ + delete __pInstallationContext; + __pInstallationContext = null; +} + +InstallationStep +HybridInstaller::GetNext(InstallationStep step) +{ + return DirectoryInstaller::GetNext(step); +} + +InstallerError +HybridInstaller::OnInit(void) +{ + bool res = true; + InstallerError error = INSTALLER_ERROR_NONE; + InstallerOperation operation = __pInstallationContext->GetInstallerOperation(); + + if (operation == INSTALLER_OPERATION_INSTALL) + { + if (__pInstallationContext->__isPreloaded) + { + String path = __pInstallationContext->__inputPath; + AppLog(" The Path is %ls", path.GetPointer()); + + String appId; + String prefix(PATH_USR_APPS); + prefix += L"/"; + + path.SubString(prefix.GetLength(), PACKAGE_ID_LENGTH, appId); + + + String versionFile = path + VERSION_INFO_FILE; + if (File::IsFileExist(versionFile) == true) + { + AppLog("install preloaded app again."); + __pInstallationContext->__isUpdated = true; + } + + String destRootPath(PATH_OPT_USR_APPS); + destRootPath += L"/"; + destRootPath += appId; + + Directory::Create(destRootPath); + + String srcPath; + String destPath; + + + srcPath = path + DIR_SETTING; + destPath = destRootPath + DIR_SETTING; + InstallerUtil::CopyDirectory(srcPath, destPath); + + + srcPath = path + DIR_DATA; + destPath = destRootPath + DIR_DATA; + InstallerUtil::CopyDirectory(srcPath, destPath); + + srcPath = path + DIR_INFO; + destPath = destRootPath + DIR_INFO; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_BIN; + destPath = destRootPath + DIR_BIN; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_RES; + destPath = destRootPath + DIR_RES; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_LIB; + destPath = destRootPath + DIR_LIB; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + DIR_SHARED; + destPath = destRootPath + DIR_SHARED; + if (File::IsFileExist(srcPath) == true) + { + InstallerUtil::CopyDirectory(srcPath, destPath); + } + else + { + Directory::Create(destPath); + } + + srcPath += DIR_RES; + destPath += DIR_RES; + if (File::IsFileExist(destPath) == false) + { + srcPath = path + DIR_ICONS; + InstallerUtil::CreateSymlink(srcPath, destPath); + } + + __pInstallationContext->__installDir = __pInstallationContext->__inputPath; + if ((File::IsFileExist(__pInstallationContext->GetSignatureXmlPath()) == true) && + (File::IsFileExist(__pInstallationContext->GetAuthorSignatureXmlPath()) == true)) + { + srcPath = path + SIGNATURE1_XML_FILE; + destPath = destRootPath + SIGNATURE1_XML_FILE; + InstallerUtil::CreateSymlink(srcPath, destPath); + + srcPath = path + AUTHOR_SIGNATURE_XML_FILE; + destPath = destRootPath + AUTHOR_SIGNATURE_XML_FILE; + InstallerUtil::CreateSymlink(srcPath, destPath); + } + + __pInstallationContext->__installDir = destRootPath; + } + DirectoryInstaller::OnInit(); + + unique_ptr pManifestInstalltionStep(new (std::nothrow) ManifestXmlStep); + TryReturn(pManifestInstalltionStep, INSTALLER_ERROR_OUT_OF_MEMORY, "[INSTALLER_ERROR_OUT_OF_MEMORY] The memory is insufficient..."); + + error = pManifestInstalltionStep.get()->Run(__pInstallationContext); + + if (error != INSTALLER_ERROR_NONE) + { + __pInstallationContext->SetError(error); + OnError(); + return error; + } + + unique_ptr pSystemCheckupInstalltionStep(new (std::nothrow) SystemCheckStep); + TryReturn(pSystemCheckupInstalltionStep, INSTALLER_ERROR_OUT_OF_MEMORY, "[INSTALLER_ERROR_OUT_OF_MEMORY] The memory is insufficient..."); + + error = pSystemCheckupInstalltionStep.get()->Run(__pInstallationContext); + + if (error != INSTALLER_ERROR_NONE) + { + __pInstallationContext->SetError(error); + OnError(); + return error; + } + } + else if (operation == INSTALLER_OPERATION_UNINSTALL) + { + String rwXmlPath; + PackageId packageId = __pInstallationContext->__packageId; + rwXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, packageId.GetPointer()); + if (File::IsFileExist(rwXmlPath) == false) + { + AppLog("This is a preload app = [%ls]", rwXmlPath.GetPointer()); + __pInstallationContext->__isPreloaded = true; + } + + InstallerUtil::TerminateApps(__pInstallationContext->__packageId, true); + + CompatibilityManager compatibilityManager; + compatibilityManager.Construct(__pInstallationContext); + + String rootPath; + rootPath = __pInstallationContext->__rootPath; + AppLog("rootPath = [%ls]", rootPath.GetPointer()); + + String compatPath(rootPath); + compatPath.Append(L"/info/compat.info"); + bool ospCompat = File::IsFileExist(compatPath); + result r = GetLastResult(); + + if (r == E_SUCCESS && ospCompat == true) + { + if (compatibilityManager.FinalizeDataCaging(rootPath) == false) + { + AppLog("[Tizen::Io] Failed to unmount directories for 2.0 application, appRootPath: %ls", + rootPath.GetPointer()); + return INSTALLER_ERROR_UNMOUNT_FAILED; + } + } + else if (r != E_SUCCESS) + { + AppLog("[Tizen::Io] Failed to access %ls", compatPath.GetPointer()); + return INSTALLER_ERROR_UNMOUNT_FAILED; + } + + res = compatibilityManager.CleanDirectories(rootPath, __pInstallationContext->__packageId); + TryReturn(res == true, INSTALLER_ERROR_FATAL_ERROR, "compatibilityManager.CleanDirectories Failed()"); + + String virtualRootInfoFile = rootPath + VIRTUAL_ROOT_INFO_FILE; + if (File::IsFileExist(virtualRootInfoFile) == true) + { + res = compatibilityManager.FinalizeVirtualRoot(rootPath, __pInstallationContext->__packageId); + TryReturn(res == true, INSTALLER_ERROR_UNMOUNT_FAILED, "compatibilityManager.FinalizeVirtualRoot(%ls) failed.", rootPath.GetPointer()); + } + + AppLog("Directory::Remove - START"); + + IListT* pAppDataList = __pInstallationContext->__pAppDataList; + TryReturn(pAppDataList, INSTALLER_ERROR_INTERNAL_STATE, "pAppDataList is null"); + + int count = pAppDataList->GetCount(); + for (int i = 0; i < count; i++) + { + AppData* pAppData = null; + pAppDataList->GetAt(i, pAppData); + + if (pAppData) + { + if (pAppData->__feature == CATEGORY_TYPE_IME) + { + String symlinkPath; + symlinkPath.Format(1024, L"%s/%ls.so", IME_PATH, pAppData->__appId.GetPointer()); + InstallerUtil::Remove(symlinkPath); + } + } + } + + AppLog("Directory::Remove - END"); + return error; + } + + return error; +} + +InstallerError +HybridInstaller::OnRegister(void) +{ + InstallerOperation operation = __pInstallationContext->GetInstallerOperation(); + DatabaseManager databaseManager; + bool res = true; + + if (operation == INSTALLER_OPERATION_INSTALL) + { + res = databaseManager.UnregisterPackageInfo(__pInstallationContext->__packageId); + TryReturn(res, INSTALLER_ERROR_DATABASE, "CreateFile() failed."); + + res = databaseManager.RegisterPackageInfo(__pInstallationContext); + TryReturn(res, INSTALLER_ERROR_DATABASE, "CreateFile() failed."); + } + else if (operation == INSTALLER_OPERATION_UNINSTALL) + { + res = databaseManager.UnregisterPackageInfo(__pInstallationContext->__packageId); + TryReturn(res, INSTALLER_ERROR_DATABASE, "CreateFile() failed."); + } + + return INSTALLER_ERROR_NONE; +} + +InstallerError +HybridInstaller::OnEnd(void) +{ + AppLog("Hybrid::OnEnd() - START"); + + bool res = true; + SmackManager smackManager; + smackManager.Construct(__pInstallationContext); + + InstallerOperation operation = __pInstallationContext->GetInstallerOperation(); + + SignatureManager sigManager; + sigManager.Construct(__pInstallationContext); + + if (operation == INSTALLER_OPERATION_INSTALL) + { + res = smackManager.Install(__pInstallationContext->__packageId); + TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "smackManager.Install(%ls) failed.", __pInstallationContext->__packageId.GetPointer()); + + res = CreateFile(); + TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "CreateFile() failed."); + + res = PermissionManager::SetDirectory(__pInstallationContext); + TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "SetDirectory() failed."); + + res = PermissionManager::SetFile(__pInstallationContext); + TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "SetFile() failed."); + + res = PostInstall(false); + TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "PostInstall() failed."); + } + else if (operation == INSTALLER_OPERATION_UNINSTALL) + { + res = RemoveFile(); + TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "RemoveFile() failed."); + + res = PostUninstall(); + TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "PostUninstall() failed."); + + res = smackManager.Uninstall(__pInstallationContext->__packageId); + AppLog("smackManager.Uninstall(%ls) res = [%d]", __pInstallationContext->__packageId.GetPointer(), res); + } + + AppLog("Hybrid::OnEnd() - END"); + AppLog("------------------------------------------"); + + return INSTALLER_ERROR_NONE; +} + +InstallerError +HybridInstaller::OnError(void) +{ + AppLog("HybridInstaller::OnError()"); + return DirectoryInstaller::OnError(); +} + +InstallerError +HybridInstaller::OnRollback(void) +{ + AppLog("HybridInstaller::OnRollback()"); + return DirectoryInstaller::OnRollback(); +} + +InstallerError +HybridInstaller::OnUserCancel(void) +{ + AppLog("HybridInstaller::OnUserCancel()"); + return DirectoryInstaller::OnUserCancel(); +} + +InstallerError +HybridInstaller::RequestHybridAppInstallation(int hybridOperation, char* pkgPath, int apiVisibility) +{ + result res = E_SUCCESS; + InstallerError errorType = INSTALLER_ERROR_NONE; + InstallerManager* pInstallManager = null; + InstallerType installerType = INSTALLER_TYPE_INSTALLER; + String hybridPackagePath = pkgPath; + PackageId hybridPackageId = ""; + FileAttributes attr; + + pInstallManager = InstallerManager::GetInstance(); + TryReturn(pInstallManager, INSTALLER_ERROR_OUT_OF_MEMORY, "[INSTALLER_ERROR_OUT_OF_MEMORY] The memory is insufficient.."); + + __pInstallationContext = new (std::nothrow) InstallationContext; + TryReturn(__pInstallationContext, INSTALLER_ERROR_OUT_OF_MEMORY, "[INSTALLER_ERROR_OUT_OF_MEMORY] The memory is insufficient.."); + + errorType = __pInstallationContext->Construct(); + TryReturn(errorType == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "Failed to Construct the Installation Context."); + + __pInstallationContext->__isHybridService = true; + __pInstallationContext->__certType = apiVisibility; + __pInstallationContext->__privilegeLevel= InstallerUtil::GetPrivilegeLevel(apiVisibility); + + switch (hybridOperation) + { + case 'i': + { + AppLog(" HybridApplication Installation starts"); + + res = File::GetAttributes(hybridPackagePath, attr); + if (IsFailed(res)) + { + AppLog("GetAttributes() failed. [%ls]", hybridPackagePath.GetPointer()); + errorType = INSTALLER_ERROR_FATAL_ERROR; + return errorType; + } + + if (attr.IsDirectory()) + { + installerType = INSTALLER_TYPE_DIRECTORY; + if (hybridPackagePath.EndsWith("/") == true) + { + int length = hybridPackagePath.GetLength(); + hybridPackagePath.Remove(length - 1, 1); + } + + if (hybridPackagePath.StartsWith(PATH_USR_APPS, 0) == true) + { + AppLog(" Preloaded HybridApp Installtion"); + installerType = INSTALLER_TYPE_PRELOADED; + __pInstallationContext->__isPreloaded = true; + } + hybridPackagePath.SubString(hybridPackagePath.GetLength() - PACKAGE_ID_LENGTH, PACKAGE_ID_LENGTH, hybridPackageId); + } + else + { + errorType = INSTALLER_ERROR_FATAL_ERROR; + return errorType; + } + + AppLog(" Hybrid PackagePath is [%ls] ", hybridPackagePath.GetPointer()); + pInstallManager->SetInstallerOperation(INSTALLER_OPERATION_INSTALL); + + __pInstallationContext->__packageId = hybridPackageId; + __pInstallationContext->__inputPath = hybridPackagePath; + __pInstallationContext->__installDir = hybridPackagePath; + __pInstallationContext->__packageSize = InstallerUtil::GetDisplaySize(hybridPackagePath); + __pInstallationContext->__apiVisibility = apiVisibility; + __pInstallationContext->__isVerificationMode = false; + __pInstallationContext->SetInstallerOperation(INSTALLER_OPERATION_INSTALL); + + errorType = Installer::Construct(__pInstallationContext); + TryReturn(errorType == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "Failed to construct the Installer"); + + errorType = OnInit(); + TryReturn(errorType == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "Hybrid Installer OnInit() failed"); + + errorType = OnRegister(); + TryReturn(errorType == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "Hybrid Installer OnRegister() failed"); + + errorType = OnEnd(); + TryReturn(errorType == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "Hybrid Installer OnEnd() failed"); + } + break; + case 'u': + { + pInstallManager->SetInstallerOperation(INSTALLER_OPERATION_UNINSTALL); + __pInstallationContext->SetInstallerOperation(INSTALLER_OPERATION_UNINSTALL); + __pInstallationContext->__packageId = hybridPackagePath; + + errorType = Installer::Construct(__pInstallationContext); + TryReturn(errorType == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "Failed to construct the Installer"); + + errorType = OnInit(); + TryReturn(errorType == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "Hybrid Installer OnInit() failed"); + + errorType = OnRegister(); + TryReturn(errorType == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "Hybrid Installer OnRegister() failed"); + + errorType = OnEnd(); + TryReturn(errorType == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "Hybrid Installer OnEnd() failed"); + + } + break; + } + return errorType; +} + +bool +HybridInstaller::RemoveInfoFiles(void) +{ + Directory* pDir = null; + DirEnumerator* pDirEnum = null; + result r = E_SUCCESS; + int res = false; + String path; + + path = __pInstallationContext->__rootPath + DIR_INFO; + + 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; + } + + // check *.info file + if ((_FileImpl::GetFileExtension(entryDir) == FILE_EXT_INFO) || + (entry.IsDirectory() == true)) + { + AppLog("Request to delete info file = [%ls]", entryDir.GetPointer()); + InstallerUtil::Remove(entryDir); + } + } + + delete pDirEnum; + delete pDir; + return true; + +CATCH: + // delete pDirEnum; + delete pDir; + return false; +} + +bool +HybridInstaller::CreateFile() +{ + int err = 0; + String rootPath; + String apiVersion; + rootPath = __pInstallationContext->__rootPath; + apiVersion = __pInstallationContext->__apiVersion; + + String versionInfoFile; + versionInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), VERSION_INFO_FILE); + InstallerUtil::CreateInfoFile(versionInfoFile, &apiVersion); + + String webServicePrivilege(TIZEN_PRIVILEGE_WEB_SERVICE); + if (FindPrivilege(__pInstallationContext, webServicePrivilege) == true) + { + AppLog("WEB_SERVICE privilege is detected. rootPath=[%ls]", rootPath.GetPointer()); + + String webServiceInfoFile; + webServiceInfoFile.Format(1024, L"%ls%ls", rootPath.GetPointer(), WEBSERVICE_INFO_FILE); + InstallerUtil::CreateInfoFile(webServiceInfoFile, null); + } + + IListT* pAppDataList = __pInstallationContext->__pAppDataList; + TryReturn(pAppDataList, false, "pAppDataList is null"); + + for (int i = 0 ; i < pAppDataList->GetCount(); i++) + { + AppData* pAppData = null; + pAppDataList->GetAt(i, pAppData); + TryReturn(pAppData, false, "pAppData is null"); + + String appName = pAppData->__name; + String appType = pAppData->__type; + AppId appId = pAppData->__appId; + + String binaryPath; + binaryPath.Format(1024, L"%ls%ls/%ls", rootPath.GetPointer(), DIR_BIN, appName.GetPointer()); + + if (File::IsFileExist(binaryPath) == true) + { + InstallerUtil::Remove(binaryPath); + } + + CreateAppInfoFile(pAppData, rootPath); + + if (appType == L"UiApp") + { + AppLog("It's not available(UiApp) in HybridApp."); + return false; + } + else if (appType == L"ServiceApp") + { + if ((__pInstallationContext->__isPreloaded == true) && (pAppData->__isSystemService == true)) + { + AppLog("copy system service loader"); + InstallerUtil::Copy(SYSTEMSERIVCE_LOADER_PATH, binaryPath); + } + else + { + AppLog("copy service app loader"); + InstallerUtil::Copy(SERVICEAPP_LOADER_PATH, binaryPath); + } + } + + InstallerUtil::ChangeMode(binaryPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + ArrayList* pContentDataList = __pInstallationContext->GetContentDataList(); + if (pContentDataList) + { + int contentCount = pContentDataList->GetCount(); + for (int i = 0 ; i < contentCount; i++) + { + ContentData* pContentData = static_cast(pContentDataList->GetAt(i)); + if (pContentData) + { + String contentId = pContentData->GetContentId(); + String oldPath = rootPath + DIR_CONTENTS + L"/" + contentId; + + if (File::IsFileExist(SLP_FONT_PATH) == false) + { + Directory::Create(SLP_FONT_PATH, false); + InstallerUtil::ChangeMode(SLP_FONT_PATH, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + String newPath = SLP_FONT_PATH; + newPath += L"/" + __pInstallationContext->__packageId; + Directory::Create(newPath, false); + InstallerUtil::ChangeMode(newPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + + newPath += L"/"; + newPath += contentId; + InstallerUtil::CreateSymlink(oldPath, newPath); + } + } + } + + String roXmlPath; + roXmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, __pInstallationContext->__packageId.GetPointer()); + + String rwXmlPath; + rwXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, __pInstallationContext->__packageId.GetPointer()); + + if (__pInstallationContext->__isPreloaded == true) + { + __pInstallationContext->__coreXmlPath = roXmlPath; + } + else + { + __pInstallationContext->__coreXmlPath = rwXmlPath; + } + + std::unique_ptr pXmlPath(_StringConverter::CopyToCharArrayN(__pInstallationContext->__coreXmlPath)); + TryReturn(pXmlPath != null, false, "pXmlPath is null"); + + String webXmlPath = pXmlPath.get(); + webXmlPath += L".wgt"; + InstallerUtil::Copy(pXmlPath.get(), webXmlPath); + + CreateCoreXmlFile(__pInstallationContext); + + String serviceXmlPath = pXmlPath.get(); + serviceXmlPath += L".tpk"; + InstallerUtil::Copy(pXmlPath.get(), serviceXmlPath); + InstallerUtil::Remove(pXmlPath.get()); + + MergeToSystemXmlFile(pXmlPath.get(), webXmlPath, serviceXmlPath); + InstallerUtil::Remove(webXmlPath); + InstallerUtil::Remove(serviceXmlPath); + + AppLog("------------------------------------------"); + AppLog("sync() - START"); + sync(); + AppLog("sync() - END"); + AppLog("------------------------------------------"); + + err = pkgmgr_parser_check_manifest_validation(pXmlPath.get()); + TryReturn(err == 0, false, "pkgmgr_parser_check_manifest_validation() is failed. error = [%d][%s]", err, pXmlPath.get()); + + return true; +} + +bool +HybridInstaller::RemoveFile() +{ + if (__pInstallationContext->__isPreloaded == true) + { + __pInstallationContext->__coreXmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, __pInstallationContext->__packageId.GetPointer()); + } + else + { + __pInstallationContext->__coreXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, __pInstallationContext->__packageId.GetPointer()); + } + + std::unique_ptr pXmlPath(_StringConverter::CopyToCharArrayN(__pInstallationContext->__coreXmlPath)); + TryReturn(pXmlPath != null, false, "pXmlPath is null"); + + return true; +} + +bool +HybridInstaller::PostInstall(bool error) const +{ + bool res = true; + PackageId packageId = __pInstallationContext->__packageId; + std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(packageId)); + TryReturn(pPackageId, false, "pPackageId is null."); + + if (error == false) + { + SmackManager smackManager; + smackManager.Construct(__pInstallationContext); + smackManager.EnablePermissions(packageId); + + res = RegisterCoreXmlFile(__pInstallationContext); + TryReturn(res, false, "RegisterCoreXmlFile() failed."); + +#if 0 + if ((__pInstallationContext->__isUpdated == true) && (__pInstallationContext->__isPreloaded == false)) + { + CopyData(__pInstallationContext); + RemoveBackup(__pInstallationContext); + } +#endif + } + else + { +#if 0 + if ((__pInstallationContext->__isUpdated == true) && (__pInstallationContext->__isPreloaded == false)) + { + RestoreBackup(__pInstallationContext); + } +#endif + } + + app2ext_handle* pHandle = (app2ext_handle*)__pInstallationContext->__pApp2ExtHandle; + if (pHandle) + { + if (error == true) + { + pHandle->interface.post_install(pPackageId.get(), APP2EXT_STATUS_FAILED); + AppLog("[app2sd] post_install(%s, APP2EXT_STATUS_FAILED)", pPackageId.get()); + } + else + { + pHandle->interface.post_install(pPackageId.get(), APP2EXT_STATUS_SUCCESS); + AppLog("[app2sd] post_install(%s, APP2EXT_STATUS_SUCCESS)", pPackageId.get()); + } + + app2ext_deinit(pHandle); + } + + return true; +} + +bool +HybridInstaller::PostUninstall() const +{ + app2ext_handle* pHandle = (app2ext_handle*)__pInstallationContext->__pApp2ExtHandle; + + PackageId packageId = __pInstallationContext->__packageId; + std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(packageId)); + TryReturn(pPackageId, false, "pPackageId is null."); + + if (pHandle) + { + pHandle->interface.post_uninstall(pPackageId.get()); + AppLog("[app2sd] post_uninstall(%s)", pPackageId.get()); + + app2ext_deinit(pHandle); + } + + SmackManager smackManager; + smackManager.Construct(__pInstallationContext); + smackManager.RevokePermissions(packageId); + + return true; +} + + + +bool +HybridInstaller::CreateCoreXmlFile(InstallationContext* __pInstallationContext) const +{ + AppLog("------------------------------------------"); + AppLog("CreateCoreXmlFile() - START"); + bool ret = false; + + ManifestGenerator manifestGenerator; + manifestGenerator.Construct(__pInstallationContext); + ret = manifestGenerator.Write(); + + if (ret == false) + { + AppLog("manifestGenerator.Write() is failed."); + } + AppLog("CreateCoreXmlFile() - END"); + AppLog("------------------------------------------"); + + return ret; +} + +bool +HybridInstaller::RegisterCoreXmlFile(InstallationContext* __pInstallationContext) const +{ + return true; +} + +bool +HybridInstaller::MergeToSystemXmlFile(const String& systemXmlPath, const String& webXmlPath, const String& serviceXmlPath) +{ + result r = E_SUCCESS; + char* pAppTagEnd = null; + char* plastAppTagEnd = null; + char* pTempServiceBuf = null; + int serviceAppLen = 0; + + FileAttributes webXmlAttr; + r = File::GetAttributes(webXmlPath, webXmlAttr); + TryReturn(!IsFailed(r), false, "File::GetAttributes() failed, webXmlPath=%ls", webXmlPath.GetPointer()); + + FileAttributes serviceAttr; + r = File::GetAttributes(serviceXmlPath, serviceAttr); + TryReturn(!IsFailed(r), false, "File::GetAttributes() failed, serviceXmlPath=%ls", serviceXmlPath.GetPointer()); + + long long webXmlFileSize = webXmlAttr.GetFileSize(); + long long serviceXmlFileSize = serviceAttr.GetFileSize(); + long long mergedSize = webXmlFileSize + serviceXmlFileSize; + + File webXml; + r = webXml.Construct(webXmlPath, L"r"); + TryReturn(!IsFailed(r), false, "webXmlPath.Construct is failed"); + + std::unique_ptr pMergedBuf(new (std::nothrow) char[mergedSize + 1]); + TryReturn(pMergedBuf, false, "pMergedBuf is null"); + memset(pMergedBuf.get(), 0, mergedSize + 1); + + int readBytes = webXml.Read(pMergedBuf.get(), webXmlFileSize); + TryReturn(readBytes >= 0, false, "webXml.Read is failed"); + + File serviceXml; + r = serviceXml.Construct(serviceXmlPath, L"r"); + TryReturn(!IsFailed(r), false, "serviceXmlPath.Construct is failed"); + + std::unique_ptr pServiceBuf(new (std::nothrow) char[serviceXmlFileSize + 1]); + TryReturn(pServiceBuf, false, "pServiceBuf is null"); + memset(pServiceBuf.get(), 0, serviceXmlFileSize + 1); + + readBytes = serviceXml.Read(pServiceBuf.get(), serviceXmlFileSize); + TryReturn(readBytes >= 0, false, "serviceXml.Read is failed"); + + + char* pManifestTag = strcasestr(pMergedBuf.get(), ""); + TryReturn(pManifestTag, false, "pManifestTag is null"); + + char* pAppTagStart = strcasestr(pServiceBuf.get(), "\n"); + memcpy(pManifestTag, pAppTagStart, serviceAppLen); + + pAppTagStart = strcasestr(pTempServiceBuf, ""); + if(plastAppTagEnd != null) + pManifestTag = pManifestTag + serviceAppLen; + + } + +#endif +#if 0 + char* pAppTagEnd = strcasestr(pServiceBuf.get(), ""); + TryReturn(pAppTagEnd, false, "pAppTagEnd is null"); + + int serviceAppLen = pAppTagEnd - pAppTagStart + strlen(""); + + memcpy(pManifestTag, pAppTagStart, serviceAppLen); +#endif + + char* pManifestEndTag = pManifestTag + serviceAppLen; + strcpy(pManifestEndTag, ""); + + int fileSize = pManifestEndTag - pMergedBuf.get() + strlen(""); + + AppLog("[0] File Size = [%d]", fileSize); + + if (strcasestr(pServiceBuf.get(), "") != null) + { + AppLog("Privileges are detected in service app."); + MergePrivileges(pMergedBuf.get(), pServiceBuf.get(), fileSize); + } + else + { + AppLog("No privileges are detected in service app."); + } + AppLog("[1] File Size = [%d]", fileSize); + + MergeAppWidgets(pMergedBuf.get(), pServiceBuf.get(), fileSize); + AppLog("[2] File Size = [%d]", fileSize); + + MergeAccounts(pMergedBuf.get(), pServiceBuf.get(), fileSize); + AppLog("[3] File Size = [%d]", fileSize); + + MergeNotifications(pMergedBuf.get(), pServiceBuf.get(), fileSize); + AppLog("[4] File Size = [%d]", fileSize); + + MergeIme(pMergedBuf.get(), pServiceBuf.get(), fileSize); + AppLog("[5] File Size = [%d]", fileSize); + + File systemXml; + r = systemXml.Construct(systemXmlPath, L"w"); + TryReturn(!IsFailed(r), false, "systemXmlPath.Construct() is failed."); + + r = systemXml.Write(pMergedBuf.get(), fileSize); + TryReturn(!IsFailed(r), false, "systemXmlPath.Write() is failed."); + + AppLog("pMergedBuf.get()=0x%0x, length=%d", (unsigned int)pMergedBuf.get(), fileSize); + InstallerUtil::DumpLogData(pMergedBuf.get(), fileSize); + + return true; +} + +bool +HybridInstaller::MergePrivileges(char* pMergedBuf, char* pServiceBuf, int& fileSize) +{ + char* pMergedPrivilegeDetected = strcasestr(pMergedBuf, ""); + char* pMergedPoint = null; + char* pServicePrivilegeStart = null; + char* pServicePrivilegeEnd = null; + int privilegeLen = 0; + int serviceBufLen = strlen(pServiceBuf); + std::unique_ptr pSelectedPrivBuf(new char[serviceBufLen + 1]); + memset(pSelectedPrivBuf.get(), 0, serviceBufLen + 1); + + if (pMergedPrivilegeDetected == null) + { + AppLog("No privileges are detected in web app."); + + pServicePrivilegeStart = strcasestr(pServiceBuf, ""); + pServicePrivilegeEnd = strcasestr(pServiceBuf, ""); + + privilegeLen = pServicePrivilegeEnd - pServicePrivilegeStart + strlen(""); + pMergedPoint = strcasestr(pMergedBuf, ""); + pServicePrivilegeEnd = strcasestr(pServiceBuf, ""); + + privilegeLen = pServicePrivilegeEnd - pServicePrivilegeStart; + pMergedPoint = strcasestr(pMergedBuf, ""); + + AppLog("Original privileges of service app"); + InstallerUtil::DumpLogData(pServicePrivilegeStart, privilegeLen); + + std::unique_ptr pPrivBuf(new char[privilegeLen + 1]); + memset(pPrivBuf.get(), 0, privilegeLen + 1); + strncpy(pPrivBuf.get(), pServicePrivilegeStart, privilegeLen); + + char* pEachPrivStart = pPrivBuf.get(); + char* pEachPrivEnd = null; + int eachPrivLen = 0; + char eachPrivBuf[512] = {0}; + + while (pEachPrivStart && (pEachPrivStart < pPrivBuf.get() + privilegeLen)) + { + pEachPrivEnd = strcasestr(pEachPrivStart, ""); + eachPrivLen = pEachPrivEnd - pEachPrivStart + strlen(""); + if ((pEachPrivEnd > 0) && (eachPrivLen > 0)) + { + memset(eachPrivBuf, 0, sizeof(eachPrivBuf)); + memcpy(eachPrivBuf, pEachPrivStart, eachPrivLen); + AppLog("[%s]", eachPrivBuf); + + if (strcasestr(pMergedBuf, eachPrivBuf) == 0) + { + strncat(pSelectedPrivBuf.get(), eachPrivBuf, serviceBufLen); + } + else + { + AppLog("This privilege is discarded, [%s]", eachPrivBuf); + } + } + else + { + AppLog("End of privileges merging."); + break; + } + + pEachPrivStart = strcasestr(pEachPrivEnd, ""); + } + + pServicePrivilegeStart = pSelectedPrivBuf.get(); + privilegeLen = strlen(pServicePrivilegeStart); + + AppLog("Filtered privileges of service app"); + InstallerUtil::DumpLogData(pServicePrivilegeStart, privilegeLen); + } + + if ((pMergedPoint > 0) && (pServicePrivilegeStart > 0) && (privilegeLen > 0)) + { + int lastPartLen = fileSize - (pMergedPoint - pMergedBuf); + std::unique_ptr pLastPartBuf(new (std::nothrow) char[fileSize + 1]); + memset(pLastPartBuf.get(), 0, fileSize + 1); + + if (lastPartLen > 0) + { + memcpy(pLastPartBuf.get(), pMergedPoint, lastPartLen); + + AppLog("Last part of merged xml for backup"); + InstallerUtil::DumpLogData(pLastPartBuf.get(), lastPartLen); + + memcpy(pMergedPoint, pServicePrivilegeStart, privilegeLen); + + memcpy(pMergedPoint + privilegeLen, pLastPartBuf.get(), lastPartLen); + fileSize += privilegeLen; + } + } + + return true; +} + +bool +HybridInstaller::MergeAppWidgets(char* pMergedBuf, char* pServiceBuf, int& fileSize) +{ + TryReturn(pMergedBuf, false, "pMergedBuf is null."); + TryReturn(pServiceBuf, false, "pServiceBuf is null."); + TryReturn(fileSize > 0, false, "fileSize is invalid."); + + if (strcasestr(pServiceBuf, "") == null) + { + AppLog(" is NOT detected in service app."); + return true; + } + + AppLog(" is detected in service app."); + MergeTags(pMergedBuf, pServiceBuf, fileSize, "\n"); + + return true; +} + +bool +HybridInstaller::MergeAccounts(char* pMergedBuf, char* pServiceBuf, int& fileSize) +{ + TryReturn(pMergedBuf, false, "pMergedBuf is null."); + TryReturn(pServiceBuf, false, "pServiceBuf is null."); + TryReturn(fileSize > 0, false, "fileSize is invalid."); + + if (strcasestr(pServiceBuf, "") == null) + { + AppLog(" is NOT detected in service app."); + return true; + } + + AppLog(" is detected in service app."); + MergeTags(pMergedBuf, pServiceBuf, fileSize, ""); + + return true; +} + +bool +HybridInstaller::MergeNotifications(char* pMergedBuf, char* pServiceBuf, int& fileSize) +{ + TryReturn(pMergedBuf, false, "pMergedBuf is null."); + TryReturn(pServiceBuf, false, "pServiceBuf is null."); + TryReturn(fileSize > 0, false, "fileSize is invalid."); + + if (strcasestr(pServiceBuf, "") == null) + { + AppLog(" is NOT detected in service app."); + return true; + } + + AppLog(" is detected in service app."); + MergeTags(pMergedBuf, pServiceBuf, fileSize, ""); + + return true; +} + +bool +HybridInstaller::MergeIme(char* pMergedBuf, char* pServiceBuf, int& fileSize) +{ + TryReturn(pMergedBuf, false, "pMergedBuf is null."); + TryReturn(pServiceBuf, false, "pServiceBuf is null."); + TryReturn(fileSize > 0, false, "fileSize is invalid."); + + if (strcasestr(pServiceBuf, "") == null) + { + AppLog(" is NOT detected in service app."); + return true; + } + + AppLog(" is detected in service app."); + MergeTags(pMergedBuf, pServiceBuf, fileSize, ""); + + return true; +} + +bool +HybridInstaller::MergeTags(char* pMergedBuf, char* pServiceBuf, int& fileSize, const char* pStartTag, const char* pEndTag) +{ + do + { + char* pBuf = null; + int length = 0; + char* pNext = null; + + AppLog("pServiceBuf = [0x%08x]", pServiceBuf); + GetPart(pServiceBuf, pStartTag, pEndTag, &pBuf, &length, &pNext); + if (length > 0) + { + MergeTo(pMergedBuf, fileSize, "", pBuf, length); + } + + delete [] pBuf; + + pServiceBuf = pNext; + } + while (pServiceBuf > 0); + + return true; +} + +bool +HybridInstaller::GetPart(const char* pStartPoint, const char* pStartTag, const char* pEndTag, char** ppBuf, int* pLength, char** ppNext) +{ + TryReturn(pStartPoint, false, "pStartPoint is null."); + TryReturn(pStartTag, false, "pStartTag is null."); + TryReturn(pEndTag, false, "pEndTag is null."); + TryReturn(ppBuf, false, "ppBuf is null."); + TryReturn(pLength, false, "pLength is null."); + TryReturn(ppNext, false, "ppNext is null."); + + const char* pStartBufPoint = strcasestr(pStartPoint, pStartTag); + TryReturn(pStartBufPoint, false, "pStartBufPoint is null."); + + const char* pEndBufPoint = strcasestr(pStartBufPoint, pEndTag); + TryReturn(pEndBufPoint, false, "pEndBufPoint is null."); + + int len = pEndBufPoint - pStartBufPoint + strlen(pEndTag); + TryReturn(len > 0, false, "len is invalid."); + + char *pBuf = null; + pBuf = new char[len + 1]; + TryReturn(pBuf, false, "pBuf is null."); + memset(pBuf, 0, len + 1); + memcpy(pBuf, pStartBufPoint, len); + + AppLog("Extracted Part, len = [%d]", len); + InstallerUtil::DumpLogData(pBuf, len); + + *ppBuf = pBuf; + *pLength = len; + *ppNext = (char *)pEndBufPoint; + + return true; +} + +bool +HybridInstaller::MergeTo(const char* pMergedBuf, int& fileSize, const char* pTag, const char* pBuf, int length) +{ + TryReturn(pMergedBuf, false, "pMergedBuf is null."); + TryReturn(fileSize > 0, false, "fileSize is invalid."); + TryReturn(pTag, false, "pTag is null."); + TryReturn(pBuf, false, "pBuf is null."); + TryReturn(length > 0, false, "length is invalid."); + + char* pMergedPoint = null; + pMergedPoint = (char *)strcasestr(pMergedBuf, pTag); + TryReturn(pMergedPoint > 0, true, "pTag is not found, pTag=[%s]", pTag); + + int lastPartLen = fileSize - (pMergedPoint - pMergedBuf); + std::unique_ptr pLastPartBuf(new (std::nothrow) char[fileSize + 1]); + memset(pLastPartBuf.get(), 0, fileSize + 1); + + if (lastPartLen > 0) + { + memcpy(pLastPartBuf.get(), pMergedPoint, lastPartLen); + + AppLog("Last part of merged xml for backup"); + InstallerUtil::DumpLogData(pLastPartBuf.get(), lastPartLen); + + memcpy(pMergedPoint, pBuf, length); + memcpy(pMergedPoint + length, pLastPartBuf.get(), lastPartLen); + fileSize += length; + } + + return true; +} + +bool +HybridInstaller::CreateImeSymlink(const String& binaryPath, const String& appId) +{ + bool res = true; + int err = 0; + const char* pExePath = null; + const char* pSymlinkPath = null; + + Directory::Create(IME_PATH, true); + + String exePath; + exePath.Format(1024, L"%ls.exe", binaryPath.GetPointer()); + + String symlinkPath; + symlinkPath.Format(1024, L"%s/%ls.so", IME_PATH, appId.GetPointer()); + + pExePath = _StringConverter::CopyToCharArrayN(exePath); + TryCatch(pExePath, res = false, "pExePath is null"); + + pSymlinkPath = _StringConverter::CopyToCharArrayN(symlinkPath); + TryCatch(pSymlinkPath, res = false, "pSymlinkPath is null"); + + err = symlink(pExePath, pSymlinkPath); + + AppLog("[%s] -> [%s]", pSymlinkPath, pExePath); + +CATCH: + delete[] pExePath; + delete[] pSymlinkPath; + + return res; +} + +bool +HybridInstaller::FindPrivilege(InstallationContext* __pInstallationContext, const String& privilege) const +{ + TryReturn(__pInstallationContext, false, "__pInstallationContext is null."); + + bool ret = false; + const ArrayList* pPrivilegeList = __pInstallationContext->GetPrivilegeList(); + + if (pPrivilegeList) + { + if (pPrivilegeList->Contains(privilege) == true) + { + AppLog("Privilege = [%ls]", privilege.GetPointer()); + ret = true; + } + } + + return ret; +} + +bool +HybridInstaller::CreateAppInfoFile(AppData* pAppData, const String& rootPath) const +{ + TryReturn(pAppData, false, "pAppData is null."); + TryReturn(rootPath.IsEmpty() == false, false, "rootPath is empty."); + + String appFolder = rootPath + DIR_INFO + L"/" + pAppData->__appId; + Directory::Create(appFolder); + + HashMap* pFeatureList = pAppData->__pFeatureList; + if (pFeatureList) + { + String coordinateSystem; + String baseScreenSize; + String logicalCoordinate; + String systemTheme; + String userDefinedTheme; + + std::unique_ptr< IMapEnumerator > pEnum(pFeatureList->GetMapEnumeratorN()); + TryReturn(pEnum, false, "GetMapEnumeratorN() failed. [%s]", GetErrorMessage(GetLastResult())); + + while (pEnum->MoveNext() == E_SUCCESS) + { + String* pKey = static_cast< String* > (pEnum->GetKey()); + TryReturn(pEnum, false, "GetKey() failed. [%s]", GetErrorMessage(GetLastResult())); + + String* pValue = static_cast< String* > (pEnum->GetValue()); + TryReturn(pEnum, false, "GetValue() failed. [%s]", GetErrorMessage(GetLastResult())); + + if ((*pKey) == L"CoordinateSystem") + { + coordinateSystem = (*pValue); + } + + if ((*pKey) == L"BaseScreenSize") + { + baseScreenSize = (*pValue); + } + + if ((*pKey) == L"LogicalCoordinate") + { + logicalCoordinate = (*pValue); + } + + if ((*pKey) == L"SystemTheme") + { + systemTheme = (*pValue); + } + + if ((*pKey) == L"UserDefinedTheme") + { + userDefinedTheme = (*pValue); + } + } + + if (coordinateSystem.IsEmpty() == false) + { + String uiScalability; + uiScalability.Format(1024, UISCALABILITY_INFO, coordinateSystem.GetPointer(), baseScreenSize.GetPointer(), logicalCoordinate.GetPointer()); + + String uiScalabilityInfoFile; + uiScalabilityInfoFile.Format(1024, L"%ls%ls", appFolder.GetPointer(), UISCALABILITY_INFO_FILE); + + InstallerUtil::CreateInfoFile(uiScalabilityInfoFile, &uiScalability); + } + + if (systemTheme.IsEmpty() == false) + { + String uiTheme; + uiTheme.Format(1024, UITHEME_INFO, systemTheme.GetPointer(), userDefinedTheme.GetPointer()); + + String uiThemeInfoFile; + uiThemeInfoFile.Format(1024, L"%ls%ls", appFolder.GetPointer(), UITHEME_INFO_FILE); + + InstallerUtil::CreateInfoFile(uiThemeInfoFile, &uiTheme); + } + } + + HashMap* pMetadataMap = pAppData->__pMetadataMap; + if (pMetadataMap) + { + String screenReaderOff(METADATA_DISABLE_SCREEN_READER); + if (pMetadataMap->ContainsKey(screenReaderOff) == true) + { + String screenReaderOffInfoFile; + screenReaderOffInfoFile.Format(1024, L"%ls%ls", appFolder.GetPointer(), DISABLE_SCREEN_READER_INFO_FILE); + + InstallerUtil::CreateInfoFile(screenReaderOffInfoFile, null); + } + } + + return true; +} + + diff --git a/src/Installer/HybridInstaller.h b/src/Installer/HybridInstaller.h new file mode 100644 index 0000000..f133156 --- /dev/null +++ b/src/Installer/HybridInstaller.h @@ -0,0 +1,89 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file HybridInstaller.h + * @brief This is the header file for the %HybridInstaller class. + * + * This header file contains the declarations of the %HybridInstaller class. + */ +#ifndef _HYBRID_INSTALLER_H_ +#define _HYBRID_INSTALLER_H_ + +#include "DirectoryInstaller.h" + + +/** + * @class HybridInstaller + * @brief This class represents the class of HybridInstaller. + * @since 1.0 + * + * This class represents the class of HybridInstaller. + * + */ +class HybridInstaller + : public DirectoryInstaller +{ +public: + HybridInstaller(void); + virtual ~HybridInstaller(void); + + virtual InstallationStep GetNext(InstallationStep step); + + virtual InstallerError OnInit(void); + virtual InstallerError OnRegister(void); + virtual InstallerError OnEnd(void); + + virtual InstallerError OnError(void); + virtual InstallerError OnRollback(void); + virtual InstallerError OnUserCancel(void); + + InstallerError RequestHybridAppInstallation(int hybridOperation, char* pkgPath, int apiVisibility); + + bool CreateFile(); + bool RemoveFile(); + + bool PostInstall(bool error) const; + bool PostUninstall() const; + +private: + bool CreateCoreXmlFile(InstallationContext* pContext) const; + bool RegisterCoreXmlFile(InstallationContext* pContext) const; + + bool MergeToSystemXmlFile(const Tizen::Base::String& systemXmlPath, const Tizen::Base::String& webXmlPath,const Tizen::Base::String& serviceXmlPath); + bool MergePrivileges(char* pMergedBuf, char* pServiceBuf, int& fileSize); + + bool MergeAppWidgets(char* pMergedBuf, char* pServiceBuf, int& fileSize); + bool MergeAccounts(char* pMergedBuf, char* pServiceBuf, int& fileSize); + bool MergeNotifications(char* pMergedBuf, char* pServiceBuf, int& fileSize); + bool MergeIme(char* pMergedBuf, char* pServiceBuf, int& fileSize); + bool MergeTags(char* pMergedBuf, char* pServiceBuf, int& fileSize, const char* pStartTag, const char* pEndTag); + + bool GetPart(const char* pStartPoint, const char* pStartTag, const char* pEndTag, char** ppBuf, int* pLength, char** ppNext); + bool MergeTo(const char* pMergedBuf, int& fileSize, const char* pTag, const char* pBuf, int length); + + bool CreateImeSymlink(const Tizen::Base::String& binaryPath, const Tizen::Base::String& packageName); + bool FindPrivilege(InstallationContext* pContext, const Tizen::Base::String& privilege) const; + + bool CreateAppInfoFile(AppData* pAppData, const Tizen::Base::String& rootPath) const; + bool RemoveInfoFiles(void); + +private: + InstallationContext* __pInstallationContext; + +}; // HybridInstaller + +#endif // _HYBRID_INSTALLER_H_ diff --git a/src/Installer/PreloadedInstaller.cpp b/src/Installer/PreloadedInstaller.cpp index d1676bc..28f7951 100755 --- a/src/Installer/PreloadedInstaller.cpp +++ b/src/Installer/PreloadedInstaller.cpp @@ -58,7 +58,7 @@ PreloadedInstaller::OnInit(void) String versionFile = path + VERSION_INFO_FILE; if (File::IsFileExist(versionFile) == true) { - AppLog("install preloaded app again.") + AppLog("install preloaded app again.[%ls]", versionFile.GetPointer()); pContext->__isUpdated = true; } diff --git a/src/Manager/CompatibilityManager.cpp b/src/Manager/CompatibilityManager.cpp index acc4700..dc8044d 100755 --- a/src/Manager/CompatibilityManager.cpp +++ b/src/Manager/CompatibilityManager.cpp @@ -136,17 +136,13 @@ CompatibilityManager::FinalizeDataCaging(const String& rootPath) { "./etc" }, { "./lib" }, { "./mnt" }, - { "./opt/usr" }, { "./opt/var/kdb/db" }, - { "./opt/storage/sdcard" }, - { "./opt" }, { "./proc" }, - { "./sbin" }, { "./smack" }, - { "./srv" }, { "./sys/kernel/debug" }, { "./sys" }, { "./tmp" }, + { "./usr/share/locale" }, { "./usr" }, { "./var/run" }, { "./var" }, @@ -155,12 +151,15 @@ CompatibilityManager::FinalizeDataCaging(const String& rootPath) { "./Share" }, { "./Share2" }, { "./Media" }, - { "./Storagecard/Media" }, { "./ShareExt" }, { "./Share2Ext" }, { "./HomeExt/Share" }, { "./HomeExt/Share2" }, - { "./HomeExt" } + { "./HomeExt" }, + { "./Storagecard/Media" }, + { "./opt/storage/sdcard" }, + { "./opt/usr" }, + { "./opt" }, }; std::unique_ptr pAppRootPath(_StringConverter::CopyToCharArrayN(rootPath)); @@ -176,22 +175,31 @@ CompatibilityManager::FinalizeDataCaging(const String& rootPath) } char* pPackageId = strrchr(pAppRootPath.get(), '/'); - char mountFlag[PATH_MAX] = {0, }; + ++pPackageId; + + String mountFlag = L"/tmp/osp-compat/mount/internal/"; + mountFlag.Append(pPackageId); + + std::unique_ptr pMountFlag(_StringConverter::CopyToCharArrayN(mountFlag)); + TryReturn(pMountFlag, false, "pMountFlag is null."); - sprintf(mountFlag, "/tmp/osp-compat/mount/internal/%s", ++pPackageId); - res = unlink(mountFlag); + res = unlink(pMountFlag.get()); if ((res == -1) && (errno != ENOENT)) { - AppLog("unlink(%s) failed, errno: %d (%s)", mountFlag, errno, strerror(errno)); + AppLog("unlink(%s) failed, errno: %d (%s)", pMountFlag.get(), errno, strerror(errno)); return false; } - memset(mountFlag, 0, PATH_MAX); - sprintf(mountFlag, "/tmp/osp-compat/mount/external/%s", pPackageId); - res = unlink(mountFlag); + String mountFlag2 = L"/tmp/osp-compat/mount/external/"; + mountFlag2.Append(pPackageId); + + std::unique_ptr pMountFlag2(_StringConverter::CopyToCharArrayN(mountFlag2)); + TryReturn(pMountFlag2, false, "pMountFlag2 is null."); + + res = unlink(pMountFlag2.get()); if ((res == -1) && (errno != ENOENT)) { - AppLog("unlink(%s) failed, errno: %d (%s)", mountFlag, errno, strerror(errno)); + AppLog("unlink(%s) failed, errno: %d (%s)", pMountFlag2.get(), errno, strerror(errno)); return false; } @@ -202,9 +210,6 @@ CompatibilityManager::FinalizeDataCaging(const String& rootPath) bool CompatibilityManager::CleanDirectories(const String& rootPath, const PackageId& packageId) { - int ret = 0; - char removeCmd[PATH_MAX] = {0, }; - String ospSharePkgIdPath = _EnvironmentImpl::GetOspCompatSharedPath(); ospSharePkgIdPath.Append(L"share/"); ospSharePkgIdPath.Append(packageId); @@ -213,19 +218,8 @@ CompatibilityManager::CleanDirectories(const String& rootPath, const PackageId& ospShare2PkgIdPath.Append(L"share2/"); ospShare2PkgIdPath.Append(packageId); - sprintf(removeCmd, "rm -rf %ls", ospSharePkgIdPath.GetPointer()); - AppLog("removeCmd = [%s]", removeCmd); - - ret = system(removeCmd); - TryReturn(ret != -1, false, "system(%s) failed.", removeCmd); - - memset(removeCmd, 0, PATH_MAX); - - sprintf(removeCmd, "rm -rf %ls", ospShare2PkgIdPath.GetPointer()); - AppLog("removeCmd = [%s]", removeCmd); - - ret = system(removeCmd); - TryReturn(ret != -1, false, "system(%s) failed.", removeCmd); + InstallerUtil::Remove(ospSharePkgIdPath); + InstallerUtil::Remove(ospShare2PkgIdPath); AppLog("[Tizen::Io] CleanDirectories() succeeded, rootPath: %ls", rootPath.GetPointer()); return true; @@ -234,35 +228,35 @@ CompatibilityManager::CleanDirectories(const String& rootPath, const PackageId& bool CompatibilityManager::LinkOspSharePath(const String& rootPath, const PackageId& packageId) { - const char* pOspCompatSharedPath = "/opt/usr/share/.osp-compat/\0"; + String ospCompatSharedPath = L"/opt/usr/share/.osp-compat/"; - std::unique_ptr pRootPath(_StringConverter::CopyToCharArrayN(rootPath)); - TryReturn(pRootPath, false, "The memory is insufficient."); + String ospAppSharePath; + String ospAppShare2Path; + String ospSharePkgIdPath; + String ospShare2PkgIdPath; - std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(packageId)); - TryReturn(pPackageId, false, "The memory is insufficient."); + ospAppSharePath = rootPath; + ospAppSharePath.Append(L"/shared/data"); - char ospAppSharePath[PATH_MAX] = {0, }; - char ospAppShare2Path[PATH_MAX] = {0, }; - char ospSharePkgIdPath[PATH_MAX] = {0, }; - char ospShare2PkgIdPath[PATH_MAX] = {0, }; + ospSharePkgIdPath = ospCompatSharedPath; + ospSharePkgIdPath.Append(L"share/"); + ospSharePkgIdPath.Append(packageId); - strncpy(ospAppSharePath, pRootPath.get(), strlen(pRootPath.get())); - strncat(ospAppSharePath, "/shared/data", 12); + ospAppShare2Path = rootPath; + ospAppShare2Path.Append(L"/shared/trusted"); - strncpy(ospSharePkgIdPath, pOspCompatSharedPath, strlen(pOspCompatSharedPath)); - strncat(ospSharePkgIdPath, "share/", 6); - strncat(ospSharePkgIdPath, pPackageId.get(), strlen(pPackageId.get())); + ospShare2PkgIdPath = ospCompatSharedPath; + ospShare2PkgIdPath.Append(L"share2/"); + ospShare2PkgIdPath.Append(packageId); - strncpy(ospAppShare2Path, pRootPath.get(), strlen(pRootPath.get())); - strncat(ospAppShare2Path, "/shared/trusted", 15); + std::unique_ptr pOspSharePkgIdPath(_StringConverter::CopyToCharArrayN(ospSharePkgIdPath)); + TryReturn(pOspSharePkgIdPath, false, "pOspSharePkgIdPathh is null."); - strncpy(ospShare2PkgIdPath, pOspCompatSharedPath, strlen(pOspCompatSharedPath)); - strncat(ospShare2PkgIdPath, "share2/", 7); - strncat(ospShare2PkgIdPath, pPackageId.get(), strlen(pPackageId.get())); + std::unique_ptr pOspShare2PkgIdPath(_StringConverter::CopyToCharArrayN(ospShare2PkgIdPath)); + TryReturn(pOspShare2PkgIdPath, false, "pOspShare2PkgIdPath is null."); - unlink(ospSharePkgIdPath); - unlink(ospShare2PkgIdPath); + unlink(pOspSharePkgIdPath.get()); + unlink(pOspShare2PkgIdPath.get()); InstallerUtil::CreateSymlink(ospAppSharePath, ospSharePkgIdPath, false); InstallerUtil::CreateSymlink(ospAppShare2Path, ospShare2PkgIdPath, false); @@ -293,6 +287,7 @@ CompatibilityManager::PrepareVirtualRoot(const Tizen::Base::String& rootPath, co { r = Directory::Create(virtualRootPath, true); TryCatch(!IsFailed(r), res = false, "Directory::Create() failed"); + InstallerUtil::ChangeDirectoryPermission(virtualRootPath, PERM_BASE, false); } result = chdir(pVirtualRootPath.get()); @@ -331,9 +326,7 @@ CompatibilityManager::FinalizeVirtualRoot(const String& rootPath, const PackageI static const struct _PathInfo mountPath[] = { { "./bin" }, - { "./cache" }, { "./csa" }, - { "./data" }, { "./dev/pts" }, { "./dev/shm" }, { "./dev" }, @@ -344,14 +337,11 @@ CompatibilityManager::FinalizeVirtualRoot(const String& rootPath, const PackageI { "./mnt" }, { "./proc" }, { "./run" }, - { "./sbin" }, { "./smack" }, - { "./srv" }, { "./sys/fs/cgroup/systemd" }, { "./sys/fs/cgroup" }, - { "./sys" }, - { "./system" }, { "./tmp" }, + { "./usr/share/locale" }, { "./usr" }, { "./var/run" }, { "./var" }, @@ -375,24 +365,29 @@ CompatibilityManager::FinalizeVirtualRoot(const String& rootPath, const PackageI AppLog("umount2(%s) is succeeded.", mountPath[i].destPath); } - std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(packageId)); - TryReturn(pPackageId, false, "The memory is insufficient."); + String mountFlag = L"/tmp/osp-compat/mount/internal/"; + mountFlag.Append(packageId); - char mountFlag[PATH_MAX] = {0, }; - sprintf(mountFlag, "/tmp/osp-compat/mount/internal/%s", pPackageId.get()); - res = unlink(mountFlag); + std::unique_ptr pMountFlag(_StringConverter::CopyToCharArrayN(mountFlag)); + TryReturn(pMountFlag, false, "pMountFlag is null."); + + res = unlink(pMountFlag.get()); if ((res == -1) && (errno != ENOENT)) { - AppLog("unlink(%s) failed, errno: %d (%s)", mountFlag, errno, strerror(errno)); + AppLog("unlink(%s) failed, errno: %d (%s)", pMountFlag.get(), errno, strerror(errno)); return false; } - memset(mountFlag, 0, PATH_MAX); - sprintf(mountFlag, "/tmp/osp-compat/mount/external/%s", pPackageId.get()); - res = unlink(mountFlag); + String mountFlag2 = L"/tmp/osp-compat/mount/external/"; + mountFlag2.Append(packageId); + + std::unique_ptr pMountFlag2(_StringConverter::CopyToCharArrayN(mountFlag2)); + TryReturn(pMountFlag2, false, "pMountFlag2 is null."); + + res = unlink(pMountFlag2.get()); if ((res == -1) && (errno != ENOENT)) { - AppLog("unlink(%s) failed, errno: %d (%s)", mountFlag, errno, strerror(errno)); + AppLog("unlink(%s) failed, errno: %d (%s)", pMountFlag2.get(), errno, strerror(errno)); return false; } @@ -532,9 +527,7 @@ CompatibilityManager::CreateSlpDirectories(void) { "./mnt", 0000, false }, { "./opt", 0000, false }, { "./proc", 0000, false }, - { "./sbin", 0000, false }, { "./smack", 0000, false }, - { "./srv", 0000, false }, { "./sys", 0000, false }, { "./tmp", 0000, false }, { "./usr", 0000, false }, @@ -586,9 +579,7 @@ CompatibilityManager::CreateVirtualRootDirectories(void) struct _OspDir virtualRootDir[] = { { "./bin", 0000, false }, - { "./cache", 0000, false }, { "./csa", 0000, false }, - { "./data", 0000, false }, { "./dev", 0000, false }, { "./etc", 0000, false }, { "./lib", 0000, false }, @@ -597,11 +588,9 @@ CompatibilityManager::CreateVirtualRootDirectories(void) { "./opt", 0000, false }, { "./proc", 0000, false }, { "./run", 0000, false }, - { "./sbin", 0000, false }, { "./smack", 0000, false }, { "./srv", 0000, false }, { "./sys", 0000, false }, - { "./system", 0000, false }, { "./tmp", 0000, false }, { "./usr", 0000, false }, { "./var", 0000, false } diff --git a/src/Manager/ConfigurationManager.cpp b/src/Manager/ConfigurationManager.cpp index 586815f..394e94c 100755 --- a/src/Manager/ConfigurationManager.cpp +++ b/src/Manager/ConfigurationManager.cpp @@ -32,8 +32,8 @@ #include #include #include -#include #include +#include #include #include "ConfigurationManager.h" @@ -42,11 +42,11 @@ #include "InstallerUtil.h" #include "SmackManager.h" +using namespace Tizen::App; +using namespace Tizen::App::Package; using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Base::Utility; -using namespace Tizen::Security::Cert; -using namespace Tizen::App; using namespace Tizen::Io; ConfigurationManager::ConfigurationManager(void) @@ -124,8 +124,30 @@ ConfigurationManager::CreateFile(InstallationContext* pContext) if (appType == L"UiApp") { - AppLog("copy ui app loader"); - InstallerUtil::Copy(UIAPP_LOADER_PATH, binaryPath); + bool uiLoader = true; + String loaderPath; + HashMap* pMetadataMap = pAppData->__pMetadataMap; + + if (pMetadataMap) + { + String key = METADATA_COMPATIBLE_MEMORY_LAYOUT; + if (pMetadataMap->ContainsKey(key) == true) + { + uiLoader = false; + } + } + + if (uiLoader == true) + { + AppLog("copy ui app loader"); + loaderPath = UIAPP_LOADER_PATH; + } + else + { + AppLog("copy exec loader"); + loaderPath = EXEC_LOADER_PATH; + } + InstallerUtil::Copy(loaderPath, binaryPath); int categoryType = pAppData->__feature; if (categoryType != CATEGORY_TYPE_NONE) @@ -214,28 +236,8 @@ ConfigurationManager::CreateFile(InstallationContext* pContext) std::unique_ptr pXmlPath(_StringConverter::CopyToCharArrayN(pContext->__coreXmlPath)); TryReturn(pXmlPath != null, false, "pXmlPath is null"); - if (pContext->__isHybridService == true) - { - String webXmlPath = pXmlPath.get(); - webXmlPath += L".wgt"; - InstallerUtil::Copy(pXmlPath.get(), webXmlPath); - - CreateCoreXmlFile(pContext); + CreateCoreXmlFile(pContext); - String serviceXmlPath = pXmlPath.get(); - serviceXmlPath += L".tpk"; - InstallerUtil::Copy(pXmlPath.get(), serviceXmlPath); - InstallerUtil::Remove(pXmlPath.get()); - - MergeToSystemXmlFile(pXmlPath.get(), webXmlPath, serviceXmlPath); - InstallerUtil::Remove(webXmlPath); - InstallerUtil::Remove(serviceXmlPath); - } - else - { - CreateCoreXmlFile(pContext); - } - AppLog("------------------------------------------"); AppLog("sync() - START"); sync(); @@ -263,22 +265,15 @@ ConfigurationManager::RemoveFile(InstallationContext* pContext) std::unique_ptr pXmlPath(_StringConverter::CopyToCharArrayN(pContext->__coreXmlPath)); TryReturn(pXmlPath != null, false, "pXmlPath is null"); - if (pContext->__isHybridService == true) - { - AppLog("Uninstallation for HybridService - skip"); - } - else + AppLog("pkgmgr_parser_parse_manifest_for_uninstallation(%s) START", pXmlPath.get()); + if (pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath.get(), null) != 0) { - AppLog("pkgmgr_parser_parse_manifest_for_uninstallation(%s) START", pXmlPath.get()); - if (pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath.get(), null) != 0) - { - AppLog("pkgmgr_parser_parse_manifest_for_uninstallation() is failed.[%s]", pXmlPath.get()); - } - AppLog("pkgmgr_parser_parse_manifest_for_uninstallation() END"); - - InstallerUtil::Remove(pXmlPath.get()); + AppLog("pkgmgr_parser_parse_manifest_for_uninstallation() is failed.[%s]", pXmlPath.get()); } + AppLog("pkgmgr_parser_parse_manifest_for_uninstallation() END"); + + InstallerUtil::Remove(pXmlPath.get()); return true; } @@ -300,18 +295,22 @@ ConfigurationManager::PostInstall(InstallationContext* pContext, bool error) con res = RegisterCoreXmlFile(pContext); TryReturn(res, false, "RegisterCoreXmlFile() failed."); +#if 0 if ((pContext->__isUpdated == true) && (pContext->__isPreloaded == false)) { CopyData(pContext); RemoveBackup(pContext); } +#endif } else { +#if 0 if ((pContext->__isUpdated == true) && (pContext->__isPreloaded == false)) { RestoreBackup(pContext); } +#endif } app2ext_handle* pHandle = (app2ext_handle*)pContext->__pApp2ExtHandle; @@ -358,6 +357,7 @@ ConfigurationManager::PostUninstall(InstallationContext* pContext) const return true; } +#if 0 bool ConfigurationManager::CreateBackup(InstallationContext* pContext) const { @@ -422,6 +422,65 @@ ConfigurationManager::CreateBackup(InstallationContext* pContext) const } bool +ConfigurationManager::RemoveGarbage(const PackageId& packageId) const +{ + TryReturn(packageId.IsEmpty() == false, false, "packageId is empty."); + + String rootPath = PATH_OPT_USR_APPS; + rootPath += L"/"; + rootPath += packageId; + + // folder + String backupPath = rootPath + BACKUP_NAME_RULE; + if (File::IsFileExist(backupPath) == true) + { + InstallerUtil::Remove(backupPath); + AppLog("[%ls] is removed.", backupPath.GetPointer()); + } + + // database + DatabaseManager databaseManager; + databaseManager.UnregisterPackageInfo(packageId, true); + + // core xml + String rwXmlPath; + rwXmlPath.Format(1024, DIR_RW_PACKAGE_SYSTEM_MANIFEST, packageId.GetPointer()); + String backupXmlPath = rwXmlPath + BACKUP_NAME_RULE; + if (File::IsFileExist(backupXmlPath) == true) + { + InstallerUtil::Remove(backupXmlPath); + } + + if (_PackageManagerImpl::GetInstance()->IsPackageInstalled(packageId) == false) + { + AppLog("[%ls] is not installed.", packageId.GetPointer()); + + if (File::IsFileExist(rootPath) == true) + { + InstallerUtil::Remove(rootPath); + } + else + { + AppLog("[%ls] is not existed.", rootPath.GetPointer()); + } + + DatabaseManager databaseManager; + databaseManager.UnregisterPackageInfo(packageId, false); + + if (File::IsFileExist(rwXmlPath) == true) + { + InstallerUtil::Remove(rwXmlPath); + } + else + { + AppLog("[%ls] is not existed.", rwXmlPath.GetPointer()); + } + } + + return true; +} + +bool ConfigurationManager::RemoveBackup(InstallationContext* pContext) const { TryReturn(pContext, false, "pContext is null."); @@ -586,6 +645,7 @@ ConfigurationManager::CopyData(InstallationContext* pContext) const return true; } +#endif bool ConfigurationManager::CreateCoreXmlFile(InstallationContext* pContext) const @@ -611,12 +671,6 @@ ConfigurationManager::CreateCoreXmlFile(InstallationContext* pContext) const bool ConfigurationManager::RegisterCoreXmlFile(InstallationContext* pContext) const { - if (pContext->__isHybridService == true) - { - AppLog("HybridService is skipped."); - return true; - } - std::unique_ptr pXmlPath(_StringConverter::CopyToCharArrayN(pContext->__coreXmlPath)); TryReturn(pXmlPath != null, false, "pXmlPath is null."); diff --git a/src/Manager/ConfigurationManager.h b/src/Manager/ConfigurationManager.h index 2156d97..3376fcd 100755 --- a/src/Manager/ConfigurationManager.h +++ b/src/Manager/ConfigurationManager.h @@ -45,7 +45,8 @@ public: bool PostInstall(InstallationContext* pContext, bool error) const; bool PostUninstall(InstallationContext* pContext) const; - bool CreateBackup(InstallationContext* pContext) const; + //bool CreateBackup(InstallationContext* pContext) const; + //bool RemoveGarbage(const Tizen::App::PackageId& packageId) const; private: bool CreateCoreXmlFile(InstallationContext* pContext) const; @@ -68,9 +69,9 @@ private: bool CreateAppInfoFile(AppData* pAppData, const Tizen::Base::String& rootPath) const; - bool RemoveBackup(InstallationContext* pContext) const; - bool RestoreBackup(InstallationContext* pContext) const; - bool CopyData(InstallationContext* pContext) const; + //bool RemoveBackup(InstallationContext* pContext) const; + //bool RestoreBackup(InstallationContext* pContext) const; + //bool CopyData(InstallationContext* pContext) const; }; // ConfigurationManager diff --git a/src/Manager/InstallerManager.cpp b/src/Manager/InstallerManager.cpp index 828978d..122e699 100755 --- a/src/Manager/InstallerManager.cpp +++ b/src/Manager/InstallerManager.cpp @@ -23,30 +23,34 @@ #include #include +#include #include #include #include #include -#include -#include +#include #include #include #include +#include #include "InstallerManager.h" +#include "ConfigurationManager.h" +#include "SmackManager.h" #include "GuestInstaller.h" #include "IDEInstaller.h" #include "PreloadedInstaller.h" #include "RestorationInstaller.h" #include "InstallerUtil.h" +#include "HybridInstaller.h" +using namespace Tizen::App; +using namespace Tizen::App::Package; using namespace Tizen::Base; using namespace Tizen::Base::Utility; using namespace Tizen::Base::Collection; using namespace Tizen::Io; -using namespace Tizen::App; -using namespace Tizen::App::Package; const int BUFSIZE = 512; InstallerManager* InstallerManager::__pInstallerManager = null; @@ -155,6 +159,24 @@ InstallerManager::Construct(const String& path, InstallerOperation operation, In if (operation == INSTALLER_OPERATION_INSTALL) { + if (option & INSTALLER_OPTION_CSC) + { + TryReturn(pOptionalData, INSTALLER_ERROR_INTERNAL_STATE, "pOptionalData(cscInfo) is null."); + + AppLog("INSTALLER_OPTION_CSC is detected."); + __pContext->__isCsc = true; + __pContext->__cscInfo = *pOptionalData; + } + + if (pOptionalData) + { + ParseOptionalData(pOptionalData); + SendEvent(__pContext->__pPkgmgrInstaller, __pContext->__packageId, "start", "install"); + } + else + { + AppLog("Input param(package) is null in case of cmd, hybrid package."); + } FileAttributes attr; r = File::GetAttributes(newPath, attr); TryReturn(!IsFailed(r), INSTALLER_ERROR_PACKAGE_NOT_FOUND, "File::GetAttributes() failed"); @@ -182,11 +204,16 @@ InstallerManager::Construct(const String& path, InstallerOperation operation, In } else { - if (option & INSTALLER_OPTION_CSC) + if (!(option & INSTALLER_OPTION_CSC)) { - AppLog("INSTALLER_OPTION_CSC is detected."); - __pContext->__isCsc = true; - __pContext->__cscInfo = *pOptionalData; + if (File::IsFileExist(DIR_RECOVERY_TPK) == true) + { + String installFlag = DIR_RECOVERY_TPK; + installFlag += L"/"; + installFlag += __pContext->__packageId; + + InstallerUtil::CreateFlagFile(installFlag); + } } installerType = INSTALLER_TYPE_PACKAGE; @@ -194,16 +221,6 @@ InstallerManager::Construct(const String& path, InstallerOperation operation, In __pContext->__packageSize = InstallerUtil::GetDisplaySize(newPath); } - if (pOptionalData) - { - ParseOptionalData(pOptionalData); - SendEvent(__pContext, __pContext->__packageId, "start", "install"); - } - else - { - AppLog("Input param(package) is null in case of cmd, hybrid package."); - } - if (option & INSTALLER_OPTION_RESET_PRELOADED) { TryReturn(__pContext->__packageId.IsEmpty() == false, INSTALLER_ERROR_INTERNAL_STATE, "packageId is empty."); @@ -224,7 +241,7 @@ InstallerManager::Construct(const String& path, InstallerOperation operation, In __pContext->SetCurrentInstallationStep(INSTALLER_STEP_INIT_UNINSTALL); __pContext->__packageId = newPath; - SendEvent(__pContext, __pContext->__packageId, "start", "uninstall"); + SendEvent(__pContext->__pPkgmgrInstaller, __pContext->__packageId, "start", "uninstall"); } else if (operation == INSTALLER_OPERATION_REINSTALL) { @@ -235,17 +252,11 @@ InstallerManager::Construct(const String& path, InstallerOperation operation, In __pContext->SetCurrentInstallationStep(INSTALLER_STEP_RDS_INIT); __pContext->__packageId = newPath; - SendEvent(__pContext, __pContext->__packageId, "start", "install"); + SendEvent(__pContext->__pPkgmgrInstaller, __pContext->__packageId, "start", "install"); } __pContext->SetInstallerOperation(operation); - if (option & INSTALLER_OPTION_HYBRID) - { - AppLog("Request to install HybridService app!"); - __pContext->__isHybridService = true; - } - __pInstaller = CreateInstaller(installerType); TryReturn(__pInstaller, INSTALLER_ERROR_INTERNAL_STATE, "__pInstaller is null."); @@ -322,7 +333,7 @@ InstallerManager::GetNext(void) InstallerError InstallerManager::Init(void) { - SendEvent(__pContext, __pContext->__packageId, "install_percent", "0"); + SendEvent(__pContext->__pPkgmgrInstaller, __pContext->__packageId, "install_percent", "0"); return __pInstaller->OnInit(); } @@ -335,7 +346,7 @@ InstallerManager::Error(void) InstallerError InstallerManager::Register(void) { - SendEvent(__pContext, __pContext->__packageId, "install_percent", "60"); + SendEvent(__pContext->__pPkgmgrInstaller, __pContext->__packageId, "install_percent", "60"); return __pInstaller->OnRegister(); } @@ -364,6 +375,9 @@ InstallerManager::Activate(void) IInstallationStep* pStep = null; InstallationStep currentStep; + SmackManager smackManager; + smackManager.Begin(); + while (__pContext->GetState() == INSTALLER_STATE_RUNNING) { currentStep = GetNext(); @@ -413,10 +427,11 @@ InstallerManager::Activate(void) } CATCH: + smackManager.End(); if (error == INSTALLER_ERROR_NONE) { - SendEvent(__pContext, __pContext->__packageId, "install_percent", "100"); - SendEvent(__pContext, __pContext->__packageId, "end", "ok"); + SendEvent(__pContext->__pPkgmgrInstaller, __pContext->__packageId, "install_percent", "100"); + SendEvent(__pContext->__pPkgmgrInstaller, __pContext->__packageId, "end", "ok"); } else { @@ -428,8 +443,8 @@ CATCH: errorString += L":"; errorString += __pContext->__additionalErrorString; } - SendEvent(__pContext, __pContext->__packageId, "error", errorString); - SendEvent(__pContext, __pContext->__packageId, "end", "fail"); + SendEvent(__pContext->__pPkgmgrInstaller, __pContext->__packageId, "error", errorString); + SendEvent(__pContext->__pPkgmgrInstaller, __pContext->__packageId, "end", "fail"); } return error; @@ -541,7 +556,7 @@ InstallerManager::ParseOptionalData(const String* pOptionalData) int InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, InstallerOption& option) { - const char* pOpts_str = "u:i:r:v:m:c"; + const char* pOpts_str = "u:i:r:v:m:c:b"; int s = 0; if (mode == NULL) @@ -581,7 +596,10 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, I } else { - strncpy(buf, optarg, BUFSIZE); + if (optarg) + { + strncpy(buf, optarg, BUFSIZE); + } AppLog("__osp_installer_parse_options: optarg = [%s]", optarg); } break; @@ -604,7 +622,10 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, I } else { - strncpy(buf, optarg, BUFSIZE); + if (optarg) + { + strncpy(buf, optarg, BUFSIZE); + } AppLog("__osp_installer_parse_options: optarg = [%s]", optarg); } break; @@ -617,7 +638,10 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, I AppLog("__osp_installer_parse_options: r"); *mode = INSTALLER_MODE_REINSTALL; - strncpy(buf, optarg, BUFSIZE); + if (optarg) + { + strncpy(buf, optarg, BUFSIZE); + } AppLog("__osp_installer_parse_options: optarg = [%s]", optarg); break; @@ -635,7 +659,10 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, I AppLog("__osp_installer_parse_options: m"); *mode = INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL; - strncpy(buf, optarg, BUFSIZE); + if (optarg) + { + strncpy(buf, optarg, BUFSIZE); + } AppLog("__osp_installer_parse_options: optarg = [%s]", optarg); break; @@ -649,8 +676,21 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, I option = (InstallerOption)(option | INSTALLER_OPTION_UPDATE_STDOUT); option = (InstallerOption)(option | INSTALLER_OPTION_CSC); *mode = INSTALLER_MODE_PARSE_CSC_STRING; - AppLog("__osp_installer_parse_options: argv[optind] = [%s]", argv[optind]); - strncpy(buf, argv[optind], BUFSIZE); + AppLog("__osp_installer_parse_options: optarg = [%s]", optarg); + if (optarg) + { + strncpy(buf, optarg, BUFSIZE); + } + break; + + case 'b': + if (*mode) + { + break; + } + + AppLog("__osp_installer_parse_options: b"); + *mode = INSTALLER_MODE_RECOVERY; break; @@ -670,25 +710,6 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, I return 0; } -bool -InstallerManager::RemoveGarbage(const String& filePath) -{ - AppLog("RemoveGarbage Directory = [%ls]", filePath.GetPointer()); - - String realPath; - if (InstallerUtil::IsSymlink(filePath) == true) - { - if (InstallerUtil::GetRealPath(filePath, realPath) == true) - { - InstallerUtil::Remove(realPath); - } - } - - InstallerUtil::Remove(filePath); - - return true; -} - int InstallerManager::ReqeustByTest(void) { @@ -724,11 +745,11 @@ InstallerManager::ReqeustByTest(void) } else if (readBuf[0] == '>') { - errorType = InstallerManager::RequestMove(path, PM_MOVE_TO_SDCARD); + errorType = InstallerManager::RequestMove(path, PM_MOVE_TO_SDCARD, null); } else if (readBuf[0] == '<') { - errorType = InstallerManager::RequestMove(path, PM_MOVE_TO_INTERNAL); + errorType = InstallerManager::RequestMove(path, PM_MOVE_TO_INTERNAL, null); } else if (readBuf[0] == '#') { @@ -772,21 +793,30 @@ InstallerManager::PrintResult(void) } String error = GetErrorString(errorType); - int duration = (int)(__endTick - __startTick); + String duration; + duration.Format(128, L"%d", (int)(__endTick - __startTick)); + int durationLen = duration.GetLength(); + + for (int i = durationLen - 3; i > 0; i = i - 3) + { + duration.Insert(L",", i); + } + + duration += L"ms"; AppLog("=========================================="); AppLog(" # osp-installer: %s", OSP_INSTALLER_VERSION); AppLog("------------------------------------------"); AppLog(" # Operation = [%s]", pOperation); - AppLog(" # Package = [%ls](%ls)", pPackageId, pPackageSize); + AppLog(" # Package = [%ls(%ls)]", pPackageId, pPackageSize); AppLog(" # Apps = [%ls]", pAppInfoStr); - AppLog(" # Time = [%d]ms", duration); + AppLog(" # Time = [%ls]", duration.GetPointer()); AppLog(" # Result = [%ls(%03d)]", error.GetPointer(), errorType); AppLog("=========================================="); - fprintf(stderr, " ## osp-installer: package=[%ls](%ls) operation=[%s] result=[%ls](%03d)\n", + fprintf(stderr, " ## osp-installer: package=[%ls(%ls)] operation=[%s] result=[%ls(%03d)]\n", pPackageId, pPackageSize, pOperation, error.GetPointer(), errorType); - fprintf(stderr, " ## osp-installer: apps=[%ls] time=[%d]ms\n", pAppInfoStr, duration); + fprintf(stderr, " ## osp-installer: apps=[%ls] time=[%ls]\n", pAppInfoStr, duration.GetPointer()); } String @@ -906,9 +936,10 @@ InstallerManager::GetAppInfoString() } appInfoStr += pAppData->__name; - if (pAppData->__main.Equals("True", false) == true) + + if ((__pContext->__isHybridService == false) && (pAppData->__main.Equals("True", false) == true)) { - appInfoStr += L"(main)"; + appInfoStr += L"{main}"; } String sizeStr = L"(" + InstallerUtil::GetDisplaySize(destPath) + L")"; @@ -967,26 +998,37 @@ InstallerManager::IsHistoryFileLogOn() const } bool -InstallerManager::SendEvent(InstallationContext* pContext, const PackageId& packageId, const String& key, const String& val) +InstallerManager::SendEvent(void* pPkgmgrInstaller, const PackageId& packageId, const String& key, const String& val) { - TryReturn(pContext, false, "pContext is null."); + TryReturn(pPkgmgrInstaller, false, "pPkgmgrInstaller is null."); TryReturn(key.IsEmpty() == false, false, "key is empty."); TryReturn(val.IsEmpty() == false, false, "val is empty."); + + InstallerManager* pInstallManager = InstallerManager::GetInstance(); + InstallationContext* pContext = pInstallManager->GetContext(); + InstallerOperation operation = pContext->GetInstallerOperation(); - if (pContext->__pPkgmgrInstaller == null) + if (pContext) { - AppLog("pContext->__pPkgmgrInstaller is null. [%ls]", packageId.GetPointer()); - return false; + InstallerOperation operation = pContext->GetInstallerOperation(); + if (operation == INSTALLER_OPERATION_UNINSTALL) + { + if (key == L"install_percent") + { + AppLog("install_percent is skipped. [%ls]", packageId.GetPointer()); + return true; + } + } } - if (operation == INSTALLER_OPERATION_UNINSTALL) + String value = val; + if (val == L"install") { - if (key == L"install_percent") + if (_PackageManagerImpl::GetInstance()->IsPackageInstalled(packageId) == true) { - AppLog("install_percent is skipped. [%ls]", packageId.GetPointer()); - return true; + value = L"update"; } } @@ -996,10 +1038,10 @@ InstallerManager::SendEvent(InstallationContext* pContext, const PackageId& pack std::unique_ptr pKey(_StringConverter::CopyToCharArrayN(key)); TryReturn(pKey, false, "pKey is null."); - std::unique_ptr pVal(_StringConverter::CopyToCharArrayN(val)); + std::unique_ptr pVal(_StringConverter::CopyToCharArrayN(value)); TryReturn(pVal, false, "pVal is null."); - pkgmgr_installer_send_signal((pkgmgr_installer*) pContext->__pPkgmgrInstaller, "tpk", pPackageId.get(), pKey.get(), pVal.get()); + pkgmgr_installer_send_signal((pkgmgr_installer*) pPkgmgrInstaller, "tpk", pPackageId.get(), pKey.get(), pVal.get()); AppLog("pkgmgr_installer_send_signal(tpk, %s, %s, %s)", pPackageId.get(), pKey.get(), pVal.get()); return true; @@ -1126,6 +1168,19 @@ CATCH: InstallerUtil::Remove(pInstallManager->GetHistoryLogFilePath()); } + InstallationContext* pContext = pInstallManager->GetContext(); + if (pContext && pContext->__packageId.IsEmpty() == false) + { + String installFlag = DIR_RECOVERY_TPK; + installFlag += L"/"; + installFlag += pContext->__packageId; + + if (File::IsFileExist(installFlag) == true) + { + InstallerUtil::Remove(installFlag); + } + } + pInstallManager->Release(); } @@ -1143,6 +1198,57 @@ CATCH: } int +InstallerManager::RequestHybrid(int operation, char* pkgPath, int apiVisibility) +{ + InstallerError errorType = INSTALLER_ERROR_NONE; + InstallerOption option = INSTALLER_OPTION_NORMAL; + Tizen::Base::_ApiVisibility nativeApiVisiblity = _API_VISIBILITY_PUBLIC; + + if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true) + { + InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP); + } + + if (File::IsFileExist(DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP) == true) + { + InstallerUtil::Remove(DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP); + } + + option = (InstallerOption)(option | INSTALLER_OPTION_HYBRID | INSTALLER_OPTION_UPDATE_STDOUT); + AppLog("Hybrid Installation option = [%d]", (int)option); + + std::unique_ptr< HybridInstaller > pHybridInstaller(new (std::nothrow) HybridInstaller); + TryCatch(pHybridInstaller != null , errorType = INSTALLER_ERROR_OUT_OF_MEMORY, "[INSTALLER_ERROR_OUT_OF_MEMORY]Failed to allocate memory"); + + nativeApiVisiblity = InstallerUtil::ConvertToNativeApiVisibility(apiVisibility); + TryCatch(nativeApiVisiblity != _API_VISIBILITY_NONE, errorType = INSTALLER_ERROR_SIGNATURE_INVALID, "Invalid apiVisibility"); + + AppLog(" Api visibility is %d", nativeApiVisiblity); + + errorType = pHybridInstaller->RequestHybridAppInstallation(operation, pkgPath, nativeApiVisiblity); + TryCatch(errorType == INSTALLER_ERROR_NONE, , "Hybrid Package Installation failed."); + +CATCH: + if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true) + { + InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP); + } + + if (File::IsFileExist(DIR_MEMORYCARD_OSP_APPLICATIONS) == true) + { + InstallerUtil::Remove(DIR_MEMORYCARD_OSP_APPLICATIONS); + } + + if (option & INSTALLER_OPTION_UPDATE_STDOUT) + { + AppLog("stdout is updated by errorType [%d]", errorType); + fprintf(stdout, "%d", errorType); + } + + return errorType; +} + +int InstallerManager::RequestRecursiveDirectory(const Tizen::Base::String& path, int& errorType) { Directory* pDir = null; @@ -1279,6 +1385,16 @@ InstallerManager::RequestByCommand(int argc, char **argv) } break; + case INSTALLER_MODE_RECOVERY: + { + AppLog("------------------------------------------"); + AppLog(" # Recovery"); + + option = (InstallerOption)(option | INSTALLER_OPTION_FILELOG_ON); + errorType = InstallerManager::RequestRecovery(); + } + break; + case INSTALLER_MODE_UNINSTALL: { AppLog("------------------------------------------"); @@ -1336,8 +1452,9 @@ InstallerManager::RequestByCommand(int argc, char **argv) } int -InstallerManager::RequestMove(const PackageId& packageId, int moveType) +InstallerManager::RequestMove(const PackageId& packageId, int moveType, void* pPkgmgrInstaller) { + TryReturn(packageId.IsEmpty() == false, INSTALLER_ERROR_INTERNAL_STATE, "packageId is empty."); result r = E_SUCCESS; int res = 0; InstallerError errorType = INSTALLER_ERROR_NONE; @@ -1350,8 +1467,10 @@ InstallerManager::RequestMove(const PackageId& packageId, int moveType) _PackageInfoImpl* pPackageInfoImpl = null; String rootPath; + SendEvent(pPkgmgrInstaller, packageId, "start", "move"); + std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(packageId)); - TryReturn(pPackageId, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageId is null"); + TryReturn(pPackageId, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageId is null."); if (moveType == PM_MOVE_TO_INTERNAL) { @@ -1359,15 +1478,16 @@ InstallerManager::RequestMove(const PackageId& packageId, int moveType) } pPackageInfo = _PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId); - TryCatch(pPackageInfo != null, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetPackageInfoN() failed"); + TryCatch(pPackageInfo != null, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetPackageInfoN() failed.") pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo); - TryCatch(pPackageInfoImpl, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetInstance() failed"); + TryCatch(pPackageInfoImpl, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetInstance() failed.") rootPath = pPackageInfoImpl->GetAppRootPath(); + TryCatch(rootPath.IsEmpty() == false, errorType = INSTALLER_ERROR_INTERNAL_STATE, "rootPath is empty."); pHandle = app2ext_init(APP2EXT_SD_CARD); - TryCatch(pHandle, errorType = INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed"); + TryCatch(pHandle, errorType = INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed."); if (location == APP2EXT_MOVE_TO_PHONE) { @@ -1375,13 +1495,13 @@ InstallerManager::RequestMove(const PackageId& packageId, int moveType) } pDir = new (std::nothrow) Directory; - TryCatch(pDir, errorType = INSTALLER_ERROR_OUT_OF_MEMORY, "pDir is null"); + 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"); + TryCatch(pDirEnum, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirEnum is null."); while (pDirEnum->MoveNext() == E_SUCCESS) { @@ -1408,7 +1528,7 @@ InstallerManager::RequestMove(const PackageId& packageId, int moveType) 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"); + TryCatch(pDirDetails, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirDetails is null."); length = entryName.GetLength(); pDirDetails->name = (char*) calloc(1, (sizeof(char) * length) + 1); @@ -1433,8 +1553,10 @@ InstallerManager::RequestMove(const PackageId& packageId, int moveType) pDirectoryList = g_list_append(pDirectoryList, pDirDetails); } + AppLog("[app2sd] pHandle->interface.move(%s, %d)", pPackageId.get(), (int)location); res = pHandle->interface.move(pPackageId.get(), pDirectoryList, location); - TryCatch(res == 0, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.move() failed [%d]", res); + TryCatch(res == 0, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.move() failed. res = [%d]", res); + AppLog("[app2sd] pHandle->interface.move(), res = [%d]", res); CATCH: if (pHandle) @@ -1464,6 +1586,15 @@ CATCH: delete pDir; delete pPackageInfo; + if (errorType == INSTALLER_ERROR_NONE) + { + SendEvent(pPkgmgrInstaller, packageId, "end", "ok"); + } + else + { + SendEvent(pPkgmgrInstaller, packageId, "end", "fail"); + } + return errorType; } @@ -1532,3 +1663,44 @@ InstallerManager::RequestCsc(const String& buffer, InstallerOption option, void* return errorType; } + +int +InstallerManager::RequestRecovery() +{ + int errorType = 0; + + std::unique_ptr pDir(new (std::nothrow) Directory); + TryReturn(pDir, INSTALLER_ERROR_OUT_OF_MEMORY, "pDir is null."); + + result r = pDir->Construct(DIR_RECOVERY_TPK); + TryReturn(!IsFailed(r), INSTALLER_ERROR_FATAL_ERROR, "pDir->Construct() failed. path = [%s]", DIR_RECOVERY_TPK); + + std::unique_ptr pDirEnum(pDir->ReadN()); + TryReturn(pDirEnum, INSTALLER_ERROR_FATAL_ERROR, "pDirEnum is null."); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String srcEntryDir = DIR_RECOVERY_TPK; + srcEntryDir += L"/"; + srcEntryDir += entryName; + + if (entryName == L"." || entryName == L"..") + { + continue; + } + +#if 0 + PackageId packageId = entryName; + + ConfigurationManager configurationManager; + configurationManager.RemoveGarbage(packageId); +#endif + + InstallerUtil::Remove(srcEntryDir); + } + + return errorType; +} diff --git a/src/Manager/InstallerManager.h b/src/Manager/InstallerManager.h index 20b5c8b..8cf85b8 100755 --- a/src/Manager/InstallerManager.h +++ b/src/Manager/InstallerManager.h @@ -59,15 +59,18 @@ public: bool IsFileLogOn() const; bool IsHistoryFileLogOn() const; - static bool SendEvent(InstallationContext* pContext, const Tizen::App::PackageId& packageId, const Tizen::Base::String& key, const Tizen::Base::String& val); + static bool SendEvent(void* pPkgmgrInstaller, const Tizen::App::PackageId& packageId, const Tizen::Base::String& key, const Tizen::Base::String& val); static bool IsUninstallUpdates(const Tizen::App::PackageId& packageId, Tizen::Base::String& originPath, bool& isCscPackage); static int Request(const Tizen::Base::String& path, InstallerOperation operation, InstallerOption option, void* pPkgmgrInstaller, const Tizen::Base::String* pOptionalData = null); 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); + static int RequestMove(const Tizen::App::PackageId& packageId, int moveType, void* pPkgmgrInstaller); static int RequestCsc(const Tizen::Base::String& buffer, InstallerOption option, void* pPkgmgrInstaller = null); + static int RequestRecovery(void); + static int RequestHybrid(int Operation, char* path, int apiVisibility = API_VISIBILITY_PUBLIC); + private: InstallerManager(const InstallerManager& value); diff --git a/src/Manager/PermissionManager.cpp b/src/Manager/PermissionManager.cpp index 2712301..a83ed99 100755 --- a/src/Manager/PermissionManager.cpp +++ b/src/Manager/PermissionManager.cpp @@ -304,6 +304,8 @@ PermissionManager::CopyForRds(InstallationContext* pContext, IList* pFileList, b result r = E_SUCCESS; String destDir; + AppLog("copy file from[%ls] to[%ls]", srcFile.GetPointer(), destFile.GetPointer()); + if (destFile.EndsWith(L"/") == true) { destDir = destFile; diff --git a/src/Manager/SignatureManager.cpp b/src/Manager/SignatureManager.cpp index a7682c2..0f1e590 100755 --- a/src/Manager/SignatureManager.cpp +++ b/src/Manager/SignatureManager.cpp @@ -69,9 +69,10 @@ SignatureManager::ValidateSignatures() std::string("/usr/share/wrt-engine/fingerprint_list.xml"), std::string("/usr/share/wrt-engine/fingerprint_list.xsd"), std::string("/opt/dbspace/.cert_svc_vcore.db")); - TryReturn(res, false, "ValidationCore::VCoreInit() is failed."); + // TryReturn(res, false, "ValidationCore::VCoreInit() is failed."); + AppLog("ValidationCore::VCoreInit() returns %d", res); + TryReturn(__pContext->__rootPath.IsEmpty() == false, false, "__pContext->__rootPath is empty."); - AppLog("ValidationCore::VCoreInit() is done"); std::unique_ptr pRootPath(_StringConverter::CopyToCharArrayN(__pContext->__rootPath)); TryReturn(pRootPath, false, "__pRootPath is null."); @@ -290,11 +291,13 @@ SignatureManager::ValidatePartialReferences(const String& path, IList* pAddedLis rootPath += "/"; AppLog("rootPath = [%s]", rootPath.c_str()); - bool res = ValidationCore::VCoreInit( + bool res = false; + res = ValidationCore::VCoreInit( std::string("/usr/share/wrt-engine/fingerprint_list.xml"), std::string("/usr/share/wrt-engine/fingerprint_list.xsd"), std::string("/opt/dbspace/.cert_svc_vcore.db")); - TryReturn(res, false, "ValidationCore::VCoreInit() failed."); + // TryReturn(res, false, "ValidationCore::VCoreInit() failed."); + AppLog("ValidationCore::VCoreInit() returns %d", res); ValidationCore::SignatureFinder::Result findRes = ValidationCore::SignatureFinder::NO_ERROR; ValidationCore::SignatureFinder signatureFinder(rootPath); @@ -383,7 +386,12 @@ SignatureManager::ValidatePartialReferences(const String& path, IList* pAddedLis } } } - TryReturn(uriList.size() != 0, false, "uriList.size is 0."); + + if (uriList.size() == 0) + { + AppLog("Need not to check AddedList, ModifiedList. uriList.size is 0."); + return true; + } AppLog("uriList.size = [%d]", uriList.size()); valRes = validator.checkList(data, rootPath, uriList); @@ -423,12 +431,6 @@ SignatureManager::RegisterCertInfo() const { TryReturn(__pContext, false, "__pContext is null"); - if (__pContext->__isHybridService == true) - { - AppLog("Skip - HybridService"); - return true; - } - AppLog("START"); int error = 0; @@ -484,12 +486,6 @@ SignatureManager::UnregisterCertInfo() const { TryReturn(__pContext, false, "__pContext is null"); - if (__pContext->__isHybridService == true) - { - AppLog("Skip - HybridService"); - return true; - } - AppLog("START"); int error = 0; std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(__pContext->__packageId)); @@ -552,7 +548,7 @@ SignatureManager::GetApiVisibility(RootCertificateType certType) int SignatureManager::GetPrivilegeLevel(int apiVisibility) { - if (apiVisibility == _API_VISIBILITY_PARTNER_MANUFACTURER || apiVisibility == _API_VISIBILITY_PARTNER_OPERATOR) + if (apiVisibility == _API_VISIBILITY_PLATFORM) { return PRIVILEGE_LEVEL_PLATFORM; } diff --git a/src/Manager/SmackManager.cpp b/src/Manager/SmackManager.cpp index 2946dbc..16b7abe 100755 --- a/src/Manager/SmackManager.cpp +++ b/src/Manager/SmackManager.cpp @@ -306,6 +306,26 @@ SmackManager::SetupPath(const PackageId& packageId, const String& dirPath, app_p return true; } +bool +SmackManager::Begin(void) +{ + AppLog("[smack] perm_begin()"); + int ret = perm_begin(); + AppLog("[smack] perm_begin(), result = [%d]", ret); + + return true; +} + +bool +SmackManager::End(void) +{ + AppLog("[smack] perm_end()"); + int ret = perm_end(); + AppLog("[smack] perm_end(), result = [%d]", ret); + + return true; +} + int SmackManager::Install(const char* pPackageId) { @@ -329,9 +349,9 @@ SmackManager::Uninstall(const char* pPackageId) int SmackManager::AddLabelDir(const char* pLabel, const char* pDirPath) { - AppLog("[smack] perm_app_setup_path(\"*\", %s, APP_PATH_ANY_LABEL, %s)", pDirPath, pLabel); - int ret = perm_app_setup_path("*", pDirPath, APP_PATH_ANY_LABEL, pLabel); - AppLog("[smack] perm_app_setup_path(\"*\", %s, APP_PATH_ANY_LABEL, %s), result = [%d]", pDirPath, pLabel, ret); + AppLog("[smack] app_label_dir(%s, %s)", pLabel, pDirPath); + int ret = app_label_dir(pLabel, pDirPath); + AppLog("[smack] app_label_dir(%s, %s), result = [%d]", pLabel, pDirPath, ret); return ret; } diff --git a/src/Manager/SmackManager.h b/src/Manager/SmackManager.h index 8941d07..890b420 100755 --- a/src/Manager/SmackManager.h +++ b/src/Manager/SmackManager.h @@ -47,6 +47,9 @@ public: bool SetupPath(const Tizen::App::PackageId& packageId, const Tizen::Base::String& dirPath, app_path_type_t type, const Tizen::Base::String& label = L""); + bool Begin(void); + bool End(void); + private: int Install(const char* pPackageId); int Uninstall(const char* pPackageId); diff --git a/src/Step/SystemCheckStep.cpp b/src/Step/SystemCheckStep.cpp index ce923ed..ce32abd 100755 --- a/src/Step/SystemCheckStep.cpp +++ b/src/Step/SystemCheckStep.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -28,11 +29,13 @@ #include "InstallationContext.h" #include "SystemCheckStep.h" #include "DatabaseManager.h" +#include "CompatibilityManager.h" using namespace Tizen::App; using namespace Tizen::App::Package; using namespace Tizen::Base; using namespace Tizen::Base::Collection; +using namespace Tizen::Io; SystemCheckStep::SystemCheckStep(void) :__state(STATE_VERSION_CHECK) @@ -153,6 +156,24 @@ SystemCheckStep::OnStateVersionCheck(void) result = InstallerUtil::TerminateApp(appId); TryReturn(result == true, INSTALLER_ERROR_FATAL_ERROR, "TerminateApp(%ls) failed.", appId.GetPointer()); } + + CompatibilityManager compatibilityManager; + compatibilityManager.Construct(__pContext); + + String rootPath = pPackageInfoImpl->GetAppRootPath(); + String compatPath = rootPath + L"/info/compat.info"; + if (File::IsFileExist(compatPath) == true) + { + result = compatibilityManager.FinalizeDataCaging(rootPath); + TryReturn(result == true, INSTALLER_ERROR_UNMOUNT_FAILED, "FinalizeDataCaging(%ls) failed.", rootPath.GetPointer()); + } + + String virtualRootInfoFile = rootPath + VIRTUAL_ROOT_INFO_FILE; + if (File::IsFileExist(virtualRootInfoFile) == true) + { + result = compatibilityManager.FinalizeVirtualRoot(rootPath, __pContext->__packageId); + TryReturn(result == true, INSTALLER_ERROR_UNMOUNT_FAILED, "FinalizeVirtualRoot(%ls) failed.", rootPath.GetPointer()); + } } GoNextState(); diff --git a/src/Step/UninstallStep.cpp b/src/Step/UninstallStep.cpp index 36d1993..a653d2a 100755 --- a/src/Step/UninstallStep.cpp +++ b/src/Step/UninstallStep.cpp @@ -119,6 +119,8 @@ UninstallStep::GoNextState(void) InstallerError UninstallStep::OnStateGetPackageInfo(void) { + bool res = true; + result r = E_SUCCESS; InstallerError error = INSTALLER_ERROR_NONE; PackageId packageId = __pContext->__packageId; @@ -127,7 +129,7 @@ UninstallStep::OnStateGetPackageInfo(void) AppLog("package = %ls", packageId.GetPointer()); - result r = pPackageInfoImpl->Construct(packageId); + r = pPackageInfoImpl->Construct(packageId); TryReturn(r == E_SUCCESS, INSTALLER_ERROR_INTERNAL_STATE, "pPackageInfoImpl->Construct(%ls) failed.", packageId.GetPointer()); // bool isUninstallable = pPackageInfoImpl->IsUninstallable(); @@ -145,14 +147,10 @@ UninstallStep::OnStateGetPackageInfo(void) __pContext->__isPreloaded = true; } - __pContext->__rootPath = pPackageInfoImpl->GetAppRootPath(); + //res = IsAvailableUninstall(); + //TryReturn(res == true, INSTALLER_ERROR_DISABLED, "IsAvailableUninstall(%ls) failed.", packageId.GetPointer()); - if (__pContext->__isHybridService == true) - { - AppLog("Uninstallation for HybridService"); - __state = STATE_TERMINATE_APP; - return error; - } + __pContext->__rootPath = pPackageInfoImpl->GetAppRootPath(); if (pPackageInfoImpl->IsInstalledInExternalStorage() == true) { @@ -212,7 +210,7 @@ UninstallStep::OnStateTerminateApp(void) { InstallerError error = INSTALLER_ERROR_NONE; - InstallerUtil::TerminateApps(__pContext->__packageId); + InstallerUtil::TerminateApps(__pContext->__packageId, true); GoNextState(); return error; @@ -271,25 +269,18 @@ UninstallStep::OnStateRemoveDir(void) AppLog("Directory::Remove - START"); - if (__pContext->__isHybridService == true) + String realPath; + if (InstallerUtil::IsSymlink(rootPath) == true) { - AppLog("Uninstallation for HybridService - skip Remove"); - - } - else - { - String realPath; - if (InstallerUtil::IsSymlink(rootPath) == true) + if (InstallerUtil::GetRealPath(rootPath, realPath) == true) { - if (InstallerUtil::GetRealPath(rootPath, realPath) == true) - { - InstallerUtil::Remove(realPath); - } + InstallerUtil::Remove(realPath); } - - InstallerUtil::Remove(rootPath); } + InstallerUtil::Remove(rootPath); + + IListT* pAppDataList = __pContext->__pAppDataList; TryReturn(pAppDataList, INSTALLER_ERROR_INTERNAL_STATE, "pAppDataList is null"); diff --git a/src/Step/UnpackStep.cpp b/src/Step/UnpackStep.cpp index 386538e..f9aa042 100755 --- a/src/Step/UnpackStep.cpp +++ b/src/Step/UnpackStep.cpp @@ -135,12 +135,14 @@ UnpackStep::OnStateBackup(void) { InstallerError error = INSTALLER_ERROR_NONE; +#if 0 if ((__pContext->__isUpdated == true) && (__pContext->__isPreloaded == false)) { ConfigurationManager configurationManager; bool res = configurationManager.CreateBackup(__pContext); TryReturn(res == true, INSTALLER_ERROR_BACKUP_FAILED, "configurationManager.CreateBackup(%ls) failed.", __pContext->__packageId.GetPointer()); } +#endif GoNextState(); return error; diff --git a/src/Util/InstallerUtil.cpp b/src/Util/InstallerUtil.cpp index b2086ee..1cb0c4d 100755 --- a/src/Util/InstallerUtil.cpp +++ b/src/Util/InstallerUtil.cpp @@ -44,6 +44,7 @@ #include "InstallerUtil.h" #include "InstallerManager.h" #include "SmackManager.h" +#include "DatabaseManager.h" using namespace Tizen::Base; using namespace Tizen::Base::Collection; @@ -574,6 +575,35 @@ InstallerUtil::CreateInfoFile(const String& filePath, const String* pContext) } bool +InstallerUtil::CreateFlagFile(const String& filePath) +{ + bool res = true; + int fd = -1; + FILE* pFile = null; + File file; + + std::unique_ptr pFilePath(_StringConverter::CopyToCharArrayN(filePath)); + TryCatch(pFilePath, res = false, "pFilePath is null."); + + pFile = fopen(pFilePath.get(), "w"); + TryCatch(pFile, res = false, "fopen(%s, w) failed.", pFilePath.get()); + + fd = fileno(pFile); + TryCatch(fd != -1, res = false, "fileno(%s) failed.", pFilePath.get()); + + fsync(fd); + AppLog("CreateFlagFile(), filePath = [%ls]", filePath.GetPointer()); + +CATCH: + if (pFile) + { + fclose(pFile); + } + + return res; +} + +bool InstallerUtil::DumpLog(const char* pBuf) { TryReturn(pBuf, false, "pBuf is null"); @@ -1076,7 +1106,7 @@ InstallerUtil::TerminateApp(const AppId& appId) } bool -InstallerUtil::TerminateApps(const PackageId& packageId) +InstallerUtil::TerminateApps(const PackageId& packageId, bool DisableAutoRestart) { std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId)); TryReturn(pPackageInfo, false, "GetPackageInfoN() failed."); @@ -1093,6 +1123,24 @@ InstallerUtil::TerminateApps(const PackageId& packageId) TryReturn(pPackageAppInfo, false, "pPackageAppList->GetAt(%d) failed.", i); AppId appId = pPackageAppInfo->GetAppId(); + + if (DisableAutoRestart == true) + { + _PackageAppInfoImpl* pAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo); + TryReturn(pAppInfoImpl, false, "pAppInfoImpl is null."); + + String key("AutoRestart"); + if (pAppInfoImpl->GetAppFeature(key) == L"True") + { + AppLog("AutoRestart = [True]"); + + DatabaseManager databaseManager; + databaseManager.DisableAutoRestart(appId); + + AppLog("AutoRestart[%ls] is updated.", pAppInfoImpl->GetAppFeature(key).GetPointer()); + } + } + TerminateApp(appId); } @@ -1316,7 +1364,7 @@ InstallerUtil::GetDisplaySize(const Tizen::Base::String& path) FileAttributes attr; r = File::GetAttributes(path, attr); - TryReturn(!IsFailed(r), unitStr, "File::GetAttributes() failed"); + TryReturn(!IsFailed(r), L"0.0KB", "File::GetAttributes() failed"); if (attr.IsDirectory()) { @@ -1324,36 +1372,60 @@ InstallerUtil::GetDisplaySize(const Tizen::Base::String& path) // root directory size += INSTALLER_BLOCK_SIZE; - AppLog("DIR=%ls, size=%d[%d KB],", path.GetPointer(), (int)size, (int)(size/1024)); + AppLog("DIR=%ls, size=%d[%dKB],", path.GetPointer(), (int)size, (int)(size/1024)); } else { size = attr.GetFileSize(); } - if (size >= 1024*1024*1024) + sizeRes = size / 1024.0; + + String resStr; + resStr.Format(128, L"%.1f", sizeRes); + + int strLen = resStr.GetLength(); + + for (int i = strLen - 5; i > 0; i = i - 3) { - sizeRes = size / (1024*1024*1024.0); - unitStr = L"GB"; + resStr.Insert(L",", i); } - else if (size >= 1024*1024) + + resStr += L"KB"; + + return resStr; +} + +Tizen::Base::_ApiVisibility +InstallerUtil::ConvertToNativeApiVisibility(int apiVisibility) +{ + switch(apiVisibility) { - sizeRes = size / (1024*1024.0); - unitStr = L"MB"; + case API_VISIBILITY_PUBLIC: + return Tizen::Base::_API_VISIBILITY_PUBLIC; + + case API_VISIBILITY_PARTNER: + return Tizen::Base::_API_VISIBILITY_PARTNER; + + case API_VISIBILITY_PLATFORM: + return Tizen::Base::_API_VISIBILITY_PLATFORM; + + default: + return Tizen::Base::_API_VISIBILITY_NONE; } - else if (size >= 1024) +} + +int +InstallerUtil::GetPrivilegeLevel(int apiVisibility) +{ + if (apiVisibility == _API_VISIBILITY_PLATFORM) { - sizeRes = size / 1024.0; - unitStr = L"KB"; + return PRIVILEGE_LEVEL_PLATFORM; } - else + else if (apiVisibility == _API_VISIBILITY_PARTNER) { - sizeRes = size; - unitStr = L"B"; + return PRIVILEGE_LEVEL_PARTNER; } - String resStr; - resStr.Format(128, L"%.1f %ls", sizeRes, unitStr.GetPointer()); - - return resStr; + return PRIVILEGE_LEVEL_PUBLIC; } diff --git a/src/Util/InstallerUtil.h b/src/Util/InstallerUtil.h index c114da1..2223055 100755 --- a/src/Util/InstallerUtil.h +++ b/src/Util/InstallerUtil.h @@ -24,6 +24,7 @@ #define _INSTALLER_UTIL_H_ #include +#include namespace Tizen { namespace Base { @@ -69,6 +70,7 @@ public: static bool CreateSymlinkForAppDirectory(const Tizen::Base::String& inPath, Tizen::Base::String& outPath); static bool CreateInfoFile(const Tizen::Base::String& filePath, const Tizen::Base::String* pContext); + static bool CreateFlagFile(const Tizen::Base::String& filePath); static bool DumpLog(const char* pBuf); static bool DumpLogData(char *pData, int dataLen); @@ -87,7 +89,7 @@ public: static Tizen::Base::Collection::IMap* ParseN(const Tizen::Base::String& str, const Tizen::Base::String& tokenDelimiter); static bool TerminateApp(const Tizen::App::AppId& appId); - static bool TerminateApps(const Tizen::App::PackageId& packageId); + static bool TerminateApps(const Tizen::App::PackageId& packageId, bool DisableAutoRestart = false); static bool IsUninstallable(const Tizen::App::PackageId& packageId); static bool IsCscPackage(const Tizen::App::PackageId& packageId, Tizen::Base::String& cscInfo); @@ -97,6 +99,8 @@ public: static bool IsAuthorSignatureVerificationEnabled(); static Tizen::Base::String GetDisplaySize(const Tizen::Base::String& path); static long long GetDirectorySize(const Tizen::Base::String& rootPath); + static Tizen::Base::_ApiVisibility ConvertToNativeApiVisibility(int apiVisibility); + static int GetPrivilegeLevel(int apiVisibility); private: static char LogChangeHexToStr(int hex); diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp index 36b2b39..8aec998 100755 --- a/src/backend/backend.cpp +++ b/src/backend/backend.cpp @@ -33,6 +33,7 @@ #include #include "InstallerManager.h" +#include "HybridInstaller.h" using namespace Tizen::App; using namespace Tizen::App::Package; @@ -48,19 +49,18 @@ int main(int argc, char **argv) { int ret = 0; - const char *pkg_info = null; - char* pkg_path = null; + int errorType = 0; + int reqType = 0; + int emul = 0; + const char* pPkgInfo = null; + const char* pPkgPath = null; const char* pOptional = null; const char* pStoreClientId = null; String path; String optionalData; PackageId packageId; - int errorType = 0; - pkgmgr_installer *pi = null; - int req_type = 0; appcore_set_i18n(null, null); - Osp_Initialize(); String buf; @@ -82,46 +82,91 @@ main(int argc, char **argv) } } - int emul = 0; - #ifdef _OSP_EMUL_ emul = 1; #endif - fprintf(stderr, " ## osp-installer: %s[%s] cmd=[%ls]\n", OSP_INSTALLER_VERSION, emul?"Emulator":"Target", buf.GetPointer()); + fprintf(stderr, " ## osp-installer: %s device=[%s] cmd=[%ls]\n", OSP_INSTALLER_VERSION, emul?"Emulator":"Target", buf.GetPointer()); if (argc == TEST_ARG_COUNT) { errorType = InstallerManager::ReqeustByTest(); goto CATCH; } - else if (argc == COMMAND_ARG_COUNT) + else if (argc <= COMMAND_ARG_COUNT && (!(argv[1][2] == 'v' || argv[1][1] == 'v'))) { errorType = InstallerManager::RequestByCommand(argc, argv); goto CATCH; } + else if (argv[1][2] == 'v') + { + if (argv[3] && argv[3][1] == 'p') + { + if(argv[4]) + { + errorType = InstallerManager::RequestHybrid(argv[1][1], argv[2], atoi(argv[4])); + } + else + { + errorType = INSTALLER_ERROR_SIGNATURE_NOT_FOUND; - pi = pkgmgr_installer_new(); - _pi = pi; + AppLog("stdout is updated by errorType [%d]", errorType); + fprintf(stdout, "%d", errorType); - pkgmgr_installer_receive_request(pi, argc, argv); + goto CATCH; + } + } + else + { + errorType = InstallerManager::RequestHybrid(argv[1][1], argv[2]); + } + goto CATCH; + } + else if(argv[1][1] == 'v') + { + if (argv[3] && argv[3][1] == 'p') + { + if(argv[4]) + { + errorType = InstallerManager::RequestHybrid(argv[1][1], argv[2], atoi(argv[4])); + } + else + { + errorType = INSTALLER_ERROR_SIGNATURE_NOT_FOUND; + + AppLog("stdout is updated by errorType [%d]", errorType); + fprintf(stdout, "%d", errorType); + + goto CATCH; + } + } + else + { + errorType = InstallerManager::RequestHybrid(argv[1][2], argv[2]); + } + goto CATCH; + } + + _pi = pkgmgr_installer_new(); - req_type = pkgmgr_installer_get_request_type(pi); - if (PKGMGR_REQ_INVALID >= req_type) + pkgmgr_installer_receive_request(_pi, argc, argv); + + reqType = pkgmgr_installer_get_request_type(_pi); + if (PKGMGR_REQ_INVALID >= reqType) { goto CATCH; } - pkg_info = pkgmgr_installer_get_request_info(pi); - pkg_path = (const_cast(pkg_info)); - AppLog(" # path = [%s]", pkg_path); + pPkgInfo = pkgmgr_installer_get_request_info(_pi); + pPkgPath = (const_cast(pPkgInfo)); + AppLog(" # path = [%s]", pPkgPath); - path = pkg_path; + path = pPkgPath; - switch (req_type) + switch (reqType) { case PKGMGR_REQ_INSTALL: { - pOptional = pkgmgr_installer_get_optional_data(pi); + pOptional = pkgmgr_installer_get_optional_data(_pi); if (pOptional) { optionalData = pOptional; @@ -160,7 +205,7 @@ main(int argc, char **argv) AppLog(" # path = [%ls] -> optionalData = [%ls]", path.GetPointer(), optionalData.GetPointer()); } - pStoreClientId = pkgmgr_installer_get_caller_pkgid(pi); + pStoreClientId = pkgmgr_installer_get_caller_pkgid(_pi); if (pStoreClientId) { PackageId StoreClientId = pStoreClientId; @@ -169,7 +214,7 @@ main(int argc, char **argv) AppLog(" # optionalData = [%ls]", optionalData.GetPointer()); } - errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, pi, &optionalData); + errorType = InstallerManager::Request(path, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_NORMAL, _pi, &optionalData); // if (errorType != 0) // { @@ -183,16 +228,18 @@ main(int argc, char **argv) case PKGMGR_REQ_UNINSTALL: { bool isCscPackage = false; + String originPath; PackageId reqeustPackageId; path.SubString(0, PACKAGE_ID_LENGTH, reqeustPackageId); AppLog("reqeustPackage = %ls", reqeustPackageId.GetPointer()); - String originPath; if (InstallerManager::IsUninstallUpdates(reqeustPackageId, originPath, isCscPackage) == true) { AppLog("originPath = [%ls], isCscPackage = [%s]", originPath.GetPointer(), isCscPackage?"true":"false"); optionalData = reqeustPackageId; + errorType = InstallerManager::Request(reqeustPackageId, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, _pi); + if (isCscPackage == false) { errorType = InstallerManager::Request(originPath, INSTALLER_OPERATION_INSTALL, INSTALLER_OPTION_RESET_PRELOADED, _pi, &optionalData); @@ -207,7 +254,7 @@ main(int argc, char **argv) } else { - ret = InstallerManager::Request(reqeustPackageId, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, _pi); + errorType = InstallerManager::Request(reqeustPackageId, INSTALLER_OPERATION_UNINSTALL, INSTALLER_OPTION_NORMAL, _pi); } __osp_installer_report_result(reqeustPackageId, errorType); @@ -234,7 +281,7 @@ main(int argc, char **argv) int moveType = -1; moveType = pkgmgr_installer_get_move_type(_pi); - InstallerManager::RequestMove(path, moveType); + InstallerManager::RequestMove(path, moveType, _pi); } else { -- 2.7.4