[Feature] Kill applications before deinstallation/update 78/46978/4
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 27 Aug 2015 13:05:15 +0000 (15:05 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Fri, 28 Aug 2015 06:47:42 +0000 (08:47 +0200)
App-manager is used to kill apps.

Change-Id: I2b34b860bfb6b217b6de6190e8b82d1bb25c491c

CMakeLists.txt
packaging/app-installers.spec
src/common/CMakeLists.txt
src/common/step/step_kill_apps.cc [new file with mode: 0644]
src/common/step/step_kill_apps.h [new file with mode: 0644]
src/tpk/tpk_installer.cc
src/wgt/wgt_installer.cc

index 6f1f24c..81edb31 100644 (file)
@@ -52,6 +52,7 @@ 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 capi-security-privilege-manager)
 PKG_CHECK_MODULES(ENCRYPTION_DEPS REQUIRED libwebappenc)
+PKG_CHECK_MODULES(APPMANAGER_DEPS REQUIRED capi-appfw-app-manager)
 
 FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem regex)
 FIND_PACKAGE(GTest REQUIRED)
index 28e644b..0dbb522 100644 (file)
@@ -32,6 +32,7 @@ BuildRequires:  pkgconfig(manifest-parser)
 BuildRequires:  pkgconfig(manifest-handlers)
 BuildRequires:  pkgconfig(capi-security-privilege-manager)
 BuildRequires:  pkgconfig(libwebappenc)
+BuildRequires:  pkgconfig(capi-appfw-app-manager)
 
 Requires: ca-certificates-tizen
 Requires: libtzplatform-config
index 6f35406..2ed10ea 100644 (file)
@@ -21,6 +21,7 @@ SET(SRCS
   step/step_copy_storage_directories.cc
   step/step_create_storage_directories.cc
   step/step_fail.cc
+  step/step_kill_apps.cc
   step/step_recover_application.cc
   step/step_recover_files.cc
   step/step_recover_icons.cc
@@ -63,6 +64,7 @@ APPLY_PKG_CONFIG(${TARGET_LIBNAME_COMMON} PUBLIC
   MINIZIP_DEPS
   ZLIB_DEPS
   PRIVILEGE_CHECKER_DEPS
+  APPMANAGER_DEPS
   Boost
 )
 
diff --git a/src/common/step/step_kill_apps.cc b/src/common/step/step_kill_apps.cc
new file mode 100644 (file)
index 0000000..4233f0e
--- /dev/null
@@ -0,0 +1,77 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/step_kill_apps.h"
+
+#include <app_manager.h>
+#include <app_manager_extension.h>
+
+#include <string>
+
+#include "common/utils/clist_helpers.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;
+  }
+  if (app_manager_terminate_app(app_context)
+      != APP_MANAGER_ERROR_NONE) {
+    LOG(ERROR) << "app_manager_terminate_app failed";
+    app_context_destroy(app_context);
+    return false;
+  }
+  LOG(DEBUG) << "Application '" << appid << "' has been killed";
+  app_context_destroy(app_context);
+  return true;
+}
+
+}  // namespace
+
+namespace common_installer {
+namespace pkgmgr {
+
+Step::Status StepKillApps::process() {
+  manifest_x* old_manifest = context_->old_manifest_data.get() ?
+      context_->old_manifest_data.get() : context_->manifest_data.get();
+  uiapplication_x* ui = nullptr;
+  PKGMGR_LIST_MOVE_NODE_TO_HEAD(old_manifest->uiapplication, ui);
+  for (; ui; ui = ui->next) {
+    if (!ui->appid)
+      continue;
+    (void) KillApp(ui->appid);
+  }
+  serviceapplication_x * svc = nullptr;
+  PKGMGR_LIST_MOVE_NODE_TO_HEAD(old_manifest->serviceapplication, svc);
+  for (; svc; svc = svc->next) {
+    if (!svc->appid)
+      continue;
+    (void) KillApp(svc->appid);
+  }
+  return Status::OK;
+}
+
+Step::Status StepKillApps::precheck() {
+  if (!context_->manifest_data.get() && !context_->old_manifest_data.get()) {
+    LOG(ERROR) << "manifest_data is empty";
+    return Status::ERROR;
+  }
+  return Status::OK;
+}
+
+}  // namespace pkgmgr
+}  // namespace common_installer
diff --git a/src/common/step/step_kill_apps.h b/src/common/step/step_kill_apps.h
new file mode 100644 (file)
index 0000000..6dd6f31
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_KILL_APPS_H_
+#define COMMON_STEP_STEP_KILL_APPS_H_
+
+#include "common/context_installer.h"
+#include "common/step/step.h"
+#include "common/utils/logging.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+class StepKillApps : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+  Status precheck() override;
+
+  SCOPE_LOG_TAG(KillApps)
+};
+
+}  // namespace pkgmgr
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_KILL_APPS_H_
index 1654512..f04f4d1 100644 (file)
@@ -10,6 +10,7 @@
 #include "common/step/step_copy_backup.h"
 #include "common/step/step_check_old_certificate.h"
 #include "common/step/step_fail.h"
