Add an exception handling about raising the window
[platform/core/appfw/app-core.git] / src / ui_base / appcore_ui_base.c
index 40919f0..eb14658 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#define _GNU_SOURCE
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <stdlib.h>
 #include <linux/limits.h>
 
-#include <Ecore_Wayland.h>
+#include <Ecore_Wl2.h>
 #include <wayland-client.h>
 #include <wayland-tbm-client.h>
 #include <tizen-extension-client-protocol.h>
 
 #include <Ecore.h>
-#include <Ecore_Evas.h>
-#include <Ecore_Input_Evas.h>
-#include <Elementary.h>
 #include <glib-object.h>
 #include <malloc.h>
 #include <glib.h>
 #include <stdbool.h>
 #include <aul.h>
 #include <aul_svc.h>
+#include <aul_rpc_port.h>
 #include <bundle_internal.h>
 #include <ttrace.h>
 
 #include "appcore_base.h"
 #include "appcore_ui_base.h"
 #include "appcore_ui_base_private.h"
+#include "appcore_ui_plugin.h"
 
 enum app_state {
        AS_NONE,
@@ -56,6 +56,18 @@ enum app_state {
        AS_DYING,
 };
 
+enum win_status {
+       WS_NONE,
+       WS_PAUSE,
+       WS_RESUME,
+};
+
+enum visibility_type {
+       VT_NONE,
+       VT_UNOBSCURED,
+       VT_FULLY_OBSCURED,
+};
+
 typedef struct _appcore_ui_base_context {
        appcore_ui_base_ops ops;
        void *data;
@@ -64,22 +76,26 @@ typedef struct _appcore_ui_base_context {
        unsigned int hint;
        char *below_app;
        char *appid;
+       bool bg_state;
+       bool resource_reclaiming;
 
        int state;
        Ecore_Event_Handler *hshow;
        Ecore_Event_Handler *hhide;
        Ecore_Event_Handler *hvchange;
        Ecore_Event_Handler *hlower;
+       Ecore_Event_Handler *hpvchange;
+       Ecore_Event_Handler *hauxmsg;
 } appcore_ui_base_context;
 
 
-static bool b_active = false;
+static int w_status = WS_NONE;
 static bool first_launch = true;
 
 struct win_node {
        unsigned int win;
        unsigned int surf;
-       bool bfobscured;
+       int vis;
 };
 
 static GSList *g_winnode_list;
@@ -87,7 +103,109 @@ static appcore_ui_base_context __context;
 static struct wl_display *dsp;
 static struct wl_registry *reg;
 static struct tizen_policy *tz_policy;
-static bool bg_state = false;
+
+static void _wl_cb_conformant(void *data,
+               struct tizen_policy *tizen_policy,
+               struct wl_surface *surface_resource,
+               uint32_t is_conformant)
+{
+       ; // nothing to do.
+}
+
+static void _wl_cb_conformant_area(void *data,
+               struct tizen_policy *tizen_policy,
+               struct wl_surface *surface_resource,
+               uint32_t conformant_part,
+               uint32_t state,
+               int32_t x, int32_t y, int32_t w, int32_t h)
+{
+       ; // nothing to do.
+}
+
+static void _wl_cb_notification_done(void *data,
+               struct tizen_policy *tizen_policy,
+               struct wl_surface *surface,
+               int32_t level,
+               uint32_t state)
+{
+       ; // nothing to do.
+}
+
+static void _wl_cb_transient_for_done(void *data,
+               struct tizen_policy *tizen_policy,
+               uint32_t child_id)
+{
+       ; // nothing to do.
+}
+
+static void _wl_cb_scr_mode_done(void *data,
+               struct tizen_policy *tizen_policy,
+               struct wl_surface *surface,
+               uint32_t mode,
+               uint32_t state)
+{
+       ; // nothing to do.
+}
+
+static void _wl_cb_iconify_state_changed(void *data,
+               struct tizen_policy *tizen_policy,
+               struct wl_surface *surface_resource,
+               uint32_t iconified,
+               uint32_t force)
+{
+       ; // nothing to do.
+}
+
+static void _wl_cb_supported_aux_hints(void *data,
+               struct tizen_policy *tizen_policy,
+               struct wl_surface *surface_resource,
+               struct wl_array *hints,
+               uint32_t num_hints)
+{
+       ; // nothing to do.
+}
+
+static void _wl_cb_allowed_aux_hint(void *data,
+               struct tizen_policy *tizen_policy,
+               struct wl_surface *surface_resource,
+               int id)
+{
+       ; // nothing to do.
+}
+
+static void _wl_cb_aux_message(void *data,
+               struct tizen_policy *tizen_policy,
+               struct wl_surface *surface_resource,
+               const char *key,
+               const char *val,
+               struct wl_array *options)
+{
+       ; // nothing to do.
+}
+
+static void _wl_cb_conformant_region(void *data,
+               struct tizen_policy *tizen_policy,
+               struct wl_surface *surface,
+               uint32_t conformant_part,
+               uint32_t state,
+               int32_t x, int32_t y, int32_t w, int32_t h,
+               uint32_t serial)
+{
+       ; // nothing to do.
+}
+
+static const struct tizen_policy_listener _tizen_policy_listener = {
+       _wl_cb_conformant,
+       _wl_cb_conformant_area,
+       _wl_cb_notification_done,
+       _wl_cb_transient_for_done,
+       _wl_cb_scr_mode_done,
+       _wl_cb_iconify_state_changed,
+       _wl_cb_supported_aux_hints,
+       _wl_cb_allowed_aux_hint,
+       _wl_cb_aux_message,
+       _wl_cb_conformant_region,
+};
 
 static void __wl_listener_cb(void *data, struct wl_registry *reg,
                uint32_t id, const char *interface, uint32_t ver)
@@ -95,7 +213,10 @@ static void __wl_listener_cb(void *data, struct wl_registry *reg,
        if (interface && !strcmp(interface, "tizen_policy")) {
                if (!tz_policy)
                        tz_policy = wl_registry_bind(reg, id,
-                                       &tizen_policy_interface, 1);
+                                       &tizen_policy_interface, 7);
+               if (tz_policy) {
+                       tizen_policy_add_listener(tz_policy, &_tizen_policy_listener, dsp);
+               }
        }
 }
 
@@ -142,6 +263,22 @@ static Eina_Bool __stub_lower_cb(void *data, int type, void *event)
        return ECORE_CALLBACK_RENEW;
 }
 
