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;
90 static struct ui_priv priv;
92 static const char *_ae_name[AE_MAX] = {
93 [AE_UNKNOWN] = "UNKNOWN",
94 [AE_CREATE] = "CREATE",
95 [AE_TERMINATE] = "TERMINATE",
97 [AE_RESUME] = "RESUME",
99 [AE_LOWMEM_POST] = "LOWMEM_POST",
100 [AE_MEM_FLUSH] = "MEM_FLUSH",
101 [AE_UPDATE_REQUESTED] = "UPDATE_REQUESTED",
104 static const char *_as_name[] = {
106 [AS_CREATED] = "CREATED",
107 [AS_RUNNING] = "RUNNING",
108 [AS_PAUSED] = "PAUSED",
109 [AS_DYING] = "DYING",
112 static bool b_active = FALSE;
113 static bool first_launch = TRUE;
124 static struct ui_wm_rotate wm_rotate;
126 static Eina_Bool __visibility_cb(void *data, int type, void *event);
127 static GSList *g_winnode_list;
129 static struct wl_display *dsp;
130 static struct wl_registry *reg;
131 static struct tizen_policy *tz_policy;
132 static bool bg_state = false;
134 static void __wl_listener_cb(void *data, struct wl_registry *reg,
135 uint32_t id, const char *interface, uint32_t ver)
137 if (interface && !strcmp(interface, "tizen_policy")) {
139 tz_policy = wl_registry_bind(reg, id,
140 &tizen_policy_interface, 1);
144 static void __wl_listener_remove_cb(void *data, struct wl_registry *reg,
150 static const struct wl_registry_listener reg_listener = {
152 __wl_listener_remove_cb
155 static int __init_wl(void)
157 _DBG("initialize wayland");
158 dsp = wl_display_connect(NULL);
160 _ERR("Failed to connect wl display");
164 reg = wl_display_get_registry(dsp);
166 _ERR("Failed to get registry");
167 wl_display_disconnect(dsp);
171 wl_registry_add_listener(reg, ®_listener, NULL);
172 wl_display_roundtrip(dsp);
175 _ERR("Failed to get tizen policy interface");
176 wl_registry_destroy(reg);
177 wl_display_disconnect(dsp);
184 static void __finish_wl(void)
187 tizen_policy_destroy(tz_policy);
192 wl_registry_destroy(reg);
197 wl_display_disconnect(dsp);
202 static void __set_bg_state(void)
207 tizen_policy_set_background_state(tz_policy, getpid());
208 wl_display_roundtrip(dsp);
210 _DBG("bg state: %d", bg_state);
213 static void __unset_bg_state(void)
218 tizen_policy_unset_background_state(tz_policy, getpid());
219 wl_display_roundtrip(dsp);
221 _DBG("bg state: %d", bg_state);
225 static void __appcore_efl_prepare_to_suspend(void *data)
227 struct ui_priv *ui = (struct ui_priv *)data;
228 struct sys_op *op = NULL;
229 int suspend = APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
231 if (ui->app_core && !ui->app_core->allowed_bg && !ui->app_core->suspended_state) {
232 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
234 op->func((void *)&suspend, op->data); /* calls c-api handler */
236 ui->app_core->suspended_state = true;
238 _DBG("[__SUSPEND__]");
241 static void __appcore_efl_exit_from_suspend(void *data)
243 struct ui_priv *ui = (struct ui_priv *)data;
244 struct sys_op *op = NULL;
245 int suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
247 if (ui->app_core && !ui->app_core->allowed_bg && ui->app_core->suspended_state) {
248 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
250 op->func((void *)&suspend, op->data); /* calls c-api handler */
252 ui->app_core->suspended_state = false;
254 _DBG("[__SUSPEND__]");
257 static void __appcore_efl_update_requested(void *data)
259 struct ui_priv *ui = (struct ui_priv *)data;
264 op = &ui->app_core->sops[SE_UPDATE_REQUESTED];
266 op->func((void *)&dummy, op->data);
268 _DBG("[__UPDATE_REQUESTED__]");
271 #if defined(MEMORY_FLUSH_ACTIVATE)
272 static Eina_Bool __appcore_memory_flush_cb(void *data)
274 struct ui_priv *ui = (struct ui_priv *)data;
276 appcore_flush_memory();
280 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui && ui->prepare_to_suspend) {
281 _DBG("[__SUSPEND__] flush case");
282 ui->prepare_to_suspend(ui);
285 return ECORE_CALLBACK_CANCEL;
288 static int __appcore_low_memory_post_cb(struct ui_priv *ui)
290 if (ui->state == AS_PAUSED)
291 appcore_flush_memory();
298 static void __appcore_timer_add(struct ui_priv *ui)
300 ui->mftimer = ecore_timer_add(5, __appcore_memory_flush_cb, ui);
303 static void __appcore_timer_del(struct ui_priv *ui)
306 ecore_timer_del(ui->mftimer);
313 static int __appcore_low_memory_post_cb(ui_priv *ui)
318 #define __appcore_timer_add(ui) 0
319 #define __appcore_timer_del(ui) 0
323 static void __appcore_efl_memory_flush_cb(void)
325 _DBG("[APP %d] __appcore_efl_memory_flush_cb()", _pid);
326 elm_cache_all_flush();
329 static void wl_raise_win(void)
331 Ecore_Wl_Window *win;
332 unsigned int win_id = appcore_get_main_window();
334 _DBG("Raise window: %d", win_id);
335 win = ecore_wl_window_find(win_id);
336 ecore_wl_window_activate(win);
339 static void wl_pause_win(void)
341 Ecore_Wl_Window *win;
342 GSList *wlist = g_winnode_list;
343 struct win_node *entry = NULL;
345 _DBG("Pause window");
350 _DBG("Pause window: %d", entry->win);
351 win = ecore_wl_window_find(entry->win);
352 ecore_wl_window_iconified_set(win, EINA_TRUE);
360 static void __do_app(enum app_event event, void *data, bundle * b)
363 struct ui_priv *ui = data;
364 const char *below_app;
365 const char *bg_launch;
367 _DBG("[APP %d] Event: %d", _pid, event);
368 _ret_if(ui == NULL || event >= AE_MAX);
369 _DBG("[APP %d] Event: %s State: %s", _pid, _ae_name[event],
370 _as_name[ui->state]);
372 if (event == AE_MEM_FLUSH) {
377 if (event == AE_LOWMEM_POST) {
378 if (__appcore_low_memory_post_cb(ui) == 0)
382 if (!(ui->state == AS_PAUSED && event == AE_PAUSE))
383 __appcore_timer_del(ui);
385 if (ui->state == AS_DYING) {
386 _ERR("Skip the event in dying state");
390 if (event == AE_TERMINATE) {
391 _DBG("[APP %d] TERMINATE", _pid);
393 aul_status_update(STATUS_DYING);
397 if (event == AE_RAISE) {
399 x_raise_win(getpid());
400 #elif defined(WAYLAND)
406 if (event == AE_LOWER) {
408 x_pause_win(getpid());
409 #elif defined(WAYLAND)
415 _ret_if(ui->ops == NULL);
419 _DBG("[APP %d] RESET", _pid);
420 if (ui->pending_data)
421 bundle_free(ui->pending_data);
422 ui->pending_data = bundle_dup(b);
423 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]", ui->name);
427 ui->below_app = NULL;
430 below_app = bundle_get_val(b, AUL_SVC_K_RELOCATE_BELOW);
432 ui->below_app = strdup(below_app);
433 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui->exit_from_suspend) {
434 _DBG("[__SUSPEND__] reset case");
435 ui->exit_from_suspend(ui);
438 if (ui->ops->reset) {
439 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
441 r = ui->ops->reset(b, ui->ops->data);
442 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
444 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]", ui->name);
447 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui->app_core->allowed_bg)
448 __appcore_timer_add(ui);
449 first_launch = FALSE;
451 _INFO("[APP %d] App already running, raise the window", _pid);
453 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
454 if (!bg_launch || strcmp(bg_launch, "enable"))
458 x_raise_win(getpid());
463 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
467 if (ui->state == AS_RUNNING) {
468 _DBG("[APP %d] PAUSE", _pid);
469 if (ui->ops->pause) {
470 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
472 r = ui->ops->pause(ui->ops->data);
473 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
475 ui->state = AS_PAUSED;
476 if (r >= 0 && resource_reclaiming == TRUE)
477 __appcore_timer_add(ui);
478 else if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && r >= 0 && resource_reclaiming == FALSE
479 && ui->prepare_to_suspend) {
480 _DBG("[__SUSPEND__] pause case");
481 ui->prepare_to_suspend(ui);
484 /* TODO : rotation stop */
485 /* r = appcore_pause_rotation_cb(); */
486 aul_status_update(STATUS_BG);
489 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
491 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
492 if (ui->exit_from_suspend) {
493 _DBG("[__SUSPEND__] resume case");
494 ui->exit_from_suspend(ui);
496 if (ui->app_core->allowed_bg)
497 __appcore_timer_del(ui);
500 if (ui->state == AS_PAUSED || ui->state == AS_CREATED) {
501 _DBG("[APP %d] RESUME", _pid);
503 if (ui->state == AS_CREATED) {
504 bundle_free(ui->pending_data);
505 ui->pending_data = NULL;
508 if (ui->ops->resume) {
509 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
511 ui->ops->resume(ui->ops->data);
512 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
514 ui->state = AS_RUNNING;
517 aul_app_group_activate_below(ui->below_app);
519 ui->below_app = NULL;
522 /*TODO : rotation start*/
523 /* r = appcore_resume_rotation_cb(); */
524 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]",
526 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
528 aul_status_update(STATUS_VISIBLE);
530 case AE_TERMINATE_BGAPP:
531 if (ui->state == AS_PAUSED) {
532 _DBG("[APP %d] is paused. TERMINATE", _pid);
533 ui->state = AS_DYING;
534 aul_status_update(STATUS_DYING);
536 } else if (ui->state == AS_RUNNING) {
537 _DBG("[APP %d] is running.", _pid);
539 _DBG("[APP %d] is another state", _pid);
542 case AE_UPDATE_REQUESTED:
543 __appcore_efl_update_requested(ui);
551 static struct ui_ops efl_ops = {
556 static bool __check_visible(void)
559 struct win_node *entry = NULL;
561 _DBG("[EVENT_TEST][EVENT] __check_visible\n");
563 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
565 _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
566 if (entry->bfobscured == FALSE)
573 static GSList *__find_win(unsigned int win)
578 for (iter = g_winnode_list; iter; iter = g_slist_next(iter)) {
580 if (t && t->win == win)
588 static bool __add_win(unsigned int win)
593 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
598 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
602 t = calloc(1, sizeof(struct win_node));
607 t->bfobscured = FALSE;
609 g_winnode_list = g_slist_append(g_winnode_list, t);
613 #elif defined(WAYLAND)
614 static bool __add_win(unsigned int win, unsigned int surf)
619 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
624 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
628 t = calloc(1, sizeof(struct win_node));
634 t->bfobscured = FALSE;
636 g_winnode_list = g_slist_append(g_winnode_list, t);
642 static bool __delete_win(unsigned int win)
649 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
655 g_winnode_list = g_slist_delete_link(g_winnode_list, f);
661 static bool __update_win(unsigned int win, bool bfobscured)
666 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
672 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
676 t = (struct win_node *)f->data;
678 t->bfobscured = bfobscured;
682 #elif defined(WAYLAND)
683 static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
688 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
694 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
698 t = (struct win_node *)f->data;
702 t->bfobscured = bfobscured;
710 static Ecore_X_Atom _WM_WINDOW_ROTATION_SUPPORTED = 0;
711 static Ecore_X_Atom _WM_WINDOW_ROTATION_CHANGE_REQUEST = 0;
713 static int __check_wm_rotation_support(void)
715 _DBG("Disable window manager rotation");
718 Ecore_X_Window root, win, win2;
721 if (!_WM_WINDOW_ROTATION_SUPPORTED) {
722 _WM_WINDOW_ROTATION_SUPPORTED =
723 ecore_x_atom_get("_E_WINDOW_ROTATION_SUPPORTED");
726 if (!_WM_WINDOW_ROTATION_CHANGE_REQUEST) {
727 _WM_WINDOW_ROTATION_CHANGE_REQUEST =
728 ecore_x_atom_get("_E_WINDOW_ROTATION_CHANGE_REQUEST");
731 root = ecore_x_window_root_first_get();
732 ret = ecore_x_window_prop_xid_get(root,
733 _WM_WINDOW_ROTATION_SUPPORTED,
736 if ((ret == 1) && (win)) {
737 ret = ecore_x_window_prop_xid_get(win,
738 _WM_WINDOW_ROTATION_SUPPORTED,
741 if ((ret == 1) && (win2 == win))
748 static void __set_wm_rotation_support(unsigned int win, unsigned int set)
751 struct win_node *entry = NULL;
754 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
757 ecore_x_window_prop_card32_set(entry->win,
758 _WM_WINDOW_ROTATION_SUPPORTED,
763 ecore_x_window_prop_card32_set(win,
764 _WM_WINDOW_ROTATION_SUPPORTED,
770 static Eina_Bool __show_cb(void *data, int type, void *event)
773 Ecore_Wl_Event_Window_Show *ev;
776 if (ev->parent_win != 0) {
777 /* This is child window. Skip!!! */
778 return ECORE_CALLBACK_PASS_ON;
781 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
783 if (!__find_win((unsigned int)ev->win))
784 __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
786 __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
789 Ecore_X_Event_Window_Show *ev;
793 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x\n", ev->win);
795 if (!__find_win((unsigned int)ev->win)) {
797 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
798 __set_wm_rotation_support(ev->win, 1);
799 __add_win((unsigned int)ev->win);
801 __update_win((unsigned int)ev->win, FALSE);
805 appcore_group_attach();
806 return ECORE_CALLBACK_RENEW;
809 static Eina_Bool __hide_cb(void *data, int type, void *event)
812 Ecore_Wl_Event_Window_Hide *ev;
814 Ecore_X_Event_Window_Hide *ev;
820 _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
822 if (__find_win((unsigned int)ev->win)) {
823 __delete_win((unsigned int)ev->win);
824 bvisibility = __check_visible();
825 if (!bvisibility && b_active == TRUE) {
826 _DBG(" Go to Pasue state \n");
828 __do_app(AE_PAUSE, data, NULL);
832 return ECORE_CALLBACK_RENEW;
836 static Eina_Bool __lower_cb(void *data, int type, void *event)
838 Ecore_Wl_Event_Window_Lower *ev;
840 if (!ev) return ECORE_CALLBACK_RENEW;
841 _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
842 appcore_group_lower();
843 return ECORE_CALLBACK_RENEW;
847 static Eina_Bool __visibility_cb(void *data, int type, void *event)
850 Ecore_Wl_Event_Window_Visibility_Change *ev;
853 __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
855 Ecore_X_Event_Window_Visibility_Change *ev;
860 __update_win((unsigned int)ev->win, ev->fully_obscured);
862 bvisibility = __check_visible();
864 _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
866 if (bvisibility && b_active == FALSE) {
867 _DBG(" Go to Resume state\n");
869 __do_app(AE_RESUME, data, NULL);
871 } else if (!bvisibility && b_active == TRUE) {
872 _DBG(" Go to Pasue state \n");
874 __do_app(AE_PAUSE, data, NULL);
876 _DBG(" No change state \n");
878 return ECORE_CALLBACK_RENEW;
884 static Eina_Bool __cmsg_cb(void *data, int type, void *event)
886 struct ui_priv *ui = (struct ui_priv *)data;
887 Ecore_X_Event_Client_Message *e = event;
890 return ECORE_CALLBACK_PASS_ON;
893 return ECORE_CALLBACK_PASS_ON;
895 if (e->message_type == _WM_WINDOW_ROTATION_CHANGE_REQUEST) {
896 if ((ui->wm_rot_supported == 0)
897 || (ui->rot_started == 0)
898 || (ui->rot_cb == NULL)) {
899 return ECORE_CALLBACK_PASS_ON;
903 switch (e->data.l[1]) {
905 rm = APPCORE_RM_PORTRAIT_NORMAL;
908 rm = APPCORE_RM_LANDSCAPE_REVERSE;
911 rm = APPCORE_RM_PORTRAIT_REVERSE;
914 rm = APPCORE_RM_LANDSCAPE_NORMAL;
917 rm = APPCORE_RM_UNKNOWN;
923 if (APPCORE_RM_UNKNOWN != rm)
924 ui->rot_cb((void *)&rm, rm, ui->rot_cb_data);
927 return ECORE_CALLBACK_PASS_ON;
931 static void __add_climsg_cb(struct ui_priv *ui)
936 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, ui);
938 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, ui);
940 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
941 __visibility_cb, ui);
943 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER,
947 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, __show_cb, ui);
949 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE, __hide_cb, ui);
951 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
952 __visibility_cb, ui);
954 /* Add client message callback for WM_ROTATE */
955 if (!__check_wm_rotation_support()) {
956 ui->hcmsg = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
958 ui->wm_rot_supported = 1;
959 appcore_set_wm_rotation(&wm_rotate);
964 static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
968 struct appcore *ac = NULL;
970 const char *bg_launch;
972 if (argc == NULL || argv == NULL) {
973 _ERR("argc/argv is NULL");
978 #if !(GLIB_CHECK_VERSION(2, 36, 0))
981 elm_init(*argc, *argv);
983 hwacc = getenv("HWACC");
985 _DBG("elm_config_accel_preference_set is not called");
986 } else if (strcmp(hwacc, "USE") == 0) {
987 elm_config_accel_preference_set("hw");
988 _DBG("elm_config_accel_preference_set : hw");
989 } else if (strcmp(hwacc, "NOT_USE") == 0) {
990 elm_config_accel_preference_set("none");
991 _DBG("elm_config_accel_preference_set : none");
993 _DBG("elm_config_accel_preference_set is not called");
996 r = appcore_init(ui->name, &efl_ops, *argc, *argv);
997 _retv_if(r == -1, -1);
999 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
1000 appcore_get_app_core(&ac);
1002 SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: #%x", ac);
1005 b = bundle_import_from_argv(*argc, *argv);
1007 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
1008 if (bg_launch && strcmp(bg_launch, "enable") == 0)
1014 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
1015 if (ui->ops && ui->ops->create) {
1016 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
1017 r = ui->ops->create(ui->ops->data);
1018 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1020 _ERR("create() return error");
1022 if (ui->ops && ui->ops->terminate) {
1023 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1024 "APPCORE:TERMINATE");
1025 ui->ops->terminate(ui->ops->data);
1026 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1031 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
1034 ui->state = AS_CREATED;
1036 __add_climsg_cb(ui);
1041 static void __after_loop(struct ui_priv *ui)
1043 appcore_unset_rotation_cb();
1046 if (ui->state == AS_RUNNING) {
1047 _DBG("[APP %d] PAUSE before termination", _pid);
1048 if (ui->ops && ui->ops->pause) {
1049 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1051 ui->ops->pause(ui->ops->data);
1052 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1056 if (ui->ops && ui->ops->terminate) {
1057 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
1058 ui->ops->terminate(ui->ops->data);
1059 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1062 ui->state = AS_DYING;
1065 ecore_event_handler_del(ui->hshow);
1067 ecore_event_handler_del(ui->hhide);
1069 ecore_event_handler_del(ui->hvchange);
1070 #if defined(WAYLAND)
1072 ecore_event_handler_del(ui->hlower);
1075 __appcore_timer_del(ui);
1079 /* Check loader case */
1080 if (getenv("AUL_LOADER_INIT")) {
1081 unsetenv("AUL_LOADER_INIT");
1086 static int __set_data(struct ui_priv *ui, const char *name,
1087 struct appcore_ops *ops)
1090 _ERR("Mainloop already started");
1091 errno = EINPROGRESS;
1095 if (name == NULL || name[0] == '\0') {
1096 _ERR("Invalid name");
1102 _ERR("ops is NULL");
1107 ui->name = strdup(name);
1108 _retv_if(ui->name == NULL, -1);
1111 ui->mfcb = __appcore_efl_memory_flush_cb;
1115 ui->wm_rot_supported = 0;
1116 ui->rot_started = 0;
1118 ui->rot_cb_data = NULL;
1119 ui->rot_mode = APPCORE_RM_UNKNOWN;
1121 if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
1122 ui->app_core = NULL;
1123 ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
1124 ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
1130 static void __unset_data(struct ui_priv *ui)
1133 free((void *)ui->name);
1135 memset(ui, 0, sizeof(struct ui_priv));
1140 static int __wm_set_rotation_cb(int (*cb) (void *event_info, enum appcore_rm, void *), void *data)
1147 if ((priv.wm_rot_supported) && (0 == priv.rot_started))
1148 __set_wm_rotation_support(0, 1);
1151 priv.rot_cb_data = data;
1152 priv.rot_started = 1;
1157 static int __wm_unset_rotation_cb(void)
1159 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
1160 __set_wm_rotation_support(0, 0);
1163 priv.rot_cb_data = NULL;
1164 priv.rot_started = 0;
1169 static int __wm_get_rotation_state(enum appcore_rm *curr)
1176 *curr = priv.rot_mode;
1181 static int __wm_pause_rotation_cb(void)
1183 if ((priv.rot_started == 1) && (priv.wm_rot_supported))
1184 __set_wm_rotation_support(0, 0);
1186 priv.rot_started = 0;
1191 static int __wm_resume_rotation_cb(void)
1193 if ((priv.rot_started == 0) && (priv.wm_rot_supported))
1194 __set_wm_rotation_support(0, 1);
1196 priv.rot_started = 1;
1201 static struct ui_wm_rotate wm_rotate = {
1202 __wm_set_rotation_cb,
1203 __wm_unset_rotation_cb,
1204 __wm_get_rotation_state,
1205 __wm_pause_rotation_cb,
1206 __wm_resume_rotation_cb
1210 EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
1211 struct appcore_ops *ops)
1215 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
1217 r = __set_data(&priv, name, ops);
1218 _retv_if(r == -1, -1);
1220 r = __before_loop(&priv, argc, argv);
1222 aul_status_update(STATUS_DYING);
1223 __unset_data(&priv);
1230 EXPORT_API void appcore_efl_fini(void)
1232 aul_status_update(STATUS_DYING);
1234 __after_loop(&priv);
1236 __unset_data(&priv);
1239 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
1240 struct appcore_ops *ops)
1244 r = appcore_efl_init(name, argc, argv, ops);
1245 _retv_if(r == -1, -1);
1254 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
1256 resource_reclaiming = enable;
1261 EXPORT_API int appcore_set_app_state(int state)
1270 EXPORT_API int appcore_set_preinit_window_name(const char *win_name)
1273 void *preinit_window = NULL;
1274 const Evas *e = NULL;
1277 _ERR("invalid parameter");
1281 preinit_window = elm_win_precreated_object_get();
1282 if (!preinit_window) {
1283 _ERR("Failed to get preinit window");
1287 e = evas_object_evas_get((const Evas_Object *)preinit_window);
1289 Ecore_Evas *ee = ecore_evas_ecore_evas_get(e);
1291 ecore_evas_name_class_set(ee, win_name, win_name);
1299 EXPORT_API unsigned int appcore_get_main_window(void)
1301 struct win_node *entry = NULL;
1303 if (g_winnode_list != NULL) {
1304 entry = g_winnode_list->data;
1305 return (unsigned int) entry->win;
1311 #if defined(WAYLAND)
1312 EXPORT_API unsigned int appcore_get_main_surface(void)
1314 struct win_node *entry = NULL;
1316 if (g_winnode_list != NULL) {
1317 entry = g_winnode_list->data;
1318 return (unsigned int) entry->surf;
1325 tizen_profile_t _get_tizen_profile()
1327 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
1328 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
1332 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
1333 switch (*profileName) {
1336 profile = TIZEN_PROFILE_MOBILE;
1340 profile = TIZEN_PROFILE_WEARABLE;
1344 profile = TIZEN_PROFILE_TV;
1348 profile = TIZEN_PROFILE_IVI;
1350 default: // common or unTIZEN_nown ==> ALL ARE COMMON.
1351 profile = TIZEN_PROFILE_COMMON;