From: Hwankyu Jhun Date: Tue, 10 Apr 2018 06:40:12 +0000 (+0900) Subject: Add a new internal API for setting indirect request X-Git-Tag: submit/tizen_4.0/20180416.070010~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb9fbed326384b529b82575205e06a9c68fa27ca;p=platform%2Fcore%2Fapi%2Fnotification.git 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 --- diff --git a/include/notification_internal.h b/include/notification_internal.h index cb91db7a..a4251243 100755 --- a/include/notification_internal.h +++ b/include/notification_internal.h @@ -1464,6 +1464,12 @@ int notification_set_extension_event_handler(notification_h noti, int notification_get_extension_event_handler(notification_h noti, notification_event_type_extension_e event, app_control_h *event_handler); +/** + * @ This API is only for App Framework internally. + */ +int notification_set_indirect_request(notification_h noti, pid_t pid, + uid_t uid); + /** * @} */ diff --git a/src/notification_internal.c b/src/notification_internal.c index 04d69152..562e0bf5 100755 --- 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; @@ -2022,3 +2025,73 @@ EXPORT_API int notification_get_all_count(notification_type_e type, int *count) return notification_get_all_count_for_uid(type, count, getuid()); } +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; +}