+static Eina_Bool __stub_pre_visibility_cb(void *data, int type, void *event)
+{
+       if (__context.ops.window.pre_visibility)
+               __context.ops.window.pre_visibility(type, event, __context.data);
+
+       return ECORE_CALLBACK_RENEW;
+}
+
+static Eina_Bool __stub_aux_message_cb(void *data, int type, void *event)
+{
+       if (__context.ops.window.aux_message)
+               __context.ops.window.aux_message(type, event, __context.data);
+
+       return ECORE_CALLBACK_RENEW;
+}
+
 static void __prepare_to_suspend(void)
 {
        int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
@@ -164,9 +301,18 @@ static void __exit_from_suspend(void)
 
 static void __do_pause(void)
 {
+       int r = -1;
+
        if (__context.state == AS_RUNNING) {
-               if (__context.ops.pause)
-                       __context.ops.pause(__context.data);
+               if (__context.ops.pause) {
+                       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:PAUSE");
+                       _DBG("Call pause callback");
+                       r = __context.ops.pause(__context.data);
+                       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+               }
+
+               if (r >= 0 && __context.resource_reclaiming)
+                       appcore_base_add_suspend_timer();
 
                __context.state = AS_PAUSED;
                __prepare_to_suspend();
@@ -180,15 +326,11 @@ static void __do_resume(void)
                __exit_from_suspend();
                if (__context.ops.resume) {
                        LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]", __context.appid);
+                       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:RESUME");
+                       _DBG("Call resume callback");
                        __context.ops.resume(__context.data);
+                       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
                        LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]", __context.appid);
-                       LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]", __context.appid);
-               }
-               if ((__context.hint & APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL) &&
-                               __context.below_app) {
-                       aul_app_group_activate_below(__context.below_app);
-                       free(__context.below_app);
-                       __context.below_app = NULL;
                }
                __context.state = AS_RUNNING;
        }
@@ -254,7 +396,7 @@ static bool __add_win(unsigned int win, unsigned int surf)
 
        t->win = win;
        t->surf = surf;
