* @brief Implementation file for main installer task
*/
#include <memory>
+#include <string>
+#include <sys/time.h>
+#include <ctime>
+#include <cstdlib>
+#include <limits.h>
+#include <regex.h>
#include <dpl/noncopyable.h>
#include <dpl/abstract_waitable_input_adapter.h>
#include <dpl/copy.h>
#include <dpl/assert.h>
#include <dpl/sstream.h>
-#include <dpl/wrt-dao-ro/common_dao_types.h>
#include <dpl/file_input.h>
#include <dpl/utils/wrt_utility.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-rw/global_dao.h> // TODO remove
+#include <dpl/localization/w3c_file_localization.h>
+
+#include <libiriwrapper.h>
+#include <pkg-manager/pkgmgr_signal.h>
+#include <app_manager.h>
+//#include <drm_client.h>
+#include <drm-oem-intel.h> //temporary code
+
#include "root_parser.h"
#include "widget_parser.h"
#include "parser_runner.h"
#include <widget_install/task_ace_check.h>
#include <widget_install/task_smack.h>
#include <widget_install/task_manifest_file.h>
-#include <widget_install/task_private_storage.h>
#include <widget_install/task_prepare_files.h>
#include <widget_install/task_recovery.h>
#include <widget_install/task_install_ospsvc.h>
#include <widget_install/task_certificates.h>
#include <widget_install/task_unzip.h>
#include <widget_install/task_commons.h>
+
#include <widget_install/task_plugins_copy.h>
#include <widget_install/widget_install_errors.h>
#include <widget_install/widget_install_context.h>
-#include <string>
-#include <sys/time.h>
-#include <ctime>
-#include <cstdlib>
-#include <limits.h>
-#include <regex.h>
-#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
-#include <dpl/wrt-dao-ro/global_config.h>
-#include <dpl/wrt-dao-rw/global_dao.h> // TODO remove
-#include <dpl/localization/w3c_file_localization.h>
-#include <libiriwrapper.h>
-#include <pkg-manager/pkgmgr_signal.h>
-#include <app_manager.h>
-#include <drm_client.h>
-#include <drm-oem-intel.h> //temporary code
+#include <widget_install_to_external.h>
using namespace WrtDB;
//allowed: a-z, A-Z, 0-9
const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}$";
-const int MAX_TIZENID_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";
+const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
+ L"prefer-external";
class InstallerTaskFail :
public DPL::TaskDecl<InstallerTaskFail>
}
return (0 == filename.compare(fileLen-extLen, extLen, extension));
}
+
+bool checkTizenIdExist(const std::string& tizenId) {
+ std::string installPath =
+ std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
+ "/" + tizenId;
+ std::string preinstallPath =
+ std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
+ "/" + tizenId;
+
+ struct stat dirStat;
+ if ((stat(installPath.c_str(), &dirStat) == 0) &&
+ (stat(preinstallPath.c_str(), &dirStat) == 0)) {
+ return true;
+ }
+ return false;
+}
} // namespace anonymous
namespace Jobs {
// Create installation tasks
if (m_installerContext.widgetConfig.packagingType !=
- WrtDB::PKG_TYPE_HOSTED_WEB_APP || !m_isDRM) {
+ WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
+ m_installerContext.widgetConfig.packagingType !=
+ WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
+ !m_isDRM)
+ {
AddTask(new TaskUnzip(m_installerContext));
}
AddTask(new TaskWidgetConfig(m_installerContext));
- if (m_installerContext.widgetConfig.packagingType ==
- WrtDB::PKG_TYPE_HOSTED_WEB_APP ) {
+ if (m_installerContext.widgetConfig.packagingType ==
+ WrtDB::PKG_TYPE_HOSTED_WEB_APP)
+ {
AddTask(new TaskPrepareFiles(m_installerContext));
}
AddTask(new TaskCertify(m_installerContext));
if (m_needEncryption) {
AddTask(new TaskEncryptResource(m_installerContext));
}
+
AddTask(new TaskFileManipulation(m_installerContext));
// TODO: Update progress information for this task
- AddTask(new TaskPrivateStorage(m_installerContext));
-
//This is sort of quick solution, because ACE verdicts are based upon
//data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
//task.
LogInfo("Configure installation updated");
LogInfo("Widget Update");
if (m_installerContext.widgetConfig.packagingType !=
- WrtDB::PKG_TYPE_HOSTED_WEB_APP || !m_isDRM) {
+ WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
+ m_installerContext.widgetConfig.packagingType !=
+ WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
+ !m_isDRM)
+ {
AddTask(new TaskUnzip(m_installerContext));
}
AddTask(new TaskWidgetConfig(m_installerContext));
if (m_installerContext.widgetConfig.packagingType ==
- WrtDB::PKG_TYPE_HOSTED_WEB_APP ) {
+ WrtDB::PKG_TYPE_HOSTED_WEB_APP)
+ {
AddTask(new TaskPrepareFiles(m_installerContext));
}
AddTask(new TaskCertify(m_installerContext));
- AddTask(new TaskUpdateFiles(m_installerContext));
+ if (m_installerContext.widgetConfig.packagingType !=
+ WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
+ {
+ AddTask(new TaskUpdateFiles(m_installerContext));
+ }
/* TODO : To backup file, save md5 values */
AddTask(new TaskSmack(m_installerContext));
PKG_TYPE_HYBRID_WEB_APP) {
AddTask(new TaskInstallOspsvc(m_installerContext));
}
- AddTask(new TaskRemoveBackupFiles(m_installerContext));
+ if (m_installerContext.widgetConfig.packagingType !=
+ WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
+ {
+ AddTask(new TaskRemoveBackupFiles(m_installerContext));
+ }
AddTask(new TaskPluginsCopy(m_installerContext));
AddTask(new TaskDatabase(m_installerContext));
AddTask(new TaskAceCheck(m_installerContext));
Try
{
- std::string tempDir = Jobs::WidgetInstall::createTempPath();
+ std::string tempDir =
+ Jobs::WidgetInstall::createTempPath(m_jobStruct.m_preload);
- bool m_isDRM = isDRMWidget(widgetPath);
+ m_isDRM = isDRMWidget(widgetPath);
if (true == m_isDRM) {
LogDebug("decrypt DRM widget");
if(DecryptDRMWidget(widgetPath, tempDir)) {
m_installerContext.widgetConfig.packagingType =
checkPackageType(widgetPath, tempDir);
- ConfigParserData configData = getWidgetDataFromXML(widgetPath, tempDir,
- m_installerContext.widgetConfig.packagingType, m_isDRM);
+ ConfigParserData configData = getWidgetDataFromXML(
+ widgetPath,
+ tempDir,
+ m_installerContext.widgetConfig.packagingType,
+ m_isDRM);
LogDebug("widget packaging type : " <<
m_installerContext.widgetConfig.packagingType.pkgType);
WidgetUpdateInfo update = detectWidgetUpdate(configData);
m_needEncryption = detectResourceEncryption(configData);
+ setInstallLocationType(configData);
// Configure installation
result = ConfigureInstallation(widgetPath, configData, update, tempDir);
return result;
}
-std::string JobWidgetInstall::generateTizenId() {
- std::string allowed("0123456789"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz");
- std::string tizenId;
- tizenId.resize(MAX_TIZENID_LENGTH);
- for (int i = 0; i < MAX_TIZENID_LENGTH; ++i) {
- tizenId[i] = allowed[rand() % allowed.length()];
- }
- return tizenId;
-}
-
bool JobWidgetInstall::setTizenId(
- const WrtDB::ConfigParserData &configInfo, ConfigureResult result)
+ const WrtDB::ConfigParserData &configInfo,
+ const WidgetUpdateInfo &update,
+ bool preload)
{
+ using namespace PackageManager;
regex_t reg;
- regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED);
- struct stat dirStat;
+ if(regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
+ LogDebug("Regcomp failed");
+ }
+
+ ConfigureResult result = checkWidgetUpdate(update);
if(!!configInfo.tizenId) {
LogDebug("Setting tizenId provided in config.xml: " << configInfo.tizenId);
+ // send start signal of pkgmgr
+ getInstallerStruct().pkgmgrInterface->setPkgname(
+ DPL::ToUTF8String(*(configInfo.tizenId)));
+ getInstallerStruct().pkgmgrInterface->sendSignal(
+ PKGMGR_START_KEY,
+ PKGMGR_START_INSTALL);
+
+ if (result == ConfigureResult::Failed) {
+ return false;
+ }
+
if ((regexec(®, DPL::ToUTF8String(*(configInfo.tizenId)).c_str(),
static_cast<size_t>(0), NULL, 0) != REG_NOERROR) ||
- ((stat((std::string(GlobalConfig::GetUserInstalledWidgetPath()) + "/"
- + DPL::ToUTF8String(*(configInfo.tizenId))).c_str(), &dirStat) == 0)
- && result != ConfigureResult::Updated))
+ (checkTizenIdExist(DPL::ToUTF8String(*(configInfo.tizenId))) &&
+ result != ConfigureResult::Updated))
{
//it is true when tizenId does not fit REG_TIZENID_PATTERN
LogError("tizen_id provided but not proper.");
m_installerContext.widgetConfig.pkgname = configInfo.tizenId;
} else {
- std::string tizenId = generateTizenId();
+ WidgetPkgName tizenId = WidgetDAOReadOnly::generateTizenId();
// only for installation, not for update
if (result == ConfigureResult::Ok) {
//check if there is package with same name and if generate different name
- std::string path = GlobalConfig::GetUserInstalledWidgetPath();
- path += "/";
-
- std::ostringstream newPath;
- newPath << path << tizenId;
LogDebug("Checking if tizen id is unique");
while (true) {
- if (stat(newPath.str().c_str(), &dirStat) == 0) {
+ if (checkTizenIdExist(DPL::ToUTF8String(tizenId))) {
//path exist, chose another one
- tizenId = generateTizenId();
- newPath.str("");
- newPath << path << tizenId;
+ tizenId = WidgetDAOReadOnly::generateTizenId();
continue;
}
break;
}
- m_installerContext.widgetConfig.pkgname =
- DPL::FromUTF8String(tizenId);
+ m_installerContext.widgetConfig.pkgname = tizenId;
}
LogInfo("tizen_id name was generated by WRT: " << tizenId);
+ // send start signal of pkgmgr
+ getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
+ *m_installerContext.widgetConfig.pkgname));
+ getInstallerStruct().pkgmgrInterface->sendSignal(
+ PKGMGR_START_KEY,
+ PKGMGR_START_INSTALL);
}
regfree(®);
return true;
}
-DPL::OptionalString JobWidgetInstall::getNewTizenId() const
-{
- return m_installerContext.widgetConfig.pkgname;
-}
-
void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
const std::string& tempPath)
{
m_installerContext.locations =
WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname),
widgetPath, tempPath,
- m_installerContext.widgetConfig.packagingType);
+ m_installerContext.widgetConfig.packagingType,
+ m_installerContext.locationType);
LogInfo("widgetSource " << widgetPath);
}
const WidgetUpdateInfo &update,
const std::string &tempPath)
{
+
+ if (!setTizenId(configData, update, m_jobStruct.m_preload)) {
+ return ConfigureResult::Failed;
+ } else {
+ LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname);
+
+ 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 ConfigureResult::Ok;
+}
+
+JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
+ const WidgetUpdateInfo &update)
+{
LogInfo(
"Widget install/update: incoming guid = '" <<
update.incomingGUID << "'");
// Check policy
WidgetUpdateMode::Type updateTypeCheckBit;
- JobWidgetInstall::ConfigureResult ret = ConfigureResult::Ok;
if (update.existingWidgetInfo.isExist == false) {
LogInfo("Widget info does not exist");
} else {
LogInfo(
"Widget is already running. Policy is not update according to WAC");
- LogInfo("Installation aborted: " << widgetSource);
return ConfigureResult::Failed;
}
updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
incomingVersion);
// Calc proceed flag
- if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0) {
+ if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
+ m_jobStruct.updateMode ==
+ WidgetUpdateMode::PolicyDirectoryForceInstall)
+ {
LogInfo("Whether widget policy allow proceed ok");
- ret = ConfigureResult::Updated;
+ return ConfigureResult::Updated;
}
else
return ConfigureResult::Failed;
}
-
- if (!setTizenId(configData, ret)) {
- return ConfigureResult::Failed;
- } else {
- using namespace PackageManager;
- LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname);
-
- configureWidgetLocation(widgetSource, tempPath);
-
- // send start signal of pkgmgr
- PkgmgrSignalSingleton::Instance().setPkgname(
- DPL::ToUTF8String(
- *m_installerContext.widgetConfig.pkgname));
- PkgmgrSignalSingleton::Instance().sendSignal(
- PKGMGR_START_KEY,
- PKGMGR_START_INSTALL);
- }
-
- // 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
- return ret;
+ return ConfigureResult::Ok;
}
WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
new RootParser<WidgetParser>(configInfo,
DPL::FromUTF32String(
L"widget"))));
+ } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) {
+ parser.Parse(widgetSource + '/' + WITH_OSP_XML,
+ ElementParserPtr(
+ new RootParser<WidgetParser>(
+ configInfo,
+ DPL::FromUTF32String(L"widget"))));
} else {
if (!isDRM) {
std::unique_ptr<DPL::ZipInput> zipFile(
LogError("Failed to parse config.xml file");
return ConfigParserData();
}
+ Catch(DPL::ZipInput::Exception::SeekFileFailed)
+ {
+ LogError("Failed to seek widget archive - corrupted package?");
+ return ConfigParserData();
+ }
return configInfo;
}
// send progress signal of pkgmgr
std::ostringstream percent;
percent << static_cast<int>(GetProgressPercent());
- PkgmgrSignalSingleton::Instance().sendSignal(
+ getInstallerStruct().pkgmgrInterface->sendSignal(
PKGMGR_PROGRESS_KEY,
percent.str());
// TODO : sync should move to separate task.
sync();
+
+ if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
+ if (false == m_installerContext.existingWidgetInfo.isExist) {
+ WidgetInstallToExtSingleton::Instance().postInstallation(true);
+ } else {
+ WidgetInstallToExtSingleton::Instance().postUpgrade(true);
+ }
+ WidgetInstallToExtSingleton::Instance().deinitialize();
+ }
+
// remove widget install information file
unlink(m_installerContext.installInfo.c_str());
//inform widget info
JobWidgetInstall::displayWidgetInfo();
- DPL::OptionalString tizenId = getNewTizenId();
+ DPL::OptionalString & tizenId = m_installerContext.widgetConfig.pkgname;
// send signal of pkgmgr
- PkgmgrSignalSingleton::Instance().sendSignal(
+ getInstallerStruct().pkgmgrInterface->sendSignal(
PKGMGR_END_KEY,
PKGMGR_END_SUCCESS);
LogError("Error in installation step: " << m_exceptionCaught);
LogError("Message: " << m_exceptionMessage);
- DPL::OptionalString tizenId = getNewTizenId();
+ DPL::OptionalString & tizenId = m_installerContext.widgetConfig.pkgname;
LogDebug("Call widget install failure finishedCallback");
// send signal of pkgmgr
- PkgmgrSignalSingleton::Instance().sendSignal(
+ getInstallerStruct().pkgmgrInterface->sendSignal(
PKGMGR_END_KEY,
PKGMGR_END_FAILURE);
const std::string &widgetSource,
const std::string &tempPath)
{
- // Check installation type (config.xml or widget.wgt)
+ // Check installation type (direcotory/ or config.xml or widget.wgt)
+ if (WidgetUpdateMode::PolicyDirectoryForceInstall == m_jobStruct.updateMode)
+ {
+ LogDebug("Install directly from directory");
+ return PKG_TYPE_DIRECTORY_WEB_APP;
+ }
if (hasExtension(widgetSource, XML_EXTENSION)) {
LogInfo("Hosted app installation");
return PKG_TYPE_HOSTED_WEB_APP;
LogDebug("Failed to open widget package");
return PKG_TYPE_UNKNOWN;
}
+ Catch(DPL::ZipInput::Exception::SeekFileFailed)
+ {
+ LogError("Failed to seek widget package file");
+ return PKG_TYPE_UNKNOWN;
+ }
Try
{
return false;
}
+void JobWidgetInstall::setInstallLocationType(const
+ WrtDB::ConfigParserData &configData)
+{
+ m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
+
+ if (true == m_jobStruct.m_preload) {
+ m_installerContext.locationType =
+ INSTALL_LOCATION_TYPE_PRELOAD;
+ } else {
+ FOREACH(it, configData.settingsList)
+ {
+ if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
+ it->m_value ==
+ SETTING_VALUE_INSTALLTOEXT_PREPER_EXT) {
+ LogDebug("This widget will be installed to sd card");
+ m_installerContext.locationType =
+ INSTALL_LOCATION_TYPE_EXTERNAL;
+ }
+ }
+ }
+}
+
bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
{
/* TODO :
bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
std::string destPath)
{
- /* TODO :
+ /* TODO :
drm_trusted_sapps_decrypt_package_info_s package_info;
strncpy(package_info.sadcf_filepath, widgetPath.c_str(),
}
*/
if (drm_oem_intel_decrypt_package(const_cast<char*>(widgetPath.c_str()),
- const_cast<char*>(destPath.c_str())) != 0) {
+ const_cast<char*>(destPath.c_str())) != 0) {
return true;
} else {
return false;