Locking launching of widget during reinstallation/uninstallation
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 24 Oct 2013 10:57:00 +0000 (12:57 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Fri, 25 Oct 2013 11:00:30 +0000 (13:00 +0200)
[Issue#]   N_SE-55833
[Problem]  Installer should block launching widget during installation
[Cause]    N/A
[Solution] Reinstallation/deinstallation is making exclusive file lock on /tmp/.dpl_lock.[tizenId] file.
           Lock of this file is used to check by wrt-client if launching is possible.

[Remarks]
    - lock is destroyed if wrt-installer finished (destrcutor of std::unique_ptr<>)
    - lock is destroyed if wrt-installer crashed,
    - if file is already lock that means:
        - another installation of this widget is proceeded,
        - wrt-client check if it can launch -> wait for freeing

[SCMRequest]  This requires wrt-commons change: "[DPL] FileLock"
[Verification] N/A
    - try to run widget while widget is being resinstalled -> widget should not run (insert sleep code after kill runnign app),
    - try to run widget while widget is being uninstalled -> widget should not run,
    - install two different apps similtonously (both should be installed and able to be run)

Change-Id: Iedf3f954536d35085ae90eb3a58386abcab7f9ac

src/jobs/widget_install/task_configuration.cpp
src/jobs/widget_install/task_configuration.h
src/jobs/widget_install/widget_install_context.h
src/jobs/widget_uninstall/task_check.cpp
src/jobs/widget_uninstall/task_check.h
src/jobs/widget_uninstall/uninstaller_context.h

index bec432c..5f79d4a 100644 (file)
@@ -105,6 +105,7 @@ TaskConfiguration::TaskConfiguration(InstallerContext& context) :
     AddStep(&TaskConfiguration::ParseXMLConfigStep);
 
     AddStep(&TaskConfiguration::TizenIdStep);
+    AddStep(&TaskConfiguration::LockInstallationStep);
     AddStep(&TaskConfiguration::CheckAppRunningStateStep);
     AddStep(&TaskConfiguration::ApplicationTypeStep);
     AddStep(&TaskConfiguration::ResourceEncryptionStep);
@@ -290,6 +291,14 @@ void TaskConfiguration::TizenIdStep()
     _D("Tizen Pkg Id : %ls", (m_context.widgetConfig.tzPkgid).c_str());
 }
 
+void TaskConfiguration::LockInstallationStep()
+{
+    std::string lockString = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
+    _D("Locking installation on file '%s'", lockString.c_str());
+    m_context.installationLock.reset(new DPL::FileBasedMutex(lockString));
+    _D("Installation locked");
+}
+
 void TaskConfiguration::CheckAppRunningStateStep()
 {
     bool isRunning = false;
index 0540ab7..1b81c20 100644 (file)
@@ -73,6 +73,7 @@ class TaskConfiguration : public DPL::TaskDecl<TaskConfiguration>
     void ParseXMLConfigStep();
 
     void TizenIdStep();
+    void LockInstallationStep();
     void CheckAppRunningStateStep();
     void DetectUpdateInstallationStep();
     void PkgmgrStartStep();
index 4816e94..77ef647 100644 (file)
 
 #include <map>
 #include <string>
+#include <memory>
+
 #include <dpl/string.h>
 #include <dpl/wrt-dao-rw/widget_dao.h>
+#include <dpl/file_lock.h>
+
 #include <widget_install/widget_security.h>
 #include <feature_logic.h>
 #include <widget_install/widget_update_info.h>
 #include <widget_location.h>
 #include <wrt_install_mode.h>
 
+
 namespace Jobs {
 namespace WidgetInstall {
 class JobWidgetInstall;
@@ -101,6 +106,8 @@ struct InstallerContext
 
     std::string requestedPath; ///input path of widget
     bool needEncryption;  ///for configuring right task if encryption needed
+
+    std::unique_ptr<DPL::FileBasedMutex> installationLock;
 };
 
 #endif // INSTALLER_CONTEXT_H
index 22a7e91..5baaaae 100644 (file)
@@ -27,6 +27,7 @@
 #include <widget_uninstall/widget_uninstall_errors.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/file_lock.h>
 #include <app_manager.h>
 #include <pkgmgr/pkgmgr_parser.h>
 #include <pkgmgr-info.h>
@@ -39,6 +40,7 @@ TaskCheck::TaskCheck(UninstallerContext& context) :
     m_context(context)
 {
     AddStep(&TaskCheck::StartStep);
+    AddStep(&TaskCheck::SetUninstallationLockStep);
     AddStep(&TaskCheck::StepUninstallPreCheck);
     AddStep(&TaskCheck::StepCheckMDM);
     AddStep(&TaskCheck::EndStep);
@@ -59,6 +61,14 @@ void TaskCheck::EndStep()
     _D("--------- <TaskCheck> : END ----------");
 }
 
+void TaskCheck::SetUninstallationLockStep()
+{
+    std::string lockString = m_context.tzAppid;
+    _D("Locking uninstallation on file '%s'", lockString.c_str());
+    m_context.installationLock.reset(new DPL::FileBasedMutex(lockString));
+    _D("Uninstallation locked");
+}
+
 void TaskCheck::StepUninstallPreCheck()
 {
     bool isRunning = false;
index 29c00db..933c813 100644 (file)
@@ -38,6 +38,7 @@ class TaskCheck :
     UninstallerContext& m_context;
 
     //steps
+    void SetUninstallationLockStep();
     void StepUninstallPreCheck();
     void StepCheckMDM();
     void StartStep();
index b6cf5bd..0ba3778 100644 (file)
@@ -27,6 +27,7 @@
 #include <widget_uninstall/widget_uninstaller_struct.h>
 #include <widget_location.h>
 #include <dpl/utils/path.h>
+#include <dpl/file_lock.h>
 
 namespace Jobs {
 namespace WidgetUninstall {
@@ -65,6 +66,8 @@ struct UninstallerContext
     bool removeAbnormal;
     DPL::Utils::Path installedPath;
     DPL::Utils::Path manifestFile;
+
+    std::unique_ptr<DPL::FileBasedMutex> installationLock;
 };
 
 #endif // WRT_SRC_INSTALLER_CORE_UNINSTALLER_TASKS_UNINSTALLER_CONTEXT_H_