+#include "common/step/step_kill_apps.h"
 #include "common/step/step_old_manifest.h"
 #include "common/step/step_open_recovery_file.h"
 #include "common/step/step_parse.h"
@@ -104,6 +105,7 @@ void TpkInstaller::UpdateSteps() {
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<ci::security::StepCheckOldCertificate>();
   AddStep<ci::backup::StepOldManifest>();
+  AddStep<ci::pkgmgr::StepKillApps>();
   AddStep<ci::backup::StepBackupManifest>();
   AddStep<ci::backup::StepBackupIcons>();
   AddStep<ci::backup::StepCopyBackup>();
@@ -119,6 +121,7 @@ void TpkInstaller::UpdateSteps() {
 void TpkInstaller::UninstallSteps() {
   AddStep<ci::configuration::StepConfigure>(pkgmgr_);
   AddStep<ci::parse::StepParse>();
+  AddStep<ci::pkgmgr::StepKillApps>();
   AddStep<ci::backup::StepBackupManifest>();
   AddStep<ci::pkgmgr::StepUnregisterApplication>();
   AddStep<ci::security::StepRollbackDeinstallationSecurity>();
index a46cf25..f46556c 100644 (file)
@@ -14,6 +14,7 @@
 #include "common/step/step_copy_backup.h"
 #include "common/step/step_copy_storage_directories.h"
 #include "common/step/step_fail.h"
+#include "common/step/step_kill_apps.h"
 #include "common/step/step_open_recovery_file.h"
 #include "common/step/step_parse.h"
 #include "common/step/step_privilege_compatibility.h"
@@ -90,6 +91,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
       AddStep<ci::security::StepCheckOldCertificate>();
       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
       AddStep<ci::backup::StepOldManifest>();
+      AddStep<ci::pkgmgr::StepKillApps>();
       AddStep<ci::backup::StepBackupManifest>();
       AddStep<ci::backup::StepBackupIcons>();
       AddStep<ci::backup::StepCopyBackup>();
@@ -104,6 +106,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
     case ci::RequestType::Uninstall: {
       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
       AddStep<ci::parse::StepParse>();
+      AddStep<ci::pkgmgr::StepKillApps>();
       AddStep<ci::backup::StepBackupManifest>();
       AddStep<ci::pkgmgr::StepUnregisterApplication>();
       AddStep<ci::security::StepRollbackDeinstallationSecurity>();
@@ -116,6 +119,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
     case ci::RequestType::Reinstall: {
       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
       AddStep<wgt::parse::StepParse>(false);
+      AddStep<ci::pkgmgr::StepKillApps>();
       AddStep<ci::backup::StepOldManifest>();
       AddStep<wgt::rds::StepRDSParse>();
       AddStep<wgt::rds::StepRDSModify>();