2 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <dbus/dbus.h>
29 #include <bundle_internal.h>
30 #include <app_control.h>
31 #include <app_control_internal.h>
32 #include <pkgmgr-info.h>
34 #include <notification.h>
35 #include <notification_list.h>
36 #include <notification_debug.h>
37 #include <notification_private.h>
38 #include <notification_noti.h>
39 #include <notification_ongoing.h>
40 #include <notification_group.h>
41 #include <notification_ipc.h>
42 #include <notification_internal.h>
43 #include <notification_shared_file.h>
45 #define REGULAR_UID_MIN 5000
47 typedef struct _notification_cb_info notification_cb_info_s;
48 typedef struct _notification_event_cb_info notification_event_cb_info_s;
50 typedef enum __notification_cb_type {
51 NOTIFICATION_CB_NORMAL = 1,
52 NOTIFICATION_CB_DETAILED,
53 } _notification_cb_type_e;
55 struct _notification_cb_info {
56 _notification_cb_type_e cb_type;
57 void (*changed_cb)(void *data, notification_type_e type);
58 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op);
62 struct _notification_event_cb_info {
68 static GHashTable *_noti_cb_hash = NULL;
69 static GList *__noti_event_cb_list = NULL;
71 void notification_reset_event_handler_list(void)
74 notification_event_cb_info_s *info;
76 if (!__noti_event_cb_list)
79 iter = g_list_first(__noti_event_cb_list);
81 info = g_list_nth_data(iter, 0);
83 notification_ipc_reset_event_handler(info->priv_id);
84 iter = g_list_next(iter);
89 static void __free_changed_cb_info(gpointer data)
91 notification_cb_info_s *noti_cb_info = (notification_cb_info_s *)data;
98 void notification_call_changed_cb_for_uid(notification_op *op_list, int op_num, uid_t uid)
100 notification_type_e type = NOTIFICATION_TYPE_NOTI;
102 notification_cb_info_s *noti_cb_info;
104 if (_noti_cb_hash == NULL)
107 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
108 if (noti_cb_list == NULL)
111 if (op_list == NULL) {
112 ERR("Invalid parameter");
116 noti_cb_list = g_list_first(noti_cb_list);
117 notification_get_type(op_list->noti, &type);
119 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
120 noti_cb_info = noti_cb_list->data;
122 if (noti_cb_info->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_info->changed_cb)
123 noti_cb_info->changed_cb(noti_cb_info->data, type);
125 if (noti_cb_info->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_info->detailed_changed_cb) {
126 noti_cb_info->detailed_changed_cb(noti_cb_info->data,
127 type, op_list, op_num);
132 static gint __priv_id_compare(gconstpointer a, gconstpointer b)
134 const notification_event_cb_info_s *info = NULL;
139 info = (notification_event_cb_info_s *)a;
141 if (info->priv_id == GPOINTER_TO_INT(b))
147 void notification_call_event_handler_cb(notification_h noti, int event_type)
152 notification_event_cb_info_s *info;
154 if (__noti_event_cb_list == NULL)
157 ret = notification_get_id(noti, NULL, &priv_id);
158 if (ret != NOTIFICATION_ERROR_NONE)
161 __noti_event_cb_list = g_list_first(__noti_event_cb_list);
162 find_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
163 (GCompareFunc)__priv_id_compare);
164 if (find_list == NULL)
167 info = g_list_nth_data(find_list, 0);
168 info->cb(noti, event_type, info->userdata);
171 /* LCOV_EXCL_START */
172 void notification_delete_event_handler_cb(int priv_id)
175 notification_event_cb_info_s *info;
177 if (__noti_event_cb_list == NULL)
180 __noti_event_cb_list = g_list_first(__noti_event_cb_list);
181 delete_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
182 (GCompareFunc)__priv_id_compare);
184 if (delete_list == NULL)
187 info = g_list_nth_data(delete_list, 0);
188 __noti_event_cb_list = g_list_remove(g_list_first(__noti_event_cb_list), info);
193 if (__noti_event_cb_list == NULL)
194 notification_ipc_event_monitor_fini();
198 EXPORT_API int notification_add_deferred_task(
199 void (*deferred_task_cb)(void *data), void *user_data)
201 if (deferred_task_cb == NULL)
202 return NOTIFICATION_ERROR_INVALID_PARAMETER;
204 return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
207 EXPORT_API int notification_del_deferred_task(
208 void (*deferred_task_cb)(void *data))
210 if (deferred_task_cb == NULL)
211 return NOTIFICATION_ERROR_INVALID_PARAMETER;
213 return notification_ipc_del_deffered_task(deferred_task_cb);
216 EXPORT_API int notification_resister_changed_cb_for_uid(
217 void (*changed_cb)(void *data, notification_type_e type),
218 void *user_data, uid_t uid)
221 notification_cb_info_s *noti_cb_info_new;
223 if (changed_cb == NULL)
224 return NOTIFICATION_ERROR_INVALID_PARAMETER;
226 if (_noti_cb_hash == NULL)
227 _noti_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
229 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
230 if (noti_cb_info_new == NULL) {
231 /* LCOV_EXCL_START */
232 ERR("Failed to alloc memory");
233 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
237 noti_cb_info_new->cb_type = NOTIFICATION_CB_NORMAL;
238 noti_cb_info_new->changed_cb = changed_cb;
239 noti_cb_info_new->detailed_changed_cb = NULL;
240 noti_cb_info_new->data = user_data;
242 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
244 if (noti_cb_list == NULL) {
245 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
246 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
248 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
251 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
252 notification_unresister_changed_cb_for_uid(changed_cb, uid);
253 return NOTIFICATION_ERROR_IO_ERROR;
256 return NOTIFICATION_ERROR_NONE;
259 EXPORT_API int notification_resister_changed_cb(
260 void (*changed_cb)(void *data, notification_type_e type),
263 return notification_resister_changed_cb_for_uid(changed_cb, user_data, getuid());
266 static gint _noti_changed_compare(gconstpointer a, gconstpointer b)
268 const struct _notification_cb_info *info = NULL;
272 info = (notification_cb_info_s *)a;
274 if (info->changed_cb == b)
280 EXPORT_API int notification_unresister_changed_cb_for_uid(
281 void (*changed_cb)(void *data, notification_type_e type), uid_t uid)
283 notification_cb_info_s *noti_cb_info;
285 GList *delete_cb_list;
287 if (changed_cb == NULL)
288 return NOTIFICATION_ERROR_INVALID_PARAMETER;
290 if (_noti_cb_hash == NULL)
291 return NOTIFICATION_ERROR_INVALID_PARAMETER;
293 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
294 if (noti_cb_list == NULL)
295 return NOTIFICATION_ERROR_INVALID_PARAMETER;
297 noti_cb_list = g_list_first(noti_cb_list);
298 delete_cb_list = g_list_find_custom(noti_cb_list, (gconstpointer)changed_cb,
299 (GCompareFunc)_noti_changed_compare);
300 if (delete_cb_list) {
301 noti_cb_info = g_list_nth_data(delete_cb_list, 0);
302 noti_cb_list = g_list_delete_link(noti_cb_list, delete_cb_list);
303 __free_changed_cb_info(noti_cb_info);
305 if (noti_cb_list == NULL) {
306 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
308 noti_cb_list = g_list_first(noti_cb_list);
309 g_hash_table_replace(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
313 return NOTIFICATION_ERROR_INVALID_PARAMETER;
316 if (g_hash_table_size(_noti_cb_hash) == 0)
317 notification_ipc_monitor_fini();
319 return NOTIFICATION_ERROR_NONE;
322 EXPORT_API int notification_unresister_changed_cb(
323 void (*changed_cb)(void *data, notification_type_e type))
325 return notification_unresister_changed_cb_for_uid(changed_cb, getuid());
328 EXPORT_API int notification_update_progress(notification_h noti,
335 double input_progress;
337 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
339 return NOTIFICATION_ERROR_INVALID_PARAMETER;
341 input_priv_id = noti->priv_id;
343 input_priv_id = priv_id;
347 caller_app_id = notification_get_app_id_by_pid(getpid());
349 caller_app_id = strdup(noti->caller_app_id);
352 input_progress = 0.0;
353 else if (progress > 1.0)
354 input_progress = 1.0;
356 input_progress = progress;
358 ret = notification_ongoing_update_progress(caller_app_id, input_priv_id,
367 EXPORT_API int notification_update_size(notification_h noti,
376 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
378 return NOTIFICATION_ERROR_INVALID_PARAMETER;
380 input_priv_id = noti->priv_id;
382 input_priv_id = priv_id;
386 caller_app_id = notification_get_app_id_by_pid(getpid());
388 caller_app_id = strdup(noti->caller_app_id);
395 ret = notification_ongoing_update_size(caller_app_id, input_priv_id,
404 EXPORT_API int notification_update_content(notification_h noti,
412 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
414 return NOTIFICATION_ERROR_INVALID_PARAMETER;
416 input_priv_id = noti->priv_id;
418 input_priv_id = priv_id;
422 caller_app_id = notification_get_app_id_by_pid(getpid());
424 caller_app_id = strdup(noti->caller_app_id);
426 ret = notification_ongoing_update_content(caller_app_id, input_priv_id,
435 /* notification_set_icon will be removed */
436 /* LCOV_EXCL_START */
437 EXPORT_API int notification_set_icon(notification_h noti,
438 const char *icon_path)
440 return notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
444 /* notification_get_icon will be removed */
445 /* LCOV_EXCL_START */
446 EXPORT_API int notification_get_icon(notification_h noti,
449 int ret = NOTIFICATION_ERROR_NONE;
450 char *ret_image_path = NULL;
452 ret = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
455 if (ret == NOTIFICATION_ERROR_NONE && icon_path != NULL)
456 *icon_path = ret_image_path;
462 EXPORT_API int notification_translate_localized_text(notification_h noti)
464 int ret = NOTIFICATION_ERROR_NONE;
465 char *ret_text = NULL;
467 char *bundle_val = NULL;
470 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
472 noti->is_translation = false;
474 for (; type <= NOTIFICATION_TEXT_TYPE_MAX; type++) {
475 ret = notification_get_text(noti, type, &ret_text);
476 if (ret == NOTIFICATION_ERROR_NONE && ret_text) {
477 if (noti->b_text == NULL) {
478 noti->b_text = bundle_create();
479 if (noti->b_text == NULL)
480 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
485 new_text = strdup(ret_text);
487 snprintf(buf_key, sizeof(buf_key), "%d", type);
488 bundle_get_str(b, buf_key, &bundle_val);
489 if (bundle_val != NULL)
490 bundle_del(b, buf_key);
492 bundle_add_str(b, buf_key, new_text);
496 noti->num_format_args = 0;
501 noti->is_translation = true;
506 /* LCOV_EXCL_START */
507 EXPORT_API int notification_set_title(notification_h noti,
509 const char *loc_title)
511 return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
513 NOTIFICATION_VARIABLE_TYPE_NONE);
517 /* LCOV_EXCL_START */
518 EXPORT_API int notification_get_title(notification_h noti,
523 char *ret_text = NULL;
525 ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
531 if (loc_title != NULL)
538 /* LCOV_EXCL_START */
539 EXPORT_API int notification_set_content(notification_h noti,
541 const char *loc_content)
543 return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
544 content, loc_content,
545 NOTIFICATION_VARIABLE_TYPE_NONE);
549 /* LCOV_EXCL_START */
550 EXPORT_API int notification_get_content(notification_h noti,
555 char *ret_text = NULL;
557 ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
563 if (loc_content != NULL)
570 /* LCOV_EXCL_START */
571 EXPORT_API int notification_set_application(notification_h noti,
574 if (noti == NULL || app_id == NULL)
575 return NOTIFICATION_ERROR_INVALID_PARAMETER;
577 if (noti->launch_app_id)
578 free(noti->launch_app_id);
580 noti->launch_app_id = strdup(app_id);
582 return NOTIFICATION_ERROR_NONE;
586 /* LCOV_EXCL_START */
587 EXPORT_API int notification_get_application(notification_h noti,
590 if (noti == NULL || app_id == NULL)
591 return NOTIFICATION_ERROR_INVALID_PARAMETER;
593 if (noti->launch_app_id)
594 *app_id = noti->launch_app_id;
596 *app_id = noti->caller_app_id;
598 return NOTIFICATION_ERROR_NONE;
602 /* LCOV_EXCL_START */
603 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
606 if (noti == NULL || args == NULL)
607 return NOTIFICATION_ERROR_INVALID_PARAMETER;
610 bundle_free(noti->args);
612 noti->args = bundle_dup(args);
614 if (noti->group_args) {
615 bundle_free(noti->group_args);
616 noti->group_args = NULL;
619 if (group_args != NULL)
620 noti->group_args = bundle_dup(group_args);
622 return NOTIFICATION_ERROR_NONE;
626 /* LCOV_EXCL_START */
627 EXPORT_API int notification_get_args(notification_h noti,
631 if (noti == NULL || args == NULL)
632 return NOTIFICATION_ERROR_INVALID_PARAMETER;
639 if (group_args != NULL && noti->group_args)
640 *group_args = noti->group_args;
642 return NOTIFICATION_ERROR_NONE;
646 /* LCOV_EXCL_START */
647 int notification_get_grouping_list_for_uid(notification_type_e type, int count,
648 notification_list_h *list, uid_t uid)
650 notification_list_h get_list = NULL;
654 return NOTIFICATION_ERROR_INVALID_PARAMETER;
656 ret = notification_noti_get_grouping_list(type, 1, count, &get_list, NULL, uid);
657 if (ret != NOTIFICATION_ERROR_NONE)
662 return NOTIFICATION_ERROR_NONE;
665 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
666 notification_list_h *list)
668 return notification_get_grouping_list_for_uid(type, count, list, getuid());
672 /* LCOV_EXCL_START */
673 EXPORT_API int notification_delete_group_by_group_id(const char *app_id,
674 notification_type_e type,
681 caller_app_id = notification_get_app_id_by_pid(getpid());
683 caller_app_id = strdup(app_id);
685 ret = notification_ipc_request_delete_multiple(type, caller_app_id, getuid());
694 /* LCOV_EXCL_START */
695 int notification_delete_group_by_priv_id_for_uid(const char *app_id,
696 notification_type_e type,
697 int priv_id, uid_t uid)
703 caller_app_id = notification_get_app_id_by_pid(getpid());
705 caller_app_id = strdup(app_id);
707 ret = notification_ipc_request_delete_single(type, caller_app_id, priv_id, uid);
716 /* LCOV_EXCL_START */
717 EXPORT_API int notification_delete_group_by_priv_id(const char *app_id,
718 notification_type_e type,
721 return notification_delete_group_by_priv_id_for_uid(app_id, type, priv_id, getuid());
724 int notification_get_count_for_uid(notification_type_e type,
727 int priv_id, int *count,
734 return NOTIFICATION_ERROR_INVALID_PARAMETER;
737 caller_app_id = notification_get_app_id_by_pid(getpid());
739 caller_app_id = strdup(app_id);
741 ret = notification_ipc_request_get_count(
756 /* LCOV_EXCL_START */
757 EXPORT_API int notification_get_count(notification_type_e type,
760 int priv_id, int *count)
762 return notification_get_count_for_uid(type, app_id, group_id, priv_id, count, getuid());
765 int notification_clear_for_uid(notification_type_e type, uid_t uid)
767 if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
768 return NOTIFICATION_ERROR_INVALID_PARAMETER;
770 return notification_ipc_request_delete_multiple(type, NULL, uid);
774 /* LCOV_EXCL_START */
775 EXPORT_API int notification_clear(notification_type_e type)
777 return notification_clear_for_uid(type, getuid());
780 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
783 if (noti_op == NULL || data == NULL)
784 return NOTIFICATION_ERROR_INVALID_PARAMETER;
787 case NOTIFICATION_OP_DATA_TYPE:
788 *((int *)data) = noti_op->type;
790 case NOTIFICATION_OP_DATA_PRIV_ID:
791 *((int *)data) = noti_op->priv_id;
793 case NOTIFICATION_OP_DATA_NOTI:
794 *((notification_h *)data) = noti_op->noti;
796 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
797 *((int *)data) = noti_op->extra_info_1;
799 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
800 *((int *)data) = noti_op->extra_info_2;
803 return NOTIFICATION_ERROR_INVALID_PARAMETER;
806 return NOTIFICATION_ERROR_NONE;
810 /* LCOV_EXCL_START */
811 EXPORT_API int notification_set_pkgname(notification_h noti,
814 return notification_set_app_id(noti, pkgname);
818 EXPORT_API int notification_set_app_id(notification_h noti,
821 if (noti == NULL || app_id == NULL)
822 return NOTIFICATION_ERROR_INVALID_PARAMETER;
824 /* Remove previous caller app_id */
825 if (noti->caller_app_id) {
826 free(noti->caller_app_id);
827 noti->caller_app_id = NULL;
830 noti->caller_app_id = strdup(app_id);
832 return NOTIFICATION_ERROR_NONE;
835 /* LCOV_EXCL_START */
836 int notification_delete_all_by_type_for_uid(const char *app_id,
837 notification_type_e type, uid_t uid)
842 if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
843 return NOTIFICATION_ERROR_INVALID_PARAMETER;
846 caller_app_id = notification_get_app_id_by_pid(getpid());
848 caller_app_id = strdup(app_id);
850 ret = notification_ipc_request_delete_multiple(type, caller_app_id, uid);
859 /* LCOV_EXCL_START */
860 EXPORT_API int notification_delete_all_by_type(const char *app_id,
861 notification_type_e type)
863 return notification_delete_all_by_type_for_uid(app_id, type, getuid());
866 int notification_delete_by_priv_id_for_uid(const char *app_id,
867 notification_type_e type,
874 if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
875 return NOTIFICATION_ERROR_INVALID_PARAMETER;
878 caller_app_id = notification_get_app_id_by_pid(getpid());
880 caller_app_id = strdup(app_id);
882 ret = notification_ipc_request_delete_single(type, caller_app_id, priv_id, uid);
891 /* LCOV_EXCL_START */
892 EXPORT_API int notification_delete_by_priv_id(const char *app_id,
893 notification_type_e type,
896 return notification_delete_by_priv_id_for_uid(app_id, type, priv_id, getuid());
899 EXPORT_API int notification_set_execute_option(notification_h noti,
900 notification_execute_type_e type,
903 bundle *service_handle)
905 char buf_key[32] = { 0, };
906 char *ret_val = NULL;
910 return NOTIFICATION_ERROR_INVALID_PARAMETER;
912 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
913 || type > NOTIFICATION_EXECUTE_TYPE_MAX)
914 return NOTIFICATION_ERROR_INVALID_PARAMETER;
916 if (noti->b_execute_option == NULL)
917 noti->b_execute_option = bundle_create();
919 b = noti->b_execute_option;
922 snprintf(buf_key, sizeof(buf_key), "text%d", type);
924 bundle_get_str(b, buf_key, &ret_val);
926 bundle_del(b, buf_key);
928 bundle_add_str(b, buf_key, text);
932 snprintf(buf_key, sizeof(buf_key), "key%d", type);
934 bundle_get_str(b, buf_key, &ret_val);
936 bundle_del(b, buf_key);
938 bundle_add_str(b, buf_key, key);
942 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
943 if (noti->b_service_responding != NULL) {
944 bundle_free(noti->b_service_responding);
945 noti->b_service_responding = NULL;
948 if (service_handle != NULL)
949 noti->b_service_responding = bundle_dup(service_handle);
952 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
953 if (noti->b_service_single_launch != NULL) {
954 bundle_free(noti->b_service_single_launch);
955 noti->b_service_single_launch = NULL;
958 if (service_handle != NULL)
959 noti->b_service_single_launch =
960 bundle_dup(service_handle);
963 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
964 if (noti->b_service_multi_launch != NULL) {
965 bundle_free(noti->b_service_multi_launch);
966 noti->b_service_multi_launch = NULL;
969 if (service_handle != NULL)
970 noti->b_service_multi_launch =
971 bundle_dup(service_handle);
976 return NOTIFICATION_ERROR_NONE;
980 /* LCOV_EXCL_START */
981 EXPORT_API int notification_get_id(notification_h noti,
982 int *group_id, int *priv_id)
985 return NOTIFICATION_ERROR_INVALID_PARAMETER;
988 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
989 *group_id = NOTIFICATION_GROUP_ID_NONE;
991 *group_id = noti->group_id;
995 *priv_id = noti->priv_id;
997 return NOTIFICATION_ERROR_NONE;
1001 EXPORT_API int notification_set_priv_id(notification_h noti, int priv_id)
1003 if (noti == NULL || priv_id <= 0)
1004 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1006 noti->priv_id = priv_id;
1008 return NOTIFICATION_ERROR_NONE;
1011 /* LCOV_EXCL_START */
1012 notification_h notification_load_for_uid(char *app_id,
1013 int priv_id, uid_t uid)
1016 notification_h noti;
1018 noti = (notification_h)calloc(1, sizeof(struct _notification));
1020 ERR("Failed to alloc memory");
1021 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1025 ret = notification_ipc_request_load_noti_by_priv_id(noti, app_id, priv_id, uid);
1026 if (ret != NOTIFICATION_ERROR_NONE) {
1027 notification_free(noti);
1028 set_last_result(ret);
1032 set_last_result(NOTIFICATION_ERROR_NONE);
1036 /* LCOV_EXCL_STOP */
1038 /* LCOV_EXCL_START */
1039 EXPORT_API notification_h notification_load(char *app_id,
1042 return notification_load_for_uid(app_id, priv_id, getuid());
1044 /* LCOV_EXCL_STOP */
1046 /* LCOV_EXCL_START */
1047 EXPORT_API notification_h notification_new(notification_type_e type,
1048 int group_id, int priv_id)
1050 return notification_create(type);
1053 static void _notification_get_text_domain(notification_h noti)
1056 /* LCOV_EXCL_STOP */
1058 /* LCOV_EXCL_START */
1059 EXPORT_API int notification_get_execute_option(notification_h noti,
1060 notification_execute_type_e type,
1062 bundle **service_handle)
1064 char buf_key[32] = { 0, };
1065 char *ret_val = NULL;
1066 char *get_str = NULL;
1070 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1072 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1073 || type > NOTIFICATION_EXECUTE_TYPE_MAX)
1074 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1077 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1078 b = noti->b_service_responding;
1080 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1081 b = noti->b_service_single_launch;
1083 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1084 b = noti->b_service_multi_launch;
1092 if (noti->domain == NULL || noti->dir == NULL)
1093 _notification_get_text_domain(noti);
1095 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1097 bundle_get_str(b, buf_key, &ret_val);
1098 if (ret_val != NULL && noti->domain != NULL
1099 && noti->dir != NULL) {
1100 bindtextdomain(noti->domain, noti->dir);
1102 get_str = dgettext(noti->domain, ret_val);
1105 } else if (ret_val != NULL) {
1106 get_str = dgettext("sys_string", ret_val);
1110 snprintf(buf_key, sizeof(buf_key), "text%d",
1113 bundle_get_str(b, buf_key, &ret_val);
1120 if (service_handle != NULL)
1121 *service_handle = b;
1123 return NOTIFICATION_ERROR_NONE;
1125 /* LCOV_EXCL_STOP */
1127 EXPORT_API int notification_insert_for_uid(notification_h noti,
1128 int *priv_id, uid_t uid)
1134 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1136 if (noti->type <= NOTIFICATION_TYPE_NONE
1137 || noti->type > NOTIFICATION_TYPE_MAX)
1138 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1141 noti->insert_time = time(NULL);
1143 ret = notification_ipc_request_insert(noti, &id);
1144 if (ret != NOTIFICATION_ERROR_NONE)
1149 /* If priv_id is valid data, set priv_id */
1150 if (priv_id != NULL)
1151 *priv_id = noti->priv_id;
1153 return NOTIFICATION_ERROR_NONE;
1156 EXPORT_API int notification_insert(notification_h noti,
1159 return notification_insert_for_uid(noti, priv_id, getuid());
1162 EXPORT_API int notification_update_async_for_uid(notification_h noti,
1163 void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
1166 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1169 /* Update insert time ? */
1170 noti->insert_time = time(NULL);
1172 return notification_ipc_request_update_async(noti, result_cb, user_data);
1175 EXPORT_API int notification_update_async(notification_h noti,
1176 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1178 return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
1181 EXPORT_API int notification_register_detailed_changed_cb_for_uid(
1182 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1183 void *user_data, uid_t uid)
1185 GList *noti_cb_list = NULL;
1186 notification_cb_info_s *noti_cb_info_new = NULL;
1188 if (detailed_changed_cb == NULL)
1189 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1191 if (_noti_cb_hash == NULL)
1192 _noti_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
1194 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
1195 if (noti_cb_info_new == NULL) {
1196 /* LCOV_EXCL_START */
1197 ERR("Failed to alloc memory");
1198 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1199 /* LCOV_EXCL_STOP */
1202 noti_cb_info_new->cb_type = NOTIFICATION_CB_DETAILED;
1203 noti_cb_info_new->changed_cb = NULL;
1204 noti_cb_info_new->detailed_changed_cb = detailed_changed_cb;
1205 noti_cb_info_new->data = user_data;
1207 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1209 if (noti_cb_list == NULL) {
1210 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1211 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1213 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1216 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
1217 notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, uid);
1218 return NOTIFICATION_ERROR_IO_ERROR;
1221 return NOTIFICATION_ERROR_NONE;
1224 EXPORT_API int notification_register_detailed_changed_cb(
1225 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1228 return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1231 static gint _noti_detailed_changed_compare(gconstpointer a, gconstpointer b)
1233 const struct _notification_cb_info *info = NULL;
1237 info = (notification_cb_info_s *)a;
1239 if (info->detailed_changed_cb == b)
1245 EXPORT_API int notification_unregister_detailed_changed_cb_for_uid(
1246 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1247 void *user_data, uid_t uid)
1249 notification_cb_info_s *noti_cb_info;
1250 GList *noti_cb_list;
1251 GList *delete_cb_list;
1253 if (detailed_changed_cb == NULL)
1254 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1256 if (_noti_cb_hash == NULL)
1257 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1259 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1261 if (noti_cb_list == NULL)
1262 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1264 noti_cb_list = g_list_first(noti_cb_list);
1265 delete_cb_list = g_list_find_custom(noti_cb_list, (gconstpointer)detailed_changed_cb,
1266 (GCompareFunc)_noti_detailed_changed_compare);
1268 if (delete_cb_list) {
1269 noti_cb_info = (notification_cb_info_s *)g_list_nth_data(delete_cb_list, 0);
1270 noti_cb_list = g_list_delete_link(noti_cb_list, delete_cb_list);
1271 __free_changed_cb_info(noti_cb_info);
1272 if (noti_cb_list == NULL) {
1273 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
1275 noti_cb_list = g_list_first(noti_cb_list);
1276 g_hash_table_replace(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1280 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1283 if (g_hash_table_size(_noti_cb_hash) == 0)
1284 notification_ipc_monitor_fini();
1286 return NOTIFICATION_ERROR_NONE;
1290 EXPORT_API int notification_unregister_detailed_changed_cb(
1291 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1294 return notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1297 /* LCOV_EXCL_START */
1298 EXPORT_API int notification_is_service_ready(void)
1300 return notification_ipc_is_master_ready();
1302 /* LCOV_EXCL_STOP */
1304 EXPORT_API int notification_set_uid(notification_h noti,
1308 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1311 return NOTIFICATION_ERROR_NONE;
1314 EXPORT_API int notification_get_uid(notification_h noti,
1317 if (noti == NULL || uid == NULL)
1318 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1321 return NOTIFICATION_ERROR_NONE;
1324 static GList *__copy_private_file(notification_h noti)
1332 GList *file_list = NULL;
1335 if (noti->b_priv_image_path && noti->b_image_path) {
1336 dst_b = noti->b_priv_image_path;
1337 src_b = noti->b_image_path;
1338 for (i = NOTIFICATION_IMAGE_TYPE_ICON; i <= NOTIFICATION_IMAGE_TYPE_MAX; i++) {
1342 snprintf(buf_key, sizeof(buf_key), "%d", i);
1344 bundle_get_str(dst_b, buf_key, &dst_path);
1345 if (dst_path == NULL)
1348 bundle_get_str(src_b, buf_key, &src_path);
1349 if (src_path == NULL)
1352 ret = notification_copy_private_file(src_path, dst_path);
1353 if (ret == NOTIFICATION_ERROR_NONE)
1354 file_list = g_list_append(file_list, strdup(dst_path));
1357 if (noti->sound_path && noti->priv_sound_path) {
1358 ret = notification_copy_private_file(noti->sound_path,
1359 noti->priv_sound_path);
1360 if (ret == NOTIFICATION_ERROR_NONE)
1361 file_list = g_list_append(file_list,
1362 strdup(noti->priv_sound_path));
1365 if (noti->vibration_path && noti->priv_vibration_path) {
1366 ret = notification_copy_private_file(noti->vibration_path,
1367 noti->priv_vibration_path);
1368 if (ret == NOTIFICATION_ERROR_NONE)
1369 file_list = g_list_append(file_list,
1370 strdup(noti->priv_vibration_path));
1376 /* LCOV_EXCL_START */
1377 static void __remove_private_file(gpointer data, gpointer user_data)
1380 char *path = (char *)data;
1382 src = g_file_new_for_path(path);
1384 g_file_delete(src, NULL, NULL);
1385 g_object_unref(src);
1388 /* LCOV_EXCL_STOP */
1390 EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
1397 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1399 if (noti->type <= NOTIFICATION_TYPE_NONE
1400 || noti->type > NOTIFICATION_TYPE_MAX)
1401 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1403 /* Save insert time */
1404 noti->insert_time = time(NULL);
1407 file_list = __copy_private_file(noti);
1408 ret = notification_ipc_request_insert(noti, &id);
1409 if (ret == NOTIFICATION_ERROR_NONE) {
1411 INFO("Posted notification id[%d]", id);
1413 g_list_foreach(file_list, __remove_private_file, NULL);
1417 g_list_free_full(file_list, free);
1422 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
1425 notification_ipc_request_refresh(uid);
1426 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1430 /* Update insert time ? */
1431 noti->insert_time = time(NULL);
1433 return notification_ipc_request_update(noti);
1436 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
1439 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1441 return notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE,
1442 noti->caller_app_id, noti->priv_id, uid);
1445 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
1448 char *caller_app_id = NULL;
1450 if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
1451 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1453 caller_app_id = notification_get_app_id_by_pid(getpid());
1455 ret = notification_ipc_request_delete_multiple(type, caller_app_id, uid);
1458 free(caller_app_id);
1463 EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
1466 notification_h noti;
1467 char *caller_app_id;
1471 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1475 caller_app_id = notification_get_app_id_by_pid(getpid());
1476 if (!caller_app_id) {
1477 /* LCOV_EXCL_START */
1478 ERR("Failed to get a package name");
1479 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1481 /* LCOV_EXCL_STOP */
1484 noti = (notification_h)calloc(1, sizeof(struct _notification));
1486 /* LCOV_EXCL_START */
1487 ERR("Failed to alloc a new notification");
1488 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1489 free(caller_app_id);
1492 /* LCOV_EXCL_STOP */
1495 ret = notification_ipc_request_load_noti_by_tag(noti, caller_app_id, (char *)tag, uid);
1496 free(caller_app_id);
1498 set_last_result(ret);
1499 if (ret != NOTIFICATION_ERROR_NONE) {
1500 notification_free(noti);
1507 EXPORT_API notification_h notification_create_from_package_template(const char *app_id, const char *template_name)
1510 notification_h noti;
1512 if (app_id == NULL || template_name == NULL) {
1513 ERR("Invalid parameter");
1514 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1518 noti = (notification_h)calloc(1, sizeof(struct _notification));
1520 /* LCOV_EXCL_START */
1521 ERR("Failed to alloc memory");
1522 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1524 /* LCOV_EXCL_STOP */
1527 ret = notification_ipc_request_create_from_package_template(noti, app_id, template_name);
1528 set_last_result(ret);
1529 if (ret != NOTIFICATION_ERROR_NONE) {
1530 notification_free(noti);
1537 EXPORT_API int notification_set_default_button(notification_h noti, notification_button_index_e index)
1540 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1542 if (index < 0 || index > NOTIFICATION_BUTTON_6)
1543 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1545 noti->default_button_index = index;
1547 return NOTIFICATION_ERROR_NONE;
1550 EXPORT_API int notification_get_default_button(notification_h noti, notification_button_index_e *index)
1552 if (noti == NULL || index == NULL)
1553 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1555 *index = noti->default_button_index;
1557 return NOTIFICATION_ERROR_NONE;
1560 EXPORT_API int notification_get_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e *type)
1562 if (noti == NULL || type == NULL)
1563 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1565 *type = noti->ongoing_value_type;
1567 return NOTIFICATION_ERROR_NONE;
1570 EXPORT_API int notification_set_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e type)
1573 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1575 if (type < NOTIFICATION_ONGOING_VALUE_TYPE_PERCENT || type > NOTIFICATION_ONGOING_VALUE_TYPE_TIME)
1576 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1578 noti->ongoing_value_type = type;
1580 return NOTIFICATION_ERROR_NONE;
1583 EXPORT_API int notification_get_ongoing_time(notification_h noti, int *current, int *duration)
1585 if (noti == NULL || current == NULL || duration == NULL)
1586 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1588 *current = noti->ongoing_current;
1589 *duration = noti->ongoing_duration;
1591 return NOTIFICATION_ERROR_NONE;
1594 EXPORT_API int notification_set_ongoing_time(notification_h noti, int current, int duration)
1597 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1599 if (current < 0 || duration < 0 || current > duration)
1600 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1602 noti->ongoing_current = current;
1603 noti->ongoing_duration = duration;
1605 return NOTIFICATION_ERROR_NONE;
1608 EXPORT_API int notification_get_hide_timeout(notification_h noti, int *timeout)
1610 if (noti == NULL || timeout == NULL)
1611 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1613 *timeout = noti->hide_timeout;
1615 return NOTIFICATION_ERROR_NONE;
1618 EXPORT_API int notification_set_hide_timeout(notification_h noti, int timeout)
1620 if (noti == NULL || timeout < 0)
1621 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1623 noti->hide_timeout = timeout;
1625 return NOTIFICATION_ERROR_NONE;
1628 EXPORT_API int notification_get_delete_timeout(notification_h noti, int *timeout)
1630 if (noti == NULL || timeout == NULL)
1631 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1633 *timeout = noti->delete_timeout;
1635 return NOTIFICATION_ERROR_NONE;
1638 EXPORT_API int notification_set_delete_timeout(notification_h noti, int timeout)
1640 if (noti == NULL || timeout < 0)
1641 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1643 noti->delete_timeout = timeout;
1645 return NOTIFICATION_ERROR_NONE;
1648 EXPORT_API int notification_get_text_input_max_length(notification_h noti, int *text_input_max_length)
1650 if (noti == NULL || text_input_max_length == NULL)
1651 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1653 *text_input_max_length = noti->text_input_max_length;
1655 return NOTIFICATION_ERROR_NONE;
1658 EXPORT_API int notification_post_with_event_cb_for_uid(notification_h noti, event_handler_cb cb,
1659 void *userdata, uid_t uid)
1663 notification_event_cb_info_s *info = NULL;
1666 if (noti == NULL || cb == NULL)
1667 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1669 if (noti->type <= NOTIFICATION_TYPE_NONE || noti->type > NOTIFICATION_TYPE_MAX)
1670 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1672 noti->insert_time = time(NULL);
1673 noti->event_flag = true;
1676 ret = notification_ipc_request_insert(noti, &priv_id);
1677 if (ret != NOTIFICATION_ERROR_NONE)
1680 noti->priv_id = priv_id;
1682 __noti_event_cb_list = g_list_first(__noti_event_cb_list);
1683 find_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
1684 (GCompareFunc)__priv_id_compare);
1687 info = g_list_nth_data(find_list, 0);
1689 info->userdata = userdata;
1691 info = (notification_event_cb_info_s *)malloc(sizeof(notification_event_cb_info_s));
1693 /* LCOV_EXCL_START */
1694 ERR("Failed to alloc memory");
1695 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1696 /* LCOV_EXCL_STOP */
1698 info->priv_id = priv_id;
1700 info->userdata = userdata;
1701 __noti_event_cb_list = g_list_append(__noti_event_cb_list, info);
1707 EXPORT_API int notification_post_with_event_cb(notification_h noti, event_handler_cb cb, void *userdata)
1709 return notification_post_with_event_cb_for_uid(noti, cb, userdata, getuid());
1712 EXPORT_API int notification_send_event(notification_h noti, int event_type)
1718 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1720 if (!((event_type >= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1721 && event_type <= NOTIFICATION_EVENT_TYPE_MAX) ||
1722 (event_type >= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER
1723 && event_type <= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) ||
1724 (event_type >= NOTIFICATION_EVENT_TYPE_PRESSED
1725 && event_type <= NOTIFICATION_EVENT_TYPE_DELETED)))
1726 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1728 ret = notification_get_event_flag(noti, &event_flag);
1729 if (ret != NOTIFICATION_ERROR_NONE || event_flag == false)
1730 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1732 ret = notification_ipc_send_event(noti, event_type, -1);
1737 EXPORT_API int notification_send_event_by_priv_id(int priv_id, int event_type)
1742 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1744 if (!((event_type >= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1745 && event_type <= NOTIFICATION_EVENT_TYPE_MAX) ||
1746 (event_type >= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER
1747 && event_type <= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) ||
1748 (event_type >= NOTIFICATION_EVENT_TYPE_PRESSED
1749 && event_type <= NOTIFICATION_EVENT_TYPE_DELETED)))
1750 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1752 ret = notification_ipc_send_event(NULL, event_type, priv_id);
1756 EXPORT_API int notification_get_event_flag(notification_h noti, bool *flag)
1758 if (noti == NULL || flag == NULL)
1759 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1761 *flag = noti->event_flag;
1763 return NOTIFICATION_ERROR_NONE;
1766 EXPORT_API int notification_check_event_receiver_available(notification_h noti, bool *available)
1771 if (noti == NULL || available == NULL)
1772 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1774 ret = notification_get_id(noti, NULL, &priv_id);
1775 if (ret != NOTIFICATION_ERROR_NONE) {
1776 ERR("Failed to get priv id");
1780 ret = notification_ipc_check_event_receiver(priv_id, available);
1785 static bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
1787 if (string == NULL || string[0] == '\0')
1790 return bundle_decode(string, strlen((char *)string));
1793 EXPORT_API int notification_set_extention_data(notification_h noti, const char *key, bundle *value)
1795 return notification_set_extension_data(noti, key, value);
1798 EXPORT_API int notification_set_extension_data(notification_h noti, const char *key, bundle *value)
1803 bundle_raw *raw = NULL;
1805 if (noti == NULL || key == NULL)
1806 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1808 if (noti->args == NULL)
1809 noti->args = bundle_create();
1811 if (value == NULL) {
1812 ret = bundle_del(noti->args, key);
1813 if (ret == BUNDLE_ERROR_NONE)
1814 return NOTIFICATION_ERROR_NONE;
1816 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1819 bundle_get_str(noti->args, key, &del);
1821 bundle_del(noti->args, key);
1825 bundle_encode(value, &raw, &len);
1826 bundle_add_str(noti->args, key, (const char *)raw);
1827 bundle_free_encoded_rawdata(&raw);
1829 return NOTIFICATION_ERROR_NONE;
1832 EXPORT_API int notification_get_extention_data(notification_h noti, const char *key, bundle **value)
1834 return notification_get_extension_data(noti, key, value);
1837 EXPORT_API int notification_get_extension_data(notification_h noti, const char *key, bundle **value)
1842 if (noti == NULL || key == NULL || value == NULL)
1843 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1845 if (noti->args == NULL)
1846 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1850 bundle_get_str(args, key, &ret_str);
1851 if (ret_str == NULL)
1852 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1854 *value = _create_bundle_from_bundle_raw((bundle_raw *)ret_str);
1856 return NOTIFICATION_ERROR_IO_ERROR;
1858 return NOTIFICATION_ERROR_NONE;
1862 #define EXTENSION_EVENT_KEY "_NOTIFICATION_EXTENSION_EVENT_"
1863 EXPORT_API int notification_set_extension_event_handler(notification_h noti,
1864 notification_event_type_extension_e event,
1865 app_control_h event_handler)
1868 int ret = NOTIFICATION_ERROR_NONE;
1870 bundle *app_control_bundle = NULL;
1871 bundle_raw *b_raw = NULL;
1875 if (noti == NULL || event_handler == NULL) {
1876 ERR("Invalid parameter");
1877 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1880 if (event < NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER ||
1881 event > NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) {
1882 ERR("Invalid event [%d]", event);
1883 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1886 if (noti->args == NULL)
1887 noti->args = bundle_create();
1889 snprintf(key, sizeof(key), "%s%d", EXTENSION_EVENT_KEY, event);
1890 bundle_get_str(noti->args, key, &del);
1892 bundle_del(noti->args, key);
1896 err = app_control_export_as_bundle(event_handler, &app_control_bundle);
1897 if (err != APP_CONTROL_ERROR_NONE) {
1898 /* LCOV_EXCL_START */
1899 ERR("Failed to export app_control to bundle [%d]", err);
1900 ret = NOTIFICATION_ERROR_IO_ERROR;
1902 /* LCOV_EXCL_STOP */
1905 err = bundle_encode(app_control_bundle, &b_raw, &len);
1906 if (err != BUNDLE_ERROR_NONE) {
1907 /* LCOV_EXCL_START */
1908 ERR("Failed to encode bundle [%d]", err);
1909 ret = NOTIFICATION_ERROR_IO_ERROR;
1911 /* LCOV_EXCL_STOP */
1914 err = bundle_add_str(noti->args, key, (const char *)b_raw);
1915 if (err != BUNDLE_ERROR_NONE) {
1916 /* LCOV_EXCL_START */
1917 ERR("Failed to add str to bundle [%d]", err);
1918 ret = NOTIFICATION_ERROR_IO_ERROR;
1920 /* LCOV_EXCL_STOP */
1925 bundle_free_encoded_rawdata(&b_raw);
1926 if (app_control_bundle)
1927 bundle_free(app_control_bundle);
1932 EXPORT_API int notification_get_extension_event_handler(notification_h noti,
1933 notification_event_type_extension_e event,
1934 app_control_h *event_handler)
1937 int ret = NOTIFICATION_ERROR_NONE;
1938 char *ret_str = NULL;
1940 bundle *app_control_bundle = NULL;
1941 app_control_h ret_app_control = NULL;
1943 if (noti == NULL || event_handler == NULL) {
1944 ERR("Invalid parameter");
1945 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1948 if (event < NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER ||
1949 event > NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) {
1950 ERR("Invalid event [%d]", event);
1951 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1954 snprintf(key, sizeof(key), "%s%d", EXTENSION_EVENT_KEY, event);
1956 bundle_get_str(noti->args, key, &ret_str);
1957 if (ret_str == NULL) {
1958 ERR("No handler, Invalid event[%d]", event);
1959 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1962 app_control_bundle = _create_bundle_from_bundle_raw((bundle_raw *)ret_str);
1963 if (app_control_bundle == NULL) {
1964 /* LCOV_EXCL_START */
1965 ERR("Failed to create bundle");
1966 return NOTIFICATION_ERROR_IO_ERROR;
1967 /* LCOV_EXCL_STOP */
1970 err = app_control_create(&ret_app_control);
1971 if (err != APP_CONTROL_ERROR_NONE) {
1972 /* LCOV_EXCL_START */
1973 ERR("Failed to create app control [%d]", err);
1974 ret = NOTIFICATION_ERROR_IO_ERROR;
1976 /* LCOV_EXCL_STOP */
1979 err = app_control_import_from_bundle(ret_app_control, app_control_bundle);
1980 if (err != APP_CONTROL_ERROR_NONE) {
1981 /* LCOV_EXCL_START */
1982 ERR("Failed to import app control from bundle [%d]", err);
1983 app_control_destroy(ret_app_control);
1984 ret = NOTIFICATION_ERROR_IO_ERROR;
1986 /* LCOV_EXCL_STOP */
1989 *event_handler = ret_app_control;
1992 if (app_control_bundle)
1993 bundle_free(app_control_bundle);
1998 EXPORT_API int notification_get_all_count_for_uid(notification_type_e type, int *count, uid_t uid)
2002 if (count == NULL) {
2003 ERR("Invalid parameter - count is null");
2004 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2007 if (type < NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX) {
2008 ERR("Invalid parameter - wrong type");
2009 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2012 ret = notification_ipc_request_get_all_count(type, count, uid);
2013 if (ret != NOTIFICATION_ERROR_NONE) {
2014 ERR("Failed to get count [%d]", ret);
2021 EXPORT_API int notification_get_all_count(notification_type_e type, int *count)
2023 return notification_get_all_count_for_uid(type, count, getuid());
2026 EXPORT_API int notification_set_app_label(notification_h noti, char *label)
2028 if (noti == NULL || label == NULL)
2029 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2031 if (noti->app_label)
2032 free(noti->app_label);
2034 noti->app_label = strdup(label);
2036 return NOTIFICATION_ERROR_NONE;
2039 EXPORT_API int notification_get_app_label(notification_h noti, char **label)
2041 if (noti == NULL || label == NULL)
2042 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2044 if (noti->app_label)
2045 *label = noti->app_label;
2047 return NOTIFICATION_ERROR_NONE;
2050 static void __set_caller_info(bundle *b, const char *appid, uid_t uid)
2052 pkgmgrinfo_appinfo_h handle;
2057 snprintf(buf, sizeof(buf), "%u", uid);
2058 bundle_del(b, AUL_K_ORG_CALLER_UID);
2059 bundle_add(b, AUL_K_ORG_CALLER_UID, buf);
2061 bundle_del(b, AUL_K_ORG_CALLER_APPID);
2062 bundle_add(b, AUL_K_ORG_CALLER_APPID, appid);
2064 r = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
2065 if (r != PMINFO_R_OK)
2068 pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
2070 bundle_del(b, AUL_K_ORG_CALLER_PKGID);
2071 bundle_add(b, AUL_K_ORG_CALLER_PKGID, pkgid);
2073 pkgmgrinfo_appinfo_destroy_appinfo(handle);
2076 static void __set_indirect_request(bundle *b)
2078 bundle_del(b, AUL_K_REQUEST_TYPE);
2079 bundle_add(b, AUL_K_REQUEST_TYPE, "indirect-request");
2082 EXPORT_API int notification_set_indirect_request(notification_h noti,
2083 pid_t pid, uid_t uid)
2085 char appid[256] = { 0, };
2089 if (noti == NULL || pid <= 1 || uid < REGULAR_UID_MIN)
2090 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2092 r = aul_app_get_appid_bypid(pid, appid, sizeof(appid));
2094 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2096 if (noti->b_service_responding) {
2097 __set_caller_info(noti->b_service_responding, appid, uid);
2098 __set_indirect_request(noti->b_service_responding);
2101 if (noti->b_service_single_launch) {
2102 __set_caller_info(noti->b_service_single_launch, appid, uid);
2103 __set_indirect_request(noti->b_service_single_launch);
2106 if (noti->b_service_multi_launch) {
2107 __set_caller_info(noti->b_service_multi_launch, appid, uid);
2108 __set_indirect_request(noti->b_service_multi_launch);
2111 for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
2112 if (noti->b_event_handler[i]) {
2113 __set_caller_info(noti->b_event_handler[i], appid, uid);
2114 __set_indirect_request(noti->b_event_handler[i]);
2118 return NOTIFICATION_ERROR_NONE;
2122 int notification_delete_by_display_applist_for_uid(int display_applist, uid_t uid)
2124 if (display_applist < NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY)
2125 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2127 return notification_ipc_request_delete_by_display_applist(display_applist, uid);
2130 EXPORT_API int notification_delete_by_display_applist(int display_applist)
2132 return notification_delete_by_display_applist_for_uid(display_applist, getuid());