2 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <sys/types.h>
18 #include <sys/socket.h>
28 #include <Ecore_Wayland.h>
29 #include <wayland-client.h>
30 #include <wayland-tbm-client.h>
31 #include <tizen-extension-client-protocol.h>
33 #include <X11/Xatom.h>
39 #include <Ecore_Evas.h>
40 #include <Ecore_Input_Evas.h>
41 #include <Elementary.h>
42 #include <glib-object.h>
49 #include <bundle_internal.h>
52 #include "appcore-internal.h"
53 #include "appcore-efl.h"
54 #include <system_info.h>
57 static bool resource_reclaiming = TRUE;
58 static int tmp_val = 0;
64 Ecore_Event_Handler *hshow;
65 Ecore_Event_Handler *hhide;
66 Ecore_Event_Handler *hvchange;
68 Ecore_Event_Handler *hlower;
70 Ecore_Event_Handler *hcmsg; /* WM_ROTATE */
72 Ecore_Timer *mftimer; /* Ecore Timer for memory flushing */
74 struct appcore *app_core;
75 void (*prepare_to_suspend) (void *data);
76 void (*exit_from_suspend) (void *data);
77 struct appcore_ops *ops;
78 void (*mfcb) (void); /* Memory Flushing Callback */
83 int (*rot_cb) (void *event_info, enum appcore_rm, void *);
85 enum appcore_rm rot_mode;
89 static struct ui_priv priv;
91 static const char *_ae_name[AE_MAX] = {
92 [AE_UNKNOWN] = "UNKNOWN",
93 [AE_CREATE] = "CREATE",
94 [AE_TERMINATE] = "TERMINATE",
96 [AE_RESUME] = "RESUME",
98 [AE_LOWMEM_POST] = "LOWMEM_POST",
99 [AE_MEM_FLUSH] = "MEM_FLUSH",
100 [AE_UPDATE_REQUESTED] = "UPDATE_REQUESTED",
103 static const char *_as_name[] = {
105 [AS_CREATED] = "CREATED",
106 [AS_RUNNING] = "RUNNING",
107 [AS_PAUSED] = "PAUSED",
108 [AS_DYING] = "DYING",
111 static bool b_active = FALSE;
112 static bool first_launch = TRUE;
123 static struct ui_wm_rotate wm_rotate;
125 static Eina_Bool __visibility_cb(void *data, int type, void *event);
126 static GSList *g_winnode_list;
128 static struct wl_display *dsp;
129 static struct wl_registry *reg;
130 static struct tizen_policy *tz_policy;
131 static bool bg_state = false;
133 static void __wl_listener_cb(void *data, struct wl_registry *reg,
134 uint32_t id, const char *interface, uint32_t ver)
136 if (interface && !strcmp(interface, "tizen_policy")) {
138 tz_policy = wl_registry_bind(reg, id,
139 &tizen_policy_interface, 1);
143 static void __wl_listener_remove_cb(void *data, struct wl_registry *reg,
149 static const struct wl_registry_listener reg_listener = {
151 __wl_listener_remove_cb
154 static int __init_wl(void)
156 _DBG("initialize wayland");
157 dsp = wl_display_connect(NULL);
159 _ERR("Failed to connect wl display");
163 reg = wl_display_get_registry(dsp);
165 _ERR("Failed to get registry");
166 wl_display_disconnect(dsp);
170 wl_registry_add_listener(reg, ®_listener, NULL);
171 wl_display_roundtrip(dsp);
174 _ERR("Failed to get tizen policy interface");
175 wl_registry_destroy(reg);
176 wl_display_disconnect(dsp);
183 static void __finish_wl(void)
186 tizen_policy_destroy(tz_policy);
191 wl_registry_destroy(reg);
196 wl_display_disconnect(dsp);
201 static void __set_bg_state(void)
206 tizen_policy_set_background_state(tz_policy, getpid());
207 wl_display_roundtrip(dsp);
209 _DBG("bg state: %d", bg_state);
212 static void __unset_bg_state(void)
217 tizen_policy_unset_background_state(tz_policy, getpid());
218 wl_display_roundtrip(dsp);
220 _DBG("bg state: %d", bg_state);
224 static void __appcore_efl_prepare_to_suspend(void *data)
226 struct ui_priv *ui = (struct ui_priv *)data;
227 struct sys_op *op = NULL;
228 int suspend = APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
230 if (ui->app_core && !ui->app_core->allowed_bg && !ui->app_core->suspended_state) {
231 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
233 op->func((void *)&suspend, op->data); /* calls c-api handler */
235 ui->app_core->suspended_state = true;
237 _DBG("[__SUSPEND__]");
240 static void __appcore_efl_exit_from_suspend(void *data)
242 struct ui_priv *ui = (struct ui_priv *)data;
243 struct sys_op *op = NULL;
244 int suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
246 if (ui->app_core && !ui->app_core->allowed_bg && ui->app_core->suspended_state) {
247 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
249 op->func((void *)&suspend, op->data); /* calls c-api handler */
251 ui->app_core->suspended_state = false;
253 _DBG("[__SUSPEND__]");
256 static void __appcore_efl_update_requested(void *data)
258 struct ui_priv *ui = (struct ui_priv *)data;
263 op = &ui->app_core->sops[SE_UPDATE_REQUESTED];
265 op->func((void *)&dummy, op->data);
267 _DBG("[__UPDATE_REQUESTED__]");
270 #if defined(MEMORY_FLUSH_ACTIVATE)
271 static Eina_Bool __appcore_memory_flush_cb(void *data)
273 struct ui_priv *ui = (struct ui_priv *)data;
275 appcore_flush_memory();
279 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui && ui->prepare_to_suspend) {
280 _DBG("[__SUSPEND__] flush case");
281 ui->prepare_to_suspend(ui);
284 return ECORE_CALLBACK_CANCEL;
287 static int __appcore_low_memory_post_cb(struct ui_priv *ui)
289 if (ui->state == AS_PAUSED)
290 appcore_flush_memory();
297 static void __appcore_timer_add(struct ui_priv *ui)
299 ui->mftimer = ecore_timer_add(5, __appcore_memory_flush_cb, ui);
302 static void __appcore_timer_del(struct ui_priv *ui)
305 ecore_timer_del(ui->mftimer);
312 static int __appcore_low_memory_post_cb(ui_priv *ui)
317 #define __appcore_timer_add(ui) 0
318 #define __appcore_timer_del(ui) 0
322 static void __appcore_efl_memory_flush_cb(void)
324 _DBG("[APP %d] __appcore_efl_memory_flush_cb()", _pid);
325 elm_cache_all_flush();
328 static void wl_raise_win(void)
330 Ecore_Wl_Window *win;
331 unsigned int win_id = appcore_get_main_window();
333 _DBG("Raise window: %d", win_id);
334 win = ecore_wl_window_find(win_id);
335 ecore_wl_window_activate(win);
338 static void wl_pause_win(void)
340 Ecore_Wl_Window *win;
341 GSList *wlist = g_winnode_list;
342 struct win_node *entry = NULL;
344 _DBG("Pause window");
349 _DBG("Pause window: %d", entry->win);
350 win = ecore_wl_window_find(entry->win);
351 ecore_wl_window_iconified_set(win, EINA_TRUE);
359 static void __do_app(enum app_event event, void *data, bundle * b)
362 struct ui_priv *ui = data;
363 const char *below_app;
364 const char *bg_launch;
366 _DBG("[APP %d] Event: %d", _pid, event);
367 _ret_if(ui == NULL || event >= AE_MAX);
368 _DBG("[APP %d] Event: %s State: %s", _pid, _ae_name[event],
369 _as_name[ui->state]);
371 if (event == AE_MEM_FLUSH) {
376 if (event == AE_LOWMEM_POST) {
377 if (__appcore_low_memory_post_cb(ui) == 0)
381 if (!(ui->state == AS_PAUSED && event == AE_PAUSE))
382 __appcore_timer_del(ui);
384 if (ui->state == AS_DYING) {
385 _ERR("Skip the event in dying state");
389 if (event == AE_TERMINATE) {
390 _DBG("[APP %d] TERMINATE", _pid);
392 aul_status_update(STATUS_DYING);
396 if (event == AE_RAISE) {
398 x_raise_win(getpid());
399 #elif defined(WAYLAND)
405 if (event == AE_LOWER) {
407 x_pause_win(getpid());
408 #elif defined(WAYLAND)
414 _ret_if(ui->ops == NULL);
418 _DBG("[APP %d] RESET", _pid);
419 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]", ui->name);
423 ui->below_app = NULL;
426 below_app = bundle_get_val(b, AUL_SVC_K_RELOCATE_BELOW);
428 ui->below_app = strdup(below_app);
429 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui->exit_from_suspend) {
430 _DBG("[__SUSPEND__] reset case");
431 ui->exit_from_suspend(ui);
434 if (ui->ops->reset) {
435 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
437 r = ui->ops->reset(b, ui->ops->data);
438 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
440 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]", ui->name);
443 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui->app_core->allowed_bg)
444 __appcore_timer_add(ui);
445 first_launch = FALSE;
447 _INFO("[APP %d] App already running, raise the window", _pid);
449 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
450 if (!bg_launch || strcmp(bg_launch, "enable"))
454 x_raise_win(getpid());
459 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
463 if (ui->state == AS_RUNNING) {
464 _DBG("[APP %d] PAUSE", _pid);
465 if (ui->ops->pause) {
466 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
468 r = ui->ops->pause(ui->ops->data);
469 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
471 ui->state = AS_PAUSED;
472 if (r >= 0 && resource_reclaiming == TRUE)
473 __appcore_timer_add(ui);
474 else if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && r >= 0 && resource_reclaiming == FALSE
475 && ui->prepare_to_suspend) {
476 _DBG("[__SUSPEND__] pause case");
477 ui->prepare_to_suspend(ui);
480 /* TODO : rotation stop */
481 /* r = appcore_pause_rotation_cb(); */
482 aul_status_update(STATUS_BG);
485 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
487 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
488 if (ui->exit_from_suspend) {
489 _DBG("[__SUSPEND__] resume case");
490 ui->exit_from_suspend(ui);
492 if (ui->app_core->allowed_bg)
493 __appcore_timer_del(ui);
496 if (ui->state == AS_PAUSED || ui->state == AS_CREATED) {
497 _DBG("[APP %d] RESUME", _pid);
499 if (ui->ops->resume) {
500 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
502 ui->ops->resume(ui->ops->data);
503 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
505 ui->state = AS_RUNNING;
508 aul_app_group_activate_below(ui->below_app);
510 ui->below_app = NULL;
513 /*TODO : rotation start*/
514 /* r = appcore_resume_rotation_cb(); */
515 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]",
517 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
519 aul_status_update(STATUS_VISIBLE);
521 case AE_TERMINATE_BGAPP:
522 if (ui->state == AS_PAUSED) {
523 _DBG("[APP %d] is paused. TERMINATE", _pid);
524 ui->state = AS_DYING;
525 aul_status_update(STATUS_DYING);
527 } else if (ui->state == AS_RUNNING) {
528 _DBG("[APP %d] is running.", _pid);
530 _DBG("[APP %d] is another state", _pid);
533 case AE_UPDATE_REQUESTED:
534 __appcore_efl_update_requested(ui);
542 static struct ui_ops efl_ops = {
547 static bool __check_visible(void)
550 struct win_node *entry = NULL;
552 _DBG("[EVENT_TEST][EVENT] __check_visible\n");
554 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
556 _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
557 if (entry->bfobscured == FALSE)
564 static GSList *__find_win(unsigned int win)
569 for (iter = g_winnode_list; iter; iter = g_slist_next(iter)) {
571 if (t && t->win == win)
579 static bool __add_win(unsigned int win)
584 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
589 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
593 t = calloc(1, sizeof(struct win_node));
598 t->bfobscured = FALSE;
600 g_winnode_list = g_slist_append(g_winnode_list, t);
604 #elif defined(WAYLAND)
605 static bool __add_win(unsigned int win, unsigned int surf)
610 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
615 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
619 t = calloc(1, sizeof(struct win_node));
625 t->bfobscured = FALSE;
627 g_winnode_list = g_slist_append(g_winnode_list, t);
633 static bool __delete_win(unsigned int win)
640 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
646 g_winnode_list = g_slist_delete_link(g_winnode_list, f);
652 static bool __update_win(unsigned int win, bool bfobscured)
657 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
663 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
667 t = (struct win_node *)f->data;
669 t->bfobscured = bfobscured;
673 #elif defined(WAYLAND)
674 static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
679 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
685 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
689 t = (struct win_node *)f->data;
693 t->bfobscured = bfobscured;
701 static Ecore_X_Atom _WM_WINDOW_ROTATION_SUPPORTED = 0;
702 static Ecore_X_Atom _WM_WINDOW_ROTATION_CHANGE_REQUEST = 0;
704 static int __check_wm_rotation_support(void)
706 _DBG("Disable window manager rotation");
709 Ecore_X_Window root, win, win2;
712 if (!_WM_WINDOW_ROTATION_SUPPORTED) {
713 _WM_WINDOW_ROTATION_SUPPORTED =
714 ecore_x_atom_get("_E_WINDOW_ROTATION_SUPPORTED");
717 if (!_WM_WINDOW_ROTATION_CHANGE_REQUEST) {
718 _WM_WINDOW_ROTATION_CHANGE_REQUEST =
719 ecore_x_atom_get("_E_WINDOW_ROTATION_CHANGE_REQUEST");
722 root = ecore_x_window_root_first_get();
723 ret = ecore_x_window_prop_xid_get(root,
724 _WM_WINDOW_ROTATION_SUPPORTED,
727 if ((ret == 1) && (win)) {
728 ret = ecore_x_window_prop_xid_get(win,
729 _WM_WINDOW_ROTATION_SUPPORTED,
732 if ((ret == 1) && (win2 == win))
739 static void __set_wm_rotation_support(unsigned int win, unsigned int set)
742 struct win_node *entry = NULL;
745 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
748 ecore_x_window_prop_card32_set(entry->win,
749 _WM_WINDOW_ROTATION_SUPPORTED,
754 ecore_x_window_prop_card32_set(win,
755 _WM_WINDOW_ROTATION_SUPPORTED,
761 static Eina_Bool __show_cb(void *data, int type, void *event)
764 Ecore_Wl_Event_Window_Show *ev;
767 if (ev->parent_win != 0) {
768 /* This is child window. Skip!!! */
769 return ECORE_CALLBACK_PASS_ON;
772 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
774 if (!__find_win((unsigned int)ev->win))
775 __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
777 __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
780 Ecore_X_Event_Window_Show *ev;
784 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x\n", ev->win);
786 if (!__find_win((unsigned int)ev->win)) {
788 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
789 __set_wm_rotation_support(ev->win, 1);
790 __add_win((unsigned int)ev->win);
792 __update_win((unsigned int)ev->win, FALSE);
796 appcore_group_attach();
797 return ECORE_CALLBACK_RENEW;
800 static Eina_Bool __hide_cb(void *data, int type, void *event)
803 Ecore_Wl_Event_Window_Hide *ev;
805 Ecore_X_Event_Window_Hide *ev;
811 _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
813 if (__find_win((unsigned int)ev->win)) {
814 __delete_win((unsigned int)ev->win);
815 bvisibility = __check_visible();
816 if (!bvisibility && b_active == TRUE) {
817 _DBG(" Go to Pasue state \n");
819 __do_app(AE_PAUSE, data, NULL);
823 return ECORE_CALLBACK_RENEW;
827 static Eina_Bool __lower_cb(void *data, int type, void *event)
829 Ecore_Wl_Event_Window_Lower *ev;
831 if (!ev) return ECORE_CALLBACK_RENEW;
832 _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
833 appcore_group_lower();
834 return ECORE_CALLBACK_RENEW;
838 static Eina_Bool __visibility_cb(void *data, int type, void *event)
841 Ecore_Wl_Event_Window_Visibility_Change *ev;
844 __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
846 Ecore_X_Event_Window_Visibility_Change *ev;
851 __update_win((unsigned int)ev->win, ev->fully_obscured);
853 bvisibility = __check_visible();
855 _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
857 if (bvisibility && b_active == FALSE) {
858 _DBG(" Go to Resume state\n");
860 __do_app(AE_RESUME, data, NULL);
862 } else if (!bvisibility && b_active == TRUE) {
863 _DBG(" Go to Pasue state \n");
865 __do_app(AE_PAUSE, data, NULL);
867 _DBG(" No change state \n");
869 return ECORE_CALLBACK_RENEW;
875 static Eina_Bool __cmsg_cb(void *data, int type, void *event)
877 struct ui_priv *ui = (struct ui_priv *)data;
878 Ecore_X_Event_Client_Message *e = event;
881 return ECORE_CALLBACK_PASS_ON;
884 return ECORE_CALLBACK_PASS_ON;
886 if (e->message_type == _WM_WINDOW_ROTATION_CHANGE_REQUEST) {
887 if ((ui->wm_rot_supported == 0)
888 || (ui->rot_started == 0)
889 || (ui->rot_cb == NULL)) {
890 return ECORE_CALLBACK_PASS_ON;
894 switch (e->data.l[1]) {
896 rm = APPCORE_RM_PORTRAIT_NORMAL;
899 rm = APPCORE_RM_LANDSCAPE_REVERSE;
902 rm = APPCORE_RM_PORTRAIT_REVERSE;
905 rm = APPCORE_RM_LANDSCAPE_NORMAL;
908 rm = APPCORE_RM_UNKNOWN;
914 if (APPCORE_RM_UNKNOWN != rm)
915 ui->rot_cb((void *)&rm, rm, ui->rot_cb_data);
918 return ECORE_CALLBACK_PASS_ON;
922 static void __add_climsg_cb(struct ui_priv *ui)
927 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, ui);
929 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, ui);
931 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
932 __visibility_cb, ui);
934 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER,
938 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, __show_cb, ui);
940 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE, __hide_cb, ui);
942 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
943 __visibility_cb, ui);
945 /* Add client message callback for WM_ROTATE */
946 if (!__check_wm_rotation_support()) {
947 ui->hcmsg = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
949 ui->wm_rot_supported = 1;
950 appcore_set_wm_rotation(&wm_rotate);
955 static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
959 struct appcore *ac = NULL;
961 const char *bg_launch;
963 if (argc == NULL || argv == NULL) {
964 _ERR("argc/argv is NULL");
969 #if !(GLIB_CHECK_VERSION(2, 36, 0))
972 elm_init(*argc, *argv);
974 hwacc = getenv("HWACC");
976 _DBG("elm_config_accel_preference_set is not called");
977 } else if (strcmp(hwacc, "USE") == 0) {
978 elm_config_accel_preference_set("hw");
979 _DBG("elm_config_accel_preference_set : hw");
980 } else if (strcmp(hwacc, "NOT_USE") == 0) {
981 elm_config_accel_preference_set("none");
982 _DBG("elm_config_accel_preference_set : none");
984 _DBG("elm_config_accel_preference_set is not called");
987 r = appcore_init(ui->name, &efl_ops, *argc, *argv);
988 _retv_if(r == -1, -1);
990 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
991 appcore_get_app_core(&ac);
993 SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: #%x", ac);
996 b = bundle_import_from_argv(*argc, *argv);
998 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
999 if (bg_launch && strcmp(bg_launch, "enable") == 0)
1005 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
1006 if (ui->ops && ui->ops->create) {
1007 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
1008 r = ui->ops->create(ui->ops->data);
1009 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1011 _ERR("create() return error");
1013 if (ui->ops && ui->ops->terminate) {
1014 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1015 "APPCORE:TERMINATE");
1016 ui->ops->terminate(ui->ops->data);
1017 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1022 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
1025 ui->state = AS_CREATED;
1027 __add_climsg_cb(ui);
1032 static void __after_loop(struct ui_priv *ui)
1034 appcore_unset_rotation_cb();
1037 if (ui->state == AS_RUNNING) {
1038 _DBG("[APP %d] PAUSE before termination", _pid);
1039 if (ui->ops && ui->ops->pause) {
1040 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1042 ui->ops->pause(ui->ops->data);
1043 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1047 if (ui->ops && ui->ops->terminate) {
1048 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
1049 ui->ops->terminate(ui->ops->data);
1050 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1053 ui->state = AS_DYING;
1056 ecore_event_handler_del(ui->hshow);
1058 ecore_event_handler_del(ui->hhide);
1060 ecore_event_handler_del(ui->hvchange);
1061 #if defined(WAYLAND)
1063 ecore_event_handler_del(ui->hlower);
1066 __appcore_timer_del(ui);
1070 /* Check loader case */
1071 if (getenv("AUL_LOADER_INIT")) {
1072 unsetenv("AUL_LOADER_INIT");
1077 static int __set_data(struct ui_priv *ui, const char *name,
1078 struct appcore_ops *ops)
1081 _ERR("Mainloop already started");
1082 errno = EINPROGRESS;
1086 if (name == NULL || name[0] == '\0') {
1087 _ERR("Invalid name");
1093 _ERR("ops is NULL");
1098 ui->name = strdup(name);
1099 _retv_if(ui->name == NULL, -1);
1102 ui->mfcb = __appcore_efl_memory_flush_cb;
1106 ui->wm_rot_supported = 0;
1107 ui->rot_started = 0;
1109 ui->rot_cb_data = NULL;
1110 ui->rot_mode = APPCORE_RM_UNKNOWN;
1112 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
1113 ui->app_core = NULL;
1114 ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
1115 ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
1121 static void __unset_data(struct ui_priv *ui)
1124 free((void *)ui->name);
1126 memset(ui, 0, sizeof(struct ui_priv));
1131 static int __wm_set_rotation_cb(int (*cb) (void *event_info, enum appcore_rm, void *), void *data)
1138 if ((priv.wm_rot_supported) && (0 == priv.rot_started))
1139 __set_wm_rotation_support(0, 1);
1142 priv.rot_cb_data = data;
1143 priv.rot_started = 1;
1148 static int __wm_unset_rotation_cb(void)
1150 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
1151 __set_wm_rotation_support(0, 0);
1154 priv.rot_cb_data = NULL;
1155 priv.rot_started = 0;
1160 static int __wm_get_rotation_state(enum appcore_rm *curr)
1167 *curr = priv.rot_mode;
1172 static int __wm_pause_rotation_cb(void)
1174 if ((priv.rot_started == 1) && (priv.wm_rot_supported))
1175 __set_wm_rotation_support(0, 0);
1177 priv.rot_started = 0;
1182 static int __wm_resume_rotation_cb(void)
1184 if ((priv.rot_started == 0) && (priv.wm_rot_supported))
1185 __set_wm_rotation_support(0, 1);
1187 priv.rot_started = 1;
1192 static struct ui_wm_rotate wm_rotate = {
1193 __wm_set_rotation_cb,
1194 __wm_unset_rotation_cb,
1195 __wm_get_rotation_state,
1196 __wm_pause_rotation_cb,
1197 __wm_resume_rotation_cb
1201 EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
1202 struct appcore_ops *ops)
1206 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
1208 r = __set_data(&priv, name, ops);
1209 _retv_if(r == -1, -1);
1211 r = __before_loop(&priv, argc, argv);
1213 aul_status_update(STATUS_DYING);
1214 __unset_data(&priv);
1221 EXPORT_API void appcore_efl_fini(void)
1223 aul_status_update(STATUS_DYING);
1225 __after_loop(&priv);
1227 __unset_data(&priv);
1230 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
1231 struct appcore_ops *ops)
1235 r = appcore_efl_init(name, argc, argv, ops);
1236 _retv_if(r == -1, -1);
1245 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
1247 resource_reclaiming = enable;
1252 EXPORT_API int appcore_set_app_state(int state)
1261 EXPORT_API int appcore_set_preinit_window_name(const char *win_name)
1264 void *preinit_window = NULL;
1265 const Evas *e = NULL;
1268 _ERR("invalid parameter");
1272 preinit_window = elm_win_precreated_object_get();
1273 if (!preinit_window) {
1274 _ERR("Failed to get preinit window");
1278 e = evas_object_evas_get((const Evas_Object *)preinit_window);
1280 Ecore_Evas *ee = ecore_evas_ecore_evas_get(e);
1282 ecore_evas_name_class_set(ee, win_name, win_name);
1290 EXPORT_API unsigned int appcore_get_main_window(void)
1292 struct win_node *entry = NULL;
1294 if (g_winnode_list != NULL) {
1295 entry = g_winnode_list->data;
1296 return (unsigned int) entry->win;
1302 #if defined(WAYLAND)
1303 EXPORT_API unsigned int appcore_get_main_surface(void)
1305 struct win_node *entry = NULL;
1307 if (g_winnode_list != NULL) {
1308 entry = g_winnode_list->data;
1309 return (unsigned int) entry->surf;
1316 tizen_profile_t _get_tizen_profile()
1318 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
1319 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
1323 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
1324 switch (*profileName) {
1327 profile = TIZEN_PROFILE_MOBILE;
1331 profile = TIZEN_PROFILE_WEARABLE;
1335 profile = TIZEN_PROFILE_TV;
1339 profile = TIZEN_PROFILE_IVI;
1341 default: // common or unTIZEN_nown ==> ALL ARE COMMON.
1342 profile = TIZEN_PROFILE_COMMON;