Modify app status setting logic in RegisterPID
authorChanggyu Choi <changyu.choi@samsung.com>
Fri, 10 Feb 2023 04:56:19 +0000 (13:56 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 13 Feb 2023 00:38:37 +0000 (09:38 +0900)
Among the apps registered as RegisterPID(),
there is a problem that the status does not change to BG sometimes.
This patch fixes the status setting logic to prevent these issues.

Change-Id: I4fcc7d1bb5f57bdf6d4cdb916bd5023cb2ff44c1
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/lib/app_status/app_status_manager.cc

index ed4d6bec9cab37b3b050088a167e183ecae12fe2..c8807da3dbc82a8bb340e756199fc7ff1495e20b 100644 (file)
@@ -47,6 +47,7 @@
 #include "lib/api/amd_api_app_request_broker.h"
 #include "lib/api/amd_api_inotify.h"
 #include "lib/app_status/app_status_dao_implementation.hh"
+#include "lib/launch/foreground_manager.hh"
 #include "lib/request/request.hh"
 
 namespace amd {
@@ -589,27 +590,28 @@ int AppStatusManager::RegisterPID(int pid, const std::string& appid,
   _noti_send(AMD_NOTI_MSG_APP_STATUS_APP_REGISTER_PID, pid, 0, app_info.get(),
       nullptr);
 
-  if (component_type != APP_TYPE_SERVICE) {
-    _signal_get_proc_status_async(pid,
-        [](int pid, int status, int focused, void* data) -> void {
-          auto* manager = static_cast<AppStatusManager*>(data);
-          if (focused == 1)
-            _launch_set_focused_pid(pid);
-
-          if (status == PROC_STATUS_FG)
-            status = STATUS_VISIBLE;
-          else if (status == PROC_STATUS_BG)
-            status = STATUS_BG;
-          else
-            return;
-
-          auto app = manager->Find(pid);
-          if (app == nullptr)
-            return;
-
-          manager->Update(app, status, false, true);
-        }, this);
-  }
+  if (component_type != APP_TYPE_SERVICE)
+    return 0;
+
+  ForegroundManager::GetInst().Add(pid);
+  _signal_get_proc_status_async(pid,
+      [](int pid, int status, int focused, void* data) -> void {
+        auto* manager = static_cast<AppStatusManager*>(data);
+        if (focused == 1)
+          _launch_set_focused_pid(pid);
+
+        if (status == PROC_STATUS_FG)
+          status = STATUS_VISIBLE;
+        else
+          status = STATUS_BG;
+
+        ForegroundManager::GetInst().Remove(pid);
+        auto app = manager->Find(pid);
+        if (app == nullptr)
+          return;
+
+        manager->Update(app, status, false, true);
+      }, this);
 
   return 0;
 }