X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fjobs%2Fwidget_install%2Fjob_widget_install.cpp;h=f0a72bb2f45f115a1897e1d33190a39aa2d36bd9;hb=84b954ffd6cbf32075f723e025b9a2ea208e8189;hp=0d333f0ff5cfc8ea2e23f4bfc4d8d02bd172da5d;hpb=15fe1dad140c3cea1391a3ea61270a9d84a45fe8;p=framework%2Fweb%2Fwrt-installer.git diff --git a/src/jobs/widget_install/job_widget_install.cpp b/src/jobs/widget_install/job_widget_install.cpp old mode 100644 new mode 100755 index 0d333f0..f0a72bb --- a/src/jobs/widget_install/job_widget_install.cpp +++ b/src/jobs/widget_install/job_widget_install.cpp @@ -48,8 +48,6 @@ #include #include #include -//#include -#include //temporary code #include "root_parser.h" #include "widget_parser.h" @@ -71,8 +69,7 @@ #include #include #include - -#include +#include #include #include @@ -94,7 +91,7 @@ const size_t PACKAGE_ID_LENGTH = 10; static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption"; static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable"; const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME = - L"install-location-type"; + L"install-location"; const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT = L"prefer-external"; @@ -112,24 +109,6 @@ bool hasExtension(const std::string& filename, const std::string& extension) } return (0 == filename.compare(fileLen - extLen, extLen, extension)); } - -bool checkTizenPkgIdExist(const std::string& tizenPkgId) -{ - std::string installPath = - std::string(GlobalConfig::GetUserInstalledWidgetPath()) + - "/" + tizenPkgId; - std::string preinstallPath = - std::string(GlobalConfig::GetUserPreloadedWidgetPath()) + - "/" + tizenPkgId; - - struct stat dirStat; - if ((stat(installPath.c_str(), &dirStat) == 0) || - (stat(preinstallPath.c_str(), &dirStat) == 0)) - { - return true; - } - return false; -} } // namespace anonymous namespace Jobs { @@ -229,13 +208,19 @@ JobWidgetInstall::JobWidgetInstall( AddTask(new TaskInstallOspsvc(m_installerContext)); } AddTask(new TaskCertificates(m_installerContext)); - AddTask(new TaskPluginsCopy(m_installerContext)); AddTask(new TaskDatabase(m_installerContext)); AddTask(new TaskAceCheck(m_installerContext)); } else if (result == ConfigureResult::Updated) { LogInfo("Configure installation updated"); LogInfo("Widget Update"); m_installerContext.job->SetProgressFlag(true); + + if (m_jobStruct.m_installMode == + InstallMode::REINSTALL_MODE_DIRECTORY) + { + AddTask(new TaskPrepareReinstall(m_installerContext)); + } + if (m_installerContext.widgetConfig.packagingType != WrtDB::PKG_TYPE_HOSTED_WEB_APP && m_installerContext.widgetConfig.packagingType != @@ -254,6 +239,10 @@ JobWidgetInstall::JobWidgetInstall( } AddTask(new TaskCertify(m_installerContext)); + if (m_needEncryption) { + AddTask(new TaskEncryptResource(m_installerContext)); + } + if (m_installerContext.widgetConfig.packagingType != WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) { @@ -274,7 +263,6 @@ JobWidgetInstall::JobWidgetInstall( { AddTask(new TaskRemoveBackupFiles(m_installerContext)); } - AddTask(new TaskPluginsCopy(m_installerContext)); AddTask(new TaskDatabase(m_installerContext)); AddTask(new TaskAceCheck(m_installerContext)); //TODO: remove widgetHandle from this task and move before database task @@ -304,8 +292,22 @@ ConfigureResult JobWidgetInstall::PrePareInstallation( Try { - std::string tempDir = - Jobs::WidgetInstall::createTempPath(m_jobStruct.m_preload); + std::string tempDir; + if (m_jobStruct.m_installMode == + InstallMode::REINSTALL_MODE_DIRECTORY) + { + std::ostringstream tempPathBuilder; + tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath(); + tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath(); + tempPathBuilder << "/"; + tempPathBuilder << widgetPath; + tempDir = tempPathBuilder.str();; + } else { + tempDir = + Jobs::WidgetInstall::createTempPath( + m_jobStruct.m_installMode == + InstallMode::INSTALL_MODE_PRELOAD); + } m_isDRM = isDRMWidget(widgetPath); if (true == m_isDRM) { @@ -324,7 +326,9 @@ ConfigureResult JobWidgetInstall::PrePareInstallation( widgetPath, tempDir, m_installerContext.widgetConfig.packagingType, - m_isDRM); + m_isDRM, + m_jobStruct.m_installMode == + InstallMode::REINSTALL_MODE_DIRECTORY); LogDebug("widget packaging type : " << m_installerContext.widgetConfig.packagingType.pkgType); @@ -379,7 +383,7 @@ void JobWidgetInstall::setTizenId( TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId(); LogDebug("Checking if pkg id is unique"); while (true) { - if (checkTizenPkgIdExist(DPL::ToUTF8String(pkgId))) { + if (!validateTizenPackageID(pkgId)) { //path exist, chose another one pkgId = WidgetDAOReadOnly::generatePkgId(); continue; @@ -452,12 +456,24 @@ void JobWidgetInstall::setTizenId( void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath, const std::string& tempPath) { - m_installerContext.locations = - WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig. - tzPkgid), - widgetPath, tempPath, - m_installerContext.widgetConfig.packagingType, - m_installerContext.locationType); + if (m_jobStruct.m_installMode == + InstallMode::REINSTALL_MODE_DIRECTORY) + { + // replace widget path to installed path + m_installerContext.locations = + WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig. + tzPkgid), + widgetPath, tempPath, + m_installerContext.widgetConfig.packagingType, + m_installerContext.locationType); + } else { + m_installerContext.locations = + WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig. + tzPkgid), + widgetPath, tempPath, + m_installerContext.widgetConfig.packagingType, + m_installerContext.locationType); + } m_installerContext.locations->registerAppid( DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid)); @@ -469,154 +485,155 @@ ConfigureResult JobWidgetInstall::ConfigureInstallation( const WrtDB::ConfigParserData &configData, const std::string &tempPath) { - WidgetUpdateInfo update = detectWidgetUpdate( - configData, - m_installerContext. - widgetConfig.webAppType, - m_installerContext. - widgetConfig.tzAppid); - ConfigureResult result = checkWidgetUpdate(update); - - // Validate tizenId - regex_t reg; - if (regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) { - LogDebug("Regcomp failed"); + ConfigureResult result = ConfigureResult::Failed; + WidgetUpdateInfo update; + + // checking installed web application + Try { + // checking existing application is installed + WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid); + // no excpetion means, it isn't update mode + getInstallerStruct().pkgmgrInterface->sendSignal( + PKGMGR_START_KEY, + PKGMGR_START_UPDATE); + + update = detectWidgetUpdate(configData, + m_installerContext.widgetConfig.tzAppid); + result = checkWidgetUpdate(update); + if (result != ConfigureResult::Updated) { + // Already installed TizenAppId. return failed + return ConfigureResult::Failed_AlreadyInstalled; + } + m_installerContext.isUpdateMode = true; } + Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) { + result = ConfigureResult::Ok; + getInstallerStruct().pkgmgrInterface->sendSignal( + PKGMGR_START_KEY, + PKGMGR_START_INSTALL); + m_installerContext.isUpdateMode = false; - if ((regexec(®, - DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid). - c_str(), - static_cast(0), NULL, 0) == REG_NOMATCH) || - (checkTizenPkgIdExist(DPL::ToUTF8String(m_installerContext.widgetConfig - .tzPkgid)) && - result != ConfigureResult::Updated)) - { - //it is true when tizenId does not fit REG_TIZENID_PATTERN - LogError("tizen_id provided but not proper or pkgId directory exists"); - //TODO(t.iwanek): appId is unique, what about installation of - // abcdefghij.test1 and abcdefghij.test2? - regfree(®); - return ConfigureResult::Failed_AlreadyInstalled; + if (!validateTizenApplicationID( + m_installerContext.widgetConfig.tzAppid)) + { + LogError("tizen application ID is already used"); + return ConfigureResult::Failed_InvalidConfig; + } + if (!validateTizenPackageID(m_installerContext.widgetConfig.tzPkgid)) { + LogError("tizen package ID is already used"); + return ConfigureResult::Failed_AlreadyInstalled; + } } - regfree(®); configureWidgetLocation(widgetSource, tempPath); // Init installer context m_installerContext.installStep = InstallerContext::INSTALL_START; m_installerContext.job = this; - m_installerContext.existingWidgetInfo = update.existingWidgetInfo; m_installerContext.widgetConfig.shareHref = std::string(); return result; } -ConfigureResult JobWidgetInstall::checkWidgetUpdate( - const WidgetUpdateInfo &update) +bool JobWidgetInstall::validateTizenApplicationID( + const WrtDB::TizenAppId &tizenAppId) { - LogInfo( - "Widget install/update: incoming guid = '" << - update.incomingGUID << "'"); - LogInfo( - "Widget install/update: incoming version = '" << - update.incomingVersion << "'"); - - // Check policy - WidgetUpdateMode::Type updateTypeCheckBit; - - if (update.existingWidgetInfo.isExist == false) { - LogInfo("Widget info does not exist"); - updateTypeCheckBit = WidgetUpdateMode::NotInstalled; + LogInfo("tizen application ID = [" << tizenAppId << "]"); - getInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_START_KEY, - PKGMGR_START_INSTALL); + regex_t reg; + if (regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) { + LogDebug("Regcomp failed"); + } - } else { - LogInfo("Widget info exists. appid: " << - update.existingWidgetInfo.tzAppid); + if (regexec(®, DPL::ToUTF8String(tizenAppId).c_str(), 0, NULL, 0) + == REG_NOMATCH) + { + regfree(®); + return false; + } + regfree(®); + return true; +} - getInstallerStruct().pkgmgrInterface->sendSignal( - PKGMGR_START_KEY, - PKGMGR_START_UPDATE); +bool JobWidgetInstall::validateTizenPackageID( + const WrtDB::TizenPkgId &tizenPkgId) +{ + std::string pkgId = DPL::ToUTF8String(tizenPkgId); - TizenAppId tzAppid = update.existingWidgetInfo.tzAppid; + std::string installPath = + std::string(GlobalConfig::GetUserInstalledWidgetPath()) + + "/" + pkgId; + std::string preinstallPath = + std::string(GlobalConfig::GetUserPreloadedWidgetPath()) + + "/" + pkgId; - LogInfo("Widget model exists. tizen app id: " << tzAppid); + struct stat dirStat; + if ((stat(installPath.c_str(), &dirStat) == 0) || + (stat(preinstallPath.c_str(), &dirStat) == 0)) + { + return false; + } + return true; +} - // Check running state - bool isRunning = false; - int retval = app_manager_is_running(DPL::ToUTF8String( - tzAppid).c_str(), &isRunning); - if (APP_MANAGER_ERROR_NONE != retval) { - LogError("Fail to get running state"); - return ConfigureResult::Failed_WidgetRunning; - } +ConfigureResult JobWidgetInstall::checkWidgetUpdate( + const WidgetUpdateInfo &update) +{ + LogInfo("incoming version = '" << update.incomingVersion); + LogInfo("Tizen AppID = " << update.tzAppId); - if (true == isRunning) { - // Must be deferred when update in progress - if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) { - LogInfo( - "Widget is already running. Policy is update according to WAC"); + if (update.existingVersion.IsNull() || update.incomingVersion.IsNull()) { + return ConfigureResult::Failed; + } - return ConfigureResult::Deferred; - } else { - LogInfo( - "Widget is already running. Policy is not update according to WAC"); + // Check running state + bool isRunning = false; + int retval = + app_manager_is_running(DPL::ToUTF8String(update.tzAppId).c_str(), + &isRunning); + if (APP_MANAGER_ERROR_NONE != retval || isRunning) { + LogError("Fail to get running state"); + return ConfigureResult::Failed_WidgetRunning; + } - return ConfigureResult::Failed_WidgetRunning; - } - } + m_installerContext.widgetConfig.tzAppid = update.tzAppId; - m_installerContext.widgetConfig.tzAppid = tzAppid; - OptionalWidgetVersion existingVersion; - existingVersion = update.existingWidgetInfo.existingVersion; - OptionalWidgetVersion incomingVersion = update.incomingVersion; - - updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion, - incomingVersion); - // Calc proceed flag - if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 || - m_jobStruct.updateMode == - WidgetUpdateMode::PolicyDirectoryForceInstall) - { - LogInfo("Whether widget policy allow proceed ok"); - return ConfigureResult::Updated; - } else { - return ConfigureResult::Failed_LowerVersion; - } + if (isUpperVersion(update.existingVersion, update.incomingVersion) || + (m_jobStruct.m_installMode == InstallMode::INSTALL_MODE_DIRECTORY) || + (m_jobStruct.m_installMode == InstallMode::REINSTALL_MODE_DIRECTORY)) + { + LogInfo("Whether widget policy allow proceed ok"); + return ConfigureResult::Updated; + } else { + return ConfigureResult::Failed_LowerVersion; } - return ConfigureResult::Ok; + + return ConfigureResult::Failed; } -WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy( +bool JobWidgetInstall::isUpperVersion( const OptionalWidgetVersion &existingVersion, - const OptionalWidgetVersion &incomingVersion) const + const OptionalWidgetVersion &incomingVersion) { - // Widget is installed, check versions + LogInfo("Existing version = '" << *existingVersion); + LogInfo("Incoming version = '" << *incomingVersion); + if (!existingVersion && !incomingVersion) { - return WidgetUpdateMode::ExistingVersionEqual; + return false; } else if (!existingVersion && !!incomingVersion) { - return WidgetUpdateMode::ExistingVersionNewer; + return false; } else if (!!existingVersion && !incomingVersion) { - return WidgetUpdateMode::ExistingVersionOlder; + return true; } else { - LogInfo("Existing widget: version = '" << *existingVersion << "'"); - - if (!existingVersion->IsWac() && !incomingVersion->IsWac()) { - return WidgetUpdateMode::BothVersionsNotStd; - } else if (!existingVersion->IsWac()) { - return WidgetUpdateMode::ExistingVersionNotStd; - } else if (!incomingVersion->IsWac()) { - return WidgetUpdateMode::IncomingVersionNotStd; + if (!existingVersion->IsWac() || !incomingVersion->IsWac()) { + return false; } else { - // Both versions are WAC-comparable. Do compare. if (*incomingVersion == *existingVersion) { - return WidgetUpdateMode::ExistingVersionEqual; + return false; } else if (*incomingVersion > *existingVersion) { - return WidgetUpdateMode::ExistingVersionOlder; + return true; } else { - return WidgetUpdateMode::ExistingVersionNewer; + return false; } } } @@ -626,7 +643,8 @@ ConfigParserData JobWidgetInstall::getWidgetDataFromXML( const std::string &widgetSource, const std::string &tempPath, WrtDB::PackagingType pkgType, - bool isDRM) + bool isDRM, + bool isReinstall) { // Parse config ParserRunner parser; @@ -641,7 +659,23 @@ ConfigParserData JobWidgetInstall::getWidgetDataFromXML( DPL::FromUTF32String( L"widget")))); } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) { - parser.Parse(widgetSource + '/' + WITH_OSP_XML, + std::string configPath; + configPath = tempPath; + configPath += "/"; + configPath += WITH_OSP_XML; + + if (isReinstall) { + // checking RDS data directory + if (access(configPath.c_str(), F_OK) != 0) { + std::string tzAppId = + widgetSource.substr(widgetSource.find_last_of("/")+1); + WidgetDAOReadOnly dao(WidgetDAOReadOnly::getTzAppId(DPL::FromUTF8String(tzAppId))); + configPath = DPL::ToUTF8String(*dao.getWidgetInstalledPath()); + configPath += "/"; + configPath += WITH_OSP_XML; + } + } + parser.Parse(configPath, ElementParserPtr( new RootParser( configInfo, @@ -724,71 +758,29 @@ ConfigParserData JobWidgetInstall::getWidgetDataFromXML( WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate( const ConfigParserData &configInfo, - const WrtDB::WidgetType appType, const WrtDB::TizenAppId &tizenId) { LogInfo("Checking up widget package for config.xml..."); + OptionalWidgetVersion incomingVersion; - DPL::OptionalString widgetGUID; - OptionalWidgetVersion widgetVersion; - - // Check widget id - widgetGUID = configInfo.widget_id; - - if (widgetGUID.IsNull()) { - LogWarning("Installed widget has no GUID"); - return WidgetUpdateInfo(); - } - - LogDebug("Installed widget GUID: " << *widgetGUID); - - // Locate widget ID with this GUID - // Incoming widget version if (!configInfo.version.IsNull()) { - widgetVersion = + incomingVersion = DPL::Optional( WidgetVersion(*configInfo.version)); } - if (appType == APP_TYPE_WAC20) { - Try - { - // Search widget handle by GUID - WidgetDAOReadOnly dao(widgetGUID); - return WidgetUpdateInfo( - widgetGUID, - widgetVersion, - WidgetUpdateInfo::ExistingWidgetInfo( - dao.getTzAppId(), dao.getVersion())); - } - Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) - { - // GUID isn't installed - return WidgetUpdateInfo( - widgetGUID, - widgetVersion, - WidgetUpdateInfo::ExistingWidgetInfo()); - } - } else { - Try - { - // Search widget handle by appId - WidgetDAOReadOnly dao(tizenId); - return WidgetUpdateInfo( - widgetGUID, - widgetVersion, - WidgetUpdateInfo::ExistingWidgetInfo( - dao.getTzAppId(), dao.getVersion())); - } - Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) - { - // GUID isn't installed - return WidgetUpdateInfo( - widgetGUID, - widgetVersion, - WidgetUpdateInfo::ExistingWidgetInfo()); - } + WidgetDAOReadOnly dao(tizenId); + + OptionalWidgetVersion optVersion; + DPL::OptionalString version = dao.getVersion(); + if (!version.IsNull()) { + optVersion = OptionalWidgetVersion(WidgetVersion(*version)); } + + return WidgetUpdateInfo( + dao.getTzAppId(), + optVersion, + incomingVersion); } void JobWidgetInstall::SendProgress() @@ -832,10 +824,10 @@ void JobWidgetInstall::SendFinishedSuccess() sync(); if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) { - if (false == m_installerContext.existingWidgetInfo.isExist) { - WidgetInstallToExtSingleton::Instance().postInstallation(true); - } else { + if (m_installerContext.isUpdateMode) { WidgetInstallToExtSingleton::Instance().postUpgrade(true); + } else { + WidgetInstallToExtSingleton::Instance().postInstallation(true); } WidgetInstallToExtSingleton::Instance().deinitialize(); } @@ -960,8 +952,8 @@ WrtDB::PackagingType JobWidgetInstall::checkPackageType( const std::string &tempPath) { // Check installation type (direcotory/ or config.xml or widget.wgt) - if (WidgetUpdateMode::PolicyDirectoryForceInstall == - m_jobStruct.updateMode) + if (m_jobStruct.m_installMode == InstallMode::INSTALL_MODE_DIRECTORY || + m_jobStruct.m_installMode == InstallMode::REINSTALL_MODE_DIRECTORY) { LogDebug("Install directly from directory"); return PKG_TYPE_DIRECTORY_WEB_APP; @@ -1098,7 +1090,7 @@ void JobWidgetInstall::setInstallLocationType( { m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL; - if (true == m_jobStruct.m_preload) { + if (m_jobStruct.m_installMode == InstallMode::INSTALL_MODE_PRELOAD) { m_installerContext.locationType = INSTALL_LOCATION_TYPE_PRELOAD; } else { @@ -1116,54 +1108,17 @@ void JobWidgetInstall::setInstallLocationType( } } -bool JobWidgetInstall::isDRMWidget(std::string widgetPath) +bool JobWidgetInstall::isDRMWidget(std::string /*widgetPath*/) { - /* TODO : - * drm_bool_type_e is_drm_file = DRM_UNKNOWN; - * int ret = -1; - * - * ret = drm_is_drm_file(widgetPath.c_str(), &is_drm_file); - * if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file) { - */ - - /* blow code temporary code for drm. */ - int ret = drm_oem_intel_isDrmFile(const_cast(widgetPath.c_str())); - if (1 == ret) { - return true; - } else { - return false; - } + /* TODO */ + return false; } -bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath, - std::string destPath) +bool JobWidgetInstall::DecryptDRMWidget(std::string /*widgetPath*/, + std::string /*destPath*/) { - /* TODO : - * drm_trusted_sapps_decrypt_package_info_s package_info; - * - * strncpy(package_info.sadcf_filepath, widgetPath.c_str(), - * sizeof(package_info.sadcf_filepath)); - * strncpy(package_info.decrypt_filepath, destPath.c_str(), - * sizeof(package_info.decrypt_filepath)); - * - * drm_trusted_request_type_e requestType = - * DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE; - * - * int ret = drm_trusted_handle_request(requestType, - * (void *)&package_info, NULL); - * if (DRM_TRUSTED_RETURN_SUCCESS == ret) { - * return true; - * } else { - * return false; - * } - */ - if (drm_oem_intel_decrypt_package(const_cast(widgetPath.c_str()), - const_cast(destPath.c_str())) != 0) - { - return true; - } else { - return false; - } + /* TODO */ + return false; } } //namespace WidgetInstall } //namespace Jobs