[Release] wrt-installer_0.1.55
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_database.cpp
index b9971c1..e9d1b6c 100644 (file)
@@ -28,7 +28,7 @@
 #include <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
-#include <web-provider-info.h>
+#include <web_provider_livebox_info.h>
 #include <dpl/wrt-dao-rw/widget_dao.h>
 #include <dpl/wrt-dao-ro/vconf_config.h>
 #include <dpl/foreach.h>
@@ -36,6 +36,7 @@
 #include <dpl/log/log.h>
 #include <dpl/assert.h>
 #include <wrt-commons/security-origin-dao/security_origin_dao.h>
+#include <dpl/wrt-dao-ro/widget_dao_types.h>
 #include <string>
 #include <sstream>
 #include <ace_api_install.h>
@@ -64,6 +65,7 @@ TaskDatabase::TaskDatabase(InstallerContext& context) :
     AddStep(&TaskDatabase::StepLiveboxDBInsert);
 
     AddAbortStep(&TaskDatabase::StepAbortDBInsert);
+    AddAbortStep(&TaskDatabase::StepAbortAceDBInsert);
 }
 
 void TaskDatabase::StepWrtDBInsert()
@@ -73,21 +75,28 @@ void TaskDatabase::StepWrtDBInsert()
         /* Set install Time */
         time(&m_context.widgetConfig.installedTime);
 
-        if (m_context.existingWidgetInfo.isExist) { //update
+        if (m_context.isUpdateMode) { //update
             LogInfo("Registering widget... (update)");
             Try
             {
                 m_handleToRemove = WidgetDAOReadOnly::getHandle(
                         m_context.widgetConfig.tzAppid);
+
+                std::string makeAppid =
+                    DPL::ToUTF8String(m_context.widgetConfig.tzAppid) + "." +
+                    "backup";
+                m_backAppId = DPL::FromUTF8String(makeAppid);
             }
             Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
             {
                 LogError(
                     "Given tizenId not found for update installation (Same GUID?)");
-                ThrowMsg(Exceptions::InvalidPackage,
+                ThrowMsg(Exceptions::DatabaseFailure,
                          "Given tizenId not found for update installation");
             }
-            WidgetDAO::registerOrUpdateWidget(
+
+            WidgetDAO::backupAndUpdateWidget(
+                m_backAppId,
                 m_context.widgetConfig.tzAppid,
                 m_context.widgetConfig,
                 m_context.wacSecurity);
@@ -152,6 +161,8 @@ void TaskDatabase::StepSecurityOriginDBInsert()
     LogDebug("Create Security origin database");
     // automatically create security origin database
     using namespace SecurityOriginDB;
+    using namespace WrtDB;
+
     SecurityOriginDAO dao(m_context.locations->getPkgId());
 
     // Checking privilege list for setting security origin exception data
@@ -161,6 +172,8 @@ void TaskDatabase::StepSecurityOriginDBInsert()
         if (result != g_W3CPrivilegeTextMap.end()) {
             if (result->second == FEATURE_USER_MEDIA) {
                 dao.setPrivilegeSecurityOriginData(result->second, false);
+            } else if (result->second == FEATURE_FULLSCREEN_MODE) {
+                continue;
             } else {
                 dao.setPrivilegeSecurityOriginData(result->second);
             }
@@ -176,7 +189,7 @@ void TaskDatabase::StepRegisterExternalFiles()
 {
     WrtDB::ExternalLocationList externalLocationsUpdate =
         m_context.locations->listExternalLocations();
-    if (m_context.existingWidgetInfo.isExist) { //update
+    if (m_context.isUpdateMode) { //update
         Try
         {
             WidgetDAO dao(m_context.widgetConfig.tzAppid);
@@ -250,6 +263,9 @@ void TaskDatabase::StepCreateVconf()
         WrtDB::VconfConfig::GetVconfKeyWebNotificationUsage(
             m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
     vconfData[
+        WrtDB::VconfConfig::GetVconfKeyWebDatabaseUsage(
+            m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
+    vconfData[
         WrtDB::VconfConfig::GetVconfKeyMemorySavingMode(
             m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_OFF;
 
@@ -275,13 +291,23 @@ void TaskDatabase::StepAbortDBInsert()
     LogWarning("[DB Update Task] Aborting... (DB Clean)");
     Try
     {
-        WidgetDAO::unregisterWidget(m_context.widgetConfig.tzAppid);
+        if (m_context.isUpdateMode) {
+            WidgetDAO::restoreUpdateWidget(m_backAppId,
+                    m_context.widgetConfig.tzAppid);
+        } else {
+            WidgetDAO::unregisterWidget(m_context.widgetConfig.tzAppid);
+        }
         LogDebug("Cleaning DB successful!");
     }
     Catch(DPL::DB::SqlConnection::Exception::Base)
     {
         LogError("Failed to handle StepAbortDBClean!");
     }
+}
+
+void TaskDatabase::StepAbortAceDBInsert()
+{
+    LogWarning("[DB Update Task] ACE DB Aborting... (DB Clean)");
 
     ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
     // Remove also old one. If it was already updated nothing wrong will happen,
@@ -289,6 +315,12 @@ void TaskDatabase::StepAbortDBInsert()
     if (INVALID_WIDGET_HANDLE != m_handleToRemove) {
         ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
     }
+
+    if (!AceApi::registerAceWidgetFromDB(m_handleToRemove))
+    {
+        LogError("ace database restore failed");
+    }
+    LogDebug("Ace data inserted");
 }
 
 void TaskDatabase::StepLiveboxDBInsert()
@@ -299,26 +331,32 @@ void TaskDatabase::StepLiveboxDBInsert()
 
     std::string tizenId = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
 
+    // insert specific information to web livebox db
     for (auto it = m_context.widgetConfig.configInfo.m_livebox.begin();
          it != m_context.widgetConfig.configInfo.m_livebox.end(); ++it)
     {
         std::string boxId = DPL::ToUTF8String((**it).m_liveboxId);
         std::string boxType;
-        if ((**it).m_type == L"") {
-            boxType = web_provider_info_get_default_type();
+        if ((**it).m_type.empty()) {
+            boxType = web_provider_livebox_get_default_type();
         } else {
             boxType = DPL::ToUTF8String((**it).m_type);
         }
         LogInfo("livebox id: " << boxId);
         LogInfo("livebox type: " << boxType);
 
-        int ret =
-            web_provider_info_insert_box_type(
-                boxId.c_str(), tizenId.c_str(), boxType.c_str());
+        int autoLaunch = (**it).m_autoLaunch == L"true" ? 1 : 0;
+        LogInfo("livebox auto-launch: " << autoLaunch);
 
-        if (ret < 0) {
-            LogDebug("failed to set type of livebox: " << boxId);
-        }
+        int mouseEvent = (**it).m_boxInfo.m_boxMouseEvent == L"true" ? 1 : 0;
+        LogInfo("livebox mouse-event: " << mouseEvent);
+
+        int pdFastOpen = (**it).m_boxInfo.m_pdFastOpen == L"true" ? 1 : 0;
+        LogInfo("livebox pd fast-open: " << pdFastOpen);
+
+        web_provider_livebox_insert_box_info(
+                boxId.c_str(), tizenId.c_str(), boxType.c_str(),
+                autoLaunch, mouseEvent, pdFastOpen);
     }
 }
 } //namespace WidgetInstall