From 3413bf252874ab54387bd399050a987da1c6976f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 10 Apr 2018 15:40:12 +0900 Subject: [PATCH] Add a new internal API for setting indirect request Adds: - notification_set_indirect_request() Requires: - https://review.tizen.org/gerrit/#/c/175262/ - https://review.tizen.org/gerrit/#/c/175212/ - https://review.tizen.org/gerrit/#/c/175419/ - https://review.tizen.org/gerrit/#/c/175210/ Change-Id: I814def8fe5cb8b3d2e13faf0ee7ccfdae7b180c3 Signed-off-by: Hwankyu Jhun --- include/notification_internal.h | 6 ++++ src/notification_internal.c | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/include/notification_internal.h b/include/notification_internal.h index bc2596c..cb6e86a 100644 --- a/include/notification_internal.h +++ b/include/notification_internal.h @@ -1560,6 +1560,12 @@ int notification_set_app_label(notification_h noti, char *label); int notification_get_app_label(notification_h noti, char **label); /** + * @ This API is only for App Framework internally. + */ +int notification_set_indirect_request(notification_h noti, pid_t pid, + uid_t uid); + +/** * @} */ #ifdef __cplusplus diff --git a/src/notification_internal.c b/src/notification_internal.c index a9d9903..1ce50d1 100644 --- a/src/notification_internal.c +++ b/src/notification_internal.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,8 @@ #include #include +#define REGULAR_UID_MIN 5000 + typedef struct _notification_cb_info notification_cb_info_s; typedef struct _notification_event_cb_info notification_event_cb_info_s; @@ -2044,3 +2047,74 @@ EXPORT_API int notification_get_app_label(notification_h noti, char **label) return NOTIFICATION_ERROR_NONE; } + +static void __set_caller_info(bundle *b, const char *appid, uid_t uid) +{ + pkgmgrinfo_appinfo_h handle; + char buf[12]; + char *pkgid = NULL; + int r; + + snprintf(buf, sizeof(buf), "%u", uid); + bundle_del(b, AUL_K_ORG_CALLER_UID); + bundle_add(b, AUL_K_ORG_CALLER_UID, buf); + + bundle_del(b, AUL_K_ORG_CALLER_APPID); + bundle_add(b, AUL_K_ORG_CALLER_APPID, appid); + + r = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle); + if (r != PMINFO_R_OK) + return; + + pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); + if (pkgid) { + bundle_del(b, AUL_K_ORG_CALLER_PKGID); + bundle_add(b, AUL_K_ORG_CALLER_PKGID, pkgid); + } + pkgmgrinfo_appinfo_destroy_appinfo(handle); +} + +static void __set_indirect_request(bundle *b) +{ + bundle_del(b, AUL_K_REQUEST_TYPE); + bundle_add(b, AUL_K_REQUEST_TYPE, "indirect-request"); +} + +EXPORT_API int notification_set_indirect_request(notification_h noti, + pid_t pid, uid_t uid) +{ + char appid[256] = { 0, }; + int r; + int i; + + if (noti == NULL || pid <= 1 || uid < REGULAR_UID_MIN) + return NOTIFICATION_ERROR_INVALID_PARAMETER; + + r = aul_app_get_appid_bypid(pid, appid, sizeof(appid)); + if (r != AUL_R_OK) + return NOTIFICATION_ERROR_INVALID_PARAMETER; + + if (noti->b_service_responding) { + __set_caller_info(noti->b_service_responding, appid, uid); + __set_indirect_request(noti->b_service_responding); + } + + if (noti->b_service_single_launch) { + __set_caller_info(noti->b_service_single_launch, appid, uid); + __set_indirect_request(noti->b_service_single_launch); + } + + if (noti->b_service_multi_launch) { + __set_caller_info(noti->b_service_multi_launch, appid, uid); + __set_indirect_request(noti->b_service_multi_launch); + } + + for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) { + if (noti->b_event_handler[i]) { + __set_caller_info(noti->b_event_handler[i], appid, uid); + __set_indirect_request(noti->b_event_handler[i]); + } + } + + return NOTIFICATION_ERROR_NONE; +} -- 2.7.4