fixed insert cert info to pkgmgr db when hybridapp.
[framework/web/wrt-installer.git] / src / jobs / widget_install / job_widget_install.cpp
index ce93dcd..e0a26bb 100644 (file)
@@ -41,6 +41,7 @@
 #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-ro/config_parser_data.h>
 #include <dpl/wrt-dao-rw/global_dao.h> // TODO remove
 #include <dpl/localization/w3c_file_localization.h>
 
@@ -85,7 +86,9 @@ const char * const CONFIG_XML = "config.xml";
 const char * const WITH_OSP_XML = "res/wgt/config.xml";
 
 //allowed: a-z, A-Z, 0-9
-const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}$";
+const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}.{1,}$";
+const char* REG_NAME_PATTERN = "^[a-zA-Z0-9._-]{1,}$";
+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";
@@ -122,29 +125,32 @@ class InstallerTaskFail :
 
 const std::string XML_EXTENSION = ".xml";
 
-bool hasExtension(const std::string& filename, const std::string& extension) {
-    LogDebug("Looking for extension " << extension << " in: "  << filename);
+bool hasExtension(const std::string& filename, const std::string& extension)
+{
+    LogDebug("Looking for extension " << extension << " in: " << filename);
     size_t fileLen = filename.length();
     size_t extLen = extension.length();
     if (fileLen < extLen) {
         LogError("Filename " << filename << " is shorter than extension "
-                 << extension);
+                             << extension);
         return false;
     }
-    return (0 == filename.compare(fileLen-extLen, extLen, extension));
+    return (0 == filename.compare(fileLen - extLen, extLen, extension));
 }
 
