Fixed build break
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_configuration.cpp
index 5bdae02..72513a1 100644 (file)
@@ -29,6 +29,7 @@
 #include <cstdlib>
 #include <limits.h>
 #include <regex.h>
+#include <vconf.h>
 
 #include <dpl/utils/wrt_utility.h>
 #include <dpl/utils/path.h>
@@ -39,7 +40,6 @@
 #include <dpl/localization/w3c_file_localization.h>
 
 #include <libiriwrapper.h>
-#include <pkg-manager/pkgmgr_signal.h>
 #include <app_manager.h>
 
 #include "root_parser.h"
@@ -53,6 +53,8 @@
 #include <widget_install/job_widget_install.h>
 #include <widget_install/task_commons.h>
 
+#include <installer_log.h>
+
 using namespace WrtDB;
 
 namespace {
@@ -68,21 +70,18 @@ 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";
 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)
 {
-    LogDebug("Looking for extension " << extension << " in: " << filename);
+    _D("Looking for extension %s in %s", extension.c_str(), filename.c_str());
     size_t fileLen = filename.length();
     size_t extLen = extension.length();
     if (fileLen < extLen) {
-        LogError("Filename " << filename << " is shorter than extension "
-                             << extension);
+        _E("Filename %s is shorter than extension %s", filename.c_str(), extension.c_str());
         return false;
     }
     return (0 == filename.compare(fileLen - extLen, extLen, extension));
@@ -95,152 +94,121 @@ namespace WidgetInstall {
 TaskConfiguration::TaskConfiguration(InstallerContext& context) :
     DPL::TaskDecl<TaskConfiguration>(this),
     m_context(context),
-    m_result(ConfigureResult::Unknown)
+    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);
 }
 
 void TaskConfiguration::StartStep()
 {
-    LogDebug("--------- <TaskConfiguration> : START ----------");
+    _D("--------- <TaskConfiguration> : START ----------");
 }
 
 void TaskConfiguration::EndStep()
 {
-    LogDebug("--------- <TaskConfiguration> : END ----------");
+    _D("--------- <TaskConfiguration> : END ----------");
 }
 
-void TaskConfiguration::AppendTasklistStep()
+void TaskConfiguration::PkgmgrStartStep()
 {
-    // TODO: (job_install_refactoring) do not store config result anywhere
-    m_context.confResult = m_result;
+    pkgMgrInterface()->sendSignal(
+            PKGMGR_PROGRESS_KEY,
+            PKGMGR_START_VALUE);
+}
 
