Check Process State 90/232390/3
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 4 May 2020 05:08:30 +0000 (14:08 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 4 May 2020 08:05:04 +0000 (17:05 +0900)
If the process is excluded from resourced, amd doesn't send the suspend
hint to resourced.

Change-Id: I852d2cc9d5bfb70051a88f4512b1da7d85313b3a
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
inc/amd_api_suspend.h
inc/amd_suspend.h
modules/ui-core/src/app_group.c
src/core/amd_app_status.c
src/core/amd_launch.c
src/core/amd_suspend.c
src/lib/amd_api_suspend.c

index 44d9938396d974e705669970efa88f8f0d65791f..dcd2e2dd8bc56b9e5a5eaa84e684b6a05962dd50 100644 (file)
@@ -41,6 +41,7 @@ enum amd_background_category_e {
        AMD_BACKGROUND_CATEGORY_SYSTEM = 0x40
 };
 
+bool amd_suspend_is_excluded(int pid);
 bool amd_suspend_is_allowed_background(amd_appinfo_h ai);
 void amd_suspend_add_timer(int pid);
 void amd_suspend_remove_timer(int pid);
index db9fbde5ecc39b3ae9a400d682e99d9a78c7b3c9..2bbfa4b4cd681f610f85769fca8adcddf82ffe33 100644 (file)
@@ -38,6 +38,9 @@ enum background_category_e {
        BACKGROUND_CATEGORY_SYSTEM = 0x40
 };
 
+int _suspend_exclude(int pid);
+int _suspend_include(int pid);
+bool _suspend_is_excluded(int pid);
 bool _suspend_is_allowed_background(const struct appinfo *ai);
 void _suspend_add_timer(int pid);
 void _suspend_remove_timer(int pid);
index 21d50cb41fd22e46bc9009fd109379eb5aed5545..d44252acf8949125ed64f35407d35b4492ee0526 100644 (file)
@@ -1069,6 +1069,7 @@ static void __app_group_send_status(pid_t pid, bool flag, bool force, bool self)
        const char *appid;
        const char *pkgid;
        bool bg_allowed;
+       bool excluded;
        uid_t uid;
 
        app_status = amd_app_status_find_by_effective_pid(pid);
@@ -1088,12 +1089,13 @@ static void __app_group_send_status(pid_t pid, bool flag, bool force, bool self)
 
        pkgid = amd_appinfo_get_value(ai, AMD_AIT_PKGID);
        bg_allowed = amd_suspend_is_allowed_background(ai);
+       excluded = amd_suspend_is_excluded(pid);
 
        LOGD("Send %s signal %s", flag ? "FG" : "BG", appid);
        aul_send_app_status_change_signal(pid, appid, pkgid,
                        flag ? STATUS_FOREGROUND : STATUS_BACKGROUND,
                        APP_TYPE_UI);
-       if (!bg_allowed) {
+       if (!excluded && !bg_allowed) {
                amd_app_status_find_service_apps(app_status,
                                flag ? STATUS_VISIBLE : STATUS_BG,
                                flag ? __prepare_to_wake : __prepare_to_suspend,
@@ -1869,6 +1871,7 @@ static void __terminate_unmanageable_app(amd_app_status_h app_status)
        const char *taskmanage;
        const char *appid;
        bool bg_allowed;
+       bool excluded;
        GList *iter;
        uid_t uid;
 
@@ -1898,7 +1901,9 @@ static void __terminate_unmanageable_app(amd_app_status_h app_status)
                ai = amd_appinfo_find(uid, appid);
                taskmanage = amd_appinfo_get_value(ai, AMD_AIT_TASKMANAGE);
                bg_allowed = amd_suspend_is_allowed_background(ai);
-               if (taskmanage && !strcmp(taskmanage, "false") && !bg_allowed) {
+               excluded = amd_suspend_is_excluded(group->leader_pid);
+               if (taskmanage && !strcmp(taskmanage, "false") &&
+                               !bg_allowed && !excluded) {
                        SECURE_LOGW("Terminate leader app(%s:%d)",
                                        appid, group->leader_pid);
                        aul_send_app_terminate_request_signal(group->leader_pid,
index 7ae76762db690b28a17a61eb1f4787d75aa45faa..fb50a2e5b659b88d166777b7eced873fb4974d07 100644 (file)
@@ -1017,6 +1017,7 @@ void _app_status_find_service_apps(app_status_h app_status, int status,
        const struct appinfo *ai;
        struct app_status_s *svc_status;
        bool bg_allowed;
+       bool excluded;
        uid_t uid;
 
        if (app_status == NULL) {
@@ -1033,7 +1034,8 @@ void _app_status_find_service_apps(app_status_h app_status, int status,
                if (svc_status && svc_status->uid == uid) {
                        ai = _appinfo_find(uid, svc_status->appid);
                        bg_allowed = _suspend_is_allowed_background(ai);
-                       if (!bg_allowed) {
+                       excluded = _suspend_is_excluded(svc_status->pid);
+                       if (!excluded && !bg_allowed) {
                                send_event_to_svc_core(svc_status->pid, uid);
                                if (svc_status->status != STATUS_DYING &&
                                                suspend)
@@ -1053,6 +1055,7 @@ void _app_status_check_service_only(app_status_h app_status,
        struct app_status_s *ui_status;
        int ui_cnt = 0;
        bool bg_allowed;
+       bool excluded;
        const char *appid;
        const struct appinfo *ai;
        uid_t uid;
@@ -1078,7 +1081,8 @@ void _app_status_check_service_only(app_status_h app_status,
                status = _app_status_get_status(app_status);
                ai = _appinfo_find(uid, appid);
                bg_allowed = _suspend_is_allowed_background(ai);
-               if (!bg_allowed && status != STATUS_DYING) {
+               excluded = _suspend_is_excluded(app_status->pid);
+               if (!excluded && !bg_allowed && status != STATUS_DYING) {
                        send_event_to_svc_core(app_status->pid, uid);
                        _suspend_add_timer(app_status->pid);
                }
index 9fd3b2139bab2602faa07acdee3dcc3754a7b9f6..9e4d1118439176de16f34ea9e119a907fc9c83f3 100644 (file)
@@ -1243,7 +1243,8 @@ static int __app_status_handler(int pid, int status, void *data)
                _app_status_update_status(app_status, STATUS_BG, false, true);
                appid = _app_status_get_appid(app_status);
                ai = _appinfo_find(uid, appid);
-               if (!_suspend_is_allowed_background(ai)) {
+               if (!_suspend_is_excluded(pid) &&
+                               !_suspend_is_allowed_background(ai)) {
                        __prepare_to_suspend(pid, uid);
                        _suspend_add_timer(pid);
                }
@@ -3144,13 +3145,13 @@ static int __do_starting_app(struct launch_s *handle, request_h req,
        _util_save_log("LAUNCHING", handle->appid);
        if (handle->debug_mode) {
                _W("Exclude - %s(%d)", handle->appid, handle->pid);
-               aul_update_freezer_status(handle->pid, "exclude");
+               _suspend_exclude(handle->pid);
                return ret;
        }
 
        if (handle->bg_category == BACKGROUND_CATEGORY_BACKGROUND_NETWORK) {
                if (!handle->bg_allowed)
-                       aul_update_freezer_status(handle->pid, "include");
+                       _suspend_include(handle->pid);
        }
 
        if (comp_type && !strcmp(comp_type, APP_TYPE_SERVICE)) {
index d6dea1ede9be672a8c9c8f39e3f9cd186b1cf755..c420be2a1e3574e350977a23c06f1a00dd97abef 100644 (file)
@@ -32,6 +32,7 @@
 typedef struct proc_info {
        pid_t pid;
        guint timer_id;
+       int ex_ref;
 } proc_info_t;
 
 typedef struct network_info {
@@ -44,6 +45,58 @@ static GHashTable *proc_info_tbl;
 static network_info_t __net_info;
 static guint __init_timer;
 
+static proc_info_t *__create_proc_info(int pid);
+static proc_info_t *__find_proc_info(int pid);
+
+int _suspend_exclude(int pid)
+{
+       proc_info_t *info;
+       int ret;
+
+       info = __find_proc_info(pid);
+       if (!info)
+               info = __create_proc_info(pid);
+
+       info->ex_ref++;
+       if (info->ex_ref == 1) {
+               ret = aul_update_freezer_status(pid, "exclude");
+               _W("[__SUSPEND__] Exclude pid(%d), result(%d)", pid, ret);
+       }
+
+       return 0;
+}
+
+int _suspend_include(int pid)
+{
+       proc_info_t *info;
+       int ret;
+
+       info = __find_proc_info(pid);
+       if (!info)
+               info = __create_proc_info(pid);
+
+       if (info->ex_ref > 0)
+               info->ex_ref--;
+
+       if (info->ex_ref == 0) {
+               ret = aul_update_freezer_status(pid, "include");
+               _W("[__SUSPEND__] Include pid(%d), result(%d)", pid, ret);
+       }
+
+       return 0;
+}
+
+bool _suspend_is_excluded(int pid)
+{
+       proc_info_t *info;
+
+       info = __find_proc_info(pid);
+       if (info)
+               return (info->ex_ref > 0) ? true : false;
+
+       return false;
+}
+
 static void __destroy_proc_info_value(gpointer data)
 {
        proc_info_t *proc = (proc_info_t *)data;
@@ -151,7 +204,7 @@ static void __wake_bg_apps(app_status_h app_status, void *data)
        __prepare_to_wake(pid, uid);
        _app_status_find_service_apps(app_status, status,
                        __prepare_to_wake, false);
-       aul_update_freezer_status(pid, "exclude");
+       _suspend_exclude(pid);
 }
 
 static void __suspend_bg_apps(app_status_h app_status, void *data)
@@ -196,7 +249,7 @@ static void __suspend_bg_apps(app_status_h app_status, void *data)
                        __prepare_to_suspend, true);
        __prepare_to_suspend(pid, uid);
        _suspend_add_timer(pid);
-       aul_update_freezer_status(pid, "include");
+       _suspend_include(pid);
 }
 
 static gboolean __handle_bg_network_apps(gpointer data)
@@ -320,7 +373,7 @@ proc_info_t *__create_proc_info(int pid)
                return NULL;
        }
 
-       proc = (proc_info_t *)malloc(sizeof(proc_info_t));
+       proc = (proc_info_t *)calloc(1, sizeof(proc_info_t));
        if (proc == NULL) {
                _E("insufficient memory");
                return NULL;
index 7c5e66393b9b87298a6e5d01cf391fb7fe0b824c..713cd371f92b111a82baa382f9c6a607ce80d5c0 100644 (file)
@@ -30,6 +30,11 @@ EXPORT_API int amd_suspend_remove_proc(int pid)
        return _suspend_remove_proc(pid);
 }
 
+EXPORT_API bool amd_suspend_is_excluded(int pid)
+{
+       return _suspend_is_excluded(pid);
+}
+
 EXPORT_API bool amd_suspend_is_allowed_background(amd_appinfo_h ai)
 {
        return _suspend_is_allowed_background(ai);