Modify pkgmgr event handler
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 23 Jun 2023 01:21:26 +0000 (01:21 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 23 Apr 2024 22:45:40 +0000 (07:45 +0900)
If the event name is 'uninstall', AMD sends the SIGKILL signal to
the running application of the uinstalling package.

Change-Id: I7a23a85f968cde83bb7862dfa7b8eaa79ccf6fb3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_app_status.cc
src/lib/app_info/app_info_manager.cc
src/lib/app_info/app_info_manager.hh
src/lib/app_status/app_status_manager.cc
src/lib/app_status/app_status_manager.hh

index 20f32d83d148cda027e5a6bada236d760c73ab94..c85e7ca58f673b04a22ed3c95eb8cc4436e35190 100644 (file)
@@ -393,7 +393,7 @@ int _app_status_terminate_apps_by_pkgid(const char* pkgid, uid_t uid) {
   if (pkgid == nullptr)
     return -1;
 
-  return amd::app_status::AppStatusManager::GetInst().TerminateAppsByPkgid(
+  return amd::app_status::AppStatusManager::GetInst().TerminateAppsByPkgId(
       pkgid, uid);
 }
 
index 4561e8cf2bb30ac752940aa62ae452160bcbd26d..03f21ca199298c56af292bf9365ee2f9aaf7f224 100644 (file)
@@ -24,6 +24,7 @@
 #include "lib/amd_restart_manager.h"
 
 #include "lib/api/amd_api_noti.hh"
+#include "lib/app_status/app_status_manager.hh"
 #include "lib/common/log_private.hh"
 
 namespace amd {
@@ -255,11 +256,11 @@ std::shared_ptr<AppInfoChunk> AppInfoManager::PrepareAppInfoChunk(uid_t uid) {
 }
 
 void AppInfoManager::SetPackageBlocking(uid_t target_uid,
-    const std::string& pkgid, const std::string& global) {
+    const std::string& pkgid, const std::string& global, bool do_kill) {
   if (target_uid < REGULAR_UID_MIN) {
     for (auto const& iter : app_info_chunk_) {
       uid_t uid = iter.first;
-      SetPackageBlocking(uid, pkgid, global);
+      SetPackageBlocking(uid, pkgid, global, do_kill);
     }
 
     return;
@@ -279,7 +280,12 @@ void AppInfoManager::SetPackageBlocking(uid_t target_uid,
   }
 
   _D("Terminate apps of package(%s)", pkgid.c_str());
-  _app_status_terminate_apps_by_pkgid(pkgid.c_str(), target_uid);
+  if (do_kill) {
+    app_status::AppStatusManager::GetInst().KillAppsByPkgId(pkgid, target_uid);
+  } else {
+    app_status::AppStatusManager::GetInst().TerminateAppsByPkgId(pkgid,
+        target_uid);
+  }
 }
 
 void AppInfoManager::UnsetPackageBlocking(uid_t target_uid,
@@ -502,7 +508,8 @@ void AppInfoManager::HandlePkgmgrEventStart(
       event_name == "move") {
     uid_t target_uid = args->GetTargetUid();
     const std::string& pkgid = args->GetPkgId();
-    SetPackageBlocking(target_uid, pkgid, helper::IsGlobalUser(target_uid));
+    SetPackageBlocking(target_uid, pkgid, helper::IsGlobalUser(target_uid),
+        event_name == "uninstall");
     helper::NotiSend(AMD_NOTI_MSG_APPINFO_PACKAGE_UPDATE_START, target_uid,
         pkgid);
   }
index f223e7e421cccdc04f1b94873c94bbcc0c240d25..ad163d1bd48c613112bc77c7dc9fff8cd35d1f7a 100644 (file)
@@ -55,7 +55,7 @@ class AppInfoManager : public PkgmgrClient::IEvent {
   std::shared_ptr<AppInfoChunk> PrepareAppInfoChunk(uid_t uid);
 
   void SetPackageBlocking(uid_t target_uid, const std::string& pkgid,
-      const std::string& global);
+      const std::string& global, bool do_kill);
   void UnsetPackageBlocking(uid_t target_uid, const std::string& pkgid,
       const std::string& global, bool restart);
   bool ExistPackageAppInfo(uid_t target_uid, const std::string& pkgid,
index 20fcdefc0abcce7090a803353ca56d257c1333ea..de910bf1acfef01bcf3bfda98ab3f71ccf815b01 100644 (file)
@@ -403,7 +403,7 @@ int AppStatusManager::TerminateApps(const std::string& appid, uid_t uid) {
   return 0;
 }
 
-int AppStatusManager::TerminateAppsByPkgid(const std::string& pkgid,
+int AppStatusManager::TerminateAppsByPkgId(const std::string& pkgid,
     uid_t uid) {
   for (auto& app : app_status_list_) {
     if (app->GetUID() == uid && app->GetStatus() != STATUS_DYING &&
@@ -450,6 +450,23 @@ int AppStatusManager::TerminateAppsByResPackageID(const std::string& pkgid,
   return 0;
 }
 
+int AppStatusManager::KillAppsByPkgId(const std::string& pkgid, uid_t uid) {
+  for (auto& app : app_status_list_) {
+    if (app->GetUID() == uid && app->GetPackageID() == pkgid) {
+      int ret = _launch_send_sigkill(app->GetPID(), app->GetUID());
+      if (ret < 0) {
+        _E("Failed to send sigkill. app(%s), pid(%d)",
+            app->GetAppID().c_str(), app->GetPID());
+      }
+
+      Update(app, STATUS_DYING, false, true);
+      DeleteSocketPath(app->GetPID(), app->GetUID());
+    }
+  }
+
+  return 0;
+}
+
 int AppStatusManager::PublishStatus(int pid, int context_status) {
   static const std::string APP_STATUS_EVENT = "app_status_event";
   auto app = Find(pid);
index 37283c9a84777eab75539bcb4fabcadc64867383..742acb0e60fb0dffd4a6a52179f862e611bef80f 100644 (file)
@@ -64,8 +64,9 @@ class AppStatusManager : public AppStatus::IEvent {
   int SendRunningAppinfo(int fd, int cmd, uid_t uid);
   int ForeachRunningAppinfo(ForeachCb callback, void* data);
   int TerminateApps(const std::string& appid, uid_t uid);
-  int TerminateAppsByPkgid(const std::string& pkgid, uid_t uid);
+  int TerminateAppsByPkgId(const std::string& pkgid, uid_t uid);
   int TerminateAppsByResPackageID(const std::string& pkgid, uid_t uid);
+  int KillAppsByPkgId(const std::string& pkgid, uid_t uid);
 
   int PublishStatus(int pid, int context_status);
   void CleanUp(AppStatusPtr app);