From 68ca0f7d8074e8b54dd3dbd44f0e15aae948d1a0 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Fri, 3 Jun 2016 21:30:09 +0900 Subject: [PATCH] Use script file for making launchpad-loader Change-Id: I1794da64cb448381c404c89acbd618d93fd93ac6 Signed-off-by: Junghoon Park --- CMakeLists.txt | 5 +- inc/launchpad.h | 1 - inc/loader_info.h | 10 +- inc/preload.h | 162 --------------- inc/process_pool_preload.h | 115 ----------- packaging/default.loader | 19 -- packaging/default.loader.in | 55 ++++++ packaging/launchpad-process-pool-preload-list.txt | 0 packaging/launchpad.spec | 2 - packaging/preload_list.txt.in | 4 - src/launchpad.c | 144 ++++++++------ src/launchpad_lib.c | 2 + src/launchpad_loader.c | 129 ++++++++++-- src/loader_info.c | 231 ++++++++++++++++++++-- 14 files changed, 482 insertions(+), 397 deletions(-) delete mode 100644 inc/preload.h delete mode 100644 inc/process_pool_preload.h delete mode 100644 packaging/default.loader create mode 100644 packaging/default.loader.in delete mode 100644 packaging/launchpad-process-pool-preload-list.txt delete mode 100644 packaging/preload_list.txt.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ac63d95..d5f0cbe 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ PKG_CHECK_MODULES(${this_target_pool} REQUIRED bundle gio-2.0 ttrace + vconf ) FOREACH(flag ${${this_target_pool}_CFLAGS}) @@ -107,9 +108,7 @@ SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} INSTALL(TARGETS ${LAUNCHPAD_PROCESS_POOL} DESTINATION bin) -CONFIGURE_FILE(packaging/preload_list.txt.in packaging/preload_list.txt @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/preload_list.txt DESTINATION share/aul) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/launchpad-process-pool-preload-list.txt DESTINATION share/aul) +CONFIGURE_FILE(packaging/default.loader.in packaging/default.loader @ONLY) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/default.loader DESTINATION share/aul) # liblaunchpad diff --git a/inc/launchpad.h b/inc/launchpad.h index 5f8364a..fb2cabf 100644 --- a/inc/launchpad.h +++ b/inc/launchpad.h @@ -51,7 +51,6 @@ typedef struct { enum LAUNCHPAD_TYPE { LAUNCHPAD_TYPE_UNSUPPORTED = -1, - LAUNCHPAD_TYPE_HW, LAUNCHPAD_TYPE_USER, LAUNCHPAD_TYPE_DYNAMIC = 100, LAUNCHPAD_TYPE_MAX diff --git a/inc/loader_info.h b/inc/loader_info.h index 4ee7c80..950aa3c 100644 --- a/inc/loader_info.h +++ b/inc/loader_info.h @@ -18,6 +18,7 @@ #include #include +#include #define METHOD_TIMEOUT 0x1 #define METHOD_VISIBILITY 0x2 @@ -27,14 +28,17 @@ typedef struct _loader_info { int type; char *name; char *exe; - char *app_type; + GList *app_types; int detection_method; int timeout_val; + char *hw_acc; + GList *alternative_loaders; + bundle *extra; } loader_info_t; GList *_loader_info_load(const char *path); void _loader_info_dispose(GList *info); -int _loader_info_find_type_by_app_type(GList *info, const char *app_type); - +int _loader_info_find_type(GList *info, const char *app_type, bool hwacc); +int *_loader_get_alternative_types(GList *info, int type, int *len); diff --git a/inc/preload.h b/inc/preload.h deleted file mode 100644 index c4dac2a..0000000 --- a/inc/preload.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2015 - 2016 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. - */ - - -#ifdef PRELOAD_ACTIVATE - -#include -#define PRELOAD_FILE SHARE_PREFIX"/preload_list.txt" - -#define EFL_PREINIT_FUNC "elm_quicklaunch_init" -#define EFL_SHUTDOWN_FUNC "elm_quicklaunch_shutdown" - -static int preload_initialized = 0; -static int g_argc; -static char **g_argv; -static int max_cmdline_size = 0; - -static int (*dl_einit) () = NULL; -static int (*dl_efini) () = NULL; - -static inline void __preload_init(int argc, char **argv) -{ - void *handle = NULL; - char soname[MAX_LOCAL_BUFSZ]; - FILE *preload_list; - int (*func)() = NULL; - int i; - - g_argc = argc; - g_argv = argv; - for (i = 0; i < argc; i++) { - max_cmdline_size += (strlen(argv[i]) + 1); - } - _D("max_cmdline_size = %d", max_cmdline_size); - - preload_list = fopen(PRELOAD_FILE, "rt"); - if (preload_list == NULL) { - _E("no preload\n"); - return; - } - - while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > 0) { - soname[strlen(soname) - 1] = 0; - handle = dlopen((const char *) soname, RTLD_NOW); - if (handle == NULL) - continue; - _D("preload %s# - handle : %x\n", soname, handle); - - func = dlsym(handle, EFL_PREINIT_FUNC); - if (func != NULL) { - _D("get pre-initialization function\n"); - dl_einit = func; - func = dlsym(handle, EFL_SHUTDOWN_FUNC); - if (func != NULL) { - _D("get shutdown function\n"); - dl_efini = func; - } - } - } - - fclose(preload_list); - preload_initialized = 1; -} - -static inline int preinit_init() -{ - if (dl_einit != NULL) - dl_einit(0, NULL); - _D("pre-initialzation on"); - return 0; -} - -static inline int preinit_fini() -{ - if (dl_efini != NULL) - dl_efini(); - _D("pre-initialization off"); - return 0; -} - -/* TODO : how to set cmdline gracefully ?? */ -static inline int __change_cmdline(char *cmdline) -{ - if (strlen(cmdline) > max_cmdline_size + 1) { - _E("cmdline exceed max size : %d", max_cmdline_size); - return -1; - } - - memset(g_argv[0], '\0', max_cmdline_size); - snprintf(g_argv[0], max_cmdline_size, "%s", cmdline); - - return 0; -} - -static inline void __preload_exec(int argc, char **argv) -{ - void *handle = NULL; - int (*dl_main)(int, char **); - char *error = NULL; - - if (!preload_initialized) - return; - - handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL); - if (handle == NULL) { - _E("dlopen(\"%s\") failed", argv[0]); - if ((error = dlerror()) != NULL) { - _E("dlopen error: %s", error); - } - return; - } - - dlerror(); - - dl_main = dlsym(handle, "main"); - if (dl_main != NULL) { - if (__change_cmdline(argv[0]) < 0) { - _E("change cmdline fail"); - dlclose(handle); - return; - } - -#ifdef _APPFW_FEATURE_PRIORITY_CHANGE - if (setpriority(PRIO_PROCESS, 0, 0) == -1) { - SECURE_LOGE("Setting process (%d) priority to 0 failed," - " errno: %d (%s)", - getpid(), errno, strerror(errno)); - } -#endif - dl_main(argc, argv); - } else { - _E("dlsym not founded. bad preloaded app - check fpie pie"); - if ((error = dlerror()) != NULL) { - _E("dlsym error: %s", error); - } - dlclose(handle); - return; - } - - exit(0); -} - -#else - -static inline void __preload_init(); -static inline void __preload_exec(int argc, char **argv); - -#endif - diff --git a/inc/process_pool_preload.h b/inc/process_pool_preload.h deleted file mode 100644 index aa84e51..0000000 --- a/inc/process_pool_preload.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __PROCESS_POOL_PRELOAD_H__ -#define __PROCESS_POOL_PRELOAD_H__ - -#include -#include -#include -#include - -#define PROCESS_POOL_PRELOAD_FILE \ - SHARE_PREFIX"/launchpad-process-pool-preload-list.txt" - -static int g_dlopen_size = 5; -static int g_dlopen_count = 0; -static void **g_dlopen_handle_list = NULL; - -static inline int __preload_save_dlopen_handle(void *handle) -{ - void **tmp; - - if (!handle) - return 1; - - if (g_dlopen_count == g_dlopen_size || !g_dlopen_handle_list) { - tmp = realloc(g_dlopen_handle_list, - 2 * g_dlopen_size * sizeof(void *)); - if (tmp == NULL) { - _E("out of memory\n"); - dlclose(handle); - return 1; - } - g_dlopen_size *= 2; - g_dlopen_handle_list = tmp; - } - g_dlopen_handle_list[g_dlopen_count++] = handle; - return 0; -} - -static inline void __preload_fini_for_process_pool(void) -{ - int i = 0; - void *handle; - - if (!g_dlopen_handle_list) - return; - - for (i = 0; i < g_dlopen_count; ++i) { - handle = g_dlopen_handle_list[i]; - if (handle) { - if (0 != dlclose(handle)) - _E("dlclose failed\n"); - } - } - free(g_dlopen_handle_list); - g_dlopen_handle_list = NULL; - g_dlopen_size = 5; - g_dlopen_count = 0; -} - -static inline void __preload_init_for_process_pool(void) -{ - void *handle = NULL; - char soname[MAX_LOCAL_BUFSZ] = { 0, }; - FILE *preload_list = NULL; - size_t len; - - if (atexit(__preload_fini_for_process_pool) != 0) { - _E("Cannot register atexit callback. " - "Libraries will not be unloaded"); - } - - preload_list = fopen(PROCESS_POOL_PRELOAD_FILE, "rt"); - if (preload_list == NULL) { - _E("no preload\n"); - return; - } - - while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > 0) { - len = strnlen(soname, MAX_LOCAL_BUFSZ); - if (len > 0) - soname[len - 1] = '\0'; - - handle = dlopen((const char *) soname, RTLD_NOW); - if (handle == NULL) { - _E("dlopen(\"%s\") was failed!", soname); - continue; - } - - if (__preload_save_dlopen_handle(handle) != 0) { - _E("Cannot save handle, no more preloads"); - break; - } - _D("preload %s# - handle : %x\n", soname, handle); - } - - fclose(preload_list); -} - -#endif /* __PROCESS_POOL_PRELOAD_H__ */ - diff --git a/packaging/default.loader b/packaging/default.loader deleted file mode 100644 index 042973e..0000000 --- a/packaging/default.loader +++ /dev/null @@ -1,19 +0,0 @@ -[LOADER] -NAME wrt-loader -EXE /usr/bin/wrt-loader -APP_TYPE webapp -DETECTION_METHOD TIMEOUT|DEMAND -TIMEOUT 5000 - -[LOADER] -NAME jsnative-loader -EXE /usr/bin/jsnative-loader -APP_TYPE jsapp -DETECTION_METHOD TIMEOUT|VISIBILITY -TIMEOUT 5000 - -[LOADER] -NAME cs-loader -EXE null -APP_TYPE csapp - diff --git a/packaging/default.loader.in b/packaging/default.loader.in new file mode 100644 index 0000000..1c90a68 --- /dev/null +++ b/packaging/default.loader.in @@ -0,0 +1,55 @@ +[LOADER] +NAME wrt-loader +EXE /usr/bin/wrt-loader +APP_TYPE webapp +DETECTION_METHOD TIMEOUT|DEMAND +TIMEOUT 5000 + +[LOADER] +NAME jsnative-loader +EXE /usr/bin/jsnative-loader +APP_TYPE jsapp +DETECTION_METHOD TIMEOUT|VISIBILITY +TIMEOUT 5000 + +[LOADER] +NAME cs-loader +EXE null +APP_TYPE csapp + +[LOADER] +NAME hw-loader1 +EXE /usr/bin/launchpad-loader +APP_TYPE capp|c++app +HW_ACC ON +DETECTION_METHOD TIMEOUT|VISIBILITY +TIMEOUT 5000 +EXTRA loader_type hw-loader +EXTRA_ARRAY preload +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-efl.so.1 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-common.so.1 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcapi-appfw-application.so.0 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/ecore_imf/modules/wayland/v-1.16/libwltextinputmodule.so +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libdali-toolkit.so +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcairo.so.2 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libefl-assist.so.0 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcapi-media-player.so.0 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcapi-media-camera.so.0 +ALTERNATIVE_LOADER common-loader1 + +[LOADER] +NAME common-loader1 +EXE /usr/bin/launchpad-loader +APP_TYPE capp|c++app +DETECTION_METHOD TIMEOUT|VISIBILITY +TIMEOUT 5000 +EXTRA loader_type common-loader +EXTRA_ARRAY preload +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-efl.so.1 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libappcore-common.so.1 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/libcapi-appfw-application.so.0 +EXTRA_ARRAY_VAL @LIB_INSTALL_DIR@/ecore_imf/modules/wayland/v-1.16/libwltextinputmodule.so +ALTERNATIVE_LOADER hw-loader1 + + + diff --git a/packaging/launchpad-process-pool-preload-list.txt b/packaging/launchpad-process-pool-preload-list.txt deleted file mode 100644 index e69de29..0000000 diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index f5db9b8..53613dd 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -77,8 +77,6 @@ cp %{_builddir}/%{name}-%{version}/LICENSE %{buildroot}/usr/share/license/%{nam %files %manifest launchpad.manifest %{_prefix}/share/license/%{name} -%{_prefix}/share/aul/preload_list.txt -%{_prefix}/share/aul/launchpad-process-pool-preload-list.txt %{_prefix}/share/aul/default.loader %{_unitdir_user}/launchpad-process-pool.service %{_unitdir_user}/launchpad-process-pool.socket diff --git a/packaging/preload_list.txt.in b/packaging/preload_list.txt.in deleted file mode 100644 index fa29fb6..0000000 --- a/packaging/preload_list.txt.in +++ /dev/null @@ -1,4 +0,0 @@ -@LIB_INSTALL_DIR@/libappcore-efl.so.1 -@LIB_INSTALL_DIR@/libappcore-common.so.1 -@LIB_INSTALL_DIR@/libcapi-appfw-application.so.0 -@LIB_INSTALL_DIR@/ecore_imf/modules/wayland/v-1.16/libwltextinputmodule.so diff --git a/src/launchpad.c b/src/launchpad.c index fad964a..54c4554 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "perf.h" #include "launchpad_common.h" @@ -71,6 +72,7 @@ typedef struct { int loader_id; } loader_context_t; +static int __sys_hwacc; static GList *loader_info_list; static int user_slot_offset; static GList *candidate_slot_list; @@ -283,18 +285,6 @@ static int __set_access(const char *appid) return security_manager_prepare_app(appid); } -static int __get_launchpad_type(const char *internal_pool, const char *hwacc, - const char *app_type) -{ - int type; - - type = _loader_info_find_type_by_app_type(loader_info_list, app_type); - if (type >= LAUNCHPAD_TYPE_USER) - return type; - - return LAUNCHPAD_TYPE_HW; -} - static int __get_loader_id(bundle *kb) { const char *val; @@ -911,6 +901,51 @@ static int __check_caller_by_pid(int pid) return -1; } +static bool __is_hw_acc(const char *hwacc) +{ + if (strcmp(hwacc, "USE") == 0 || + (strcmp(hwacc, "SYS") == 0 && + __sys_hwacc == SETTING_HW_ACCELERATION_ON)) + return true; + + return false; +} + +static candidate_process_context_t *__find_available_slot(const char *hwacc, + const char *app_type) +{ + int type; + candidate_process_context_t *cpc; + int *a_types; + int len = 0; + int i; + + type = _loader_info_find_type(loader_info_list, app_type, __is_hw_acc(hwacc)); + cpc = __find_slot(type, PAD_LOADER_ID_STATIC); + if (!cpc) + return NULL; + + if (cpc->prepared) + return cpc; + + a_types = _loader_get_alternative_types(loader_info_list, type, &len); + if (!a_types) + return NULL; + + for (i = 0; i < len; i++) { + cpc = __find_slot(a_types[i], PAD_LOADER_ID_STATIC); + if (!cpc) + continue; + if (cpc->prepared) { + free(a_types); + return cpc; + } + } + + free(a_types); + return NULL; +} + static gboolean __handle_launch_event(gpointer data) { loader_context_t *lc = (loader_context_t *) data; @@ -918,7 +953,7 @@ static gboolean __handle_launch_event(gpointer data) bundle *kb = NULL; app_pkt_t *pkt = NULL; appinfo_t *menu_info = NULL; - candidate_process_context_t *cpc; + candidate_process_context_t *cpc = NULL; const char *app_path = NULL; int pid = -1; int clifd = -1; @@ -1006,21 +1041,15 @@ static gboolean __handle_launch_event(gpointer data) SECURE_LOGD("app_type : %s\n", menu_info->app_type); SECURE_LOGD("pkg_type : %s\n", menu_info->pkg_type); - if ((loader_id = __get_loader_id(kb)) <= PAD_LOADER_ID_STATIC) { - type = __get_launchpad_type(menu_info->internal_pool, - menu_info->hwacc, menu_info->app_type); - if (type < 0) { - _E("failed to get launchpad type"); - goto end; - } - if (menu_info->comp_type && - strcmp(menu_info->comp_type, "svcapp") == 0) - loader_id = PAD_LOADER_ID_DIRECT; - else - loader_id = PAD_LOADER_ID_STATIC; + if (menu_info->comp_type && + strcmp(menu_info->comp_type, "svcapp") == 0) { + loader_id = PAD_LOADER_ID_DIRECT; + } else if ((loader_id = __get_loader_id(kb)) <= PAD_LOADER_ID_STATIC) { + cpc = __find_available_slot(menu_info->hwacc, menu_info->app_type); } else { type = LAUNCHPAD_TYPE_DYNAMIC; + cpc = __find_slot(type, loader_id); } _modify_bundle(kb, cr.pid, menu_info, pkt->cmd); @@ -1031,21 +1060,13 @@ static gboolean __handle_launch_event(gpointer data) PERF("get package information & modify bundle done"); - if (loader_id == PAD_LOADER_ID_DIRECT || - (cpc = __find_slot(type, loader_id)) == NULL) { - _W("Launch directly"); + if (loader_id == PAD_LOADER_ID_DIRECT || cpc == NULL) { + _W("Launch directly %d %d", loader_id, cpc); pid = __launch_directly(menu_info->appid, app_path, clifd, kb, menu_info, NULL); } else { - if (cpc->prepared) { - _W("Launch %d type process", type); - pid = __send_launchpad_loader(cpc, pkt, app_path, - clifd); - } else { - _W("Launch directly"); - pid = __launch_directly(menu_info->appid, app_path, - clifd, kb, menu_info, cpc); - } + _W("Launch %d type process", cpc->type); + pid = __send_launchpad_loader(cpc, pkt, app_path, clifd); } __send_result_to_caller(clifd, pid, app_path); @@ -1200,6 +1221,8 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) { loader_info_t *info = (loader_info_t *)data; candidate_process_context_t *cpc; + bundle_raw *extra = NULL; + int len; if (!strcmp(info->exe, "null")) { cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, PAD_LOADER_ID_DIRECT, @@ -1213,8 +1236,11 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) } if (access(info->exe, F_OK | X_OK) == 0) { + if (info->extra) + bundle_encode(info->extra, &extra, &len); + cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, PAD_LOADER_ID_STATIC, - 0, info->exe, NULL, info->detection_method, info->timeout_val); + 0, info->exe, (char *)extra, info->detection_method, info->timeout_val); if (cpc == NULL) return; @@ -1227,7 +1253,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) } } -static void __add_default_slots_from_file(void) +static int __add_default_slots(void) { if (loader_info_list) _loader_info_dispose(loader_info_list); @@ -1235,30 +1261,23 @@ static void __add_default_slots_from_file(void) loader_info_list = _loader_info_load(LOADER_INFO_PATH); if (loader_info_list == NULL) - return; + return -1; user_slot_offset = 0; g_list_foreach(loader_info_list, __add_slot_from_info, NULL); + + return 0; } -static int __add_default_slots(void) +static void __vconf_cb(keynode_t *key, void *data) { - candidate_process_context_t *cpc; - int ret; - - cpc = __add_slot(LAUNCHPAD_TYPE_HW, PAD_LOADER_ID_STATIC, 0, - LOADER_PATH_DEFAULT, NULL, - METHOD_TIMEOUT | METHOD_VISIBILITY, 5000); - if (cpc == NULL) - return -1; - - ret = __prepare_candidate_process(LAUNCHPAD_TYPE_HW, - PAD_LOADER_ID_STATIC); - if (ret != 0) - return -1; + const char *name; - __add_default_slots_from_file(); - return 0; + name = vconf_keynode_get_name(key); + if (name && strcmp(name, VCONFKEY_SETAPPL_APP_HW_ACCELERATION) == 0) { + __sys_hwacc = vconf_keynode_get_int(key); + _D("sys hwacc: %d", __sys_hwacc); + } } static int __before_loop(int argc, char **argv) @@ -1277,6 +1296,19 @@ static int __before_loop(int argc, char **argv) return -1; } + ret = vconf_get_int(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, &__sys_hwacc); + if (ret != VCONF_OK) { + _E("Failed to get vconf int: %s", + VCONFKEY_SETAPPL_APP_HW_ACCELERATION); + } + + ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, + __vconf_cb, NULL); + if (ret != 0) { + _E("Failed to register callback for %s", + VCONFKEY_SETAPPL_APP_HW_ACCELERATION); + } + return 0; } diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index 7ca5aab..f655ed6 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef _APPFW_FEATURE_LOADER_PRIORITY #include #include @@ -351,6 +352,7 @@ static int __before_loop(int argc, char **argv) if (extra) bundle_free(extra); + malloc_trim(0); #ifdef _APPFW_FEATURE_LOADER_PRIORITY res = setpriority(PRIO_PGRP, 0, 0); if (res == -1) { diff --git a/src/launchpad_loader.c b/src/launchpad_loader.c index 0c19f91..fbde22a 100644 --- a/src/launchpad_loader.c +++ b/src/launchpad_loader.c @@ -29,10 +29,14 @@ #include #include "launchpad_common.h" -#include "preload.h" -#include "process_pool_preload.h" #include "launchpad.h" +#define KEY_LOADER_TYPE "loader_type" +#define LOADER_TYPE_COMMON "common-loader" +#define LOADER_TYPE_HW "hw-loader" +#define LOADER_TYPE_SW "sw-loader" + + extern bundle *launchpad_loader_get_bundle(); static Ecore_Fd_Handler *__fd_handler; @@ -44,6 +48,22 @@ static int __sys_hwacc; static Evas_Object *__win; static Evas_Object *__bg; static Evas_Object *__conform; +static int __type; + +enum loader_type { + TYPE_COMMON, + TYPE_SW, + TYPE_HW, + MAX_LOADER_TYPE +}; + +enum acc_type { + SW_ACC, + HW_ACC, + MAX_ACC_TYPE +}; + +typedef void (*loader_convertible)(void); static void __vconf_cb(keynode_t *key, void *data) { @@ -56,6 +76,18 @@ static void __vconf_cb(keynode_t *key, void *data) } } +static void __init_theme(void) +{ + char *theme = elm_theme_list_item_path_get(eina_list_data_get( + elm_theme_list_get(NULL)), NULL); + Eina_Bool is_exist = edje_file_group_exists(theme, "*"); + if (!is_exist) + _D("theme path: %s", theme); + + if (theme) + free(theme); +} + static void __init_window(void) { __win = elm_win_add(NULL, "package_name", ELM_WIN_BASIC); @@ -89,6 +121,8 @@ static void __init_window(void) static void __fini_window(void) { + _D("Drop window"); + if (__conform) { evas_object_del(__conform); elm_conformant_precreated_object_set(NULL); @@ -108,19 +142,74 @@ static void __fini_window(void) } } +static void __preload_lib(bundle *b) +{ + void *handle = NULL; + int i; + int len = 0; + const char **so_array; + + if (!b) + return; + + so_array = bundle_get_str_array(b, "preload", &len); + + if (!so_array) + return; + + for (i = 0; i < len; i++) { + handle = dlopen(so_array[i], RTLD_NOW); + _D("preload %s# - handle : %x\n", so_array[i], handle); + } +} + static void __loader_create_cb(bundle *extra, int type, void *user_data) { int elm_init_cnt = 0; int ret; + char *ltype = NULL; + + if (extra == NULL) { + _E("No extra data"); + return; + } + + bundle_get_str(extra, KEY_LOADER_TYPE, <ype); + + if (ltype == NULL) { + _E("No loader type"); + return; + } - __preload_init(__argc, __argv); - __preload_init_for_process_pool(); + if (!strcmp(LOADER_TYPE_COMMON, ltype)) + __type = TYPE_COMMON; + else if (!strcmp(LOADER_TYPE_SW, ltype)) + __type = TYPE_SW; + else if (!strcmp(LOADER_TYPE_HW, ltype)) + __type = TYPE_HW; + + _D("Loader type:%d", __type); + + __preload_lib(extra); elm_init_cnt = elm_init(__argc, __argv); _D("[candidate] elm init, returned: %d", elm_init_cnt); - elm_config_accel_preference_set("hw"); - __init_window(); + switch (__type) { + case TYPE_SW: + elm_config_accel_preference_set("none"); + __init_window(); + break; + + case TYPE_HW: + elm_config_accel_preference_set("hw"); + __init_window(); + break; + + default: + __init_theme(); + break; + } ret = vconf_get_int(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, &__sys_hwacc); if (ret != VCONF_OK) { @@ -134,15 +223,24 @@ static void __loader_create_cb(bundle *extra, int type, void *user_data) _E("Failed to register callback for %s", VCONFKEY_SETAPPL_APP_HW_ACCELERATION); } - malloc_trim(0); } +static loader_convertible __converter_table[MAX_LOADER_TYPE][MAX_ACC_TYPE] = { + [TYPE_COMMON][SW_ACC] = NULL, + [TYPE_COMMON][HW_ACC] = NULL, + [TYPE_SW][SW_ACC] = NULL, + [TYPE_SW][HW_ACC] = __fini_window, + [TYPE_HW][SW_ACC] = __fini_window, + [TYPE_HW][HW_ACC] = NULL, +}; + static int __loader_launch_cb(int argc, char **argv, const char *app_path, const char *appid, const char *pkgid, const char *pkg_type, void *user_data) { const char *hwacc; bundle *kb = launchpad_loader_get_bundle(); + int acc = SW_ACC; vconf_ignore_key_changed(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, __vconf_cb); if (kb == NULL) @@ -153,18 +251,15 @@ static int __loader_launch_cb(int argc, char **argv, const char *app_path, if (!hwacc) return 0; - if (strcmp(hwacc, "USE") == 0) { - _D("Use preinitialized window"); - return 0; - } else if (strcmp(hwacc, "SYS") == 0 && - __sys_hwacc == SETTING_HW_ACCELERATION_ON) { - _D("Use preinitialized window"); - return 0; + if (strcmp(hwacc, "USE") == 0 || + (strcmp(hwacc, "SYS") == 0 && + __sys_hwacc == SETTING_HW_ACCELERATION_ON)) { + acc = HW_ACC; } - _D("Dispose window"); - __fini_window(); - elm_config_accel_preference_set("none"); + loader_convertible convert = __converter_table[__type][acc]; + if (convert) + convert(); return 0; } diff --git a/src/loader_info.c b/src/loader_info.c index cfcab66..fc86f29 100644 --- a/src/loader_info.c +++ b/src/loader_info.c @@ -30,10 +30,18 @@ #define TAG_APP_TYPE "APP_TYPE" #define TAG_DETECTION_METHOD "DETECTION_METHOD" #define TAG_TIMEOUT "TIMEOUT" +#define TAG_EXTRA "EXTRA" +#define TAG_EXTRA_ARRAY "EXTRA_ARRAY" +#define TAG_EXTRA_ARRAY_VAL "EXTRA_ARRAY_VAL" +#define TAG_ALTERNATIVE_LOADER "ALTERNATIVE_LOADER" +#define TAG_HW_ACC "HW_ACC" +#define VAL_ON "ON" +#define VAL_OFF "OFF" #define VAL_METHOD_TIMEOUT "TIMEOUT" #define VAL_METHOD_DEMAND "DEMAND" #define VAL_METHOD_VISIBILITY "VISIBILITY" + static loader_info_t *__create_loader_info() { loader_info_t *info = malloc(sizeof(loader_info_t)); @@ -41,9 +49,12 @@ static loader_info_t *__create_loader_info() info->type = 0; info->name = NULL; info->exe = NULL; - info->app_type = NULL; + info->app_types = NULL; + info->hw_acc = NULL; + info->alternative_loaders = NULL; info->detection_method = METHOD_TIMEOUT | METHOD_VISIBILITY; info->timeout_val = 5000; + info->extra = bundle_create(); return info; } @@ -71,6 +82,72 @@ static void __parse_detection_method(loader_info_t *info, char *line) _D("detection_method:%d", info->detection_method); } +static void __parse_app_types(loader_info_t *info, char *line) +{ + char *token; + char *savedptr; + char refined_tok[MAX_LOCAL_BUFSZ]; + + token = strtok_r(line, "|", &savedptr); + while (token) { + refined_tok[0] = '\0'; + sscanf(token, "%s", refined_tok); + if (refined_tok[0] != '\0') + info->app_types = g_list_append(info->app_types, strdup(refined_tok)); + token = strtok_r(NULL, "|", &savedptr); + } +} + +static void __parse_extra(loader_info_t *info, char *line) +{ + char tok1[MAX_LOCAL_BUFSZ] = { 0, }; + char tok2[MAX_LOCAL_BUFSZ] = { 0, }; + char tok3[MAX_LOCAL_BUFSZ] = { 0, }; + + if (info->extra == NULL) + return; + + sscanf(line, "%s %s %s", tok1, tok2, tok3); + + if (strlen(tok2) == 0 || strlen(tok3) == 0) + return; + + bundle_add_str(info->extra, tok2, tok3); +} + +static void __add_extra_array_from_list(bundle *b, const char *key, GList *list) +{ + const char **array; + int len; + int i; + GList *cur; + + if (b == NULL || key == NULL || list == NULL) + return; + + len = g_list_length(list); + array = malloc(sizeof(const char *) * len); + + cur = list; + for (i = 0; i < len; i++) { + array[i] = cur->data; + cur = g_list_next(cur); + } + + bundle_add_str_array(b, key, array, len); + free(array); +} + +static void __flush_extra_array(bundle *b, char *key, GList *list) +{ + if (list) { + __add_extra_array_from_list(b, key, list); + g_list_free_full(list, free); + } + + free(key); +} + static GList *__parse_file(GList *list, const char *path) { FILE *fp; @@ -78,6 +155,8 @@ static GList *__parse_file(GList *list, const char *path) char tok1[MAX_LOCAL_BUFSZ]; char tok2[MAX_LOCAL_BUFSZ]; loader_info_t *cur_info = NULL; + char *key = NULL; + GList *extra_array = NULL; fp = fopen(path, "rt"); @@ -90,8 +169,12 @@ static GList *__parse_file(GList *list, const char *path) sscanf(buf, "%s %s", tok1, tok2); if (strcasecmp(TAG_LOADER, tok1) == 0) { - if (cur_info != NULL) + if (cur_info != NULL) { + __flush_extra_array(cur_info->extra, key, extra_array); + extra_array = NULL; + key = NULL; list = g_list_append(list, cur_info); + } cur_info = __create_loader_info(); continue; } @@ -99,20 +182,35 @@ static GList *__parse_file(GList *list, const char *path) if (tok1[0] == '\0' || tok2[0] == '\0' || tok1[0] == '#') continue; - if (strcasecmp(TAG_NAME, tok1) == 0) + if (strcasecmp(TAG_NAME, tok1) == 0) { cur_info->name = strdup(tok2); - else if (strcasecmp(TAG_EXE, tok1) == 0) + } else if (strcasecmp(TAG_EXE, tok1) == 0) { cur_info->exe = strdup(tok2); - else if (strcasecmp(TAG_APP_TYPE, tok1) == 0) - cur_info->app_type = strdup(tok2); - else if (strcasecmp(TAG_DETECTION_METHOD, tok1) == 0) + } else if (strcasecmp(TAG_APP_TYPE, tok1) == 0) { + __parse_app_types(cur_info, &buf[strlen(tok1)]); + } else if (strcasecmp(TAG_DETECTION_METHOD, tok1) == 0) { __parse_detection_method(cur_info, &buf[strlen(tok1)]); - else if (strcasecmp(TAG_TIMEOUT, tok1) == 0) + } else if (strcasecmp(TAG_TIMEOUT, tok1) == 0) { cur_info->timeout_val = atoi(tok2); + } else if (strcasecmp(TAG_EXTRA, tok1) == 0) { + __parse_extra(cur_info, buf); + } else if (strcasecmp(TAG_EXTRA_ARRAY, tok1) == 0) { + __flush_extra_array(cur_info->extra, key, extra_array); + extra_array = NULL; + key = strdup(tok2); + } else if (strcasecmp(TAG_EXTRA_ARRAY_VAL, tok1) == 0) { + extra_array = g_list_append(extra_array, strdup(tok2)); + } else if (strcasecmp(TAG_HW_ACC, tok1) == 0) { + cur_info->hw_acc = strdup(tok2); + } else if (strcasecmp(TAG_ALTERNATIVE_LOADER, tok1) == 0) { + cur_info->alternative_loaders = g_list_append(cur_info->alternative_loaders, strdup(tok2)); + } } - if (cur_info != NULL) + if (cur_info != NULL) { + __flush_extra_array(cur_info->extra, key, extra_array); list = g_list_append(list, cur_info); + } fclose(fp); @@ -157,7 +255,13 @@ static void __free_info(gpointer data) free(info->name); free(info->exe); - free(info->app_type); + if (info->app_types) + g_list_free_full(info->app_types, free); + free(info->hw_acc); + if (info->extra) + bundle_free(info->extra); + if (info->alternative_loaders) + g_list_free_full(info->alternative_loaders, free); free(info); } @@ -167,19 +271,58 @@ void _loader_info_dispose(GList *info) g_list_free_full(info, __free_info); } -static int __comp_app_type(gconstpointer a, gconstpointer b) +static int __comp_str(gconstpointer a, gconstpointer b) +{ + return strcmp(a, b); +} + +static int __comp_app_type_with_hw_acc(gconstpointer a, gconstpointer b) +{ + loader_info_t *info = (loader_info_t *)a; + + if (info == NULL || info->app_types == NULL || b == NULL) + return -1; + + if (g_list_find_custom(info->app_types, b, __comp_str) && + (info->hw_acc == NULL || !strcasecmp(VAL_ON, info->hw_acc))) + return 0; + + return -1; +} + +static int __comp_app_type_with_sw_acc(gconstpointer a, gconstpointer b) +{ + loader_info_t *info = (loader_info_t *)a; + + if (info == NULL || info->app_types == NULL || b == NULL) + return -1; + + if (g_list_find_custom(info->app_types, b, __comp_str) && + (info->hw_acc == NULL || !strcasecmp(VAL_OFF, info->hw_acc))) + return 0; + + return -1; +} + +static int __comp_name(gconstpointer a, gconstpointer b) { loader_info_t *info = (loader_info_t *)a; - if (info == NULL || info->app_type == NULL || b == NULL) + if (info == NULL || info->name == NULL || b == NULL) return -1; - return strcmp(info->app_type, b); + return strcmp(info->name, b); } -int _loader_info_find_type_by_app_type(GList *info, const char *app_type) +int _loader_info_find_type(GList *info, const char *app_type, bool hwacc) { - GList *cur = g_list_find_custom(info, app_type, __comp_app_type); + GList *cur = NULL; + + + if (hwacc) + cur = g_list_find_custom(info, app_type, __comp_app_type_with_hw_acc); + else + cur = g_list_find_custom(info, app_type, __comp_app_type_with_sw_acc); if (cur == NULL) return -1; @@ -189,6 +332,64 @@ int _loader_info_find_type_by_app_type(GList *info, const char *app_type) return cur_info->type; } +static int *__make_type_array(GList *info, GList *loaders, int *len) +{ + int l; + int *t; + loader_info_t *i; + GList *c; + GList *cur; + int j = 0; + + l = g_list_length(loaders); + + if (l <= 0) + return NULL; + + t = malloc(sizeof(int) * l); + if (!t) + return NULL; + + *len = l; + + cur = loaders; + while (cur) { + c = g_list_find_custom(info, cur->data, __comp_name); + + if (c) { + i = (loader_info_t *)c->data; + t[j] = i->type; + j++; + } + + cur = g_list_next(cur); + } + + return t; +} + +int *_loader_get_alternative_types(GList *info, int type, int *len) +{ + GList *cur; + loader_info_t *i; + + if (!info) + return NULL; + + cur = info; + while (cur) { + i = (loader_info_t *)cur->data; + if (i->type == type) { + if (!i->alternative_loaders) + return NULL; + + return __make_type_array(info, i->alternative_loaders, len); + } + cur = g_list_next(cur); + } + + return NULL; +} -- 2.7.4