Add a new internal API for setting indirect request 19/175419/10
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 10 Apr 2018 06:40:12 +0000 (15:40 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Mon, 16 Apr 2018 02:15:22 +0000 (02:15 +0000)
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 <h.jhun@samsung.com>
include/notification_internal.h
src/notification_internal.c

index bc2596c..cb6e86a 100644 (file)
@@ -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
index a9d9903..1ce50d1 100644 (file)
@@ -30,6 +30,7 @@
 #include <bundle_internal.h>
 #include <app_control.h>
 #include <app_control_internal.h>
+#include <pkgmgr-info.h>
 
 #include <notification.h>
 #include <notification_list.h>
@@ -42,6 +43,8 @@
 #include <notification_internal.h>
 #include <notification_shared_file.h>
 
+#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;
+}