Check app status before sending a request 75/302775/3
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 13 Dec 2023 09:19:42 +0000 (18:19 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 13 Dec 2023 09:34:02 +0000 (18:34 +0900)
Before sending a request(APP_RESUME_BY_PID or APP_PAUSE_BY_PID) to the running
application, amd checks whether the app status is dying or not.
If it's STATUS_DYING, amd does not send the request. In this case, the caller
process will get the error from amd.

Change-Id: I860aee5301688843a03d6cf2f33edd8301bb0fcb
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_launch.cc

index 4b9b23b..591a672 100644 (file)
@@ -268,13 +268,13 @@ void CheckAndSetInstanceId(const std::shared_ptr<tizen_base::Bundle>& b) {
   _D("instance_id: %s", instance_id.c_str());
 }
 
-void SetStartTime(tizen_base::Bundle& b) {
+void SetStartTime(tizen_base::Bundle* b) {
   struct timespec start;
   clock_gettime(CLOCK_MONOTONIC, &start);
   char buf[128];
   snprintf(buf, sizeof(buf), "%ld/%ld", start.tv_sec, start.tv_nsec);
-  b.Delete(AUL_K_STARTTIME);
-  b.Add(AUL_K_STARTTIME, buf);
+  b->Delete(AUL_K_STARTTIME);
+  b->Add(AUL_K_STARTTIME, buf);
 }
 
 bool CheckOnbootCondition(uid_t uid, const char* appid, appinfo_h app_info) {
@@ -435,6 +435,12 @@ static int DispatchAppResumeByPid(request_h request) {
     return -1;
   }
 
+  if (app_status->GetStatus() == STATUS_DYING) {
+    _E("%s(%d) is dying", app_status->GetAppID().c_str(), app_status->GetPID());
+    req->SendResult(-1);
+    return -1;
+  }
+
   pid_t pid = app_status->GetPID();
   SendAppResumeRequestSignal(app_status);
   int ret = amd::AppRequest::Resume(pid, app_status->GetUID(),
@@ -466,6 +472,12 @@ static int DispatchAppResumeByPidAsync(request_h request) {
     return -1;
   }
 
+  if (app_status->GetStatus() == STATUS_DYING) {
+    _E("%s(%d) is dying", app_status->GetAppID().c_str(), app_status->GetPID());
+    req->SendResult(-1);
+    return -1;
+  }
+
   pid_t pid = app_status->GetPID();
   SendAppResumeRequestSignal(app_status);
   req->SendResult(0);
@@ -619,7 +631,7 @@ static int DispatchAppTermByPidSyncWithoutRestart(request_h request) {
   auto& b = req->GetBundle();
   std::string pid_str = b->GetString(AUL_K_APPID);
   amd::AppStatusPtr app_status = FindAppStatus(pid_str);
-  if (app_status->GetAppType() == AT_SERVICE_APP) {
+  if (app_status != nullptr && app_status->GetAppType() == AT_SERVICE_APP) {
     appinfo_h app_info = _appinfo_find(app_status->GetUID(),
         app_status->GetAppID().c_str());
     const char* status = _appinfo_get_value(app_info, AIT_STATUS);
@@ -677,7 +689,7 @@ static int DispatchAppTermByPidAsync(request_h request) {
   }
 
   appinfo_h app_info = _appinfo_find(app_status->GetUID(),
-                                      app_status->GetAppID().c_str());
+      app_status->GetAppID().c_str());
   if (app_info) {
     const char* status = _appinfo_get_value(app_info, AIT_STATUS);
     if (status && strcmp(status, "blocking") != 0)
@@ -816,6 +828,12 @@ static int DispatchAppPause(request_h request) {
     return -1;
   }
 
+  if (app_status->GetStatus() == STATUS_DYING) {
+    _E("%s(%d) is dying", app_status->GetAppID().c_str(), app_status->GetPID());
+    req->SendResult(-1);
+    return -1;
+  }
+
   pid_t pid = app_status->GetPID();
   SendAppResumeRequestSignal(app_status);
   int ret = amd::AppRequest::Pause(pid, req);
@@ -846,6 +864,12 @@ static int DispatchAppPauseByPid(request_h request) {
     return -1;
   }
 
+  if (app_status->GetStatus() == STATUS_DYING) {
+    _E("%s(%d) is dying", app_status->GetAppID().c_str(), app_status->GetPID());
+    req->SendResult(-1);
+    return -1;
+  }
+
   pid_t pid = app_status->GetPID();
   SendAppResumeRequestSignal(app_status);
   int ret = amd::AppRequest::Pause(pid, req);
@@ -1449,7 +1473,7 @@ int _launch_start_app(const char* appid, request_h request, bool* pending,
 int _launch_start_app_local_with_bundle(uid_t uid, const char* appid,
     bundle* kb) {
   tizen_base::Bundle b(kb, false, false);
-  SetStartTime(b);
+  SetStartTime(&b);
   b.Delete(AUL_K_APPID);
   b.Add(AUL_K_APPID, appid);
   amd::RequestPtr req = amd::RequestManager::GetInst().CreateRequestLocal(