From: Sangyoon Jang Date: Tue, 19 May 2015 07:35:13 +0000 (+0900) Subject: Launch service app on amd_session_agent, handle on-boot X-Git-Tag: accepted/tizen/common/20150521.125634^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a808f75a5d484161abe2f923773c94052c7f58c0;p=platform%2Fcore%2Fappfw%2Faul-1.git Launch service app on amd_session_agent, handle on-boot launch service app on amd_session_agent, not amd. all applications should be launched by proper session agent. when user appinfo initialized, amd sends launch request for applications which have on-boot attributes. handle on-boot when package installed. Change-Id: Iaf8fb1c69ff2006d3e835e9e4a981ef9847c4764 Signed-off-by: Sangyoon Jang --- diff --git a/am_daemon/amd_appinfo.c b/am_daemon/amd_appinfo.c index 67b0262..b7916b3 100644 --- a/am_daemon/amd_appinfo.c +++ b/am_daemon/amd_appinfo.c @@ -11,7 +11,7 @@ #include "amd_config.h" #include "simple_util.h" #include "amd_appinfo.h" - +#include "amd_launch.h" #define SERVICE_GROUP "Service" @@ -89,10 +89,23 @@ static void _free_user_appinfo(gpointer data) 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 __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *data) { struct appinfo *c; - gboolean r; struct user_appinfo *info = (struct user_appinfo *)data; char *exec; char *type; @@ -101,108 +114,115 @@ static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *d bool multiple; bool onboot; bool restart; + bool preload; pkgmgrinfo_app_hwacceleration hwacc; pkgmgrinfo_app_component component; pkgmgrinfo_permission_type permission; - int ret = -1; - bool preload; if (!handle) { _E("null app handle"); return -1; } - ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); - if (ret < 0) { + if (pkgmgrinfo_appinfo_get_appid(handle, &appid)) { _E("fail to get appinfo"); return -1; } g_hash_table_remove(info->tbl, appid); - c = calloc(1, sizeof(*c)); + c = calloc(1, sizeof(struct appinfo)); if (!c) { _E("create appinfo: %s", strerror(errno)); return -1; } - memset(c, 0, sizeof(struct appinfo)); - c->val[_AI_FILE] = strdup(appid); - if (!c->val[_AI_FILE]) { - _E("create appinfo: %s", strerror(errno)); + c->val[_AI_NAME] = strdup(appid); //TODO : + + if (pkgmgrinfo_appinfo_get_component(handle, &component)) { + _E("failed to get component"); _free_appinfo(c); return -1; } - c->val[_AI_NAME] = strdup(appid); //TODO : - - pkgmgrinfo_appinfo_get_component(handle, &component); - if(component == PMINFO_UI_APP) { + if (component == PMINFO_UI_APP) { c->val[_AI_COMP] = strdup("ui"); //TODO : - - r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple); - if(multiple == true) - c->val[_AI_MULTI] = strdup("true"); - else c->val[_AI_MULTI] = strdup("false"); - - r = pkgmgrinfo_appinfo_is_preload(handle, &preload); - if (preload == false) { - c->val[_AI_PRELOAD] = strdup("false"); - } else { - c->val[_AI_PRELOAD] = strdup("true"); + if (pkgmgrinfo_appinfo_is_multiple(handle, &multiple)) { + _E("failed to get multiple"); + _free_appinfo(c); + return -1; } - - if(gles == 0) { - c->val[_AI_HWACC] = strdup("NOT_USE"); - } else { - - r = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc); - if (hwacc == PMINFO_HWACCELERATION_USE_GL) { - c->val[_AI_HWACC] = strdup("USE"); - } else if (hwacc == PMINFO_HWACCELERATION_USE_SYSTEM_SETTING) { - c->val[_AI_HWACC] = strdup("SYS"); - } else { - c->val[_AI_HWACC] = strdup("NOT_USE"); - } + c->val[_AI_MULTI] = strdup(multiple ? "true" : "false"); + if (pkgmgrinfo_appinfo_is_preload(handle, &preload)) { + _E("failed to get preload"); + _free_appinfo(c); + return -1; + } + c->val[_AI_PRELOAD] = strdup(preload ? "true" : "false"); + if (pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc)) { + _E("failed to get hwacc"); + _free_appinfo(c); + return -1; } + c->val[_AI_HWACC] = strdup( + (gles == 0 || + hwacc == PMINFO_HWACCELERATION_NOT_USE_GL) ? + "NOT_USE" : + (hwacc == PMINFO_HWACCELERATION_USE_GL) ? + "USE" : + "SYS"); + c->val[_AI_ONBOOT] = strdup("false"); + c->val[_AI_RESTART] = strdup("false"); } else { c->val[_AI_COMP] = strdup("svc"); - - r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot); - if(onboot == true) - c->val[_AI_ONBOOT] = strdup("true"); - else c->val[_AI_ONBOOT] = strdup("false"); - - r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart); - if(restart == true) - c->val[_AI_RESTART] = strdup("true"); - else c->val[_AI_RESTART] = strdup("false"); + c->val[_AI_MULTI] = strdup("false"); + c->val[_AI_PRELOAD] = strdup("false"); + c->val[_AI_HWACC] = strdup("NOT_USE"); + if (pkgmgrinfo_appinfo_is_onboot(handle, &onboot)) { + _E("failed to get onboot"); + _free_appinfo(c); + return -1; + } + c->val[_AI_ONBOOT] = strdup(onboot ? "true" : "false"); + if (pkgmgrinfo_appinfo_is_autorestart(handle, &restart)) { + _E("failed to get restart"); + _free_appinfo(c); + return -1; + } + c->val[_AI_RESTART] = strdup(restart ? "true" : "false"); } - r = pkgmgrinfo_appinfo_get_exec(handle, &exec); + if (pkgmgrinfo_appinfo_get_exec(handle, &exec)) { + _E("failed to get exec"); + _free_appinfo(c); + return -1; + } c->val[_AI_EXEC] = strdup(exec); - r = pkgmgrinfo_appinfo_get_apptype(handle, &type); - if(strncmp(type, "capp", 4) == 0 ) { - c->val[_AI_TYPE] = strdup("rpm"); - } else if (strncmp(type, "c++app", 6) == 0 || strncmp(type, "ospapp", 6) == 0) { - c->val[_AI_TYPE] = strdup("tpk"); - } else if (strncmp(type, "webapp", 6) == 0) { - c->val[_AI_TYPE] = strdup("wgt"); + if (pkgmgrinfo_appinfo_get_apptype(handle, &type)) { + _E("failed to get apptype"); + _free_appinfo(c); + return -1; } + c->val[_AI_TYPE] = __convert_apptype(type); - r = pkgmgrinfo_appinfo_get_permission_type(handle, &permission); - if (permission == PMINFO_PERMISSION_SIGNATURE) { - c->val[_AI_PERM] = strdup("signature"); - } else if (permission == PMINFO_PERMISSION_PRIVILEGE) { - c->val[_AI_PERM] = strdup("privilege"); - } else { - c->val[_AI_PERM] = strdup("normal"); + if (pkgmgrinfo_appinfo_get_permission_type(handle, &permission)) { + _E("failed to get permission type"); + _free_appinfo(c); + return -1; + } + c->val[_AI_PERM] = strdup( + (permission == PMINFO_PERMISSION_SIGNATURE) ? + "signature" : + (permission == PMINFO_PERMISSION_PRIVILEGE) ? + "privilege" : + "normal"); + if (pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid)) { + _E("failed to get pkgid"); + _free_appinfo(c); + return -1; } - - r = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); c->val[_AI_PKGID] = strdup(pkgid); - c->val[_AI_STATUS] = strdup("installed"); SECURE_LOGD("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]); @@ -239,6 +259,19 @@ 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)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; @@ -262,6 +295,11 @@ static struct user_appinfo *_add_user_appinfo(uid_t uid) return NULL; } + if (uid != GLOBAL_USER) { + appinfo_foreach(uid, __handle_onboot, uid); + appinfo_foreach(GLOBAL_USER, __handle_onboot, uid); + } + _D("loaded appinfo table for uid %d", uid); return info; @@ -328,6 +366,7 @@ static void _appinfo_delete_on_event(uid_t uid, const char *pkgid) static void _appinfo_insert_on_event(uid_t uid, const char *pkgid) { appinfo_insert(uid, pkgid); + appinfo_foreach(uid, __handle_onboot, uid); } static int __package_event_cb(uid_t target_uid, int req_id, diff --git a/am_daemon/amd_launch.c b/am_daemon/amd_launch.c index 41968ca..ec8b7f5 100644 --- a/am_daemon/amd_launch.c +++ b/am_daemon/amd_launch.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -77,6 +78,7 @@ struct ktimer { 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_sdk_env(const char* appid, char* str) { char buf[MAX_LOCAL_BUFSZ]; @@ -196,85 +198,66 @@ static char **__create_argc_argv(bundle * kb, int *margc) *margc = argc; return argv; } -static void _do_exec(const char *cmd, const char *group, bundle *kb) -{ - gchar **argv; - gint argc; - char **b_argv; - int b_argc; - gboolean b; - int r; - - b = g_shell_parse_argv(cmd, &argc, &argv, NULL); - if (kb) { - b_argv = __create_argc_argv(kb, &b_argc); - b_argv[0] = strdup(argv[0]); - _prepare_exec(group, kb); - execv(b_argv[0], b_argv); - } - - if (b) { - _prepare_exec(group, kb); - execv(argv[0], argv); - } +static void __set_stime(bundle *kb) +{ + struct timeval tv; + char tmp[MAX_LOCAL_BUFSZ]; - _E("exec error: %s", strerror(errno)); - g_strfreev(argv); + gettimeofday(&tv, NULL); + snprintf(tmp, MAX_LOCAL_BUFSZ, "%ld/%ld", tv.tv_sec, tv.tv_usec); + bundle_add(kb, AUL_K_STARTTIME, tmp); } -int service_start(const char *group, const char *cmd, bundle *kb) +int _start_app_local(uid_t uid, char *appid) { - int r; - pid_t p; + int ret; + int pid; + struct appinfo* ai; + bundle *kb; + const char *app_path; + const char *pkg_type; + const char *hwacc; + char tmpbuf[MAX_PID_STR_BUFSZ]; - if (!group || !*group || !cmd || !*cmd) { - errno = EINVAL; - _E("service start: %s", strerror(errno)); - return -1; + kb = bundle_create(); + snprintf(tmpbuf, sizeof(tmpbuf), "%d", getpid()); + bundle_add_str(kb, AUL_K_CALLER_PID, tmpbuf); + snprintf(tmpbuf, sizeof(tmpbuf), "%d", uid); + bundle_add_str(kb, AUL_K_CALLER_UID, tmpbuf); + bundle_add_str(kb, AUL_K_APPID, appid); + + pid = _status_app_is_running(appid, uid); + if (pid > 0) { + ret = __nofork_processing(APP_START, pid, kb, -1); + bundle_free(kb); + return ret; } - p = fork(); - switch (p) { - case 0: /* child process */ - _do_exec(cmd, group, kb); - /* exec error */ - exit(0); - break; - case -1: - _E("service start: fork: %s", strerror(errno)); - r = -1; - break; - default: /* parent process */ - _D("child process: %d", p); - r = p; - break; + ai = appinfo_find(uid, appid); + if (ai == NULL) { + _E("cannot find appinfo of %s", appid); + return -1; } - return r; -} + hwacc = appinfo_get_value(ai, AIT_HWACC); + app_path = appinfo_get_value(ai, AIT_EXEC); + pkg_type = appinfo_get_value(ai, AIT_TYPE); -int _start_srv(const struct appinfo *ai, bundle *kb) -{ - int r; - const char *group; - const char *cmd; + __set_stime(kb); + bundle_add_str(kb, AUL_K_HWACC, hwacc); + bundle_add_str(kb, AUL_K_EXEC, app_path); + bundle_add_str(kb, AUL_K_PACKAGETYPE, pkg_type); - group = appinfo_get_filename(ai); + pid = app_agent_send_cmd(uid, APP_START, kb); - cmd = appinfo_get_value(ai, AIT_EXEC); - if (!cmd) { - _E("start service: '%s' has no exec", group); - return -1; - } + bundle_free(kb); - r = service_start( group, cmd, kb); - if (r == -1) { - _E("start service: '%s': failed", group); - return -1; - } + if (pid > 0) + _status_add_app_info_list( + appid, app_path, pid, LAUNCHPAD_PID, uid); - return 0; + return pid; } static void _free_kt(struct ktimer *kt) @@ -678,8 +661,8 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui } ai = appinfo_find(caller_uid, appid); - if (ai == NULL) { + _D("cannot find appinfo of %s", appid); __real_send(fd, -1); return -1; } @@ -741,44 +724,32 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui pkgmgrinfo_client_request_enable_external_pkg(pkgid); - if (componet && strncmp(componet, "ui", 2) == 0) { - multiple = appinfo_get_value(ai, AIT_MULTI); - if (!multiple || strncmp(multiple, "false", 5) == 0) { - pid = _status_app_is_running(appid, caller_uid); - } - - if (pid > 0) { - if (_status_get_app_info_status(pid) == STATUS_DYING) { - pid = -ETERMINATING; - } else if (caller_pid == pid) { - SECURE_LOGD("caller process & callee process is same.[%s:%d]", appid, pid); - pid = -ELOCALLAUNCH_ID; - } else { - if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) { - pid = ret; - } else { - delay_reply = 1; - } - } - } else if (cmd != APP_RESUME) { - 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); - pid = app_agent_send_cmd(caller_uid, cmd, kb); + multiple = appinfo_get_value(ai, AIT_MULTI); + if (!multiple || strncmp(multiple, "false", 5) == 0) { + pid = _status_app_is_running(appid, caller_uid); + } - } - } else if (componet && strncmp(componet, "svc", 3) == 0) { - pid = _status_app_is_running_v2(caller_uid,appid); - if (pid > 0) { + if (pid > 0) { + if (_status_get_app_info_status(pid) == STATUS_DYING) { + pid = -ETERMINATING; + } else if (caller_pid == pid) { + SECURE_LOGD("caller process & callee process is same.[%s:%d]", appid, pid); + pid = -ELOCALLAUNCH_ID; + } else { if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) { pid = ret; + } else { + delay_reply = 1; } - } else if (cmd != APP_RESUME) { - pid = service_start(appid, app_path, kb); } + } else if (cmd == APP_RESUME) { + _E("%s is not running", appid); } else { - _E("unkown application"); + 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); + pid = app_agent_send_cmd(caller_uid, cmd, kb); } if(!delay_reply) diff --git a/am_daemon/amd_launch.h b/am_daemon/amd_launch.h index 72b8fb7..c14fc56 100644 --- a/am_daemon/amd_launch.h +++ b/am_daemon/amd_launch.h @@ -31,7 +31,7 @@ int _resume_app(int pid, int clifd); int _term_app(int pid); int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd); int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd); +int _start_app_local(uid_t uid, char *appid); void service_release(const char *group); -int _start_srv(const struct appinfo *ai, bundle *kb); #endif /* __AUL_AMD_LAUNCH_H_ */ diff --git a/am_daemon/amd_main.c b/am_daemon/amd_main.c index add1d4b..848bc06 100644 --- a/am_daemon/amd_main.c +++ b/am_daemon/amd_main.c @@ -248,25 +248,6 @@ int __agent_dead_handler(uid_t user) _status_remove_app_info_list_with_uid(user); } -static void __start_cb(void *user_data, - const char *filename, const struct appinfo *ai) -{ - /*struct amdmgr *amd = user_data;*/ - const char *componet; - int r; - - componet = appinfo_get_value(ai, AIT_COMP); - - r = appinfo_get_boolean(ai, AIT_ONBOOT); - if (r == 1 && strncmp(componet, "svc", 3) == 0) - _start_srv(ai, NULL); -} - -static void _start_services() -{ - appinfo_foreach(GLOBAL_USER, __start_cb, NULL); -} - static int __init() { appinfo_init(); @@ -276,8 +257,6 @@ static int __init() __vconf_cb, NULL) != 0) _E("Unable to register callback for VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS\n"); - _start_services(); - return 0; } diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c index cc4bdee..caab765 100644 --- a/am_daemon/amd_request.c +++ b/am_daemon/amd_request.c @@ -190,7 +190,7 @@ static int __release_srv(uid_t caller_uid, const char *filename) if (r == 1) { /* Auto restart */ SECURE_LOGD("Auto restart set: '%s'", filename); - return _start_srv(ai, NULL); + return _start_app_local(ai, NULL); } service_release(filename);