From: Sangyoon Jang Date: Mon, 1 Jun 2015 12:16:32 +0000 (+0900) Subject: Add some api from Tizen 2.4 X-Git-Tag: submit/tizen/20150604.015241^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c37da426b3cf42ff13adfaf4edf452b102318a3d;p=platform%2Fcore%2Fappfw%2Faul-1.git Add some api from Tizen 2.4 added: aul_terminate_bgapp_pid aul_terminate_pid_without_restart aul_pause_app aul_pause_pid Change-Id: I9ebae51e8c55a4678064debc310e563585cf63d3 Signed-off-by: Sangyoon Jang --- diff --git a/am_daemon/amd_appinfo.c b/am_daemon/amd_appinfo.c index a34db67..20b9968 100644 --- a/am_daemon/amd_appinfo.c +++ b/am_daemon/amd_appinfo.c @@ -580,6 +580,26 @@ const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type) 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) { diff --git a/am_daemon/amd_appinfo.h b/am_daemon/amd_appinfo.h index 053bb3d..3e43dc0 100644 --- a/am_daemon/amd_appinfo.h +++ b/am_daemon/amd_appinfo.h @@ -28,6 +28,7 @@ int appinfo_insert(uid_t uid, const char *pkgid); const 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); diff --git a/am_daemon/amd_launch.c b/am_daemon/amd_launch.c index 492ff41..1354df3 100644 --- a/am_daemon/amd_launch.c +++ b/am_daemon/amd_launch.c @@ -409,19 +409,114 @@ int _resume_app(int pid, int clifd) return ret; } -int _term_app(int pid) +int _pause_app(int pid, int clifd) { int dummy; - if (__app_send_raw - (pid, APP_TERM_BY_PID, (unsigned char *)&dummy, sizeof(int)) < 0) { + int ret; + if ((ret = + __app_send_raw_with_delay_reply(pid, APP_PAUSE_BY_PID, (unsigned char *)&dummy, + sizeof(int))) < 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; + } + } + _D("pause done"); + + if (ret > 0) + __set_reply_handler(ret, pid, clifd, APP_PAUSE_BY_PID); + + return ret; +} + +int _term_app(int pid, int clifd) +{ + int dummy; + int ret; + + if ((ret = __app_send_raw_with_delay_reply(pid, APP_TERM_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\n", pid); + _E("fail to killing - %d", pid); return -1; } } - _D("term done\n"); + _D("term done"); + + 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, sizeof(int))) < 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) +{ + return _term_app(pid, clifd); + /* FIXME: app group feature should be merged */ +#if 0 + 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]); + 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; +#endif } int _fake_launch_app(int cmd, int pid, bundle *kb, int clifd) diff --git a/am_daemon/amd_launch.h b/am_daemon/amd_launch.h index c14fc56..cf2bb8e 100644 --- a/am_daemon/amd_launch.h +++ b/am_daemon/amd_launch.h @@ -28,7 +28,10 @@ int _send_to_sigkill(int pid); int _resume_app(int pid, int clifd); -int _term_app(int pid); +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 _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); diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c index 124e168..e6f216d 100644 --- a/am_daemon/amd_request.c +++ b/am_daemon/amd_request.c @@ -143,7 +143,11 @@ static int __app_process_by_pid(int cmd, ret = _resume_app(pid, clifd); break; case APP_TERM_BY_PID: - ret = _term_app(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) @@ -160,6 +164,9 @@ static int __app_process_by_pid(int cmd, } __real_send(clifd, ret); break; + case APP_PAUSE_BY_PID: + ret = _pause_app(pid, clifd); + break; } return ret; @@ -254,12 +261,12 @@ static gboolean __request_handler(gpointer data) int ret = -1; int free_pkt = 1; char *appid; - /*char *app_path; - char *tmp_pid;*/ + char *term_pid; int pid; bundle *kb = NULL; item_pkt_t *item; pkt_t *pkt_uid; + const struct appinfo *ai; if ((pkt = __app_recv_raw(fd, &clifd, &cr)) == NULL) { _E("recv error"); @@ -304,11 +311,48 @@ static gboolean __request_handler(gpointer data) //__real_send(clifd, ret); close(clifd); break; - case APP_TERM_BY_PID: + case APP_PAUSE: + kb = bundle_decode(pkt->data, pkt->len); + appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME); + 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); + } + break; case APP_RESUME_BY_PID: - case APP_KILL_BY_PID: + case APP_PAUSE_BY_PID: case APP_TERM_REQ_BY_PID: + kb = bundle_decode(pkt->data, pkt->len); + appid = (char *)bundle_get_val(kb, AUL_K_APPID); + ret = __app_process_by_pid(pkt->cmd, appid, &cr, clifd); + break; + case APP_TERM_BY_PID_WITHOUT_RESTART: case APP_TERM_BY_PID_ASYNC: + /* TODO: check caller's privilege */ + kb = bundle_decode(pkt->data, pkt->len); + 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"); + ret = __app_process_by_pid(pkt->cmd, term_pid, &cr, clifd); + } else { + ret = -1; + close(clifd); + } + break; + case APP_TERM_BY_PID: + case APP_KILL_BY_PID: + /* TODO: check caller's privilege */ + kb = bundle_decode(pkt->data, pkt->len); + appid = (char *)bundle_get_val(kb, AUL_K_APPID); + ret = __app_process_by_pid(pkt->cmd, appid, &cr, clifd); + break; + case APP_TERM_BGAPP_BY_PID: + /* TODO: check caller's privilege */ kb = bundle_decode(pkt->data, pkt->len); appid = (char *)bundle_get_val(kb, AUL_K_APPID); ret = __app_process_by_pid(pkt->cmd, appid, &cr, clifd); diff --git a/am_daemon/amd_status.c b/am_daemon/amd_status.c index baed7b3..c0eb78b 100644 --- a/am_daemon/amd_status.c +++ b/am_daemon/amd_status.c @@ -172,6 +172,21 @@ int _status_app_is_running(char *appid, uid_t uid) 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) { GSList *iter = NULL; diff --git a/am_daemon/amd_status.h b/am_daemon/amd_status.h index b3cbeea..aed3ca6 100644 --- a/am_daemon/amd_status.h +++ b/am_daemon/amd_status.h @@ -31,6 +31,7 @@ int _status_get_app_info_status(int pid); int _status_send_running_appinfo(int fd); int _status_app_is_running(char *appid, uid_t uid); int _status_app_is_running_v2(char *appid, uid_t caller_uid); +char *_status_app_get_appid_bypid(int pid); int _status_send_running_appinfo_v2(int fd); //depcrecated int _status_get_appid_bypid(int fd, int pid); diff --git a/include/app_sock.h b/include/app_sock.h index e0488a3..04b4060 100644 --- a/include/app_sock.h +++ b/include/app_sock.h @@ -34,6 +34,7 @@ enum app_cmd { APP_RESUME, APP_RESUME_BY_PID, APP_TERM_BY_PID, + APP_TERM_BY_PID_WITHOUT_RESTART, APP_RESULT, APP_START_RES, APP_CANCEL, @@ -53,6 +54,9 @@ enum app_cmd { 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, /* for special purpose */ AMD_RELOAD_APPINFO, diff --git a/include/aul.h b/include/aul.h index 30598c5..aab060d 100644 --- a/include/aul.h +++ b/include/aul.h @@ -125,7 +125,9 @@ enum app_status { typedef enum _aul_type{ AUL_START, AUL_RESUME, - AUL_TERMINATE + AUL_TERMINATE, + AUL_TERMINATE_BGAPP, + AUL_PAUSE, }aul_type; /** AUL internal private key */ @@ -622,6 +624,8 @@ int aul_resume_pid(int pid); * If you have not the permission, this API return AUL_R_ERROR. \n */ int aul_terminate_pid(int pid); +int aul_terminate_bgapp_pid(int pid); +int aul_terminate_pid_without_restart(int pid); int aul_terminate_pid_async(int pid); /** @} */ @@ -1648,6 +1652,8 @@ int aul_is_subapp(void); typedef int (*data_control_provider_handler_fn) (bundle *b, int request_id, void *data); int aul_set_data_control_provider_cb(data_control_provider_handler_fn handler); int aul_unset_data_control_provider_cb(void); +int aul_pause_app(const char *appid); +int aul_pause_pid(int pid); int aul_reload_appinfo(void); /** @} */ diff --git a/src/launch.c b/src/launch.c index 9243675..e9ecd06 100644 --- a/src/launch.c +++ b/src/launch.c @@ -101,7 +101,17 @@ static int app_terminate() return 0; } +static int bgapp_terminate(void) +{ + __call_aul_handler(AUL_TERMINATE_BGAPP, NULL); + return 0; +} +static int app_pause(void) +{ + __call_aul_handler(AUL_PAUSE, NULL); + return 0; +} /** @@ -445,6 +455,10 @@ int aul_sock_handler(int fd) app_terminate(); break; + case APP_TERM_BGAPP_BY_PID: + bgapp_terminate(); + break; + case APP_TERM_REQ_BY_PID: /* run in callee */ app_subapp_terminate_request(); break; @@ -470,6 +484,10 @@ int aul_sock_handler(int fd) bundle_free(kbundle); break; + case APP_PAUSE_BY_PID: + app_pause(); + break; + default: _E("no support packet"); } @@ -625,6 +643,32 @@ SLPAPI int aul_terminate_pid(int pid) return ret; } +SLPAPI int aul_terminate_bgapp_pid(int pid) +{ + char pkgname[MAX_PID_STR_BUFSZ]; + int ret; + + if (pid <= 0) + return AUL_R_EINVAL; + + snprintf(pkgname, MAX_PID_STR_BUFSZ, "%d", pid); + ret = app_request_to_launchpad(APP_TERM_BGAPP_BY_PID, pkgname, NULL); + return ret; +} + +SLPAPI int aul_terminate_pid_without_restart(int pid) +{ + char pkgname[MAX_PID_STR_BUFSZ]; + int ret; + + if (pid <= 0) + return AUL_R_EINVAL; + + snprintf(pkgname, MAX_PID_STR_BUFSZ, "%d", pid); + ret = app_request_to_launchpad(APP_TERM_BY_PID_WITHOUT_RESTART, pkgname, NULL); + return ret; +} + SLPAPI int aul_terminate_pid_async(int pid) { char pkgname[MAX_PID_STR_BUFSZ]; @@ -663,6 +707,30 @@ SLPAPI int aul_unset_data_control_provider_cb(void) return 0; } +SLPAPI int aul_pause_app(const char *appid) +{ + int ret; + + if (appid == NULL) + return AUL_R_EINVAL; + + ret = app_request_to_launchpad(APP_PAUSE, appid, NULL); + return ret; +} + +SLPAPI int aul_pause_pid(int pid) +{ + char app_pid[MAX_PID_STR_BUFSZ]; + int ret; + + if (pid <= 0) + return AUL_R_EINVAL; + + snprintf(app_pid, MAX_PID_STR_BUFSZ, "%d", pid); + ret = app_request_to_launchpad(APP_PAUSE_BY_PID, app_pid, NULL); + return ret; +} + SLPAPI int aul_reload_appinfo(void) { char pkgname[MAX_PID_STR_BUFSZ]; diff --git a/test/aul_test.c b/test/aul_test.c index 709cabb..80bd715 100644 --- a/test/aul_test.c +++ b/test/aul_test.c @@ -166,6 +166,36 @@ int term_req_pid_test() return aul_subapp_terminate_request_pid(apn_pid); } +int term_pid_without_restart_test(void) +{ + static int num = 0; + printf("[aul_term_pid_without_restart %d test] %d \n", num++, apn_pid); + return aul_terminate_pid_without_restart(apn_pid); +} + +int term_bgapp_pid_test(void) +{ + static int num = 0; + printf("[aul_term_pid_without_restart %d test] %d \n", num++, apn_pid); + return aul_terminate_bgapp_pid(apn_pid); +} + +int pause_test(void) +{ + static int num = 0; + + printf("[aul_pause_app %d test] %s \n", num++, gargv[2]); + return aul_pause_app(gargv[2]); +} + +int pause_pid_test(void) +{ + static int num = 0; + + printf("[aul_pause_pid %d test] %d \n", num++, apn_pid); + return aul_pause_pid(apn_pid); +} + static test_func_t scn_func[] = { {"n", launch_test, "launch_test", ""}, {"n", launch_test, "launch_test", ""}, @@ -587,6 +617,10 @@ static test_func_t test_func[] = { "[usage] term_pid " }, {"term_req_pid", term_req_pid_test,"aul_subapp_terminate_request_pid test", "[usage] term_req_pid " }, + {"term_pid_without_restart", term_pid_without_restart_test, "aul_terminate_pid_without_restart test", + "[usage] term_pid_without_restart " }, + {"term_bgapp", term_bgapp_pid_test, "aul_terminate_bgapp_pid test", + "[usage] term_bgapp " }, {"dbuslaunch", dbus_launch_test,"launch by dbus auto activation", "[usage] term_pid " }, {"all",all_test,"test based on predefine scenario", @@ -633,6 +667,10 @@ static test_func_t test_func[] = { {"getpkg", get_pkg_func, "get package", "[usage] getpkg "}, + {"pause", pause_test,"aul_pause_app test", + "[usage] pause " }, + {"pause_pid", pause_pid_test,"aul_pause_pid test", + "[usage] pause_pid " }, {"update_list", update_running_list, "update running list", "[usage] update_list "}, {"reload", reload_appinfo, "reload appinfo table",