From 15ea634a19f15ea53b9c4293732ad15402ec13c7 Mon Sep 17 00:00:00 2001 From: Dongeup Ham Date: Wed, 15 May 2013 11:21:29 +0900 Subject: [PATCH] terminate app during uninstall Change-Id: I3e44e5f72e60ec12a00a1c73cd3ad883288c360c Signed-off-by: Dongeup Ham --- inc/InstallerDefs.h | 2 +- src/Step/UninstallStep.cpp | 22 ++++++++++++++++++++-- src/Util/InstallerUtil.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/Util/InstallerUtil.h | 2 ++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/inc/InstallerDefs.h b/inc/InstallerDefs.h index 00e90fb..09e0a24 100755 --- a/inc/InstallerDefs.h +++ b/inc/InstallerDefs.h @@ -23,7 +23,7 @@ #include "InstallerUtil.h" -#define OSP_INSTALLER_VERSION "version=[20130514.2]" +#define OSP_INSTALLER_VERSION "version=[20130515.1]" #define DIR_BIN L"/bin" #define DIR_INFO L"/info" diff --git a/src/Step/UninstallStep.cpp b/src/Step/UninstallStep.cpp index b5fb20b..3116128 100755 --- a/src/Step/UninstallStep.cpp +++ b/src/Step/UninstallStep.cpp @@ -24,6 +24,8 @@ #include #include +#include +#include #include #include #include @@ -151,7 +153,7 @@ UninstallStep::OnStateGetPackageInfo(void) if (__pContext->__isHybridService == true) { AppLog("Uninstallation for HybridService"); - __state = STATE_DELETE_DIR; + __state = STATE_TERMINATE_APP; return error; } @@ -196,7 +198,7 @@ UninstallStep::OnStateGetPackageInfo(void) } delete pList; - __state = STATE_DELETE_DIR; + __state = STATE_TERMINATE_APP; return error; } @@ -215,6 +217,22 @@ InstallerError UninstallStep::OnStateTerminateApp(void) { InstallerError error = INSTALLER_ERROR_NONE; + std::unique_ptr< PackageInfo > pPackageInfo(_PackageManagerImpl::GetInstance()->GetPackageInfoN(__pContext->__packageId)); + + _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get()); + TryReturn(pPackageInfoImpl, INSTALLER_ERROR_INTERNAL_STATE, "GetInstance() failed."); + + std::unique_ptr< IList > pPackageAppList(pPackageInfoImpl->GetPackageAppInfoListN()); + TryReturn(pPackageAppList, INSTALLER_ERROR_INTERNAL_STATE, "GetPackageAppInfoListN() failed."); + + for (int i = 0; i < pPackageAppList->GetCount(); i++) + { + PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppList->GetAt(i)); + TryReturn(pPackageAppInfo, INSTALLER_ERROR_INTERNAL_STATE, "pPackageAppList->GetAt(%d) failed.", i); + + AppId appId = pPackageAppInfo->GetAppId(); + InstallerUtil::TerminateApp(appId); + } GoNextState(); return error; diff --git a/src/Util/InstallerUtil.cpp b/src/Util/InstallerUtil.cpp index d1a067f..1a23da4 100755 --- a/src/Util/InstallerUtil.cpp +++ b/src/Util/InstallerUtil.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "InstallerDefs.h" #include "InstallerUtil.h" @@ -922,3 +923,45 @@ InstallerUtil::ParseN(const String& str, const String& tokenDelimiter) return pMap.release(); } + +bool +InstallerUtil::TerminateApp(const AppId& appId) +{ + bool res = true; + + if (_Aul::IsRunning(appId) == true) + { + AppLog("App(%ls) is running.", appId.GetPointer()); + + result r = _Aul::TerminateApplication(appId); + TryReturn(r == E_SUCCESS, false, "TerminateApplication() failed. [%ls]", appId.GetPointer()); + + for (int j = 0; j < TERMINATE_RETRY_COUNT; j++) + { + res = _Aul::IsRunning(appId); + if (res == false) + { + AppLog("App(%ls) is terminated.", appId.GetPointer()); + break; + } + else + { + AppLog("App(%ls) is not terminated yet. wait count = [%d]", appId.GetPointer(), j); + usleep(100000); + } + } + + if (res == true) + { + AppLog("App(%ls) can't be terminated.", appId.GetPointer()); + return false; + } + } + else + { + AppLog("App(%ls) is not running.", appId.GetPointer()); + } + + return true; +} + diff --git a/src/Util/InstallerUtil.h b/src/Util/InstallerUtil.h index 0a71d78..da11bfc 100755 --- a/src/Util/InstallerUtil.h +++ b/src/Util/InstallerUtil.h @@ -86,6 +86,8 @@ public: static Tizen::Base::Collection::IMap* ParseN(const Tizen::Base::String& str, const Tizen::Base::String& tokenDelimiter); + static bool TerminateApp(const Tizen::App::AppId& appId); + private: static char LogChangeHexToStr(int hex); InstallerUtil(const InstallerUtil& value); -- 2.7.4