Change implementation of step kill apps 32/69032/12 submit/tizen/20160517.005404
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 11 May 2016 07:12:33 +0000 (16:12 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Tue, 17 May 2016 00:07:37 +0000 (17:07 -0700)
Change implementation of step_kill_apps
to work properly on multi-user scenario
such as kill global apps, etc.

Change-Id: I48a7953d2f1ae72f6671f588697e56d8cb5de2df
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
CMakeLists.txt
packaging/app-installers.spec
src/common/CMakeLists.txt
src/common/app-installers.pc.in
src/common/step/pkgmgr/step_kill_apps.cc

index ac16106..ff80564 100644 (file)
@@ -37,6 +37,7 @@ INCLUDE(FindPkgConfig)
 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)
@@ -51,7 +52,6 @@ PKG_CHECK_MODULES(PKGMGR_PARSER_DEPS REQUIRED pkgmgr-parser)
 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)
 
index ec3043a..04f01bb 100644 (file)
@@ -30,9 +30,9 @@ BuildRequires:  pkgconfig(cert-svc-vcore)
 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
index f706ac6..277029f 100644 (file)
@@ -84,6 +84,7 @@ ADD_LIBRARY(${TARGET_LIBNAME_COMMON} SHARED ${SRCS})
 TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_COMMON} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
 # Target - deps
 APPLY_PKG_CONFIG(${TARGET_LIBNAME_COMMON} PUBLIC
+  AUL_DEPS
   PKGMGR_DEPS
   PKGMGR_INFO_DEPS
   PKGMGR_PARSER_DEPS
@@ -96,7 +97,6 @@ APPLY_PKG_CONFIG(${TARGET_LIBNAME_COMMON} PUBLIC
   MINIZIP_DEPS
   ZLIB_DEPS
   PRIVILEGE_CHECKER_DEPS
-  APPMANAGER_DEPS
   DELTA_MANIFEST_HANDLERS_DEPS
   TPK_MANIFEST_HANDLERS_DEPS
   Boost
index 0a035d5..db03b61 100644 (file)
@@ -6,6 +6,6 @@ includedir=@INCLUDEDIR@
 Name: app-installers
 Description: Common library for pkgmgr backends
 Version: @VERSION@
-Requires: pkgmgr pkgmgr-installer minizip zlib libtzplatform-config security-manager manifest-parser-utils delta-manifest-handlers cert-svc-vcore pkgmgr-parser pkgmgr-info libxml-2.0 security-privilege-manager capi-appfw-app-manager
+Requires: pkgmgr pkgmgr-installer minizip zlib libtzplatform-config security-manager manifest-parser-utils delta-manifest-handlers cert-svc-vcore pkgmgr-parser pkgmgr-info libxml-2.0 security-privilege-manager
 Libs: -L${libdir} -lapp-installers
 Cflags: -I${includedir}/app-installers/
index 2eca3ae..bf325f2 100644 (file)
@@ -4,56 +4,61 @@
 
 #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;
 }