-       t->bfobscured = FALSE;
+       t->vis = VT_NONE;
 
        g_winnode_list = g_slist_append(g_winnode_list, t);
 
@@ -279,13 +421,13 @@ static bool __delete_win(unsigned int win)
        return TRUE;
 }
 
-static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
+static bool __update_win(unsigned int win, unsigned int surf, int vis)
 {
        GSList *f;
        struct win_node *t;
 
-       _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
-            bfobscured);
+       _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x visibility %d\n",
+                       win, vis);
 
        f = __find_win(win);
        if (!f) {
@@ -298,14 +440,15 @@ static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
        t->win = win;
        if (surf != 0)
                t->surf = surf;
-       t->bfobscured = bfobscured;
+       if (vis != VT_NONE)
+               t->vis = vis;
 
        return TRUE;
 }
 
 static void __raise_win(void)
 {
-       Ecore_Wl_Window *win;
+       Ecore_Wl2_Window *win;
        unsigned int win_id;
 
        if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL))
@@ -314,13 +457,13 @@ static void __raise_win(void)
        win_id = __get_main_window();
 
        _DBG("Raise window: %d", win_id);
-       win = ecore_wl_window_find(win_id);
-       ecore_wl_window_activate(win);
+       win = ecore_wl2_display_window_find(ecore_wl2_connected_display_get(NULL), win_id);
+       ecore_wl2_window_activate(win);
 }
 
 static void __pause_win(void)
 {
-       Ecore_Wl_Window *win;
+       Ecore_Wl2_Window *win;
        GSList *wlist = g_winnode_list;
        struct win_node *entry = NULL;
 
@@ -333,8 +476,8 @@ static void __pause_win(void)
                entry = wlist->data;
 
                _DBG("Pause window: %d", entry->win);
-               win = ecore_wl_window_find(entry->win);
-               ecore_wl_window_iconified_set(win, EINA_TRUE);
+               win = ecore_wl2_display_window_find(ecore_wl2_connected_display_get(NULL), entry->win);
+               ecore_wl2_window_iconified_set(win, EINA_TRUE);
 
                wlist = wlist->next;
        }
@@ -394,8 +537,8 @@ static void __set_bg_state(void)
 
        tizen_policy_set_background_state(tz_policy, getpid());
        wl_display_roundtrip(dsp);
-       bg_state = true;
-       _DBG("bg state: %d", bg_state);
+       __context.bg_state = true;
+       _DBG("bg state: %d", __context.bg_state);
 }
 
 static void __unset_bg_state(void)
@@ -405,14 +548,15 @@ static void __unset_bg_state(void)
 
        tizen_policy_unset_background_state(tz_policy, getpid());
        wl_display_roundtrip(dsp);
