INCLUDE(ApplyPkgConfig)
# Find all needed packages once
+PKG_CHECK_MODULES(AUL_DEPS REQUIRED aul)
PKG_CHECK_MODULES(PKGMGR_DEPS REQUIRED pkgmgr)
PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer)
PKG_CHECK_MODULES(MINIZIP_DEPS REQUIRED minizip)
PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
PKG_CHECK_MODULES(LIBXML_DEPS REQUIRED libxml-2.0)
PKG_CHECK_MODULES(PRIVILEGE_CHECKER_DEPS REQUIRED security-privilege-manager)
-PKG_CHECK_MODULES(APPMANAGER_DEPS REQUIRED capi-appfw-app-manager)
PKG_CHECK_MODULES(TPK_MANIFEST_HANDLERS_DEPS REQUIRED tpk-manifest-handlers)
PKG_CHECK_MODULES(DBUS_DEPS REQUIRED dbus-1)
BuildRequires: pkgconfig(manifest-parser-utils)
BuildRequires: pkgconfig(delta-manifest-handlers)
BuildRequires: pkgconfig(security-privilege-manager)
-BuildRequires: pkgconfig(capi-appfw-app-manager)
BuildRequires: pkgconfig(tpk-manifest-handlers)
BuildRequires: pkgconfig(dbus-1)
+BuildRequires: pkgconfig(aul)
Requires: ca-certificates-tizen
Requires: libtzplatform-config
#include "common/step/pkgmgr/step_kill_apps.h"
-#include <app_manager.h>
-#include <app_manager_extension.h>
#include <sys/time.h>
-
#include <string>
+#include <systemd/sd-login.h>
+#include <aul.h>
#include "common/utils/glist_range.h"
namespace {
-bool KillApp(const std::string& appid) {
- bool is_running = false;
- if (app_manager_is_running(appid.c_str(), &is_running)
- != APP_MANAGER_ERROR_NONE) {
- LOG(ERROR) << "app_manager_is_running failed";
- return false;
- }
- if (!is_running) {
- return false;
- }
- app_context_h app_context;
- if (app_manager_get_app_context(appid.c_str(), &app_context)
- != APP_MANAGER_ERROR_NONE) {
- LOG(ERROR) << "app_manager_get_app_context failed";
- return false;
+bool CheckAndKill(const std::string& appid, uid_t uid) {
+
+ int ret = aul_app_is_running_for_uid(appid.c_str(), uid);
+ if (ret == 0)
+ return true;
+
+ int pid = aul_app_get_pid_for_uid(appid.c_str(), uid);
+ if (pid < 0) {
+ LOG(ERROR) << "Failed to get pid for appid[" << appid << "] for uid [" << uid << "]";
+ return true;
}
- if (app_manager_terminate_app(app_context)
- != APP_MANAGER_ERROR_NONE) {
- LOG(ERROR) << "app_manager_terminate_app failed";
- app_context_destroy(app_context);
+
+ ret = aul_terminate_pid_sync_for_uid(pid, uid);
+ if (ret != AUL_R_OK) {
+ LOG(ERROR) << "Failed to kill app[" << appid << "] for uid [" << uid << "]";
return false;
}
- // temporary fix, check running status again
- for (int i = 0; i < 10; i++) {
- if (app_manager_is_running(appid.c_str(), &is_running)
- != APP_MANAGER_ERROR_NONE)
- LOG(ERROR) << "app_manager_is_running failed, check again!";
+ return true;
+}
+
+bool KillApp(const std::string& appid) {
+ uid_t* uids = nullptr;
+ int ret = -1;
+ int i;
- if (!is_running) {
- LOG(DEBUG) << "kill waiting count (" << i << ")";
- break;
+ uid_t uid = getuid();
+ if (uid == 0 || uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
+ ret = sd_get_uids(&uids);
+ if (ret < 0 || (ret == 0 || uids == nullptr)) {
+ LOG(ERROR) << "Failed to get uids [" << ret << "]";
+ return false;
}
- usleep(100000); // 100msec
- if (i == 10)
- LOG(ERROR) << "kill timeout";
- }
+ for (i = 0; i < ret; i++) {
+ if (!CheckAndKill(appid, uids[i])) {
+ free(uids);
+ return false;
+ }
+ }
+ } else {
+ if (!CheckAndKill(appid, uid))
+ return false;
+ }
+ free(uids);
LOG(DEBUG) << "Application '" << appid << "' has been killed";
- app_context_destroy(app_context);
return true;
}