Task database fix - TC11
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_database.cpp
index 3054c08..78c06ef 100644 (file)
@@ -27,6 +27,7 @@
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
 #include <dpl/wrt-dao-rw/widget_dao.h>
+#include <dpl/wrt-dao-ro/vconf_config.h>
 #include <dpl/foreach.h>
 #include <dpl/utils/wrt_utility.h>
 #include <dpl/log/log.h>
 #include <ace_registration.h>
 #include <errno.h>
 #include <string.h>
+#include <vconf.h>
+#include <map>
 
 using namespace WrtDB;
 
 namespace Jobs {
 namespace WidgetInstall {
+
 TaskDatabase::TaskDatabase(InstallerContext& context) :
     DPL::TaskDecl<TaskDatabase>(this),
     m_context(context),
@@ -52,6 +56,7 @@ TaskDatabase::TaskDatabase(InstallerContext& context) :
     AddStep(&TaskDatabase::StepWrtDBInsert);
     AddStep(&TaskDatabase::StepAceDBInsert);
     AddStep(&TaskDatabase::StepRemoveExternalFiles);
+    AddStep(&TaskDatabase::StepCreateVconf);
 
     AddAbortStep(&TaskDatabase::StepAbortDBInsert);
 }
@@ -65,9 +70,17 @@ void TaskDatabase::StepWrtDBInsert()
 
         if (m_context.existingWidgetInfo.isExist) //update
         {
-            m_handleToRemove = WidgetDAOReadOnly::getHandle(
-                m_context.locations->getPkgname());
             LogInfo("Registering widget... (update)");
+            Try
+            {
+                m_handleToRemove = WidgetDAOReadOnly::getHandle(
+                    m_context.locations->getPkgname());
+            }
+            Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
+            {
+                LogError("Given tizenId not found for update installation (Same GUID?)");
+                ThrowMsg(Exceptions::InvalidPackage, "Given tizenId not found for update installation");
+            }
             WidgetDAO::registerOrUpdateWidget(
                     m_context.locations->getPkgname(),
                     m_context.widgetConfig,
@@ -121,7 +134,7 @@ void TaskDatabase::StepAceDBInsert()
                                   m_context.wacSecurity.getCertificateList()))
     {
         LogError("ace database insert failed");
-        ThrowMsg(Exceptions::NotAllowed, "Update failure. ace_register_widget failed");
+        ThrowMsg(Exceptions::UpdateFailed, "Update failure. ace_register_widget failed");
     }
     LogDebug("Ace data inserted");
 
@@ -135,15 +148,23 @@ void TaskDatabase::StepRegisterExternalFiles()
     WrtDB::ExternalLocationList externalLocationsUpdate = m_context.locations->listExternalLocations();
     if (m_context.existingWidgetInfo.isExist) //update
     {
-        WidgetDAO dao(m_context.locations->getPkgname());
-        WrtDB::ExternalLocationList externalLocationsDB = dao.getWidgetExternalLocations();
-        FOREACH(file, externalLocationsDB)
+        Try
         {
-            if(std::find(externalLocationsUpdate.begin(), externalLocationsUpdate.end(), *file) == externalLocationsUpdate.end())
+            WidgetDAO dao(m_context.locations->getPkgname());
+            WrtDB::ExternalLocationList externalLocationsDB = dao.getWidgetExternalLocations();
+            FOREACH(file, externalLocationsDB)
             {
-                m_externalLocationsToRemove.push_back(*file);
+                if(std::find(externalLocationsUpdate.begin(), externalLocationsUpdate.end(), *file) == externalLocationsUpdate.end())
+                {
+                    m_externalLocationsToRemove.push_back(*file);
+                }
             }
         }
+        Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
+        {
+            LogError("Given tizenId not found for update installation (Same GUID?)");
+            ThrowMsg(Exceptions::UpdateFailed, "Given tizenId not found for update installation");
+        }
     }
     LogDebug("Registering external files:");
     FOREACH(file, externalLocationsUpdate)
@@ -184,6 +205,45 @@ void TaskDatabase::StepRemoveExternalFiles()
     }
 }
 
+void TaskDatabase::StepCreateVconf()
+{
+    LogDebug("StepCreateVconf");
+    std::map<std::string, WrtDB::SettingsType> vconfData;
+    vconfData[
+        WrtDB::VconfConfig::GetVconfKeyPopupUsage(
+            m_context.locations->getPkgname())] = WrtDB::SETTINGS_TYPE_ON;
+    vconfData[
+        WrtDB::VconfConfig::GetVconfKeyGeolocationUsage(
+            m_context.locations->getPkgname())] = WrtDB::SETTINGS_TYPE_ON;
+    vconfData[
+        WrtDB::VconfConfig::GetVconfKeyWebNotificationUsage(
+            m_context.locations->getPkgname())] = WrtDB::SETTINGS_TYPE_ON;
+    vconfData[
+        WrtDB::VconfConfig::GetVconfKeyWebDatabaseUsage(
+            m_context.locations->getPkgname())] = WrtDB::SETTINGS_TYPE_ON;
+    vconfData[
+        WrtDB::VconfConfig::GetVconfKeyFilesystemUsage(
+            m_context.locations->getPkgname())] = WrtDB::SETTINGS_TYPE_ON;
+    vconfData[
+        WrtDB::VconfConfig::GetVconfKeyMemorySavingMode(
+            m_context.locations->getPkgname())] = WrtDB::SETTINGS_TYPE_OFF;
+
+    // vconftool -g 5000 set -t int <path> initialize value
+    // Current installer should use vconftool for setting group ID
+    // In case of install application by pkgcmd, permission for others
+    // set to read-only
+    FOREACH(it, vconfData) {
+        std::ostringstream command;
+        command << "vconftool -g 5000 set -t int ";
+        command << (*it).first;
+        command << " \"" << static_cast<int>((*it).second) << "\"";
+        int ret = system(command.str().c_str());
+        if (-1 == ret) {
+            ThrowMsg(Exceptions::CreateVconfFailure, "Failed to create vconf files");
+        }
+    }
+}
+
 void TaskDatabase::StepAbortDBInsert()
 {
     LogWarning("[DB Update Task] Aborting... (DB Clean)");