From 24e6c1bd654b793c747b33e7a1332dac6722a93c Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 9 Jun 2017 09:58:52 +0900 Subject: [PATCH] Get launch-on-event items for default user - At first, get the launch-on-event items for default user. - Listen UserSessionStartupFinished signal and update launch-on-event items if another user is activated. Change-Id: I70336e21bdf4123429ef478dc0b94bb1999c10b8 Signed-off-by: Jiwoong Im --- include/eventsystem_daemon.h | 1 + src/esd_main.c | 93 ++++++++++++++++++++++++-------------------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/include/eventsystem_daemon.h b/include/eventsystem_daemon.h index 56f44a0..a5aaa8f 100644 --- a/include/eventsystem_daemon.h +++ b/include/eventsystem_daemon.h @@ -46,6 +46,7 @@ extern "C" { #define SYSTEMD_DBUS_IFACE_MANAGER SYSTEMD_DBUS_DEST ".Manager" #define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1" #define SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED "StartupFinished" +#define SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED "UserSessionStartupFinished" int __esd_register_vconf_callbacks(void); diff --git a/src/esd_main.c b/src/esd_main.c index 93e096a..33bb1cb 100644 --- a/src/esd_main.c +++ b/src/esd_main.c @@ -21,6 +21,7 @@ #include #include "eventsystem_daemon.h" +#define DEFAULT_USER tzplatform_getuid(TZ_SYS_DEFAULT_USER) #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) #define ROOT_USER 0 @@ -978,55 +979,39 @@ static int __esd_dbus_name_monitor(GDBusConnection *connection) return ES_R_OK; } -static int __esd_get_user_items(void) +static int __esd_get_user_items(uid_t uid) { int ret = 0; - int i = 0; - uid_t *uids = NULL; - uid_t cur_uid = 0; pkgmgrinfo_appinfo_filter_h handle = NULL; - ret = sd_get_uids(&uids); + _I("get user items for uid(%d)", uid); + /* reset user's item */ + __esd_launch_table_remove_private_usr_items(); + + ret = pkgmgrinfo_appinfo_filter_create(&handle); if (ret < 0) { - _E("failed to get uids (%d)", ret); + _E("failed to create appinfo filter"); return ES_R_ERROR; } - - if (ret == 0 || uids == NULL) { - _I("there is no uid for now"); - } else { - /* reset user's item */ - __esd_launch_table_remove_private_usr_items(); - for (i = 0; i < ret; i++) { - cur_uid = uids[i]; - _I("found uid(%d)", cur_uid); - - ret = pkgmgrinfo_appinfo_filter_create(&handle); - if (ret < 0) { - _E("failed to create appinfo filter"); - return ES_R_ERROR; - } - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_COMPONENT, "svcapp"); - if (ret < 0) { - _E("failed to add appinfo filter string"); - return ES_R_ERROR; - } - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_OPERATION, APPSVC_OPERATION_LAUNCH_ON_EVENT); - if (ret < 0) { - _E("failed to add appinfo filter string"); - return ES_R_ERROR; - } - ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, - __esd_add_appinfo_handler, &cur_uid, cur_uid); - if (ret < 0) { - _E("appinfo filter foreach error"); - return ES_R_ERROR; - } - pkgmgrinfo_appinfo_filter_destroy(handle); - } + ret = pkgmgrinfo_appinfo_filter_add_string(handle, + PMINFO_APPINFO_PROP_APP_COMPONENT, "svcapp"); + if (ret < 0) { + _E("failed to add appinfo filter string"); + return ES_R_ERROR; } + ret = pkgmgrinfo_appinfo_filter_add_string(handle, + PMINFO_APPINFO_PROP_APP_OPERATION, APPSVC_OPERATION_LAUNCH_ON_EVENT); + if (ret < 0) { + _E("failed to add appinfo filter string"); + return ES_R_ERROR; + } + ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, + __esd_add_appinfo_handler, &uid, uid); + if (ret < 0) { + _E("appinfo filter foreach error"); + return ES_R_ERROR; + } + pkgmgrinfo_appinfo_filter_destroy(handle); __esd_launch_table_print_items(); @@ -1043,6 +1028,7 @@ static void __esd_signal_handler(GDBusConnection *connection, { int handle; bundle *b; + guint64 uid = 0; if (!g_strcmp0(signal_name, SYSTEMD_DBUS_SIGNAL_STARTUP_FINISHED)) { @@ -1057,6 +1043,12 @@ static void __esd_signal_handler(GDBusConnection *connection, handle = creat(ESD_BOOT_COMPLETED, 0640); if (handle != -1) close(handle); + } else if (!g_strcmp0(signal_name, + SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED)) { + g_variant_get(parameters, "(t)", &uid); + _I("User session finished uid : %d", uid); + if ((uid_t)uid != DEFAULT_USER) + __esd_get_user_items((uid_t)uid); } } @@ -1652,6 +1644,7 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, guint reg_id = 0; guint boot_id = 0; + guint user_boot_id = 0; GError *error = NULL; reg_id = g_dbus_connection_register_object(connection, @@ -1679,6 +1672,22 @@ static void __esd_on_bus_acquired(GDBusConnection *connection, _E("g_dbus_connection_signal_subscribe() is failed."); g_object_unref(connection); } + + user_boot_id = g_dbus_connection_signal_subscribe(connection, + NULL, + SYSTEMD_DBUS_IFACE_MANAGER, + SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED, + SYSTEMD_DBUS_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + __esd_signal_handler, + NULL, + NULL); + + if (user_boot_id == 0) { + _E("g_dbus_connection_signal_subscribe() is failed."); + g_object_unref(connection); + } } static void __esd_on_name_acquired(GDBusConnection *connection, @@ -1700,7 +1709,7 @@ static void __esd_on_name_acquired(GDBusConnection *connection, __esd_trusted_busname_print_items(); - __esd_get_user_items(); + __esd_get_user_items(DEFAULT_USER); __esd_dbus_name_monitor(connection); } -- 2.7.4