-bool checkTizenIdExist(const std::string& tizenId) {
+bool checkTizenPkgIdExist(const std::string& tizenPkgId)
+{
     std::string installPath =
         std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
-        "/" + tizenId;
+        "/" + tizenPkgId;
     std::string preinstallPath =
         std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
-        "/" + tizenId;
+        "/" + tizenPkgId;
 
     struct stat dirStat;
-    if ((stat(installPath.c_str(), &dirStat) == 0) &&
-            (stat(preinstallPath.c_str(), &dirStat) == 0)) {
+    if ((stat(installPath.c_str(), &dirStat) == 0) ||
+        (stat(preinstallPath.c_str(), &dirStat) == 0))
+    {
         return true;
     }
     return false;
@@ -153,38 +159,37 @@ bool checkTizenIdExist(const std::string& tizenId) {
 
 namespace Jobs {
 namespace WidgetInstall {
-JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
-        const WidgetInstallationStruct &installerStruct) :
+JobWidgetInstall::JobWidgetInstall(
+    std::string const &widgetPath,
+    const WidgetInstallationStruct &
+    installerStruct) :
     Job(Installation),
     JobContextBase<WidgetInstallationStruct>(installerStruct),
     m_exceptionCaught(Exceptions::Success)
 {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    srand(time(NULL) + tv.tv_usec);
-
     m_installerContext.m_quiet = m_jobStruct.m_quiet;
 
     ConfigureResult result = PrePareInstallation(widgetPath);
 
     if (result == ConfigureResult::Ok) {
         LogInfo("Configure installation succeeded");
+        m_installerContext.job->SetProgressFlag(true);
 
         AddTask(new TaskRecovery(m_installerContext));
 
         // Create installation tasks
         if (m_installerContext.widgetConfig.packagingType !=
-                WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
+            WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
             m_installerContext.widgetConfig.packagingType !=
-                WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
+            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));
         }
@@ -202,21 +207,23 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
         AddTask(new TaskSmack(m_installerContext));
 
         AddTask(new TaskManifestFile(m_installerContext));
-        AddTask(new TaskCertificates(m_installerContext));
         if (m_installerContext.widgetConfig.packagingType ==
-                PKG_TYPE_HYBRID_WEB_APP) {
+            PKG_TYPE_HYBRID_WEB_APP)
+        {
             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_installerContext.widgetConfig.packagingType !=
-                WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
+            WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
             m_installerContext.widgetConfig.packagingType !=
-                WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
+            WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
             !m_isDRM)
         {
             AddTask(new TaskUnzip(m_installerContext));
@@ -225,7 +232,7 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
         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));
         }
@@ -242,7 +249,8 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
 
         AddTask(new TaskManifestFile(m_installerContext));
         if (m_installerContext.widgetConfig.packagingType ==
-                PKG_TYPE_HYBRID_WEB_APP) {
+            PKG_TYPE_HYBRID_WEB_APP)
+        {
             AddTask(new TaskInstallOspsvc(m_installerContext));
         }
         if (m_installerContext.widgetConfig.packagingType !=
@@ -256,7 +264,6 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
         //TODO: remove widgetHandle from this task and move before database task
         // by now widget handle is needed in ace check
         // Any error in acecheck while update will break widget
-
     } else if (result == ConfigureResult::Deferred) {
         // Installation is deferred
         LogInfo("Configure installation deferred");
@@ -273,7 +280,7 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
 }
 
 JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
-        const std::string &widgetPath)
+    const std::string &widgetPath)
 {
     ConfigureResult result;
     m_needEncryption = false;
@@ -286,7 +293,7 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
         m_isDRM = isDRMWidget(widgetPath);
         if (true == m_isDRM) {
             LogDebug("decrypt DRM widget");
-            if(DecryptDRMWidget(widgetPath, tempDir)) {
+            if (DecryptDRMWidget(widgetPath, tempDir)) {
                 LogDebug("Failed decrypt DRM widget");
                 return ConfigureResult::Failed;
             }
@@ -297,18 +304,20 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
         m_installerContext.widgetConfig.packagingType =
             checkPackageType(widgetPath, tempDir);
         ConfigParserData configData = getWidgetDataFromXML(
-            widgetPath,
-            tempDir,
-            m_installerContext.widgetConfig.packagingType,
-            m_isDRM);
+                widgetPath,
+                tempDir,
+                m_installerContext.widgetConfig.packagingType,
+                m_isDRM);
         LogDebug("widget packaging type : " <<
-                m_installerContext.widgetConfig.packagingType.pkgType);
-        WidgetUpdateInfo update = detectWidgetUpdate(configData);
+                 m_installerContext.widgetConfig.packagingType.pkgType);
+
+        setTizenId(configData);
+        setApplicationType(configData);
         m_needEncryption = detectResourceEncryption(configData);
         setInstallLocationType(configData);
 
         // Configure installation
-        result = ConfigureInstallation(widgetPath, configData, update, tempDir);
+        result = ConfigureInstallation(widgetPath, configData, tempDir);
     }
     Catch(Exceptions::ExtractFileFailed)
     {
@@ -319,103 +328,162 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
     return result;
 }
 
-bool JobWidgetInstall::setTizenId(
-        const WrtDB::ConfigParserData &configInfo,
-        const WidgetUpdateInfo &update,
-        bool preload)
+void JobWidgetInstall::setTizenId(
+    const WrtDB::ConfigParserData &configInfo)
 {
+    bool shouldMakeAppid = false;
     using namespace PackageManager;
-    regex_t reg;
-    if(regcomp(&reg, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
-        LogDebug("Regcomp failed");
-    }
+    if (!!configInfo.tizenAppId) {
+        LogDebug("Setting tizenAppId provided in config.xml: " <<
+                 configInfo.tizenAppId);
 
-    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);
+        m_installerContext.widgetConfig.tzAppid = *configInfo.tizenAppId;
+        //check package id.
+        if (!!configInfo.tizenPkgId) {
+            LogDebug("Setting tizenPkgId provided in config.xml: " <<
+                     configInfo.tizenPkgId);
 
-        if (result == ConfigureResult::Failed) {
-            return false;
+            m_installerContext.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
+        } else {
+            DPL::String appid = *configInfo.tizenAppId;
+            if (appid.length() > PACKAGE_ID_LENGTH) {
+                m_installerContext.widgetConfig.tzPkgid =
+                    appid.substr(0, PACKAGE_ID_LENGTH);
+            } else {
+                //old version appid only has 10byte random character is able to install for a while.
+                //this case appid equal pkgid.
+                m_installerContext.widgetConfig.tzPkgid =
+                    *configInfo.tizenAppId;
+                shouldMakeAppid = true;
+            }
         }
-
-        if ((regexec(&reg, DPL::ToUTF8String(*(configInfo.tizenId)).c_str(),
-             static_cast<size_t>(0), NULL, 0) != REG_NOERROR) ||
-            (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.");
-            regfree(&reg);
-            return false;
+    } else {
+        shouldMakeAppid = true;
+        TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
+        LogDebug("Checking if pkg id is unique");
+        while (true) {
+            if (checkTizenPkgIdExist(DPL::ToUTF8String(pkgId))) {
+                //path exist, chose another one
+                pkgId = WidgetDAOReadOnly::generatePkgId();
+                continue;
+            }
+            break;
         }
-        m_installerContext.widgetConfig.pkgName = *configInfo.tizenId;
+        m_installerContext.widgetConfig.tzPkgid = pkgId;
+        LogInfo("tizen_id name was generated by WRT: " <<
+                m_installerContext.widgetConfig.tzPkgid);
+    }
 
-    } else {
-        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
-
-            LogDebug("Checking if tizen id is unique");
-            while (true) {
-                if (checkTizenIdExist(DPL::ToUTF8String(tizenId))) {
-                    //path exist, chose another one
-                    tizenId = WidgetDAOReadOnly::generateTizenId();
-                    continue;
+    if (shouldMakeAppid == true) {
+        DPL::OptionalString name;
+        DPL::OptionalString defaultLocale = configInfo.defaultlocale;
+
+        FOREACH(localizedData, configInfo.localizedDataSet)
+        {
+            Locale i = localizedData->first;
+            if (!!defaultLocale) {
+                if (defaultLocale == i) {
+                    name = localizedData->second.name;
+                    break;
                 }
+            } else {
+                name = localizedData->second.name;
                 break;
             }
+        }
+        regex_t regx;
+        if (regcomp(&regx, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
+            LogDebug("Regcomp failed");
+        }
 
-            m_installerContext.widgetConfig.pkgName = tizenId;
+        LogDebug("Name : " << name);
+        if (!name || (regexec(&regx, DPL::ToUTF8String(*name).c_str(),
+                              static_cast<size_t>(0), NULL, 0) != REG_NOERROR))
+        {
+            // TODO : generate name move to wrt-commons
+            std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+            std::ostringstream genName;
+            struct timeval tv;
+            gettimeofday(&tv, NULL);
+            unsigned int seed = time(NULL) + tv.tv_usec;
+
+            genName << "_" << allowedString[rand_r(&seed) % allowedString.length()];
+            name = DPL::FromUTF8String(genName.str());
+            LogDebug("name was generated by WRT");
         }
-        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(&regx);
+        LogDebug("Name : " << name);
+        std::ostringstream genid;
+        genid << m_installerContext.widgetConfig.tzPkgid << "." << name;
+        LogDebug("tizen appid was generated by WRT : " << genid.str());
+
+        DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
+        NormalizeAndTrimSpaceString(appid);
+        m_installerContext.widgetConfig.tzAppid = *appid;
     }
-    regfree(&reg);
 
-    LogInfo("Tizen Id : " << m_installerContext.widgetConfig.pkgName);
+    // send start signal of pkgmgr
+    getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
+                                                         m_installerContext.
+                                                             widgetConfig.
+                                                             tzPkgid));
+    LogInfo("Tizen App Id : " << m_installerContext.widgetConfig.tzAppid);
+    LogInfo("Tizen Pkg Id : " << m_installerContext.widgetConfig.tzPkgid);
     LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
-    return true;
 }
 
 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.locationType);
+        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));
 
     LogInfo("widgetSource " << widgetPath);
 }
 
 JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
-        const std::string &widgetSource,
-        const WrtDB::ConfigParserData &configData,
-        const WidgetUpdateInfo &update,
-        const std::string &tempPath)
+    const std::string &widgetSource,
+    const WrtDB::ConfigParserData &configData,
+    const std::string &tempPath)
 {
+    WidgetUpdateInfo update = detectWidgetUpdate(
+            configData,
+            m_installerContext.
+                widgetConfig.webAppType,
+            m_installerContext.
+                widgetConfig.tzAppid);
+    ConfigureResult result = checkWidgetUpdate(update);
 
-    if (!setTizenId(configData, update, m_jobStruct.m_preload)) {
-        return ConfigureResult::Failed;
-    } else {
-        LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgName);
+    // Validate tizenId
+    regex_t reg;
+    if (regcomp(&reg, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
+        LogDebug("Regcomp failed");
+    }
 
-        configureWidgetLocation(widgetSource, tempPath);
+    if ((regexec(&reg,
+                 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid).
+                     c_str(),
+                     static_cast<size_t>(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(&reg);
+        return ConfigureResult::Failed;
     }
+    regfree(&reg);
+
+    configureWidgetLocation(widgetSource, tempPath);
 
     // Init installer context
     m_installerContext.installStep = InstallerContext::INSTALL_START;
@@ -423,11 +491,11 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
     m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
     m_installerContext.widgetConfig.shareHref = std::string();
 
-    return ConfigureResult::Ok;
+    return result;
 }
 
 JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
-        const WidgetUpdateInfo &update)
+    const WidgetUpdateInfo &update)
 {
     LogInfo(
         "Widget install/update: incoming guid = '" <<
@@ -442,18 +510,27 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
     if (update.existingWidgetInfo.isExist == false) {
         LogInfo("Widget info does not exist");
         updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
+
+        getInstallerStruct().pkgmgrInterface->sendSignal(
+                PKGMGR_START_KEY,
+                PKGMGR_START_INSTALL);
+
     } else {
-        LogInfo("Widget info exists. PkgName: " <<
-                update.existingWidgetInfo.pkgname);
+        LogInfo("Widget info exists. appid: " <<
+                update.existingWidgetInfo.tzAppid);
 
-        WidgetPkgName pkgname = update.existingWidgetInfo.pkgname;
+        getInstallerStruct().pkgmgrInterface->sendSignal(
+                PKGMGR_START_KEY,
+                PKGMGR_START_UPDATE);
 
-        LogInfo("Widget model exists. package name: " << pkgname);
+        TizenAppId tzAppid = update.existingWidgetInfo.tzAppid;
+
+        LogInfo("Widget model exists. tizen app id: " << tzAppid);
 
         // Check running state
-        int retval = APP_MANAGER_ERROR_NONE;
         bool isRunning = false;
-        retval = app_manager_is_running(DPL::ToUTF8String(pkgname).c_str(), &isRunning);
+        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;
@@ -474,7 +551,7 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
             }
         }
 
-        m_installerContext.widgetConfig.pkgName = pkgname;
+        m_installerContext.widgetConfig.tzAppid = tzAppid;
         OptionalWidgetVersion existingVersion;
         existingVersion = update.existingWidgetInfo.existingVersion;
         OptionalWidgetVersion incomingVersion = update.incomingVersion;
@@ -484,20 +561,20 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
         // Calc proceed flag
         if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
             m_jobStruct.updateMode ==
-                WidgetUpdateMode::PolicyDirectoryForceInstall)
+            WidgetUpdateMode::PolicyDirectoryForceInstall)
         {
             LogInfo("Whether widget policy allow proceed ok");
             return ConfigureResult::Updated;
-        }
-        else
+        } else {
             return ConfigureResult::Failed;
+        }
     }
     return ConfigureResult::Ok;
 }
 
 WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
