Add routine terminated application when update application
authorJihoon Chung <jihoon.chung@samsung.com>
Mon, 22 Apr 2013 13:08:53 +0000 (22:08 +0900)
committerGerrit Code Review <gerrit2@kim11>
Tue, 23 Apr 2013 05:56:44 +0000 (14:56 +0900)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] Terminate application when update application.
[SCMRequest] N/A

Change-Id: Id019472d5ed67d7cb7e400aa20ea6f77d89a3bcc

src/jobs/widget_install/job_widget_install.cpp [changed mode: 0755->0644]
src/jobs/widget_uninstall/task_check.cpp

old mode 100755 (executable)
new mode 100644 (file)
index 9e76928..239f8d1
@@ -588,14 +588,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) ||
index 09d9116..bb6a73b 100644 (file)
@@ -19,7 +19,7 @@
  * @version 1.0
  * @brief   Header file for widget uninstall task check
  */
-#include <time.h>
+#include <ctime>
 #include <dpl/sstream.h>
 #include <widget_uninstall/task_check.h>
 #include <widget_uninstall/job_widget_uninstall.h>