-       bg_state = false;
-       _DBG("bg state: %d", bg_state);
+       __context.bg_state = false;
+       _DBG("bg state: %d", __context.bg_state);
 }
 
 static void __do_start(bundle *b)
 {
        const char *bg_launch;
        const char *below_app;
+       const char *rpc_port;
 
        if (__context.hint & APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL) {
                if (__context.below_app) {
@@ -433,16 +577,44 @@ static void __do_start(bundle *b)
        if (__context.hint & APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL) {
                bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
                if (bg_launch && strcmp(bg_launch, "enable") == 0) {
-                       if (!bg_state && __context.state != AS_RUNNING)
+                       if (!__context.bg_state &&
+                                       __context.state != AS_RUNNING)
                                __set_bg_state();
                } else {
-                       if (bg_state)
+                       if (__context.bg_state)
                                __unset_bg_state();
                }
        }
 
-       if (!bg_state)
-               __raise_win();
+       if (__context.hint & APPCORE_UI_BASE_HINT_WINDOW_AUTO_CONTROL) {
+               if (!__context.bg_state) {
+                       rpc_port = bundle_get_val(b, AUL_K_RPC_PORT);
+                       if (!rpc_port)
+                               __raise_win();
+               }
+       }
+}
+
+static int __is_legacy_lifecycle(void)
+{
+       static int is_legacy = -1;
+       const char *api_version;
+
+       if (is_legacy != -1)
+               return is_legacy;
+
+       api_version = getenv("TIZEN_API_VERSION");
+       if (api_version) {
+               if (strverscmp("2.4", api_version) > 0 &&
+                               strverscmp("2.2.1", api_version) < 0)
+                       is_legacy = 1;
+               else
+                       is_legacy = 0;
+       } else {
+               is_legacy = 0;
+       }
+
+       return is_legacy;
 }
 
 EXPORT_API int appcore_ui_base_on_receive(aul_type type, bundle *b)
@@ -463,8 +635,16 @@ EXPORT_API int appcore_ui_base_on_receive(aul_type type, bundle *b)
        switch (type) {
        case AUL_START:
                __do_start(b);
+               if (__context.hint & APPCORE_UI_BASE_HINT_LEGACY_CONTROL) {
+                       if (!__context.bg_state && __is_legacy_lifecycle()) {
+                               _DBG("Legacy lifecycle");
+                               __do_resume();
+                       }
+               }
                break;
        case AUL_RESUME:
+               if (__context.bg_state)
+                       __unset_bg_state();
                __raise_win();
                break;
        case AUL_TERMINATE:
@@ -486,15 +666,76 @@ EXPORT_API int appcore_ui_base_on_receive(aul_type type, bundle *b)
        return 0;
 }
 
+static void __add_ecore_events(void)
+{
+       __context.hshow = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW,
+                       __stub_show_cb, NULL);
+       if (!__context.hshow)
+               _ERR("Failed to add ECORE_WL_EVENT_WINDOW_SHOW event");
+
+       __context.hhide = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_HIDE,
+                       __stub_hide_cb, NULL);
+       if (!__context.hhide)
+               _ERR("Failed to add ECORE_WL_EVENT_WINDOW_HIDE event");
+
+       __context.hvchange = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE,
+                       __stub_visibility_cb, NULL);
+       if (!__context.hvchange)
+               _ERR("Failed to add ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE event");
+
+       __context.hlower = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_LOWER,
+                       __stub_lower_cb, NULL);
+       if (!__context.hlower)
+               _ERR("Failed to add ECORE_WL_EVENT_WINDOW_LOWER event");
+
+       __context.hpvchange = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_PRE_VISIBILITY_CHANGE,
+                       __stub_pre_visibility_cb, NULL);
+       if (!__context.hpvchange)
+               _ERR("Failed to add ECORE_WL_EVENT_WINDOW_PRE_VISIBILITY_CHANGE event");
+
+       __context.hauxmsg = ecore_event_handler_add(ECORE_WL2_EVENT_AUX_MESSAGE,
+                       __stub_aux_message_cb, NULL);
+       if (!__context.hauxmsg)
+               _ERR("Failed to add ECORE_WL2_EVENT_AUX_MESSAGE event");
+}
+
+static void __del_ecore_events(void)
+{
+       if (__context.hshow) {
+               ecore_event_handler_del(__context.hshow);
+               __context.hshow = NULL;
+       }
+
+       if (__context.hhide) {
+               ecore_event_handler_del(__context.hhide);
+               __context.hhide = NULL;
+       }
+
+       if (__context.hvchange) {
+               ecore_event_handler_del(__context.hvchange);
+               __context.hvchange = NULL;
+       }
+
+       if (__context.hlower) {
+               ecore_event_handler_del(__context.hlower);
+               __context.hlower = NULL;
+       }
+
+       if (__context.hpvchange) {
+               ecore_event_handler_del(__context.hpvchange);
+               __context.hpvchange = NULL;
+       }
+
+       if (__context.hauxmsg) {
+               ecore_event_handler_del(__context.hauxmsg);
+               __context.hauxmsg = NULL;
+       }
+}
+
 EXPORT_API int appcore_ui_base_on_create(void)
 {
+       __add_ecore_events();
        appcore_base_on_create();
-
-       __context.hshow = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __stub_show_cb, NULL);
-       __context.hhide = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __stub_hide_cb, NULL);
-       __context.hvchange = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
-                               __stub_visibility_cb, NULL);
-       __context.hlower = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __stub_lower_cb, NULL);
        __context.state = AS_CREATED;
        LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]", __context.appid);
 