-        const OptionalWidgetVersion &existingVersion,
-        const OptionalWidgetVersion &incomingVersion) const
+    const OptionalWidgetVersion &existingVersion,
+    const OptionalWidgetVersion &incomingVersion) const
 {
     // Widget is installed, check versions
     if (!existingVersion && !incomingVersion) {
@@ -529,10 +606,10 @@ WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
 }
 
 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
-        const std::string &widgetSource,
-        const std::string &tempPath,
-        WrtDB::PackagingType pkgType,
-        bool isDRM)
+    const std::string &widgetSource,
+    const std::string &tempPath,
+    WrtDB::PackagingType pkgType,
+    bool isDRM)
 {
     // Parse config
     ParserRunner parser;
@@ -542,20 +619,20 @@ ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
     {
         if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
             parser.Parse(widgetSource,
-                    ElementParserPtr(
-                        new RootParser<WidgetParser>(configInfo,
-                            DPL::FromUTF32String(
-                                L"widget"))));
+                         ElementParserPtr(
+                             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"))));
+                                 configInfo,
+                                 DPL::FromUTF32String(L"widget"))));
         } else {
             if (!isDRM) {
                 std::unique_ptr<DPL::ZipInput> zipFile(
-                        new DPL::ZipInput(widgetSource));
+                    new DPL::ZipInput(widgetSource));
 
                 std::unique_ptr<DPL::ZipInput::File> configFile;
 
@@ -572,10 +649,11 @@ ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
                 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
                 DPL::Copy(&inputAdapter, &outputAdapter);
                 parser.Parse(&buffer,
-                        ElementParserPtr(
-                            new RootParser<WidgetParser>(configInfo,
-                                DPL::FromUTF32String(
-                                    L"widget"))));
+                             ElementParserPtr(
+                                 new RootParser<WidgetParser>(configInfo,
+                                                              DPL::
+                                                                  FromUTF32String(
+                                                                  L"widget"))));
             } else {
                 // DRM widget
                 std::string configFile;
@@ -586,10 +664,11 @@ ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
                 }
 
                 parser.Parse(configFile,
-                        ElementParserPtr(
-                            new RootParser<WidgetParser>(configInfo,
-                                DPL::FromUTF32String(
-                                    L"widget"))));
+                             ElementParserPtr(
+                                 new RootParser<WidgetParser>(configInfo,
+                                                              DPL::
+                                                                  FromUTF32String(
+                                                                  L"widget"))));
             }
         }
     }
