proc-monitor: Update window stack when updating app life cycle 61/296561/2
authorUnsung Lee <unsung.lee@samsung.com>
Mon, 31 Jul 2023 07:27:36 +0000 (16:27 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 1 Aug 2023 06:34:33 +0000 (15:34 +0900)
Update window stack information when app life cycle is updated
to get the latest window stack information.

Window stack is dbus method call, so resourced doest not know
when window stack is updated. On the other hand, app life cycle update
can be caught by call back function. That is, resourced can catch
timing of window stack update using app life cycle

Change-Id: I626d338e7e45814449a899f2ed9ebf059e9a964a
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
packaging/resourced.spec
src/CMakeLists.txt
src/process/proc-monitor.c

index 0c970fa..bc25e47 100644 (file)
@@ -43,6 +43,7 @@ BuildRequires:  pkgconfig(capi-system-resource)
 BuildRequires:  pkgconfig(cmocka)
 BuildRequires:  pkgconfig(libsyscommon)
 BuildRequires:  pkgconfig(libsyscommon-plugin-api-resourced)
+BuildRequires:  pkgconfig(aul)
 BuildRequires: gperf
 
 # for swap plugin
index f3d9067..7dc00aa 100644 (file)
@@ -111,6 +111,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
        dbus-1
        libsyscommon
        libsyscommon-plugin-api-resourced
+       aul
   )
 
 INCLUDE(FindPkgConfig)
index 0948090..85275b5 100644 (file)
@@ -32,6 +32,8 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 
+#include <aul_app_lifecycle.h>
+
 #include "proc-main.h"
 #include "proc-monitor.h"
 #include "resourced.h"
@@ -228,7 +230,7 @@ static void free_window_stack(GVariantIter *iter, GVariant *reply,
                g_hash_table_remove_all(window_table);
 }
 
-static int dbus_update_window_stack(pid_t *pid, const char *app_state)
+static int dbus_update_window_stack(pid_t pid, const char *app_state)
 {
        static GHashTable *window_table = NULL;
        struct proc_app_window_info window;
@@ -238,7 +240,7 @@ static int dbus_update_window_stack(pid_t *pid, const char *app_state)
        int z = 0;
        int ret;
 
-       if (!pid || !app_state) {
+       if (!app_state) {
                _E("It is impossible to parse pid or app status");
                return RESOURCED_ERROR_INVALID_PARAMETER;
        }
@@ -272,7 +274,7 @@ static int dbus_update_window_stack(pid_t *pid, const char *app_state)
                ++z;
                window.z = z;
 
-               is_same_pid = (*pid == window.pid);
+               is_same_pid = (pid == window.pid);
                if (!is_valid_window(name, is_same_pid ? app_state : NULL, &window))
                        goto error_to_parse_window_stack;
 
@@ -1203,7 +1205,6 @@ EXPORT_TEST void proc_dbus_aul_changestate(GVariant *params)
                apptype = PROC_TYPE_GUI;
 
        resourced_proc_status_change(status, pid, appid, pkgid, apptype);
-       dbus_update_window_stack(&pid, statstr);
 }
 
 EXPORT_TEST void proc_dbus_aul_group(GVariant *params)
@@ -1274,6 +1275,24 @@ EXPORT_TEST void proc_dbus_suspend_hint(GVariant *params)
        }
 }
 
+static void aul_app_lifecycle_state_changed_monitor_cb(const char *appid, pid_t pid,
+               aul_app_lifecycle_state_e state, bool has_focus, void *user_data) {
+       char app_state[4];
+
+       switch (state) {
+       case AUL_APP_LIFECYCLE_STATE_RESUMED:
+               strncpy(app_state, "fg", sizeof(app_state) - 1);
+               dbus_update_window_stack(pid, app_state);
+               break;
+       case AUL_APP_LIFECYCLE_STATE_PAUSED:
+               strncpy(app_state, "bg", sizeof(app_state) -1);
+               dbus_update_window_stack(pid, app_state);
+               break;
+       default:
+               return;
+       }
+}
+
 static const char dbus_methods_xml[] =
 "<node>"
 "      <interface name='"RESOURCED_INTERFACE_PROCESS"'>"
@@ -1423,6 +1442,7 @@ static const struct d_bus_signal dbus_signals[] = {
 
 static int proc_dbus_init(void *data)
 {
+       int ret_register_fail;
        resourced_ret_c ret;
 
        /* start watchdog check timer for preveting ANR during booting */
@@ -1436,6 +1456,12 @@ static int proc_dbus_init(void *data)
 
        ret = d_bus_register_methods(RESOURCED_PATH_PROCESS, dbus_methods_xml,
                        dbus_methods, ARRAY_SIZE(dbus_methods));
+
+       ret_register_fail = aul_app_lifecycle_register_state_changed_cb(
+               aul_app_lifecycle_state_changed_monitor_cb, NULL);
+       if (ret_register_fail)
+               _W("Failed to register call back function to monitor app lifecycle");
+
 out:
        return ret;
 }
@@ -1444,6 +1470,9 @@ static int proc_dbus_exit(void *data)
 {
        if (app_watchdog_check_timer)
                g_source_destroy(app_watchdog_check_timer);
+
+       aul_app_lifecycle_deregister_state_changed_cb();
+
        return RESOURCED_ERROR_NONE;
 }