@@ -504,28 +745,13 @@ EXPORT_API int appcore_ui_base_on_create(void)
 EXPORT_API int appcore_ui_base_on_terminate(void)
 {
        if (__context.state == AS_RUNNING) {
-               if (__context.ops.pause)
+               if (__context.ops.pause) {
+                       _DBG("Call pause callback");
                        __context.ops.pause(__context.data);
+               }
        }
 
        __context.state = AS_DYING;
-       if (__context.hshow)
-               ecore_event_handler_del(__context.hshow);
-       if (__context.hhide)
-               ecore_event_handler_del(__context.hhide);
-       if (__context.hvchange)
-               ecore_event_handler_del(__context.hvchange);
-       if (__context.hlower)
-               ecore_event_handler_del(__context.hlower);
-
-       __finish_wl();
-       elm_shutdown();
-
-       /* Check loader case */
-       if (getenv("AUL_LOADER_INIT")) {
-               unsetenv("AUL_LOADER_INIT");
-               elm_shutdown();
-       }
 
        appcore_base_on_terminate();
 
@@ -551,12 +777,29 @@ EXPORT_API int appcore_ui_base_on_control(bundle *b)
        return 0;
 }
 
+EXPORT_API int appcore_ui_base_on_trim_memory(void)
+{
+       return appcore_base_on_trim_memory();
+}
+
 static void __group_attach()
 {
-       static bool attached = false;
+       if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
+               return;
 
+       appcore_ui_base_group_add();
+}
+
+static void __group_lower()
+{
        if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
                return;
+       appcore_ui_base_group_remove();
+}
+
+EXPORT_API void appcore_ui_base_group_add()
+{
+       static bool attached = false;
 
        _DBG("__group_attach");
        if (attached)
@@ -572,13 +815,10 @@ static void __group_attach()
        attached = true;
 }
 