@@ -627,7 +706,9 @@ ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
 }
 
 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
-        const ConfigParserData &configInfo)
+    const ConfigParserData &configInfo,
+    const WrtDB::WidgetType appType,
+    const WrtDB::TizenAppId &tizenId)
 {
     LogInfo("Checking up widget package for config.xml...");
 
@@ -652,23 +733,44 @@ WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
                 WidgetVersion(*configInfo.version));
     }
 
-    Try
-    {
-        // Search widget handle by GUID
-        WidgetDAOReadOnly dao(widgetGUID);
-        return WidgetUpdateInfo(
-            widgetGUID,
-            widgetVersion,
-            WidgetUpdateInfo::ExistingWidgetInfo(
-                dao.getPkgName(), dao.getVersion()));
-    }
-    Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
-    {
-        // GUID isn't installed
-        return WidgetUpdateInfo(
-            widgetGUID,
-            widgetVersion,
-            WidgetUpdateInfo::ExistingWidgetInfo());
+    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());
+        }
     }
 }
 
@@ -681,12 +783,27 @@ void JobWidgetInstall::SendProgress()
             std::ostringstream percent;
             percent << static_cast<int>(GetProgressPercent());
             getInstallerStruct().pkgmgrInterface->sendSignal(
-                        PKGMGR_PROGRESS_KEY,
-                        percent.str());
+                PKGMGR_PROGRESS_KEY,
+                percent.str());
 
             LogDebug("Call widget install progressCallbak");
