From 7d6c99b8ffb4fe7666d5f083b321b0f6b585dbc3 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 10 Nov 2015 17:58:28 +0900 Subject: [PATCH] merge tizen 2.4 Change-Id: I6808f3fe20e489ffb848a2feedba4803394857a1 Signed-off-by: jongmyeongko --- CMakeLists.txt | 5 +- include/eventsystem_daemon.h | 46 ++ packaging/esd.spec | 2 +- src/esd_main.c | 977 +++++++++++++++++++++++------------ src/esd_system_event.c | 603 +++++++++++++++++++++ 5 files changed, 1309 insertions(+), 324 deletions(-) mode change 100755 => 100644 CMakeLists.txt create mode 100644 include/eventsystem_daemon.h mode change 100755 => 100644 packaging/esd.spec mode change 100755 => 100644 src/esd_main.c create mode 100644 src/esd_system_event.c diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index 7d16abc..06a859c --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,10 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") ##build eventsystem daemon -add_executable(esd src/esd_main.c) +add_executable(esd + src/esd_main.c + src/esd_system_event.c +) TARGET_LINK_LIBRARIES(esd eventsystem pkgmgr-client ${pkgs_LDFLAGS}) SET_TARGET_PROPERTIES(esd PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE") SET_TARGET_PROPERTIES(esd PROPERTIES LINK_FLAGS "-pie") diff --git a/include/eventsystem_daemon.h b/include/eventsystem_daemon.h new file mode 100644 index 0000000..a06821d --- /dev/null +++ b/include/eventsystem_daemon.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __EVENTSYSTEM_DAEMON_H__ +#define __EVENTSYSTEM_DAEMON_H__ + +/** + * header file for eventsystem_daemon + */ + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +#undef LOG_TAG +#define LOG_TAG "ESD" + +#define _E(fmt, arg...) LOGE(fmt, ##arg) +#define _D(fmt, arg...) LOGD(fmt, ##arg) +#define _W(fmt, arg...) LOGW(fmt, ##arg) +#define _I(fmt, arg...) LOGI(fmt, ##arg) + +#define ESD_BOOT_COMPLETED "/tmp/esd_ready" + +int __esd_register_vconf_callbacks(void); + +#endif /* __EVENTSYSTEM_DAEMONE_H__ */ + diff --git a/packaging/esd.spec b/packaging/esd.spec old mode 100755 new mode 100644 index 6965731..b942935 --- a/packaging/esd.spec +++ b/packaging/esd.spec @@ -2,7 +2,7 @@ Name: esd Summary: Event system daemon Version: 0.0.1 Release: 1 -Group: Application Framework/Daemons +Group: Application Framework/Service License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1: esd.service diff --git a/src/esd_main.c b/src/esd_main.c old mode 100755 new mode 100644 index bbb66ca..5486111 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -14,33 +14,18 @@ #include #include #include +#include "eventsystem_daemon.h" -#undef LOG_TAG -#define LOG_TAG "ESD" - -#define _E(fmt, arg...) LOGE(fmt, ##arg) -#define _D(fmt, arg...) LOGD(fmt, ##arg) -#define _W(fmt, arg...) LOGW(fmt, ##arg) -#define _I(fmt, arg...) LOGI(fmt, ##arg) - -#define retvm_if(expr, val, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - _E("(%s) -> %s() return", #expr, __func__); \ - return val; \ - } \ -} while (0) - -#define retv_if(expr, val) do { \ - if (expr) { \ - _E("(%s) -> %s() return", #expr, __func__); \ - return val; \ - } \ -} while (0) +static GHashTable *event_launch_table; /* table of events for launch_on_event*/ -#define ESD_BOOT_COMPLETED "/tmp/esd_ready" +static const char *allowed_event_list[] = { }; -static GHashTable *event_launch_table; /* table of events for launch_on_event*/ +static const char *event_launch_support_list[] = { + SYS_EVENT_BATTERY_CHARGER_STATUS, + SYS_EVENT_USB_STATUS, + SYS_EVENT_EARJACK_STATUS, + SYS_EVENT_INCOMMING_MSG +}; struct privilege_info { const char *event_name; @@ -60,7 +45,8 @@ static const char *earlier_event_list[] = { SYS_EVENT_ESD_STATUS, SYS_EVENT_LOW_MEMORY, SYS_EVENT_BOOT_COMPLETED, - SYS_EVENT_SYSTEM_SHUTDOWN + SYS_EVENT_SYSTEM_SHUTDOWN, + SYS_EVENT_BATTERY_CHARGER_STATUS }; static GHashTable *earlier_event_table; /* table of events for earlier_data */ @@ -125,18 +111,107 @@ static esd_info_s s_info; static void __esd_event_handler(char *event_name, bundle *data, void *user_data); static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *data); -static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) +/* TODO(jongmyeong.ko) */ +/* +static int __esd_get_visibility_from_cert_svc(const char *pkgid, int *visibility) +{ + int ret = ES_R_OK; + const char *cert_value = NULL; + pkgmgrinfo_certinfo_h certinfo = NULL; + + ret = pkgmgrinfo_pkginfo_create_certinfo(&certinfo); + if (ret != PMINFO_R_OK) { + _E("pkgmgrinfo_pkginfo_create_certinfo() failed."); + return ES_R_ERROR; + } + + ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, certinfo); + if (ret != PMINFO_R_OK) { + _E("pkgmgrinfo_pkginfo_load_certinfo() failed."); + ret = ES_R_ERROR; + goto end; + } + + ret = pkgmgrinfo_pkginfo_get_cert_value(certinfo, PMINFO_DISTRIBUTOR_ROOT_CERT, + &cert_value); + if (ret != PMINFO_R_OK) { + _E("pkgmgrinfo_pkginfo_get_cert_value() failed."); + ret = ES_R_ERROR; + goto end; + } + + ret = cert_svc_get_visibility_by_root_certificate(cert_value, + strlen(cert_value), visibility); + if (ret != CERT_SVC_ERR_NO_ERROR) { + _E("cert_svc_get_visibility_by_root_cert() failed. err = [%d]", ret); + ret = ES_R_ERROR; + goto end; + } + _D("visibility = [%d]", *visibility); + +end: + pkgmgrinfo_pkginfo_destroy_certinfo(certinfo); + + return ret; +} +*/ + +static int __esd_is_sending_allowed_event(const char *event_name) +{ + int i = 0; + int size = sizeof(allowed_event_list)/sizeof(*allowed_event_list); + + for (i = 0; i < size; i++) { + if (strcmp(allowed_event_list[i], event_name) == 0) { + return true; + } + } + + return false; +} + +#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE +static int __esd_check_earlier_support(const char *event_name) +{ + int i = 0; + int size = sizeof(earlier_event_list)/sizeof(*earlier_event_list); + + for (i = 0; i < size; i++) { + if (strcmp(earlier_event_list[i], event_name) == 0) { + return true; + } + } + + return false; +} +#endif + +static int __esd_check_event_launch_support(const char *event_name) +{ + int i = 0; + int size = sizeof(event_launch_support_list)/sizeof(*event_launch_support_list); + + for (i = 0; i < size; i++) { + if (strcmp(event_launch_support_list[i], event_name) == 0) { + return true; + } + } + + return false; +} + +static int __get_sender_unixinfo(GDBusConnection *conn, const char *sender_name, const char *type) { GDBusMessage *msg = NULL; GDBusMessage *reply = NULL; GError *err = NULL; GVariant *body; - int pid = 0; + int value = -1; msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", - "org.freedesktop.DBus", "GetConnectionUnixProcessID"); + "org.freedesktop.DBus", type); if (!msg) { - _D("Can't allocate new method call"); + _E("Can't allocate new method call"); goto out; } @@ -146,14 +221,14 @@ static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) if (!reply) { if (err != NULL) { - _E("Failed to get pid [%s]", err->message); + _E("Failed to get info [%s]", err->message); g_error_free(err); } goto out; } body = g_dbus_message_get_body(reply); - g_variant_get(body, "(u)", &pid); + g_variant_get(body, "(u)", &value); out: if (msg) @@ -161,11 +236,38 @@ out: if (reply) g_object_unref(reply); + return value; +} + +static int __get_sender_pid(GDBusConnection *conn, const char *sender_name) +{ + int pid = 0; + + pid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixProcessID"); + if (pid < 0) { + _E("failed to get pid"); + pid = 0; + } + _D("sender_name(%s), pid(%d)", sender_name, pid); return pid; } +static int __get_sender_uid(GDBusConnection *conn, const char *sender_name) +{ + int uid = -1; + + uid = __get_sender_unixinfo(conn, sender_name, "GetConnectionUnixUser"); + if (uid < 0) { + _E("failed to get uid"); + } + + _D("sender_name(%s), uid(%d)", sender_name, uid); + + return uid; +} + static int __esd_check_certificate_match(const char *app_id, const char *from_appid) { pkgmgrinfo_cert_compare_result_type_e res; @@ -204,7 +306,7 @@ static bool __esd_check_application_validation(const char *appid) return true; } -static void esd_trusted_busname_print_items(void) +static void __esd_trusted_busname_print_items(void) { GHashTableIter iter; gpointer key, value; @@ -219,7 +321,7 @@ static void esd_trusted_busname_print_items(void) } } -static int esd_trusted_busname_add_item(const char *appid, const char *busname, int pid) +static int __esd_trusted_busname_add_item(const char *appid, const char *busname, int pid) { char *app_id = NULL; char *bus_name = NULL; @@ -269,7 +371,7 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na GVariantIter *iter; gchar *str; char *ptr; - char tmp_appid[256] = {0, }; + char tmp_appid[128] = {0, }; int pid = 0; int ret = 0; @@ -296,7 +398,6 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na continue; } - _D("pid(%d)", pid); memset(tmp_appid, 0, sizeof(tmp_appid)); ret = aul_app_get_appid_bypid(pid, tmp_appid, sizeof(tmp_appid)); if (ret != AUL_R_OK) { @@ -307,7 +408,7 @@ static int __esd_check_trusted_events(GDBusConnection *conn, const char *list_na _D("appid(%s)", tmp_appid); if (__esd_check_application_validation(tmp_appid)) { _D("add to table"); - ret = esd_trusted_busname_add_item(tmp_appid, (const char *)str, pid); + ret = __esd_trusted_busname_add_item(tmp_appid, (const char *)str, pid); if (ret < 0) { _E("failed to add item"); } @@ -359,7 +460,7 @@ static bool __esd_check_valid_privilege(const char *appid, const char *privilege /* * ret = security_server_app_has_privilege(pkg_id, APP_TYPE_EFL, * privilege_name, &result); - * TODO : replace security_server api to cynara api. + * TODO(jongmyeong.ko) : replace security_server api to cynara api. */ result = 1; @@ -382,7 +483,7 @@ static bool __esd_check_valid_privilege(const char *appid, const char *privilege static int __esd_check_app_privileged_event(const char *appid, const char *event_name) { char *privilege_name = NULL; - int ret = 0; + int retval = 0; _D("appid(%s), event_name(%s)", appid, event_name); @@ -390,22 +491,15 @@ static int __esd_check_app_privileged_event(const char *appid, const char *event if (privilege_name && !__esd_check_valid_privilege(appid, privilege_name)) { _E("app(%s) has NOT privilege(%s)", appid, privilege_name); - ret = 0; + retval = 0; } else { - ret = 1; + retval = 1; } - return ret; -} - -void __esd_free_app_list(gpointer data) -{ - char *n = (char *)data; - - FREE_AND_NULL(n); + return retval; } -static void esd_print_appid_with_eventid(gpointer data, gpointer user_data) +static void __esd_print_appid_with_eventid(gpointer data, gpointer user_data) { esd_list_item_s *item = (esd_list_item_s *)data; char *event_name = (char *)user_data; @@ -413,15 +507,15 @@ static void esd_print_appid_with_eventid(gpointer data, gpointer user_data) _D("event_name(%s)-app_id(%s)-pkg_id(%s)", event_name, item->app_id, item->pkg_id); } -static void esd_print_interested_event(gpointer data, gpointer user_data) +static void __esd_print_interested_event(gpointer data, gpointer user_data) { event_launch_item *el_item = (event_launch_item *)data; char *event_name = (char *)el_item->event_name; _D("event_name = (%s)", event_name); - g_list_foreach(el_item->app_list_evtlaunch, esd_print_appid_with_eventid, event_name); + g_list_foreach(el_item->app_list_evtlaunch, __esd_print_appid_with_eventid, event_name); } -static void esd_launch_table_print_items(void) +static void __esd_launch_table_print_items(void) { GHashTableIter iter; gpointer key, value; @@ -429,11 +523,11 @@ static void esd_launch_table_print_items(void) g_hash_table_iter_init(&iter, event_launch_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - esd_print_interested_event(value, NULL); + __esd_print_interested_event(value, NULL); } } -static int esd_find_compare_by_list_item(gconstpointer data, gconstpointer user_data) +static int __esd_find_compare_by_list_item(gconstpointer data, gconstpointer user_data) { esd_list_item_s *item_1 = (esd_list_item_s *)user_data; esd_list_item_s *item_2 = (esd_list_item_s *)data; @@ -539,7 +633,7 @@ static int __esd_add_launch_item(const char *event_name, const char *appid) item_of_list->pkg_id = pkg_id; app_list = g_list_find_custom(el_item->app_list_evtlaunch, - item_of_list, (GCompareFunc)esd_find_compare_by_list_item); + item_of_list, (GCompareFunc)__esd_find_compare_by_list_item); free(item_of_list); if (app_list == NULL) { _D("add new item (list item only)"); @@ -614,7 +708,7 @@ static void __esd_remove_app_list(gpointer data, gpointer user_data) } } -static int esd_remove_launch_item(gpointer data, const char *pkg_id) +static int __esd_remove_launch_item(gpointer data, const char *pkg_id) { event_launch_item *eli = (event_launch_item *)data; GList *first_list = NULL; @@ -633,7 +727,7 @@ static int esd_remove_launch_item(gpointer data, const char *pkg_id) return ES_R_OK; } -static int esd_launch_table_remove_items(const char *pkg_id) +static int __esd_launch_table_remove_items(const char *pkg_id) { GHashTableIter iter; gpointer key, value; @@ -641,7 +735,7 @@ static int esd_launch_table_remove_items(const char *pkg_id) g_hash_table_iter_init(&iter, event_launch_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - if (esd_remove_launch_item(value, pkg_id) == ES_R_REMOVE) { + if (__esd_remove_launch_item(value, pkg_id) == ES_R_REMOVE) { _D("remove item itself"); g_hash_table_iter_remove(&iter); } @@ -650,7 +744,7 @@ static int esd_launch_table_remove_items(const char *pkg_id) return ES_R_OK; } -static void esd_event_launch_with_appid(gpointer data, gpointer user_data) +static void __esd_event_launch_with_appid(gpointer data, gpointer user_data) { esd_list_item_s *item = (esd_list_item_s *)data; char *app_id = item->app_id; @@ -687,18 +781,18 @@ static void esd_event_launch_with_appid(gpointer data, gpointer user_data) } } -static void esd_check_event_launch_with_eventid(gpointer data, gpointer user_data) +static void __esd_check_event_launch_with_eventid(gpointer data, gpointer user_data) { event_launch_item *el_item = (event_launch_item *)data; esd_event_param *eep = (esd_event_param *)user_data; if (strcmp(eep->event_name, (char *)el_item->event_name) == 0) { g_list_foreach(el_item->app_list_evtlaunch, - esd_event_launch_with_appid, user_data); + __esd_event_launch_with_appid, user_data); } } -static void __esd_event_handler(char *event_name, bundle *data, void *user_data) +static void __esd_launch_event_handler(char *event_name, bundle *data, void *user_data) { _D("event_name(%s)", event_name); @@ -710,6 +804,37 @@ static void __esd_event_handler(char *event_name, bundle *data, void *user_data) } if (el_item->app_list_evtlaunch != NULL) { + if (strcmp(SYS_EVENT_BATTERY_CHARGER_STATUS, event_name) == 0) { + const char *val = bundle_get_val(data, EVT_KEY_BATTERY_CHARGER_STATUS); + _D("charger val(%s)", val); + if (strcmp(EVT_VAL_BATTERY_CHARGER_CONNECTED, val) != 0) { + return; + } + } else if (strcmp(SYS_EVENT_USB_STATUS, event_name) == 0) { + const char *val = bundle_get_val(data, EVT_KEY_USB_STATUS); + _D("usb val(%s)", val); + if (strcmp(EVT_VAL_USB_CONNECTED, val) != 0) { + return; + } + } else if (strcmp(SYS_EVENT_EARJACK_STATUS, event_name) == 0) { + const char *val = bundle_get_val(data, EVT_KEY_EARJACK_STATUS); + _D("earjack val(%s)", val); + if (strcmp(EVT_VAL_EARJACK_CONNECTED, val) != 0) { + return; + } + } else if (strcmp(SYS_EVENT_INCOMMING_MSG, event_name) == 0) { + const char *msg_type = bundle_get_val(data, EVT_KEY_MSG_TYPE); + _D("msg_type(%s)", msg_type); + if (msg_type == NULL) { + return; + } + const char *msg_id = bundle_get_val(data, EVT_KEY_MSG_ID); + _D("msg_id(%s)", msg_id); + if (msg_id == NULL) { + return; + } + } + esd_event_param *eep = calloc(1, sizeof(esd_event_param)); if (!eep) { _E("memory alloc failed"); @@ -718,12 +843,53 @@ static void __esd_event_handler(char *event_name, bundle *data, void *user_data) eep->event_name = event_name; eep->event_data = data; eep->user_data = (void *)user_data; - esd_check_event_launch_with_eventid(el_item, eep); + __esd_check_event_launch_with_eventid(el_item, eep); free(eep); } } #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE +static void __esd_print_earlier_event(gpointer data, gpointer user_data) +{ + earlier_item *item = (earlier_item *)data; + char *event_name = (char *)item->event_name; + _D("event_name = (%s)", event_name); + + if (strcmp(event_name, SYS_EVENT_BOOT_COMPLETED) == 0) { + if (item->earlier_data) { + const char *val = bundle_get_val(item->earlier_data, EVT_KEY_BOOT_COMPLETED); + _D("boot_completed(%s)", val); + } + } else if (strcmp(event_name, SYS_EVENT_SYSTEM_SHUTDOWN) == 0) { + if (item->earlier_data) { + const char *val = bundle_get_val(item->earlier_data, EVT_KEY_SYSTEM_SHUTDOWN); + _D("shutdown(%s)", val); + } + } else if (strcmp(event_name, SYS_EVENT_LOW_MEMORY) == 0) { + if (item->earlier_data) { + const char *val = bundle_get_val(item->earlier_data, EVT_KEY_LOW_MEMORY); + _D("low_memory(%s)", val); + } + } else if (strcmp(event_name, SYS_EVENT_BATTERY_CHARGER_STATUS) == 0) { + if (item->earlier_data) { + const char *val = bundle_get_val(item->earlier_data, EVT_KEY_BATTERY_CHARGER_STATUS); + _D("charger_status(%s)", val); + } + } +} + +static void __esd_earlier_table_print_items(void) +{ + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init(&iter, earlier_event_table); + + while (g_hash_table_iter_next(&iter, &key, &value)) { + __esd_print_earlier_event(value, NULL); + } +} + static void __esd_earlier_event_handler(char *event_name, bundle *data, void *user_data) { _D("event_name(%s)", event_name); @@ -750,10 +916,32 @@ static void __esd_earlier_event_handler(char *event_name, bundle *data, void *us } #endif +static void __esd_event_handler(char *event_name, bundle *data, void *user_data) +{ + _D("event_name(%s)", event_name); + +#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE + if (__esd_check_earlier_support(event_name)) { + __esd_earlier_event_handler(event_name, data, user_data); + } +#endif + + if (__esd_check_event_launch_support(event_name)) { + __esd_launch_event_handler(event_name, data, user_data); + } +} + + static GDBusNodeInfo *introspection_data; static const gchar introspection_xml[] = "" " " +" " +" " +" " +" " +" " +" " " " " " " " @@ -801,45 +989,157 @@ static const gchar introspection_xml[] = " " ""; -static void handle_method_call(GDBusConnection *connection, - const gchar *sender, const gchar *object_path, - const gchar *interface_name, const gchar *method_name, - GVariant *parameters, GDBusMethodInvocation *invocation, - gpointer user_data) +static int __esd_get_appid_by_pid(int pid, char *app_id, int buf_size) +{ + int retval = ES_R_OK; + int ret = 0; + + if (pid > 0) { + ret = aul_app_get_appid_bypid(pid, app_id, buf_size); + if (ret != AUL_R_OK) { + _E("failed to get appid by pid"); + retval = ES_R_ERROR; + } + _D("pid(%d)-appid(%s)", pid, app_id); + } else { + _E("invalid pid"); + retval = ES_R_ERROR; + } + + return retval; +} + +static int check_user_event_sender_valid(const char *event_name, const char *app_id) +{ + char *valid_name = NULL; + char *temp_name = NULL; + char *tmp = NULL; + int retval = ES_R_OK; + int len = 0; + int valid_name_len = 0; + + temp_name = strdup(event_name); + if (temp_name == NULL) { + _E("out of memory"); + return ES_R_ENOMEM; + } + + tmp = strrchr(temp_name, '.'); + if (tmp == NULL || strlen(tmp) == 0) { + _E("invalid event name"); + FREE_AND_NULL(temp_name); + return ES_R_EINVAL; + } + len = strlen(tmp); + if (len <= 1 || len > 128) { + _E("invalid length(%d) of user-defined name"); + FREE_AND_NULL(temp_name); + return ES_R_EINVAL; + } + *tmp = '\0'; + + _D("app_id(%s), len(%d)", app_id, strlen(app_id)); + + valid_name_len = strlen(USER_EVENT_NAME_PREFIX) + strlen(app_id) + 1; + valid_name = calloc(1, valid_name_len); + if (valid_name == NULL) { + _E("memory alloc failed"); + FREE_AND_NULL(temp_name); + return ES_R_ENOMEM; + } + snprintf(valid_name, valid_name_len, "%s%s", USER_EVENT_NAME_PREFIX, app_id); + _D("valid_name(%s)", valid_name); + + if (strcmp(temp_name, valid_name) != 0) { + _E("appid misamatch"); + retval = ES_R_EINVAL; + } + + FREE_AND_NULL(temp_name); + FREE_AND_NULL(valid_name); + + return retval; +} + +static void check_sender_valid_method_call(GVariant *parameters, + GDBusMethodInvocation *invocation) { GVariant *param = NULL; int result = 0; + char *event_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; - if (g_strcmp0(method_name, "GetTrustedPeerList") == 0) { - GVariantBuilder *builder = NULL; - GHashTableIter iter; - gpointer key, value; - char *event_name = NULL; - char app_id[256] = {0, }; - int sender_pid = 0; - int ret = 0; - char *_appid = NULL; - char *_busname = NULL; + g_variant_get(parameters, "(is)", &sender_pid, &event_name); + _D("sender_pid(%d), event_name(%s)", sender_pid, event_name); + + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { + if (check_user_event_sender_valid(event_name, app_id) < 0) { + _E("invalid sender"); + result = ES_R_EINVAL; + } else { + result = 1; + } + } - g_variant_get(parameters, "(s)", &event_name); + param = g_variant_new("(is)", result, app_id); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} - _D("event_name(%s)", event_name); +static void check_send_event_valid_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; - sender_pid = __get_sender_pid(connection, sender); + g_variant_get(parameters, "(s)", &event_name); + _D("event_name(%s)", event_name); - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); - result = ES_R_ERROR; - goto out_get_trust; - } + sender_pid = __get_sender_pid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { + if (check_user_event_sender_valid(event_name, app_id) < 0) { + _E("invalid sender"); + result = ES_R_EINVAL; } else { - _E("failed to get sender_pid"); - result = ES_R_ERROR; - goto out_get_trust; + result = 1; } + } + + param = g_variant_new("(i)", result); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} + +static void get_trusted_peer_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + GVariantBuilder *builder = NULL; + GHashTableIter iter; + gpointer key, value; + char *event_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; + int ret = 0; + char *_appid = NULL; + char *_busname = NULL; + g_variant_get(parameters, "(s)", &event_name); + _D("event_name(%s)", event_name); + + sender_pid = __get_sender_pid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { builder = g_variant_builder_new(G_VARIANT_TYPE("as")); g_hash_table_iter_init(&iter, trusted_busname_table); @@ -855,252 +1155,226 @@ static void handle_method_call(GDBusConnection *connection, } result = 1; -out_get_trust: - param = g_variant_new("(ias)", result, builder); - _D("result(%d)", result); - g_dbus_method_invocation_return_value(invocation, param); - if (builder) - g_variant_builder_unref(builder); - } else if (g_strcmp0(method_name, "SetupTrustedPeer") == 0) { - char *event_name = NULL; - char *destination_name = NULL; - char app_id[256] = {0, }; - int sender_pid = 0; - int ret = 0; - - g_variant_get(parameters, "(ss)", &event_name, &destination_name); + } - _D("event_name(%s), destination_name(%s)", event_name, destination_name); + param = g_variant_new("(ias)", result, builder); + _D("result(%d)", result); + g_dbus_method_invocation_return_value(invocation, param); + if (builder) { + g_variant_builder_unref(builder); + } +} - if (destination_name && destination_name[0] != '\0') { - sender_pid = __get_sender_pid(connection, sender); +static void setup_trusted_peer_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + char *destination_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; + int ret = 0; - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); - result = ES_R_ERROR; - goto out_trust; - } - } else { - _E("failed to get sender_pid"); - result = ES_R_ERROR; - goto out_trust; - } + g_variant_get(parameters, "(ss)", &event_name, &destination_name); + _D("event_name(%s), destination_name(%s)", event_name, destination_name); - ret = esd_trusted_busname_add_item(app_id, destination_name, sender_pid); + if (destination_name && destination_name[0] != '\0') { + sender_pid = __get_sender_pid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { + ret = __esd_trusted_busname_add_item(app_id, destination_name, + sender_pid); if (ret < 0) { _E("failed to add trusted busname item"); result = ES_R_ERROR; - } else - result = 1; - } else { - _E("invalid destination name"); - result = ES_R_ERROR; - } - -out_trust: - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "CheckPrivilegeValidation") == 0) { - char *event_name = NULL; - char *privilege_name = NULL; - char app_id[256] = {0, }; - int sender_pid = 0; - int ret = 0; - - g_variant_get(parameters, "(s)", &event_name); - - __esd_check_privilege_name(event_name, &privilege_name); - - _D("event_name(%s), privilege_name(%s)", event_name, privilege_name); - - if (privilege_name) { - sender_pid = __get_sender_pid(connection, sender); - - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); - result = ES_R_ERROR; - goto out_priv; - } } else { - _E("failed to get sender_pid"); - result = ES_R_ERROR; - goto out_priv; - } - - if (__esd_check_valid_privilege(app_id, privilege_name)) { result = 1; - } else { - result = ES_R_EINVAL; } - } else { - result = 1; } -out_priv: - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "CheckUserSendValidation") == 0) { - char *event_name = NULL; - char app_id[256] = {0, }; - char valid_name[1024]; - int sender_pid = 0; - int ret = 0; - int len = 0; + } else { + _E("invalid destination name"); + result = ES_R_ERROR; + } - g_variant_get(parameters, "(s)", &event_name); + param = g_variant_new("(i)", result); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} - _D("event_name(%s)", event_name); +static void check_privilege_valid_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + char *privilege_name = NULL; + char app_id[128] = {0, }; + int sender_pid = 0; - sender_pid = __get_sender_pid(connection, sender); + g_variant_get(parameters, "(s)", &event_name); + __esd_check_privilege_name(event_name, &privilege_name); + _D("event_name(%s), privilege_name(%s)", event_name, privilege_name); - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); - result = ES_R_ERROR; - goto out_send; - } - } else { - _E("failed to get sender_pid"); + if (privilege_name) { + sender_pid = __get_sender_pid(connection, sender); + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { result = ES_R_ERROR; - goto out_send; - } - - snprintf(valid_name, 1024, "%s%s.", USER_EVENT_NAME_PREFIX, app_id); - len = strlen(valid_name); - - _D("valid_name(%s)", valid_name); - - if (strncmp(event_name, valid_name, len) != 0) { - _E("appid misamatch"); - result = ES_R_EINVAL; - goto out_send; } else { - len = strlen(event_name) - len; - if (len < 1 || len > 127) { - _E("Invalid Length of user-defined name"); + if (__esd_check_valid_privilege(app_id, privilege_name)) { + result = 1; + } else { result = ES_R_EINVAL; - goto out_send; } } - + } else { result = 1; -out_send: - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "RequestEventLaunch") == 0) { - char *event_name = NULL; - bundle_raw *raw = NULL; - bundle *b = NULL; - int len = 0; - - g_variant_get(parameters, "(ssi)", &event_name, &raw, &len); - - b = bundle_decode(raw, len); - __esd_event_handler(event_name, b, NULL); - bundle_free(b); + } - result = 1; + param = g_variant_new("(i)", result); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "RequestTrustedEventLaunch") == 0) { - char app_id[256] = {0, }; - int sender_pid = 0; - int ret = 0; - char *event_name = NULL; - bundle_raw *raw = NULL; - bundle *b = NULL; - int len = 0; +static void request_sending_event_method_call(GDBusConnection *connection, const gchar *sender, + GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + bundle_raw *raw = NULL; + bundle *b = NULL; + int len = 0; + const char *access_rule = NULL; + const char *check_object = NULL; + char app_id[128] = {0, }; + char *pkg_id = NULL; + int sender_pid = 0; + int sender_uid = -1; + int visibility = 0; + int send_flag = 0; + int ret = 0; - g_variant_get(parameters, "(ssi)", &event_name, &raw, &len); + g_variant_get(parameters, "(ssi)", &event_name, &raw, &len); + _D("event_name(%s)", event_name); - _D("requested trusted-event launch"); + if (!__esd_is_sending_allowed_event(event_name)) { + /* no effect */ + _E("not allowed"); + result = 1; + goto end; + } - sender_pid = __get_sender_pid(connection, sender); + sender_uid = __get_sender_uid(connection, sender); + _D("uid(%d), getuid(%d)", sender_uid, getuid()); + if (sender_uid >= 0 && sender_uid <= getuid()) { + send_flag = 1; + goto end; + } - if (sender_pid > 0) { - ret = aul_app_get_appid_bypid(sender_pid, app_id, sizeof(app_id)); - if (ret != AUL_R_OK) { - _E("failed to get appid by sender_pid"); + /* TODO(jongmyeong.ko) */ + /* + sender_pid = __get_sender_pid(connection, sender); + if (sender_pid > 0) { + if (__esd_get_appid_by_pid(sender_pid, app_id, sizeof(app_id)) < 0) { + result = ES_R_ERROR; + } else { + if (__esd_get_pkgid_by_appid(app_id, &pkg_id) < 0) { result = ES_R_ERROR; - goto out_trust_launch; } - } else { - _E("failed to get sender_pid"); + } + } + + if (pkg_id) { + if (__esd_get_visibility_from_cert_svc(pkg_id, &visibility) < 0) { result = ES_R_ERROR; - goto out_trust_launch; + } else { + if (visibility == CERT_SVC_VISIBILITY_PLATFORM) { + _D("platfrom package"); + send_flag = 1; + } } + FREE_AND_NULL(pkg_id); + } + */ - _D("from_appid(%s)", app_id); +end: + if (send_flag) { b = bundle_decode(raw, len); - __esd_event_handler(event_name, b, app_id); + eventsystem_send_system_event(event_name, b); bundle_free(b); - result = 1; -out_trust_launch: - param = g_variant_new("(i)", result); - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); - } else if (g_strcmp0(method_name, "RequestSendingEvent") == 0) { - char *event_name = NULL; - bundle_raw *raw = NULL; - bundle *b = NULL; - int len = 0; - - g_variant_get(parameters, "(ssi)", &event_name, &raw, &len); + } - b = bundle_decode(raw, len); - eventsystem_send_system_event(event_name, b); - bundle_free(b); + param = g_variant_new("(i)", result); - result = 1; - param = g_variant_new("(i)", result); + _D("event_name(%s), result(%d)", event_name, result); + g_dbus_method_invocation_return_value(invocation, param); +} - _D("event_name(%s), result(%d)", event_name, result); - g_dbus_method_invocation_return_value(invocation, param); #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE - } else if (g_strcmp0(method_name, "GetEarlierData") == 0) { - char *event_name = NULL; - bundle *b = NULL; - bundle_raw *raw = NULL; - int len = 0; +static void get_earlier_data_method_call(GVariant *parameters, GDBusMethodInvocation *invocation) +{ + GVariant *param = NULL; + int result = 0; + char *event_name = NULL; + bundle *b = NULL; + bundle_raw *raw = NULL; + int len = 0; - g_variant_get(parameters, "(s)", &event_name); + g_variant_get(parameters, "(s)", &event_name); - if (event_name && strlen(event_name) > 0) { - _D("event_name(%s)", event_name); - result = ES_R_OK; - } else { - _E("invalid appid(%s)", event_name); - result = ES_R_ERROR; - } + if (event_name && strlen(event_name) > 0) { + _D("event_name(%s)", event_name); + result = ES_R_OK; + } else { + _E("invalid event_name(%s)", event_name); + result = ES_R_ERROR; + } - earlier_item *item = - (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); + earlier_item *item = + (earlier_item *)g_hash_table_lookup(earlier_event_table, event_name); - if (item != NULL) { - if (item->earlier_data) { - b = bundle_dup(item->earlier_data); - bundle_add_str(b, "is_earlier_data", "true"); - bundle_encode(b, &raw, &len); - bundle_free(b); - } + if (item != NULL) { + if (item->earlier_data) { + b = bundle_dup(item->earlier_data); + bundle_add_str(b, "is_earlier_data", "true"); + bundle_encode(b, &raw, &len); + bundle_free(b); } + } - param = g_variant_new("(iis)", result, len, raw); + param = g_variant_new("(iis)", result, len, raw); - _D("result(%d), len(%d)", result, len); - g_dbus_method_invocation_return_value(invocation, param); + _D("result(%d), len(%d)", result, len); + g_dbus_method_invocation_return_value(invocation, param); + + bundle_free_encoded_rawdata(&raw); +} +#endif - bundle_free_encoded_rawdata(&raw); +static void handle_method_call(GDBusConnection *connection, + const gchar *sender, const gchar *object_path, + const gchar *interface_name, const gchar *method_name, + GVariant *parameters, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + if (g_strcmp0(method_name, "CheckSenderValidation") == 0) { + check_sender_valid_method_call(parameters, invocation); + } else if (g_strcmp0(method_name, "GetTrustedPeerList") == 0) { + get_trusted_peer_method_call(connection, sender, parameters, invocation); + } else if (g_strcmp0(method_name, "SetupTrustedPeer") == 0) { + setup_trusted_peer_method_call(connection, sender, parameters, invocation); + } else if (g_strcmp0(method_name, "CheckPrivilegeValidation") == 0) { + check_privilege_valid_method_call(connection, sender, parameters, invocation); + } else if (g_strcmp0(method_name, "CheckUserSendValidation") == 0) { + check_send_event_valid_method_call(connection, sender, parameters, invocation); + } else if (g_strcmp0(method_name, "RequestSendingEvent") == 0) { + request_sending_event_method_call(connection, sender, parameters, invocation); +#ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE + } else if (g_strcmp0(method_name, "GetEarlierData") == 0) { + get_earlier_data_method_call(parameters, invocation); #endif } } @@ -1114,7 +1388,7 @@ static const GDBusInterfaceVTable interface_vtable = { static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { - _D("on_bus_acquired(%s)", name); + _I("on_bus_acquired(%s)", name); guint reg_id = 0; GError *error = NULL; @@ -1133,7 +1407,7 @@ static void on_bus_acquired(GDBusConnection *connection, static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { - _D("on_name_acquired(%s)", name); + _I("on_name_acquired(%s)", name); __esd_check_trusted_events(connection, "ListNames"); __esd_check_trusted_events(connection, "ListActivatableNames"); @@ -1143,13 +1417,15 @@ static void on_name_acquired(GDBusConnection *connection, eventsystem_send_system_event(SYS_EVENT_ESD_STATUS, b); bundle_free(b); - esd_trusted_busname_print_items(); + __esd_register_vconf_callbacks(); + + __esd_trusted_busname_print_items(); } static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data) { - _D("on_name_lost(%s)", name); + _E("on_name_lost(%s)", name); } static int __esd_before_loop(void) @@ -1193,6 +1469,20 @@ static int __esd_before_loop(void) EVT_VAL_BOOT_COMPLETED_TRUE); close(fd); } + } else if (strcmp(event_name, SYS_EVENT_SYSTEM_SHUTDOWN) == 0) { + int val; + ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val); + if (ret != VCONF_OK) { + _E("failed to get power_off status (%d)", ret); + } else { + if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || + val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) { + /* power-off requested */ + item->earlier_data = bundle_create(); + bundle_add_str(item->earlier_data, EVT_KEY_SYSTEM_SHUTDOWN, + EVT_VAL_SYSTEM_SHUTDOWN_TRUE); + } + } } else if (strcmp(event_name, SYS_EVENT_LOW_MEMORY) == 0) { int status; ret = vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &status); @@ -1210,19 +1500,58 @@ static int __esd_before_loop(void) bundle_add_str(item->earlier_data, EVT_KEY_LOW_MEMORY, EVT_VAL_MEMORY_NORMAL); } + } else if (strcmp(event_name, SYS_EVENT_BATTERY_CHARGER_STATUS) == 0) { + int charger_status; + int charge_now; + ret = vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &charger_status); + if (ret != VCONF_OK) { + _E("failed to get charger_status (%d)", ret); + } else { + ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &charge_now); + if (ret != VCONF_OK) { + _E("failed to get charge_now (%d)", ret); + } + } + + if (ret == VCONF_OK) { + item->earlier_data = bundle_create(); + if (charger_status == VCONFKEY_SYSMAN_CHARGER_CONNECTED) { + if (charge_now == 0) { + bundle_add_str(item->earlier_data, + EVT_KEY_BATTERY_CHARGER_STATUS, + EVT_VAL_BATTERY_CHARGER_DISCHARGING); + } else { + bundle_add_str(item->earlier_data, + EVT_KEY_BATTERY_CHARGER_STATUS, + EVT_VAL_BATTERY_CHARGER_CHARGING); + } + } else { + bundle_add_str(item->earlier_data, + EVT_KEY_BATTERY_CHARGER_STATUS, + EVT_VAL_BATTERY_CHARGER_DISCONNECTED); + } + } } - g_hash_table_insert(earlier_event_table, event_name, item); - eventsystem_register_event(item->event_name, &subscription_id, - (eventsystem_handler)__esd_earlier_event_handler, NULL); + eventsystem_register_event(event_name, &subscription_id, + (eventsystem_handler)__esd_event_handler, NULL); if (subscription_id == 0) { - _E("signal subscription error, event_name(%s)", item->event_name); + _E("signal subscription error, event_name(%s)", event_name); + if (item->earlier_data) + bundle_free(item->earlier_data); + free(item->event_name); + free(item); + return ES_R_ERROR; } else { item->reg_id = subscription_id; } + + g_hash_table_insert(earlier_event_table, event_name, item); } + + __esd_earlier_table_print_items(); #endif event_launch_table = g_hash_table_new(g_str_hash, g_str_equal); @@ -1233,7 +1562,7 @@ static int __esd_before_loop(void) _E("pkgmgrinfo_appinfo_get_usr_installed_list error"); return ES_R_ERROR; } - esd_launch_table_print_items(); + __esd_launch_table_print_items(); trusted_busname_table = g_hash_table_new(g_str_hash, g_str_equal); @@ -1262,10 +1591,12 @@ static int __esd_before_loop(void) return ES_R_ERROR; } + _I("esd before_loop done"); + return ES_R_OK; } -static void esd_pkgmgr_event_free(esd_pkgmgr_event *pkg_event) +static void __esd_pkgmgr_event_free(esd_pkgmgr_event *pkg_event) { pkg_event->type = UNKNOWN; if (pkg_event->pkgid) { @@ -1289,7 +1620,9 @@ static int __esd_appcontrol_cb(const char *operation, event_name = strdup(&uri[8]); if (event_name) { _D("appid(%s), event_name(%s)", appid, event_name); - if (!__esd_check_app_privileged_event(appid, event_name)) { + if (!__esd_check_event_launch_support(event_name)) { + _E("failed to add item (not support event)"); + } else if (!__esd_check_app_privileged_event(appid, event_name)) { _E("failed to add item (no privilege)"); } else { if (__esd_add_launch_item(event_name, appid)) { @@ -1333,13 +1666,13 @@ static int __esd_add_appinfo_handler(const pkgmgrinfo_appinfo_h handle, void *da _E("failed to get appcontrol info"); return ES_R_ERROR; } - esd_launch_table_print_items(); + __esd_launch_table_print_items(); } return ES_R_OK; } -static int esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_type, +static int __esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_type, const char *pkgid, const char *key, const char *val, const void *pmsg, void *data) { @@ -1362,7 +1695,7 @@ static int esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_type pkg_event->type = UPDATE; } else { _D("val(%s) start", val); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); } } else if (strcmp(key, "end") == 0 && strcmp(val, "ok") == 0) { if (pkg_event->type == INSTALL || pkg_event->type == UPDATE) { @@ -1370,34 +1703,34 @@ static int esd_pkgmgr_event_callback(uid_t uid, int req_id, const char *pkg_type ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); if (ret < 0) { _E("failed to get pkginfo"); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); return 0; } ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, __esd_add_appinfo_handler, NULL); if (ret < 0) { _E("failed to get appinfo"); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); return 0; } ret = pkgmgrinfo_pkginfo_destroy_pkginfo(handle); if (ret < 0) { _E("failed to destroy pkginfo"); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); return 0; } } else if (pkg_event->type == UNINSTALL) { _D("uninstall end (ok)"); - esd_launch_table_remove_items(pkgid); - esd_launch_table_print_items(); + __esd_launch_table_remove_items(pkgid); + __esd_launch_table_print_items(); } - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); } else if (strcmp(key, "end") == 0 && strcmp(val, "fail") == 0) { _E("pkg_event(%d) falied", pkg_event->type); - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); } else { if (strcmp(key, "install_percent") != 0) { - esd_pkgmgr_event_free(pkg_event); + __esd_pkgmgr_event_free(pkg_event); } } @@ -1460,7 +1793,7 @@ static int __esd_init() return ES_R_ENOMEM; } - req_id = pkgmgr_client_listen_status(client, esd_pkgmgr_event_callback, pkg_event); + req_id = pkgmgr_client_listen_status(client, __esd_pkgmgr_event_callback, pkg_event); if (req_id < 0) { _E("pkgmgr client listen failed"); ret = pkgmgr_client_free(client); @@ -1472,12 +1805,12 @@ static int __esd_init() s_info.client = client; - _D("ESD init done\n"); + _I("esd init done"); return 0; } -static void esd_remove_app_list(gpointer data, gpointer user_data) +static void __esd_remove_esd_list_item(gpointer data, gpointer user_data) { esd_list_item_s *item = (esd_list_item_s *)data; @@ -1485,7 +1818,7 @@ static void esd_remove_app_list(gpointer data, gpointer user_data) free(item->pkg_id); } -static void esd_finalize(void) +static void __esd_finalize(void) { gpointer key, value; int ret = 0; @@ -1544,7 +1877,7 @@ static void esd_finalize(void) eventsystem_unregister_event(el_item->reg_id); free(el_item->event_name); g_list_foreach(el_item->app_list_evtlaunch, - esd_remove_app_list, NULL); + __esd_remove_esd_list_item, NULL); g_list_free(el_item->app_list_evtlaunch); free(el_item); } else { @@ -1571,17 +1904,17 @@ static void esd_finalize(void) int main(int argc, char *argv[]) { - _D("event system daemon : main()\n"); + _I("event system daemon : main()"); if (__esd_init() != 0) { - _E("ESD Initialization failed!\n"); + _E("ESD Initialization failed!"); assert(0); return ES_R_ERROR; } if (__esd_before_loop() < 0) { - _E("ESD failed!\n"); - esd_finalize(); + _E("ESD failed!"); + __esd_finalize(); assert(0); return ES_R_ERROR; } @@ -1590,7 +1923,7 @@ int main(int argc, char *argv[]) _E("shutdown"); - esd_finalize(); + __esd_finalize(); ecore_shutdown(); diff --git a/src/esd_system_event.c b/src/esd_system_event.c new file mode 100644 index 0000000..5579ac5 --- /dev/null +++ b/src/esd_system_event.c @@ -0,0 +1,603 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "eventsystem_daemon.h" + +/* table item : sent system-event by esd */ +static GHashTable *esd_sent_table; + +typedef struct __esd_sent_table_item { + char *event_name; + bundle *event_data; +} esd_sent_item; + +struct esd_vconf_handler { + const char *key; + void (*esd_vconfcb_fn) (keynode_t *node, void *user_data); +}; + +static int __esd_event_data_compare(bundle *b1, bundle *b2, const char *key) +{ + int ret = 0; + int tmp1 = 0; + int tmp2 = 0; + char *str1 = NULL; + char *str2 = NULL; + + if (bundle_get_count(b1) == bundle_get_count(b2)) { + tmp1 = bundle_get_str(b1, key, &str1); + tmp2 = bundle_get_str(b2, key, &str2); + if (tmp1 == BUNDLE_ERROR_NONE && tmp2 == BUNDLE_ERROR_NONE) { + if (strcmp(str1, str2) != 0) { + _D("new event_data : value check"); + ret = 1; + } + } + } else { + _D("new event_data : bundle_count check"); + ret = 1; + } + + if (ret == 0) { + _D("same event_data"); + } + + return ret; +} + +static int __esd_send_system_event(const char *event_name, bundle *b, const char *key) +{ + int ret = ES_R_OK; + + esd_sent_item *item = + (esd_sent_item *)g_hash_table_lookup(esd_sent_table, event_name); + + if (item && __esd_event_data_compare(item->event_data, b, key) == 0) { + _D("skip send: same with previous data"); + } else { + ret = eventsystem_send_system_event(event_name, b); + if (ret != ES_R_OK) { + _E("failed to send event"); + goto out; + } + + if (item) { + bundle_free(item->event_data); + item->event_data = bundle_dup(b); + } else { + item = calloc(1, sizeof(esd_sent_item)); + if (item == NULL) { + _E("memory alloc failed"); + ret = ES_R_ERROR; + goto out; + } + item->event_name = strdup(event_name); + if (item->event_name == NULL) { + _E("out of memory"); + FREE_AND_NULL(item); + ret = ES_R_ERROR; + goto out; + } + item->event_data = bundle_dup(b); + } + + g_hash_table_insert(esd_sent_table, item->event_name, item); + } + +out: + return ret; +} + +static void __esd_vconfcb_location_use_mylocation(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_int(VCONFKEY_LOCATION_USE_MY_LOCATION, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_LOCATION_ENABLE_STATE; + + if (enabled) { + val = EVT_VAL_LOCATION_ENABLED; + } else { + val = EVT_VAL_LOCATION_DISABLED; + } + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_LOCATION_ENABLE_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_location_enabled(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_int(VCONFKEY_LOCATION_ENABLED, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_GPS_ENABLE_STATE; + + if (enabled) { + val = EVT_VAL_GPS_ENABLED; + } else { + val = EVT_VAL_GPS_DISABLED; + } + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_GPS_ENABLE_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_location_network_enabled(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_int(VCONFKEY_LOCATION_NETWORK_ENABLED, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_NPS_ENABLE_STATE; + + if (enabled) { + val = EVT_VAL_NPS_ENABLED; + } else { + val = EVT_VAL_NPS_DISABLED; + } + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_NPS_ENABLE_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_language_set(keynode_t *node, void *user_data) +{ + char *str = 0; + bundle *b = NULL; + const char *key = NULL; + + _D("vconfcb called"); + + str = vconf_get_str(VCONFKEY_LANGSET); + if (str == NULL) { + _E("failed to get vconf str"); + return; + } + + key = EVT_KEY_LANGUAGE_SET; + + b = bundle_create(); + bundle_add_str(b, key, str); + + if (__esd_send_system_event(SYS_EVENT_LANGUAGE_SET, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_hour_format(keynode_t *node, void *user_data) +{ + int ret = 0; + int hours = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &hours); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_HOUR_FORMAT; + + if (hours == VCONFKEY_TIME_FORMAT_24) + val = EVT_VAL_HOURFORMAT_24; + else + val = EVT_VAL_HOURFORMAT_12; + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_HOUR_FORMAT, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_region_format(keynode_t *node, void *user_data) +{ + char *str = 0; + bundle *b = NULL; + const char *key = NULL; + + _D("vconfcb called"); + + str = vconf_get_str(VCONFKEY_REGIONFORMAT); + if (str == NULL) { + _E("failed to get vconf str"); + return; + } + + key = EVT_KEY_REGION_FORMAT; + + b = bundle_create(); + bundle_add_str(b, key, str); + + if (__esd_send_system_event(SYS_EVENT_REGION_FORMAT, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_vibration_status(keynode_t *node, void *user_data) +{ + int ret = 0; + int vibration_on = 0; + int sound_on = 0; + bundle *b = NULL; + char *key = NULL; + char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + if (vibration_on) { + key = EVT_KEY_VIBRATION_STATE; + val = EVT_VAL_VIBRATION_ON; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + + key = EVT_KEY_SILENT_MODE; + val = EVT_VAL_SILENTMODE_OFF; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + } else { + key = EVT_KEY_VIBRATION_STATE; + val = EVT_VAL_VIBRATION_OFF; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + + if (!sound_on) { + key = EVT_KEY_SILENT_MODE; + val = EVT_VAL_SILENTMODE_ON; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + } + } +} + +static void __esd_vconfcb_sound_status(keynode_t *node, void *user_data) +{ + int ret = 0; + int vibration_on = 0; + int sound_on = 0; + bundle *b = NULL; + char *key = NULL; + char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &vibration_on); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + ret = vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sound_on); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + if (sound_on) { + key = EVT_KEY_VIBRATION_STATE; + val = EVT_VAL_VIBRATION_OFF; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_VIBRATION_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + + key = EVT_KEY_SILENT_MODE; + val = EVT_VAL_SILENTMODE_OFF; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + } else { + if (!vibration_on) { + key = EVT_KEY_SILENT_MODE; + val = EVT_VAL_SILENTMODE_ON; + b = bundle_create(); + bundle_add_str(b, key, val); + if (__esd_send_system_event(SYS_EVENT_SILENT_MODE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + if (b) { + bundle_free(b); + } + } + } +} + +static void __esd_vconfcb_auto_rotate(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_SCREEN_AUTOROTATE_STATE; + + if (enabled) + val = EVT_VAL_SCREEN_AUTOROTATE_ON; + else + val = EVT_VAL_SCREEN_AUTOROTATE_OFF; + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_SCREEN_AUTOROTATE_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_mobiledata_state(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_3G_ENABLE, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_MOBILE_DATA_STATE; + + if (enabled) + val = EVT_VAL_MOBILE_DATA_ON; + else + val = EVT_VAL_MOBILE_DATA_OFF; + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_MOBILE_DATA_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_roaming_state(keynode_t *node, void *user_data) +{ + int ret = 0; + int enabled = 0; + bundle *b = NULL; + const char *key = NULL; + const char *val = NULL; + + _D("vconfcb called"); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, &enabled); + if (ret != VCONF_OK) { + _E("failed to get vconf (%d)", ret); + return; + } + + key = EVT_KEY_DATA_ROAMING_STATE; + + if (enabled) + val = EVT_VAL_DATA_ROAMING_ON; + else + val = EVT_VAL_DATA_ROAMING_OFF; + + b = bundle_create(); + bundle_add_str(b, key, val); + + if (__esd_send_system_event(SYS_EVENT_DATA_ROAMING_STATE, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static void __esd_vconfcb_font_set(keynode_t *node, void *user_data) +{ + char *str = 0; + bundle *b = NULL; + const char *key = NULL; + + _D("vconfcb called"); + + str = vconf_get_str(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME); + if (str == NULL) { + _E("failed to get vconf str"); + return; + } + + key = EVT_KEY_FONT_SET; + + b = bundle_create(); + bundle_add_str(b, key, str); + + if (__esd_send_system_event(SYS_EVENT_FONT_SET, b, key) != ES_R_OK) { + _E("failed to send event"); + } + + if (b) { + bundle_free(b); + } +} + +static struct esd_vconf_handler vconf_callbacks[] = { + {VCONFKEY_LOCATION_USE_MY_LOCATION, __esd_vconfcb_location_use_mylocation}, + {VCONFKEY_LOCATION_ENABLED, __esd_vconfcb_location_enabled}, + {VCONFKEY_LOCATION_NETWORK_ENABLED, __esd_vconfcb_location_network_enabled}, + {VCONFKEY_LANGSET, __esd_vconfcb_language_set}, + {VCONFKEY_REGIONFORMAT_TIME1224, __esd_vconfcb_hour_format}, + {VCONFKEY_REGIONFORMAT, __esd_vconfcb_region_format}, + {VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, __esd_vconfcb_vibration_status}, + {VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, __esd_vconfcb_sound_status}, + {VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __esd_vconfcb_auto_rotate}, + {VCONFKEY_3G_ENABLE, __esd_vconfcb_mobiledata_state}, + {VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, __esd_vconfcb_roaming_state}, + {VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, __esd_vconfcb_font_set}, +}; + +static int vconfcbs_size = sizeof(vconf_callbacks)/sizeof(struct esd_vconf_handler); + +int __esd_register_vconf_callbacks(void) +{ + int i = 0; + int ret = 0; + int result = ES_R_OK; + +#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36) + g_type_init(); +#endif + + esd_sent_table = g_hash_table_new(g_str_hash, g_str_equal); + + _D("vconf callbacks size(%d)", vconfcbs_size); + for (i = 0; i < vconfcbs_size; i++) { + ret = vconf_notify_key_changed(vconf_callbacks[i].key, + vconf_callbacks[i].esd_vconfcb_fn, NULL); + if (ret != VCONF_OK) { + _E("failed to register vconf callback (%s)", vconf_callbacks[i].key); + result = ES_R_ERROR; + break; + } + } + + return result; +} + -- 2.34.1