2 * Copyright (c) 2017 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.
24 #include <Elementary.h>
28 #include "appcore_efl_base_private.h"
29 #include "appcore_efl_base.h"
31 #define PATH_LIB_VC_ELM "/usr/lib/libvc-elm.so.0"
33 static bool __vc_elm_initialized;
34 static void *__vc_elm_handle;
35 static int (*__vc_elm_initialize)(void);
36 static int (*__vc_elm_deinitialize)(void);
37 static int (*__vc_elm_set_auto_register_mode)(int, int);
38 static GThread *__vc_elm_thread;
40 static void __unload_vc_elm(void)
45 __vc_elm_initialize = NULL;
46 __vc_elm_deinitialize = NULL;
47 __vc_elm_set_auto_register_mode = NULL;
49 dlclose(__vc_elm_handle);
50 __vc_elm_handle = NULL;
53 static int __load_vc_elm(void)
55 _DBG("Load voice-control-elm");
57 if (__vc_elm_handle) {
58 _DBG("Already exists");
62 if (access(PATH_LIB_VC_ELM, F_OK) != 0) {
63 _ERR("Failed to access %s", PATH_LIB_VC_ELM);
67 __vc_elm_handle = dlopen(PATH_LIB_VC_ELM, RTLD_LAZY | RTLD_LOCAL);
68 if (!__vc_elm_handle) {
69 _ERR("Failed to open %s", PATH_LIB_VC_ELM);
73 __vc_elm_initialize = dlsym(__vc_elm_handle, "vc_elm_initialize");
74 if (!__vc_elm_initialize) {
75 _ERR("Failed to load vc_elm_initialize");
80 __vc_elm_deinitialize = dlsym(__vc_elm_handle, "vc_elm_deinitialize");
81 if (!__vc_elm_deinitialize) {
82 _ERR("Failed to load vc_elm_deinitialize");
87 __vc_elm_set_auto_register_mode = dlsym(__vc_elm_handle,
88 "vc_elm_set_auto_register_mode");
89 if (!__vc_elm_set_auto_register_mode) {
90 _ERR("Failed to load vc_elm_set_auto_register_mode");
98 static void __vc_vtauto_changed_cb(keynode_t *key, void *data)
103 name = vconf_keynode_get_name(key);
104 if (!name || strcmp(name, VCONFKEY_VC_VOICE_TOUCH_AUTOMODE) != 0)
107 vt_automode = vconf_keynode_get_bool(key);
109 if (!__vc_elm_initialized) {
110 __vc_elm_initialize();
111 __vc_elm_initialized = true;
113 __vc_elm_set_auto_register_mode(2, 0);
115 __vc_elm_deinitialize();
116 __vc_elm_initialized = false;
120 static void __vc_elm_init(void)
124 if (!__vc_elm_handle)
127 vconf_notify_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
128 __vc_vtauto_changed_cb, NULL);
129 vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &vt_automode);
131 if (!__vc_elm_initialized) {
132 __vc_elm_initialize();
133 __vc_elm_initialized = true;
135 __vc_elm_set_auto_register_mode(2, 0);
139 static void __vc_elm_finish(void)
141 if (!__vc_elm_handle)
144 vconf_ignore_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
145 __vc_vtauto_changed_cb);
146 if (__vc_elm_initialized) {
147 __vc_elm_deinitialize();
148 __vc_elm_initialized = false;
152 static gboolean __init_vc_elm(gpointer data)
154 _DBG("Initialize vc-elm");
155 /* Postpone initialization to improve app launching performance */
156 /* VC voice touch setting */
159 return G_SOURCE_REMOVE;
162 static gpointer __vc_elm_loader(gpointer data)
170 g_idle_add(__init_vc_elm, NULL);
173 } while (retry_count--);
174 LOGW("[vc-elm-loader] Result: %d", r);
176 return GINT_TO_POINTER(r);
179 static void __efl_app_init(int argc, char **argv, void *data)
185 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:ELM_INIT");
186 elm_init(argc, argv);
187 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
189 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:ELM_CONFIG_SET");
190 hint = appcore_efl_base_get_hint();
191 if ((hint & APPCORE_EFL_BASE_HINT_HW_ACC_CONTROL) &&
192 !getenv("AUL_HWACC")) {
193 hwacc = getenv("HWACC");
195 _DBG("elm_config_accel_preference_set is not called");
196 } else if (strcmp(hwacc, "USE") == 0) {
197 elm_config_accel_preference_set("hw");
198 _DBG("elm_config_accel_preference_set : hw");
199 } else if (strcmp(hwacc, "NOT_USE") == 0) {
200 elm_config_accel_preference_set("none");
201 _DBG("elm_config_accel_preference_set : none");
203 _DBG("elm_config_accel_preference_set is not called");
206 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
208 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:VC_ELM_CHECK");
209 vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &vt_automode);
211 __vc_elm_thread = g_thread_new("vc-elm-loader",
212 __vc_elm_loader, NULL);
214 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
217 static void __efl_app_finish(void)
223 if (__vc_elm_thread) {
224 r = g_thread_join(__vc_elm_thread);
225 __vc_elm_thread = NULL;
226 _DBG("vc-elm-loader. result(%d)", GPOINTER_TO_INT(r));
231 /* Check loader case */
232 env = getenv("AUL_LOADER_INIT");
233 if (env && env[0] == '1') {
234 setenv("AUL_LOADER_INIT", "0", 1);
239 static void __efl_app_run(void *data)
244 static void __efl_app_exit(void *data)
249 static void __efl_app_trim_memory(void *data)
252 elm_cache_all_flush();
253 appcore_base_on_trim_memory();
256 EXPORT_API int appcore_efl_base_init(appcore_efl_base_ops ops, int argc,
257 char **argv, void *data, unsigned int hint)
259 return appcore_ui_base_init(ops.ui_base, argc, argv, data, hint);
262 EXPORT_API void appcore_efl_base_fini(void)
264 appcore_ui_base_fini();
267 EXPORT_API appcore_efl_base_ops appcore_efl_base_get_default_ops(void)
269 appcore_efl_base_ops ops;
271 ops.ui_base = appcore_ui_base_get_default_ops();
273 /* override methods */
274 ops.ui_base.base.init = __efl_app_init;
275 ops.ui_base.base.finish = __efl_app_finish;
276 ops.ui_base.base.run = __efl_app_run;
277 ops.ui_base.base.exit = __efl_app_exit;
278 ops.ui_base.base.trim_memory = __efl_app_trim_memory;
283 EXPORT_API int appcore_efl_base_on_receive(aul_type type, bundle *b)
285 return appcore_ui_base_on_receive(type, b);
288 EXPORT_API int appcore_efl_base_on_create(void)
290 return appcore_ui_base_on_create();
293 EXPORT_API int appcore_efl_base_on_terminate(void)
295 return appcore_ui_base_on_terminate();
298 EXPORT_API int appcore_efl_base_on_pause(void)
300 return appcore_ui_base_on_pause();
303 EXPORT_API int appcore_efl_base_on_resume(void)
305 return appcore_ui_base_on_resume();
308 EXPORT_API int appcore_efl_base_on_control(bundle *b)
310 return appcore_ui_base_on_control(b);
313 EXPORT_API int appcore_efl_base_on_trim_memory(void)
315 return appcore_ui_base_on_trim_memory();
318 EXPORT_API void appcore_efl_base_window_on_show(int type, void *event)
320 appcore_ui_base_window_on_show(type, event);
323 EXPORT_API void appcore_efl_base_window_on_hide(int type, void *event)
325 appcore_ui_base_window_on_hide(type, event);
328 EXPORT_API void appcore_efl_base_window_on_lower(int type, void *event)
330 appcore_ui_base_window_on_lower(type, event);
333 EXPORT_API void appcore_efl_base_window_on_visibility(int type, void *event)
335 appcore_ui_base_window_on_visibility(type, event);
338 EXPORT_API void appcore_efl_base_window_on_pre_visibility(int type, void *event)
340 appcore_ui_base_window_on_pre_visibility(type, event);
343 EXPORT_API void appcore_efl_base_window_on_aux_message(int type, void *event)
345 appcore_ui_base_window_on_aux_message(type, event);
348 EXPORT_API void appcore_efl_base_pause(void)
350 appcore_ui_base_pause();
353 EXPORT_API void appcore_efl_base_resume(void)
355 appcore_ui_base_resume();
358 EXPORT_API bool appcore_efl_base_is_resumed(void)
360 return appcore_ui_base_is_resumed();
363 EXPORT_API void appcore_efl_base_exit(void)
365 appcore_ui_base_exit();
368 EXPORT_API void appcore_efl_base_group_add(void)
370 appcore_ui_base_group_add();
373 EXPORT_API void appcore_efl_base_group_remove(void)
375 appcore_ui_base_group_remove();
378 EXPORT_API unsigned int appcore_efl_base_get_main_window(void)
380 return appcore_ui_base_get_main_window();
383 EXPORT_API unsigned int appcore_efl_base_get_main_surface(void)
385 return appcore_ui_base_get_main_surface();
388 EXPORT_API int appcore_efl_base_get_hint(void)
390 return appcore_ui_base_get_hint();
393 EXPORT_API bool appcore_efl_base_get_bg_state(void)
395 return appcore_ui_base_get_bg_state();
398 EXPORT_API void appcore_efl_base_set_bg_state(bool bg_state)
400 appcore_ui_base_set_bg_state(bg_state);
403 EXPORT_API void appcore_efl_base_set_system_resource_reclaiming(bool enable)
405 appcore_ui_base_set_system_resource_reclaiming(enable);