Postpone calling pause callback 86/183586/1
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 5 Jul 2018 09:55:04 +0000 (18:55 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 9 Jul 2018 01:23:03 +0000 (10:23 +0900)
The watch-application can have multiple viewers. Sometimes,
it has a timing issue when the viewers' state are changed.
This patch adds a pause timer for handling multiple viewer scenario.
It's a workaround.

Change-Id: I4cd1d498fe47912ac0eeabea702234c2fe8879f2
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/base/watch_base.c

index 21cfb2e..ba0758e 100755 (executable)
@@ -112,6 +112,7 @@ struct watch_base_context {
        int viewer_visibility;
        bool ambient_mode;
        bool ambient_mode_skip_resume;
+       guint pause_timer;
        void *data;
 };
 
@@ -693,18 +694,44 @@ static void __on_window_show(int type, void *event, void *data)
                _D("viewer is not resumed, do not resume watch");
 }
 
+static gboolean __delayed_pause(gpointer data)
+{
+       LOGW("Delayed pause");
+       __on_ui_base_pause(NULL);
+       __context.pause_timer = 0;
+       return G_SOURCE_REMOVE;
+}
+
+static void __add_pause_timer(void)
+{
+       if (__context.pause_timer == 0) {
+               _D("Add pause timer");
+               __context.pause_timer = g_timeout_add(200,
+                               __delayed_pause, NULL);
+       }
+}
+
+static void __remove_pause_timer(void)
+{
+       if (__context.pause_timer) {
+               _D("Remove pause timer");
+               g_source_remove(__context.pause_timer);
+               __context.pause_timer = 0;
+       }
+}
+
 static void __on_window_visibility(int type, void *event, void *data)
 {
        Ecore_Wl2_Event_Window_Visibility_Change *ev = event;
 
-       _D("visibility %u %u",
-                       (unsigned int)ev->win,
-                       (unsigned int)ev->fully_obscured);
+       _D("win(%u), fully_obscured(%d)",
+                       (unsigned int)ev->win, ev->fully_obscured);
 
        if (ev->fully_obscured) {
                __context.watch_visibility = WVS_PAUSE;
-               __on_ui_base_pause(NULL);
+               __add_pause_timer();
        } else {
+               __remove_pause_timer();
                __context.watch_visibility = WVS_RESUME;
                if (__context.viewer_visibility == AUL_SCREEN_STATUS_RESUME)
                        __on_ui_base_resume(NULL);
@@ -792,10 +819,12 @@ static int __viewer_state_handler(const char *widget_id, aul_app_com_result_e e,
 
        if (*state == AUL_SCREEN_STATUS_RESUME &&
                        __context.watch_visibility == WVS_RESUME) {
+               __remove_pause_timer();
                __on_ui_base_resume(NULL);
        } else if (*state == AUL_SCREEN_STATUS_PAUSE) {
-               __on_ui_base_pause(NULL);
+               __add_pause_timer();
        } else if (*state == AUL_SCREEN_STATUS_PRE_RESUME) {
+               __remove_pause_timer();
                _D("call pre resume tick");
                __on_pre_resume(NULL);
        }
@@ -809,6 +838,7 @@ static int __viewer_state_handler(const char *widget_id, aul_app_com_result_e e,
 static void __lcd_on_handler(void *user_data)
 {
        _D("Call pre resume tick");
+       __remove_pause_timer();
        __on_pre_resume(NULL);
 }