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 <s89.jang@samsung.com>
#include "amd_config.h"
#include "simple_util.h"
#include "amd_appinfo.h"
-
+#include "amd_launch.h"
#define SERVICE_GROUP "Service"
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;
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]);
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;
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;
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,
#include <stdlib.h>
#include <stdio.h>
#include <sys/prctl.h>
+#include <sys/time.h>
#include <pkgmgr-info.h>
#include <poll.h>
#include <privacy_manager_client.h>
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];
*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)
}
ai = appinfo_find(caller_uid, appid);
-
if (ai == NULL) {
+ _D("cannot find appinfo of %s", appid);
__real_send(fd, -1);
return -1;
}
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)
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_ */
_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();
__vconf_cb, NULL) != 0)
_E("Unable to register callback for VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS\n");
- _start_services();
-
return 0;
}
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);