-static void __group_lower()
+EXPORT_API void appcore_ui_base_group_remove()
 {
        int exit = 0;
 
-       if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
-               return;
-
        _DBG("__group_lower");
        aul_app_group_lower(&exit);
        if (exit) {
@@ -590,7 +830,7 @@ static void __group_lower()
 
 EXPORT_API void appcore_ui_base_window_on_show(int type, void *event)
 {
-       Ecore_Wl_Event_Window_Show *ev;
+       Ecore_Wl2_Event_Window_Show *ev;
 
        ev = event;
        if (ev->parent_win != 0) {
@@ -598,12 +838,15 @@ EXPORT_API void appcore_ui_base_window_on_show(int type, void *event)
                return;
        }
 
-       _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
+       _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n",
+                       ev->win, ev->data[0]);
 
-       if (!__find_win((unsigned int)ev->win))
+       if (!__find_win((unsigned int)ev->win)) {
                __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
-       else
-               __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
+       } else {
+               __update_win((unsigned int)ev->win, (unsigned int)ev->data[0],
+                               VT_NONE);
+       }
 
        if (ev->data[0] != 0)
                __group_attach();
@@ -618,8 +861,8 @@ static bool __check_visible(void)
 
        for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
                entry = iter->data;
-               _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
-               if (entry->bfobscured == FALSE)
+               _DBG("win : %x visibility : %d\n", entry->win, entry->vis);
+               if (entry->vis == VT_UNOBSCURED)
                        return true;
        }
 
@@ -628,7 +871,7 @@ static bool __check_visible(void)
 
 EXPORT_API void appcore_ui_base_window_on_hide(int type, void *event)
 {
-       Ecore_Wl_Event_Window_Hide *ev;
+       Ecore_Wl2_Event_Window_Hide *ev;
        int bvisibility;
 
        ev = event;
@@ -637,9 +880,9 @@ EXPORT_API void appcore_ui_base_window_on_hide(int type, void *event)
        if (__find_win((unsigned int)ev->win)) {
                __delete_win((unsigned int)ev->win);
                bvisibility = __check_visible();
-               if (!bvisibility && b_active == TRUE) {
+               if (!bvisibility && w_status != WS_PAUSE) {
                        _DBG(" Go to Pasue state \n");
-                       b_active = FALSE;
+                       w_status = WS_PAUSE;
                        __do_pause();
                }
        }
@@ -647,33 +890,41 @@ EXPORT_API void appcore_ui_base_window_on_hide(int type, void *event)
 
 EXPORT_API void appcore_ui_base_window_on_lower(int type, void *event)
 {
-       Ecore_Wl_Event_Window_Lower *ev;
+       Ecore_Wl2_Event_Window_Lower *ev;
 
        ev = event;
        if (!ev)
                return;
-       _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
+       _DBG("ECORE_WL2_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
        __group_lower();
 }
 
 EXPORT_API void appcore_ui_base_window_on_visibility(int type, void *event)
 {
-       Ecore_Wl_Event_Window_Visibility_Change *ev;
+       Ecore_Wl2_Event_Window_Visibility_Change *ev;
        int bvisibility;
 
        ev = event;
-       __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
+       __update_win((unsigned int)ev->win, 0,
+                       ev->fully_obscured ? VT_FULLY_OBSCURED : VT_UNOBSCURED);
        bvisibility = __check_visible();
 
-       _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
+       _DBG("bvisibility %d, w_status %d", bvisibility, w_status);
+
+       if (bvisibility && (__context.hint & APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL) &&
+                       __context.below_app) {
+               aul_app_group_activate_below(__context.below_app);
+               free(__context.below_app);
+               __context.below_app = NULL;
+       }
 
-       if (bvisibility && b_active == FALSE) {
+       if (bvisibility && w_status != WS_RESUME) {
                _DBG(" Go to Resume state\n");
-               b_active = TRUE;
+               w_status = WS_RESUME;
                __do_resume();
-       } else if (!bvisibility && b_active == TRUE) {
+       } else if (!bvisibility && w_status != WS_PAUSE) {
                _DBG(" Go to Pasue state \n");
-               b_active = FALSE;
+               w_status = WS_PAUSE;
                __do_pause();
        } else {
                _DBG(" No change state \n");
@@ -681,15 +932,62 @@ EXPORT_API void appcore_ui_base_window_on_visibility(int type, void *event)
 
 }
 
+EXPORT_API void appcore_ui_base_window_on_pre_visibility(int type, void *event)
+{
+       Ecore_Wl2_Event_Window_Pre_Visibility_Change *ev = event;
+       bool bvisibility;
+
+       if (ev && ev->type == ECORE_WL2_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED) {
+               __update_win((unsigned int)ev->win, 0, VT_UNOBSCURED);
+               bvisibility = __check_visible();
+
+               _DBG("bvisibility %d, w_status %d", bvisibility, w_status);
+               if (bvisibility && w_status != WS_RESUME) {
+                       _DBG(" Go to Resume state\n");
+                       w_status = WS_RESUME;
+                       __do_resume();
+               }
+       }
+}
+
+EXPORT_API void appcore_ui_base_window_on_aux_message(int type, void *event)
+{
+       Ecore_Wl2_Event_Aux_Message *ev = event;
+
+       if (ev->key && !strcmp(ev->key, "dpms_wm")) {
+               if (ev->val && !strcmp(ev->val, "on")) {
+                       _DBG("Display state: on");
+                       appcore_base_set_display_state(
+                                       APPCORE_BASE_DISPLAY_STATE_ON);
+               } else if (ev->val && !strcmp(ev->val, "off")) {
+                       _DBG("Display state: off");
+                       appcore_base_set_display_state(
+                                       APPCORE_BASE_DISPLAY_STATE_OFF);
+               } else {
+                       _ERR("Unknown state: %s", ev->val);
+               }
+       }
+}
+
 EXPORT_API int appcore_ui_base_init(appcore_ui_base_ops ops, int argc, char **argv,
                void *data, unsigned int hint)
 {
-       char *hwacc;
        const char *bg_launch;
        bundle *b;
        char appid[PATH_MAX] = {0, };
+       int ret;
+
+       if (!ecore_wl2_init()) {
+               _ERR("could not wl2 init");
+               return -1;
+       }
 
-       aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+       ecore_wl2_display_connect(NULL);
+       appcore_ui_plugin_init(&ops, argc, argv, &hint);
+       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+       if (ret != 0) {
+               _ERR("Fail to get appid (%d)", getpid());
+       }
        __context.ops = ops;
        __context.data = data;
        __context.argc = argc;
@@ -697,26 +995,9 @@ EXPORT_API int appcore_ui_base_init(appcore_ui_base_ops ops, int argc, char **ar
        __context.hint = hint;
        __context.state = AS_NONE;
        __context.appid = strdup(appid);
+       __context.resource_reclaiming = true;
 
        LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", appid);
-       elm_init(argc, argv);
-
-       if (__context.hint & APPCORE_UI_BASE_HINT_HW_ACC_CONTROL) {
-               hwacc = getenv("HWACC");
-
-               if (hwacc == NULL) {
-                       _DBG("elm_config_accel_preference_set is not called");
-               } else if (strcmp(hwacc, "USE") == 0) {
-                       elm_config_accel_preference_set("hw");
-                       _DBG("elm_config_accel_preference_set : hw");
-               } else if (strcmp(hwacc, "NOT_USE") == 0) {
-                       elm_config_accel_preference_set("none");
-                       _DBG("elm_config_accel_preference_set : none");
-               } else {
-                       _DBG("elm_config_accel_preference_set is not called");
-               }
-       }
-
        if (__context.hint & APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL) {
                b = bundle_import_from_argv(argc, argv);
                if (b) {
@@ -733,9 +1014,17 @@ EXPORT_API int appcore_ui_base_init(appcore_ui_base_ops ops, int argc, char **ar
 
 EXPORT_API void appcore_ui_base_fini(void)
 {
-       appcore_base_fini();
+       __del_ecore_events();
+       __finish_wl();
+
        free(__context.appid);
        __context.appid = NULL;
+
+       appcore_base_fini();
+       appcore_ui_plugin_fini();
+       _ERR("disconnect wl2_display");
+       ecore_wl2_display_disconnect(ecore_wl2_connected_display_get(NULL));
+       ecore_wl2_shutdown();
 }
 
 EXPORT_API void appcore_ui_base_pause(void)
@@ -759,6 +1048,36 @@ EXPORT_API void appcore_ui_base_exit(void)
                __context.ops.base.exit(__context.data);
 }
 
+EXPORT_API unsigned int appcore_ui_base_get_main_window(void)
+{
+       return __get_main_window();
+}
+
+EXPORT_API unsigned int appcore_ui_base_get_main_surface(void)
+{
+       return __get_main_surface();
+}
+
+EXPORT_API int appcore_ui_base_get_hint(void)
+{
+       return __context.hint;
+}
+
+EXPORT_API bool appcore_ui_base_get_bg_state(void)
+{
+       return __context.bg_state;
+}
+
+EXPORT_API void appcore_ui_base_set_bg_state(bool bg_state)
+{
+       __context.bg_state = bg_state;
+}
+
+EXPORT_API void appcore_ui_base_set_system_resource_reclaiming(bool enable)
+{
+       __context.resource_reclaiming = enable;
+}
+
 static int __on_receive(aul_type type, bundle *b, void *data)
 {
        return appcore_ui_base_on_receive(type, b);
@@ -804,14 +1123,14 @@ static void __window_on_visibility(int type, void *event, void *data)
        appcore_ui_base_window_on_visibility(type, event);
 }
 
-static void __run(void *data)
+static void __window_on_pre_visibility(int type, void *event, void *data)
 {
-       elm_run();
+       appcore_ui_base_window_on_pre_visibility(type, event);
 }
 
-static void __exit(void *data)
+static void __window_on_aux_message(int type, void *event, void *data)
 {
-       elm_exit();
+       appcore_ui_base_window_on_aux_message(type, event);
 }
 
 EXPORT_API appcore_ui_base_ops appcore_ui_base_get_default_ops(void)
@@ -824,8 +1143,10 @@ EXPORT_API appcore_ui_base_ops appcore_ui_base_get_default_ops(void)
        ops.base.create = __on_create;
        ops.base.terminate = __on_terminate;
        ops.base.receive = __on_receive;
-       ops.base.run = __run;
-       ops.base.exit = __exit;
+       ops.base.init = NULL;
+       ops.base.finish = NULL;
+       ops.base.run = NULL;
+       ops.base.exit = NULL;
 
        ops.pause = __on_pause;
        ops.resume = __on_resume;
@@ -833,6 +1154,8 @@ EXPORT_API appcore_ui_base_ops appcore_ui_base_get_default_ops(void)
        ops.window.hide = __window_on_hide;
        ops.window.lower = __window_on_lower;
        ops.window.visibility = __window_on_visibility;
+       ops.window.pre_visibility = __window_on_pre_visibility;
+       ops.window.aux_message = __window_on_aux_message;
 
        return ops;
 }