-    if (m_result == ConfigureResult::Ok) {
-        LogInfo("TaskConfiguration -> new installation task list");
+void TaskConfiguration::AppendTasklistStep()
+{
+    if (!m_context.isUpdateMode) {
+        _D("TaskConfiguration -> new installation task list");
         m_context.job->appendNewInstallationTaskList();
-    } else if (m_result == ConfigureResult::Updated) {
-        LogInfo("TaskConfiguration -> update installation task list");
-        m_context.job->appendUpdateInstallationTaskList();
     } else {
-        LogInfo("TaskConfiguration -> failure task list");
-        m_context.job->appendFailureTaskList();
+        _D("TaskConfiguration -> update installation task list");
+        m_context.job->appendUpdateInstallationTaskList();
     }
 }
 
-void TaskConfiguration::PrepareInstallationStep()
+std::shared_ptr<PackageManager::IPkgmgrSignal> TaskConfiguration::pkgMgrInterface()
 {
-    // TODO: (job_install_refactoring) clean up this task
-    std::string widgetPath = m_context.requestedPath;
-    ConfigureResult result;
-    m_context.needEncryption = false;
-    Try
-    {
-        std::string tempDir;
-        if (m_context.mode.extension == InstallMode::ExtensionType::DIR) {
-            if (m_context.mode.command ==
-                    InstallMode::Command::REINSTALL) {
-                std::ostringstream tempPathBuilder;
-                tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
-                tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
-                tempPathBuilder << "/";
-                tempPathBuilder << widgetPath;
-                tempDir = tempPathBuilder.str();
-            } else {
-                tempDir = widgetPath;
-            }
+    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) {
+            std::ostringstream tempPathBuilder;
+            tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
+            tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
+            tempPathBuilder << "/";
+            tempPathBuilder << m_context.requestedPath;
+            m_tempDir = tempPathBuilder.str();
         } else {
-            tempDir =
-                Jobs::WidgetInstall::createTempPath(
-                        m_context.mode.rootPath ==
-                            InstallMode::RootPath::RO);
+            m_tempDir = m_context.requestedPath;
+        }
+    } else {
+        m_tempDir =
+            Jobs::WidgetInstall::createTempPath(
+                    m_context.mode.rootPath ==
+                        InstallMode::RootPath::RO);
+        if(!hasExtension(m_context.requestedPath, XML_EXTENSION)) //unzip everything except xml files
+        {
             WidgetUnzip wgtUnzip;
-            wgtUnzip.unzipWgtFile(widgetPath, tempDir);
+            wgtUnzip.unzipWgtFile(m_context.requestedPath, m_tempDir);
+        }
+        else
+        {
+            _D("From browser installation - unzip is not done");
         }
-
-        LogDebug("widgetPath:" << widgetPath);
-        LogDebug("tempPath:" << tempDir);
-
-        m_context.widgetConfig.packagingType =
-            checkPackageType(widgetPath, tempDir);
-        ConfigParserData configData = getWidgetDataFromXML(
-                widgetPath,
-                tempDir,
-                m_context.widgetConfig.packagingType,
-                m_context.mode.command == InstallMode::Command::REINSTALL);
-        LogDebug("widget packaging type : " <<
-                 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());
-        LogDebug("Caller Package Id : " << m_context.callerPkgId);
-
-        // 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);
-    }
-    Catch(Exceptions::OpenZipFailed)
-    {
-        LogError("Failed to unzip for widget");
-        result = ConfigureResult::Failed_OpenZipError;
-    }
-    Catch(Exceptions::ExtractFileFailed)
-    {
-        LogError("Failed to unzip for widget");
-        result = ConfigureResult::Failed_UnzipError;
-    }
-    Catch(Exceptions::DrmDecryptFailed)
-    {
-        LogError("Failed to unzip for widget");
-        result = ConfigureResult::Failed_DrmError;
-    }
-    Catch(Exceptions::MissingConfig)
-    {
-        LogError("Failed to localize config.xml");
-        result = ConfigureResult::Failed_InvalidConfig;
-    }
-    Catch(Exceptions::WidgetConfigFileInvalid)
-    {
-        LogError("Invalid configuration file");
-        result = ConfigureResult::Failed_InvalidConfig;
-    }
-    Catch(DPL::Exception)
-    {
-        LogError("Unknown exception");
-        result = ConfigureResult::Failed;
     }
+}
 
-    m_result = result;
+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));
 }
 
