From 4b35c74f2c179b1c2e28cbf1128e4b217f01b24f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 31 Aug 2016 17:45:47 +0900 Subject: [PATCH] Add asynchronous API to resume an application - Add APIs aul_resume_pid_async() aul_resume_pid_async_for_uid() Change-Id: I662927086cfcb0ad8b2682f5682e54a9414132f4 Signed-off-by: Hwankyu Jhun --- include/aul.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/aul_cmd.h | 1 + src/launch.c | 20 ++++++++++++++++++++ tool/aul_test.c | 20 ++++++++++++++++++++ 4 files changed, 94 insertions(+) diff --git a/include/aul.h b/include/aul.h index fb60307..26df2b3 100644 --- a/include/aul.h +++ b/include/aul.h @@ -2847,6 +2847,59 @@ int aul_app_get_last_caller_pid(int pid); */ int aul_app_get_last_caller_pid_for_uid(int pid, uid_t uid); +/** + * @par Description: + * This API trigger to resume application asynchronously. + * If the application is running, this API send a resume event to the App. + * If the application is not running, this API return AUL_R_ERROR. + * Although the application is running, if the application cannot receive resume event, + * AUL try to raise the application's default windows. + * @par Purpose: + * This API is for caller. + * This API's purpose is to send resume event. + * @par Typical use case: + * In multiple application model, If you want to only resume specific application, Use this API + * + * @param[in] pid application's pid to be resumed + * @return 0 if success, negative value(<0) if fail + * @retval AUL_R_OK - success + * @retval AUL_R_EINVAL - invaild pid + * @retval AUL_R_ECOM - internal AUL IPC error + * @retval AUL_R_ERROR - general error (include application is not running) + * @warning This API need to require root or inhouse permisssion \n + * If you have not the permission, this API return AUL_R_ERROR. \n + * @remark + * This API is only available to User Session. + */ +int aul_resume_pid_async(int pid); + +/** + * @par Description: + * This API trigger to resume application asynchronously. + * If the application is running, this API send a resume event to the App. + * If the application is not running, this API return AUL_R_ERROR. + * Although the application is running, if the application cannot receive resume event, + * AUL try to raise the application's default windows. + * @par Purpose: + * This API is for caller. + * This API's purpose is to send resume event. + * @par Typical use case: + * In multiple application model, If you want to only resume specific application, Use this API + * + * @param[in] pid application's pid to be resumed + * @param[in] uid User ID + * @return 0 if success, negative value(<0) if fail + * @retval AUL_R_OK - success + * @retval AUL_R_EINVAL - invaild pid + * @retval AUL_R_ECOM - internal AUL IPC error + * @retval AUL_R_ERROR - general error (include application is not running) + * @warning This API need to require root or inhouse permisssion \n + * If you have not the permission, this API return AUL_R_ERROR. \n + * @remark + * This API is only available to System user. + */ +int aul_resume_pid_async_for_uid(int pid, uid_t uid); + #ifdef __cplusplus } #endif diff --git a/include/aul_cmd.h b/include/aul_cmd.h index e566ddf..59a86f9 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -107,6 +107,7 @@ enum app_cmd { APP_GET_STATUS_BY_APPID, APP_GET_LAST_CALLER_PID, APP_TERM_BY_PID_SYNC_WITHOUT_RESTART, + APP_RESUME_BY_PID_ASYNC, APP_CMD_MAX }; diff --git a/src/launch.c b/src/launch.c index c19c2ba..ed538d8 100644 --- a/src/launch.c +++ b/src/launch.c @@ -328,6 +328,7 @@ int app_request_to_launchpad_for_uid(int cmd, const char *appid, bundle *kb, uid case APP_OPEN: case APP_RESUME: case APP_RESUME_BY_PID: + case APP_RESUME_BY_PID_ASYNC: ret = __app_resume_local(); break; default: @@ -1067,3 +1068,22 @@ API int aul_terminate_pid_sync_for_uid(int pid, uid_t uid) return ret; } +API int aul_resume_pid_async(int pid) +{ + return aul_resume_pid_async_for_uid(pid, getuid()); +} + +API int aul_resume_pid_async_for_uid(int pid, uid_t uid) +{ + char pid_str[MAX_PID_STR_BUFSZ]; + int ret; + + if (pid <= 0) + return AUL_R_EINVAL; + + snprintf(pid_str, sizeof(pid_str), "%d", pid); + ret = app_request_to_launchpad_for_uid(APP_RESUME_BY_PID_ASYNC, + pid_str, NULL, uid); + return ret; +} + diff --git a/tool/aul_test.c b/tool/aul_test.c index f552064..ba4fc62 100644 --- a/tool/aul_test.c +++ b/tool/aul_test.c @@ -666,6 +666,22 @@ static int get_last_caller_pid_test_for_uid(void) return aul_app_get_last_caller_pid_for_uid(apn_pid, atoi(gargv[3])); } +static int resume_pid_async_test(void) +{ + static int num; + + printf("aul_resume_pid_async %d test] %d \n", num++, apn_pid); + return aul_resume_pid_async(apn_pid); +} + +static int resume_pid_async_test_for_uid(void) +{ + static int num; + + printf("aul_resume_pid_async_for_uid %d test] %d \n", num++, apn_pid); + return aul_resume_pid_async_for_uid(apn_pid, atoi(gargv[3])); +} + static int test_regex() { char *token; @@ -801,6 +817,10 @@ static test_func_t test_func[] = { "[usage] get_last_caller_pid "}, {"get_last_caller_pid_for_uid", get_last_caller_pid_test_for_uid, "aul_app_get_last_caller_pid_for_uid test", "[usage] get_last_caller_pid_for_uid "}, + {"resume_pid_async_for_uid", resume_pid_async_test_for_uid, "aul_resume_pid_async_for_uid", + "[usage] resume_pid_async_for_uid "}, }; int callfunc(char *testname) -- 2.7.4