From 26b0c0a9557d15aee39ed4e08c928368f2b96aa9 Mon Sep 17 00:00:00 2001 From: Jihoon Chung Date: Sat, 20 Apr 2013 00:24:34 +0900 Subject: [PATCH 1/1] Add terminate application during uninstalling [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] Terminate application during uninstall step when application is still running state. [SCMRequest] N/A Change-Id: Idf14d3181c7e97d194c7270553f040d6194b6f01 --- src/jobs/widget_uninstall/task_check.cpp | 47 ++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/jobs/widget_uninstall/task_check.cpp b/src/jobs/widget_uninstall/task_check.cpp index aac218b..09d9116 100644 --- a/src/jobs/widget_uninstall/task_check.cpp +++ b/src/jobs/widget_uninstall/task_check.cpp @@ -19,6 +19,7 @@ * @version 1.0 * @brief Header file for widget uninstall task check */ +#include #include #include #include @@ -55,9 +56,49 @@ void TaskCheck::StepUninstallPreCheck() } if (true == isRunning) { - LogError("Widget is not stopped. Cannot uninstall!"); - ThrowMsg(Exceptions::AppIsRunning, - "Widget is not stopped. Cannot uninstall!"); + // 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(m_context.tzAppid.c_str(), &appCtx); + if (APP_MANAGER_ERROR_NONE != ret) { + LogError("Fail to get app_context"); + ThrowMsg(Exceptions::AppIsRunning, + "Widget is not stopped. Cannot uninstall!"); + } + + // 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); + ThrowMsg(Exceptions::AppIsRunning, + "Widget is not stopped. Cannot uninstall!"); + } 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(m_context.tzAppid.c_str(), &isStillRunning); + if (APP_MANAGER_ERROR_NONE != ret) { + LogError("Fail to get running state"); + ThrowMsg(Exceptions::PlatformAPIFailure, + "Fail to get widget state"); + } + if (!isStillRunning) { + break; + } + } + if (isStillRunning) { + LogError("Fail to terminate running application"); + ThrowMsg(Exceptions::AppIsRunning, + "Widget is not stopped. Cannot uninstall!"); + } + LogInfo("terminate application"); + } } LogInfo("Widget Can be uninstalled. Pkgname : " << m_context.tzAppid); -- 2.7.4