Fixed build break
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_configuration.cpp
index d790b94..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"
@@ -70,11 +70,9 @@ 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)
@@ -96,11 +94,27 @@ 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);
 }
 
@@ -114,129 +128,87 @@ void TaskConfiguration::EndStep()
     _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) {
+void TaskConfiguration::AppendTasklistStep()
+{
+    if (!m_context.isUpdateMode) {
         _D("TaskConfiguration -> new installation task list");
         m_context.job->appendNewInstallationTaskList();
-    } else if (m_result == ConfigureResult::Updated) {
+    } else {
         _D("TaskConfiguration -> update installation task list");
         m_context.job->appendUpdateInstallationTaskList();
-    } else {
-        _D("TaskConfiguration -> failure task list");
-        m_context.job->appendFailureTaskList();
     }
 }
 
-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");
         }
-
-        _D("widgetPath:%s", widgetPath.c_str());
-        _D("tempPath:%s", tempDir.c_str());
-
-        m_context.widgetConfig.packagingType =
-            checkPackageType(widgetPath, tempDir);
-        ConfigParserData configData = getWidgetDataFromXML(
-                widgetPath,
-                tempDir,
-                m_context.widgetConfig.packagingType,
-                m_context.mode.command == InstallMode::Command::REINSTALL);
-        _D("widget packaging type : %d", 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 : %ls", 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);
-    }
-    Catch(Exceptions::OpenZipFailed)
-    {
-        _E("Failed to unzip for widget");
-        result = ConfigureResult::Failed_OpenZipError;
-    }
-    Catch(Exceptions::ExtractFileFailed)
-    {
-        _E("Failed to unzip for widget");
-        result = ConfigureResult::Failed_UnzipError;
-    }
-    Catch(Exceptions::DrmDecryptFailed)
-    {
-        _E("Failed to unzip for widget");
-        result = ConfigureResult::Failed_DrmError;
-    }
-    Catch(Exceptions::MissingConfig)
-    {
-        _E("Failed to localize config.xml");
-        result = ConfigureResult::Failed_InvalidConfig;
-    }
-    Catch(Exceptions::WidgetConfigFileInvalid)
-    {
-        _E("Invalid configuration file");
-        result = ConfigureResult::Failed_InvalidConfig;
-    }
-    Catch(DPL::Exception)
-    {
-        _E("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) {
-        _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);
@@ -244,7 +216,7 @@ 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;
             }
         }
@@ -266,9 +238,9 @@ void TaskConfiguration::setTizenId(
 
     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) {
@@ -290,8 +262,7 @@ void TaskConfiguration::setTizenId(
         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);
@@ -313,22 +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));
-    _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,
@@ -336,62 +302,54 @@ void TaskConfiguration::configureWidgetLocation(const std::string & widgetPath,
     m_context.locations->registerAppid(
         DPL::ToUTF8String(m_context.widgetConfig.tzAppid));
 
-    _D("widgetSource %s", widgetPath.c_str());
+    _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))
         {
             _E("tizen application ID is already used");
-            return ConfigureResult::Failed_InvalidConfig;
+            ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetConfigFileInvalid,
+                "invalid config");
         }
         if (!validateTizenPackageID(m_context.widgetConfig.tzPkgid)) {
             _E("tizen package ID is already used");
-            return ConfigureResult::Failed_AlreadyInstalled;
+            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(
@@ -431,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;
     }
 
     _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) {
         _E("Fail to get running state");
-        return ConfigureResult::Failed_WidgetRunning;
+        ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
+                "widget is running");
     }
 
     if (true == isRunning) {
@@ -462,7 +421,8 @@ ConfigureResult TaskConfiguration::checkWidgetUpdate(
                 &appCtx);
         if (APP_MANAGER_ERROR_NONE != ret) {
             _E("Fail to get app_context");
-            return ConfigureResult::Failed_WidgetRunning;
+            ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
+                    "widget is running");
         }
 
         // terminate app_context_h
@@ -470,7 +430,8 @@ ConfigureResult TaskConfiguration::checkWidgetUpdate(
         if (APP_MANAGER_ERROR_NONE != ret) {
             _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
@@ -486,7 +447,8 @@ ConfigureResult TaskConfiguration::checkWidgetUpdate(
                         &isStillRunning);
                 if (APP_MANAGER_ERROR_NONE != ret) {
                     _E("Fail to get running state");
-                    return ConfigureResult::Failed_WidgetRunning;
+                    ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
+                            "widget is running");
                 }
                 if (!isStillRunning) {
                     break;
@@ -494,24 +456,26 @@ ConfigureResult TaskConfiguration::checkWidgetUpdate(
             }
             if (isStillRunning) {
                 _E("Fail to terminate running application");
-                return ConfigureResult::Failed_WidgetRunning;
+                ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
+                        "widget is running");
             }
             _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,
@@ -519,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 {
@@ -552,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"))));
@@ -563,19 +533,17 @@ ConfigParserData TaskConfiguration::getWidgetDataFromXML(
     Catch(ElementParser::Exception::ParseError)
     {
         _E("Failed to parse config.xml file");
-        return ConfigParserData();
+        ThrowMsg(Exceptions::WidgetConfigFileInvalid, "Parser exeption");
     }
     Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
     {
         _E("Failed to find installed widget - give proper tizenId");
-        return ConfigParserData();
+        ThrowMsg(Exceptions::RDSDeltaFailure, "WidgetNotExist");
     }
     Catch(Exceptions::WidgetConfigFileNotFound){
         _E("Failed to find config.xml");
-        return ConfigParserData();
+        ThrowMsg(Exceptions::MissingConfig, "Parser exeption");
     }
-
-    return configInfo;
 }
 
 WidgetUpdateInfo TaskConfiguration::detectWidgetUpdate(
@@ -605,29 +573,27 @@ 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) {
@@ -641,36 +607,69 @@ void TaskConfiguration::setApplicationType(
     _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;
+        }
     }
 }