Fix foreground check logic 21/95321/1 accepted/tizen/common/20161103.160029 accepted/tizen/ivi/20161103.231559 accepted/tizen/mobile/20161103.231505 accepted/tizen/tv/20161103.231523 accepted/tizen/wearable/20161103.231541 submit/tizen/20161103.060805
authorKwangyoun Kim <ky85.kim@samsung.com>
Thu, 3 Nov 2016 00:47:44 +0000 (09:47 +0900)
committerKwangyoun Kim <ky85.kim@samsung.com>
Thu, 3 Nov 2016 00:48:06 +0000 (09:48 +0900)
Change-Id: Iaa3669707d0ee7cc1b6820b56dd4f616ebddf0fe

client/vc.c
client/vc_widget.c

index 46ef551..8ea8acc 100644 (file)
@@ -19,6 +19,7 @@
 #include <cynara-client.h>
 #include <cynara-error.h>
 #include <cynara-session.h>
+#include <Ecore_Wayland.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdbool.h>
@@ -42,6 +43,9 @@
 
 static Ecore_Timer* g_connect_timer = NULL;
 
+static Ecore_Event_Handler* g_focus_in_handler = NULL;
+static Ecore_Event_Handler* g_focus_out_handler = NULL;
+
 static vc_h g_vc = NULL;
 
 static int g_daemon_pid = 0;
@@ -233,13 +237,12 @@ static Eina_Bool __notify_auth_changed_cb(void *data)
        return EINA_FALSE;
 }
 
-static int __vc_app_state_changed_cb(int app_state, void *data)
+static Eina_Bool __focus_changed_cb(void *data, int type, void *event)
 {
-       int ret = -1;
-       SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] app state changed");
+       SLOG(LOG_DEBUG, TAG_VCC, "===== Focus changed");
 
-       /* Set current pid */
-       if (STATUS_VISIBLE == app_state) {
+       int ret;
+       if (ECORE_WL_EVENT_FOCUS_IN == type) {
                SLOG(LOG_DEBUG, TAG_VCC, "===== Set foreground");
                ret = vc_dbus_set_foreground(getpid(), true);
                if (0 != ret) {
@@ -262,8 +265,8 @@ static int __vc_app_state_changed_cb(int app_state, void *data)
                        /* notify auth changed cb */
                        ecore_timer_add(0, __notify_auth_changed_cb, NULL);
                }
-       } else if (STATUS_BG == app_state) {
-               SLOG(LOG_DEBUG, TAG_VCC, "===== Set background");
+       } else if (ECORE_WL_EVENT_FOCUS_OUT == type) {
+               SLOG(LOG_DEBUG, TAG_VCW, "===== Set background");
                ret = vc_dbus_set_foreground(getpid(), false);
                if (0 != ret) {
                        SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set foreground (false) : %d", ret);
@@ -286,13 +289,13 @@ static int __vc_app_state_changed_cb(int app_state, void *data)
                        ecore_timer_add(0, __notify_auth_changed_cb, NULL);
                }
        } else {
-               SLOG(LOG_DEBUG, TAG_VCC, "===== App state is NOT valid");
+               SLOG(LOG_DEBUG, TAG_VCC, "===== type(%d) is NOT valid", type);
        }
 
        SLOG(LOG_DEBUG, TAG_VCC, "=====");
-       SLOG(LOG_DEBUG, TAG_VCC, " ");
+       SLOG(LOG_DEBUG, TAG_VCC, "");
 
-       return 0;
+       return ECORE_CALLBACK_RENEW;
 }
 
 int vc_initialize(void)
@@ -378,6 +381,14 @@ static void __vc_internal_unprepare(void)
                SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request finalize : %s", __vc_get_error_code(ret));
        }
 
+       if (NULL != g_focus_in_handler) {
+               ecore_event_handler_del(g_focus_in_handler);
+               g_focus_in_handler = NULL;
+       }
+       if (NULL != g_focus_out_handler) {
+               ecore_event_handler_del(g_focus_out_handler);
+               g_focus_out_handler = NULL;
+       }
 
        ret = vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_FOREGROUND);
        if (0 != ret)
@@ -492,13 +503,14 @@ static Eina_Bool __vc_connect_daemon(void *data)
 
        g_connect_timer = NULL;
 
-       ret = aul_add_status_local_cb(__vc_app_state_changed_cb, NULL);
-       if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set app stae changed callback");
-       }
+       g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL);
+       g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL);
+
+       char appid[255] = {'\0',};
+       aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
 
-       int status = aul_app_get_status_bypid(getpid());
-       if (STATUS_FOCUS == status || STATUS_VISIBLE == status) {
+       int status = aul_app_get_status(appid);
+       if (STATUS_FOCUS == status) {
                SLOG(LOG_DEBUG, TAG_VCC, "===== Set foreground");
                ret = vc_dbus_set_foreground(getpid(), true);
                if (0 != ret) {
index 6714f40..3089ab4 100644 (file)
@@ -32,6 +32,9 @@
 
 static Ecore_Timer* g_w_connect_timer = NULL;
 
+static Ecore_Event_Handler* g_focus_in_handler = NULL;
+static Ecore_Event_Handler* g_focus_out_handler = NULL;
+
 static Ecore_Timer* g_w_start_timer = NULL;
 static Ecore_Timer* g_w_tooltip_timer = NULL;
 
@@ -162,6 +165,15 @@ static void __vc_widget_internal_unprepare()
                SLOG(LOG_WARN, TAG_VCW, "[ERROR] Fail to request finalize : %s", __vc_widget_get_error_code(ret));
        }
 
+       if (NULL != g_focus_in_handler) {
+               ecore_event_handler_del(g_focus_in_handler);
+               g_focus_in_handler = NULL;
+       }
+       if (NULL != g_focus_out_handler) {
+               ecore_event_handler_del(g_focus_out_handler);
+               g_focus_out_handler = NULL;
+       }
+
        ret = vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_WIDGET);
        if (0 != ret)
                SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to delete file, type(%d), ret(%d)", VC_COMMAND_TYPE_WIDGET, ret);
@@ -286,8 +298,8 @@ static Eina_Bool __vc_widget_connect_daemon(void *data)
 
        vc_widget_client_set_service_state(g_vc_w, (vc_service_state_e)service_state);
 
-       ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL);
-       ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL);
+       g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL);
+       g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL);
 
        char appid[255] = {'\0',};
        aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));