From 46384ab9ea5bf4c0b326f81b5bf387223e1c5904 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 16 May 2016 18:13:08 +0900 Subject: [PATCH] Add APIs to get the status of an application - Add new APIs aul_app_get_status() aul_app_get_status_for_uid() Change-Id: I9b2441f1d56e4d5a12c9b05b10a5387ee58ee9e5 Signed-off-by: Hwankyu Jhun --- include/aul.h | 57 ++++++++++++++++++++++++++++++++++++++ include/aul_cmd.h | 1 + src/status.c | 31 +++++++++++++++++++-- tool/aul_test.c | 82 ++++++++++++++++++++----------------------------------- 4 files changed, 116 insertions(+), 55 deletions(-) diff --git a/include/aul.h b/include/aul.h index 2f8f1e9..f35a81c 100644 --- a/include/aul.h +++ b/include/aul.h @@ -1813,6 +1813,63 @@ int aul_app_get_status_bypid(int pid); int aul_app_get_status_bypid_for_uid(int pid, uid_t uid); /** + * @par Description: + * This API gets the status of specified application id. + * @par Purpose: + * This API's purpose is to get the status of the application. + * + * @param[in] appid application ID + * @return 0 or greater if success, nagative value if fail + * @retval STATUS_LAUNCHING + * @retval STATUS_FOCUS + * @retval STATUS_VISIBLE + * @retval STATUS_BG + * @retval STATUS_DYING + * @retval STATUS_NORESTART + * @see + * aul_status_update + * @code + * #include + * + * int func(void) + * { + * int status; + * + * status = aul_app_get_status("org.tizen.helloworld"); + * if (status == STATUS_FOCUS) + * printf("org.tizen.helloworld has focus"); + * + * return 0; + * } + * + * @endcode + * @remark + * This API is only available in User Session. + */ +int aul_app_get_status(const char *appid); + +/** + * @par Description: + * This API gets the status of specified application id. + * @par Purpose: + * This API's purpose is to get the status of the application + * + * @param[in] appid application ID + * @param[in] uid User ID + * @return 0 or greater if success, nagative value if fail + * @retval STATUS_LAUNCHING + * @retval STATUS_FOCUS + * @retval STATUS_VISIBLE + * @retval STATUS_BG + * @retval STATUS_DYING + * @retval STATUS_NORESTART + * + * @remark + * This API is only available to System user. + */ +int aul_app_get_status_for_uid(const char *appid, uid_t uid); + +/** * @par Description * This API sets callback function that on application status changed. * @par Purpose: diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 1fb6fc0..7eff16d 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -92,6 +92,7 @@ enum app_cmd { APP_SET_PROCESS_GROUP, APP_PREPARE_CANDIDATE_PROCESS, APP_TERM_BY_PID_SYNC, + APP_GET_STATUS_BY_APPID, APP_CMD_MAX }; diff --git a/src/status.c b/src/status.c index 9e570ad..6089f2d 100644 --- a/src/status.c +++ b/src/status.c @@ -61,12 +61,12 @@ API int aul_status_update(int status) return ret; } -API int aul_app_get_status_bypid(int pid) +API int aul_app_get_status_bypid(int pid) { return aul_app_get_status_bypid_for_uid(pid, getuid()); } -API int aul_app_get_status_bypid_for_uid(int pid, uid_t uid) +API int aul_app_get_status_bypid_for_uid(int pid, uid_t uid) { int ret; @@ -79,6 +79,33 @@ API int aul_app_get_status_bypid_for_uid(int pid, uid_t uid) return ret; } +API int aul_app_get_status(const char *appid) +{ + return aul_app_get_status_for_uid(appid, getuid()); +} + +API int aul_app_get_status_for_uid(const char *appid, uid_t uid) +{ + int ret; + bundle *kb; + + if (appid == NULL) + return AUL_R_EINVAL; + + kb = bundle_create(); + if (kb == NULL) { + _E("out of memory"); + return AUL_R_ERROR; + } + + bundle_add(kb, AUL_K_APPID, appid); + ret = app_send_cmd_for_uid(AUL_UTIL_PID, uid, + APP_GET_STATUS_BY_APPID, kb); + bundle_free(kb); + + return ret; +} + API int aul_add_status_local_cb(int (*func)(int status, void *data), void *data) { app_status_cb_info_t *cb = app_status_cb; diff --git a/tool/aul_test.c b/tool/aul_test.c index 42c52bb..ae50976 100644 --- a/tool/aul_test.c +++ b/tool/aul_test.c @@ -618,65 +618,37 @@ static int term_pid_sync_test_for_uid() return aul_terminate_pid_sync_for_uid(apn_pid, atoi(gargv[3])); } -/* -static int set_pkg_func() -{ - char* pkgname; - char* apppath; - char* appname; - char query[QUERY_LEN]; - - pkgname = gargv[2]; - apppath = gargv[3]; - - appname = strrchr(apppath,'/')+1; - snprintf(ai.app_icon_path, PATH_LEN, "aul_test_icon_path/%d",getpid()); - snprintf(ai.desktop_path, PATH_LEN, - "aul_test_desktop_path/%d",getpid()); - - snprintf (query, sizeof(query), "insert into "TABLE_MENU"(\ - pkg_name,\ - app_path,\ - app_name,\ - app_icon_path,\ - desktop_path)\ - values ('%s', '%s', '%s', '%s', '%s')", - pkgname, - apppath, - appname, - record->app_icon_path, - record->desktop_path, - ); - - // TODO: record_add is not supported anymore; use AIL - if (record_add(ADD_ICON, &ai)){ - printf("set pkg success\n"); - return 0; - } - else{ - printf("set pkg fail\n"); - return -1; - } +static int get_status_test(void) +{ + static int num; + int ret; + + printf("[aul_app_get_status %d test] %s \n", num++, gargv[2]); + + ret = aul_app_get_status(gargv[2]); + printf("appid: %s, status: %d", gargv[2], ret); + if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART) + printf("(%s)", status_text[ret]); + printf("\n"); + + return 0; } -static int del_pkg_func() +static int get_status_test_for_uid(void) { - app_info ai; + static int num; + int ret; - memset(&ai, 0, sizeof(app_info)); - snprintf(ai.pkg_name, NAME_LEN, "%s", gargv[2]); + printf("[aul_app_get_status %d test] %s \n", num++, gargv[2]); - // TODO: record_add is not supported anymore; use AIL - if(record_delete(DELETE_MENU, &ai)){ - printf("del pkg success\n"); - return 0; - } - else { - printf("del pkg fail\n"); - return -1; - } + ret = aul_app_get_status_for_uid(gargv[2], atoi(gargv[3])); + printf("appid: %s, uid: %d, status: %d", gargv[2], atoi(gargv[3]), ret); + if (ret >= STATUS_LAUNCHING && ret <= STATUS_NORESTART) + printf("(%s)", status_text[ret]); + printf("\n"); + + return 0; } -*/ static int test_regex() { @@ -805,6 +777,10 @@ static test_func_t test_func[] = { "[usage] term_pid_sync "}, {"term_pid_sync_for_uid", term_pid_sync_test_for_uid, "aul_terminate_pid_sync_for_uid test", "[usage] term_pid_sync_for_uid "}, + {"get_status", get_status_test, "aul_app_get_status test", + "[usage] get_status "}, + {"get_status_for_uid", get_status_test_for_uid, "aul_app_get_status_for_uid test", + "[usage] get_status_for_uid "}, }; int callfunc(char *testname) -- 2.7.4