#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 <stdbool.h>
#include <aul.h>
#include <aul_svc.h>
+#include <aul_rpc_port.h>
#include <bundle_internal.h>
#include <ttrace.h>
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;
char *below_app;
char *appid;
bool bg_state;
+ bool resource_reclaiming;
int state;
Ecore_Event_Handler *hshow;
Ecore_Event_Handler *hvchange;
Ecore_Event_Handler *hlower;
Ecore_Event_Handler *hpvchange;
+ Ecore_Event_Handler *hauxmsg;
} appcore_ui_base_context;
struct win_node {
unsigned int win;
unsigned int surf;
- bool bfobscured;
+ int vis;
};
static GSList *g_winnode_list;
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;
static void __do_pause(void)
{
+ int r = -1;
+
if (__context.state == AS_RUNNING) {
if (__context.ops.pause) {
traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:PAUSE");
- __context.ops.pause(__context.data);
+ _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();
}
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);
}
- 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;
}
t->win = win;
t->surf = surf;
- t->bfobscured = FALSE;
+ t->vis = VT_NONE;
g_winnode_list = g_slist_append(g_winnode_list, t);
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) {
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))
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;
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;
}
_DBG("bg state: %d", __context.bg_state);
}
+static void __set_app_id(void)
+{
+ if (!tz_policy && __init_wl() < 0)
+ return;
+
+ tizen_policy_set_appid(tz_policy, getpid(), __context.appid);
+ wl_display_roundtrip(dsp);
+ _DBG("set appid: %s", __context.appid);
+}
+
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) {
}
if (__context.hint & APPCORE_UI_BASE_HINT_WINDOW_AUTO_CONTROL) {
- if (!__context.bg_state)
- __raise_win();
+ if (!__context.bg_state) {
+ rpc_port = bundle_get_val(b, AUL_K_RPC_PORT);
+ if (!rpc_port)
+ __raise_win();
+ }
}
}
return 0;
}
- if (type == AUL_TERMINATE_BGAPP && __context.state != AS_PAUSED)
+ if ((type == AUL_TERMINATE_BGAPP || type == AUL_TERMINATE_BG_INST) &&
+ __context.state != AS_PAUSED)
return 0;
if (type == AUL_START)
break;
case AUL_TERMINATE:
break;
+ case AUL_TERMINATE_BG_INST:
+ case AUL_TERMINATE_INST:
case AUL_TERMINATE_BGAPP:
- _DBG("[APP %d] is paused. TERMINATE", getpid());
+ _DBG("[APP %d] TERMINATE", getpid());
__context.state = AS_DYING;
aul_status_update(STATUS_DYING);
if (__context.ops.base.exit)
static void __add_ecore_events(void)
{
- __context.hshow = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW,
+ __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_WL_EVENT_WINDOW_HIDE,
+ __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_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
+ __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_WL_EVENT_WINDOW_LOWER,
+ __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_WL_EVENT_WINDOW_PRE_VISIBILITY_CHANGE,
+ __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)
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)
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;
return 0;
}
+EXPORT_API int appcore_ui_base_on_trim_memory(void)
+{
+ return appcore_base_on_trim_memory();
+}
+
static void __group_attach()
{
if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
appcore_ui_base_group_remove();
}
-EXPORT_API void appcore_ui_base_group_add()
+EXPORT_API int appcore_ui_base_group_add()
{
static bool attached = false;
+ int ret;
_DBG("__group_attach");
if (attached)
- return;
+ return 0;
int wid = __get_main_surface();
if (wid == 0) {
_ERR("window wasn't ready");
- return;
+ return -1;
+ }
+
+ ret = aul_app_group_set_window(wid);
+ if (ret < 0) {
+ _ERR("Failed to set app group window. error(%d)", ret);
+ return ret;
}
- aul_app_group_set_window(wid);
attached = true;
+ return 0;
}
EXPORT_API void appcore_ui_base_group_remove()
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) {
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();
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;
}
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;
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, 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 && w_status != WS_RESUME) {
_DBG(" Go to Resume state\n");
w_status = WS_RESUME;
EXPORT_API void appcore_ui_base_window_on_pre_visibility(int type, void *event)
{
- Ecore_Wl_Event_Window_Pre_Visibility_Change *ev = event;
+ Ecore_Wl2_Event_Window_Pre_Visibility_Change *ev = event;
bool bvisibility;
- if (ev && ev->type == ECORE_WL_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED) {
- __update_win((unsigned int)ev->win, 0, false);
+ 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);
}
}
+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)
{
const char *bg_launch;
bundle *b;
char appid[PATH_MAX] = {0, };
+ int ret;
- ecore_wl_init(NULL);
+ if (!ecore_wl2_init()) {
+ _ERR("could not wl2 init");
+ return -1;
+ }
+ ecore_wl2_display_connect(NULL);
appcore_ui_plugin_init(&ops, argc, argv, &hint);
- aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+ 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;
__context.hint = hint;
__context.state = AS_NONE;
__context.appid = strdup(appid);
+ __context.resource_reclaiming = true;
LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", appid);
if (__context.hint & APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL) {
}
}
+ __set_app_id();
+
return appcore_base_init(ops.base, argc, argv, data);
}
appcore_base_fini();
appcore_ui_plugin_fini();
- ecore_wl_shutdown();
+ _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)
__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);
appcore_ui_base_window_on_pre_visibility(type, event);
}
+static void __window_on_aux_message(int type, void *event, void *data)
+{
+ appcore_ui_base_window_on_aux_message(type, event);
+}
+
EXPORT_API appcore_ui_base_ops appcore_ui_base_get_default_ops(void)
{
appcore_ui_base_ops ops;
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;
}