[Release] wrt-installer_0.1.37
[framework/web/wrt-installer.git] / src / jobs / widget_install / job_widget_install.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 9e76928..e2b2086
@@ -194,12 +194,6 @@ JobWidgetInstall::JobWidgetInstall(
         }
 
         AddTask(new TaskFileManipulation(m_installerContext));
-        // TODO: Update progress information for this task
-
-        //This is sort of quick solution, because ACE verdicts are based upon
-        //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
-        //task.
-        AddTask(new TaskSmack(m_installerContext));
 
         AddTask(new TaskManifestFile(m_installerContext));
         if (m_installerContext.widgetConfig.packagingType ==
@@ -210,6 +204,7 @@ JobWidgetInstall::JobWidgetInstall(
         AddTask(new TaskCertificates(m_installerContext));
         AddTask(new TaskDatabase(m_installerContext));
         AddTask(new TaskAceCheck(m_installerContext));
+        AddTask(new TaskSmack(m_installerContext));
     } else if (result == ConfigureResult::Updated) {
         LogInfo("Configure installation updated");
         LogInfo("Widget Update");
@@ -249,9 +244,6 @@ JobWidgetInstall::JobWidgetInstall(
             AddTask(new TaskUpdateFiles(m_installerContext));
         }
 
-        /* TODO : To backup file, save md5 values */
-        AddTask(new TaskSmack(m_installerContext));
-
         AddTask(new TaskManifestFile(m_installerContext));
         if (m_installerContext.widgetConfig.packagingType ==
             PKG_TYPE_HYBRID_WEB_APP)
@@ -268,6 +260,7 @@ JobWidgetInstall::JobWidgetInstall(
         //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
+        AddTask(new TaskSmack(m_installerContext));
     } else if (result == ConfigureResult::Deferred) {
         // Installation is deferred
         LogInfo("Configure installation deferred");
@@ -588,14 +581,62 @@ ConfigureResult JobWidgetInstall::checkWidgetUpdate(
 
     // Check running state
     bool isRunning = false;
-    int retval =
+    int ret =
         app_manager_is_running(DPL::ToUTF8String(update.tzAppId).c_str(),
                                &isRunning);
-    if (APP_MANAGER_ERROR_NONE != retval || isRunning) {
+    if (APP_MANAGER_ERROR_NONE != ret) {
         LogError("Fail to get running state");
         return ConfigureResult::Failed_WidgetRunning;
     }
 
+    if (true == isRunning) {
+        // get app_context for running application
+        // app_context must be released with app_context_destroy
+        app_context_h appCtx = NULL;
+        ret =
+            app_manager_get_app_context(
+                DPL::ToUTF8String(update.tzAppId).c_str(),
+                &appCtx);
+        if (APP_MANAGER_ERROR_NONE != ret) {
+            LogError("Fail to get app_context");
+            return ConfigureResult::Failed_WidgetRunning;
+        }
+
+        // terminate app_context_h
+        ret = app_manager_terminate_app(appCtx);
+        if (APP_MANAGER_ERROR_NONE != ret) {
+            LogError("Fail to terminate running application");
+            app_context_destroy(appCtx);
+            return ConfigureResult::Failed_WidgetRunning;
+        } else {
+            app_context_destroy(appCtx);
+            // app_manager_terminate_app isn't sync API
+            // wait until application isn't running (50ms * 100)
+            bool isStillRunning = true;
+            int checkingloop = 100;
+            struct timespec duration = { 0, 50 * 1000 * 1000 };
+            while (--checkingloop >= 0) {
+                nanosleep(&duration, NULL);
+                int ret =
+                    app_manager_is_running(
+                        DPL::ToUTF8String(update.tzAppId).c_str(),
+                        &isStillRunning);
+                if (APP_MANAGER_ERROR_NONE != ret) {
+                    LogError("Fail to get running state");
+                    return ConfigureResult::Failed_WidgetRunning;
+                }
+                if (!isStillRunning) {
+                    break;
+                }
+            }
+            if (isStillRunning) {
+                LogError("Fail to terminate running application");
+                return ConfigureResult::Failed_WidgetRunning;
+            }
+            LogInfo("terminate application");
+        }
+    }
+
     m_installerContext.widgetConfig.tzAppid = update.tzAppId;
 
     if (isUpperVersion(update.existingVersion, update.incomingVersion) ||