Send FG/BG signal to resourced 74/116074/1
authorJunghoon Park <jh9216.park@samsung.com>
Wed, 22 Feb 2017 01:33:32 +0000 (10:33 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Thu, 23 Feb 2017 01:07:43 +0000 (17:07 -0800)
- resourced should know the FG/BG status to control oom score

Change-Id: Ieab8aa28f9f80bbb087cef1f662c58ad8e4cb3de
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
(cherry picked from commit 0c9faf0db7a4b3776c9a097e6952f8393087f01a)

src/widget_app.c

index b3c18c5..3911a6d 100755 (executable)
@@ -16,6 +16,7 @@
 
 
 #include <stdlib.h>
+#include <stdbool.h>
 
 #include <bundle.h>
 #include <bundle_internal.h>
@@ -50,6 +51,9 @@
 #define STR_MAX_BUF 128
 #define LOG_TAG "CAPI_WIDGET_APPLICATION"
 #define K_REASON    "__WC_K_REASON__"
+#define APP_TYPE_WIDGET "widgetapp"
+#define STATUS_FOREGROUND "fg"
+#define STATUS_BACKGROUND "bg"
 
 typedef enum _widget_obj_state_e {
        WC_READY = 0,
@@ -86,6 +90,7 @@ static char *appid;
 static widget_class_h class_provider;
 static int exit_called;
 static char *package_id;
+static bool fg_signal;
 
 static void _widget_core_set_appcore_event_cb(void);
 static void _widget_core_unset_appcore_event_cb(void);
@@ -149,6 +154,28 @@ static widget_context_s *__find_context_by_id(const char *id)
        return ret->data;
 }
 
+static gint __comp_by_state(gconstpointer a, gconstpointer b)
+{
+       widget_context_s *wc = (widget_context_s *)a;
+
+       if (wc->state == (widget_obj_state_e)GPOINTER_TO_INT(b))
+               return 0;
+
+       return -1;
+}
+
+static widget_context_s *__find_context_by_state(widget_obj_state_e state)
+{
+       GList *ret;
+       GList *contexts = _widget_app_get_contexts();
+
+       ret = g_list_find_custom(contexts, GINT_TO_POINTER((int)state), __comp_by_state);
+       if (ret == NULL)
+               return NULL;
+
+       return ret->data;
+}
+
 static gint __comp_by_win(gconstpointer a, gconstpointer b)
 {
        int win = GPOINTER_TO_INT(b);
@@ -283,6 +310,15 @@ static int __instance_resume(widget_class_h handle, const char *id, int send_upd
        if (send_update) {
                ret = __send_update_status(handle->classid, wc->id,
                        WIDGET_INSTANCE_EVENT_RESUME, NULL);
+               if (!fg_signal) {
+                       _D("Send fg signal to resourceD");
+                       aul_send_app_status_change_signal(getpid(),
+                                       appid,
+                                       package_id,
+                                       STATUS_FOREGROUND,
+                                       APP_TYPE_WIDGET);
+                       fg_signal = true;
+               }
        } else {
                ret = 0;
        }
@@ -318,6 +354,16 @@ static int __instance_pause(widget_class_h handle, const char *id, int send_upda
        if (send_update) {
                ret = __send_update_status(handle->classid, wc->id,
                        WIDGET_INSTANCE_EVENT_PAUSE, NULL);
+               wc = __find_context_by_state(WC_RUNNING);
+               if (!wc && fg_signal) {
+                       _D("Send bg signal to resourceD");
+                       aul_send_app_status_change_signal(getpid(),
+                                       appid,
+                                       package_id,
+                                       STATUS_BACKGROUND,
+                                       APP_TYPE_WIDGET);
+                       fg_signal = false;
+               }
        } else {
                ret = 0;
        }