Terminate sub app 61/301061/1
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 8 Nov 2023 01:38:08 +0000 (10:38 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 8 Nov 2023 01:38:08 +0000 (10:38 +0900)
If the leader process is terminated while executing an application,
amd should terminate the sub application.
And, when the application type is not a component-based application,
the process must be terminated even though the process does not handle
the termination request properly.

Change-Id: If06788d09dc22a6c16437a418ed23d7357da0826
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_launch.cc
src/modules/ui-core/src/app_group.c

index d2e0bd7..629f4f1 100644 (file)
@@ -1489,14 +1489,35 @@ int _launch_start_onboot_app_local(uid_t uid, const char* appid,
 }
 
 int _term_sub_app(int pid, uid_t uid) {
-  return amd::AppRequest::TerminateSubApp(pid, uid);
+  amd::AppStatusPtr app_status = amd::AppStatusManager::GetInst().Find(pid);
+  if (app_status == nullptr) {
+    _W("Failed to find app status. pid(%d)", pid);
+    return -1;
+  }
+
+  int ret = amd::AppRequest::TerminateSubApp(pid, uid);
+  amd::AppStatusManager::GetInst().Update(app_status, STATUS_DYING, false,
+      true);
+  return ret;
 }
 
 int _term_sub_inst(int pid, const char* instance_id, uid_t uid) {
   if (instance_id == nullptr)
     return -1;
 
-  return amd::AppRequest::TerminateSubInstance(pid, uid, instance_id);
+  amd::AppStatusPtr app_status = amd::AppStatusManager::GetInst().Find(pid);
+  if (app_status == nullptr) {
+    _W("Failed to find app status. pid(%d)", pid);
+    return -1;
+  }
+
+  int ret = amd::AppRequest::TerminateSubInstance(pid, uid, instance_id);
+  if (app_status->GetAppType() != amd::AppType::ComponentBased) {
+    amd::AppStatusManager::GetInst().Update(app_status, STATUS_DYING, false,
+        true);
+  }
+
+  return ret;
 }
 
 int _terminate_app_local(uid_t uid, int pid) {
@@ -1537,8 +1558,20 @@ int _launch_terminate_bg_inst(int pid, request_h request) {
 }
 
 int _launch_terminate_inst(int pid, request_h request) {
-  return amd::AppRequest::TerminateInstance(
-      pid, static_cast<amd::Request*>(request));
+  amd::AppStatusPtr app_status = amd::AppStatusManager::GetInst().Find(pid);
+  if (app_status == nullptr) {
+    _W("Failed to find app status. pid(%d)", pid);
+    return -1;
+  }
+
+  int ret = amd::AppRequest::TerminateInstance(pid,
+      static_cast<amd::Request*>(request));
+  if (app_status->GetAppType() != amd::AppType::ComponentBased) {
+    amd::AppStatusManager::GetInst().Update(app_status, STATUS_DYING, false,
+        true);
+  }
+
+  return ret;
 }
 
 void _launch_set_focused_pid(int pid) {
index 26fb37a..020aed2 100644 (file)
@@ -908,6 +908,12 @@ static struct app_group_context_s *__app_group_add(
        found = g_list_find_custom(__app_group_list, leader_id,
                        __compare_group_id);
        if (!found) {
+               if (leader_pid != pid) {
+                       _E("%d is not reader(%d)", pid, leader_pid);
+                       __destroy_app_group_context(ctx);
+                       return NULL;
+               }
+
                group = __create_app_group(leader_id, leader_pid);
                if (!group) {
                        _E("Failed to create app group. %s:%d",
@@ -978,6 +984,8 @@ static void __app_group_start(pid_t leader_pid, const char *leader_id,
        bool attach_below = false;
        app_group_node_h caller_node;
        app_group_node_h next_node;
+       amd_app_status_h app_status;
+       uid_t uid;
 
        _D("app_group_start");
 
@@ -1013,6 +1021,13 @@ static void __app_group_start(pid_t leader_pid, const char *leader_id,
                ctx = __app_group_add(leader_pid, leader_id, pid, id,
                                caller_pid, caller_id, launch_mode,
                                false, recycle, before_wid, attach_below);
+               if (!ctx) {
+                       app_status = amd_app_status_find_by_pid(pid);
+                       if (app_status) {
+                               uid = amd_app_status_get_uid(app_status);
+                               amd_launch_term_sub_inst(pid, id, uid);
+                       }
+               }
        } else {
                ctx = __app_group_add(pid, id, pid, id,
                                caller_pid, caller_id, launch_mode,