From 79a1baf53dec5dcde4d8bb1e504129bf690d30e5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 19 Jul 2016 20:26:01 +0900 Subject: [PATCH] Add new APIs to get last caller process id - Add APIs aul_app_get_last_caller() aul_app_get_last_caller_for_uid() Change-Id: I5495250cfac1a3a22daf1a496112fb897e0e0a1b Signed-off-by: Hwankyu Jhun --- include/aul.h | 29 +++++++++++++++++++++++++++++ include/aul_cmd.h | 1 + src/pkginfo.c | 24 ++++++++++++++++++++++++ tool/aul_test.c | 20 ++++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/include/aul.h b/include/aul.h index 1470fe9..0b3ebfc 100644 --- a/include/aul.h +++ b/include/aul.h @@ -2782,6 +2782,35 @@ int aul_widget_instance_foreach(const char *widget_id, aul_widget_instance_forea */ int aul_widget_instance_update(const char *widget_id, const char *instance_id, bundle *b); +/** + * @par Description: + * This API gets the last caller process id of specified application process id. + * @par Purpose: + * This API's purpose is to get the application's last caller process id. + * + * @param[in] pid pid of application + * @return caller pid if success, nagative value if fail + * + * @remark + * This API is only available in User Session. + */ +int aul_app_get_last_caller_pid(int pid); + +/** + * @par Description: + * This API gets the last caller process id of specified application process id. + * @par Purpose: + * This API's purpose is to get the last caller process id of the application. + * + * @param[in] pid pid of application + * @param[in] uid User ID + * @return caller pid if success, nagative value if fail + * + * @remark + * This API is only available in System users. + */ +int aul_app_get_last_caller_pid_for_uid(int pid, uid_t uid); + #ifdef __cplusplus } #endif diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 77615fa..ce2ee7b 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -105,6 +105,7 @@ enum app_cmd { APP_PREPARE_CANDIDATE_PROCESS, APP_TERM_BY_PID_SYNC, APP_GET_STATUS_BY_APPID, + APP_GET_LAST_CALLER_PID, APP_CMD_MAX }; diff --git a/src/pkginfo.c b/src/pkginfo.c index 2b716dd..1741a40 100644 --- a/src/pkginfo.c +++ b/src/pkginfo.c @@ -437,3 +437,27 @@ API int aul_unset_default_app_by_operation(const char *app_id) return AUL_R_OK; } + +API int aul_app_get_last_caller_pid(int pid) +{ + return aul_app_get_last_caller_pid_for_uid(pid, getuid()); +} + +API int aul_app_get_last_caller_pid_for_uid(int pid, uid_t uid) +{ + int ret; + + if (pid < 0) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + ret = aul_sock_send_raw(AUL_UTIL_PID, uid, APP_GET_LAST_CALLER_PID, + (unsigned char *)&pid, sizeof(int), + AUL_SOCK_NONE); + if (ret < 0) + return aul_error_convert(ret); + + return ret; +} + diff --git a/tool/aul_test.c b/tool/aul_test.c index ae50976..f552064 100644 --- a/tool/aul_test.c +++ b/tool/aul_test.c @@ -650,6 +650,22 @@ static int get_status_test_for_uid(void) return 0; } +static int get_last_caller_pid_test(void) +{ + static int num; + + printf("[aul_app_get_last_caller_pid %d test] %d \n", num++, apn_pid); + return aul_app_get_last_caller_pid(apn_pid); +} + +static int get_last_caller_pid_test_for_uid(void) +{ + static int num; + + printf("[aul_app_get_last_caller_pid_for_uid %d test] %d \n", num++, apn_pid); + return aul_app_get_last_caller_pid_for_uid(apn_pid, atoi(gargv[3])); +} + static int test_regex() { char *token; @@ -781,6 +797,10 @@ static test_func_t test_func[] = { "[usage] get_status "}, {"get_status_for_uid", get_status_test_for_uid, "aul_app_get_status_for_uid test", "[usage] get_status_for_uid "}, + {"get_last_caller_pid", get_last_caller_pid_test, "aul_app_get_last_caller_pid test", + "[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