From 441a127cb06c3f04e2c65de0d55d1f1a2631f7f7 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 24 Jan 2018 17:45:26 +0900 Subject: [PATCH] Adjust the timing of the loader creation If the application is not installed, the launchpad doesn't prepare the loader processes. Change-Id: I7db937b1bed93c7689f0b944cc16fabc071ba458 Signed-off-by: Hwankyu Jhun --- inc/key.h | 1 + inc/launchpad_common.h | 1 + inc/loader_info.h | 8 +++- src/launchpad.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++--- src/loader_info.c | 28 ++++++++++++ 5 files changed, 149 insertions(+), 8 deletions(-) diff --git a/inc/key.h b/inc/key.h index 7401ace..b75bc38 100644 --- a/inc/key.h +++ b/inc/key.h @@ -47,6 +47,7 @@ extern "C" { #define AUL_K_HIGHPRIORITY "__AUL_HIGHPRIORITY__" #define AUL_K_IS_GLOBAL "__AUL_IS_GLOBAL__" #define AUL_K_TEP_PATH "__AUL_TEP_PATH__" +#define AUL_K_IS_INSTALLED "__AUL_IS_INSTALLED__" #ifdef __cplusplus } diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index dcfcac6..102fa5a 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -47,6 +47,7 @@ #define PAD_CMD_MAKE_DEFAULT_SLOTS 13 #define PAD_CMD_DEMAND 14 #define PAD_CMD_PING 15 +#define PAD_CMD_UPDATE_APP_TYPE 16 #define LAUNCHPAD_LAUNCH_SIGNAL 83 #define LAUNCHPAD_DEAD_SIGNAL 61 diff --git a/inc/loader_info.h b/inc/loader_info.h index 493cdf6..5a7e298 100644 --- a/inc/loader_info.h +++ b/inc/loader_info.h @@ -41,12 +41,16 @@ typedef struct _loader_info { int cpu_threshold_min; bool on_boot; bool global; + bool app_exists; } loader_info_t; +typedef void (*loader_info_foreach_cb)(loader_info_t *info, void *data); + GList *_loader_info_load(const char *path); void _loader_info_dispose(GList *info); int _loader_info_find_type(GList *info, const char *app_type, bool hwacc); int _loader_info_find_type_by_loader_name(GList *info, const char *loader_name); int *_loader_get_alternative_types(GList *info, int type, int *len); - - +int _loader_info_foreach(GList *info, loader_info_foreach_cb callback, + void *data); +bool _loader_info_exist_app_type(loader_info_t *info, const char *app_type); diff --git a/src/launchpad.c b/src/launchpad.c index 6497113..2d0e01e 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -87,6 +87,7 @@ typedef struct { int threshold_min; int cur_event; bool on_boot; + bool app_exists; } candidate_process_context_t; typedef struct { @@ -107,6 +108,11 @@ struct app_arg { char **argv; }; +struct app_info { + const char *type; + bool exists; +}; + static int __sys_hwacc; static GList *loader_info_list; static int user_slot_offset; @@ -118,7 +124,8 @@ static GHashTable *__pid_table; static candidate_process_context_t *__add_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *extra, int detection_method, int timeout_val, - int threshold_max, int threshold_min, bool on_boot); + int threshold_max, int threshold_min, bool on_boot, + bool app_exists); static int __remove_slot(int type, int loader_id); static int __add_default_slots(void); static gboolean __handle_idle_checker(gpointer data); @@ -1207,6 +1214,11 @@ static int __add_idle_checker(int detection_method, GList *cur) continue; } + if (!cpc->app_exists) { + iter = g_list_next(iter); + continue; + } + if (cpc->pid == CANDIDATE_NONE && (detection_method == EVENT_BOOTING || (cpc->detection_method & detection_method))) { @@ -1259,8 +1271,10 @@ static int __dispatch_cmd_add_loader(bundle *kb) cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid), add_slot_str, extra, METHOD_TIMEOUT | METHOD_VISIBILITY, 2000, - DEFAULT_CPU_THRESHOLD_MAX, DEFAULT_CPU_THRESHOLD_MIN, - false); + DEFAULT_CPU_THRESHOLD_MAX, + DEFAULT_CPU_THRESHOLD_MIN, + false, + true); __set_timer(cpc); return lid; } @@ -1354,6 +1368,86 @@ static candidate_process_context_t *__find_available_slot(const char *hwacc, return NULL; } +static void __update_slot(int type, bool app_exists) +{ + candidate_process_context_t *cpc; + unsigned long long total = 0; + unsigned long long idle = 0; + + cpc = __find_slot(type, PAD_LOADER_ID_STATIC); + if (!cpc) + return; + + cpc->app_exists = app_exists; + if (!cpc->app_exists) { + if (cpc->pid > 0) { + if (cpc->source > 0) + g_source_remove(cpc->source); + if (cpc->timer > 0) + g_source_remove(cpc->timer); + if (cpc->idle_checker > 0) + g_source_remove(cpc->idle_checker); + if (cpc->send_fd > 0) + close(cpc->send_fd); + _D("Dispose candidate process %d", cpc->pid); + __kill_process(cpc->pid); + __reset_slot(cpc); + } + } else { + if (cpc->pid == CANDIDATE_NONE && + cpc->idle_checker == 0) { + _get_cpu_idle(&total, &idle); + cpc->cpu_idle_time = idle; + cpc->cpu_total_time = total; + _D("Add idle checker"); + cpc->idle_checker = g_timeout_add(CPU_CHECKER_TIMEOUT, + __handle_idle_checker, + g_list_find(candidate_slot_list, cpc)); + } + } +} + +static void __foreach_loader_info(loader_info_t *info, void *data) +{ + struct app_info *ai = (struct app_info *)data; + bool exist; + + exist = _loader_info_exist_app_type(info, ai->type); + if (!exist) + return; + + info->app_exists = ai->exists; + __update_slot(info->type, info->app_exists); +} + +static int __dispatch_cmd_update_app_type(bundle *b) +{ + int r; + struct app_info info; + const char *is_installed; + + info.type = bundle_get_val(b, AUL_K_APP_TYPE); + if (!info.type) + return -1; + + is_installed = bundle_get_val(b, AUL_K_IS_INSTALLED); + if (is_installed && !strcmp(is_installed, "true")) + info.exists = true; + else + info.exists = false; + + _I("[LAUNCHPAD] type(%s), exists(%d)", info.type, info.exists); + + r = _loader_info_foreach(loader_info_list, __foreach_loader_info, + &info); + if (r != 0) { + _E("Failed to retrieve loader info"); + return -1; + } + + return 0; +} + static gboolean __handle_launch_event(gpointer data) { loader_context_t *lc = (loader_context_t *) data; @@ -1426,6 +1520,11 @@ static gboolean __handle_launch_event(gpointer data) __real_send(clifd, 0); clifd = -1; goto end; + case PAD_CMD_UPDATE_APP_TYPE: + __dispatch_cmd_update_app_type(kb); + close(clifd); + clifd = -1; + goto end; } INIT_PERF(kb); @@ -1536,7 +1635,8 @@ end: static candidate_process_context_t *__add_slot(int type, int loader_id, int caller_pid, const char *loader_path, const char *loader_extra, int detection_method, - int timeout_val, int threshold_max, int threshold_min, bool on_boot) + int timeout_val, int threshold_max, int threshold_min, + bool on_boot, bool app_exists) { candidate_process_context_t *cpc; int fd = -1; @@ -1570,6 +1670,7 @@ static candidate_process_context_t *__add_slot(int type, int loader_id, cpc->threshold_max = threshold_max; cpc->threshold_min = threshold_min; cpc->on_boot = on_boot; + cpc->app_exists = app_exists; fd = __listen_candidate_process(cpc->type, cpc->loader_id); if (fd == -1) { @@ -1764,7 +1865,10 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) cpc = __add_slot(LAUNCHPAD_TYPE_USER + user_slot_offset, PAD_LOADER_ID_DIRECT, 0, info->exe, NULL, 0, 0, - info->cpu_threshold_max, info->cpu_threshold_min, false); + info->cpu_threshold_max, + info->cpu_threshold_min, + false, + info->app_exists); if (cpc == NULL) return; @@ -1784,7 +1888,10 @@ static void __add_slot_from_info(gpointer data, gpointer user_data) PAD_LOADER_ID_STATIC, 0, info->exe, (char *)extra, info->detection_method, info->timeout_val, - info->cpu_threshold_max, info->cpu_threshold_min, info->on_boot); + info->cpu_threshold_max, + info->cpu_threshold_min, + info->on_boot, + info->app_exists); if (cpc == NULL) return; diff --git a/src/loader_info.c b/src/loader_info.c index 5d2e327..e48ffef 100644 --- a/src/loader_info.c +++ b/src/loader_info.c @@ -67,6 +67,7 @@ static loader_info_t *__create_loader_info() info->cpu_threshold_max = DEFAULT_CPU_THRESHOLD_MAX; info->cpu_threshold_min = DEFAULT_CPU_THRESHOLD_MIN; info->on_boot = true; + info->app_exists = false; return info; } @@ -442,5 +443,32 @@ int *_loader_get_alternative_types(GList *info, int type, int *len) return NULL; } +int _loader_info_foreach(GList *info, loader_info_foreach_cb callback, + void *data) +{ + GList *cur; + loader_info_t *i; + + if (!info || !callback) + return -1; + + cur = info; + while (cur) { + i = (loader_info_t *)cur->data; + callback(i, data); + cur = g_list_next(cur); + } + + return 0; +} + +bool _loader_info_exist_app_type(loader_info_t *info, const char *app_type) +{ + GList *list; + list = g_list_find_custom(info->app_types, app_type, __comp_str); + if (list) + return true; + return false; +} -- 2.7.4