2 * Copyright (c) 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.
24 #include <sys/types.h>
30 #include <linux/limits.h>
37 #include <bundle_internal.h>
38 #include <sensor_internal.h>
40 #include <system_info.h>
41 #include "appcore_base.h"
42 #include "appcore_base_private.h"
44 #define PATH_LOCALE "locale"
45 #define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
46 #define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer"
47 #define RESOURCED_FREEZER_SIGNAL "FreezerState"
49 typedef struct _appcore_base_context {
59 } appcore_base_context;
61 typedef struct _appcore_base_event_node {
63 appcore_base_event_cb cb;
65 } appcore_base_event_node;
67 typedef struct _appcore_base_rotation {
71 enum appcore_base_rm rm;
72 } appcore_base_rotation;
79 static appcore_base_context __context;
80 static GList *__events;
81 static GDBusConnection *__bus;
82 static guint __suspend_dbus_handler_initialized;
83 static char *__locale_dir;
84 static appcore_base_rotation __rotation;
86 appcore_base_tizen_profile_t appcore_base_get_tizen_profile(void)
88 static appcore_base_tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
89 char *profile_name = NULL;
91 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
94 system_info_get_platform_string("http://tizen.org/feature/profile",
96 if (profile_name == NULL)
99 switch (*profile_name) {
102 profile = TIZEN_PROFILE_MOBILE;
106 profile = TIZEN_PROFILE_WEARABLE;
110 profile = TIZEN_PROFILE_TV;
114 profile = TIZEN_PROFILE_IVI;
117 profile = TIZEN_PROFILE_COMMON;
126 static void __invoke_callback(void *event, int type)
128 GList *iter = __events;
131 appcore_base_event_node *node = iter->data;
133 if (node->type == type)
134 node->cb(event, node->data);
135 iter = g_list_next(iter);
139 static bool __exist_callback(int type)
141 GList *iter = __events;
144 appcore_base_event_node *node = iter->data;
146 if (node->type == type)
149 iter = g_list_next(iter);
155 static enum appcore_base_rm __get_rm(sensor_data_t data)
158 enum appcore_base_rm rm;
160 if (data.value_count <= 0) {
161 _ERR("Failed to get sensor data");
162 return APPCORE_BASE_RM_UNKNOWN;
165 event = data.values[0];
167 case AUTO_ROTATION_DEGREE_0:
168 rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
170 case AUTO_ROTATION_DEGREE_90:
171 rm = APPCORE_BASE_RM_LANDSCAPE_NORMAL;
173 case AUTO_ROTATION_DEGREE_180:
174 rm = APPCORE_BASE_RM_PORTRAIT_REVERSE;
176 case AUTO_ROTATION_DEGREE_270:
177 rm = APPCORE_BASE_RM_LANDSCAPE_REVERSE;
180 rm = APPCORE_BASE_RM_UNKNOWN;
187 static void __lock_cb(keynode_t *node, void *user_data)
191 enum appcore_base_rm rm;
193 __rotation.lock = !vconf_keynode_get_bool(node);
194 if (__rotation.lock) {
195 _DBG("Rotation locked");
196 rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
198 _DBG("Rotation unlocked");
199 r = sensord_get_data(__rotation.conn, AUTO_ROTATION_SENSOR, &data);
201 _ERR("Failed to get sensor data");
206 if (rm == APPCORE_BASE_RM_UNKNOWN) {
207 _ERR("Unknown mode");
212 if (__rotation.rm == rm)
215 _DBG("Rotation: %d -> %d", __rotation.rm, rm);
217 __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
220 static void __auto_rotation_changed_cb(sensor_t sensor, unsigned int event_type,
221 sensor_data_t *data, void *user_data)
223 enum appcore_base_rm rm;
231 if (event_type != AUTO_ROTATION_CHANGE_STATE_EVENT)
234 rm = __get_rm(*data);
235 if (rm == APPCORE_BASE_RM_UNKNOWN) {
236 _ERR("Unknown mode");
240 _DBG("Rotation: %d -> %d", __rotation.rm, rm);
242 __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
245 static void __unregister_rotation_changed_event(void)
251 if (__rotation.ref > 1)
254 vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb);
255 sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
256 sensord_stop(__rotation.conn);
257 sensord_disconnect(__rotation.conn);
263 static void __register_rotation_changed_event(void)
269 if (__rotation.ref) {
274 sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
275 __rotation.conn = sensord_connect(sensor);
276 if (__rotation.conn < 0) {
277 _ERR("Failed to connect sensord");
281 r = sensord_register_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT,
282 SENSOR_INTERVAL_NORMAL, 0, __auto_rotation_changed_cb, NULL);
284 _ERR("Failed to register auto rotation change event");
285 sensord_disconnect(__rotation.conn);
289 r = sensord_start(__rotation.conn, 0);
291 _ERR("Failed to start sensord");
292 sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
293 sensord_disconnect(__rotation.conn);
298 vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
299 vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb, NULL);
301 __rotation.lock = !lock;
305 static void __on_low_memory(keynode_t *key, void *data)
309 val = vconf_keynode_get_int(key);
311 if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
312 __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_MEMORY);
317 static void __on_low_battery(keynode_t *key, void *data)
321 val = vconf_keynode_get_int(key);
323 if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW)
324 __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_BATTERY);
327 static void __destroy_lang_info(gpointer data)
329 struct lang_info_s *info = (struct lang_info_s *)data;
335 g_list_free_full(info->list, free);
341 static struct lang_info_s *__create_lang_info(const char *lang)
343 struct lang_info_s *info;
345 info = calloc(1, sizeof(struct lang_info_s));
347 _ERR("Out of memory");
351 info->parent = strdup(lang);
352 if (info->parent == NULL) {
353 _ERR("Out of memory");
361 static gint __compare_langs(gconstpointer a, gconstpointer b)
369 static char *__get_string_before(const char *str, const char *delim)
375 dup_str = strdup(str);
379 token = strtok(dup_str, delim);
385 new_str = strdup(token);
391 static GHashTable *__get_lang_table(void)
395 struct dirent *dentry;
397 struct stat stat_buf;
400 struct lang_info_s *info;
402 if (__locale_dir == NULL || __locale_dir[0] == '\0')
405 table = g_hash_table_new_full(g_str_hash, g_str_equal,
406 NULL, __destroy_lang_info);
408 _ERR("Out of memory");
412 dp = opendir(__locale_dir);
414 g_hash_table_destroy(table);
418 while ((dentry = readdir(dp)) != NULL) {
419 if (!strcmp(dentry->d_name, ".") ||
420 !strcmp(dentry->d_name, ".."))
423 snprintf(buf, sizeof(buf), "%s/%s",
424 __locale_dir, dentry->d_name);
425 ret = stat(buf, &stat_buf);
426 if (ret != 0 || !S_ISDIR(stat_buf.st_mode))
429 parent_lang = __get_string_before(dentry->d_name, "_");
430 if (parent_lang == NULL) {
431 _ERR("Out of memory");
435 info = g_hash_table_lookup(table, parent_lang);
437 info = __create_lang_info(parent_lang);
442 g_hash_table_insert(table, info->parent, info);
444 info->list = g_list_append(info->list, strdup(dentry->d_name));
452 static GList *__append_langs(const char *lang, GList *list, GHashTable *table)
454 struct lang_info_s *info;
456 char *parent_lang = NULL;
462 list = g_list_append(list, strdup(lang));
464 extract_lang = __get_string_before(lang, ".");
465 if (extract_lang == NULL)
468 found = g_list_find_custom(list, extract_lang, __compare_langs);
470 list = g_list_remove_link(list, found);
471 list = g_list_concat(list, found);
475 parent_lang = __get_string_before(extract_lang, "_");
476 if (parent_lang == NULL)
479 info = g_hash_table_lookup(table, parent_lang);
483 found = g_list_find_custom(info->list, extract_lang, __compare_langs);
485 info->list = g_list_remove_link(info->list, found);
486 list = g_list_concat(list, found);
490 found = g_list_find_custom(info->list, parent_lang, __compare_langs);
492 info->list = g_list_remove_link(info->list, found);
493 list = g_list_concat(list, found);
497 found = g_list_first(info->list);
499 info->list = g_list_remove_link(info->list, found);
500 list = g_list_concat(list, found);
512 static GList *__split_language(const char *lang)
518 dup_lang = strdup(lang);
519 if (dup_lang == NULL) {
520 _ERR("Out of memory");
524 token = strtok(dup_lang, ":");
525 while (token != NULL) {
526 list = g_list_append(list, strdup(token));
527 token = strtok(NULL, ":");
534 static GList *__append_default_langs(GList *list)
536 const char *langs[] = {"en_US", "en_GB", "en"};
540 for (i = 0; i < (sizeof(langs) / sizeof(langs[0])); i++) {
541 found = g_list_find_custom(list, langs[i], __compare_langs);
543 list = g_list_append(list, strdup(langs[i]));
549 static char *__get_language(const char *lang)
553 GList *lang_list = NULL;
556 char buf[LINE_MAX] = {'\0'};
559 list = __split_language(lang);
563 table = __get_lang_table();
565 g_list_free_full(list, free);
569 iter = g_list_first(list);
571 language = (char *)iter->data;
572 lang_list = __append_langs(language, lang_list, table);
573 iter = g_list_next(iter);
575 g_list_free_full(list, free);
576 g_hash_table_destroy(table);
578 lang_list = __append_default_langs(lang_list);
579 iter = g_list_first(lang_list);
581 language = (char *)iter->data;
583 if (buf[0] == '\0') {
584 snprintf(buf, sizeof(buf), "%s", language);
586 n = sizeof(buf) - strlen(buf) - 1;
587 strncat(buf, ":", n);
588 n = sizeof(buf) - strlen(buf) - 1;
589 strncat(buf, language, n);
592 iter = g_list_next(iter);
594 g_list_free_full(lang_list, free);
599 static void __update_lang(void)
605 lang = vconf_get_str(VCONFKEY_LANGSET);
607 /* TODO: Use VCONFKEY_SETAPPL_LANGUAGES key */
608 language = __get_language(lang);
610 _DBG("*****language(%s)", language);
611 setenv("LANGUAGE", language, 1);
614 setenv("LANGUAGE", lang, 1);
616 setenv("LANG", lang, 1);
617 setenv("LC_MESSAGES", lang, 1);
618 r = setlocale(LC_ALL, "");
620 r = setlocale(LC_ALL, "en_US.UTF-8");
622 _DBG("*****appcore setlocale=%s\n", r);
628 static void __update_region(void)
633 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
635 setenv("LC_CTYPE", region, 1);
636 setenv("LC_NUMERIC", region, 1);
637 setenv("LC_TIME", region, 1);
638 setenv("LC_COLLATE", region, 1);
639 setenv("LC_MONETARY", region, 1);
640 setenv("LC_PAPER", region, 1);
641 setenv("LC_NAME", region, 1);
642 setenv("LC_ADDRESS", region, 1);
643 setenv("LC_TELEPHONE", region, 1);
644 setenv("LC_MEASUREMENT", region, 1);
645 setenv("LC_IDENTIFICATION", region, 1);
646 r = setlocale(LC_ALL, "");
648 _DBG("*****appcore setlocale=%s\n", r);
654 static void __on_language_change(keynode_t *key, void *data)
659 g_source_remove(__context.sid);
663 val = vconf_keynode_get_str(key);
666 __invoke_callback((void *)val, APPCORE_BASE_EVENT_LANG_CHANGE);
669 static void __on_region_change(keynode_t *key, void *data)
674 name = vconf_keynode_get_name(key);
678 if (strcmp(name, VCONFKEY_REGIONFORMAT) &&
679 strcmp(name, VCONFKEY_REGIONFORMAT_TIME1224))
682 val = vconf_get_str(VCONFKEY_REGIONFORMAT);
685 __invoke_callback((void *)val, APPCORE_BASE_EVENT_REGION_CHANGE);
689 static gboolean __invoke_lang_change(gpointer data)
695 lang = getenv("LANG");
697 return G_SOURCE_REMOVE;
699 __invoke_callback((void *)lang, APPCORE_BASE_EVENT_LANG_CHANGE);
701 return G_SOURCE_REMOVE;
704 static void __verify_language(void)
707 const char *env_lang;
709 env_lang = getenv("LANG");
713 lang = vconf_get_str(VCONFKEY_LANGSET);
717 if (strcmp(env_lang, lang) != 0) {
718 _INFO("LANG(%s), LANGSET(%s)", env_lang, lang);
719 __context.sid = g_idle_add(__invoke_lang_change, NULL);
725 static gboolean __flush_memory(gpointer data)
727 int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
729 appcore_base_flush_memory();
732 if (!__context.allowed_bg && !__context.suspended_state) {
733 _DBG("[__SUSPEND__] flush case");
734 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
735 __context.suspended_state = true;
741 static void __add_suspend_timer(void)
743 __context.tid = g_timeout_add_seconds(5, __flush_memory, NULL);
746 static void __remove_suspend_timer(void)
748 if (__context.tid > 0) {
749 g_source_remove(__context.tid);
754 static void __on_receive_suspend_signal(GDBusConnection *connection,
755 const gchar *sender_name,
756 const gchar *object_path,
757 const gchar *interface_name,
758 const gchar *signal_name,
759 GVariant *parameters,
762 gint suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
766 if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) == 0) {
767 g_variant_get(parameters, "(ii)", &status, &pid);
768 if (pid == getpid() && status == 0) {
769 if (!__context.allowed_bg && __context.suspended_state) {
770 __remove_suspend_timer();
771 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
772 __context.suspended_state = false;
773 __add_suspend_timer();
779 static int __init_suspend_dbus_handler(void)
783 if (__suspend_dbus_handler_initialized)
787 __bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
789 _ERR("Failed to connect to the D-BUS daemon: %s",
796 __suspend_dbus_handler_initialized = g_dbus_connection_signal_subscribe(
799 RESOURCED_FREEZER_INTERFACE,
800 RESOURCED_FREEZER_SIGNAL,
801 RESOURCED_FREEZER_PATH,
803 G_DBUS_SIGNAL_FLAGS_NONE,
804 __on_receive_suspend_signal,
807 if (__suspend_dbus_handler_initialized == 0) {
808 _ERR("g_dbus_connection_signal_subscribe() is failed.");
812 _DBG("[__SUSPEND__] suspend signal initialized");
817 static void __fini_suspend_dbus_handler(void)
822 if (__suspend_dbus_handler_initialized) {
823 g_dbus_connection_signal_unsubscribe(__bus,
824 __suspend_dbus_handler_initialized);
825 __suspend_dbus_handler_initialized = 0;
828 g_object_unref(__bus);
832 static int __get_locale_resource_dir(char *locale_dir, int size)
834 const char *res_path;
836 res_path = aul_get_app_resource_path();
837 if (res_path == NULL) {
838 _ERR("Failed to get resource path");
842 snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path);
843 if (access(locale_dir, R_OK) != 0)
844 _DBG("%s does not exist", locale_dir);
849 static int __get_app_name(const char *appid, char **name)
851 char *name_token = NULL;
856 /* com.vendor.name -> name */
857 name_token = strrchr(appid, '.');
858 if (name_token == NULL)
863 *name = strdup(name_token);
870 static int __set_i18n(const char *domain, const char *dir)
874 if (domain == NULL) {
882 __locale_dir = strdup(dir);
888 r = setlocale(LC_ALL, "");
889 /* if locale is not set properly, try to set "en_US" again */
891 r = setlocale(LC_ALL, "en_US.UTF-8");
892 _DBG("*****appcore setlocale=%s\n", r);
895 _ERR("appcore: setlocale() error");
897 r = bindtextdomain(domain, dir);
899 _ERR("appcore: bindtextdomain() error");
901 r = textdomain(domain);
903 _ERR("appcore: textdomain() error");
908 EXPORT_API int appcore_base_on_set_i18n(void)
911 char locale_dir[PATH_MAX];
912 char appid[PATH_MAX];
915 r = aul_app_get_appid_bypid(getpid(), appid, PATH_MAX);
917 _ERR("Failed to get application ID - pid(%d)", getpid());
921 r = __get_app_name(appid, &name);
925 r = __get_locale_resource_dir(locale_dir, sizeof(locale_dir));
931 r = __set_i18n(name, locale_dir);
942 EXPORT_API int appcore_base_set_i18n(const char *domain_name, const char *dir_name)
944 return __set_i18n(domain_name, dir_name);
947 EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, void *data)
953 __context.argc = argc;
954 __context.argv = argv;
955 __context.data = data;
957 __context.suspended_state = false;
958 __context.allowed_bg = false;
960 if (__context.ops.init)
961 __context.ops.init(argc, argv, data);
963 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
964 __init_suspend_dbus_handler();
966 if (!__context.dirty) {
967 __context.dirty = true;
969 for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
970 if (__exist_callback(i)) {
971 if (__context.ops.set_event)
972 __context.ops.set_event(i, __context.data);
978 if (__context.ops.set_i18n)
979 __context.ops.set_i18n(__context.data);
981 if (__context.ops.create) {
982 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
983 r = __context.ops.create(__context.data);
984 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
986 aul_status_update(STATUS_DYING);
991 if (__context.ops.run)
992 __context.ops.run(__context.data);
997 EXPORT_API void appcore_base_fini(void)
1001 aul_status_update(STATUS_DYING);
1002 if (__context.ops.terminate) {
1003 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
1004 __context.ops.terminate(__context.data);
1005 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1008 for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
1009 if (__exist_callback(i)) {
1010 if (__context.ops.unset_event)
1011 __context.ops.unset_event(i, __context.data);
1015 if (__context.sid) {
1016 g_source_remove(__context.sid);
1020 g_list_free_full(__events, free);
1023 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
1024 __fini_suspend_dbus_handler();
1028 __locale_dir = NULL;
1031 __context.dirty = false;
1033 if (__context.ops.finish)
1034 __context.ops.finish();
1037 EXPORT_API int appcore_base_flush_memory(void)
1043 EXPORT_API int appcore_base_on_receive(aul_type type, bundle *b)
1046 const char **tep_path;
1054 _DBG("[APP %d] AUL event: AUL_START", getpid());
1055 tep_path = bundle_get_str_array(b, AUL_TEP_PATH, &len);
1057 for (i = 0; i < len; i++) {
1058 ret = aul_check_tep_mount(tep_path[i]);
1060 _ERR("mount request not completed within 1 sec");
1066 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1067 bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
1068 if (bg && !strcmp(bg, "ALLOWED_BG")) {
1069 _DBG("[__SUSPEND__] allowed background");
1070 __context.allowed_bg = true;
1071 __remove_suspend_timer();
1075 if (__context.ops.control) {
1076 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:RESET");
1077 __context.ops.control(b, __context.data);
1078 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1082 _DBG("[APP %d] AUL event: AUL_RESUME", getpid());
1083 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1084 bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
1085 if (bg && !strcmp(bg, "ALLOWED_BG")) {
1086 _DBG("[__SUSPEND__] allowed background");
1087 __context.allowed_bg = true;
1088 __remove_suspend_timer();
1093 _DBG("[APP %d] AUL event: AUL_TERMINATE", getpid());
1094 aul_status_update(STATUS_DYING);
1095 if (!__context.allowed_bg)
1096 __remove_suspend_timer();
1098 if (__context.ops.exit)
1099 __context.ops.exit(__context.data);
1101 case AUL_TERMINATE_BGAPP:
1102 _DBG("[APP %d] AUL event: AUL_TERMINATE_BGAPP", getpid());
1103 if (!__context.allowed_bg)
1104 __remove_suspend_timer();
1107 _DBG("[APP %d] AUL event: AUL_WAKE", getpid());
1108 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1109 if (!__context.allowed_bg &&
1110 __context.suspended_state) {
1111 int suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
1112 __remove_suspend_timer();
1113 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
1114 __context.suspended_state = false;
1119 _DBG("[APP %d] AUL event: AUL_SUSPEND", getpid());
1120 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1121 if (!__context.allowed_bg &&
1122 !__context.suspended_state) {
1123 __remove_suspend_timer();
1124 __flush_memory(NULL);
1128 case AUL_UPDATE_REQUESTED:
1129 _DBG("[APP %d] AUL event: AUL_UPDATE_REQUESTED", getpid());
1130 __invoke_callback((void *)&dummy, APPCORE_BASE_EVENT_UPDATE_REQUESTED);
1133 _DBG("[APP %d] AUL event: %d", getpid(), type);
1141 EXPORT_API int appcore_base_on_create(void)
1144 r = aul_launch_init(__context.ops.receive, NULL);
1146 _ERR("Aul init failed: %d", r);
1150 r = aul_launch_argv_handler(__context.argc, __context.argv);
1152 _ERR("Aul argv handler failed: %d", r);
1159 EXPORT_API int appcore_base_on_control(bundle *b)
1164 EXPORT_API int appcore_base_on_terminate()
1171 EXPORT_API void appcore_base_on_set_event(enum appcore_base_event event)
1176 case APPCORE_BASE_EVENT_LOW_MEMORY:
1177 vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory, NULL);
1179 case APPCORE_BASE_EVENT_LOW_BATTERY:
1180 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery, NULL);
1182 case APPCORE_BASE_EVENT_LANG_CHANGE:
1183 vconf_notify_key_changed(VCONFKEY_LANGSET, __on_language_change, NULL);
1185 case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
1186 __register_rotation_changed_event();
1188 case APPCORE_BASE_EVENT_REGION_CHANGE:
1189 r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change, NULL);
1193 vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change, NULL);
1195 case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
1204 EXPORT_API void appcore_base_on_unset_event(enum appcore_base_event event)
1209 case APPCORE_BASE_EVENT_LOW_MEMORY:
1210 vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory);
1212 case APPCORE_BASE_EVENT_LOW_BATTERY:
1213 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery);
1215 case APPCORE_BASE_EVENT_LANG_CHANGE:
1216 vconf_ignore_key_changed(VCONFKEY_LANGSET, __on_language_change);
1218 case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
1219 __unregister_rotation_changed_event();
1221 case APPCORE_BASE_EVENT_REGION_CHANGE:
1222 r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change);
1225 vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change);
1227 case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
1234 EXPORT_API appcore_base_event_h appcore_base_add_event(enum appcore_base_event event,
1235 appcore_base_event_cb cb, void *data)
1237 appcore_base_event_node *node;
1239 if (__context.dirty && !__exist_callback(event)) {
1240 if (__context.ops.set_event)
1241 __context.ops.set_event(event, __context.data);
1244 node = malloc(sizeof(appcore_base_event_node));
1252 __events = g_list_append(__events, node);
1257 EXPORT_API int appcore_base_remove_event(appcore_base_event_h handle)
1259 appcore_base_event_node *node = handle;
1260 enum appcore_base_event event;
1262 if (!node || !g_list_find(__events, node))
1266 __events = g_list_remove(__events, node);
1268 if (__context.dirty && !__exist_callback(event)) {
1269 if (__context.ops.unset_event)
1270 __context.ops.unset_event(event, __context.data);
1276 EXPORT_API int appcore_base_raise_event(void *event, enum appcore_base_event type)
1278 __invoke_callback(event, type);
1282 EXPORT_API int appcore_base_get_rotation_state(enum appcore_base_rm *curr)
1287 if (!__rotation.ref)
1290 *curr = __rotation.rm;
1294 EXPORT_API bool appcore_base_is_bg_allowed(void)
1296 return __context.allowed_bg;
1299 EXPORT_API bool appcore_base_is_suspended(void)
1301 return __context.suspended_state;
1304 EXPORT_API void appcore_base_toggle_suspended_state(void)
1306 __context.suspended_state ^= __context.suspended_state;
1309 EXPORT_API void appcore_base_exit(void)
1311 if (__context.ops.exit)
1312 __context.ops.exit(__context.data);
1315 static int __on_receive(aul_type type, bundle *b, void *data)
1317 return appcore_base_on_receive(type, b);
1320 static int __on_create(void *data)
1322 return appcore_base_on_create();
1325 static int __on_control(bundle *b, void *data)
1327 return appcore_base_on_control(b);
1330 static int __on_terminate(void *data)
1332 return appcore_base_on_terminate();
1335 static int __on_set_i18n(void *data)
1337 return appcore_base_on_set_i18n();
1340 static void __on_set_event(enum appcore_base_event event, void *data)
1342 return appcore_base_on_set_event(event);
1345 static void __on_unset_event(enum appcore_base_event event, void *data)
1347 return appcore_base_on_unset_event(event);
1350 EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
1352 appcore_base_ops ops;
1354 ops.create = __on_create;
1355 ops.control = __on_control;
1356 ops.terminate = __on_terminate;
1357 ops.receive = __on_receive;
1358 ops.set_i18n = __on_set_i18n;
1363 ops.set_event = __on_set_event;
1364 ops.unset_event = __on_unset_event;