-void TaskConfiguration::setTizenId(
-    const WrtDB::ConfigParserData &configInfo)
+void TaskConfiguration::TizenIdStep()
 {
     bool shouldMakeAppid = false;
     using namespace PackageManager;
-    if (!!configInfo.tizenAppId) {
-        LogDebug("Setting tizenAppId provided in config.xml: " <<
-                 configInfo.tizenAppId);
 
-        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) {
-            LogDebug("Setting tizenPkgId provided in config.xml: " <<
-                     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 = *configInfo.tizenPkgId;
+            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);
@@ -248,14 +216,14 @@ void TaskConfiguration::setTizenId(
                 //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;
             }
         }
     } else {
         shouldMakeAppid = true;
         TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
-        LogDebug("Checking if pkg id is unique");
+        _D("Checking if pkg id is unique");
         while (true) {
             if (!validateTizenPackageID(pkgId)) {
                 //path exist, chose another one
@@ -265,15 +233,14 @@ void TaskConfiguration::setTizenId(
             break;
         }
         m_context.widgetConfig.tzPkgid = pkgId;
-        LogDebug("tizen_id name was generated by WRT: " <<
-                m_context.widgetConfig.tzPkgid);
+        _D("tizen_id name was generated by WRT: %ls", m_context.widgetConfig.tzPkgid.c_str());
     }
 
     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) {
@@ -288,15 +255,14 @@ void TaskConfiguration::setTizenId(
         }
         regex_t regx;
         if (regcomp(&regx, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
-            LogDebug("Regcomp failed");
+            _D("Regcomp failed");
         }
 
-        LogDebug("Name : " << name);
+        _D("Name : %ls", (*name).c_str());
         if (!name || (regexec(&regx, 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);
@@ -304,13 +270,13 @@ void TaskConfiguration::setTizenId(
 
             genName << "_" << allowedString[rand_r(&seed) % allowedString.length()];
             name = DPL::FromUTF8String(genName.str());
-            LogDebug("name was generated by WRT");
+            _D("name was generated by WRT");
         }
         regfree(&regx);
-        LogDebug("Name : " << name);
+        _D("Name : %ls", (*name).c_str());
         std::ostringstream genid;
         genid << m_context.widgetConfig.tzPkgid << "." << name;
-        LogDebug("tizen appid was generated by WRT : " << genid.str());
+        _D("tizen appid was generated by WRT : %s", genid.str().c_str());
 
         DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
         NormalizeAndTrimSpaceString(appid);
@@ -318,23 +284,17 @@ void TaskConfiguration::setTizenId(
     }
 
     // send start signal of pkgmgr
-    // TODO: (job_install_refactoring) hide this call
-    m_context.job->getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
-                                                         m_context.
-                                                             widgetConfig.
-                                                             tzPkgid));
-    LogDebug("Tizen App Id : " << m_context.widgetConfig.tzAppid);
-    LogDebug("Tizen Pkg Id : " << m_context.widgetConfig.tzPkgid);
-    LogDebug("W3C Widget GUID : " << m_context.widgetConfig.guid);
+    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,
@@ -342,72 +302,64 @@ void TaskConfiguration::configureWidgetLocation(const std::string & widgetPath,
     m_context.locations->registerAppid(
         DPL::ToUTF8String(m_context.widgetConfig.tzAppid));
 
-    LogDebug("widgetSource " << widgetPath);
+    _D("widgetSource %s", m_context.requestedPath.c_str());
 }
 
-ConfigureResult TaskConfiguration::ConfigureInstallation(
-    const std::string &widgetSource,
-    const WrtDB::ConfigParserData &configData,
-    const std::string &tempPath)
+void TaskConfiguration::DetectUpdateInstallationStep()
 {
-    ConfigureResult result = ConfigureResult::Failed;
     WidgetUpdateInfo update;
-
     // checking installed web application
     Try {
-        // checking existing application is installed
-        WidgetDAOReadOnly dao(m_context.widgetConfig.tzAppid);
         // 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 != ConfigureResult::Updated) {
-            // Already installed TizenAppId. return failed
-            return ConfigureResult::Failed_AlreadyInstalled;
-        }
-        if (!checkSupportRDSUpdate(configData)) {
-            return ConfigureResult::Failed_NotSupportRDSUpdate;
-        }
+        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 = ConfigureResult::Ok;
+        pkgMgrInterface()->sendSignal(PKGMGR_START_KEY, PKGMGR_START_INSTALL);
+
         m_context.isUpdateMode = false;
 
         if (!validateTizenApplicationID(
             m_context.widgetConfig.tzAppid))
         {
-            LogError("tizen application ID is already used");
-            return ConfigureResult::Failed_InvalidConfig;
+            _E("tizen application ID is already used");
+            ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetConfigFileInvalid,
+                "invalid config");
         }
         if (!validateTizenPackageID(m_context.widgetConfig.tzPkgid)) {
-            LogError("tizen package ID is already used");
-            return ConfigureResult::Failed_AlreadyInstalled;
+            _E("tizen package ID is already used");
+            ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageAlreadyInstalled,
+                "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(
     const WrtDB::TizenAppId &tizenAppId)
 {
-    LogDebug("tizen application ID = [" << tizenAppId << "]");
+    _D("tizen application ID = [%ls]", tizenAppId.c_str());
 
     regex_t reg;
     if (regcomp(&reg, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
-        LogDebug("Regcomp failed");
+        _D("Regcomp failed");
     }
 
     if (regexec(&reg, DPL::ToUTF8String(tizenAppId).c_str(), 0, NULL, 0)
@@ -437,25 +389,26 @@ bool TaskConfiguration::validateTizenPackageID(
     return true;
 }
 
-ConfigureResult TaskConfiguration::checkWidgetUpdate(
+bool TaskConfiguration::checkWidgetUpdate(
     const WidgetUpdateInfo &update)
 {
     if (update.existingVersion.IsNull() || update.incomingVersion.IsNull()) {
-        return ConfigureResult::Failed;
+        return false;
     }
 
-    LogDebug("existing version = '" << update.existingVersion);
-    LogDebug("incoming version = '" << update.incomingVersion);
-    LogDebug("Tizen AppID = " << update.tzAppId);
+    _D("existing version = '%ls", update.existingVersion->Raw().c_str());
+    _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(),
                                &isRunning);
     if (APP_MANAGER_ERROR_NONE != ret) {
-        LogError("Fail to get running state");
-        return ConfigureResult::Failed_WidgetRunning;
+        _E("Fail to get running state");
+        ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
+                "widget is running");
     }
 
     if (true == isRunning) {
@@ -467,16 +420,18 @@ ConfigureResult TaskConfiguration::checkWidgetUpdate(
                 DPL::ToUTF8String(update.tzAppId).c_str(),
                 &appCtx);
         if (APP_MANAGER_ERROR_NONE != ret) {
-            LogError("Fail to get app_context");
-            return ConfigureResult::Failed_WidgetRunning;
+            _E("Fail to get app_context");
+            ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
+                    "widget is running");
         }
 
         // terminate app_context_h
         ret = app_manager_terminate_app(appCtx);
         if (APP_MANAGER_ERROR_NONE != ret) {
-            LogError("Fail to terminate running application");
+            _E("Fail to terminate running application");
             app_context_destroy(appCtx);
-            return ConfigureResult::Failed_WidgetRunning;
+            ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
+                    "widget is running");
         } else {
             app_context_destroy(appCtx);
             // app_manager_terminate_app isn't sync API
@@ -491,33 +446,36 @@ ConfigureResult TaskConfiguration::checkWidgetUpdate(
                         DPL::ToUTF8String(update.tzAppId).c_str(),
                         &isStillRunning);
                 if (APP_MANAGER_ERROR_NONE != ret) {
-                    LogError("Fail to get running state");
-                    return ConfigureResult::Failed_WidgetRunning;
+                    _E("Fail to get running state");
+                    ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
+                            "widget is running");
                 }
                 if (!isStillRunning) {
                     break;
                 }
             }
             if (isStillRunning) {
-                LogError("Fail to terminate running application");
-                return ConfigureResult::Failed_WidgetRunning;
+                _E("Fail to terminate running application");
+                ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
+                        "widget is running");
             }
-            LogDebug("terminate application");
+            _D("terminate application");
         }
     }
+    //...
 
     m_context.widgetConfig.tzAppid = update.tzAppId;
 
     if (!!update.existingVersion ||
             m_context.mode.extension ==
             InstallMode::ExtensionType::DIR) {
-        return ConfigureResult::Updated;
+        return true;
     }
 
-    return ConfigureResult::Failed;
+    return false;
 }
 