-            getInstallerStruct().progressCallback(getInstallerStruct().userParam,
-                    GetProgressPercent(),GetProgressDescription());
+            getInstallerStruct().progressCallback(
+                getInstallerStruct().userParam,
+                GetProgressPercent(),
+                GetProgressDescription());
+        }
+    }
+}
+
+void JobWidgetInstall::SendProgressIconPath(const std::string &path)
+{
+    using namespace PackageManager;
+    if (GetProgressFlag() != false) {
+        if (getInstallerStruct().progressCallback != NULL) {
+            // send progress signal of pkgmgr
+            getInstallerStruct().pkgmgrInterface->sendSignal(
+                PKGMGR_ICON_PATH,
+                path);
         }
     }
 }
@@ -697,7 +814,6 @@ void JobWidgetInstall::SendFinishedSuccess()
     // 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);
@@ -713,16 +829,17 @@ void JobWidgetInstall::SendFinishedSuccess()
     //inform widget info
     JobWidgetInstall::displayWidgetInfo();
 
-    WidgetPkgName& tizenId = m_installerContext.widgetConfig.pkgName;
+    TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
 
     // send signal of pkgmgr
     getInstallerStruct().pkgmgrInterface->sendSignal(
-                PKGMGR_END_KEY,
-                PKGMGR_END_SUCCESS);
+        PKGMGR_END_KEY,
+        PKGMGR_END_SUCCESS);
 
     LogDebug("Call widget install successfinishedCallback");
     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
-            DPL::ToUTF8String(tizenId), Exceptions::Success);
+                                          DPL::ToUTF8String(
+                                              tizenId), Exceptions::Success);
 }
 
 void JobWidgetInstall::SendFinishedFailure()
@@ -733,17 +850,18 @@ void JobWidgetInstall::SendFinishedFailure()
 
     LogError("Error in installation step: " << m_exceptionCaught);
     LogError("Message: " << m_exceptionMessage);
-    WidgetPkgName & tizenId = m_installerContext.widgetConfig.pkgName;
+    TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
 
     LogDebug("Call widget install failure finishedCallback");
 
     // send signal of pkgmgr
     getInstallerStruct().pkgmgrInterface->sendSignal(
-                PKGMGR_END_KEY,
-                PKGMGR_END_FAILURE);
+        PKGMGR_END_KEY,
+        PKGMGR_END_FAILURE);
 
     getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
