X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fjobs%2Fwidget_uninstall%2Ftask_check.cpp;h=bb6a73b50d9eea88895b1d99b4bc2dfe1656a870;hb=80392791b3b7919b59596326dd9fdd9b25a1be1e;hp=d2ae7287270007b150163f52186afb9a39cca10d;hpb=8751fcd683990373dd3d8275dc01052a658fe34f;p=framework%2Fweb%2Fwrt-installer.git diff --git a/src/jobs/widget_uninstall/task_check.cpp b/src/jobs/widget_uninstall/task_check.cpp index d2ae728..bb6a73b 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 @@ -38,8 +39,7 @@ TaskCheck::TaskCheck(UninstallerContext& context) : } TaskCheck::~TaskCheck() -{ -} +{} void TaskCheck::StepUninstallPreCheck() { @@ -47,9 +47,8 @@ void TaskCheck::StepUninstallPreCheck() //check if deferred //TODO if widget to be updated, then remove it from Deferred list? - int ret = APP_MANAGER_ERROR_NONE; bool isRunning = false; - ret = app_manager_is_running(m_context.tzAppid.c_str(), &isRunning); + int ret = app_manager_is_running(m_context.tzAppid.c_str(), &isRunning); if (APP_MANAGER_ERROR_NONE != ret) { LogError("Fail to get running state"); ThrowMsg(Exceptions::PlatformAPIFailure, @@ -57,17 +56,54 @@ void TaskCheck::StepUninstallPreCheck() } if (true == isRunning) { - LogError("Widget is not stopped. Cannot uninstall!"); - //TODO different error - ThrowMsg(Exceptions::AlreadyUninstalling, - "Widget is not stopped. Cannot uninstall!"); - //TODO or defer 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); m_context.job->UpdateProgress(UninstallerContext::UNINSTALL_PRECHECK, "Uninstall pre-checking Finished"); } - } //namespace WidgetUninstall } //namespace Jobs