Handle a new request 48/259848/2
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 16 Jun 2021 02:15:48 +0000 (11:15 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 16 Jun 2021 02:20:45 +0000 (11:20 +0900)
Some process wants to get the state of the application lifecycle state.
This patch is for aul_app_lifecycle_get_state() function.

Requires:
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/259845/
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/259848/

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

index 5e89fa8a133bdb7e86a873bad75aa10d9ca17448..bafdba0f91e22aac35818aec65c206eb21680321 100644 (file)
@@ -17,6 +17,7 @@
 #include <aul.h>
 #include <aul_app_lifecycle.h>
 #include <aul_cmd.h>
+#include <aul_sock.h>
 #include <bundle_cpp.h>
 #include <errno.h>
 
@@ -135,6 +136,43 @@ static int __dispatch_app_lifecycle_update_state(request_h req) {
   return 0;
 }
 
+static int __dispatch_app_lifecycle_get_state(request_h req) {
+  bundle* kb = _request_get_bundle(req);
+  if (kb == nullptr) {
+    _E("Failed to get bundle");
+    return -EINVAL;
+  }
+
+  tizen_base::Bundle b(kb, false, false);
+  b.Delete(AUL_K_STATE);
+
+  std::string app_id = b.GetString(AUL_K_APPID);
+  uid_t target_uid = _request_get_target_uid(req);
+  app_status_h app_status = _app_status_find_by_appid(app_id.c_str(),
+      target_uid);
+  if (app_status == nullptr) {
+    aul_sock_send_bundle_with_fd(_request_remove_fd(req), APP_GET_INFO_ERROR,
+        b.GetHandle(), AUL_SOCK_NOREPLY);
+    return -1;
+  }
+
+  int pid = _app_status_get_pid(app_status);
+  auto& inst = AppLifecycleManager::GetInst();
+  auto info = inst.Find(pid);
+  if (info == nullptr) {
+    _E("Failed to find app lifecycle info. pid(%d)", pid);
+    aul_sock_send_bundle_with_fd(_request_remove_fd(req), APP_GET_INFO_ERROR,
+        b.GetHandle(), AUL_SOCK_NOREPLY);
+    return -1;
+  }
+
+  b.Add(AUL_K_STATE, std::to_string(info->GetState()));
+  aul_sock_send_bundle_with_fd(_request_remove_fd(req), APP_GET_INFO_OK,
+      b.GetHandle(), AUL_SOCK_NOREPLY);
+  _W("app_id(%s), pid(%d), state(%d)", app_id.c_str(), pid, info->GetState());
+  return 0;
+}
+
 int _app_lifecycle_init(void) {
   _W("APP_LIFECYCLE_INIT");
 
@@ -143,6 +181,10 @@ int _app_lifecycle_init(void) {
       .cmd = APP_LIFECYCLE_UPDATE_STATE,
       .callback = __dispatch_app_lifecycle_update_state
     },
+    {
+      .cmd = APP_LIFECYCLE_GET_STATE,
+      .callback = __dispatch_app_lifecycle_get_state
+    },
   };
 
   int ret = _request_register_cmds(dispatch_table, ARRAY_SIZE(dispatch_table));