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) {
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);
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)
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);
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)
}
__real_send(clifd, ret);
break;
+ case APP_PAUSE_BY_PID:
+ ret = _pause_app(pid, clifd);
+ break;
}
return ret;
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");
//__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);
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;
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);
APP_RESUME,
APP_RESUME_BY_PID,
APP_TERM_BY_PID,
+ APP_TERM_BY_PID_WITHOUT_RESTART,
APP_RESULT,
APP_START_RES,
APP_CANCEL,
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,
typedef enum _aul_type{
AUL_START,
AUL_RESUME,
- AUL_TERMINATE
+ AUL_TERMINATE,
+ AUL_TERMINATE_BGAPP,
+ AUL_PAUSE,
}aul_type;
/** AUL internal private key */
* 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);
/** @} */
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);
/** @} */
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;
+}
/**
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;
bundle_free(kbundle);
break;
+ case APP_PAUSE_BY_PID:
+ app_pause();
+ break;
+
default:
_E("no support packet");
}
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];
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];
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", ""},
"[usage] term_pid <pid>" },
{"term_req_pid", term_req_pid_test,"aul_subapp_terminate_request_pid test",
"[usage] term_req_pid <pid>" },
+ {"term_pid_without_restart", term_pid_without_restart_test, "aul_terminate_pid_without_restart test",
+ "[usage] term_pid_without_restart <pid>" },
+ {"term_bgapp", term_bgapp_pid_test, "aul_terminate_bgapp_pid test",
+ "[usage] term_bgapp <pid>" },
{"dbuslaunch", dbus_launch_test,"launch by dbus auto activation",
"[usage] term_pid <pid>" },
{"all",all_test,"test based on predefine scenario",
{"getpkg", get_pkg_func, "get package",
"[usage] getpkg <pkgname>"},
+ {"pause", pause_test,"aul_pause_app test",
+ "[usage] pause <pkgname>" },
+ {"pause_pid", pause_pid_test,"aul_pause_pid test",
+ "[usage] pause_pid <pid>" },
{"update_list", update_running_list, "update running list",
"[usage] update_list <appid> <app_path> <pid>"},
{"reload", reload_appinfo, "reload appinfo table",