Add send signal if there is not enough memory during web app installation
authorSoyoung Kim <sy037.kim@samsung.com>
Fri, 13 Sep 2013 13:38:53 +0000 (22:38 +0900)
committerSoo-Hyun Choi <sh9.choi@samsung.com>
Tue, 22 Oct 2013 08:37:42 +0000 (17:37 +0900)
[Issue#]   WGL-299
[Problem]  Unable to get low memory popup when installing widgets.
[Cause]    There is no way to send out of memory signal to package manager.
[Solution]
    1. Add step to check condition of low memory before unzip.
    2. Add to send signal low memory if there aren't enough memory.

[SCMRequest] Depends on https://review.tizendev.org/gerrit/#/c/90132/
[Verification] Check the steps described in http://goo.gl/mgATi1

Change-Id: I77f468427312909a48f0989bd08ee5d6532b7571

13 files changed:
src/jobs/widget_install/job_widget_install.cpp
src/jobs/widget_install/job_widget_install.h
src/jobs/widget_install/task_manifest_file.cpp
src/jobs/widget_install/widget_install_errors.h
src/jobs/widget_install/widget_unzip.cpp
src/jobs/widget_install/widget_unzip.h
src/logic/installer_controller.cpp
src/logic/installer_controller.h
src/logic/installer_logic.cpp
src/logic/installer_logic.h
src/wrt-installer/wrt-installer.cpp
src/wrt-installer/wrt_installer_api.cpp
src/wrt-installer/wrt_installer_api.h

index 55ab2c0..72b1052 100644 (file)
@@ -69,6 +69,7 @@ namespace WidgetInstall {
 
 JobWidgetInstall::JobWidgetInstall(
     std::string const &widgetPath,
+    std::string const &tzPkgId,
     const Jobs::WidgetInstall::WidgetInstallationStruct &
     installerStruct) :
     Job(UnknownInstallation),
index dd68dca..a87337d 100644 (file)
@@ -54,6 +54,7 @@ class JobWidgetInstall :
      * @brief Automaticaly sets installation process
      */
     JobWidgetInstall(std::string const & widgetPath,
+         std::string const &tzPkgId,
          const Jobs::WidgetInstall::WidgetInstallationStruct &installerStruct);
 
     //overrides
index 47898ff..48562eb 100755 (executable)
@@ -1082,7 +1082,7 @@ void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
     }
 
     FOREACH(it, liveboxList) {
-        LogDebug("setLiveBoxInfo");
+        _D("setLiveBoxInfo");
         LiveBoxInfo liveBox;
         DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
         DPL::String appid = m_context.widgetConfig.tzAppid;
index 473d9cb..31a46cc 100644 (file)
@@ -91,6 +91,7 @@ DECLARE_JOB_EXCEPTION(Base, EncryptionFailed, ErrorEncryptionFailed)
 DECLARE_JOB_EXCEPTION(Base, InstallOspsvcFailed, ErrorInstallOspServcie)
 DECLARE_JOB_EXCEPTION(Base, PrivilegeLevelViolation, ErrorPrivilegeLevelViolation)
 DECLARE_JOB_EXCEPTION(Base, NotSupportRDSUpdate, ErrorNotSupportRDSUpdate)
+DECLARE_JOB_EXCEPTION(Base, OutOfStorageFailed, ErrorOutOfStorage)
 } //namespace
 } //namespace
 } //namespace
index d41b890..06a1d88 100644 (file)
@@ -29,6 +29,7 @@
 #include <dpl/abstract_waitable_input_adapter.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <sys/stat.h>
+#include <sys/statvfs.h>
 #include <dlfcn.h>
 #include <installer_log.h>
 
@@ -36,6 +37,7 @@ using namespace WrtDB;
 
 namespace {
 const char *const DRM_LIB_PATH = "/usr/lib/libdrm-service-core-tizen.so";
+const size_t SPACE_SIZE = 1024 * 1024;
 
 struct PathAndFilePair
 {
@@ -286,6 +288,8 @@ void WidgetUnzip::unzipWgtFile(const std::string &source, const std::string &des
             ThrowMsg(Exceptions::ZipEmpty, wgtFile);
         }
 
+        checkAvailableSpace(destination);
+
         // Set iterator to first file
         m_zipIterator = m_zip->begin();
 
@@ -311,5 +315,25 @@ void WidgetUnzip::unzipWgtFile(const std::string &source, const std::string &des
     }
 }
 
+void WidgetUnzip::checkAvailableSpace(const std::string &destination)
+{
+    _D("checkAvailableSpace ... ");
+
+    double unCompressedSize = m_zip->GetTotalUncompressedSize();
+    _D("unCompressedSize : %ld", unCompressedSize);
+
+    struct statvfs vfs;
+    if (-1 == statvfs(destination.c_str(), &vfs)) {
+        ThrowMsg(Exceptions::OutOfStorageFailed, "There is no space for installation");
+    }
+
+    double freeSize = (double)vfs.f_bsize * vfs.f_bavail;
+    _D("Space Size : %ld", freeSize);
+
+    if (unCompressedSize + SPACE_SIZE >= freeSize) {
+        ThrowMsg(Exceptions::OutOfStorageFailed, "There is no space for installation");
+    }
+}
+
 } //namespace WidgetInstall
 } //namespace Jobs