-ConfigParserData TaskConfiguration::getWidgetDataFromXML(
+void TaskConfiguration::parseWidgetXMLConfig(
     const std::string &widgetSource,
     const std::string &tempPath,
     WrtDB::PackagingType pkgType,
@@ -525,13 +483,12 @@ ConfigParserData TaskConfiguration::getWidgetDataFromXML(
 {
     // 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 {
@@ -558,9 +515,16 @@ ConfigParserData TaskConfiguration::getWidgetDataFromXML(
                 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"))));
@@ -568,27 +532,25 @@ ConfigParserData TaskConfiguration::getWidgetDataFromXML(
     }
     Catch(ElementParser::Exception::ParseError)
     {
-        LogError("Failed to parse config.xml file");
-        return ConfigParserData();
+        _E("Failed to parse config.xml file");
+        ThrowMsg(Exceptions::WidgetConfigFileInvalid, "Parser exeption");
     }
     Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
     {
-        LogError("Failed to find installed widget - give proper tizenId");
-        return ConfigParserData();
+        _E("Failed to find installed widget - give proper tizenId");
+        ThrowMsg(Exceptions::RDSDeltaFailure, "WidgetNotExist");
     }
     Catch(Exceptions::WidgetConfigFileNotFound){
-        LogError("Failed to find config.xml");
-        return ConfigParserData();
+        _E("Failed to find config.xml");
+        ThrowMsg(Exceptions::MissingConfig, "Parser exeption");
     }
-
-    return configInfo;
 }
 
 WidgetUpdateInfo TaskConfiguration::detectWidgetUpdate(
     const ConfigParserData &configInfo,
     const WrtDB::TizenAppId &tizenId)
 {
-    LogDebug("Checking up widget package for config.xml...");
+    _D("Checking up widget package for config.xml...");
     OptionalWidgetVersion incomingVersion;
 
     if (!configInfo.version.IsNull()) {
@@ -611,82 +573,103 @@ WidgetUpdateInfo TaskConfiguration::detectWidgetUpdate(
         incomingVersion);
 }
 
-
-WrtDB::PackagingType TaskConfiguration::checkPackageType(
-    const std::string &widgetSource,
-    const std::string &tempPath)
+void TaskConfiguration::CheckPackageTypeStep()
 {
-    if (hasExtension(widgetSource, XML_EXTENSION)) {
-        LogDebug("Hosted app installation");
-        return PKG_TYPE_HOSTED_WEB_APP;
+    if (hasExtension(m_context.requestedPath, XML_EXTENSION)) {
+        _D("Hosted app installation");
+        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) {
-        LogDebug("namespace = [" << *iterator << "]");
+    FOREACH(iterator, m_widgetConfig.nameSpaces) {
+        _D("namespace = [%ls]", (*iterator).c_str());
 
         if (*iterator == ConfigurationNamespace::TizenWebAppNamespaceName) {
-            if (widgetAppType != APP_TYPE_UNKNOWN &&
-                widgetAppType != APP_TYPE_TIZENWEBAPP)
-            {
-                LogError("To many namespaces declared in configuration fileA.");
-                ThrowMsg(Exceptions::WidgetConfigFileInvalid,
-                         "Config.xml has more than one valid namespace");
-            }
             widgetAppType = APP_TYPE_TIZENWEBAPP;
-        } else {
-            LogDebug("Namespace ignored.");
+            break;
         }
     }
 
     m_context.widgetConfig.webAppType = widgetAppType;
 
-    LogDebug("type = [" <<
-            m_context.widgetConfig.webAppType.getApptypeToString() <<
-            "]");
+    _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)
         {
-            LogDebug("resource need encryption");
-            return true;
+            _D("resource need encryption");
+            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)
-            {
-                LogDebug("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;
+        }
     }
 }
 
@@ -717,7 +700,7 @@ bool TaskConfiguration::checkSupportRDSUpdate(const WrtDB::ConfigParserData
             }
         }
         if (configValue != dbValue) {
-            LogError("Not Support RDS mode because of encryption setting");
+            _E("Not Support RDS mode because of encryption setting");
             return false;
         }
     }