2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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>
27 #include <glib-object.h>
29 #include <json-glib/json-glib.h>
35 #include <efl_assist.h>
37 #include <system_settings.h>
41 #include <dynamicbox_service.h>
42 #include <dynamicbox_provider.h>
43 #include <dynamicbox_script.h>
44 #include <dynamicbox_conf.h>
45 #include <dynamicbox.h>
46 #include <internal/dynamicbox.h>
49 #include "critical_log.h"
52 #include "update_monitor.h"
55 #include "so_handler.h"
58 #include "theme_loader.h"
60 #define TEXT_CLASS "tizen"
61 #define DEFAULT_FONT_SIZE -100
62 #define WVGA_DEFAULT_SCALE 1.8f
64 #if !defined(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME)
65 #define VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME "db/setting/accessibility/font_name"
68 #if !defined(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE)
69 #define VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE "db/setting/accessibility/font_size"
75 int (*heap_monitor_initialized)(void);
76 size_t (*heap_monitor_target_usage)(const char *name);
77 int (*heap_monitor_add_target)(const char *name);
78 int (*heap_monitor_del_target)(const char *name);
80 Ea_Theme_Font_Table *table;
82 app_event_handler_h lang_changed_handler;
83 app_event_handler_h region_changed_handler;
86 .font_size = DEFAULT_FONT_SIZE,
87 .heap_monitor_initialized = NULL,
88 .heap_monitor_target_usage = NULL,
89 .heap_monitor_add_target = NULL,
90 .heap_monitor_del_target = NULL,
93 .lang_changed_handler = NULL,
94 .region_changed_handler = NULL,
97 #define SLAVE_VCONFKEY_FONT_NAME "db/setting/accessibility/font_name"
99 static void font_changed_cb(void *user_data)
105 if (s_info.font_name) {
106 font_name = vconf_get_str(SLAVE_VCONFKEY_FONT_NAME);
108 ErrPrint("Invalid font name (NULL)\n");
112 if (!strcmp(s_info.font_name, font_name)) {
113 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
118 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
119 free(s_info.font_name);
124 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
125 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
126 ErrPrint("System settings: %d, font_name[%p]\n", ret, font_name);
131 s_info.font_name = font_name;
132 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
136 * Try to update all dynamicboxes
138 edje_text_class_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
140 DbgPrint("Call system event\n");
141 dbox_system_event_all(DBOX_SYS_EVENT_FONT_CHANGED);
144 static inline int convert_font_size(int size)
147 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
150 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
153 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
156 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
159 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
167 DbgPrint("Return size: %d\n", size);
171 static void font_size_cb(system_settings_key_e key, void *user_data)
175 if (system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &size) != SYSTEM_SETTINGS_ERROR_NONE) {
179 size = convert_font_size(size);
181 if (size == s_info.font_size) {
182 DbgPrint("Font size is not changed\n");
186 s_info.font_size = size;
187 DbgPrint("Font size is changed to %d, but don't try to update it.\n", size);
190 static void tts_changed_cb(keynode_t *node, void *user_data)
192 DbgPrint("TTS status is changed\n");
193 dbox_system_event_all(DBOX_SYS_EVENT_TTS_CHANGED);
196 static void mmc_changed_cb(keynode_t *node, void *user_data)
198 DbgPrint("MMC status is changed\n");
199 dbox_system_event_all(DBOX_SYS_EVENT_MMC_STATUS_CHANGED);
202 static void time_changed_cb(keynode_t *node, void *user_data)
204 DbgPrint("Time is changed\n");
205 dbox_system_event_all(DBOX_SYS_EVENT_TIME_CHANGED);
208 static void initialize_glib_type_system(void)
212 type = G_TYPE_DBUS_ACTION_GROUP;
213 if (type != G_TYPE_OBJECT) {
214 DbgPrint("initialized\n");
216 type = G_TYPE_DBUS_ANNOTATION_INFO;
217 if (type != G_TYPE_OBJECT) {
218 DbgPrint("initialized\n");
220 type = G_TYPE_DBUS_ARG_INFO;
221 if (type != G_TYPE_OBJECT) {
222 DbgPrint("initialized\n");
224 type = G_TYPE_DBUS_AUTH_OBSERVER;
225 if (type != G_TYPE_OBJECT) {
226 DbgPrint("initialized\n");
228 type = G_TYPE_DBUS_CALL_FLAGS;
229 if (type != G_TYPE_OBJECT) {
230 DbgPrint("initialized\n");
232 type = G_TYPE_DBUS_CAPABILITY_FLAGS;
233 if (type != G_TYPE_OBJECT) {
234 DbgPrint("initialized\n");
236 type = G_TYPE_DBUS_CONNECTION;
237 if (type != G_TYPE_OBJECT) {
238 DbgPrint("initialized\n");
240 type = G_TYPE_DBUS_CONNECTION_FLAGS;
241 if (type != G_TYPE_OBJECT) {
242 DbgPrint("initialized\n");
244 type = G_TYPE_DBUS_ERROR;
245 if (type != G_TYPE_OBJECT) {
246 DbgPrint("initialized\n");
248 type = G_TYPE_DBUS_INTERFACE;
249 if (type != G_TYPE_OBJECT) {
250 DbgPrint("initialized\n");
252 type = G_TYPE_DBUS_INTERFACE_INFO;
253 if (type != G_TYPE_OBJECT) {
254 DbgPrint("initialized\n");
256 type = G_TYPE_DBUS_INTERFACE_SKELETON;
257 if (type != G_TYPE_OBJECT) {
258 DbgPrint("initialized\n");
260 type = G_TYPE_DBUS_INTERFACE_SKELETON_FLAGS;
261 if (type != G_TYPE_OBJECT) {
262 DbgPrint("initialized\n");
264 type = G_TYPE_DBUS_MENU_MODEL;
265 if (type != G_TYPE_OBJECT) {
266 DbgPrint("initialized\n");
268 type = G_TYPE_DBUS_MESSAGE;
269 if (type != G_TYPE_OBJECT) {
270 DbgPrint("initialized\n");
272 type = G_TYPE_DBUS_MESSAGE_BYTE_ORDER;
273 if (type != G_TYPE_OBJECT) {
274 DbgPrint("initialized\n");
276 type = G_TYPE_DBUS_MESSAGE_FLAGS;
277 if (type != G_TYPE_OBJECT) {
278 DbgPrint("initialized\n");
280 type = G_TYPE_DBUS_MESSAGE_HEADER_FIELD;
281 if (type != G_TYPE_OBJECT) {
282 DbgPrint("initialized\n");
284 type = G_TYPE_DBUS_MESSAGE_TYPE;
285 if (type != G_TYPE_OBJECT) {
286 DbgPrint("initialized\n");
288 type = G_TYPE_DBUS_METHOD_INFO;
289 if (type != G_TYPE_OBJECT) {
290 DbgPrint("initialized\n");
292 type = G_TYPE_DBUS_METHOD_INVOCATION;
293 if (type != G_TYPE_OBJECT) {
294 DbgPrint("initialized\n");
296 type = G_TYPE_DBUS_NODE_INFO;
297 if (type != G_TYPE_OBJECT) {
298 DbgPrint("initialized\n");
300 type = G_TYPE_DBUS_OBJECT;
301 if (type != G_TYPE_OBJECT) {
302 DbgPrint("initialized\n");
304 type = G_TYPE_DBUS_OBJECT_MANAGER;
305 if (type != G_TYPE_OBJECT) {
306 DbgPrint("initialized\n");
308 type = G_TYPE_DBUS_OBJECT_MANAGER_CLIENT;
309 if (type != G_TYPE_OBJECT) {
310 DbgPrint("initialized\n");
312 type = G_TYPE_DBUS_OBJECT_MANAGER_CLIENT_FLAGS;
313 if (type != G_TYPE_OBJECT) {
314 DbgPrint("initialized\n");
316 type = G_TYPE_DBUS_OBJECT_MANAGER_SERVER;
317 if (type != G_TYPE_OBJECT) {
318 DbgPrint("initialized\n");
320 type = G_TYPE_DBUS_OBJECT_PROXY;
321 if (type != G_TYPE_OBJECT) {
322 DbgPrint("initialized\n");
324 type = G_TYPE_DBUS_OBJECT_SKELETON;
325 if (type != G_TYPE_OBJECT) {
326 DbgPrint("initialized\n");
328 type = G_TYPE_DBUS_PROPERTY_INFO;
329 if (type != G_TYPE_OBJECT) {
330 DbgPrint("initialized\n");
332 type = G_TYPE_DBUS_PROPERTY_INFO_FLAGS;
333 if (type != G_TYPE_OBJECT) {
334 DbgPrint("initialized\n");
336 type = G_TYPE_DBUS_PROXY;
337 if (type != G_TYPE_OBJECT) {
338 DbgPrint("initialized\n");
340 type = G_TYPE_DBUS_PROXY_FLAGS;
341 if (type != G_TYPE_OBJECT) {
342 DbgPrint("initialized\n");
344 type = G_TYPE_DBUS_SEND_MESSAGE_FLAGS;
345 if (type != G_TYPE_OBJECT) {
346 DbgPrint("initialized\n");
348 type = G_TYPE_DBUS_SERVER;
349 if (type != G_TYPE_OBJECT) {
350 DbgPrint("initialized\n");
352 type = G_TYPE_DBUS_SERVER_FLAGS;
353 if (type != G_TYPE_OBJECT) {
354 DbgPrint("initialized\n");
356 type = G_TYPE_DBUS_SIGNAL_FLAGS;
357 if (type != G_TYPE_OBJECT) {
358 DbgPrint("initialized\n");
360 type = G_TYPE_DBUS_SIGNAL_INFO;
361 if (type != G_TYPE_OBJECT) {
362 DbgPrint("initialized\n");
364 type = G_TYPE_DBUS_SUBTREE_FLAGS;
365 if (type != G_TYPE_OBJECT) {
366 DbgPrint("initialized\n");
368 type = JSON_TYPE_NODE;
369 if (type != G_TYPE_OBJECT) {
370 DbgPrint("initialized\n");
372 type = JSON_TYPE_OBJECT;
373 if (type != G_TYPE_OBJECT) {
374 DbgPrint("initialized\n");
376 type = JSON_TYPE_ARRAY;
377 if (type != G_TYPE_OBJECT) {
378 DbgPrint("initialized\n");
380 type = JSON_TYPE_ARRAY;
381 if (type != G_TYPE_OBJECT) {
382 DbgPrint("initialized\n");
384 type = JSON_TYPE_SERIALIZABLE;
385 if (type != G_TYPE_OBJECT) {
386 DbgPrint("initialized\n");
388 type = JSON_TYPE_PARSER;
389 if (type != G_TYPE_OBJECT) {
390 DbgPrint("initialized\n");
392 type = JSON_TYPE_GENERATOR;
393 if (type != G_TYPE_OBJECT) {
394 DbgPrint("initialized\n");
398 static bool app_create(void *argv)
402 elm_app_base_scale_set(WVGA_DEFAULT_SCALE);
403 // elm_config_preferred_engine_set("opengl_x11");
405 dynamicbox_conf_init();
406 if (!dynamicbox_conf_is_loaded()) {
407 ret = dynamicbox_conf_load();
409 DbgPrint("Configureation manager is initiated: %d\n", ret);
413 critical_log_init(util_basename(((char **)argv)[0]));
416 * Touch the glib type system
418 initialize_glib_type_system();
420 DbgPrint("Scale factor: %lf\n", elm_config_scale_get());
422 if (DYNAMICBOX_CONF_COM_CORE_THREAD) {
423 if (setenv("PROVIDER_COM_CORE_THREAD", "true", 0) < 0) {
424 ErrPrint("setenv: %s\n", strerror(errno));
427 if (setenv("PROVIDER_COM_CORE_THREAD", "false", 0) < 0){
428 ErrPrint("setenv: %s\n", strerror(errno));
432 ret = dynamicbox_service_init();
434 DbgPrint("Livebox service init: %d\n", ret);
439 * Slave is not able to initiate system, before
440 * receive its name from the master
442 * So create callback doesn't do anything.
444 ret = fault_init(argv);
446 DbgPrint("Crash recover is initiated: %d\n", ret);
449 ret = update_monitor_init();
451 DbgPrint("Content update monitor is initiated: %d\n", ret);
454 s_info.table = ea_theme_font_table_new("/usr/share/themes/FontInfoTable.xml");
456 DbgPrint("FONT TABLE Prepared");
457 ea_theme_fonts_set(s_info.table);
459 ea_theme_event_callback_add(EA_THEME_CALLBACK_TYPE_FONT, font_changed_cb, NULL);
461 ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, font_size_cb, NULL);
463 DbgPrint("System font size changed callback is added: %d\n", ret);
466 ret = vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, time_changed_cb, NULL);
468 DbgPrint("System time changed event callback added: %d\n", ret);
471 ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, mmc_changed_cb, NULL);
473 DbgPrint("MMC status changed event callback added: %d\n", ret);
476 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, tts_changed_cb, NULL);
478 DbgPrint("TTS changed callback is added: %s\n", ret);
481 font_changed_cb(NULL);
482 font_size_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE, NULL);
483 theme_loader_load(THEME_DIR);
490 static void app_terminate(void *data)
494 DbgPrint("Terminating provider\n");
498 theme_loader_unload();
501 DbgPrint("FONT TABLE Destroyed");
502 ea_theme_font_table_free(s_info.table);
506 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, tts_changed_cb);
508 DbgPrint("TTS changed callback is added: %s\n", ret);
511 ret = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_FONT_SIZE);
513 DbgPrint("unset fontsize: %d\n", ret);
516 ea_theme_event_callback_del(EA_THEME_CALLBACK_TYPE_FONT, font_changed_cb);
518 ret = vconf_ignore_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED, time_changed_cb);
520 DbgPrint("Remove time changed callback: %d\n", ret);
523 ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, mmc_changed_cb);
525 DbgPrint("Remove MMC status changed callback: %d\n", ret);
528 ret = update_monitor_fini();
530 DbgPrint("Content update monitor is finalized: %d\n", ret);
535 DbgPrint("Crash recover is finalized: %d\n", ret);
540 DbgPrint("client finalized: %d\n", ret);
543 ret = dynamicbox_service_fini();
545 DbgPrint("dynamicbox service fini: %d\n", ret);
548 free(s_info.font_name);
549 s_info.font_name = NULL;
557 static void app_pause(void *data)
559 /* Will not be invoked */
563 static void app_resume(void *data)
565 /* Will not be invoked */
569 static void app_region_changed(app_event_info_h event_info, void *data)
572 // app_event_get_region_format(event_info, ®ion);
573 dbox_system_event_all(DBOX_SYS_EVENT_REGION_CHANGED);
576 static void app_language_changed(app_event_info_h event_info, void *data)
579 // app_event_get_language(event_info, &lang);
580 dbox_system_event_all(DBOX_SYS_EVENT_LANG_CHANGED);
583 static void app_control(app_control_h service, void *data)
588 static int initialized = 0;
591 ErrPrint("Already initialized\n");
595 ret = app_control_get_extra_data(service, "name", &name);
596 if (ret != APP_CONTROL_ERROR_NONE) {
597 ErrPrint("Name is not valid\n");
601 ret = app_control_get_extra_data(service, "secured", &secured);
602 if (ret != APP_CONTROL_ERROR_NONE) {
604 ErrPrint("Secured is not valid\n");
608 if (!strcasecmp(secured, "true")) {
609 /* Don't use the update timer */
610 dbox_turn_secured_on();
613 DbgPrint("Name assigned: %s\n", name);
614 DbgPrint("Secured: %s\n", secured);
615 ret = client_init(name);
623 #if defined(_ENABLE_MCHECK)
624 static inline void mcheck_cb(enum mcheck_status status)
628 ptr = util_get_current_module(NULL);
631 case MCHECK_DISABLED:
632 ErrPrint("[DISABLED] Heap incosistency detected: %s\n", ptr);
635 ErrPrint("[OK] Heap incosistency detected: %s\n", ptr);
638 ErrPrint("[HEAD] Heap incosistency detected: %s\n", ptr);
641 ErrPrint("[TAIL] Heap incosistency detected: %s\n", ptr);
644 ErrPrint("[FREE] Heap incosistency detected: %s\n", ptr);
652 #define HEAP_MONITOR_PATH "/usr/lib/libheap-monitor.so"
653 #define BIN_PATH "/usr/apps/com.samsung.data-provider-slave/bin/"
654 int main(int argc, char *argv[])
657 ui_app_lifecycle_callback_s event_callback;
661 memset(argv[0], 0, strlen(argv[0]));
662 strcpy(argv[0], BIN_PATH "data-provider-slave");
663 DbgPrint("Replace argv[0] with %s\n", argv[0]);
665 #if defined(_ENABLE_MCHECK)
668 option = getenv("PROVIDER_DISABLE_CALL_OPTION");
669 if (option && !strcasecmp(option, "true")) {
670 fault_disable_call_option();
673 option = getenv("PROVIDER_HEAP_MONITOR_START");
674 if (option && !strcasecmp(option, "true")) {
675 s_info.heap_monitor = dlopen(HEAP_MONITOR_PATH, RTLD_NOW);
676 if (s_info.heap_monitor) {
677 s_info.heap_monitor_initialized = dlsym(s_info.heap_monitor, "heap_monitor_initialized");
678 s_info.heap_monitor_target_usage = dlsym(s_info.heap_monitor, "heap_monitor_target_usage");
679 s_info.heap_monitor_add_target = dlsym(s_info.heap_monitor, "heap_monitor_add_target");
680 s_info.heap_monitor_del_target = dlsym(s_info.heap_monitor, "heap_monitor_del_target");
684 if (setenv("BUFMGR_LOCK_TYPE", "once", 0) < 0) {
685 ErrPrint("setenv: %s\n", strerror(errno));
688 if (setenv("BUFMGR_MAP_CACHE", "true", 0) < 0) {
689 ErrPrint("setenv: %s\n", strerror(errno));
692 event_callback.create = app_create;
693 event_callback.terminate = app_terminate;
694 event_callback.pause = app_pause;
695 event_callback.resume = app_resume;
696 event_callback.app_control = app_control;
698 ui_app_add_event_handler(&s_info.lang_changed_handler, APP_EVENT_LANGUAGE_CHANGED, app_language_changed, argv);
699 ui_app_add_event_handler(&s_info.region_changed_handler, APP_EVENT_REGION_FORMAT_CHANGED, app_region_changed, argv);
700 // APP_EVENT_DEVICE_ORIENTATION_CHANGED
701 // APP_EVENT_LOW_MEMORY
702 // APP_EVENT_LOW_BATTERY
704 ret = ui_app_main(argc, argv, &event_callback, (void *)argv);
705 ErrPrint("app_efl_main: %d\n", ret);
707 if (s_info.heap_monitor) {
708 if (dlclose(s_info.heap_monitor) < 0) {
709 ErrPrint("dlclose: %s\n", strerror(errno));
716 HAPI int main_heap_monitor_is_enabled(void)
718 return s_info.heap_monitor_initialized ? s_info.heap_monitor_initialized() : 0;
721 HAPI size_t main_heap_monitor_target_usage(const char *name)
723 return s_info.heap_monitor_target_usage ? s_info.heap_monitor_target_usage(name) : 0;
726 HAPI int main_heap_monitor_add_target(const char *name)
728 return s_info.heap_monitor_add_target ? s_info.heap_monitor_add_target(name) : 0;
731 HAPI int main_heap_monitor_del_target(const char *name)
733 return s_info.heap_monitor_del_target ? s_info.heap_monitor_del_target(name) : 0;