index 25e1293..f9c0d6d 100644 (file)
@@ -45,7 +45,7 @@ class WidgetUnzip
     bool decryptDRMPackage(const std::string &source, const std::string
             &decryptedSource);
     std::string getDecryptedPackage(const std::string &source);
-
+    void checkAvailableSpace(const std::string &destination);
 };
 
 } //namespace WidgetInstall
index 658ed20..d9b41d5 100644 (file)
@@ -26,8 +26,9 @@ void InstallerController::OnEventReceived(
     const InstallerControllerEvents::InstallWidgetEvent &event)
 {
     std::string fileName = event.GetArg0();
-    Jobs::WidgetInstall::WidgetInstallationStruct installerStruct = event.GetArg1();
-    m_installerLogic.InstallWidget(fileName, installerStruct);
+    std::string pkgId = event.GetArg1();
+    Jobs::WidgetInstall::WidgetInstallationStruct installerStruct = event.GetArg2();
+    m_installerLogic.InstallWidget(fileName, pkgId, installerStruct);
 }
 
 void InstallerController::OnEventReceived(
index 61093c2..9f04288 100644 (file)
@@ -37,8 +37,9 @@ namespace InstallerControllerEvents {
  *
  * This event holds std::string witch should be path to widget package
  */
-DECLARE_GENERIC_EVENT_2(InstallWidgetEvent,
+DECLARE_GENERIC_EVENT_3(InstallWidgetEvent,
             std::string,              // zipFileName
+            std::string,              // package id
             Jobs::WidgetInstall::WidgetInstallationStruct) // installerStruct
 
 /**
index 8dea334..df67764 100644 (file)
@@ -69,6 +69,7 @@ Jobs::JobHandle InstallerLogic::AddAndStartJob()
 // But each Job has different constructor, so creating new Job is specific
 Jobs::JobHandle InstallerLogic::InstallWidget(
     const std::string & widgetPath,
+    const std::string & pkgId,
     const Jobs::WidgetInstall::WidgetInstallationStruct &
     installerStruct)
 {
@@ -80,9 +81,7 @@ Jobs::JobHandle InstallerLogic::InstallWidget(
 
     _D("New Widget Installation:");
 
-    m_job =
-        new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, installerStruct);
-
+    m_job = new Jobs::WidgetInstall::JobWidgetInstall(widgetPath, pkgId, installerStruct);
 
     return AddAndStartJob();
 }
index 4bb4258..abe1b5c 100644 (file)
@@ -49,6 +49,7 @@ class InstallerLogic
 
     Jobs::JobHandle InstallWidget(
         const std::string & widgetPath,
+        const std::string & pkgId,
         const Jobs::WidgetInstall::WidgetInstallationStruct &
         installerStruct);
 
index 8c41ef1..5cfda82 100644 (file)
@@ -279,6 +279,8 @@ void WrtInstaller::OnCreate()
         switch (reqType) {
         case PackageManager::PkgmgrSignal::RequestType::INSTALL:
             m_packagePath = m_argv[4];
+            m_name = m_argv[6];
+
             struct stat info;
             if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
                 _D("Installing package directly from directory");
@@ -451,7 +453,7 @@ void WrtInstaller::installStep()
                                                         m_packagePath.c_str()));
 
     wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
-                       this, &staticWrtStatusCallback,
+                       m_name.c_str(), this, &staticWrtStatusCallback,
                        (m_installByPkgmgr)
                        ? &staticWrtInstallProgressCallback : NULL,
                        m_installMode,
@@ -704,7 +706,7 @@ void WrtInstaller::staticWrtInitializeToPreloadCallback(std::string tizenId, Wrt
             std::string(WrtDB::GlobalConfig::GetUserPreloadedWidgetPath()) + "/" +
             This->m_name;
 
-        wrt_install_widget(packagePath.c_str(),
+        wrt_install_widget(packagePath.c_str(), NULL,
                 This, &staticWrtInitPreloadStatusCallback,
                 NULL,
                 mode,
index 752f676..ba1ee19 100644 (file)
@@ -160,6 +160,7 @@ void wrt_installer_shutdown()
 
 void wrt_install_widget(
     const char *path,
+    const char *tzPkgId,
     void* userdata,
     WrtInstallerStatusCallback status_cb,
     WrtProgressCallback progress_cb,
@@ -182,7 +183,7 @@ void wrt_install_widget(
         CONTROLLER_POST_EVENT(
             Logic::InstallerController,
             InstallerControllerEvents::InstallWidgetEvent(
-                path, Jobs::WidgetInstall::WidgetInstallationStruct(
+                path, tzPkgId, Jobs::WidgetInstall::WidgetInstallationStruct(
                     InstallerCallbacksTranslate::installFinishedCallback,
                     InstallerCallbacksTranslate::installProgressCallback,
                     new InstallerCallbacksTranslate::StatusCallbackStruct(
index 694c9d1..eb2be3c 100644 (file)
@@ -48,6 +48,7 @@ void wrt_installer_init(
 void wrt_installer_shutdown(void);
 void wrt_install_widget(
     const char *path,
+    const char *tzPkgId,
     void *user_parameter,
     WrtInstallerStatusCallback status_callback,
     WrtProgressCallback progress_callback,