From a99347155d80d1c885d271e7c7226459172b2d45 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 21 Dec 2015 10:09:04 +0900 Subject: [PATCH] Remove AMD - AMD will be moved to platform/core/appfw/amd Change-Id: I9f7b647407d8153e35ba6da06cb932c4f34cf0bb Signed-off-by: Junghoon Park --- CMakeLists.txt | 22 +- am_daemon/amd_app_group.c | 1413 ----------------------------------------- am_daemon/amd_app_group.h | 60 -- am_daemon/amd_appinfo.c | 955 ---------------------------- am_daemon/amd_appinfo.h | 68 -- am_daemon/amd_config.h | 20 - am_daemon/amd_cynara.c | 124 ---- am_daemon/amd_cynara.h | 19 - am_daemon/amd_launch.c | 844 ------------------------- am_daemon/amd_launch.h | 39 -- am_daemon/amd_main.c | 330 ---------- am_daemon/amd_request.c | 1524 --------------------------------------------- am_daemon/amd_request.h | 23 - am_daemon/amd_status.c | 765 ----------------------- am_daemon/amd_status.h | 40 -- include/app_sock.h | 52 +- include/aul_cmd.h | 72 +++ packaging/ac.conf | 5 - packaging/ac.service | 15 - packaging/ac.socket | 6 - packaging/aul.changes | 13 - packaging/aul.spec | 37 +- 22 files changed, 77 insertions(+), 6369 deletions(-) delete mode 100644 am_daemon/amd_app_group.c delete mode 100644 am_daemon/amd_app_group.h delete mode 100644 am_daemon/amd_appinfo.c delete mode 100644 am_daemon/amd_appinfo.h delete mode 100644 am_daemon/amd_config.h delete mode 100644 am_daemon/amd_cynara.c delete mode 100644 am_daemon/amd_cynara.h delete mode 100644 am_daemon/amd_launch.c delete mode 100644 am_daemon/amd_launch.h delete mode 100644 am_daemon/amd_main.c delete mode 100644 am_daemon/amd_request.c delete mode 100644 am_daemon/amd_request.h delete mode 100644 am_daemon/amd_status.c delete mode 100644 am_daemon/amd_status.h create mode 100644 include/aul_cmd.h delete mode 100644 packaging/ac.conf delete mode 100644 packaging/ac.service delete mode 100644 packaging/ac.socket delete mode 100644 packaging/aul.changes diff --git a/CMakeLists.txt b/CMakeLists.txt index 006d7db..0a1ba66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ ENDIF (with_x11) # Set required packages INCLUDE(FindPkgConfig) -SET(AUL-1_LIB_PKG_CHECK_MODULES dlog bundle dbus-glib-1 xdgmime libtzplatform-config pkgmgr-info libsystemd-daemon security-manager cynara-client cynara-creds-socket cynara-session capi-system-info vconf sqlite3 iniparser) +SET(AUL-1_LIB_PKG_CHECK_MODULES dlog bundle dbus-glib-1 xdgmime libtzplatform-config pkgmgr-info libsystemd-daemon capi-system-info vconf sqlite3 iniparser) IF (with_wayland) pkg_check_modules(libpkgs REQUIRED ${AUL-1_LIB_PKG_CHECK_MODULES} wayland-client tizen-extension-client ecore-wayland) ENDIF (with_wayland) @@ -24,12 +24,6 @@ FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(AUL-1_PKG_CHECK_MODULES dlog rua glib-2.0 gio-2.0 vconf pkgmgr-info pkgmgr bundle) -pkg_check_modules(pkgs REQUIRED ${AUL-1_PKG_CHECK_MODULES} ) -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - pkg_check_modules(APP_LAUNCHER_DEPS glib-2.0 pkgmgr-info bundle) FOREACH(APP_LAUNCHER_FLAGS ${APP_LAUNCHER_DEPS_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${APP_LAUNCHER_FLAGS}") @@ -78,19 +72,6 @@ SET_TARGET_PROPERTIES(aul PROPERTIES SOVERSION ${MAJORVER}) SET_TARGET_PROPERTIES(aul PROPERTIES VERSION ${FULLVER}) INSTALL(TARGETS aul DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) -ADD_EXECUTABLE(amd - am_daemon/amd_main.c - am_daemon/amd_request.c - am_daemon/amd_appinfo.c - am_daemon/amd_launch.c - am_daemon/amd_status.c - am_daemon/amd_app_group.c - am_daemon/amd_cynara.c - ) -SET_TARGET_PROPERTIES(amd PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS} -fPIE") -TARGET_LINK_LIBRARIES(amd aul_mods aul ${pkgs_LDFLAGS} "-pie") -INSTALL(TARGETS amd DESTINATION bin) - # app_launcher SET(APP_LAUNCHER "app_launcher") ADD_EXECUTABLE(${APP_LAUNCHER} app_launcher.c) @@ -114,6 +95,7 @@ CONFIGURE_FILE(feature/preexec_list.txt.in feature/preexec_list.txt @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul.h DESTINATION include/aul) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_rsc_mgr.h DESTINATION include/aul) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_svc.h DESTINATION include/aul) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul_cmd.h DESTINATION include/aul) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/aul.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/legacy/preload_list.txt DESTINATION ${SHARE_INSTALL_PREFIX}/aul ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/feature/preexec_list.txt DESTINATION ${SHARE_INSTALL_PREFIX}/aul ) diff --git a/am_daemon/amd_app_group.c b/am_daemon/amd_app_group.c deleted file mode 100644 index 28546aa..0000000 --- a/am_daemon/amd_app_group.c +++ /dev/null @@ -1,1413 +0,0 @@ -/* - * 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. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include - -#include "app_sock.h" -#include "simple_util.h" -#include "amd_app_group.h" -#include "amd_launch.h" -#include "amd_request.h" -#include "amd_status.h" -#include "app_signal.h" -#include "amd_appinfo.h" - -#define APP_SVC_K_LAUNCH_MODE "__APP_SVC_LAUNCH_MODE__" - -#ifdef WAYLAND -#include -#include -#include -static struct tizen_policy *tz_policy; - -static void _reg_handle_global(void *data, struct wl_registry *reg, - uint32_t id, const char *interface, uint32_t ver) -{ - if (!strcmp(interface, "tizen_policy")) { - tz_policy = wl_registry_bind(reg, - id, - &tizen_policy_interface, - 1); - } -} - -static void _reg_handle_global_remove(void *data, struct wl_registry *reg, - uint32_t id) -{ - /* do nothing */ -} - -static const struct wl_registry_listener reg_listener = { - _reg_handle_global, - _reg_handle_global_remove -}; -#endif - -static GHashTable *app_group_hash = NULL; -static int dead_pid = -1; -static int focused_leader_pid = -1; -static GList *recycle_bin = NULL; - -extern char *home_appid; - -typedef struct _app_group_context_t { - int pid; - int wid; - int status; - int fg; - int group_sig; - int can_be_leader; - int reroute; - int caller_pid; - int can_shift; - int recycle; - app_group_launch_mode launch_mode; -} app_group_context_t; - -static void __attach_window(int parent_wid, int child_wid) -{ -#ifdef WAYLAND - struct wl_display *dpy; - struct wl_registry *reg; - - dpy = wl_display_connect(NULL); - reg = wl_display_get_registry(dpy); - wl_registry_add_listener(reg, ®_listener, NULL); - wl_display_roundtrip(dpy); - - if (!tz_policy) { - _E("ERR: no tizen_policy global interface"); - wl_registry_destroy(reg); - wl_display_disconnect(dpy); - return; - } - - tizen_policy_set_transient_for(tz_policy, child_wid, parent_wid); - wl_display_roundtrip(dpy); - - tizen_policy_destroy(tz_policy); - wl_registry_destroy(reg); - wl_display_disconnect(dpy); -#else - /* ecore_x_icccm_transient_for_set(child_wid, parent_wid); */ -#endif -} - -static void __detach_window(int child_wid) -{ -#ifdef WAYLAND - struct wl_display *dpy; - struct wl_registry *reg; - - dpy = wl_display_connect(NULL); - reg = wl_display_get_registry(dpy); - wl_registry_add_listener(reg, ®_listener, NULL); - wl_display_roundtrip(dpy); - - if (!tz_policy) { - _E("ERR: no tz_policy global interface"); - wl_registry_destroy(reg); - wl_display_disconnect(dpy); - return; - } - - tizen_policy_unset_transient_for(tz_policy, child_wid); - wl_display_roundtrip(dpy); - - tizen_policy_destroy(tz_policy); - wl_registry_destroy(reg); - wl_display_disconnect(dpy); -#else - /* ecore_x_icccm_transient_for_unset(child_wid); */ -#endif -} - -static gint __comp_pid(gconstpointer a, gconstpointer b) -{ - app_group_context_t *ac1 = (app_group_context_t *)a; - - return ac1->pid - GPOINTER_TO_INT(b); -} - -static void __list_destroy_cb(gpointer data) -{ - free(data); -} - -static gboolean __hash_table_cb(gpointer key, gpointer value, - gpointer user_data) -{ - int pid = GPOINTER_TO_INT(user_data); - GList *list = (GList *)value; - GList *itr = g_list_first(list); - app_group_context_t *ac; - - while (itr != NULL) { - ac = (app_group_context_t *)itr->data; - if (ac && ac->pid == pid) { - free(ac); - list = g_list_remove_link(list, itr); - if (g_list_length(list) == 0) { - g_list_free_full(list, __list_destroy_cb); - return TRUE; - } else - return FALSE; - } - itr = g_list_next(itr); - } - - return FALSE; -} - -static GList* __find_removable_apps(int from) -{ - int cnt; - int *pids = NULL; - GList *list = NULL; - gboolean found = FALSE; - int i; - int j; - int *gpids = NULL; - int gcnt; - - app_group_get_leader_pids(&cnt, &pids); - - for (i = 0; i < cnt; i++) { - app_group_get_group_pids(pids[i], &gcnt, &gpids); - for (j = 0; j < gcnt; j++) { - if (gpids[j] == from) { - found = TRUE; - continue; - } - - if (found) - list = g_list_append(list, GINT_TO_POINTER(gpids[j])); - } - - if (gpids != NULL) - free(gpids); - - if (found) - break; - } - - if (pids != NULL) - free(pids); - - return list; -} - -static void __prepare_to_suspend_services(int pid) -{ - /* - int dummy; - SECURE_LOGD("[__SUSPEND__] pid: %d", pid); - __app_send_raw_with_noreply(pid, APP_SUSPEND, (unsigned char *)&dummy, sizeof(int)); - */ -} - -static void __prepare_to_wake_services(int pid) -{ - /* - int dummy; - SECURE_LOGD("[__SUSPEND__] pid: %d", pid); - __app_send_raw_with_noreply(pid, APP_WAKE, (unsigned char *)&dummy, sizeof(int)); - */ -} - -static void __set_fg_flag(int cpid, int flag, gboolean force) -{ - int lpid = app_group_get_leader_pid(cpid); - GHashTableIter iter; - gpointer key; - gpointer value; - const char *appid = NULL; - const char *pkgid = NULL; - const struct appinfo *ai = NULL; - GList *list; - GList *i; - app_group_context_t *ac; - int bg_category = 0x00; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - ac = (app_group_context_t *)i->data; - if (ac && ac->pid == lpid) { - while (i != NULL) { - ac = (app_group_context_t*) i->data; - if ((ac && ac->fg != flag) || force == TRUE) { - appid = _status_app_get_appid_bypid(ac->pid); - ai = appinfo_find(getuid(), appid); - pkgid = appinfo_get_value(ai, AIT_PKGID); - bg_category = (bool)appinfo_get_value(ai, AIT_BG_CATEGORY); - - if (flag) { - _D("send_signal FG %s", appid); - - aul_send_app_status_change_signal(ac->pid, appid, - pkgid, - STATUS_FOREGROUND, - APP_TYPE_UI); - if (!bg_category) - _status_find_service_apps(ac->pid, getuid(), STATUS_VISIBLE, __prepare_to_wake_services, false); - - } else { - _D("send_signal BG %s", appid); - aul_send_app_status_change_signal(ac->pid, appid, - pkgid, - STATUS_BACKGROUND, - APP_TYPE_UI); - if (!bg_category) - _status_find_service_apps(ac->pid, getuid(), STATUS_BG, __prepare_to_suspend_services, true); - - } - ac->fg = flag; - } - i = g_list_next(i); - } - break; - } - } -} - -static gboolean __is_visible(int cpid) -{ - int lpid = app_group_get_leader_pid(cpid); - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - app_group_context_t *ac; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - ac = (app_group_context_t *)i->data; - if (ac && ac->pid == lpid) { - while (i != NULL) { - ac = (app_group_context_t*) i->data; - if (ac && ac->status == STATUS_VISIBLE) - return TRUE; - - i = g_list_next(i); - } - break; - } - } - - return FALSE; -} - -static gboolean __can_attach_window(bundle *b, const char *appid, app_group_launch_mode *launch_mode) -{ - char *str = NULL; - const char *mode = NULL; - const struct appinfo *ai = NULL; - - ai = appinfo_find(getuid(), appid); - mode = appinfo_get_value(ai, AIT_LAUNCH_MODE); - - if (mode == NULL) - *launch_mode = APP_GROUP_LAUNCH_MODE_SINGLE; - else if (strcmp(mode, "caller") == 0) - *launch_mode = APP_GROUP_LAUNCH_MODE_CALLER; - else if (strcmp(mode, "single") == 0) - *launch_mode = APP_GROUP_LAUNCH_MODE_SINGLE; - else if (strcmp(mode, "group") == 0) - *launch_mode = APP_GROUP_LAUNCH_MODE_GROUP; - else if (strcmp(mode, "singleton") == 0) - *launch_mode = APP_GROUP_LAUNCH_MODE_SINGLETON; - - switch (*launch_mode) { - case APP_GROUP_LAUNCH_MODE_CALLER: - case APP_GROUP_LAUNCH_MODE_SINGLETON: - _D("launch mode from db is caller or singleton"); - - bundle_get_str(b, APP_SVC_K_LAUNCH_MODE, &str); - if (str != NULL && strncmp(str, "group", 5) == 0) - return TRUE; - break; - case APP_GROUP_LAUNCH_MODE_GROUP: - return TRUE; - case APP_GROUP_LAUNCH_MODE_SINGLE: - return FALSE; - } - - return FALSE; -} - -static gboolean __can_be_leader(bundle *b) -{ - char *str = NULL; - - bundle_get_str(b, AUL_SVC_K_CAN_BE_LEADER, &str); - - if (str != NULL && strcmp(str, "true") == 0) - return TRUE; - - return FALSE; -} - -static int __get_previous_pid(int pid) -{ - int previous_pid = -1; - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - app_group_context_t *ac; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - - while (i != NULL) { - ac = (app_group_context_t*)i->data; - if (ac && ac->pid == pid) - return previous_pid; - - previous_pid = ac->pid; - i = g_list_next(i); - } - } - - return -1; -} - -static int __get_caller_pid(bundle *kb) -{ - const char *pid_str; - int pid; - - pid_str = bundle_get_val(kb, AUL_K_ORG_CALLER_PID); - if (pid_str) - goto end; - - pid_str = bundle_get_val(kb, AUL_K_CALLER_PID); - if (pid_str == NULL) - return -1; - -end: - pid = atoi(pid_str); - if (pid <= 1) - return -1; - - return pid; -} - -static app_group_context_t* __detach_context_from_recycle_bin(int pid) -{ - GList *iter = recycle_bin; - app_group_context_t *ac; - - while (iter) { - ac = (app_group_context_t *)iter->data; - if (ac && ac->pid == pid) { - recycle_bin = g_list_remove_link(recycle_bin, iter); - return ac; - } - - iter = g_list_next(iter); - } - - return NULL; - -} - -static void __group_add(int leader_pid, int pid, int wid, app_group_launch_mode mode, - int caller_pid, int can_shift, int recycle) -{ - app_group_context_t *ac = NULL; - GList *list; - - if ((ac = __detach_context_from_recycle_bin(pid)) == NULL) { - ac = malloc(sizeof(app_group_context_t)); - if (ac == NULL) { - _E("out of memory"); - return; - } - ac->pid = pid; - ac->wid = wid; - ac->fg = 0; - ac->can_be_leader = 0; - ac->reroute = 0; - ac->launch_mode = mode; - ac->caller_pid = caller_pid; - ac->can_shift = can_shift; - ac->recycle = recycle; - } - - if (leader_pid == pid || ac->recycle) - ac->group_sig = 1; - else - ac->group_sig = 0; - - dead_pid = -1; - - list = (GList *)g_hash_table_lookup(app_group_hash, - GINT_TO_POINTER(leader_pid)); - if (list != NULL) { - if (g_list_find_custom(list, GINT_TO_POINTER(pid), __comp_pid) != NULL) { - _E("pid exist"); - free(ac); - return; - } - } - - list = g_list_append(list, ac); - g_hash_table_insert(app_group_hash, GINT_TO_POINTER(leader_pid), list); - - if (ac->wid != 0) - app_group_set_window(pid, ac->wid); -} - -static void __group_remove(int pid) -{ - int ppid = __get_previous_pid(pid); - - g_hash_table_foreach_remove(app_group_hash, __hash_table_cb, - GINT_TO_POINTER(pid)); - - if (ppid != -1) - app_group_set_status(ppid, -1, false); -} - -static app_group_context_t* __get_context(int pid) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - app_group_context_t *ac; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - while (i != NULL) { - ac = (app_group_context_t *)i->data; - if (ac && ac->pid == pid) - return ac; - - i = g_list_next(i); - } - } - - return NULL; -} - -static int __can_recycle(int pid) -{ - app_group_context_t *context = __get_context(pid); - - if (context) - return context->recycle; - - return 0; -} - -static int __can_reroute(int pid) -{ - app_group_context_t *context = __get_context(pid); - - if (context) - return context->reroute; - - return 0; -} - -static app_group_context_t *__context_dup(const app_group_context_t *context) -{ - app_group_context_t *dup; - - if (!context) { - _E("context is NULL."); - return NULL; - } - - dup = malloc(sizeof(app_group_context_t)); - if (!dup) { - _E("out of memory"); - return NULL; - } - - memcpy(dup, context, sizeof(app_group_context_t)); - return dup; -} - -static void __do_recycle(app_group_context_t *context) -{ - const char *appid = NULL; - const char *pkgid = NULL; - const struct appinfo *ai = NULL; - - if (context->fg) { - appid = _status_app_get_appid_bypid(context->pid); - ai = appinfo_find(getuid(), appid); - pkgid = appinfo_get_value(ai, AIT_PKGID); - - _D("send_signal BG %s", appid); - aul_send_app_status_change_signal(context->pid, appid, pkgid, - STATUS_BACKGROUND, - APP_TYPE_UI); - _status_find_service_apps(context->pid, getuid(), STATUS_BG, __prepare_to_suspend_services, true); - context->fg = 0; - } - recycle_bin = g_list_append(recycle_bin, context); - /* _revoke_temporary_permission(context->pid); */ -} - -void app_group_init() -{ - app_group_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, - NULL); -} - -void app_group_remove(int pid) -{ - app_group_context_t *context; - - __group_remove(pid); - context = __detach_context_from_recycle_bin(pid); - if (context) - free(context); -} - -void app_group_remove_from_recycle_bin(int pid) -{ - app_group_context_t *context = __detach_context_from_recycle_bin(pid); - - if (context) - free(context); -} - -int app_group_get_window(int pid) -{ - app_group_context_t *context = __get_context(pid); - - if (context) - return context->wid; - - return -1; -} - -int app_group_set_window(int pid, int wid) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - int previous_wid; - int caller_wid; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - previous_wid = 0; - while (i != NULL) { - app_group_context_t *ac = (app_group_context_t*) i->data; - if (ac && ac->pid == pid) { - ac->wid = wid; - if (previous_wid != 0) - __attach_window(previous_wid, wid); - - if (ac->can_shift && ac->caller_pid > 0) { - caller_wid = app_group_get_window(ac->caller_pid); - if (caller_wid != 0) - __attach_window(caller_wid, wid); - } - - i = g_list_next(i); - if (i) { - ac = (app_group_context_t*) i->data; - if (ac->wid != 0) - __attach_window(wid, ac->wid); - } - - return 0; - } - previous_wid = ac->wid; - i = g_list_next(i); - } - } - - return -1; -} - -void app_group_clear_top(int pid) -{ - int p; - GList *list = __find_removable_apps(pid); - - if (list != NULL) { - GList *itr = g_list_last(list); - - while (itr != NULL) { - p = GPOINTER_TO_INT(itr->data); - __detach_window(p); - _term_sub_app(p); - app_group_remove(p); - itr = g_list_previous(itr); - } - g_list_free(list); - } -} - -gboolean app_group_is_group_app(bundle* kb) -{ - char *str = NULL; - const char *mode = NULL; - char *appid = NULL; - const struct appinfo *ai = NULL; - - if (kb == NULL) - return FALSE; - - bundle_get_str(kb, AUL_K_APPID, &appid); - - if (appid == NULL) - return FALSE; - - ai = appinfo_find(getuid(), appid); - mode = appinfo_get_value(ai, AIT_LAUNCH_MODE); - - if (mode != NULL && (strncmp(mode, "caller", 6) == 0 || - strncmp(mode, "singleton", 9) == 0)) { - bundle_get_str(kb, APP_SVC_K_LAUNCH_MODE, &str); - - if (str != NULL && strncmp(str, "group", 5) == 0) - return TRUE; - } else if (mode != NULL && strncmp(mode, "group", 5) == 0) { - return TRUE; - } - - return FALSE; -} - -void app_group_get_leader_pids(int *cnt, int **pids) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - int size = g_hash_table_size(app_group_hash); - int *leader_pids; - int i; - - if (size > 0) { - leader_pids = (int*)malloc(sizeof(int) * size); - if (leader_pids == NULL) { - _E("out of memory"); - *cnt = 0; - *pids = NULL; - return; - } - - g_hash_table_iter_init(&iter, app_group_hash); - i = 0; - while (g_hash_table_iter_next(&iter, &key, &value)) { - leader_pids[i] = GPOINTER_TO_INT(key); - i++; - } - - *cnt = size; - *pids = leader_pids; - } else { - *cnt = 0; - *pids = NULL; - } -} - -gboolean app_group_is_leader_pid(int pid) -{ - int cnt; - int *pids = NULL; - int i; - - app_group_get_leader_pids(&cnt, &pids); - - for (i = 0; i < cnt; i++) { - if (pid == pids[i]) { - free(pids); - return TRUE; - } - } - - if (pids != NULL) - free(pids); - - return FALSE; -} - -void app_group_get_group_pids(int leader_pid, int *cnt, int **pids) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - int size; - int *pid_array; - int j; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - if (GPOINTER_TO_INT(key) == leader_pid) { - list = (GList *)value; - i = g_list_first(list); - size = g_list_length(list); - - if (size > 0) { - j = 0; - pid_array = (int *)malloc(sizeof(int) * size); - if (pid_array == NULL) { - _E("out of memory"); - *cnt = 0; - *pids = NULL; - return; - } - - while (i != NULL) { - app_group_context_t *ac = (app_group_context_t*) i->data; - - pid_array[j] = ac->pid; - i = g_list_next(i); - j++; - } - - *cnt = size; - *pids = pid_array; - } else { - *cnt = 0; - *pids = NULL; - } - return; - } - } - - *cnt = 0; - *pids = NULL; -} - -gboolean app_group_is_sub_app(int pid) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *found;; - - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - found = NULL; - - if (list != NULL) { - if ((found = g_list_find_custom(list, GINT_TO_POINTER(pid), __comp_pid)) != NULL) { - if (g_list_first(list) == found) - return FALSE; - return TRUE; - } - } - } - - return FALSE; -} - -void app_group_reroute(int pid) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *found = NULL; - GList *before = NULL; - GList *after = NULL; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - found = NULL; - before = NULL; - after = NULL; - - if (list != NULL) { - if ((found = g_list_find_custom(list, GINT_TO_POINTER(pid), __comp_pid)) != NULL) { - before = g_list_previous(found); - after = g_list_next(found); - - if (before == NULL || after == NULL) - return; - - _D("reroute"); - app_group_context_t *ac1 = (app_group_context_t*) before->data; - app_group_context_t *ac2 = (app_group_context_t*) after->data; - - __detach_window(ac2->wid); - __attach_window(ac1->wid, ac2->wid); - break; - } - } - } -} - -int app_group_get_leader_pid(int pid) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - int lpid = -1; - int again = 0; - -repeat: - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - if (list != NULL) { - if (g_list_find_custom(list, GINT_TO_POINTER(pid), __comp_pid) != NULL) { - lpid = GPOINTER_TO_INT(key); - break; - } - } - } - - if (lpid == -1 && dead_pid == pid) - lpid = focused_leader_pid; - - if (lpid == -1 && again == 0) { - pid = getpgid(pid); - again = 1; - goto repeat; - } - - return lpid; -} - -void app_group_set_dead_pid(int pid) -{ - focused_leader_pid = app_group_get_leader_pid(pid); - dead_pid = pid; - - if (dead_pid == focused_leader_pid) { - focused_leader_pid = -1; - dead_pid = -1; - } -} - -int app_group_get_status(int pid) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - app_group_context_t *ac; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - - while (i != NULL) { - ac = (app_group_context_t*) i->data; - if (ac && ac->pid == pid) - return ac->status; - - i = g_list_next(i); - } - } - return -1; -} - -int app_group_set_status(int pid, int status, gboolean force) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - app_group_context_t *ac; - GList *last; - app_group_context_t *last_ac; - char *appid = NULL; - const char *pkgid = NULL; - const struct appinfo *ai = NULL; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - - while (i != NULL) { - ac = (app_group_context_t*) i->data; - if (ac && ac->pid == pid) { - if (status > 0) - ac->status = status; - last = g_list_last(list); - last_ac = (app_group_context_t *)last->data; - - if (last_ac->wid != 0 || status == STATUS_VISIBLE || force == TRUE) { - if (__is_visible(pid)) { - __set_fg_flag(pid, 1, force); - if (!ac->group_sig && GPOINTER_TO_INT(key) != pid) { - appid = _status_app_get_appid_bypid(pid); - ai = appinfo_find(getuid(), appid); - pkgid = appinfo_get_value(ai, AIT_PKGID); - - _D("send group signal %d", pid); - aul_send_app_group_signal(GPOINTER_TO_INT(key), pid, pkgid); - ac->group_sig = 1; - } - } else { - __set_fg_flag(pid, 0, force); - } - } - return 0; - } - i = g_list_next(i); - } - } - return -1; -} - -int app_group_get_fg_flag(int pid) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - app_group_context_t *ac; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList*) value; - i = g_list_first(list); - while (i != NULL) { - ac = (app_group_context_t*) i->data; - if (ac && ac->pid == pid) - return ac->fg; - - i = g_list_next(i); - } - } - - return 0; -} - -int app_group_set_hint(int pid, bundle *kb) -{ - char *str_leader = NULL; - char *str_reroute = NULL; - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - app_group_context_t *ac; - - if (kb == NULL) - return -1; - - bundle_get_str(kb, AUL_SVC_K_CAN_BE_LEADER, &str_leader); - bundle_get_str(kb, AUL_SVC_K_REROUTE, &str_reroute); - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - while (i != NULL) { - ac = (app_group_context_t *)i->data; - if (ac && ac->pid == pid) { - if (str_leader != NULL && strcmp(str_leader, "true") == 0) - ac->can_be_leader = 1; - if (str_reroute != NULL && strcmp(str_reroute, "true") == 0) - ac->reroute = 1; - return 0; - } - i = g_list_next(i); - } - } - - return -1; -} - -int app_group_find_second_leader(int lpid) -{ - app_group_context_t *ac; - GList *list = (GList *)g_hash_table_lookup(app_group_hash, - GINT_TO_POINTER(lpid)); - if (list != NULL) { - list = g_list_next(list); - if (list != NULL) { - ac = (app_group_context_t*) list->data; - if (ac && ac->can_be_leader) { - _W("found the second leader, lpid: %d, pid: %d", lpid, ac->pid); - return ac->pid; - } - } - } - - return -1; -} - -void app_group_remove_leader_pid(int lpid) -{ - app_group_context_t *ac; - GList *next; - GList *list = (GList*)g_hash_table_lookup(app_group_hash, - GINT_TO_POINTER(lpid)); - - if (list != NULL) { - next = g_list_next(list); - if (next != NULL) { - ac = (app_group_context_t *)list->data; - if (ac) - free(ac); - list = g_list_remove_link(list, list); - - ac = (app_group_context_t *)next->data; - g_hash_table_insert(app_group_hash, GINT_TO_POINTER(ac->pid), next); - g_hash_table_remove(app_group_hash, GINT_TO_POINTER(lpid)); - } - } -} - -int app_group_can_start_app(const char *appid, bundle *b, gboolean *can_attach, - int *lpid, app_group_launch_mode *mode) -{ - const char *val = NULL; - int caller_pid; - int caller_wid; - - *can_attach = FALSE; - if (__can_attach_window(b, appid, mode)) { - *can_attach = TRUE; - - val = bundle_get_val(b, AUL_K_ORG_CALLER_PID); - if (val == NULL) - val = bundle_get_val(b, AUL_K_CALLER_PID); - - if (val == NULL) { - _E("no caller pid"); - return -1; - } - - caller_pid = atoi(val); - - *lpid = app_group_get_leader_pid(caller_pid); - if (*lpid != -1) { - caller_wid = app_group_get_window(caller_pid); - - if (caller_wid == 0) { - _E("caller window wasn't ready"); - if (__can_be_leader(b)) - *can_attach = FALSE; - else - *can_attach = TRUE; - } - - } else { - _E("no lpid"); - if (__can_be_leader(b)) - *can_attach = FALSE; - else - return -1; - } - } - - return 0; -} - -void app_group_start_app(int pid, bundle *b, int lpid, gboolean can_attach, - app_group_launch_mode mode) -{ - _E("app_group_start_app"); - - int caller_pid = __get_caller_pid(b); - int can_shift = 0; - int recycle = 0; - const char *str; - - str = bundle_get_val(b, AUL_SVC_K_SHIFT_WINDOW); - if (str != NULL && strcmp(str, "true") == 0) - can_shift = 1; - - str = bundle_get_val(b, AUL_SVC_K_RECYCLE); - if (str != NULL && strcmp(str, "true") == 0) - recycle = 1; - - if (can_attach) - __group_add(lpid, pid, 0, mode, caller_pid, 0, recycle); - else - __group_add(pid, pid, 0, mode, caller_pid, can_shift, 0); - app_group_set_hint(pid, b); -} - -int app_group_find_singleton(const char *appid, int *found_pid, int *found_lpid) -{ - GHashTableIter iter; - gpointer key = NULL; - gpointer value = NULL; - char *target = NULL; - GList *list; - app_group_context_t *ac; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - while (list != NULL) { - ac = (app_group_context_t *)list->data; - if (ac && ac->launch_mode == APP_GROUP_LAUNCH_MODE_SINGLETON) { - target = _status_app_get_appid_bypid(ac->pid); - if (appid != NULL && target != NULL && strcmp(appid, target) == 0) { - *found_pid = ac->pid; - *found_lpid = GPOINTER_TO_INT(key); - return 0; - } - } - list = g_list_next(list); - } - } - - return -1; -} - -int app_group_can_reroute(int pid) -{ - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - app_group_context_t *ac; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - while (i != NULL) { - ac = (app_group_context_t *)i->data; - if (ac && ac->pid == pid) - return ac->reroute; - - i = g_list_next(i); - } - } - - return 0; -} - -void app_group_lower(int pid, int *exit) -{ - app_group_context_t *ac; - GHashTableIter iter; - gpointer key; - gpointer value; - GList *list; - GList *i; - - if (app_group_is_sub_app(pid)) { - if (__can_recycle(pid) && __can_reroute(pid)) { - ac = __get_context(pid); - if (ac) { - if (ac->wid != 0) - __detach_window(ac->wid); - app_group_reroute(pid); - ac = __context_dup(ac); - __group_remove(pid); - if (ac) - __do_recycle(ac); - } - *exit = 0; - } else - *exit = 1; - return; - } - - *exit = 0; - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList *)value; - i = g_list_first(list); - while (i != NULL) { - ac = (app_group_context_t *)i->data; - if (ac && ac->can_shift) { - __detach_window(ac->wid); - ac->can_shift = 0; -#ifdef WAYLAND - ecore_wl_window_lower((Ecore_Wl_Window *)((intptr_t)ac->wid)); -#else - /* ecore_x_window_lower(ac->wid); */ -#endif - } - return; - } - i = g_list_next(i); - } -} - -void app_group_restart_app(int pid, bundle *b) -{ - const char *pid_str; - int cwid; - GList *list; - GList *i; - GHashTableIter iter; - gpointer key; - gpointer value; - app_group_context_t *ac; - - if (b == NULL) - return; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList*) value; - i = g_list_first(list); - - while (i != NULL) { - ac = (app_group_context_t *)i->data; - if (ac && ac->pid == pid) { - ac->caller_pid = __get_caller_pid(b); - - if (ac->can_shift) { - if (ac->wid != 0) - __detach_window(ac->wid); - ac->can_shift = 0; - } - - pid_str = bundle_get_val(b, AUL_SVC_K_SHIFT_WINDOW); - if (pid_str != NULL && strcmp(pid_str, "true") == 0) { - ac->can_shift = 1; - if (ac->wid != 0) { - if (ac->caller_pid > 0) { - cwid = app_group_get_window(ac->caller_pid); - if (cwid != 0) - __attach_window(cwid, ac->wid); - else - _E("invalid caller wid"); - } else { - _E("invalid caller pid"); - } - } - } - return; - } - i = g_list_next(i); - } - } -} - -int app_group_find_pid_from_recycle_bin(const char *appid) -{ - app_group_context_t *ac; - const char *appid_from_bin; - GList *iter = recycle_bin; - - while (iter) { - ac = (app_group_context_t *)iter->data; - appid_from_bin = _status_app_get_appid_bypid(ac->pid); - if (appid && appid_from_bin && strcmp(appid, appid_from_bin) == 0) - return ac->pid; - - iter = g_list_next(iter); - } - - return -1; -} - -void app_group_get_idle_pids(int *cnt, int **pids) -{ - GList *iter = recycle_bin; - int idle_cnt = g_list_length(iter); - int *idle_pids = NULL; - int i = 0; - app_group_context_t *ac; - - if (idle_cnt <= 0) { - *cnt = 0; - *pids = NULL; - return; - } - - idle_pids = malloc(sizeof(int) * idle_cnt); - if (idle_pids == NULL) { - _E("Out-of-memory"); - *cnt = 0; - *pids = NULL; - return; - } - - while (iter) { - ac = (app_group_context_t *)iter->data; - idle_pids[i] = ac->pid; - iter = g_list_next(iter); - i++; - } - - *cnt = idle_cnt; - *pids = idle_pids; -} - -int app_group_get_next_caller_pid(int pid) -{ - GList *list; - GList *i; - GHashTableIter iter; - gpointer key; - gpointer value; - app_group_context_t *ac; - - g_hash_table_iter_init(&iter, app_group_hash); - while (g_hash_table_iter_next(&iter, &key, &value)) { - list = (GList*)value; - i = g_list_first(list); - - while (i != NULL) { - ac = (app_group_context_t *)i->data; - if (ac && ac->pid == pid) { - i = g_list_next(i); - if (i == NULL) - return -1; - - ac = (app_group_context_t *)i->data; - return ac->caller_pid; - } - i = g_list_next(i); - } - } - - return -1; -} diff --git a/am_daemon/amd_app_group.h b/am_daemon/amd_app_group.h deleted file mode 100644 index e891f34..0000000 --- a/am_daemon/amd_app_group.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -#pragma once - -#include -#include - -typedef enum { - APP_GROUP_LAUNCH_MODE_SINGLE = 0, - APP_GROUP_LAUNCH_MODE_GROUP, - APP_GROUP_LAUNCH_MODE_CALLER, - APP_GROUP_LAUNCH_MODE_SINGLETON, -} app_group_launch_mode; - -void app_group_init(); -void app_group_remove(int pid); -int app_group_get_window(int pid); -int app_group_set_window(int pid, int wid); -void app_group_get_leader_pids(int *cnt, int **pids); -void app_group_get_group_pids(int leader_pid, int *cnt, int **pids); -gboolean app_group_is_leader_pid(int pid); -gboolean app_group_is_group_app(bundle* kb); -gboolean app_group_is_sub_app(int pid); -void app_group_reroute(int pid); -int app_group_get_caller_pid(); -void app_group_clear_top(int pid); -int app_group_get_leader_pid(int pid); -void app_group_set_dead_pid(int pid); -int app_group_get_status(int pid); -int app_group_set_status(int pid, int status, gboolean force); -int app_group_get_fg_flag(int pid); -int app_group_set_hint(int pid, bundle *kb); -int app_group_find_second_leader(int lpid); -void app_group_remove_leader_pid(int lpid); -int app_group_can_start_app(const char *appid, bundle *b, gboolean *can_attach, int *lpid, app_group_launch_mode *mode); -void app_group_start_app(int pid, bundle *b, int lpid, gboolean can_attach, app_group_launch_mode mode); -int app_group_find_singleton(const char *appid, int *found_pid, int *found_lpid); -int app_group_can_reroute(int pid); -void app_group_lower(int pid, int *exit); -void app_group_restart_app(int pid, bundle *b); -int app_group_find_pid_from_recycle_bin(const char *appid); -void app_group_get_idle_pids(int *cnt, int **pids); -void app_group_remove_from_recycle_bin(int pid); -int app_group_get_next_caller_pid(int pid); - - diff --git a/am_daemon/amd_appinfo.c b/am_daemon/amd_appinfo.c deleted file mode 100644 index ffd8377..0000000 --- a/am_daemon/amd_appinfo.c +++ /dev/null @@ -1,955 +0,0 @@ -/* - * 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. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include "amd_config.h" -#include "simple_util.h" -#include "amd_appinfo.h" -#include "amd_launch.h" -#include "amd_status.h" - -#define SERVICE_GROUP "Service" - -static pkgmgr_client *pc; -static GHashTable *user_tbl; -static GHashTable *pkg_pending; -struct user_appinfo { - uid_t uid; - GHashTable *tbl; /* key is filename, value is struct appinfo */ - void *extra_data; -}; - -enum _appinfo_idx { - _AI_FILE = 0, /* service filename */ - _AI_NAME, - _AI_EXEC, - _AI_TYPE, - _AI_ONBOOT, - _AI_RESTART, - _AI_MULTI, - _AI_HWACC, - _AI_PERM, - _AI_PKGID, - _AI_PRELOAD, - _AI_STATUS, - _AI_POOL, - _AI_COMPTYPE, - _AI_TEP, - _AI_STORAGE_TYPE, - _AI_BG_CATEGORY, - _AI_LAUNCH_MODE, - _AI_GLOBAL, - _AI_EFFECTIVE_APPID, - _AI_MAX, -}; -#define _AI_START _AI_NAME /* start index */ - -typedef int (*appinfo_handler_cb)(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data); - -struct appinfo_t { - char *name; - enum appinfo_type type; - appinfo_handler_cb add; -}; - -enum _background_category { - _BACKGROUND_CATEGORY_MEDIA = 0x01, - _BACKGROUND_CATEGORY_DOWNLOAD = 0x02, - _BACKGROUND_CATEGORY_BACKGROUND_NETWORK = 0x04, - _BACKGROUND_CATEGORY_LOCATION = 0x08, - _BACKGROUND_CATEGORY_SENSOR = 0x10, - _BACKGROUND_CATEGORY_IOT_COMMUNICATION = 0x20, - _BACKGROUND_CATEGORY_SYSTEM = 0x40 -}; - -struct appinfo { - char *val[_AI_MAX]; -}; - -static int gles = 1; - -static void __free_appinfo(gpointer data) -{ - struct appinfo *c = data; - int i; - - if (!c) - return; - - for (i = 0; i < sizeof(c->val)/sizeof(c->val[0]); i++) { - if (i != _AI_BG_CATEGORY && c->val[i] != NULL) - free(c->val[i]); - } - - free(c); -} - -static void __free_user_appinfo(gpointer data) -{ - struct user_appinfo *info = (struct user_appinfo *)data; - - g_hash_table_destroy(info->tbl); - free(info); -} - -static char *__convert_apptype(const char *type) -{ - if (strncmp(type, "capp", 4) == 0) { - return strdup("rpm"); - } else if (strncmp(type, "c++app", 6) == 0 || - strncmp(type, "ospapp", 6) == 0) { - return strdup("tpk"); - } else if (strncmp(type, "webapp", 6) == 0) { - return strdup("wgt"); - } - - return NULL; -} - -static int __read_background_category(const char *category_name, void *user_data) -{ - struct appinfo *c = user_data; - int category = (intptr_t)(c->val[_AI_BG_CATEGORY]); - - if (!category_name) - return 0; - - if (strncmp(category_name, "disable", strlen("disable")) == 0) { - c->val[_AI_BG_CATEGORY] = 0x00; - return -1; - } - - if (strncmp(category_name, "media", strlen("media")) == 0) - c->val[_AI_BG_CATEGORY] = (char *)((intptr_t)(category | _BACKGROUND_CATEGORY_MEDIA)); - else if (strncmp(category_name, "download", strlen("download")) == 0) - c->val[_AI_BG_CATEGORY] = (char *)((intptr_t)(category | _BACKGROUND_CATEGORY_DOWNLOAD)); - else if (strncmp(category_name, "background-network", strlen("background-network")) == 0) - c->val[_AI_BG_CATEGORY] = (char *)((intptr_t)(category | _BACKGROUND_CATEGORY_BACKGROUND_NETWORK)); - else if (strncmp(category_name, "location", strlen("location")) == 0) - c->val[_AI_BG_CATEGORY] = (char *)((intptr_t)(category | _BACKGROUND_CATEGORY_LOCATION)); - else if (strncmp(category_name, "sensor", strlen("sensor")) == 0) - c->val[_AI_BG_CATEGORY] = (char *)((intptr_t)(category | _BACKGROUND_CATEGORY_SENSOR)); - else if (strncmp(category_name, "iot-communication", strlen("iot-communication")) == 0) - c->val[_AI_BG_CATEGORY] = (char *)((intptr_t)(category | _BACKGROUND_CATEGORY_IOT_COMMUNICATION)); - else if (strncmp(category_name, "system", strlen("system")) == 0) - c->val[_AI_BG_CATEGORY] = (char *)((intptr_t)(category | _BACKGROUND_CATEGORY_SYSTEM)); - - return 0; -} - -static int __appinfo_add_name(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - char *appid = NULL; - - if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK) { - _E("fail to get appinfo"); - return -1; - } - - info->val[_AI_NAME] = strdup(appid); - - return 0; -} - -static int __appinfo_add_exec(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - char *exec = NULL; - - if (pkgmgrinfo_appinfo_get_exec(handle, &exec) != PMINFO_R_OK) { - _E("failed to get exec"); - return -1; - } - - info->val[_AI_EXEC] = strdup(exec); - - return 0; -} - -static int __appinfo_add_type(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - char *type = NULL; - - if (pkgmgrinfo_appinfo_get_apptype(handle, &type) != PMINFO_R_OK) { - _E("failed to get apptype"); - return -1; - } - - info->val[_AI_TYPE] = __convert_apptype(type); - - return 0; -} - -static int __appinfo_add_onboot(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - bool onboot = false; - - if (pkgmgrinfo_appinfo_is_onboot(handle, &onboot) != PMINFO_R_OK) { - _E("failed to get onboot"); - return -1; - } - - info->val[_AI_ONBOOT] = strdup(onboot ? "true" : "false"); - - return 0; -} - -static int __appinfo_add_restart(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - bool restart = false; - - if (pkgmgrinfo_appinfo_is_autorestart(handle, &restart) != PMINFO_R_OK) { - _E("failed to get restart"); - return -1; - } - - info->val[_AI_RESTART] = strdup(restart ? "true" : "false"); - - return 0; -} - -static int __appinfo_add_multi(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - bool multiple = false; - - if (pkgmgrinfo_appinfo_is_multiple(handle, &multiple) != PMINFO_R_OK) { - _E("failed to get multiple"); - return -1; - } - - info->val[_AI_MULTI] = strdup(multiple ? "true" : "false"); - - return 0; -} - -static int __appinfo_add_hwacc(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - pkgmgrinfo_app_hwacceleration hwacc; - - if (pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc)) { - _E("failed to get hwacc"); - return -1; - } - - info->val[_AI_HWACC] = strdup( - (gles == 0 || - hwacc == PMINFO_HWACCELERATION_NOT_USE_GL) ? - "NOT_USE" : - (hwacc == PMINFO_HWACCELERATION_USE_GL) ? - "USE" : - "SYS"); - - return 0; -} - -static int __appinfo_add_perm(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - pkgmgrinfo_permission_type permission; - - if (pkgmgrinfo_appinfo_get_permission_type(handle, - &permission) != PMINFO_R_OK) { - _E("failed to get permission type"); - return -1; - } - - info->val[_AI_PERM] = strdup( - (permission == PMINFO_PERMISSION_SIGNATURE) ? - "signature" : - (permission == PMINFO_PERMISSION_PRIVILEGE) ? - "privilege" : - "normal"); - - return 0; -} - -static int __appinfo_add_pkgid(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - char *pkgid = NULL; - - if (pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK) { - _E("failed to get pkgid"); - return -1; - } - - info->val[_AI_PKGID] = strdup(pkgid); - - return 0; -} - -static int __appinfo_add_preload(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - bool preload = false; - - if (pkgmgrinfo_appinfo_is_preload(handle, &preload) != PMINFO_R_OK) { - _E("failed to get preload"); - return -1; - } - - info->val[_AI_PRELOAD] = strdup(preload ? "true" : "false"); - - return 0; -} - -static int __appinfo_add_status(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - info->val[_AI_STATUS] = strdup("installed"); - - return 0; -} - -static int __appinfo_add_pool(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - bool process_pool = false; - - if (pkgmgrinfo_appinfo_is_process_pool(handle, &process_pool) != PMINFO_R_OK) { - _E("failed to get process_pool"); - return -1; - } - - info->val[_AI_POOL] = strdup(process_pool ? "true" : "false"); - - return 0; -} - -static int __appinfo_add_comptype(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - char *component_type = NULL; - - if (pkgmgrinfo_appinfo_get_component_type(handle, - &component_type) != PMINFO_R_OK) { - _E("failed to get component type"); - return -1; - } - - info->val[_AI_COMPTYPE] = strdup(component_type); - - return 0; -} - -static int __appinfo_add_tep(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - char *tep_name = NULL; - struct user_appinfo *user_data = (struct user_appinfo *)data; - - if (pkgmgrinfo_pkginfo_get_tep_name((pkgmgrinfo_pkginfo_h)user_data->extra_data, - &tep_name) != PMINFO_R_OK) { - _E("failed to get tep_name"); - info->val[_AI_TEP] = NULL; - } else { - info->val[_AI_TEP] = strdup(tep_name); - } - - return 0; -} - -static int __appinfo_add_storage_type(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - pkgmgrinfo_installed_storage installed_storage; - - if (pkgmgrinfo_appinfo_get_installed_storage_location(handle, - &installed_storage) == PMINFO_R_OK) { - if (installed_storage == PMINFO_INTERNAL_STORAGE) - info->val[_AI_STORAGE_TYPE] = strdup("internal"); - else if (installed_storage == PMINFO_EXTERNAL_STORAGE) - info->val[_AI_STORAGE_TYPE] = strdup("external"); - } else { - info->val[_AI_STORAGE_TYPE] = strdup("internal"); - } - - return 0; -} - -static int __appinfo_add_bg_category(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - info->val[_AI_BG_CATEGORY] = 0x0; - if (pkgmgrinfo_appinfo_foreach_background_category(handle, - __read_background_category, info) != PMINFO_R_OK) { - _E("Failed to get background category"); - return -1; - } - - return 0; -} - -static int __appinfo_add_launch_mode(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - char *mode = NULL; - - if (pkgmgrinfo_appinfo_get_launch_mode(handle, &mode) != PMINFO_R_OK) { - _E("failed to get launch_mode"); - return -1; - } - - info->val[_AI_LAUNCH_MODE] = strdup(mode ? mode : "single"); - - return 0; -} - -static int __appinfo_add_global(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - bool is_global = false; - struct user_appinfo *user_data = (struct user_appinfo *)data; - - if (pkgmgrinfo_pkginfo_is_for_all_users((pkgmgrinfo_pkginfo_h)user_data->extra_data, - &is_global) != PMINFO_R_OK) { - _E("get pkginfo failed"); - return -1; - } - - info->val[_AI_GLOBAL] = strdup(is_global ? "true" : "false"); - - return 0; -} - -static int __appinfo_add_effective_appid(const pkgmgrinfo_appinfo_h handle, struct appinfo *info, void *data) -{ - char *effective_appid = NULL; - - if (pkgmgrinfo_appinfo_get_effective_appid(handle, &effective_appid) != PMINFO_R_OK) { - _D("Failed to get effective appid"); - info->val[_AI_EFFECTIVE_APPID] = NULL; - } else { - if (effective_appid && strlen(effective_appid) > 0) - info->val[_AI_EFFECTIVE_APPID] = strdup(effective_appid); - } - - return 0; -} - -static struct appinfo_t _appinfos[] = { - [_AI_NAME] = {"Name", AIT_NAME, __appinfo_add_name}, - [_AI_EXEC] = {"Exec", AIT_EXEC, __appinfo_add_exec}, - [_AI_TYPE] = {"PkgType", AIT_TYPE, __appinfo_add_type}, - [_AI_ONBOOT] = {"StartOnBoot", AIT_ONBOOT, __appinfo_add_onboot}, - [_AI_RESTART] = {"AutoRestart", AIT_RESTART, __appinfo_add_restart}, - [_AI_MULTI] = {"Multiple", AIT_MULTI, __appinfo_add_multi}, - [_AI_HWACC] = {"Hwacceleration", AIT_HWACC, __appinfo_add_hwacc}, - [_AI_PERM] = {"PermissionType", AIT_PERM, __appinfo_add_perm}, - [_AI_PKGID] = {"PackageId", AIT_PKGID, __appinfo_add_pkgid}, - [_AI_PRELOAD] = {"Preload", AIT_PRELOAD, __appinfo_add_preload}, - [_AI_STATUS] = {"Status", AIT_STATUS, __appinfo_add_status}, - [_AI_POOL] = {"ProcessPool", AIT_POOL, __appinfo_add_pool}, - [_AI_COMPTYPE] = {"ComponentType", AIT_COMPTYPE, __appinfo_add_comptype}, - [_AI_TEP] = {"Tep", AIT_TEP, __appinfo_add_tep}, - [_AI_STORAGE_TYPE] = {"StorageType", AIT_STORAGE_TYPE, __appinfo_add_storage_type}, - [_AI_BG_CATEGORY] = {"BackgroundCategory", AIT_BG_CATEGORY, __appinfo_add_bg_category}, - [_AI_LAUNCH_MODE] = {"launch_mode", AIT_LAUNCH_MODE, __appinfo_add_launch_mode}, - [_AI_GLOBAL] = {"global", AIT_GLOBAL, __appinfo_add_global}, - [_AI_EFFECTIVE_APPID] = {"effective-appid", AIT_EFFECTIVE_APPID, __appinfo_add_effective_appid}, -}; - -static int __appinfo_insert_handler (const pkgmgrinfo_appinfo_h handle, - void *data) -{ - int i; - struct appinfo *c; - struct user_appinfo *info = (struct user_appinfo *)data; - char *appid; - - if (!handle) { - _E("null app handle"); - return -1; - } - - if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK) { - _E("fail to get appinfo"); - return -1; - } - - g_hash_table_remove(info->tbl, appid); - - c = calloc(1, sizeof(struct appinfo)); - if (!c) { - _E("create appinfo: %s", strerror(errno)); - return -1; - } - - c->val[_AI_FILE] = strdup(appid); - - for (i = 0; i < _AI_MAX; i++) { - if (_appinfos[i].add && _appinfos[i].add(handle, c, info) < 0) { - __free_appinfo(c); - return -1; - } - } - - SECURE_LOGD("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMPTYPE], - c->val[_AI_TYPE]); - - g_hash_table_insert(info->tbl, c->val[_AI_FILE], c); - - return 0; -} - -static int __pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data) -{ - bool is_global; - struct user_appinfo *info = (struct user_appinfo *)user_data; - - if (pkgmgrinfo_pkginfo_is_for_all_users(handle, &is_global)) { - _E("get pkginfo failed"); - return -1; - } - - /* do not load appinfo for attached global apps */ - if (info->uid != GLOBAL_USER && is_global) - return 0; - - info->extra_data = handle; - if (pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, - __appinfo_insert_handler, user_data, - info->uid)) { - _E("get appinfo failed"); - return -1; - } - - return 0; -} - -static void __remove_user_appinfo(uid_t uid) -{ - g_hash_table_remove(user_tbl, GINT_TO_POINTER(uid)); -} - -static void __handle_onboot(void *user_data, const char *appid, - struct appinfo *info) -{ - uid_t uid = (uid_t)(intptr_t)user_data; - - if (!strcmp(info->val[_AI_ONBOOT], "true")) { - if (_status_app_is_running(appid, uid) > 0) - return; - _D("start app %s from user %d by onboot", appid, uid); - _start_app_local(uid, info->val[_AI_NAME]); - } -} - -static struct user_appinfo *__add_user_appinfo(uid_t uid) -{ - int r; - struct user_appinfo *info; - - info = calloc(1, sizeof(struct user_appinfo)); - if (info == NULL) { - _E("out of memory"); - return NULL; - } - - info->uid = uid; - info->tbl = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, - __free_appinfo); - if (info->tbl == NULL) { - _E("out of memory"); - free(info); - return NULL; - } - - g_hash_table_insert(user_tbl, GINT_TO_POINTER(uid), info); - - r = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, info, info->uid); - if (r != PMINFO_R_OK) { - __remove_user_appinfo(uid); - return NULL; - } - - if (uid != GLOBAL_USER) { - appinfo_foreach(uid, __handle_onboot, (void *)(intptr_t)uid); - appinfo_foreach(GLOBAL_USER, __handle_onboot, - (void *)(intptr_t)uid); - } - - _D("loaded appinfo table for uid %d", uid); - - return info; -} - -static struct user_appinfo *__find_user_appinfo(uid_t uid) -{ - return g_hash_table_lookup(user_tbl, GINT_TO_POINTER(uid)); -} - -static void __appinfo_set_blocking_cb(void *user_data, - const char *appid, struct appinfo *info) -{ - char *pkgid = (char *)user_data; - - if (strcmp(info->val[_AI_PKGID], pkgid)) - return; - - free(info->val[_AI_STATUS]); - info->val[_AI_STATUS] = strdup("blocking"); - _D("%s status changed: blocking", appid); -} - -static void __appinfo_unset_blocking_cb(void *user_data, - const char *appid, struct appinfo *info) -{ - char *pkgid = (char *)user_data; - - if (strcmp(info->val[_AI_PKGID], pkgid)) - return; - - free(info->val[_AI_STATUS]); - info->val[_AI_STATUS] = strdup("installed"); - _D("%s status changed: installed", appid); -} - -static gboolean __appinfo_remove_cb(gpointer key, gpointer value, gpointer data) -{ - char *pkgid = (char *)data; - struct appinfo *info = (struct appinfo *)value; - - if (!strcmp(info->val[_AI_PKGID], pkgid)) { - _D("appinfo removed: %s", info->val[_AI_NAME]); - return TRUE; - } - - return FALSE; -} - -static void __appinfo_delete_on_event(uid_t uid, const char *pkgid) -{ - struct user_appinfo *info; - - info = __find_user_appinfo(uid); - if (info == NULL) { - _E("cannot find appinfo for uid %d", uid); - return; - } - - g_hash_table_foreach_remove(info->tbl, __appinfo_remove_cb, - (gpointer)pkgid); -} - -static void __appinfo_insert_on_event(uid_t uid, const char *pkgid) -{ - appinfo_insert(uid, pkgid); - appinfo_foreach(uid, __handle_onboot, (void *)(intptr_t)uid); -} - -static int __package_event_cb(uid_t target_uid, int req_id, - const char *pkg_type, const char *pkgid, - const char *key, const char *val, const void *pmsg, void *data) -{ - char *op; - - if (!strcasecmp(key, "start")) { - if (!strcasecmp(val, "uninstall") || - !strcasecmp(val, "update")) { - appinfo_foreach(target_uid, __appinfo_set_blocking_cb, - (void *)pkgid); - } - g_hash_table_insert(pkg_pending, strdup(pkgid), strdup(val)); - } - - if (!strcasecmp(key, "error")) { - if (!strcasecmp(val, "uninstall") || - !strcasecmp(val, "update")) { - appinfo_foreach(target_uid, __appinfo_unset_blocking_cb, - (void *)pkgid); - } - g_hash_table_remove(pkg_pending, pkgid); - } - - if (!strcasecmp(key, "end")) { - op = g_hash_table_lookup(pkg_pending, pkgid); - if (op == NULL) - return 0; - - if (!strcasecmp(op, "uninstall")) { - __appinfo_delete_on_event(target_uid, pkgid); - } else if (!strcasecmp(op, "install")) { - __appinfo_insert_on_event(target_uid, pkgid); - } else if (!strcasecmp(op, "update")) { - __appinfo_delete_on_event(target_uid, pkgid); - __appinfo_insert_on_event(target_uid, pkgid); - } - - g_hash_table_remove(pkg_pending, pkgid); - } - - return 0; -} - -static int __init_package_event_handler(void) -{ - pc = pkgmgr_client_new(PC_LISTENING); - if (pc == NULL) - return -1; - - if (pkgmgr_client_listen_status(pc, __package_event_cb, NULL) < 0) - return -1; - - return 0; -} - -static void __fini_package_event_handler(void) -{ - pkgmgr_client_free(pc); -} - -int appinfo_init(void) -{ - FILE *fp; - char buf[4096] = {0,}; - char *tmp; - struct user_appinfo *global_appinfo; - - fp = fopen("/proc/cmdline", "r"); - if (fp == NULL) { - _E("appinfo init failed: %s", strerror(errno)); - return -1; - } - - if (fgets(buf, sizeof(buf), fp) != NULL) { - tmp = strstr(buf, "gles"); - if (tmp != NULL) - sscanf(tmp, "gles=%d", &gles); - } - fclose(fp); - - user_tbl = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, - __free_user_appinfo); - if (user_tbl == NULL) - return -1; - - pkg_pending = g_hash_table_new_full(g_str_hash, g_str_equal, - free, free); - if (pkg_pending == NULL) - return -1; - - - global_appinfo = __add_user_appinfo(GLOBAL_USER); - if (global_appinfo == NULL) { - appinfo_fini(); - return -1; - } - - if (__init_package_event_handler()) { - appinfo_fini(); - return -1; - } - - return 0; -} - -void appinfo_fini(void) -{ - g_hash_table_destroy(user_tbl); - g_hash_table_destroy(pkg_pending); - __fini_package_event_handler(); -} - -struct appinfo *appinfo_find(uid_t caller_uid, const char *appid) -{ - struct user_appinfo *info; - struct appinfo *ai; - - /* search from user table */ - info = __find_user_appinfo(caller_uid); - if (info == NULL) { - info = __add_user_appinfo(caller_uid); - if (info == NULL) - return NULL; - } - - ai = g_hash_table_lookup(info->tbl, appid); - if (ai) - return ai; - - if (caller_uid == GLOBAL_USER) - return NULL; - - /* search again from global table */ - info = __find_user_appinfo(GLOBAL_USER); - if (info == NULL) { - _E("cannot find global appinfo table!"); - return NULL; - } - - return g_hash_table_lookup(info->tbl, appid); -} - -int appinfo_insert(uid_t uid, const char *pkgid) -{ - struct user_appinfo *info; - pkgmgrinfo_pkginfo_h handle; - - info = __find_user_appinfo(uid); - if (info == NULL) { - info = __add_user_appinfo(uid); - if (info == NULL) - _E("load appinfo for uid %d failed", uid); - return 0; - } - - if (pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle)) { - _E("get pkginfo failed: %s", pkgid); - return -1; - } - - info->extra_data = handle; - if (pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, - __appinfo_insert_handler, - info, info->uid)) { - _E("add appinfo of pkg %s failed", pkgid); - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return -1; - } - - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - - return 0; -} - -static void __reload_appinfo(gpointer key, gpointer value, gpointer user_data) -{ - int r; - struct user_appinfo *info = (struct user_appinfo *)value; - - g_hash_table_remove_all(info->tbl); - - r = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, info, info->uid); - if (r != PMINFO_R_OK) { - __remove_user_appinfo(info->uid); - return; - } - - _D("reloaded appinfo table for uid %d", info->uid); -} - -void appinfo_reload(void) -{ - g_hash_table_foreach(user_tbl, __reload_appinfo, NULL); -} - -const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type) -{ - enum _appinfo_idx i; - - if (!c) { - errno = EINVAL; - _E("appinfo get value: %s", strerror(errno)); - return NULL; - } - - for (i = _AI_START; i < sizeof(_appinfos)/sizeof(_appinfos[0]); i++) { - if (type == _appinfos[i].type) - return c->val[i]; - } - - errno = ENOENT; - _E("appinfo get value: %s", strerror(errno)); - - return NULL; -} - -int appinfo_set_value(struct appinfo *c, enum appinfo_type type, const char *val) -{ - int i; - - if (!c || !val) { - errno = EINVAL; - _E("appinfo is NULL, type: %d, val %s", type, val); - return -1; - } - - for (i = _AI_START; i < sizeof(_appinfos)/sizeof(_appinfos[0]); i++) { - if (type == _appinfos[i].type) - _D("%s : %s : %s", c->val[_AI_FILE], c->val[i], val); - free(c->val[i]); - c->val[i] = strdup(val); - } - - return 0; -} - -const char *appinfo_get_filename(const struct appinfo *c) -{ - if (!c) { - errno = EINVAL; - SECURE_LOGE("appinfo get filename: %s", strerror(errno)); - return NULL; - } - - return c->val[_AI_FILE]; -} - -struct _cbinfo { - appinfo_iter_callback cb; - void *cb_data; -}; - -static void __iter_cb(gpointer key, gpointer value, gpointer user_data) -{ - struct _cbinfo *cbi = user_data; - - cbi->cb(cbi->cb_data, key, value); -} - -void appinfo_foreach(uid_t uid, appinfo_iter_callback cb, void *user_data) -{ - struct user_appinfo *info; - struct _cbinfo cbi; - - info = __find_user_appinfo(uid); - if (info == NULL) { - info = __add_user_appinfo(uid); - if (info == NULL) - return; - } - - if (!cb) { - errno = EINVAL; - _E("appinfo foreach: %s", strerror(errno)); - return; - } - - cbi.cb = cb; - cbi.cb_data = user_data; - - g_hash_table_foreach(info->tbl, __iter_cb, &cbi); -} - -int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type) -{ - const char *v; - - v = appinfo_get_value(c, type); - if (!v) - return -1; - - if (!strcmp(v, "1") || !strcasecmp(v, "true")) - return 1; - - if (!strcmp(v, "0") || !strcasecmp(v, "false")) - return 0; - - errno = EFAULT; - - return -1; -} - diff --git a/am_daemon/amd_appinfo.h b/am_daemon/amd_appinfo.h deleted file mode 100644 index 94a02e2..0000000 --- a/am_daemon/amd_appinfo.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - */ - -#pragma once - -#include - -struct appinfomgr; -struct appinfo; - -enum appinfo_type { - AIT_NAME, - AIT_EXEC, - AIT_TYPE, - AIT_ONBOOT, /* start on boot: boolean */ - AIT_RESTART, /* auto restart: boolean */ - AIT_MULTI, - AIT_HWACC, - AIT_PERM, - AIT_PKGID, - AIT_PRELOAD, - AIT_STATUS, - AIT_POOL, - AIT_COMPTYPE, - AIT_TEP, - AIT_STORAGE_TYPE, - AIT_BG_CATEGORY, - AIT_LAUNCH_MODE, - AIT_GLOBAL, - AIT_EFFECTIVE_APPID, - AIT_MAX -}; - -#define APP_TYPE_SERVICE "svcapp" -#define APP_TYPE_UI "uiapp" -#define APP_TYPE_WIDGET "widgetapp" -#define APP_TYPE_WATCH "watchapp" - -int appinfo_init(void); -void appinfo_fini(void); - -int appinfo_insert(uid_t uid, const char *pkgid); - -struct appinfo *appinfo_find(uid_t caller_uid, const char *appid); -const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type); -int appinfo_set_value(struct appinfo *c, enum appinfo_type, const char *val); -const char *appinfo_get_filename(const struct appinfo *c); -int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type); - -typedef void (*appinfo_iter_callback)(void *user_data, - const char *filename, struct appinfo *c); -void appinfo_foreach(uid_t uid, appinfo_iter_callback cb, void *user_data); -void appinfo_reload(void); - - diff --git a/am_daemon/amd_config.h b/am_daemon/amd_config.h deleted file mode 100644 index 397d2c0..0000000 --- a/am_daemon/amd_config.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2000 - 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. - */ - - - -#define AMD_LOG - diff --git a/am_daemon/amd_cynara.c b/am_daemon/amd_cynara.c deleted file mode 100644 index feeeb11..0000000 --- a/am_daemon/amd_cynara.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include - -#include "simple_util.h" - -static cynara *r_cynara = NULL; - -static int _get_caller_info_from_cynara(int sockfd, char **client, char **user, char **session) -{ - pid_t pid; - int r; - char buf[MAX_LOCAL_BUFSZ] = {0,}; - - r = cynara_creds_socket_get_pid(sockfd, &pid); - if (r != CYNARA_API_SUCCESS) { - cynara_strerror(r, buf, MAX_LOCAL_BUFSZ); - _E("cynara_creds_socket_get_pid failed: %s", buf); - return -1; - } - - *session = cynara_session_from_pid(pid); - if (*session == NULL) { - _E("cynara_session_from_pid failed."); - return -1; - } - - r = cynara_creds_socket_get_user(sockfd, USER_METHOD_DEFAULT, user); - if (r != CYNARA_API_SUCCESS) { - cynara_strerror(r, buf, MAX_LOCAL_BUFSZ); - _E("cynara_cred_socket_get_user failed."); - return -1; - } - - r = cynara_creds_socket_get_client(sockfd, CLIENT_METHOD_DEFAULT, client); - if (r != CYNARA_API_SUCCESS) { - cynara_strerror(r, buf, MAX_LOCAL_BUFSZ); - _E("cynara_creds_socket_get_client failed."); - return -1; - } - - return 0; -} - -int check_privilege_by_cynara(int sockfd, const char *privilege) -{ - int r; - int ret; - char buf[MAX_LOCAL_BUFSZ] = {0,}; - char *client = NULL; - char *session = NULL; - char *user = NULL; - - r = _get_caller_info_from_cynara(sockfd, &client, &user, &session); - if (r < 0) { - ret = -1; - goto end; - } - - r = cynara_check(r_cynara, client, session, user, privilege); - switch (r) { - case CYNARA_API_ACCESS_ALLOWED: - _D("%s(%s) from user %s privilege %s allowed.", client, session, user, privilege); - ret = 0; - break; - case CYNARA_API_ACCESS_DENIED: - _E("%s(%s) from user %s privilege %s denied.", client, session, user, privilege); - ret = -1; - break; - default: - cynara_strerror(r, buf, MAX_LOCAL_BUFSZ); - _E("cynara_check failed: %s", buf); - ret = -1; - break; - } - -end: - if (user) - free(user); - if (session) - free(session); - if (client) - free(client); - - return ret; -} - -int init_cynara(void) -{ - int ret; - - ret = cynara_initialize(&r_cynara, NULL); - if (ret != CYNARA_API_SUCCESS) { - _E("cynara initialize failed."); - return ret; - } - - return 0; -} - -void finish_cynara(void) -{ - if (r_cynara) - cynara_finish(r_cynara); - r_cynara = NULL; -} diff --git a/am_daemon/amd_cynara.h b/am_daemon/amd_cynara.h deleted file mode 100644 index 869cc95..0000000 --- a/am_daemon/amd_cynara.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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. - */ - -int init_cynara(void); -void finish_cynara(void); -int check_privilege_by_cynara(int sockfd, const char *privilege); diff --git a/am_daemon/amd_launch.c b/am_daemon/amd_launch.c deleted file mode 100644 index ad45c22..0000000 --- a/am_daemon/amd_launch.c +++ /dev/null @@ -1,844 +0,0 @@ -/* - * Copyright (c) 2000 - 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. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "amd_config.h" -#include "amd_launch.h" -#include "amd_appinfo.h" -#include "amd_status.h" -#include "amd_app_group.h" -#include "app_sock.h" -#include "simple_util.h" -#include "launch.h" -#include "app_signal.h" -#include "aul_svc.h" -#include "aul_svc_priv_key.h" -#include "amd_cynara.h" - -#define DAC_ACTIVATE - -#define TERM_WAIT_SEC 3 -#define INIT_PID 1 - -#define AUL_PR_NAME 16 - -/* SDK related defines */ -#define PATH_APP_ROOT tzplatform_getenv(TZ_USER_APP) -#define PATH_GLOBAL_APP_ROOT tzplatform_getenv(TZ_SYS_RW_APP) -#define PATH_DATA "/data" -#define SDK_CODE_COVERAGE "CODE_COVERAGE" -#define SDK_DYNAMIC_ANALYSIS "DYNAMIC_ANALYSIS" -#define PATH_DA_SO "/home/developer/sdk_tools/da/da_probe.so" -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) -#define PREFIX_EXTERNAL_STORAGE_PATH "/opt/storage/sdcard/" - -typedef struct { - char *pkg_name; /* package */ - char *app_path; /* exec */ - char *original_app_path; /* exec */ - int multiple; /* x_slp_multiple */ - char *pkg_type; -} app_info_from_pkgmgr; - -static int __pid_of_last_launched_ui_app; - -static void __set_reply_handler(int fd, int pid, int clifd, int cmd); -static void __real_send(int clifd, int ret); -static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd); - -static void __set_stime(bundle *kb) -{ - struct timeval tv; - char tmp[MAX_LOCAL_BUFSZ]; - - gettimeofday(&tv, NULL); - snprintf(tmp, MAX_LOCAL_BUFSZ, "%ld/%ld", tv.tv_sec, tv.tv_usec); - bundle_add(kb, AUL_K_STARTTIME, tmp); -} - -int _start_app_local_with_bundle(uid_t uid, const char *appid, bundle *kb) -{ - bool dummy; - - __set_stime(kb); - bundle_add(kb, AUL_K_APPID, appid); - return _start_app(appid, kb, APP_START, getpid(), uid, -1, &dummy); -} - -int _start_app_local(uid_t uid, const char *appid) -{ - int pid; - bundle *kb; - - kb = bundle_create(); - if (kb == NULL) { - _E("out of memory"); - return -1; - } - - pid = _start_app_local_with_bundle(uid, appid, kb); - - bundle_free(kb); - - return pid; -} - -int _send_to_sigkill(int pid) -{ - int pgid; - - pgid = getpgid(pid); - if (pgid <= 1) - return -1; - - if (killpg(pgid, SIGKILL) < 0) - return -1; - - return 0; -} - -int _resume_app(int pid, int clifd) -{ - int dummy; - int ret; - - if ((ret = __app_send_raw_with_delay_reply(pid, APP_RESUME_BY_PID, - (unsigned char *)&dummy, 0)) < 0) { - if (ret == -EAGAIN) - _E("resume packet timeout error"); - else { - _E("raise failed - %d resume fail\n", pid); - _E("we will term the app - %d\n", pid); - _send_to_sigkill(pid); - ret = -1; - } - __real_send(clifd, ret); - } - _D("resume done\n"); - - if (ret > 0) - __set_reply_handler(ret, pid, clifd, APP_RESUME_BY_PID); - - return ret; -} - -int _pause_app(int pid, int clifd) -{ - int dummy; - int ret; - - if ((ret = __app_send_raw_with_delay_reply(pid, APP_PAUSE_BY_PID, - (unsigned char *)&dummy, 0)) < 0) { - if (ret == -EAGAIN) - _E("pause packet timeout error"); - else { - _E("iconify failed - %d pause fail", pid); - _E("we will term the app - %d", pid); - _send_to_sigkill(pid); - ret = -1; - } - close(clifd); - } - _D("pause done"); - - if (ret > 0) - __set_reply_handler(ret, pid, clifd, APP_PAUSE_BY_PID); - - return ret; -} - -int _term_sub_app(int pid) -{ - int dummy; - int ret; - - if ((ret = __app_send_raw_with_noreply(pid, APP_TERM_BY_PID_ASYNC, - (unsigned char *)&dummy, 0)) < 0) { - _E("terminate packet send error - use SIGKILL"); - if (_send_to_sigkill(pid) < 0) { - _E("fail to killing - %d\n", pid); - return -1; - } - } - - return 0; -} - -int _term_app(int pid, int clifd) -{ - int dummy; - int ret; - - if (app_group_is_leader_pid(pid)) { - int cnt; - int *pids = NULL; - int i; - - app_group_get_group_pids(pid, &cnt, &pids); - if (cnt > 0) { - for (i = cnt - 1 ; i >= 0; i--) { - if (i != 0) - _term_sub_app(pids[i]); - app_group_remove(pids[i]); - - } - free(pids); - } - } - - if ((ret = __app_send_raw_with_delay_reply(pid, APP_TERM_BY_PID, - (unsigned char *)&dummy, 0)) < 0) { - _D("terminate packet send error - use SIGKILL"); - if (_send_to_sigkill(pid) < 0) { - _E("fail to killing - %d\n", pid); - __real_send(clifd, -1); - return -1; - } - __real_send(clifd, 0); - } - _D("term done\n"); - if (ret > 0) - __set_reply_handler(ret, pid, clifd, APP_TERM_BY_PID); - - return 0; -} - -int _term_req_app(int pid, int clifd) -{ - int dummy; - int ret; - - if ((ret = __app_send_raw_with_delay_reply(pid, APP_TERM_REQ_BY_PID, - (unsigned char *)&dummy, 0)) < 0) { - _D("terminate req send error"); - __real_send(clifd, ret); - } - - if (ret > 0) - __set_reply_handler(ret, pid, clifd, APP_TERM_REQ_BY_PID); - - return 0; -} - -int _term_bgapp(int pid, int clifd) -{ - int dummy; - int fd; - int cnt; - int *pids = NULL; - int i; - int status = -1; - - if (app_group_is_leader_pid(pid)) { - app_group_get_group_pids(pid, &cnt, &pids); - if (cnt > 0) { - status = _status_get_app_info_status(pids[cnt - 1], getuid()); - if (status == STATUS_BG) { - for (i = cnt - 1 ; i >= 0; i--) { - if (i != 0) - _term_sub_app(pids[i]); - app_group_remove(pids[i]); - } - } - } - free(pids); - } - - if ((fd = __app_send_raw_with_delay_reply(pid, APP_TERM_BGAPP_BY_PID, - (unsigned char *)&dummy, sizeof(int))) < 0) { - _D("terminate packet send error - use SIGKILL"); - if (_send_to_sigkill(pid) < 0) { - _E("fail to killing - %d", pid); - __real_send(clifd, -1); - return -1; - } - __real_send(clifd, 0); - } - _D("term_bgapp done"); - if (fd > 0) - __set_reply_handler(fd, pid, clifd, APP_TERM_BGAPP_BY_PID); - - return 0; -} - -int _fake_launch_app(int cmd, int pid, bundle *kb, int clifd) -{ - int datalen; - int ret; - bundle_raw *kb_data; - - bundle_encode(kb, &kb_data, &datalen); - if ((ret = __app_send_raw_with_delay_reply(pid, cmd, kb_data, datalen)) < 0) { - _E("error request fake launch - error code = %d", ret); - __real_send(clifd, ret); - } - free(kb_data); - - if (ret > 0) - __set_reply_handler(ret, pid, clifd, cmd); - - return ret; -} - -static void __real_send(int clifd, int ret) -{ - if (clifd < 0) - return; - - if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) { - if (errno == EPIPE) - _E("send failed due to EPIPE.\n"); - - _E("send fail to client"); - } - - close(clifd); -} - -static gboolean __au_glib_check(GSource *src) -{ - GSList *fd_list; - GPollFD *tmp; - - fd_list = src->poll_fds; - do { - tmp = (GPollFD *) fd_list->data; - if ((tmp->revents & (POLLIN | POLLPRI))) - return TRUE; - fd_list = fd_list->next; - } while (fd_list); - - return FALSE; -} - -static gboolean __au_glib_dispatch(GSource *src, GSourceFunc callback, gpointer data) -{ - callback(data); - return TRUE; -} - -static gboolean __au_glib_prepare(GSource *src, gint *timeout) -{ - return FALSE; -} - -static GSourceFuncs funcs = { - .prepare = __au_glib_prepare, - .check = __au_glib_check, - .dispatch = __au_glib_dispatch, - .finalize = NULL -}; - -struct reply_info { - GSource *src; - GPollFD *gpollfd; - guint timer_id; - int clifd; - int pid; - int cmd; -}; - -static gboolean __reply_handler(gpointer data) -{ - struct reply_info *r_info = (struct reply_info *) data;; - int fd = r_info->gpollfd->fd; - int len; - int res = 0; - int clifd = r_info->clifd; - int pid = r_info->pid; - - len = recv(fd, &res, sizeof(int), 0); - if (len == -1) { - if (errno == EAGAIN) { - _E("recv timeout : %s", strerror(errno)); - res = -EAGAIN; - } else { - _E("recv error : %s", strerror(errno)); - res = -ECOMM; - } - } - close(fd); - - if (res < 0) - __real_send(clifd, res); - else - __real_send(clifd, pid); - - _D("listen fd : %d , send fd : %d, pid : %d", fd, clifd, pid); - - g_source_remove(r_info->timer_id); - g_source_remove_poll(r_info->src, r_info->gpollfd); - g_source_destroy(r_info->src); - g_free(r_info->gpollfd); - free(r_info); - - return TRUE; -} - -static gboolean __recv_timeout_handler(gpointer data) -{ - struct reply_info *r_info = (struct reply_info *) data; - int fd = r_info->gpollfd->fd; - int clifd = r_info->clifd; - - __real_send(clifd, -EAGAIN); - - close(fd); - - g_source_remove_poll(r_info->src, r_info->gpollfd); - g_source_destroy(r_info->src); - g_free(r_info->gpollfd); - free(r_info); - - return FALSE; -} - -static void __set_reply_handler(int fd, int pid, int clifd, int cmd) -{ - GPollFD *gpollfd; - GSource *src; - struct reply_info *r_info; - - src = g_source_new(&funcs, sizeof(GSource)); - - gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD)); - gpollfd->events = POLLIN; - gpollfd->fd = fd; - - r_info = malloc(sizeof(*r_info)); - if (r_info == NULL) { - _E("out of memory"); - g_free(gpollfd); - g_source_unref(src); - return; - } - - r_info->clifd = clifd; - r_info->pid = pid; - r_info->src = src; - r_info->gpollfd = gpollfd; - r_info->cmd = cmd; - - r_info->timer_id = g_timeout_add(5000, __recv_timeout_handler, (gpointer) r_info); - g_source_add_poll(src, gpollfd); - g_source_set_callback(src, (GSourceFunc) __reply_handler, (gpointer) r_info, NULL); - g_source_set_priority(src, G_PRIORITY_DEFAULT); - g_source_attach(src, NULL); - - _D("listen fd : %d, send fd : %d", fd, clifd); -} - -static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd) -{ - int ret; - - switch (cmd) { - case APP_OPEN: - case APP_RESUME: - _D("resume app's pid : %d\n", pid); - if ((ret = _resume_app(pid, clifd)) < 0) - _E("__resume_app failed. error code = %d", ret); - _D("resume app done"); - break; - - case APP_START: - case APP_START_RES: - _D("fake launch pid : %d\n", pid); - if ((ret = _fake_launch_app(cmd, pid, kb, clifd)) < 0) - _E("fake_launch failed. error code = %d", ret); - _D("fake launch done"); - break; - default: - _E("unknown command: %d", cmd); - ret = -1; - } - - return ret; -} - -static int __compare_signature(const struct appinfo *ai, int cmd, - uid_t caller_uid, const char* appid, char *caller_appid, int fd) -{ - const char *permission; - int ret; - const struct appinfo *caller_ai; - const char *preload; - pkgmgrinfo_cert_compare_result_type_e compare_result; - - permission = appinfo_get_value(ai, AIT_PERM); - if (permission && strncmp(permission, "signature", 9) == 0) { - if (caller_uid != 0 && (cmd == APP_START || cmd == APP_START_RES)) { - caller_ai = appinfo_find(caller_uid, caller_appid); - preload = appinfo_get_value(caller_ai, AIT_PRELOAD); - if (preload && strncmp(preload, "true", 4) != 0) { - /* is admin is global */ - if (caller_uid != GLOBAL_USER) - pkgmgrinfo_pkginfo_compare_usr_app_cert_info(caller_appid, - appid, caller_uid, &compare_result); - else - pkgmgrinfo_pkginfo_compare_app_cert_info(caller_appid, - appid, &compare_result); - if (compare_result != PMINFO_CERT_COMPARE_MATCH) { - ret = -EILLEGALACCESS; - __real_send(fd, ret); - return ret; - } - } - } - } - - return 0; -} - -static int __get_pid_for_app_group(const char *appid, int pid, int caller_uid, bundle* kb, - int *lpid, gboolean *can_attach, gboolean *new_process, - app_group_launch_mode* launch_mode, bool *is_subapp) -{ - int st = -1; - int found_pid = -1; - int found_lpid = -1; - - if (app_group_is_group_app(kb)) { - pid = -1; - *is_subapp = true; - } else { - *is_subapp = false; - } - - if (pid > 0) - st = _status_get_app_info_status(pid, caller_uid); - - if (pid == -1 || st == STATUS_DYING) { - - if (app_group_find_singleton(appid, &found_pid, &found_lpid) == 0) { - pid = found_pid; - *new_process = FALSE; - } else { - *new_process = TRUE; - } - - if (app_group_can_start_app(appid, kb, can_attach, lpid, launch_mode) != 0) { - _E("can't make group info"); - return -EILLEGALACCESS; - } - - if (*can_attach && *lpid == found_lpid) { - _E("can't launch singleton app in the same group"); - return -EILLEGALACCESS; - } - - if (found_pid != -1) { - _W("app_group_clear_top, pid: %d", found_pid); - app_group_clear_top(found_pid); - } - } - - if (pid == -1 && *can_attach) - pid = app_group_find_pid_from_recycle_bin(appid); - - return pid; -} - -static int __tep_mount(char *mnt_path[]) -{ - DBusMessage *msg; - int func_ret = 0; - int rv = 0; - struct stat link_buf = {0,}; - - static DBusConnection *conn = NULL; - - if (!conn) { - conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); - if (!conn) { - _E("dbus_bus_get error"); - return -1; - } - } - - rv = lstat(mnt_path[0], &link_buf); - if (rv == 0) { - rv = unlink(mnt_path[0]); - if (rv) - _E("Unable tp remove link file %s", mnt_path[0]); - } - - msg = dbus_message_new_method_call(TEP_BUS_NAME, TEP_OBJECT_PATH, - TEP_INTERFACE_NAME, TEP_MOUNT_METHOD); - if (!msg) { - _E("dbus_message_new_method_call(%s:%s-%s)", TEP_OBJECT_PATH, - TEP_INTERFACE_NAME, TEP_MOUNT_METHOD); - return -1; - } - - if (!dbus_message_append_args(msg, - DBUS_TYPE_STRING, &mnt_path[0], - DBUS_TYPE_STRING, &mnt_path[1], - DBUS_TYPE_INVALID)) { - _E("Ran out of memory while constructing args\n"); - func_ret = -1; - goto func_out; - } - - if (dbus_connection_send(conn, msg, NULL) == FALSE) { - _E("dbus_connection_send error"); - func_ret = -1; - goto func_out; - } - -func_out: - dbus_message_unref(msg); - - return func_ret; -} - -static void __send_mount_request(const struct appinfo *ai, const char *tep_name, - bundle *kb) -{ - SECURE_LOGD("tep name is: %s", tep_name); - char *mnt_path[2] = {NULL, }; - const char *installed_storage = NULL; - char tep_path[PATH_MAX] = {0, }; - const char *path_app_root = NULL; - - const char *global = appinfo_get_value(ai, AIT_GLOBAL); - const char *pkgid = appinfo_get_value(ai, AIT_PKGID); - installed_storage = appinfo_get_value(ai, AIT_STORAGE_TYPE); - - if (global && strcmp("true", global) == 0) - path_app_root = PATH_GLOBAL_APP_ROOT; - else - path_app_root = PATH_APP_ROOT; - - if (installed_storage != NULL) { - SECURE_LOGD("storage: %s", installed_storage); - if (strncmp(installed_storage, "internal", 8) == 0) { - snprintf(tep_path, PATH_MAX, "%s/%s/res/%s", - path_app_root, pkgid, tep_name); - mnt_path[1] = strdup(tep_path); - snprintf(tep_path, PATH_MAX, "%s/%s/res/tep", - path_app_root, pkgid); - mnt_path[0] = strdup(tep_path); - } else if (strncmp(installed_storage, "external", 8) == 0) { - snprintf(tep_path, PATH_MAX, "%step/%s", - PREFIX_EXTERNAL_STORAGE_PATH, tep_name); - mnt_path[1] = strdup(tep_path); - snprintf(tep_path, PATH_MAX, "%step/tep-access", - PREFIX_EXTERNAL_STORAGE_PATH); /* TODO : keeping tep/tep-access for now for external storage */ - mnt_path[0] = strdup(tep_path); - } - - if (mnt_path[0] && mnt_path[1]) { - bundle_add(kb, AUL_TEP_PATH, mnt_path[0]); - int ret = -1; - ret = aul_is_tep_mount_dbus_done(mnt_path[0]); - if (ret != 1) { - ret = __tep_mount(mnt_path); - if (ret < 0) - _E("dbus error %d", ret); - } - } - if (mnt_path[0]) - free(mnt_path[0]); - if (mnt_path[1]) - free(mnt_path[1]); - } -} - -int _send_hint_for_visibility(uid_t uid) -{ - bundle *b = NULL; - int ret; - - b = bundle_create(); - - ret = app_agent_send_cmd(uid, LAUNCHPAD_PROCESS_POOL_SOCK, - PAD_CMD_VISIBILITY, b); - - if (b) - bundle_free(b); - __pid_of_last_launched_ui_app = 0; - - return ret; -} - -int _get_pid_of_last_launched_ui_app() -{ - return __pid_of_last_launched_ui_app; -} - -int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, - uid_t caller_uid, int fd, bool *pending) -{ - int ret; - const struct appinfo *ai; - const char *status; - const char *multiple = NULL; - const char *app_path = NULL; - const char *pkg_type = NULL; - const char *pkg_id = NULL; - const char *component_type = NULL; - const char *process_pool = NULL; - const char *tep_name = NULL; - int pid = -1; - char tmpbuf[MAX_PID_STR_BUFSZ]; - const char *hwacc; - char *caller_appid; - int lpid; - int callee_status = -1; - gboolean can_attach = FALSE; - gboolean new_process = FALSE; - app_group_launch_mode launch_mode; - const char *pad_type = LAUNCHPAD_PROCESS_POOL_SOCK; - bool is_subapp = false; - - snprintf(tmpbuf, MAX_PID_STR_BUFSZ, "%d", caller_pid); - bundle_add(kb, AUL_K_CALLER_PID, tmpbuf); - - snprintf(tmpbuf, MAX_PID_STR_BUFSZ, "%d", caller_uid); - bundle_add(kb, AUL_K_CALLER_UID, tmpbuf); - - _D("_start_app: caller pid=%d uid=%d", caller_pid, caller_uid); - - if (cmd == APP_START_RES) - bundle_add(kb, AUL_K_WAIT_RESULT, "1"); - - caller_appid = _status_app_get_appid_bypid(caller_pid); - if (caller_appid != NULL) { - bundle_add(kb, AUL_K_CALLER_APPID, caller_appid); - } else { - caller_appid = _status_app_get_appid_bypid(getpgid(caller_pid)); - if (caller_appid != NULL) - bundle_add(kb, AUL_K_CALLER_APPID, caller_appid); - } - - ai = appinfo_find(caller_uid, appid); - if (ai == NULL) { - _D("cannot find appinfo of %s", appid); - __real_send(fd, -ENOENT); - return -1; - } - - status = appinfo_get_value(ai, AIT_STATUS); - if (status == NULL) - return -1; - - if (!strcmp(status, "blocking")) { - _D("blocking"); - __real_send(fd, -EREJECTED); - return -EREJECTED; - } - - app_path = appinfo_get_value(ai, AIT_EXEC); - pkg_type = appinfo_get_value(ai, AIT_TYPE); - pkg_id = appinfo_get_value(ai, AIT_PKGID); - process_pool = appinfo_get_value(ai, AIT_POOL); - - if ((ret = __compare_signature(ai, cmd, caller_uid, appid, caller_appid, fd)) != 0) - return ret; - - multiple = appinfo_get_value(ai, AIT_MULTI); - if (!multiple || strncmp(multiple, "false", 5) == 0) - pid = _status_app_is_running(appid, caller_uid); - - component_type = appinfo_get_value(ai, AIT_COMPTYPE); - if (strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0) { - pid = __get_pid_for_app_group(appid, pid, caller_uid, kb, - &lpid, &can_attach, &new_process, &launch_mode, &is_subapp); - if (pid == -EILLEGALACCESS) { - __real_send(fd, pid); - return pid; - } - } - - tep_name = appinfo_get_value(ai, AIT_TEP); - if (tep_name != NULL) - __send_mount_request(ai, tep_name, kb); - - if (pid > 0) - callee_status = _status_get_app_info_status(pid, caller_uid); - - if (pid > 0 && callee_status != STATUS_DYING) { - if (caller_pid == pid) { - SECURE_LOGD("caller process & callee process is same.[%s:%d]", appid, pid); - pid = -ELOCALLAUNCH_ID; - __real_send(fd, pid); - } else { - aul_send_app_resume_request_signal(pid, appid, pkg_id, component_type); - if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) { - pid = ret; - __real_send(fd, pid); - } - } - } else { - if (callee_status == STATUS_DYING && pid > 0) { - ret = kill(pid, SIGKILL); - if (ret == -1) - _W("send SIGKILL: %s", strerror(errno)); - } - - hwacc = appinfo_get_value(ai, AIT_HWACC); - bundle_add(kb, AUL_K_HWACC, hwacc); - bundle_add(kb, AUL_K_EXEC, app_path); - bundle_add(kb, AUL_K_PACKAGETYPE, pkg_type); - bundle_add(kb, AUL_K_PKGID, pkg_id); - bundle_add(kb, AUL_K_INTERNAL_POOL, process_pool); - bundle_add(kb, AUL_K_COMP_TYPE, component_type); - - if (bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) - pad_type = DEBUG_LAUNCHPAD_SOCK; - - pid = app_agent_send_cmd(caller_uid, pad_type, PAD_CMD_LAUNCH, kb); - if (pid > 0) { - *pending = true; - aul_send_app_launch_request_signal(pid, appid, pkg_id, component_type); - } - } - - if (pid > 0) { - _status_add_app_info_list(appid, app_path, pid, LAUNCHPAD_PID, is_subapp, caller_uid); - if (strncmp(component_type, APP_TYPE_UI, strlen(APP_TYPE_UI)) == 0) { - if (new_process) { - _D("add app group info"); - __pid_of_last_launched_ui_app = pid; - app_group_start_app(pid, kb, lpid, can_attach, launch_mode); - } else { - app_group_restart_app(pid, kb); - } - } - } - - return pid; -} diff --git a/am_daemon/amd_launch.h b/am_daemon/amd_launch.h deleted file mode 100644 index 8bb6f54..0000000 --- a/am_daemon/amd_launch.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2000 - 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. - */ - -#pragma once - -#include - -#include -#include "aul_util.h" -#include "amd_appinfo.h" - -int _send_to_sigkill(int pid); -int _resume_app(int pid, int clifd); -int _pause_app(int pid, int clifd); -int _term_app(int pid, int clifd); -int _term_req_app(int pid, int clifd); -int _term_bgapp(int pid, int clifd); -int _term_sub_app(int pid); -int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd); -int _start_app(const char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd, bool *pend); -int _start_app_local(uid_t uid, const char *appid); -int _start_app_local_with_bundle(uid_t uid, const char *appid, bundle *kb); -int _get_pid_of_last_launched_ui_app(); -int _send_hint_for_visibility(uid_t uid); - - diff --git a/am_daemon/amd_main.c b/am_daemon/amd_main.c deleted file mode 100644 index 1b76bc0..0000000 --- a/am_daemon/amd_main.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright (c) 2000 - 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. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "amd_config.h" -#include "simple_util.h" -#include "aul_util.h" -#include "amd_appinfo.h" -#include "amd_status.h" -#include "amd_launch.h" -#include "amd_request.h" -#include "amd_app_group.h" - -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) -#define AUL_SP_DBUS_PATH "/Org/Tizen/Aul/Syspopup" -#define AUL_SP_DBUS_SIGNAL_INTERFACE "org.tizen.aul.syspopup" -#define AUL_SP_DBUS_LAUNCH_REQUEST_SIGNAL "syspopup_launch_request" - -struct restart_info { - char *appid; - int count; - guint timer; -}; - -static GHashTable *restart_tbl; - -static void __vconf_cb(keynode_t *key, void *data); -static int __init(void); - -static void __vconf_cb(keynode_t *key, void *data) -{ - const char *name; - - name = vconf_keynode_get_name(key); - if (name == NULL) - return; - else if (strcmp(name, VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS) == 0) { - //TODO : clear bgapp - - } -} - -static gboolean __restart_timeout_handler(void *data) -{ - struct restart_info *ri = (struct restart_info *)data; - - _D("ri (%x)", ri); - _D("appid (%s)", ri->appid); - - g_hash_table_remove(restart_tbl, ri->appid); - free(ri->appid); - free(ri); - - return FALSE; -} - -static bool __check_restart(const char *appid) -{ - struct restart_info *ri = NULL; - - ri = g_hash_table_lookup(restart_tbl, appid); - if (!ri) { - ri = malloc(sizeof(struct restart_info)); - if (!ri) { - _E("create restart info: %s", strerror(errno)); - return false; - } - memset(ri, 0, sizeof(struct restart_info)); - ri->appid = strdup(appid); - ri->count = 1; - g_hash_table_insert(restart_tbl, ri->appid, ri); - - _D("ri (%x)", ri); - _D("appid (%s)", appid); - - ri->timer = g_timeout_add(10 * 1000, __restart_timeout_handler, ri); - } else { - ri->count++; - _D("count (%d)", ri->count); - if (ri->count > 5) { - g_source_remove(ri->timer); - g_hash_table_remove(restart_tbl, ri->appid); - free(ri->appid); - free(ri); - return false; - } - } - return true; -} - -static bool __can_restart_app(int pid) -{ - const char *pkg_status; - const char *appid = NULL; - const struct appinfo *ai = NULL; - - appid = _status_app_get_appid_bypid(pid); - - if (!appid) - return false; - - ai = appinfo_find(getuid(), appid); - pkg_status = appinfo_get_value(ai, AIT_STATUS); - _D("appid: %s", appid); - - if (ai && pkg_status && strncmp(pkg_status, "blocking", 8) == 0) { - appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "restart"); - } else if (ai && pkg_status && strncmp(pkg_status, "norestart", 9) == 0) { - appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "installed"); - } else { - int r = appinfo_get_boolean(ai, AIT_RESTART); - - if (r && __check_restart(appid)) - return true; - } - - return false; -} - -static int __app_dead_handler(int pid, void *data) -{ - if (pid <= 0) - return 0; - - _D("APP_DEAD_SIGNAL : %d", pid); - - bool restart; - char *appid = NULL; - const char *tmp_appid; - - restart = __can_restart_app(pid); - if (restart) { - tmp_appid = _status_app_get_appid_bypid(pid); - - if (tmp_appid) - appid = strdup(tmp_appid); - } - - if (app_group_is_leader_pid(pid)) { - _W("app_group_leader_app, pid: %d", pid); - if (app_group_find_second_leader(pid) == -1) { - app_group_clear_top(pid); - app_group_set_dead_pid(pid); - app_group_remove(pid); - } else - app_group_remove_leader_pid(pid); - } else if (app_group_is_sub_app(pid)) { - _W("app_group_sub_app, pid: %d", pid); - int caller_pid = app_group_get_next_caller_pid(pid); - - if (app_group_can_reroute(pid) || (caller_pid > 0 && caller_pid != pid)) { - _W("app_group reroute"); - app_group_reroute(pid); - } else { - _W("app_group clear top"); - app_group_clear_top(pid); - } - app_group_set_dead_pid(pid); - app_group_remove(pid); - } - - _status_remove_app_info_list(pid, getuid()); - _request_flush_pending_request(pid); - aul_send_app_terminated_signal(pid); - - if (restart) - _start_app_local(getuid(), appid); - if (appid) - free(appid); - - return 0; -} - -int __agent_dead_handler(uid_t user) -{ - _status_remove_app_info_list_with_uid(user); - return 0; -} - -static DBusHandlerResult __syspopup_signal_filter(DBusConnection *conn, - DBusMessage *message, void *data) -{ - DBusError error; - const char *interface; - const char *appid; - const char *b_raw; - bundle *kb; - - dbus_error_init(&error); - - interface = dbus_message_get_interface(message); - if (interface == NULL) { - _E("reject by security issue - no interface"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - if (dbus_message_is_signal(message, interface, - AUL_SP_DBUS_LAUNCH_REQUEST_SIGNAL)) { - if (dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &appid, - DBUS_TYPE_STRING, &b_raw, DBUS_TYPE_INVALID) == FALSE) { - _E("Failed to get data: %s", error.message); - dbus_error_free(&error); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - _D("syspopup launch request: %s", appid); - kb = bundle_decode((const bundle_raw *)b_raw, strlen(b_raw)); - if (kb) { - if (_start_app_local_with_bundle(getuid(), appid, kb) < 0) - _E("syspopup launch request failed: %s", appid); - - bundle_free(kb); - } - } - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static int __syspopup_dbus_signal_handler_init(void) -{ - DBusError error; - DBusConnection *conn; - char rule[MAX_LOCAL_BUFSZ]; - - dbus_error_init(&error); - - conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error); - if (conn == NULL) { - _E("Failed to connect to the D-BUS Daemon: %s", error.message); - dbus_error_free(&error); - return -1; - } - - dbus_connection_setup_with_g_main(conn, NULL); - - snprintf(rule, sizeof(rule), "path='%s',type='signal',interface='%s'", - AUL_SP_DBUS_PATH, AUL_SP_DBUS_SIGNAL_INTERFACE); - dbus_bus_add_match(conn, rule, &error); - if (dbus_error_is_set(&error)) { - _E("Failed to rule set: %s", error.message); - dbus_error_free(&error); - return -1; - } - - if (dbus_connection_add_filter(conn, - __syspopup_signal_filter, NULL, NULL) == FALSE) { - _E("Failed to add filter"); - return -1; - } - - _D("syspopup dbus signal initialized"); - - return 0; -} - -static int __init(void) -{ - if (appinfo_init()) { - _E("appinfo_init failed\n"); - return -1; - } - - if (aul_listen_app_dead_signal(__app_dead_handler, NULL)) { - _E("aul_listen_app_dead_signal failed"); - return -1; - } - - restart_tbl = g_hash_table_new(g_str_hash, g_str_equal); - _request_init(); - _status_init(); - app_group_init(); - - if (vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, - __vconf_cb, NULL) != 0) - _E("Unable to register callback for VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS\n"); - - if (__syspopup_dbus_signal_handler_init() < 0) - _E("__syspopup_dbus_signal_handler_init failed"); - - return 0; -} - -int main(int argc, char *argv[]) -{ - GMainLoop *mainloop = NULL; - - if (__init() != 0) { - _E("AMD Initialization failed!\n"); - return -1; - } - - mainloop = g_main_loop_new(NULL, FALSE); - if (!mainloop) { - _E("failed to create glib main loop"); - return -1; - } - g_main_loop_run(mainloop); - - return 0; -} diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c deleted file mode 100644 index f61997d..0000000 --- a/am_daemon/amd_request.c +++ /dev/null @@ -1,1524 +0,0 @@ -/* - * Copyright (c) 2000 - 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. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "amd_config.h" -#include "simple_util.h" -#include "app_sock.h" -#include "aul_util.h" -#include "amd_request.h" -#include "amd_launch.h" -#include "amd_appinfo.h" -#include "amd_status.h" -#include "amd_app_group.h" -#include "amd_cynara.h" -#include "launch.h" -#include "aul_svc.h" -#include "aul_svc_priv_key.h" - -#define INHOUSE_UID tzplatform_getuid(TZ_USER_NAME) -#define REGULAR_UID_MIN 5000 - -#define PRIVILEGE_APPMANAGER_LAUNCH "http://tizen.org/privilege/appmanager.launch" -#define PRIVILEGE_APPMANAGER_KILL "http://tizen.org/privilege/appmanager.kill" -#define PRIVILEGE_APPMANAGER_KILL_BGAPP "http://tizen.org/privilege/appmanager.kill.bgapp" -#define PRIVILEGE_DOWNLOAD "http://tizen.org/privilege/download" -#define PRIVILEGE_CALL "http://tizen.org/privilege/call" - -#define MAX_NR_OF_DESCRIPTORS 2 -#define PENDING_REQUEST_TIMEOUT 5000 /* msec */ - -static GHashTable *__socket_pair_hash = NULL; -static GHashTable *pending_table; - -struct pending_item { - int clifd; - int pid; - guint timer; - GList *pending_list; -}; - -struct request { - int clifd; - app_pkt_t *pkt; - struct ucred cr; -}; - -typedef struct _rua_stat_pkt_t { - int uid; - char *stat_tag; - char *stat_caller; - char appid[512]; - gboolean is_group_app; - char *data; - int len; -} rua_stat_pkt_t; - -typedef int (*app_cmd_dispatch_func)(int clifd, const app_pkt_t *pkt, struct ucred *cr); - -static int __send_result_to_client(int fd, int res); -static gboolean __request_handler(gpointer data); -static gboolean __timeout_pending_item(gpointer user_data); - -static int __send_message(int sock, const struct iovec *vec, int vec_size, const int *desc, int nr_desc) -{ - struct msghdr msg = {0}; - int sndret; - - if (vec == NULL || vec_size < 1) - return -EINVAL; - if (nr_desc < 0 || nr_desc > MAX_NR_OF_DESCRIPTORS) - return -EINVAL; - if (desc == NULL) - nr_desc = 0; - - msg.msg_iov = (struct iovec *)vec; - msg.msg_iovlen = vec_size; - - /* sending ancillary data */ - if (nr_desc > 0) { - int desclen = 0; - struct cmsghdr *cmsg = NULL; - char buff[CMSG_SPACE(sizeof(int) * MAX_NR_OF_DESCRIPTORS)] = {0}; - - msg.msg_control = buff; - msg.msg_controllen = sizeof(buff); - cmsg = CMSG_FIRSTHDR(&msg); - if (cmsg == NULL) - return -EINVAL; - - /* packing files descriptors */ - if (nr_desc > 0) { - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - desclen = cmsg->cmsg_len = CMSG_LEN(sizeof(int) * nr_desc); - memcpy((int *)CMSG_DATA(cmsg), desc, sizeof(int) * nr_desc); - cmsg = CMSG_NXTHDR(&msg, cmsg); - - _D("packing file descriptors done"); - } - - /* finished packing updating the corect length */ - msg.msg_controllen = desclen; - } else { - msg.msg_control = NULL; - msg.msg_controllen = 0; - } - - sndret = sendmsg(sock, &msg, 0); - - _D("sendmsg ret : %d", sndret); - if (sndret < 0) - return -errno; - else - return sndret; -} - -static int __send_result_data(int fd, int cmd, unsigned char *kb_data, int datalen) -{ - int len; - int sent = 0; - int res = 0; - app_pkt_t *pkt = NULL; - - pkt = (app_pkt_t *)malloc(AUL_PKT_HEADER_SIZE + datalen); - if (NULL == pkt) { - _E("Malloc Failed!"); - return -ENOMEM; - } - - pkt->cmd = cmd; - pkt->len = datalen; - memcpy(pkt->data, kb_data, datalen); - - while (sent != AUL_PKT_HEADER_SIZE + datalen) { - len = send(fd, pkt, AUL_PKT_HEADER_SIZE + datalen - sent, 0); - if (len <= 0) { - _E("send error fd:%d (errno %d)", fd, errno); - close(fd); - free(pkt); - return -ECOMM; - } - sent += len; - } - - free(pkt); - close(fd); - - return res; -} - -extern int __app_dead_handler(int pid, uid_t user); -extern int __agent_dead_handler(uid_t user); - -static int __send_result_to_client(int fd, int res) -{ - if (send(fd, &res, sizeof(int), MSG_NOSIGNAL) < 0) { - if (errno == EPIPE) - _E("send failed due to EPIPE.\n"); - _E("send fail to client"); - } - close(fd); - return 0; -} - -static void __real_send(int clifd, int ret) -{ - if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) { - if (errno == EPIPE) - _E("send failed due to EPIPE.\n"); - - _E("send fail to client"); - } - - close(clifd); -} - -static int __get_caller_pid(bundle *kb) -{ - const char *pid_str; - int pid; - - pid_str = bundle_get_val(kb, AUL_K_ORG_CALLER_PID); - if (pid_str) - goto end; - - pid_str = bundle_get_val(kb, AUL_K_CALLER_PID); - if (pid_str == NULL) - return -1; - -end: - pid = atoi(pid_str); - if (pid <= 1) - return -1; - - return pid; -} - -static int __foward_cmd(int cmd, bundle *kb, int cr_pid) -{ - int pid; - int pgid; - char tmp_pid[MAX_PID_STR_BUFSZ]; - int datalen; - bundle_raw *kb_data; - int res; - - if ((pid = __get_caller_pid(kb)) < 0) - return AUL_R_ERROR; - - pgid = getpgid(cr_pid); - if (pgid > 0) { - snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", pgid); - bundle_del(kb, AUL_K_CALLEE_PID); - bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid); - } - - bundle_encode(kb, &kb_data, &datalen); - if ((res = __app_send_raw_with_noreply(pid, cmd, kb_data, datalen)) < 0) - res = AUL_R_ERROR; - - free(kb_data); - - return res; -} - -static int __app_process_by_pid(int cmd, - const char *pkg_name, struct ucred *cr, int clifd) -{ - int pid; - int ret; - int dummy; - char *appid; - const char *pkgid = NULL; - const char *type = NULL; - const struct appinfo *ai = NULL; - - if (pkg_name == NULL) - return -1; - - pid = atoi(pkg_name); - if (pid <= 1) { - _E("invalid pid"); - return -1; - } - - appid = _status_app_get_appid_bypid(pid); - if (appid == NULL) { - _E("pid %d is not an app", pid); - __real_send(clifd, -1); - return -1; - } - - ai = appinfo_find(cr->uid, appid); - if (ai) { - pkgid = appinfo_get_value(ai, AIT_PKGID); - type = appinfo_get_value(ai, AIT_COMPTYPE); - } - - if (ai && (cmd == APP_RESUME_BY_PID || cmd == APP_PAUSE_BY_PID)) - aul_send_app_resume_request_signal(pid, appid, pkgid, type); - else - aul_send_app_terminate_request_signal(pid, appid, pkgid, type); - - switch (cmd) { - case APP_RESUME_BY_PID: - ret = _resume_app(pid, clifd); - break; - case APP_TERM_BY_PID: - case APP_TERM_BY_PID_WITHOUT_RESTART: - ret = _term_app(pid, clifd); - break; - case APP_TERM_BGAPP_BY_PID: - ret = _term_bgapp(pid, clifd); - break; - case APP_KILL_BY_PID: - if ((ret = _send_to_sigkill(pid)) < 0) - _E("fail to killing - %d\n", pid); - _status_update_app_info_list(pid, STATUS_DYING, cr->uid); - __real_send(clifd, ret); - break; - case APP_TERM_REQ_BY_PID: - ret = _term_req_app(pid, clifd); - break; - case APP_TERM_BY_PID_ASYNC: - if ((ret = __app_send_raw_with_noreply(pid, cmd, (unsigned char *)&dummy, sizeof(int))) < 0) - _D("terminate req packet send error"); - - __real_send(clifd, ret); - break; - case APP_PAUSE_BY_PID: - ret = _pause_app(pid, clifd); - break; - default: - _E("unknown command: %d", cmd); - ret = -1; - } - - return ret; -} - -static void __set_effective_appid(uid_t uid, bundle *kb) -{ - const struct appinfo *ai; - const struct appinfo *effective_ai; - const char *appid; - const char *effective_appid; - const char *pkgid; - const char *effective_pkgid; - - appid = bundle_get_val(kb, AUL_K_APPID); - if (appid == NULL) - return; - - ai = appinfo_find(uid, appid); - if (ai == NULL) - return; - - effective_appid = appinfo_get_value(ai, AIT_EFFECTIVE_APPID); - if (effective_appid == NULL) - return; - - effective_ai = appinfo_find(uid, effective_appid); - if (effective_ai == NULL) - return; - - pkgid = appinfo_get_value(ai, AIT_PKGID); - effective_pkgid = appinfo_get_value(effective_ai, AIT_PKGID); - if (pkgid && effective_pkgid && strcmp(pkgid, effective_pkgid) == 0) { - _D("use effective appid instead of the real appid"); - bundle_del(kb, AUL_K_APPID); - bundle_add(kb, AUL_K_APPID, effective_appid); - } -} - -static gboolean __add_history_handler(gpointer user_data) -{ - struct rua_rec rec; - int ret; - char *app_path = NULL; - struct appinfo *ai; - - rua_stat_pkt_t *pkt = (rua_stat_pkt_t *)user_data; - - if (!pkt) - return FALSE; - - if (!pkt->is_group_app) { - ai = (struct appinfo *)appinfo_find(pkt->uid, pkt->appid);; - app_path = (char *)appinfo_get_value(ai, AIT_EXEC); - - memset((void *)&rec, 0, sizeof(rec)); - - rec.pkg_name = pkt->appid; - rec.app_path = app_path; - - if (pkt->len > 0) - rec.arg = pkt->data; - - SECURE_LOGD("add rua history %s %s", rec.pkg_name, rec.app_path); - - ret = rua_add_history(&rec); - if (ret == -1) - _D("rua add history error"); - } - - if (pkt->stat_caller != NULL && pkt->stat_tag != NULL) { - SECURE_LOGD("rua_stat_caller: %s, rua_stat_tag: %s", pkt->stat_caller, pkt->stat_tag); - rua_stat_update(pkt->stat_caller, pkt->stat_tag); - } - if (pkt) { - if (pkt->data) - free(pkt->data); - if (pkt->stat_caller) - free(pkt->stat_caller); - if (pkt->stat_tag) - free(pkt->stat_tag); - free(pkt); - } - - return FALSE; -} - -static int __add_rua_info(const app_pkt_t *pkt, bundle *kb, uid_t uid, const char *appid) -{ - const char *stat_caller = NULL; - const char *stat_tag = NULL; - rua_stat_pkt_t *rua_stat_item = NULL; - - rua_stat_item = calloc(1, sizeof(rua_stat_pkt_t)); - if (rua_stat_item == NULL) { - _E("out of memory"); - goto error; - } - - if (pkt->len > 0) { - rua_stat_item->data = (char *)calloc(pkt->len, sizeof(char)); - if (rua_stat_item->data == NULL) { - _E("out of memory"); - goto error; - } - memcpy(rua_stat_item->data, pkt->data, pkt->len); - } - stat_caller = bundle_get_val(kb, AUL_SVC_K_RUA_STAT_CALLER); - stat_tag = bundle_get_val(kb, AUL_SVC_K_RUA_STAT_TAG); - - rua_stat_item->len = pkt->len; - if (stat_caller != NULL) { - rua_stat_item->stat_caller = strdup(stat_caller); - if (rua_stat_item->stat_caller == NULL) { - _E("Out of memory"); - goto error; - } - } - - if (stat_tag != NULL) { - rua_stat_item->stat_tag = strdup(stat_tag); - if (rua_stat_item->stat_tag == NULL) { - _E("Out of memory"); - goto error; - } - - } - rua_stat_item->uid = uid; - rua_stat_item->is_group_app = app_group_is_group_app(kb); - strncpy(rua_stat_item->appid, appid, 511); - - g_timeout_add(1500, __add_history_handler, rua_stat_item); - - return 0; -error: - if (rua_stat_item) { - if (rua_stat_item->data) - free(rua_stat_item->data); - if (rua_stat_item->stat_caller) - free(rua_stat_item->stat_caller); - if (rua_stat_item->stat_tag) - free(rua_stat_item->stat_tag); - free(rua_stat_item); - } - return -1; -} - -static void __handle_agent_dead_signal(struct ucred *pcr) -{ - /* TODO: check the credentials from the caller: must be the amd agent */ - - _D("AGENT_DEAD_SIGNAL : %d", pcr->uid); - __agent_dead_handler(pcr->uid); -} - -static int __check_app_control_privilege(int fd, const char *operation) -{ - int ret = 0; - - if (operation == NULL || fd < 0) - return 0; - - if (!strcmp(operation, AUL_SVC_OPERATION_DOWNLOAD)) { - ret = check_privilege_by_cynara(fd, PRIVILEGE_DOWNLOAD); - if (ret != 0) { - _E("no privilege for DOWNLOAD operation"); - return -EILLEGALACCESS; - } - } else if (!strcmp(operation, AUL_SVC_OPERATION_CALL)) { - ret = check_privilege_by_cynara(fd, PRIVILEGE_CALL); - if (ret != 0) { - _E("no privilege for CALL operation"); - return -EILLEGALACCESS; - } - } - - return 0; -} - -static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - char *caller; - char *callee; - char *socket_pair_key; - int socket_pair_key_len; - int *handles = NULL; - struct iovec vec[3]; - int msglen = 0; - char buffer[1024]; - struct sockaddr_un saddr; - char *datacontrol_type; - bundle *kb; - - kb = bundle_decode(pkt->data, pkt->len); - caller = (char *)bundle_get_val(kb, AUL_K_CALLER_APPID); - callee = (char *)bundle_get_val(kb, AUL_K_CALLEE_APPID); - datacontrol_type = (char *)bundle_get_val(kb, "DATA_CONTOL_TYPE"); - - socket_pair_key_len = strlen(caller) + strlen(callee) + 2; - - socket_pair_key = (char *)calloc(socket_pair_key_len, sizeof(char)); - if (socket_pair_key == NULL) { - _E("calloc fail"); - goto err_out; - } - - snprintf(socket_pair_key, socket_pair_key_len, "%s_%s", caller, callee); - _D("socket pair key : %s", socket_pair_key); - - handles = g_hash_table_lookup(__socket_pair_hash, socket_pair_key); - if (handles == NULL) { - handles = (int *)calloc(2, sizeof(int)); - if (socketpair(AF_UNIX, SOCK_STREAM, 0, handles) != 0) { - _E("error create socket pair"); - __send_result_to_client(clifd, -1); - - if (handles) - free(handles); - goto err_out; - } - - if (handles[0] == -1) { - _E("error socket open"); - __send_result_to_client(clifd, -1); - - if (handles) - free(handles); - goto err_out; - } - g_hash_table_insert(__socket_pair_hash, strdup(socket_pair_key), - handles); - - _D("New socket pair insert done."); - } - - - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - - SECURE_LOGD("amd send fd : [%d, %d]", handles[0], handles[1]); - vec[0].iov_base = buffer; - vec[0].iov_len = strlen(buffer) + 1; - - if (datacontrol_type != NULL) { - _D("datacontrol_type : %s", datacontrol_type); - if (strcmp(datacontrol_type, "consumer") == 0) { - msglen = __send_message(clifd, vec, 1, &handles[0], 1); - if (msglen < 0) { - _E("Error[%d]: while sending message\n", -msglen); - __send_result_to_client(clifd, -1); - g_hash_table_remove(__socket_pair_hash, socket_pair_key); - goto err_out; - } - close(handles[0]); - handles[0] = -1; - if (handles[1] == -1) { - _E("remove from hash : %s", socket_pair_key); - g_hash_table_remove(__socket_pair_hash, socket_pair_key); - } - - } else { - msglen = __send_message(clifd, vec, 1, &handles[1], 1); - if (msglen < 0) { - _E("Error[%d]: while sending message\n", -msglen); - __send_result_to_client(clifd, -1); - g_hash_table_remove(__socket_pair_hash, socket_pair_key); - goto err_out; - } - close(handles[1]); - handles[1] = -1; - if (handles[0] == -1) { - _E("remove from hash : %s", socket_pair_key); - g_hash_table_remove(__socket_pair_hash, socket_pair_key); - } - } - } - SECURE_LOGD("send_message msglen : [%d]\n", msglen); - if (socket_pair_key) - free(socket_pair_key); - if (kb) - bundle_free(kb); - - return 0; - -err_out: - if (socket_pair_key) - free(socket_pair_key); - if (kb) - bundle_free(kb); - - return -1; -} - -static int __dispatch_remove_history(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ -/* - int result = 0; - bundle *b = NULL; - b = bundle_decode(pkt->data, pkt->len); - result = rua_delete_history_from_db(b); - bundle_free(b); - - __send_result_data(clifd, APP_REMOVE_HISTORY, - (unsigned char *)&result, sizeof(int)); -*/ - return 0; -} - -static int __dispatch_app_group_get_window(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - bundle *b; - char *buf; - int pid; - int wid; - - b = bundle_decode(pkt->data, pkt->len); - bundle_get_str(b, AUL_K_PID, &buf); - pid = atoi(buf); - bundle_free(b); - wid = app_group_get_window(pid); - __send_result_to_client(clifd, wid); - - return 0; -} - -static int __dispatch_app_group_set_window(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - bundle *b; - char *buf; - int wid; - int ret; - - b = bundle_decode(pkt->data, pkt->len); - bundle_get_str(b, AUL_K_WID, &buf); - wid = atoi(buf); - bundle_free(b); - ret = app_group_set_window(cr->pid, wid); - __send_result_to_client(clifd, ret); - - return ret; -} - -static int __dispatch_app_group_get_fg_flag(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - bundle *b; - char *buf; - int pid; - int fg; - - b = bundle_decode(pkt->data, pkt->len); - bundle_get_str(b, AUL_K_PID, &buf); - pid = atoi(buf); - bundle_free(b); - fg = app_group_get_fg_flag(pid); - __send_result_to_client(clifd, fg); - - return 0; -} - -static int __dispatch_app_group_clear_top(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - app_group_clear_top(cr->pid); - __send_result_to_client(clifd, 0); - - return 0; -} - -static int __dispatch_app_group_get_leader_pid(int clifd, - const app_pkt_t *pkt, struct ucred *cr) -{ - bundle *b; - char *buf; - int pid; - int lpid; - - b = bundle_decode(pkt->data, pkt->len); - bundle_get_str(b, AUL_K_PID, &buf); - pid = atoi(buf); - bundle_free(b); - lpid = app_group_get_leader_pid(pid); - __send_result_to_client(clifd, lpid); - - return 0; -} - -static int __dispatch_app_group_get_leader_pids(int clifd, - const app_pkt_t *pkt, struct ucred *cr) -{ - int cnt; - int *pids; - unsigned char empty[1] = { 0 }; - - app_group_get_leader_pids(&cnt, &pids); - - if (pids == NULL || cnt == 0) { - __send_result_data(clifd, APP_GROUP_GET_LEADER_PIDS, empty, 0); - } else { - __send_result_data(clifd, APP_GROUP_GET_LEADER_PIDS, - (unsigned char *)pids, cnt * sizeof(int)); - } - if (pids != NULL) - free(pids); - - return 0; -} - -static int __dispatch_app_group_get_idle_pids(int clifd, - const app_pkt_t *pkt, struct ucred *cr) -{ - int cnt; - int *pids; - unsigned char empty[1] = { 0 }; - - app_group_get_idle_pids(&cnt, &pids); - - if (pids == NULL || cnt == 0) { - __send_result_data(clifd, APP_GROUP_GET_IDLE_PIDS, empty, 0); - } else { - __send_result_data(clifd, APP_GROUP_GET_IDLE_PIDS, - (unsigned char *)pids, cnt * sizeof(int)); - } - if (pids != NULL) - free(pids); - - return 0; -} - -static int __dispatch_app_group_get_group_pids(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - bundle *b; - char *buf; - int leader_pid; - int cnt; - int *pids; - unsigned char empty[1] = { 0 }; - - b = bundle_decode(pkt->data, pkt->len); - bundle_get_str(b, AUL_K_LEADER_PID, &buf); - leader_pid = atoi(buf); - bundle_free(b); - - app_group_get_group_pids(leader_pid, &cnt, &pids); - if (pids == NULL || cnt == 0) { - __send_result_data(clifd, APP_GROUP_GET_GROUP_PIDS, empty, 0); - } else { - __send_result_data(clifd, APP_GROUP_GET_GROUP_PIDS, - (unsigned char *)pids, cnt * sizeof(int)); - } - if (pids != NULL) - free(pids); - - return 0; -} - -static int __dispatch_app_group_lower(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - int ret = 0; - - app_group_lower(cr->pid, &ret); - __send_result_to_client(clifd, ret); - - return ret; -} - -static int __dispatch_app_start(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - const char *appid; - const char *target_uid; - bundle *kb; - int ret = -1; - int t_uid; - char *state; - bool pending = false; - struct pending_item *pending_item; - const char *operation = NULL; - - kb = bundle_decode(pkt->data, pkt->len); - if (kb == NULL) { - close(clifd); - return -1; - } - - __set_effective_appid(cr->uid, kb); - - appid = bundle_get_val(kb, AUL_K_APPID); - if (cr->uid < REGULAR_UID_MIN) { - target_uid = bundle_get_val(kb, AUL_K_TARGET_UID); - if (target_uid != NULL) { - t_uid = atoi(target_uid); - sd_uid_get_state(t_uid, &state); - if (strcmp(state, "offline") && - strcmp(state, "closing")) { - ret = _start_app(appid, kb, pkt->cmd, cr->pid, - t_uid, clifd, &pending); - } else { - _E("uid:%d session is %s", t_uid, state); - __real_send(clifd, AUL_R_ERROR); - goto error; - } - } else { - _E("request from root, treat as global user"); - ret = _start_app(appid, kb, pkt->cmd, cr->pid, - GLOBAL_USER, clifd, &pending); - } - } else { - operation = bundle_get_val(kb, AUL_SVC_K_OPERATION); - if (operation) { - ret = __check_app_control_privilege(clifd, operation); - if (ret != 0) { - __real_send(clifd, ret); - goto error; - } - } - - ret = _start_app(appid, kb, pkt->cmd, cr->pid, cr->uid, clifd, - &pending); - } - - /* add pending list to wait app launched successfully */ - if (pending) { - pending_item = calloc(1, sizeof(struct pending_item)); - pending_item->clifd = clifd; - pending_item->pid = ret; - pending_item->timer = g_timeout_add(PENDING_REQUEST_TIMEOUT, - __timeout_pending_item, (gpointer)pending_item); - g_hash_table_insert(pending_table, GINT_TO_POINTER(ret), - pending_item); - } - - if (ret > 0 && __add_rua_info(pkt, kb, cr->uid, appid) < 0) - goto error; - bundle_free(kb); - return 0; - -error: - if (kb) - bundle_free(kb); - return -1; -} - -static int __dispatch_app_result(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - bundle *kb; - - kb = bundle_decode(pkt->data, pkt->len); - if (kb == NULL) { - close(clifd); - return -1; - } - - __foward_cmd(pkt->cmd, kb, cr->pid); - close(clifd); - bundle_free(kb); - - return 0; -} - -static int __dispatch_app_pause(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - char *appid; - bundle *kb; - int ret; - - kb = bundle_decode(pkt->data, pkt->len); - if (kb == NULL) { - close(clifd); - return -1; - } - - appid = (char *)bundle_get_val(kb, AUL_K_APPID); - ret = _status_app_is_running_v2(appid, cr->uid); - if (ret > 0) { - ret = _pause_app(ret, clifd); - } else { - _E("%s is not running", appid); - close(clifd); - } - bundle_free(kb); - - return 0; -} - -static int __dispatch_app_process_by_pid(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - char *appid; - bundle *kb; - - kb = bundle_decode(pkt->data, pkt->len); - if (kb == NULL) { - close(clifd); - return -1; - } - - appid = (char *)bundle_get_val(kb, AUL_K_APPID); - __app_process_by_pid(pkt->cmd, appid, cr, clifd); - bundle_free(kb); - - return 0; -} - -static int __dispatch_app_term_async(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - char *appid; - bundle *kb; - char *term_pid; - struct appinfo *ai; - - kb = bundle_decode(pkt->data, pkt->len); - if (kb == NULL) { - close(clifd); - return -1; - } - - term_pid = (char *)bundle_get_val(kb, AUL_K_APPID); - appid = _status_app_get_appid_bypid(atoi(term_pid)); - ai = appinfo_find(cr->uid, appid); - if (ai) { - appinfo_set_value(ai, AIT_STATUS, "norestart"); - __app_process_by_pid(pkt->cmd, term_pid, cr, clifd); - } else { - close(clifd); - } - bundle_free(kb); - - return 0; -} - -static int __dispatch_app_term(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - char *appid; - bundle *kb; - - kb = bundle_decode(pkt->data, pkt->len); - if (kb == NULL) { - close(clifd); - return -1; - } - - appid = (char *)bundle_get_val(kb, AUL_K_APPID); - __app_process_by_pid(pkt->cmd, appid, cr, clifd); - bundle_free(kb); - - return 0; -} - -static int __dispatch_app_running_info(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - _status_send_running_appinfo(clifd, cr->uid); - return 0; -} - -static int __dispatch_app_is_running(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - char *appid = NULL; - int ret; - - appid = malloc(MAX_PACKAGE_STR_SIZE); - if (appid == NULL) { - _E("out of memory"); - __send_result_to_client(clifd, -1); - return -1; - } - strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1); - ret = _status_app_is_running(appid, cr->uid); - SECURE_LOGD("APP_IS_RUNNING : %s : %d", appid, ret); - __send_result_to_client(clifd, ret); - free(appid); - - return 0; -} - -static int __dispatch_app_get_appid_by_pid(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - int pid; - int ret; - - memcpy(&pid, pkt->data, pkt->len); - ret = _status_get_appid_bypid(clifd, pid); - _D("app_get_appid_bypid : %d : %d", pid, ret); - return 0; -} - -static int __dispatch_app_get_pkgid_by_pid(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - int pid; - int ret; - - memcpy(&pid, pkt->data, sizeof(int)); - ret = _status_get_pkgid_bypid(clifd, pid); - _D("APP_GET_PKGID_BYPID : %d : %d", pid, ret); - return 0; -} - -static int __dispatch_legacy_command(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - __send_result_to_client(clifd, 0); - return 0; -} - -static int __dispatch_app_status_update(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - int *status; - char *appid; - struct appinfo *ai; - - status = (int *)pkt->data; - if (*status == STATUS_NORESTART) { - appid = _status_app_get_appid_bypid(cr->pid); - ai = appinfo_find(cr->uid, appid); - appinfo_set_value((struct appinfo *)ai, AIT_STATUS, "norestart"); - } else { - if (*status == STATUS_VISIBLE && cr->pid == _get_pid_of_last_launched_ui_app()) - _send_hint_for_visibility(cr->uid); - _status_update_app_info_list(cr->pid, *status, cr->uid); - } - close(clifd); - - return 0; -} - -static int __dispatch_app_get_status(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - int pid; - int ret; - - memcpy(&pid, pkt->data, sizeof(int)); - ret = _status_get_app_info_status(pid, 0); - __send_result_to_client(clifd, ret); - - return 0; -} - -static int __dispatch_app_add_loader(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - bundle *kb; - int ret; - char tmpbuf[MAX_PID_STR_BUFSZ]; - - kb = bundle_decode(pkt->data, pkt->len); - if (kb == NULL) { - close(clifd); - return -1; - } - - snprintf(tmpbuf, sizeof(tmpbuf), "%d", getpgid(cr->pid)); - bundle_add(kb, AUL_K_CALLER_PID, tmpbuf); - ret = app_agent_send_cmd(cr->uid, LAUNCHPAD_PROCESS_POOL_SOCK, - PAD_CMD_ADD_LOADER, kb); - bundle_free(kb); - __send_result_to_client(clifd, ret); - - return ret; -} - -static int __dispatch_app_remove_loader(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - bundle *kb; - int ret; - - kb = bundle_decode(pkt->data, pkt->len); - if (kb == NULL) { - close(clifd); - return -1; - } - - ret = app_agent_send_cmd(cr->uid, LAUNCHPAD_PROCESS_POOL_SOCK, - PAD_CMD_REMOVE_LOADER, kb); - bundle_free(kb); - __send_result_to_client(clifd, ret); - - return ret; -} - -static int __dispatch_agent_dead_signal(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - _D("AMD_AGENT_DEAD_SIGNAL"); - __handle_agent_dead_signal(cr); - close(clifd); - - return 0; -} - -static int __dispatch_amd_reload_appinfo(int clifd, const app_pkt_t *pkt, struct ucred *cr) -{ - _D("AMD_RELOAD_APPINFO"); - appinfo_reload(); - __send_result_to_client(clifd, 0); - - return 0; -} - -static const char *__convert_cmd_to_privilege(int cmd) -{ - switch (cmd) { - case APP_OPEN: - case APP_RESUME: - case APP_START: - case APP_START_RES: - return PRIVILEGE_APPMANAGER_LAUNCH; - case APP_TERM_BY_PID_WITHOUT_RESTART: - case APP_TERM_BY_PID_ASYNC: - case APP_TERM_BY_PID: - case APP_KILL_BY_PID: - return PRIVILEGE_APPMANAGER_KILL; - case APP_TERM_BGAPP_BY_PID: - return PRIVILEGE_APPMANAGER_KILL_BGAPP; - default: - return NULL; - } -} - -static app_cmd_dispatch_func dispatch_table[APP_CMD_MAX] = { - [APP_GET_SOCKET_PAIR] = __dispatch_get_socket_pair, - [APP_START] = __dispatch_app_start, - [APP_OPEN] = __dispatch_app_start, - [APP_RESUME] = __dispatch_app_start, - [APP_RESUME_BY_PID] = __dispatch_app_process_by_pid, - [APP_TERM_BY_PID] = __dispatch_app_term, - [APP_TERM_BY_PID_WITHOUT_RESTART] = __dispatch_app_term_async, - [APP_RESULT] = __dispatch_app_result, - [APP_START_RES] = __dispatch_app_start, - [APP_CANCEL] = __dispatch_app_result, - [APP_KILL_BY_PID] = __dispatch_app_term, - [APP_ADD_HISTORY] = NULL, - [APP_REMOVE_HISTORY] = __dispatch_remove_history, - [APP_RUNNING_INFO] = __dispatch_app_running_info, - [APP_RUNNING_INFO_RESULT] = NULL, - [APP_IS_RUNNING] = __dispatch_app_is_running, - [APP_GET_APPID_BYPID] = __dispatch_app_get_appid_by_pid, - [APP_GET_PKGID_BYPID] = __dispatch_app_get_pkgid_by_pid, - [APP_GET_INFO_OK] = NULL, - [APP_GET_INFO_ERROR] = NULL, - [APP_KEY_EVENT] = NULL, - [APP_KEY_RESERVE] = __dispatch_legacy_command, - [APP_KEY_RELEASE] = __dispatch_legacy_command, - [APP_STATUS_UPDATE] = __dispatch_app_status_update, - [APP_RUNNING_LIST_UPDATE] = __dispatch_legacy_command, - [APP_TERM_REQ_BY_PID] = __dispatch_app_process_by_pid, - [APP_TERM_BY_PID_ASYNC] = __dispatch_app_term_async, - [APP_TERM_BGAPP_BY_PID] = __dispatch_app_term, - [APP_PAUSE] = __dispatch_app_pause, - [APP_PAUSE_BY_PID] = __dispatch_app_process_by_pid, - [APP_GROUP_GET_WINDOW] = __dispatch_app_group_get_window, - [APP_GROUP_SET_WINDOW] = __dispatch_app_group_set_window, - [APP_GROUP_GET_FG] = __dispatch_app_group_get_fg_flag, - [APP_GROUP_GET_LEADER_PID] = __dispatch_app_group_get_leader_pid, - [APP_GROUP_GET_LEADER_PIDS] = __dispatch_app_group_get_leader_pids, - [APP_GROUP_GET_GROUP_PIDS] = __dispatch_app_group_get_group_pids, - [APP_GROUP_GET_IDLE_PIDS] = __dispatch_app_group_get_idle_pids, - [APP_GROUP_LOWER] = __dispatch_app_group_lower, - [APP_GROUP_CLEAR_TOP] = __dispatch_app_group_clear_top, - [APP_GET_STATUS] = __dispatch_app_get_status, - [APP_ADD_LOADER] = __dispatch_app_add_loader, - [APP_REMOVE_LOADER] = __dispatch_app_remove_loader, - [APP_GET_PID] = __dispatch_app_is_running, - [AMD_RELOAD_APPINFO] = __dispatch_amd_reload_appinfo, - [AGENT_DEAD_SIGNAL] = __dispatch_agent_dead_signal, -}; - -static void __free_request(gpointer data) -{ - struct request *req = (struct request *)data; - - free(req->pkt); - free(req); -} - -static void __free_pending_item(struct pending_item *item) -{ - g_list_free_full(item->pending_list, __free_request); - if (g_main_context_find_source_by_user_data(NULL, item)) - g_source_remove(item->timer); - free(item); -} - -static void __process_pending_request(gpointer data, gpointer user_data) -{ - struct request *req = (struct request *)data; - - dispatch_table[req->pkt->cmd](req->clifd, req->pkt, &req->cr); -} - -static void __timeout_pending_request(gpointer data, gpointer user_data) -{ - struct request *req = (struct request *)data; - - __send_result_to_client(req->clifd, -1); -} - -static gboolean __timeout_pending_item(gpointer user_data) -{ - struct pending_item *item = (struct pending_item *)user_data; - - __send_result_to_client(item->clifd, item->pid); - g_list_foreach(item->pending_list, __timeout_pending_request, NULL); - - g_hash_table_remove(pending_table, GINT_TO_POINTER(item->pid)); - __free_pending_item(item); - - return FALSE; -} - -int _request_flush_pending_request(int pid) -{ - struct pending_item *item; - - item = (struct pending_item *)g_hash_table_lookup( - pending_table, GINT_TO_POINTER(pid)); - if (item == NULL) - return -1; - - __timeout_pending_item((gpointer)item); - - return 0; -} - -int _request_reply_for_pending_request(int pid) -{ - struct pending_item *item; - - item = (struct pending_item *)g_hash_table_lookup( - pending_table, GINT_TO_POINTER(pid)); - if (item == NULL) - return -1; - - __send_result_to_client(item->clifd, pid); - g_hash_table_remove(pending_table, GINT_TO_POINTER(pid)); - g_list_foreach(item->pending_list, __process_pending_request, NULL); - - __free_pending_item(item); - - return 0; -} - -static struct request *__get_request(int clifd, app_pkt_t *pkt, - struct ucred cr) -{ - struct request *req; - - req = malloc(sizeof(struct request)); - if (req == NULL) - return NULL; - - req->clifd = clifd; - req->pkt = calloc(1, AUL_PKT_HEADER_SIZE + pkt->len + 1); - memcpy(req->pkt, pkt, AUL_PKT_HEADER_SIZE + pkt->len + 1); - memcpy(&req->cr, &cr, sizeof(struct ucred)); - - return req; -} - -static int __check_app_is_running(struct request *req) -{ - bundle *b; - char *str; - int pid; - int ret = 0; - - b = bundle_decode(req->pkt->data, req->pkt->len); - if (b == NULL) - return -1; - - if (bundle_get_str(b, AUL_K_APPID, &str)) { - _E("cannot get target pid"); - bundle_free(b); - return -1; - } - - switch (req->pkt->cmd) { - case APP_RESUME_BY_PID: - case APP_TERM_BY_PID: - case APP_TERM_BY_PID_WITHOUT_RESTART: - case APP_KILL_BY_PID: - case APP_TERM_REQ_BY_PID: - case APP_TERM_BY_PID_ASYNC: - case APP_TERM_BGAPP_BY_PID: - case APP_PAUSE_BY_PID: - /* get pid */ - pid = atoi(str); - if (_status_app_get_appid_bypid(pid)) - ret = pid; - break; - default: - pid = _status_app_is_running(str, req->cr.uid); - if (pid > 0) - ret = pid; - } - - bundle_free(b); - - return ret; -} - -static int __check_request(struct request *req) -{ - int pid; - struct pending_item *item; - - /* TODO: categorize commands */ - if (req->pkt->cmd != APP_START && req->pkt->cmd != APP_OPEN && - req->pkt->cmd != APP_RESUME && - req->pkt->cmd != APP_RESUME_BY_PID && - req->pkt->cmd != APP_TERM_BY_PID && - req->pkt->cmd != APP_TERM_BY_PID_WITHOUT_RESTART && - req->pkt->cmd != APP_START_RES && - req->pkt->cmd != APP_KILL_BY_PID && - req->pkt->cmd != APP_TERM_REQ_BY_PID && - req->pkt->cmd != APP_TERM_BY_PID_ASYNC && - req->pkt->cmd != APP_TERM_BGAPP_BY_PID && - req->pkt->cmd != APP_PAUSE && - req->pkt->cmd != APP_PAUSE_BY_PID) - return 0; - - pid = __check_app_is_running(req); - if (pid < 0) - return -1; - else if (pid == 0) - return 0; - - if (_status_get_app_info_status(pid, req->cr.uid) == STATUS_DYING) - return 0; - - item = g_hash_table_lookup(pending_table, GINT_TO_POINTER(pid)); - if (item == NULL) - return 0; - - item->pending_list = g_list_append(item->pending_list, req); - - return 1; -} - -static gboolean __request_handler(gpointer data) -{ - GPollFD *gpollfd = (GPollFD *) data; - int fd = gpollfd->fd; - app_pkt_t *pkt; - int ret; - int clifd; - struct ucred cr; - const char *privilege; - struct request *req; - - if ((pkt = __app_recv_raw(fd, &clifd, &cr)) == NULL) { - _E("recv error"); - return FALSE; - } - - req = __get_request(clifd, pkt, cr); - if (req == NULL) { - close(clifd); - free(pkt); - return TRUE; - } - - if (cr.uid >= REGULAR_UID_MIN) { - privilege = __convert_cmd_to_privilege(pkt->cmd); - if (privilege) { - ret = check_privilege_by_cynara(clifd, privilege); - if (ret < 0) { - _E("request has been denied by smack"); - ret = -EILLEGALACCESS; - __real_send(clifd, ret); - __free_request(req); - free(pkt); - return TRUE; - } - } - } - - ret = __check_request(req); - if (ret < 0) { - __real_send(clifd, ret); - __free_request(req); - free(pkt); - return TRUE; - } else if (ret > 0) { - free(pkt); - return TRUE; - } - - if (pkt->cmd >= 0 && pkt->cmd < APP_CMD_MAX && dispatch_table[pkt->cmd]) { - if (dispatch_table[pkt->cmd](clifd, pkt, &cr) != 0) - _E("callback returns FALSE : %d", pkt->cmd); - } else { - _E("Invalid packet or not supported command"); - close(clifd); - } - __free_request(req); - free(pkt); - - return TRUE; -} - -static gboolean __au_glib_check(GSource *src) -{ - GSList *fd_list; - GPollFD *tmp; - - fd_list = src->poll_fds; - do { - tmp = (GPollFD *) fd_list->data; - if ((tmp->revents & (POLLIN | POLLPRI))) - return TRUE; - fd_list = fd_list->next; - } while (fd_list); - - return FALSE; -} - -static gboolean __au_glib_dispatch(GSource *src, GSourceFunc callback, - gpointer data) -{ - callback(data); - return TRUE; -} - -static gboolean __au_glib_prepare(GSource *src, gint *timeout) -{ - return FALSE; -} - -static GSourceFuncs funcs = { - .prepare = __au_glib_prepare, - .check = __au_glib_check, - .dispatch = __au_glib_dispatch, - .finalize = NULL -}; - -int _request_init(void) -{ - int fd; - int r; - GPollFD *gpollfd; - GSource *src; - - __socket_pair_hash = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); - pending_table = g_hash_table_new(g_direct_hash, g_direct_equal); - - fd = __create_sock_activation(); - if (fd == -1) { - _D("Create server socket without socket activation"); - fd = __create_server_sock(AUL_UTIL_PID); - if (fd == -1) { - _E("Create server socket failed."); - return -1; - } - } - - r = init_cynara(); - if (r != 0) { - _E("cynara initialize failed."); - close(fd); - return -1; - } - - src = g_source_new(&funcs, sizeof(GSource)); - if (!src) { - _E("out of memory"); - finish_cynara(); - close(fd); - return -1; - } - - gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD)); - if (!gpollfd) { - _E("out of memory"); - g_source_destroy(src); - finish_cynara(); - close(fd); - return -1; - } - - gpollfd->events = POLLIN; - gpollfd->fd = fd; - - g_source_add_poll(src, gpollfd); - g_source_set_callback(src, (GSourceFunc) __request_handler, - (gpointer) gpollfd, NULL); - g_source_set_priority(src, G_PRIORITY_DEFAULT); - - r = g_source_attach(src, NULL); - if (r == 0) { - g_free(gpollfd); - g_source_destroy(src); - finish_cynara(); - close(fd); - return -1; - } - r = rua_init(); - r = rua_clear_history(); - - _D("rua_clear_history : %d", r); - - return 0; -} diff --git a/am_daemon/amd_request.h b/am_daemon/amd_request.h deleted file mode 100644 index 41b5423..0000000 --- a/am_daemon/amd_request.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2000 - 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. - */ - -#pragma once - -int _request_init(void); -int _request_reply_for_pending_request(int pid); -int _request_flush_pending_request(int pid); - - diff --git a/am_daemon/amd_status.c b/am_daemon/amd_status.c deleted file mode 100644 index cde9732..0000000 --- a/am_daemon/amd_status.c +++ /dev/null @@ -1,765 +0,0 @@ -/* - * Copyright (c) 2000 - 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. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "amd_config.h" -#include "amd_status.h" -#include "amd_appinfo.h" -#include "amd_request.h" -#include "aul_util.h" -#include "simple_util.h" -#include "app_sock.h" -#include "menu_db_util.h" -#include "amd_app_group.h" - -typedef struct _pkg_status_info_t { - char *pkgid; - int status; - GSList *ui_list; - GSList *svc_list; -} pkg_status_info_t; - -typedef struct _app_status_info_t { - char *appid; - char *app_path; - char *pkgid; - int status; - int pid; - int pad_pid; - bool is_subapp; - pkg_status_info_t *pkginfo; - uid_t uid; -} app_status_info_t; - -static GSList *app_status_info_list = NULL; -static GHashTable *pkg_status_info_table = NULL; - -static void __add_pkg_info(const char *pkgid, app_status_info_t *appinfo) -{ - pkg_status_info_t *pkginfo = NULL; - - if (pkgid == NULL || appinfo == NULL) { - _E("empty arguments: %s", pkgid == NULL ? (appinfo == NULL ? "appinfo, pkgid" : "pkgid") : "appinfo"); - return; - } - - if (pkg_status_info_table == NULL) - pkg_status_info_table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); - - pkginfo = g_hash_table_lookup(pkg_status_info_table, pkgid); - if (pkginfo == NULL) { - pkginfo = (pkg_status_info_t *)malloc(sizeof(pkg_status_info_t)); - if (pkginfo == NULL) { - _E("failed to allocate memory"); - return; - } - - memset(pkginfo, 0, sizeof(pkg_status_info_t)); - pkginfo->pkgid = strdup(pkgid); - if (pkginfo->pkgid == NULL) { - free(pkginfo); - _E("failed to allocate memory"); - return; - } - - g_hash_table_insert(pkg_status_info_table, pkginfo->pkgid, pkginfo); - } - - pkginfo->status = appinfo->status; - appinfo->pkginfo = pkginfo; - - if (appinfo->status == STATUS_SERVICE) - pkginfo->svc_list = g_slist_append(pkginfo->svc_list, appinfo); - else - pkginfo->ui_list = g_slist_append(pkginfo->ui_list, appinfo); -} - -static int __get_ui_app_status_pkg_info(pkg_status_info_t *pkginfo) -{ - app_status_info_t *appinfo = NULL; - GSList *iter = NULL; - int status = STATUS_BG; - - if (pkginfo == NULL) - return -1; - - iter = pkginfo->ui_list; - while (iter) { - appinfo = (app_status_info_t *)iter->data; - if (appinfo->status != STATUS_BG) - status = appinfo->status; - - iter = g_slist_next(iter); - } - - return status; -} - -static int __update_pkg_info(const char *pkgid, app_status_info_t *appinfo) -{ - pkg_status_info_t *pkginfo = NULL; - int ret = 0; - - if (pkgid == NULL || appinfo == NULL) - return -1; - - if (pkg_status_info_table == NULL) - return -1; - - pkginfo = (pkg_status_info_t *)g_hash_table_lookup(pkg_status_info_table, pkgid); - if (pkginfo == NULL) { - _E("pkgid(%s) is not on list"); - return -1; - } - - if (pkginfo->ui_list) { - ret = __get_ui_app_status_pkg_info(pkginfo); - if (ret > -1) - pkginfo->status = ret; - } else { - pkginfo->status = STATUS_SERVICE; - } - - return 0; -} - - -static void __remove_pkg_info(const char *pkgid, app_status_info_t *appinfo, uid_t caller_uid) -{ - pkg_status_info_t *pkginfo = NULL; - const struct appinfo *ai = NULL; - const char *component_type = NULL; - - if (pkgid == NULL || appinfo == NULL) { - _E("empty arguments: %s", pkgid == NULL ? (appinfo == NULL ? "appinfo, pkgid" : "pkgid") : "appinfo"); - return; - } - - ai = appinfo_find(caller_uid, appinfo->appid); - component_type = appinfo_get_value(ai, AIT_COMPTYPE); - - pkginfo = (pkg_status_info_t *)g_hash_table_lookup(pkg_status_info_table, pkgid); - if (pkginfo == NULL) { - _E("pkgid(%s) is not on list"); - return; - } - - if (component_type && strcmp(component_type, APP_TYPE_SERVICE) == 0) { - if (pkginfo->svc_list) { - pkginfo->svc_list = g_slist_remove(pkginfo->svc_list, appinfo); - _D("STATUS_SERVICE : appid(%s)", appinfo->appid); - } - } else { - if (pkginfo->ui_list) { - pkginfo->ui_list = g_slist_remove(pkginfo->ui_list, appinfo); - _D("~STATUS_SERVICE : appid(%s)", appinfo->appid); - } - } - - if (!pkginfo->svc_list && !pkginfo->ui_list) { - g_hash_table_remove(pkg_status_info_table, pkgid); - if (pkginfo->pkgid) { - free(pkginfo->pkgid); - pkginfo->pkgid = NULL; - } - free(pkginfo); - } -} - -static void __destroy_app_status_info(app_status_info_t *info_t) -{ - if (info_t == NULL) - return; - - if (info_t->appid) { - free(info_t->appid); - info_t->appid = NULL; - } - - if (info_t->app_path) { - free(info_t->app_path); - info_t->app_path = NULL; - } - - if (info_t->pkgid) { - free(info_t->pkgid); - info_t->pkgid = NULL; - } - - free(info_t); -} - -int _status_add_app_info_list(const char *appid, const char *app_path, int pid, - int pad_pid, bool is_subapp, uid_t uid) -{ - GSList *iter; - GSList *iter_next; - app_status_info_t *info_t; - const struct appinfo *ai; - const char *component_type = NULL; - const char *pkgid = NULL; - - if (!appid || !app_path) - return -1; - - GSLIST_FOREACH_SAFE(app_status_info_list, iter, iter_next) { - info_t = (app_status_info_t *)iter->data; - if (pid == info_t->pid) { - if (uid == info_t->uid) - return 0; - else { - /* PID is unique so if it is exist but user value is not correct remove it. */ - app_status_info_list = g_slist_remove(app_status_info_list, info_t); - __remove_pkg_info(info_t->pkgid, info_t, uid); - __destroy_app_status_info(info_t); - break; - } - } - } - - ai = appinfo_find(uid, appid); - - info_t = malloc(sizeof(app_status_info_t)); - if (info_t == NULL) { - _E("out of memory"); - return -1; - } - - memset(info_t, 0, sizeof(app_status_info_t)); - - info_t->appid = strdup(appid); - if (info_t->appid == NULL) - goto error; - - info_t->app_path = strdup(app_path); - if (info_t->app_path == NULL) - goto error; - - component_type = appinfo_get_value(ai, AIT_COMPTYPE); - if (component_type && strcmp(component_type, APP_TYPE_SERVICE) == 0) - info_t->status = STATUS_SERVICE; - else - info_t->status = STATUS_LAUNCHING; - - pkgid = appinfo_get_value(ai, AIT_PKGID); - if (pkgid == NULL) - goto error; - - info_t->pid = pid; - info_t->pad_pid = pad_pid; - info_t->is_subapp = is_subapp; - info_t->uid = uid; - info_t->pkgid = strdup(pkgid); - if (info_t->pkgid == NULL) - goto error; - - app_status_info_list = g_slist_append(app_status_info_list, info_t); - __add_pkg_info(pkgid, info_t); - _D("pid(%d) appid(%s) pkgid(%s) comp(%s)", pid, appid, pkgid, component_type); - - return 0; -error: - __destroy_app_status_info(info_t); - - return -1; -} - -int _status_update_app_info_list(int pid, int status, uid_t uid) -{ - GSList *iter = NULL; - app_status_info_t *info_t = NULL; - - _D("pid(%d) status(%d)", pid, status); - for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) { - info_t = (app_status_info_t *)iter->data; - if ((pid == info_t->pid) && ((info_t->uid == uid) || (info_t->uid == 0))) { - info_t->status = status; - __update_pkg_info(info_t->pkgid, info_t); - - _D("pid(%d) appid(%s) pkgid(%s) status(%d)", pid, info_t->appid, info_t->pkgid, info_t->status); - break; - } - } - - app_group_set_status(pid, status, false); - - return 0; -} - -int _status_remove_app_info_list_with_uid(uid_t uid) -{ - GSList *iter; - GSList *iter_next; - app_status_info_t *info_t; - - GSLIST_FOREACH_SAFE(app_status_info_list, iter, iter_next) { - info_t = (app_status_info_t *)iter->data; - if (info_t->uid == uid) { - app_status_info_list = - g_slist_remove(app_status_info_list, info_t); - free(info_t); - } - } - - return 0; -} - -int _status_remove_app_info_list(int pid, uid_t uid) -{ - GSList *iter; - GSList *iter_next; - app_status_info_t *info_t; - - GSLIST_FOREACH_SAFE(app_status_info_list, iter, iter_next) { - info_t = (app_status_info_t *)iter->data; - if ((pid == info_t->pid) && ((info_t->uid == uid) || (info_t->uid == 0))) { - app_status_info_list = g_slist_remove(app_status_info_list, info_t); - __remove_pkg_info(info_t->pkgid, info_t, uid); - __destroy_app_status_info(info_t); - break; - } - } - - return 0; -} - -int _status_get_app_info_status(int pid, uid_t uid) -{ - GSList *iter = NULL; - app_status_info_t *info_t = NULL; - - for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) { - info_t = (app_status_info_t *)iter->data; - if (pid == info_t->pid - && ((uid == 0) ? true : (uid == info_t->uid))) - return info_t->status; - } - - return app_group_get_status(pid); -} - -static gint __find_app_bypid(gconstpointer app_data, gconstpointer pid_data) -{ - int pid = GPOINTER_TO_INT(pid_data); - app_status_info_t *appinfo = (app_status_info_t *)app_data; - - if (appinfo && pid && appinfo->pid == pid) - return 0; - - return -1; -} - -void _status_find_service_apps(int pid, uid_t uid, enum app_status status, void (*send_event_to_svc_core) (int), bool suspend) -{ - GSList *app_list = NULL; - GSList *svc_list = NULL; - app_status_info_t *info_t = NULL; - app_status_info_t *svc_info_t = NULL; - const struct appinfo *ai = NULL; - int bg_allowed = 0x00; - - app_list = g_slist_find_custom(app_status_info_list, GINT_TO_POINTER(pid), __find_app_bypid); - - if (!app_list) { - _E("unable to find app by pid:%d", pid); - return; - } - - info_t = (app_status_info_t *)app_list->data; - if (info_t && info_t->pkginfo && info_t->pkginfo->status == status) - svc_list = info_t->pkginfo->svc_list; - - while (svc_list) { - svc_info_t = (app_status_info_t *)svc_list->data; - if (svc_info_t) { - ai = appinfo_find(uid, svc_info_t->appid); - bg_allowed = (intptr_t)appinfo_get_value(ai, AIT_BG_CATEGORY); - if (!bg_allowed) { - send_event_to_svc_core(svc_info_t->pid); - /* TODO: APIs should be prepared - if (suspend) - _amd_suspend_add_timer(svc_info_t->pid, ai); - else - _amd_suspend_remove_timer(svc_info_t->pid); - */ - } - } - svc_list = g_slist_next(svc_list); - } -} - -void _status_check_service_only(int pid, uid_t uid, void (*send_event_to_svc_core) (int)) -{ - GSList *app_list = NULL; - GSList *ui_list = NULL; - app_status_info_t *info_t = NULL; - app_status_info_t *ui_info_t = NULL; - int ui_cnt = 0; - - app_list = g_slist_find_custom(app_status_info_list, GINT_TO_POINTER(pid), __find_app_bypid); - - if (!app_list) { - _E("unable to find app by pid:%d", pid); - return; - } - - info_t = (app_status_info_t *)app_list->data; - ui_list = info_t->pkginfo->ui_list; - while (ui_list) { - ui_info_t = (app_status_info_t *)ui_list->data; - if (ui_info_t && _status_app_is_running_v2(ui_info_t->appid, uid) > 0) - ui_cnt++; - ui_list = g_slist_next(ui_list); - } - - if (ui_cnt == 0) { - const char *appid = NULL; - const struct appinfo *ai = NULL; - int bg_allowed = 0x00; - - appid = _status_app_get_appid_bypid(pid); - if (appid) { - ai = appinfo_find(uid, appid); - bg_allowed = (intptr_t)appinfo_get_value(ai, AIT_BG_CATEGORY); - - if (!bg_allowed) { - send_event_to_svc_core(pid); - /* TODO: APIs should be prepared - _amd_suspend_add_timer(pid, ai); - */ - } - } - } -} - -int _status_app_is_running(const char *appid, uid_t uid) -{ - GSList *iter = NULL; - app_status_info_t *info_t = NULL; - - for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) { - info_t = (app_status_info_t *)iter->data; - if ((strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE) == 0) - && (info_t->uid == uid) && !info_t->is_subapp) - return info_t->pid; - } - - return -1; -} - -char* _status_app_get_appid_bypid(int pid) -{ - GSList *iter = NULL; - app_status_info_t *info_t = NULL; - - for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) { - info_t = (app_status_info_t *)iter->data; - if (pid == info_t->pid) - return info_t->appid; - } - - return NULL; -} - -int _status_send_running_appinfo(int fd, uid_t uid) -{ - GSList *iter = NULL; - app_status_info_t *info_t = NULL; - app_pkt_t *pkt = NULL; - int len; - char tmp_pid[MAX_PID_STR_BUFSZ]; - char buf[AUL_SOCK_MAXBUFF] = {0, }; - - for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) { - info_t = (app_status_info_t *)iter->data; - if (info_t->uid != uid || app_group_is_sub_app(info_t->pid)) - continue; - - snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", info_t->pid); - strncat(buf, tmp_pid, MAX_PID_STR_BUFSZ); - strncat(buf, ":", 1); - strncat(buf, info_t->appid, MAX_PACKAGE_STR_SIZE); - strncat(buf, ":", 1); - strncat(buf, info_t->app_path, MAX_PACKAGE_APP_PATH_SIZE); - strncat(buf, ";", 1); - } - - len = strlen(buf); - pkt = (app_pkt_t *)malloc(AUL_PKT_HEADER_SIZE + len); - if (!pkt) { - _E("malloc fail"); - return 0; - } - - pkt->cmd = APP_RUNNING_INFO_RESULT; - pkt->len = len; - memcpy(pkt->data, buf, len); - - if ((len = send(fd, pkt, pkt->len + AUL_PKT_HEADER_SIZE, 0)) != - pkt->len + AUL_PKT_HEADER_SIZE) { - if (errno == EPIPE) - _E("send failed due to EPIPE.\n"); - _E("send fail to client"); - } - - if (pkt) - free(pkt); - - close(fd); - - return 0; -} - -static inline int __find_pid_by_appid(const char *dname, const char *appid, - void *priv, uid_t uid) -{ - int pid = 0; - - if (strncmp(appid, (char *)priv, MAX_LOCAL_BUFSZ-1) == 0) { - pid = atoi(dname); - if (pid != getpgid(pid) || app_group_is_sub_app(pid)) - pid = 0; - } - - return pid; -} - -int _status_app_is_running_v2(const char *appid, uid_t caller_uid) -{ - int ret; - struct appinfo *ai; - - if (appid == NULL) - return -1; - - ai = appinfo_find(caller_uid, appid); - if (ai == NULL) - return -1; - - ret = __proc_iter_appid(__find_pid_by_appid, (void *)appid); - - return ret; -} - -static int __get_appid_bypid(int pid, char *appid, int len) -{ - char *result; - - result = __proc_get_appid_bypid(pid); - if (result == NULL) - return -1; - - snprintf(appid, len, "%s", result); - free(result); - - return 0; -} - -int _status_get_appid_bypid(int fd, int pid) -{ - app_pkt_t *pkt = NULL; - int cmd; - int len = 0; - int pgid; - char appid[MAX_PACKAGE_STR_SIZE] = {0, }; - - cmd = APP_GET_INFO_ERROR; - - if (__get_appid_bypid(pid, appid, MAX_PACKAGE_STR_SIZE) == 0) { - SECURE_LOGD("appid for %d is %s", pid, appid); - len = strlen(appid); - cmd = APP_GET_INFO_OK; - goto out; - } - /* support app launched by shell script*/ - _D("second chance"); - pgid = getpgid(pid); - if (pgid <= 1) { - close(fd); - return 0; - } - - _D("second change pgid = %d, pid = %d", pgid, pid); - if (__get_appid_bypid(pgid, appid, MAX_PACKAGE_STR_SIZE) == 0) { - len = strlen(appid); - cmd = APP_GET_INFO_OK; - } - - out: - pkt = (app_pkt_t *)malloc(AUL_PKT_HEADER_SIZE + len); - if (!pkt) { - _E("malloc fail"); - close(fd); - return 0; - } - pkt->cmd = cmd; - pkt->len = len; - memcpy(pkt->data, appid, len); - - if ((len = send(fd, pkt, pkt->len + AUL_PKT_HEADER_SIZE, 0)) != - pkt->len + AUL_PKT_HEADER_SIZE) { - if (errno == EPIPE) - _E("send failed due to EPIPE.\n"); - _E("send fail to client"); - } - - if (pkt) - free(pkt); - - close(fd); - - return 0; -} - -static int __get_pkgid_bypid(int pid, char *pkgid, int len) -{ - char *appid; - app_info_from_db *menu_info; - uid_t uid; - appid = __proc_get_appid_bypid(pid); - if (appid == NULL) - return -1; - - uid = __proc_get_usr_bypid(pid); - if (uid == -1) { - free(appid); - return -1; - } - - if ((menu_info = _get_app_info_from_db_by_appid_user(appid, uid)) == NULL) { - free(appid); - return -1; - } else { - snprintf(pkgid, len, "%s", _get_pkgid(menu_info)); - } - - free(appid); - _free_app_info_from_db(menu_info); - - return 0; -} - -int _status_get_pkgid_bypid(int fd, int pid) -{ - app_pkt_t *pkt = NULL; - int cmd; - int len = 0; - int pgid; - char pkgid[MAX_PACKAGE_STR_SIZE] = {0, }; - - cmd = APP_GET_INFO_ERROR; - - if (__get_pkgid_bypid(pid, pkgid, MAX_PACKAGE_STR_SIZE) == 0) { - SECURE_LOGD("pkgid for %d is %s", pid, pkgid); - len = strlen(pkgid); - cmd = APP_GET_INFO_OK; - goto out; - } - /* support app launched by shell script*/ - _D("second chance"); - pgid = getpgid(pid); - if (pgid <= 1) { - close(fd); - return 0; - } - - _D("second change pgid = %d, pid = %d", pgid, pid); - if (__get_pkgid_bypid(pgid, pkgid, MAX_PACKAGE_STR_SIZE) == 0) { - len = strlen(pkgid); - cmd = APP_GET_INFO_OK; - } - - out: - pkt = (app_pkt_t *)malloc(AUL_PKT_HEADER_SIZE + len); - if (!pkt) { - _E("malloc fail"); - close(fd); - return 0; - } - pkt->cmd = cmd; - pkt->len = len; - memcpy(pkt->data, pkgid, len); - - if ((len = send(fd, pkt, pkt->len + AUL_PKT_HEADER_SIZE, 0)) != - pkt->len + AUL_PKT_HEADER_SIZE) { - if (errno == EPIPE) - _E("send failed due to EPIPE.\n"); - _E("send fail to client"); - } - - if (pkt) - free(pkt); - - close(fd); - - return 0; -} - -static void __socket_monitor_cb(GFileMonitor *monitor, GFile *file, - GFile *other_file, GFileMonitorEvent event_type, - gpointer user_data) -{ - char *path; - char *p; - int pid; - - if (event_type != G_FILE_MONITOR_EVENT_CREATED) - return; - - path = g_file_get_path(file); - p = strrchr(path, '/'); - pid = atoi(p + 1); - - if (pid < 1) - return; - - _request_reply_for_pending_request(pid); - - g_free(path); -} - -int _status_init(void) -{ - char buf[PATH_MAX]; - GFile *file; - GFileMonitor *monitor; - GError *err = NULL; - - snprintf(buf, sizeof(buf), "/run/user/%d", getuid()); - file = g_file_new_for_path(buf); - if (file == NULL) - return -1; - - monitor = g_file_monitor_directory(file, G_FILE_MONITOR_NONE, - NULL, &err); - if (monitor == NULL) - return -1; - - g_signal_connect(monitor, "changed", G_CALLBACK(__socket_monitor_cb), - NULL); - - return 0; -} diff --git a/am_daemon/amd_status.h b/am_daemon/amd_status.h deleted file mode 100644 index a89beb7..0000000 --- a/am_daemon/amd_status.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -#pragma once - -#include -#include -#include -#include -#include - -int _status_add_app_info_list(const char *appid, const char *app_path, int pid, int pad_pid, bool is_subapp, uid_t uid); -int _status_update_app_info_list(int pid, int status, uid_t uid); -int _status_remove_app_info_list_with_uid(uid_t uid); -int _status_remove_app_info_list(int pid, uid_t uid); -int _status_get_app_info_status(int pid, uid_t uid); -int _status_send_running_appinfo(int fd, uid_t uid); -int _status_app_is_running(const char *appid, uid_t uid); -int _status_app_is_running_v2(const char *appid, uid_t caller_uid); -void _status_find_service_apps(int pid, uid_t uid, enum app_status status, void (*send_event_to_svc_core) (int), bool suspend); -void _status_check_service_only(int pid, uid_t uid, void (*send_event_to_svc_core) (int)); -char *_status_app_get_appid_bypid(int pid); -int _status_get_appid_bypid(int fd, int pid); -int _status_get_pkgid_bypid(int fd, int pid); -int _status_init(void); - - diff --git a/include/app_sock.h b/include/app_sock.h index 89211f1..d69ff04 100644 --- a/include/app_sock.h +++ b/include/app_sock.h @@ -21,57 +21,7 @@ #include #include -enum app_cmd { - APP_START = 0, - APP_OPEN, - APP_RESUME, - APP_RESUME_BY_PID, - APP_TERM_BY_PID, - APP_TERM_BY_PID_WITHOUT_RESTART, - APP_RESULT, - APP_START_RES, - APP_CANCEL, - APP_KILL_BY_PID, - APP_ADD_HISTORY, - APP_REMOVE_HISTORY, - APP_RUNNING_INFO, - APP_RUNNING_INFO_RESULT, - APP_IS_RUNNING, - APP_GET_APPID_BYPID, - APP_GET_PKGID_BYPID, - APP_GET_INFO_OK, - APP_GET_INFO_ERROR, - APP_KEY_EVENT, - APP_KEY_RESERVE, - APP_KEY_RELEASE, - APP_STATUS_UPDATE, - APP_RUNNING_LIST_UPDATE, - APP_TERM_REQ_BY_PID, - APP_TERM_BY_PID_ASYNC, - APP_TERM_BGAPP_BY_PID, - APP_PAUSE, - APP_PAUSE_BY_PID, - APP_GROUP_GET_WINDOW, - APP_GROUP_SET_WINDOW, - APP_GROUP_GET_FG, - APP_GROUP_GET_LEADER_PID, - APP_GROUP_GET_LEADER_PIDS, - APP_GROUP_GET_GROUP_PIDS, - APP_GROUP_GET_IDLE_PIDS, - APP_GROUP_LOWER, - APP_GROUP_CLEAR_TOP, - APP_GET_STATUS, - APP_GET_SOCKET_PAIR, - APP_ADD_LOADER, - APP_REMOVE_LOADER, - APP_GET_PID, - - /* for special purpose */ - AMD_RELOAD_APPINFO, - /* reserved for AMD Agent */ - AGENT_DEAD_SIGNAL, - APP_CMD_MAX -}; +#include "aul_cmd.h" #define AUL_SOCK_PREFIX "/tmp/alaunch" #define AUL_SOCK_MAXBUFF 65535 diff --git a/include/aul_cmd.h b/include/aul_cmd.h new file mode 100644 index 0000000..ef5d0ba --- /dev/null +++ b/include/aul_cmd.h @@ -0,0 +1,72 @@ +/* + * 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. + * + */ + +#pragma once + +enum app_cmd { + APP_START = 0, + APP_OPEN, + APP_RESUME, + APP_RESUME_BY_PID, + APP_TERM_BY_PID, + APP_TERM_BY_PID_WITHOUT_RESTART, + APP_RESULT, + APP_START_RES, + APP_CANCEL, + APP_KILL_BY_PID, + APP_ADD_HISTORY, + APP_REMOVE_HISTORY, + APP_RUNNING_INFO, + APP_RUNNING_INFO_RESULT, + APP_IS_RUNNING, + APP_GET_APPID_BYPID, + APP_GET_PKGID_BYPID, + APP_GET_INFO_OK, + APP_GET_INFO_ERROR, + APP_KEY_EVENT, + APP_KEY_RESERVE, + APP_KEY_RELEASE, + APP_STATUS_UPDATE, + APP_RUNNING_LIST_UPDATE, + APP_TERM_REQ_BY_PID, + APP_TERM_BY_PID_ASYNC, + APP_TERM_BGAPP_BY_PID, + APP_PAUSE, + APP_PAUSE_BY_PID, + APP_GROUP_GET_WINDOW, + APP_GROUP_SET_WINDOW, + APP_GROUP_GET_FG, + APP_GROUP_GET_LEADER_PID, + APP_GROUP_GET_LEADER_PIDS, + APP_GROUP_GET_GROUP_PIDS, + APP_GROUP_GET_IDLE_PIDS, + APP_GROUP_LOWER, + APP_GROUP_CLEAR_TOP, + APP_GET_STATUS, + APP_GET_SOCKET_PAIR, + APP_ADD_LOADER, + APP_REMOVE_LOADER, + APP_GET_PID, + + /* for special purpose */ + AMD_RELOAD_APPINFO, + /* reserved for AMD Agent */ + AGENT_DEAD_SIGNAL, + APP_CMD_MAX +}; + + diff --git a/packaging/ac.conf b/packaging/ac.conf deleted file mode 100644 index ffb25c7..0000000 --- a/packaging/ac.conf +++ /dev/null @@ -1,5 +0,0 @@ -d /tmp/alaunch 1777 root root -t /tmp/alaunch - - - - security.SMACK64=* -d /tmp/data-control 1770 owner users -t /tmp/data-control - - - - security.SMACK64="User::App::Shared" -t /tmp/data-control - - - - security.SMACK64TRANSMUTE="TRUE" diff --git a/packaging/ac.service b/packaging/ac.service deleted file mode 100644 index ef5ad7c..0000000 --- a/packaging/ac.service +++ /dev/null @@ -1,15 +0,0 @@ -# -# Systemd script to Launch AMD -# - -[Unit] -Description=Start the Access Control server - -[Service] -EnvironmentFile=-/run/tizen-system-env -ExecStart=/usr/bin/amd - -OOMScoreAdjust=-100 - -[Install] -WantedBy=default.target diff --git a/packaging/ac.socket b/packaging/ac.socket deleted file mode 100644 index 241fd22..0000000 --- a/packaging/ac.socket +++ /dev/null @@ -1,6 +0,0 @@ -[Socket] -ListenStream=/run/user/%U/-2 -DirectoryMode=0777 - -[Install] -WantedBy=sockets.target diff --git a/packaging/aul.changes b/packaging/aul.changes deleted file mode 100644 index b179cb5..0000000 --- a/packaging/aul.changes +++ /dev/null @@ -1,13 +0,0 @@ -* Tue Nov 19 2013 Patrick McCarty cd1dd9c -- Move package manifest to the proper location (packaging directory) - -* Fri Nov 08 2013 Casey Schaufler 7ae8114 -- Assign launchpad_preloading_preinitializing_daemon a Smack execution label of - "User". This sets the Smack label on the daemon process upon invocation. This - allows the daemon to launch applications into the User security domain. - -* Thu Oct 31 2013 Rusty Lynch accepted/tizen/20131022.163320@68dbf2e -- Add warning when ecore_x_init() failes -- Adding initial changelog so all further development will follow the Tizen 3.0 guidelines - which requires proper changelog updates - diff --git a/packaging/aul.spec b/packaging/aul.spec index 3ad3a80..0ed2df8 100644 --- a/packaging/aul.spec +++ b/packaging/aul.spec @@ -5,12 +5,9 @@ Name: aul Summary: App utility library Version: 0.0.300 Release: 1 -Group: System/Libraries +Group: Application Framework/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz -Source100: ac.conf -Source101: ac.service -Source102: ac.socket Source1001: %{name}.manifest Requires(post): /sbin/ldconfig @@ -19,26 +16,19 @@ Requires(postun): /sbin/ldconfig Requires(postun): /usr/bin/systemctl Requires(preun): /usr/bin/systemctl Requires: tizen-platform-config +Requires: amd BuildRequires: cmake BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(dlog) BuildRequires: xdgmime-devel, pkgconfig(xdgmime) -BuildRequires: pkgconfig(security-manager) -BuildRequires: pkgconfig(rua) BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(pkgmgr-info) -BuildRequires: pkgconfig(pkgmgr) BuildRequires: libattr-devel BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(libsystemd-daemon) -BuildRequires: pkgconfig(cynara-client) -BuildRequires: pkgconfig(cynara-creds-socket) -BuildRequires: pkgconfig(cynara-session) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(sqlite3) @@ -96,38 +86,21 @@ rm -rf %{buildroot} %make_install mkdir -p %{buildroot}%{_tmpfilesdir} -mkdir -p %{buildroot}%{_unitdir_user}/default.target.wants -mkdir -p %{buildroot}%{_unitdir_user}/sockets.target.wants mkdir -p %{buildroot}%{_sysconfdir}/skel/.applications/dbspace install -m 0644 .appsvc.db %{buildroot}%{_sysconfdir}/skel/.applications/dbspace/.appsvc.db -install -m 0644 %SOURCE100 %{buildroot}%{_tmpfilesdir}/ac.conf -install -m 0644 %SOURCE101 %{buildroot}%{_unitdir_user}/ac.service -install -m 0644 %SOURCE102 %{buildroot}%{_unitdir_user}/ac.socket -ln -sf ../ac.service %{buildroot}%{_unitdir_user}/default.target.wants/ac.service -ln -sf ../ac.socket %{buildroot}%{_unitdir_user}/sockets.target.wants/ac.socket mkdir -p %{buildroot}%{_datadir}/appsvc cp -R %{_builddir}/%{name}-%{version}/alias/* %{buildroot}%{_datadir}/appsvc %preun -if [ $1 == 0 ]; then - systemctl stop ac.service - systemctl disable ac -fi %post /sbin/ldconfig chsmack -a 'User::Home' %{_sysconfdir}/skel/.applications/dbspace/.appsvc.db -systemctl daemon-reload -if [ $1 == 1 ]; then - systemctl restart ac.service -fi - %postun /sbin/ldconfig -systemctl daemon-reload %files %license LICENSE @@ -143,12 +116,6 @@ systemctl daemon-reload %{_datadir}/aul/preload_list.txt %{_datadir}/aul/preexec_list.txt %{_datadir}/appsvc/* -%{_tmpfilesdir}/ac.conf -%{_unitdir_user}/ac.service -%{_unitdir_user}/default.target.wants/ac.service -%{_unitdir_user}/ac.socket -%{_unitdir_user}/sockets.target.wants/ac.socket -%{_bindir}/amd %{_sysconfdir}/skel/.applications/dbspace/.appsvc.db %files test -- 2.7.4