Mofidy APP_REGISTER_PID handler 77/303577/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 2 Jan 2024 09:57:57 +0000 (18:57 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 2 Jan 2024 09:57:57 +0000 (18:57 +0900)
After this patch is applied, the launchpad-process-pool is able to
register the pid with the application ID.

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

index 3ad19ff..cef81c0 100644 (file)
@@ -565,7 +565,7 @@ int _app_status_register_pid(pid_t pid, const char* appid, uid_t uid) {
     return -1;
 
   return amd::AppStatusManager::GetInst().RegisterPID(
-      pid, appid, uid);
+      pid, appid, uid, pid);
 }
 
 static int DispatchAppRunningInfo(request_h request) {
@@ -804,23 +804,32 @@ static int DispatchAppRegisterPID(request_h request) {
   auto* req = static_cast<amd::Request*>(request);
   uid_t target_uid = req->GetTargetUID();
   auto& b = req->GetBundle();
-  if (b == nullptr)
+  if (b == nullptr) {
+    _E("Failed to get bundle");
     return -1;
+  }
 
   std::string appid = b->GetString(AUL_K_APPID);
-  if (appid.empty())
+  if (appid.empty()) {
+    _E("Failed to get application ID");
     return -1;
+  }
 
   std::string pid_str = b->GetString(AUL_K_PID);
-  if (pid_str.empty())
+  if (pid_str.empty()) {
+    _E("Failed to get process ID");
     return -1;
+  }
 
   pid_t pid = std::stoi(pid_str);
-  if (pid <= 1)
+  if (pid <= 1) {
+    _E("Failed to convert to string. pid(%s)", pid_str.c_str());
     return -1;
+  }
 
+  _W("[APP_REGISTER_PID] appid(%s), pid(%d)", appid.c_str(), pid);
   return amd::AppStatusManager::GetInst().RegisterPID(
-      pid, appid, target_uid);
+      pid, appid, target_uid, req->GetPID());
 }
 
 static int DispatchAppRunningInstanceInfo(request_h request) {
index 6616851..0aa6322 100644 (file)
@@ -39,6 +39,7 @@
 #include "lib/amd_app_com.h"
 #include "lib/amd_appinfo.h"
 #include "lib/amd_launch.h"
+#include "lib/amd_login_monitor.h"
 #include "lib/amd_noti.h"
 #include "lib/amd_proc.h"
 #include "lib/amd_restart_manager.h"
@@ -582,13 +583,17 @@ void AppStatusManager::UserFinish(uid_t uid) {
 }
 
 int AppStatusManager::RegisterPID(int pid, const std::string& appid,
-    uid_t uid) {
+    uid_t uid, int caller_pid) {
   auto app_info = AppInfoManager::GetInst().FindAppInfo(uid, appid);
-  if (app_info == nullptr)
+  if (app_info == nullptr) {
+    _E("Failed to find appinfo. %s:%u", appid.c_str(), uid);
     return -1;
+  }
 
-  if (VerifyAppProcess(pid, app_info->GetPkgId()) < 0)
-    return -1;
+  if (_login_monitor_get_launchpad_pid(uid) != caller_pid) {
+    if (VerifyAppProcess(pid, app_info->GetPkgId()) < 0)
+      return -1;
+  }
 
   auto app_status = FindByAppID(appid, uid);
   if (app_status != nullptr && app_status->IsRunning()) {
@@ -600,7 +605,7 @@ int AppStatusManager::RegisterPID(int pid, const std::string& appid,
     return -1;
   }
 
-  _D("appid: %s, pid: %d", appid.c_str(), pid);
+  _W("appid: %s, pid: %d", appid.c_str(), pid);
   AppStatus::Builder builder;
   builder.SetRequestId(Request::GenerateRequestID());
   builder.SetAppId(app_info->GetAppId());
index deb126d..13a6feb 100644 (file)
@@ -72,7 +72,7 @@ class AppStatusManager : public AppStatus::IEvent {
 
   int PublishStatus(int pid, int context_status);
   void CleanUp(AppStatusPtr app);
-  int RegisterPID(int pid, const std::string& appid, uid_t uid);
+  int RegisterPID(int pid, const std::string& appid, uid_t uid, int caller_pid);
   int TerminateBackgroundApps(GCompareFunc func);
 
   AppStatusPtr AddAppInfo(LaunchContext* context);