From 488b62f6ba11d279faf60caf332aa2e3749d0962 Mon Sep 17 00:00:00 2001 From: Hawnkyu Jhun Date: Sat, 21 Jan 2017 11:26:51 +0900 Subject: [PATCH] Support app group instance launch - Add new internal APIs to get instance id Change-Id: I75dbed523133202c8ad52faa5eaf9b44e2f6158f Signed-off-by: Hawnkyu Jhun --- include/aul.h | 7 +++++++ include/aul_cmd.h | 1 + src/pkginfo.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/include/aul.h b/include/aul.h index bfac5f7..e45af3e 100644 --- a/include/aul.h +++ b/include/aul.h @@ -3015,6 +3015,13 @@ int aul_app_get_running_app_instance_info(aul_app_info_iter_fn iter_fn, int aul_app_get_running_app_instance_info_for_uid(aul_app_info_iter_fn iter_fn, void *user_data, uid_t uid); +/* + * This API is only for Appfw internally. + */ +int aul_app_get_instance_id_bypid(int pid, char *instance_id, int len); +int aul_app_get_instance_id_bypid_for_uid(int pid, char *instance_id, + int len, uid_t uid); + #ifdef __cplusplus } #endif diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 4259111..55e653e 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -114,6 +114,7 @@ enum app_cmd { REMOVE_SCREEN_VIEWER = 84, LAUNCHPAD_LAUNCH_SIGNAL = 85, APP_RUNNING_INSTANCE_INFO = 86, + APP_GET_INSTANCE_ID_BYPID = 87, APP_CMD_MAX }; diff --git a/src/pkginfo.c b/src/pkginfo.c index 7ce560c..70c648c 100644 --- a/src/pkginfo.c +++ b/src/pkginfo.c @@ -663,3 +663,56 @@ API int aul_disable_alias_info(const char *appid) return AUL_R_OK; } + +API int aul_app_get_instance_id_bypid_for_uid(int pid, char *instance_id, + int len, uid_t uid) +{ + app_pkt_t *pkt = NULL; + bundle *b; + int ret; + int fd; + char buf[MAX_PID_STR_BUFSZ]; + + if (pid <= 0 || instance_id == NULL) { + _E("Invalid parameter"); + return AUL_R_EINVAL; + } + + b = bundle_create(); + if (b == NULL) { + _E("Out of memory"); + return AUL_R_ERROR; + } + + snprintf(buf, sizeof(buf), "%d", pid); + bundle_add(b, AUL_K_PID, buf); + snprintf(buf, sizeof(buf), "%d", uid); + bundle_add(b, AUL_K_TARGET_UID, buf); + + fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, + APP_GET_INSTANCE_ID_BYPID, b, + AUL_SOCK_ASYNC); + bundle_free(b); + if (fd <= 0) + return AUL_R_ERROR; + + ret = aul_sock_recv_reply_pkt(fd, &pkt); + if (ret < 0 || pkt == NULL) + return AUL_R_ERROR; + + if (pkt->cmd == APP_GET_INFO_OK) { + snprintf(instance_id, len, "%s", pkt->data); + free(pkt); + return AUL_R_OK; + } + + free(pkt); + + return AUL_R_ERROR; +} + +API int aul_app_get_instance_id_bypid(int pid, char *instance_id, int len) +{ + return aul_app_get_instance_id_bypid_for_uid(pid, + instance_id, len, getuid()); +} -- 2.7.4