From: Myungki Lee Date: Wed, 27 Jan 2016 10:47:40 +0000 (+0900) Subject: Add aul_app_get_all_running_app_info func X-Git-Tag: accepted/tizen/mobile/20160202.114600~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F30%2F57130%2F8;p=platform%2Fcore%2Fappfw%2Faul-1.git Add aul_app_get_all_running_app_info func This API use to get all running application list, including sub app. Change-Id: Icd4cd3df43acf752f10045d4df57f054cc3c4801 Signed-off-by: Myungki Lee --- diff --git a/include/aul.h b/include/aul.h index 8f26a41..9be56d8 100644 --- a/include/aul.h +++ b/include/aul.h @@ -626,9 +626,12 @@ int aul_terminate_pid_async(int pid); */ typedef struct _aul_app_info { int pid; /**< app's pid if running*/ - char* pkg_name; /**< application id */ - char* app_path; /**< application excutable path */ - char* appid; + char *pkg_name; /**< application id */ + char *app_path; /**< application excutable path */ + char *appid; + char *pkgid; /**< package id */ + int status; /**< app's status */ + int is_sub_app; /**< state whether sub app of app group */ } aul_app_info; /** @@ -694,7 +697,6 @@ int aul_app_is_running_for_uid(const char *appid, uid_t uid); * This API call iter_fn with each aul_app_info of running apps when running application is found. * @par Purpose: * If you want to get running application list, use this API - * This API give you running applications which has SLP desktop file. * @par Typical use case: * In general, this API is used by task manager appllication. (running application list viewer) * @@ -733,6 +735,51 @@ int aul_app_get_running_app_info(aul_app_info_iter_fn iter_fn, void *data); /** * @par Description: + * This API use to get all running application list, including sub app. + * This API call iter_fn with each aul_app_info of running apps when running application is found. + * @par Purpose: + * If you want to get all running application list, use this API + * @par Typical use case: + * In general, this API is used by task manager application. (running application list viewer) + * + * @param[in] iter_fn iterator function + * @param[in] data user-supplied data for iter_fn + * @return 0 if success, negative value(<0) if fail + * @retval AUL_R_OK - success + * @retval AUL_R_ERROR - internal error + * + * @code + * #include + * + * int iterfunc_status(const aul_app_info *info, void *data) + * { + * printf("\t==========================\n"); + * printf("\t pid: %d\n", info->pid); + * printf("\t appid: %s\n", info->appid); + * printf("\t app_path: %s\n", info->app_path); + * printf("\t pkgid: %s\n", info->pkgid); + * printf("\t status: %d\n", info->status); + * printf("\t is_sub_app : %d\n", info->is_sub_app); + * printf("\t==========================\n"); + * return 0; + * } + * + * int iterate_running_apps() + * { + * return aul_app_get_all_running_app_info(iterfunc_status,NULL); + * } + * + * @endcode + * @remark + * This API should use if you want to know running application which has desktop files. + * If you want to get all process list, you must iterate process information by using proc filesystem + * Or, If you want to get all window list, you must iterate XWindows by using XWindow APIs + * This API is only available in User Session. + */ +int aul_app_get_all_running_app_info(aul_app_info_iter_fn iter_fn, void *data); + +/** + * @par Description: * This API get application package name by pid * @par Purpose: * If you want to get package name of running application, use this API diff --git a/include/aul_cmd.h b/include/aul_cmd.h index fd6185f..7d7aa79 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -79,6 +79,8 @@ enum app_cmd { AMD_RELOAD_APPINFO, /* reserved for AMD Agent */ AGENT_DEAD_SIGNAL, + + APP_ALL_RUNNING_INFO, APP_CMD_MAX }; diff --git a/src/pkginfo.c b/src/pkginfo.c index accd99b..ee009b3 100644 --- a/src/pkginfo.c +++ b/src/pkginfo.c @@ -94,6 +94,49 @@ API int aul_app_get_running_app_info(aul_app_info_iter_fn enum_fn, info.pid = atoi(strtok_r(token, ":", &saveptr2)); info.appid = strtok_r(NULL, ":", &saveptr2); info.app_path = strtok_r(NULL, ":", &saveptr2); + info.pkgid = strtok_r(NULL, ":", &saveptr2); + info.status = atoi(strtok_r(NULL, ":", &saveptr2)); + info.is_sub_app = atoi(strtok_r(NULL, ":", &saveptr2)); + info.pkg_name = strdup(info.appid); + + enum_fn(&info, user_param); + free(info.pkg_name); + } + + free(pkt); + + return AUL_R_OK; +} + +API int aul_app_get_all_running_app_info(aul_app_info_iter_fn enum_fn, + void *user_param) +{ + app_pkt_t *pkt; + char *saveptr1; + char *saveptr2; + char *token; + char *pkt_data; + aul_app_info info; + + memset(&info, 0, sizeof(info)); + if (enum_fn == NULL) + return AUL_R_EINVAL; + + pkt = aul_sock_send_raw_with_pkt_reply(AUL_UTIL_PID, getuid(), + APP_ALL_RUNNING_INFO, NULL, 0, AUL_SOCK_NONE); + if (pkt == NULL) + return AUL_R_ERROR; + + for (pkt_data = (char *)pkt->data; ; pkt_data = NULL) { + token = strtok_r(pkt_data, ";", &saveptr1); + if (token == NULL) + break; + info.pid = atoi(strtok_r(token, ":", &saveptr2)); + info.appid = strtok_r(NULL, ":", &saveptr2); + info.app_path = strtok_r(NULL, ":", &saveptr2); + info.pkgid = strtok_r(NULL, ":", &saveptr2); + info.status = atoi(strtok_r(NULL, ":", &saveptr2)); + info.is_sub_app = atoi(strtok_r(NULL, ":", &saveptr2)); info.pkg_name = strdup(info.appid); enum_fn(&info, user_param); diff --git a/tool/aul_test.c b/tool/aul_test.c index 3010d08..15badd7 100644 --- a/tool/aul_test.c +++ b/tool/aul_test.c @@ -255,6 +255,26 @@ int get_allpkg_test() return aul_app_get_running_app_info(iterfunc, NULL); } +int iterfunc_status(const aul_app_info *info, void *data) +{ + printf("\t==========================\n"); + printf("\t pid: %d\n", info->pid); + printf("\t appid: %s\n", info->appid); + printf("\t app_path: %s\n", info->app_path); + printf("\t pkgid: %s\n", info->pkgid); + printf("\t status: %d\n", info->status); + printf("\t is_sub_app : %d\n", info->is_sub_app); + printf("\t==========================\n"); + + return 0; +} + +int get_all_app_test() +{ + static int num = 0; + printf("[aul_app_get_all_running_app_info %d test] \n", num++); + return aul_app_get_all_running_app_info(iterfunc_status, NULL); +} int get_app_bypid_test() { int pid = 0; @@ -564,6 +584,8 @@ static test_func_t test_func[] = { "[usage] is_run "}, {"getallpkg", get_allpkg_test, "aul_app_get_running_app_info test", "[usage] getallpkg all"}, + {"getallappstatus", get_all_app_test, "aul_app_get_all_running_app_info test", + "[usage] getallappstatus "}, {"get_app_bypid", get_app_bypid_test, "aul_app_get_appid_bypid test", "[usage] get_app_bypid "}, {"get_pkg_bypid", get_pkg_bypid_test, "aul_app_get_pkgid_bypid test",