-            DPL::ToUTF8String(tizenId), m_exceptionCaught);
+                                          DPL::ToUTF8String(
+                                              tizenId), m_exceptionCaught);
 }
 
 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
@@ -754,38 +872,39 @@ void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
 
 void JobWidgetInstall::displayWidgetInfo()
 {
-    WidgetDAOReadOnly dao(m_installerContext.locations->getPkgname());
+    WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
 
     std::ostringstream out;
     WidgetLocalizedInfo localizedInfo =
-        W3CFileLocalization::getLocalizedInfo(dao.getPkgName());
+        W3CFileLocalization::getLocalizedInfo(dao.getTzAppId());
 
     out << std::endl <<
-        "===================================== INSTALLED WIDGET INFO ========="\
-        "============================";
+    "===================================== INSTALLED WIDGET INFO =========" \
+    "============================";
     out << std::endl << "Name:                        " << localizedInfo.name;
-    out << std::endl << "PkgName:                     " << dao.getPkgName();
+    out << std::endl << "AppId:                     " << dao.getTzAppId();
     WidgetSize size = dao.getPreferredSize();
     out << std::endl << "Width:                       " << size.width;
     out << std::endl << "Height:                      " << size.height;
     out << std::endl << "Start File:                  " <<
-        W3CFileLocalization::getStartFile(dao.getPkgName());
+    W3CFileLocalization::getStartFile(dao.getTzAppId());
     out << std::endl << "Version:                     " << dao.getVersion();
     out << std::endl << "Licence:                     " <<
-        localizedInfo.license;
+    localizedInfo.license;
     out << std::endl << "Licence Href:                " <<
-        localizedInfo.licenseHref;
+    localizedInfo.licenseHref;
     out << std::endl << "Description:                 " <<
-        localizedInfo.description;
+    localizedInfo.description;
     out << std::endl << "Widget Id:                   " << dao.getGUID();
     out << std::endl << "Widget recognized:           " << dao.isRecognized();
     out << std::endl << "Widget wac signed:           " << dao.isWacSigned();
     out << std::endl << "Widget distributor signed:   " <<
-        dao.isDistributorSigned();
+    dao.isDistributorSigned();
     out << std::endl << "Widget trusted:              " << dao.isTrusted();
 
-    OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getPkgName());
-    DPL::OptionalString iconSrc = !!icon ? icon->src : DPL::OptionalString::Null;
+    OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTzAppId());
+    DPL::OptionalString iconSrc =
+        !!icon ? icon->src : DPL::OptionalString::Null;
     out << std::endl << "Icon:                        " << iconSrc;
 
     out << std::endl << "Preferences:";
@@ -794,9 +913,9 @@ void JobWidgetInstall::displayWidgetInfo()
         FOREACH(it, list)
         {
             out << std::endl << "  Key:                       " <<
-                it->key_name;
+            it->key_name;
             out << std::endl << "      Readonly:              " <<
-                it->readonly;
+            it->readonly;
         }
     }
 
@@ -817,11 +936,12 @@ void JobWidgetInstall::displayWidgetInfo()
 }
 
 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
