process: Add dbus method to get app info
authorSangYoun Kwak <sy.kwak@samsung.com>
Tue, 6 Aug 2024 06:56:31 +0000 (15:56 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 21 Oct 2024 09:56:51 +0000 (18:56 +0900)
To get app information using dbue method, a method "GetAppInfo" is
added. This method gets an app id as a parameter and returns the
informations of app if exists.

Change-Id: Ie22bd26a7a8e58d01067639b7c2e16a36cdf5cef
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/process/proc-monitor.c

index 62c231906b5565b1019f6be1ca8daefe2cc7210e..83b8a90d925c77131065c214beb7e6bcdb158068 100644 (file)
@@ -362,6 +362,48 @@ static void dbus_get_meminfo(GDBusMethodInvocation *invocation, GVariant *params
                                mem_total, mem_free, cached, used, swap));
 }
 
+EXPORT_TEST void dbus_get_app_info(GDBusMethodInvocation *invocation, GVariant *params)
+{
+       char *appid = NULL;
+       struct proc_app_info *pai = NULL;
+       const char *error_message = "Success";
+
+       do_expr_unless_g_variant_get_typechecked(return, params, "(s)", &appid);
+       if (appid == NULL) {
+               _E("Invalid parameters");
+               error_message = "Parameter should be a string";
+               goto failure;
+       }
+
+       pai = find_app_info_by_appid(appid);
+       if (pai == NULL) {
+               _E("No such app: %s", appid);
+               error_message = "No such application exists";
+               goto failure;
+       }
+
+       g_dbus_method_invocation_return_value(invocation, g_variant_new("(ibbiiiiii)",
+                               pai->main_pid,
+                               pai->app_watchdog_exclude,
+                               pai->app_cpu_nice_update_exclude,
+                               pai->runtime_exclude,
+                               pai->flags,
+                               pai->lru_state,
+                               pai->categories,
+                               pai->state,
+                               pai->type));
+
+       g_free(appid);
+
+       return;
+
+failure:
+       g_free(appid);
+
+       g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
+               G_DBUS_ERROR_INVALID_ARGS, "%s", error_message);
+}
+
 static void dbus_reclaim_memory(GDBusMethodInvocation *invocation, GVariant *params)
 {
        _D("reclaiming memory!");
@@ -1372,6 +1414,18 @@ static const char dbus_methods_xml[] =
 "                      <arg type='u' name='MemUsed' direction='out'/>"
 "                      <arg type='u' name='MemSwap' direction='out'/>"
 "              </method>"
+"              <method name='GetAppInfo'>"
+"                      <arg type='s' name='AppId' direction='in'/>"
+"                      <arg type='i' name='MainPid' direction='out'/>"
+"                      <arg type='b' name='AppWatchdogExclude' direction='out'/>"
+"                      <arg type='b' name='AppCpuNiceUpdateExclude' direction='out'/>"
+"                      <arg type='i' name='RuntimeExclude' direction='out'/>"
+"                      <arg type='i' name='Flags' direction='out'/>"
+"                      <arg type='i' name='LruState' direction='out'/>"
+"                      <arg type='i' name='Categories' direction='out'/>"
+"                      <arg type='i' name='State' direction='out'/>"
+"                      <arg type='i' name='Type' direction='out'/>"
+"              </method>"
 "              <method name='ReclaimMemory'>"
 "                      <arg type='i' name='ZeroOnSuccess' direction='out'/>"
 "              </method>"
@@ -1416,6 +1470,7 @@ static struct d_bus_method dbus_methods[] = {
        { "GetMemoryList", dbus_get_memory_list },
        { "GetMemoryLists", dbus_get_memory_lists },
        { "GetMemInfo", dbus_get_meminfo },
+       { "GetAppInfo", dbus_get_app_info },
        { "ReclaimMemory", dbus_reclaim_memory },
        { "PrePoweroff", dbus_pre_poweroff },
        { "ProcExclude", proc_dbus_exclude_method_handler},