#include <cstdlib>
#include <limits.h>
#include <regex.h>
+#include <vconf.h>
#include <dpl/utils/wrt_utility.h>
#include <dpl/utils/path.h>
#include <dpl/localization/w3c_file_localization.h>
#include <libiriwrapper.h>
-#include <pkg-manager/pkgmgr_signal.h>
#include <app_manager.h>
#include "root_parser.h"
static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable";
static const DPL::String SETTING_VALUE_ENCRYPTION_DISABLE = L"disable";
-const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME =
- L"install-location";
-const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
- L"prefer-external";
-
+const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME = L"install-location";
+const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT = L"prefer-external";
+const DPL::String SETTING_VALUE_INSTALLTOEXT_AUTO = L"auto";
const std::string XML_EXTENSION = ".xml";
bool hasExtension(const std::string& filename, const std::string& extension)
TaskConfiguration::TaskConfiguration(InstallerContext& context) :
DPL::TaskDecl<TaskConfiguration>(this),
- m_context(context)
+ m_context(context),
+ m_widgetConfig(m_context.widgetConfig.configInfo)
{
AddStep(&TaskConfiguration::StartStep);
- AddStep(&TaskConfiguration::PrepareInstallationStep);
+
+ AddStep(&TaskConfiguration::SetupTempDirStep);
+ AddStep(&TaskConfiguration::CheckPackageTypeStep);
+
+ AddStep(&TaskConfiguration::ParseXMLConfigStep);
+
+ AddStep(&TaskConfiguration::TizenIdStep);
+ AddStep(&TaskConfiguration::ApplicationTypeStep);
+ AddStep(&TaskConfiguration::ResourceEncryptionStep);
+ AddStep(&TaskConfiguration::InstallationFSLocationStep);
+
+ AddStep(&TaskConfiguration::DetectUpdateInstallationStep);
+ AddStep(&TaskConfiguration::CheckRDSSupportStep);
+ AddStep(&TaskConfiguration::ConfigureWidgetLocationStep);
+ AddStep(&TaskConfiguration::PkgmgrStartStep);
+
AddStep(&TaskConfiguration::AppendTasklistStep);
+
AddStep(&TaskConfiguration::EndStep);
}
_D("--------- <TaskConfiguration> : END ----------");
}
+void TaskConfiguration::PkgmgrStartStep()
+{
+ pkgMgrInterface()->sendSignal(
+ PKGMGR_PROGRESS_KEY,
+ PKGMGR_START_VALUE);
+}
+
void TaskConfiguration::AppendTasklistStep()
{
if (!m_context.isUpdateMode) {
}
}
-void TaskConfiguration::PrepareInstallationStep()
+std::shared_ptr<PackageManager::IPkgmgrSignal> TaskConfiguration::pkgMgrInterface()
{
- // TODO: (job_install_refactoring) clean up this task
- std::string widgetPath = m_context.requestedPath;
- bool result;
- m_context.needEncryption = false;
- std::string tempDir;
+ return m_context.job->GetInstallerStruct().pkgmgrInterface;
+}
+
+void TaskConfiguration::SetupTempDirStep()
+{
+ _D("widgetPath: %s", m_context.requestedPath.c_str());
+ _D("tempPath: %s", m_tempDir.c_str());
if (m_context.mode.extension == InstallMode::ExtensionType::DIR) {
if (m_context.mode.command ==
InstallMode::Command::REINSTALL) {
tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
tempPathBuilder << "/";
- tempPathBuilder << widgetPath;
- tempDir = tempPathBuilder.str();
+ tempPathBuilder << m_context.requestedPath;
+ m_tempDir = tempPathBuilder.str();
} else {
- tempDir = widgetPath;
+ m_tempDir = m_context.requestedPath;
}
} else {
- tempDir =
+ m_tempDir =
Jobs::WidgetInstall::createTempPath(
m_context.mode.rootPath ==
InstallMode::RootPath::RO);
- WidgetUnzip wgtUnzip;
- wgtUnzip.unzipWgtFile(widgetPath, tempDir);
+ if(!hasExtension(m_context.requestedPath, XML_EXTENSION)) //unzip everything except xml files
+ {
+ WidgetUnzip wgtUnzip;
+ wgtUnzip.unzipWgtFile(m_context.requestedPath, m_tempDir);
+ }
+ else
+ {
+ _D("From browser installation - unzip is not done");
+ }
}
+}
- _D("widgetPath: %s", widgetPath.c_str());
- _D("tempPath: %s", tempDir.c_str());
-
- m_context.widgetConfig.packagingType =
- checkPackageType(widgetPath, tempDir);
- ConfigParserData configData = getWidgetDataFromXML(
- widgetPath,
- tempDir,
+void TaskConfiguration::ParseXMLConfigStep()
+{
+ parseWidgetXMLConfig(
+ m_context.requestedPath, m_tempDir,
m_context.widgetConfig.packagingType,
m_context.mode.command == InstallMode::Command::REINSTALL);
_D("widget packaging type : %d", static_cast<WrtDB::PkgType>(m_context.widgetConfig.packagingType.pkgType));
-
- setTizenId(configData);
- setApplicationType(configData);
- m_context.needEncryption = detectResourceEncryption(configData);
- setInstallLocationType(configData);
- // TODO: (job_install_refactoring) hide this call
- m_context.callerPkgId =
- DPL::FromUTF8String(m_context.job->GetInstallerStruct().pkgmgrInterface->getCallerId());
- _D("Caller Package Id : %s", DPL::ToUTF8String(m_context.callerPkgId).c_str());
-
- // Configure installation
- result = ConfigureInstallation(widgetPath, configData, tempDir);
- // TODO: (job_install_refactoring) hide this call
- m_context.job->GetInstallerStruct().pkgmgrInterface->sendSignal(
- PKGMGR_PROGRESS_KEY,
- PKGMGR_START_VALUE);
-
- m_context.isUpdateMode = result;
}
-void TaskConfiguration::setTizenId(
- const WrtDB::ConfigParserData &configInfo)
+void TaskConfiguration::TizenIdStep()
{
bool shouldMakeAppid = false;
using namespace PackageManager;
- if (!!configInfo.tizenAppId) {
- _D("Setting tizenAppId provided in config.xml: %ls", (*configInfo.tizenAppId).c_str());
- m_context.widgetConfig.tzAppid = *configInfo.tizenAppId;
+
+ if (!!m_widgetConfig.tizenAppId) {
+ _D("Setting tizenAppId provided in config.xml: %s", DPL::ToUTF8String(*m_widgetConfig.tizenAppId).c_str());
+
+ m_context.widgetConfig.tzAppid = *m_widgetConfig.tizenAppId;
//check package id.
- if (!!configInfo.tizenPkgId) {
- _D("Setting tizenPkgId provided in config.xml: %ls", (*configInfo.tizenPkgId).c_str());
- m_context.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
+ if (!!m_widgetConfig.tizenPkgId) {
+ _D("Setting tizenPkgId provided in config.xml: %s", DPL::ToUTF8String(*m_widgetConfig.tizenPkgId).c_str());
+
+ m_context.widgetConfig.tzPkgid = *m_widgetConfig.tizenPkgId;
} else {
- DPL::String appid = *configInfo.tizenAppId;
+ DPL::String appid = *m_widgetConfig.tizenAppId;
if (appid.length() > PACKAGE_ID_LENGTH) {
m_context.widgetConfig.tzPkgid =
appid.substr(0, PACKAGE_ID_LENGTH);
//old version appid only has 10byte random character is able to install for a while.
//this case appid equal pkgid.
m_context.widgetConfig.tzPkgid =
- *configInfo.tizenAppId;
+ *m_widgetConfig.tizenAppId;
shouldMakeAppid = true;
}
}
if (shouldMakeAppid == true) {
DPL::OptionalString name;
- DPL::OptionalString defaultLocale = configInfo.defaultlocale;
+ DPL::OptionalString defaultLocale = m_widgetConfig.defaultlocale;
- FOREACH(localizedData, configInfo.localizedDataSet)
+ FOREACH(localizedData, m_widgetConfig.localizedDataSet)
{
Locale i = localizedData->first;
if (!!defaultLocale) {
if (!name || (regexec(®x, DPL::ToUTF8String(*name).c_str(),
static_cast<size_t>(0), NULL, 0) != REG_NOERROR))
{
- // TODO : (job_install_refactoring) generate name move to wrt-commons
- std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+ const std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
std::ostringstream genName;
struct timeval tv;
gettimeofday(&tv, NULL);
}
// send start signal of pkgmgr
- // TODO: (job_install_refactoring) hide this call
- m_context.job->GetInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
- m_context.
- widgetConfig.
- tzPkgid));
- _D("Tizen App Id : %ls", m_context.widgetConfig.tzAppid.c_str());
- _D("Tizen Pkg Id : %ls", m_context.widgetConfig.tzPkgid.c_str());
+ pkgMgrInterface()->setPkgname(DPL::ToUTF8String(m_context.widgetConfig.tzPkgid));
+
+ _D("Tizen App Id : %ls", (m_context.widgetConfig.tzAppid).c_str());
+ _D("Tizen Pkg Id : %ls", (m_context.widgetConfig.tzPkgid).c_str());
}
-void TaskConfiguration::configureWidgetLocation(const std::string & widgetPath,
- const std::string& tempPath)
+void TaskConfiguration::ConfigureWidgetLocationStep()
{
m_context.locations =
- WidgetLocation(DPL::ToUTF8String(m_context.widgetConfig.
- tzPkgid),
- widgetPath, tempPath,
+ WidgetLocation(DPL::ToUTF8String(m_context.widgetConfig.tzPkgid),
+ m_context.requestedPath, m_tempDir,
m_context.widgetConfig.packagingType,
m_context.mode.rootPath ==
InstallMode::RootPath::RO,
m_context.locations->registerAppid(
DPL::ToUTF8String(m_context.widgetConfig.tzAppid));
- _D("widgetSource %s", widgetPath.c_str());
+ _D("widgetSource %s", m_context.requestedPath.c_str());
}
-bool TaskConfiguration::ConfigureInstallation(
- const std::string &widgetSource,
- const WrtDB::ConfigParserData &configData,
- const std::string &tempPath)
+void TaskConfiguration::DetectUpdateInstallationStep()
{
- bool result;
-
WidgetUpdateInfo update;
-
// checking installed web application
Try {
// no excpetion means, it isn't update mode
- // TODO: (job_install_refactoring) hide this call/
- m_context.job->GetInstallerStruct().pkgmgrInterface->sendSignal(
- PKGMGR_START_KEY,
- PKGMGR_START_UPDATE);
-
- update = detectWidgetUpdate(configData,
+ update = detectWidgetUpdate(m_widgetConfig,
m_context.widgetConfig.tzAppid);
- result = checkWidgetUpdate(update);
- if (!result) {
- // Already installed TizenAppId. return failed
- ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageAlreadyInstalled,
- "package is already installed");
- }
- if (!checkSupportRDSUpdate(configData)) {
- ThrowMsg(Jobs::WidgetInstall::Exceptions::NotSupportRDSUpdate,
- "RDS update failed");
- }
- result = true;
+ checkWidgetUpdate(update);
+
+ m_context.isUpdateMode = true;
+
+ //if update, notify pkgmgr that this is update
+ pkgMgrInterface()->sendSignal( PKGMGR_START_KEY, PKGMGR_START_UPDATE);
}
Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {
- // TODO: (job_install_refactoring) hide this call
- m_context.job->GetInstallerStruct().pkgmgrInterface->sendSignal(
- PKGMGR_START_KEY,
- PKGMGR_START_INSTALL);
- result = false;
+ pkgMgrInterface()->sendSignal(PKGMGR_START_KEY, PKGMGR_START_INSTALL);
+
+ m_context.isUpdateMode = false;
if (!validateTizenApplicationID(
m_context.widgetConfig.tzAppid))
"package is already installed");
}
}
+}
- configureWidgetLocation(widgetSource, tempPath);
-
- return result;
+void TaskConfiguration::CheckRDSSupportStep()
+{
+ //update needs RDS support to go ahead
+ if(m_context.isUpdateMode)
+ {
+ if (!checkSupportRDSUpdate(m_widgetConfig)) {
+ ThrowMsg(Jobs::WidgetInstall::Exceptions::NotSupportRDSUpdate,
+ "RDS update failed");
+ }
+ }
}
bool TaskConfiguration::validateTizenApplicationID(
_D("incoming version = '%ls", update.incomingVersion->Raw().c_str());
_D("Tizen AppID = %ls", update.tzAppId.c_str());
- // Check running state
+ // TODO: step Check running state
bool isRunning = false;
int ret =
app_manager_is_running(DPL::ToUTF8String(update.tzAppId).c_str(),
if (APP_MANAGER_ERROR_NONE != ret) {
_E("Fail to get running state");
ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
- "widget is running");
+ "widget is running");
}
if (true == isRunning) {
if (APP_MANAGER_ERROR_NONE != ret) {
_E("Fail to get app_context");
ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
- "widget is running");
+ "widget is running");
}
// terminate app_context_h
_E("Fail to terminate running application");
app_context_destroy(appCtx);
ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
- "widget is running");
+ "widget is running");
} else {
app_context_destroy(appCtx);
// app_manager_terminate_app isn't sync API
if (APP_MANAGER_ERROR_NONE != ret) {
_E("Fail to get running state");
ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
- "widget is running");
+ "widget is running");
}
if (!isStillRunning) {
break;
if (isStillRunning) {
_E("Fail to terminate running application");
ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
- "widget is running");
+ "widget is running");
}
_D("terminate application");
}
}
+ //...
m_context.widgetConfig.tzAppid = update.tzAppId;
return false;
}
-ConfigParserData TaskConfiguration::getWidgetDataFromXML(
+void TaskConfiguration::parseWidgetXMLConfig(
const std::string &widgetSource,
const std::string &tempPath,
WrtDB::PackagingType pkgType,
{
// Parse config
ParserRunner parser;
- ConfigParserData configInfo;
Try
{
if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
parser.Parse(widgetSource,
ElementParserPtr(
- new RootParser<WidgetParser>(configInfo,
+ new RootParser<WidgetParser>(m_widgetConfig,
DPL::FromUTF32String(
L"widget"))));
} else {
ThrowMsg(Exceptions::MissingConfig, "Config file not exists");
}
+#ifdef SCHEMA_VALIDATION_ENABLED
+ if(!parser.Validate(configFilePath, WRT_WIDGETS_XML_SCHEMA))
+ {
+ _E("Invalid configuration file - schema validation failed");
+ ThrowMsg(Exceptions::WidgetConfigFileInvalid, "Failed to parse config.xml file");
+ }
+#endif
parser.Parse(configFile,
ElementParserPtr(
- new RootParser<WidgetParser>(configInfo,
+ new RootParser<WidgetParser>(m_widgetConfig,
DPL::
FromUTF32String(
L"widget"))));
_E("Failed to find config.xml");
ThrowMsg(Exceptions::MissingConfig, "Parser exeption");
}
-
- return configInfo;
}
WidgetUpdateInfo TaskConfiguration::detectWidgetUpdate(
incomingVersion);
}
-
-WrtDB::PackagingType TaskConfiguration::checkPackageType(
- const std::string &widgetSource,
- const std::string &tempPath)
+void TaskConfiguration::CheckPackageTypeStep()
{
- if (hasExtension(widgetSource, XML_EXTENSION)) {
+ if (hasExtension(m_context.requestedPath, XML_EXTENSION)) {
_D("Hosted app installation");
- return PKG_TYPE_HOSTED_WEB_APP;
+ m_context.widgetConfig.packagingType = PKG_TYPE_HOSTED_WEB_APP;
+ return;
}
- std::string configFile = tempPath + "/" + OSP_MANIFEST_XML;
+ std::string configFile = m_tempDir + "/" + OSP_MANIFEST_XML;
if (WrtUtilFileExists(configFile)) {
- return PKG_TYPE_HYBRID_WEB_APP;
+ m_context.widgetConfig.packagingType = PKG_TYPE_HYBRID_WEB_APP;
+ return;
}
- return PKG_TYPE_NOMAL_WEB_APP;
+ m_context.widgetConfig.packagingType = PKG_TYPE_NOMAL_WEB_APP;
}
-void TaskConfiguration::setApplicationType(
- const WrtDB::ConfigParserData &configInfo)
+void TaskConfiguration::ApplicationTypeStep() //TODO: is this really needed as WAC is not supported?
{
AppType widgetAppType = APP_TYPE_UNKNOWN;
- FOREACH(iterator, configInfo.nameSpaces) {
+ FOREACH(iterator, m_widgetConfig.nameSpaces) {
_D("namespace = [%ls]", (*iterator).c_str());
if (*iterator == ConfigurationNamespace::TizenWebAppNamespaceName) {
_D("type = [%s]", m_context.widgetConfig.webAppType.getApptypeToString().c_str());
}
-bool TaskConfiguration::detectResourceEncryption(
- const WrtDB::ConfigParserData &configData)
-{
- FOREACH(it, configData.settingsList)
+void TaskConfiguration::ResourceEncryptionStep()
+{
+ m_context.needEncryption = false;
+ FOREACH(it, m_widgetConfig.settingsList)
{
if (it->m_name == SETTING_VALUE_ENCRYPTION &&
it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE)
{
_D("resource need encryption");
- return true;
+ m_context.needEncryption = true;
}
}
+}
+
+bool TaskConfiguration::getMMCStatus()
+{
+ int mmcStatus;
+ if (vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmcStatus)) {
+ _E("vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS) failed.");
+ return false;
+ }
+
+ switch(mmcStatus)
+ {
+ case VCONFKEY_SYSMAN_MMC_MOUNTED:
+ _D("mmcStatus is MMC_MOUNTED.");
+ return true;
+ case VCONFKEY_SYSMAN_MMC_REMOVED:
+ case VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED:
+ _D("mmcStatus is MMC_REMOVED or NOT_MOUNTED.");
+ return false;
+ default:
+ _E("Platform is not supported, use the default settings");
+ return false;
+ }
+}
+
+bool TaskConfiguration::getDefaultExternalStorage()
+{
+ // XXX NOT IMPLEMENTED.
return false;
}
-void TaskConfiguration::setInstallLocationType(
- const WrtDB::ConfigParserData & configData)
+void TaskConfiguration::InstallationFSLocationStep()
{
m_context.locationType = INSTALL_LOCATION_TYPE_NOMAL;
+ DPL::String locationValue;
+
if (m_context.mode.installTime != InstallMode::InstallTime::PRELOAD) {
- FOREACH(it, configData.settingsList) {
- if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
- it->m_value ==
- SETTING_VALUE_INSTALLTOEXT_PREPER_EXT)
- {
- _D("This widget will be installed to sd card");
- m_context.locationType =
- INSTALL_LOCATION_TYPE_EXTERNAL;
+ FOREACH(it, m_widgetConfig.settingsList) {
+ if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME) {
+ locationValue = it->m_value;
+ break;
}
}
+
+ if ((SETTING_VALUE_INSTALLTOEXT_PREPER_EXT == locationValue
+ && getMMCStatus()) ||
+ (SETTING_VALUE_INSTALLTOEXT_AUTO == locationValue
+ && getDefaultExternalStorage())) {
+ _D("This webapp will be installed to sd card");
+ m_context.locationType = INSTALL_LOCATION_TYPE_EXTERNAL;
+ }
}
}