-        const std::string &widgetSource,
-        const std::string &tempPath)
+    const std::string &widgetSource,
+    const std::string &tempPath)
 {
     // Check installation type (direcotory/ or config.xml or widget.wgt)
-    if (WidgetUpdateMode::PolicyDirectoryForceInstall == m_jobStruct.updateMode)
+    if (WidgetUpdateMode::PolicyDirectoryForceInstall ==
+        m_jobStruct.updateMode)
     {
         LogDebug("Install directly from directory");
         return PKG_TYPE_DIRECTORY_WEB_APP;
@@ -848,7 +968,6 @@ WrtDB::PackagingType JobWidgetInstall::checkPackageType(
         {
             // Open zip file
             zipFile.reset(new DPL::ZipInput(widgetSource));
-
         }
         Catch(DPL::ZipInput::Exception::OpenFailed)
         {
@@ -865,7 +984,7 @@ WrtDB::PackagingType JobWidgetInstall::checkPackageType(
         {
             // Open config.xml file in package root
             std::unique_ptr<DPL::ZipInput::File> configFile(
-                    zipFile->OpenFile(CONFIG_XML));
+                zipFile->OpenFile(CONFIG_XML));
             return PKG_TYPE_NOMAL_WEB_APP;
         }
         Catch(DPL::ZipInput::Exception::OpenFileFailed)
@@ -877,7 +996,7 @@ WrtDB::PackagingType JobWidgetInstall::checkPackageType(
         {
             // Open config.xml file in package root
             std::unique_ptr<DPL::ZipInput::File> configFile(
-                    zipFile->OpenFile(WITH_OSP_XML));
+                zipFile->OpenFile(WITH_OSP_XML));
 
             return PKG_TYPE_HYBRID_WEB_APP;
         }
@@ -891,12 +1010,60 @@ WrtDB::PackagingType JobWidgetInstall::checkPackageType(
     return PKG_TYPE_UNKNOWN;
 }
 
-bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &configData)
+void JobWidgetInstall::setApplicationType(
+    const WrtDB::ConfigParserData &configInfo)
+{
+    FOREACH(iterator, configInfo.nameSpaces) {
+        LogInfo("namespace = [" << *iterator << "]");
+        AppType currentAppType = APP_TYPE_UNKNOWN;
+
+        if (*iterator == ConfigurationNamespace::W3CWidgetNamespaceName) {
+            continue;
+        } else if (
+            *iterator ==
+            ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement ||
+            *iterator ==
+            ConfigurationNamespace::WacWidgetNamespaceName)
+        {
+            currentAppType = APP_TYPE_WAC20;
+        } else if (*iterator ==
+                   ConfigurationNamespace::TizenWebAppNamespaceName)
+        {
+            currentAppType = APP_TYPE_TIZENWEBAPP;
+        }
+
+        if (m_installerContext.widgetConfig.webAppType ==
+            APP_TYPE_UNKNOWN)
+        {
+            m_installerContext.widgetConfig.webAppType = currentAppType;
+        } else if (m_installerContext.widgetConfig.webAppType ==
+                   currentAppType)
+        {
+            continue;
+        } else {
+            ThrowMsg(Exceptions::WidgetConfigFileInvalid,
+                     "Config.xml has more than one namespace");
+        }
+    }
+
+    // If there is no define, type set to WAC 2.0
+    if (m_installerContext.widgetConfig.webAppType == APP_TYPE_UNKNOWN) {
+        m_installerContext.widgetConfig.webAppType = APP_TYPE_WAC20;
+    }
+
+    LogInfo("type = [" <<
+            m_installerContext.widgetConfig.webAppType.getApptypeToString() <<
+            "]");
+}
+
+bool JobWidgetInstall::detectResourceEncryption(
+    const WrtDB::ConfigParserData &configData)
 {
     FOREACH(it, configData.settingsList)
     {
         if (it->m_name == SETTING_VALUE_ENCRYPTION &&
-                it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE) {
+            it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE)
+        {
             LogDebug("resource need encryption");
             return true;
         }
@@ -904,8 +1071,10 @@ bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &c
     return false;
 }
 
-void JobWidgetInstall::setInstallLocationType(const
-        WrtDB::ConfigParserData &configData)
+void JobWidgetInstall::setInstallLocationType(
+    const
+    WrtDB::ConfigParserData &
+    configData)
 {
     m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
 
@@ -916,8 +1085,9 @@ void JobWidgetInstall::setInstallLocationType(const
         FOREACH(it, configData.settingsList)
         {
             if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
-                    it->m_value ==
-                    SETTING_VALUE_INSTALLTOEXT_PREPER_EXT) {
+                it->m_value ==
+                SETTING_VALUE_INSTALLTOEXT_PREPER_EXT)
+            {
                 LogDebug("This widget will be installed to sd card");
                 m_installerContext.locationType =
                     INSTALL_LOCATION_TYPE_EXTERNAL;
@@ -929,16 +1099,16 @@ void JobWidgetInstall::setInstallLocationType(const
 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) {
-    */
+     * 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<char*>(widgetPath.c_str()));
-    if ( 1 == ret) {
+    if (1 == ret) {
         return true;
     } else {
         return false;
@@ -946,34 +1116,34 @@ bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
 }
 
 bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
-        std::string destPath)
+                                        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;
-    }
-    */
+     * 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<char*>(widgetPath.c_str()),
-                const_cast<char*>(destPath.c_str())) != 0) {
+                                      const_cast<char*>(destPath.c_str())) != 0)
+    {
         return true;
     } else {
         return false;
     }
 }
-
 } //namespace WidgetInstall
 } //namespace Jobs