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;
72 void notification_reset_event_handler_list(void)
75 notification_event_cb_info_s *info;
77 if (!__noti_event_cb_list)
80 iter = g_list_first(__noti_event_cb_list);
82 info = g_list_nth_data(iter, 0);
84 notification_ipc_reset_event_handler(info->priv_id);
85 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;
99 void notification_call_changed_cb_for_uid(notification_op *op_list, int op_num, uid_t uid)
101 notification_type_e type = NOTIFICATION_TYPE_NOTI;
103 notification_cb_info_s *noti_cb_info;
105 if (_noti_cb_hash == NULL)
108 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
109 if (noti_cb_list == NULL)
112 if (op_list == NULL) {
113 ERR("Invalid parameter");
117 noti_cb_list = g_list_first(noti_cb_list);
118 notification_get_type(op_list->noti, &type);
120 for (; noti_cb_list != NULL; noti_cb_list = noti_cb_list->next) {
121 noti_cb_info = noti_cb_list->data;
123 if (noti_cb_info->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_info->changed_cb)
124 noti_cb_info->changed_cb(noti_cb_info->data, type);
126 if (noti_cb_info->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_info->detailed_changed_cb) {
127 noti_cb_info->detailed_changed_cb(noti_cb_info->data,
128 type, op_list, op_num);
133 static gint __priv_id_compare(gconstpointer a, gconstpointer b)
135 const notification_event_cb_info_s *info = NULL;
140 info = (notification_event_cb_info_s *)a;
142 if (info->priv_id == GPOINTER_TO_INT(b))
148 void notification_call_event_handler_cb(notification_h noti, int event_type)
153 notification_event_cb_info_s *info;
155 if (__noti_event_cb_list == NULL)
158 ret = notification_get_id(noti, NULL, &priv_id);
159 if (ret != NOTIFICATION_ERROR_NONE)
162 __noti_event_cb_list = g_list_first(__noti_event_cb_list);
163 find_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
164 (GCompareFunc)__priv_id_compare);
165 if (find_list == NULL)
168 info = g_list_nth_data(find_list, 0);
169 info->cb(noti, event_type, info->userdata);
173 /* LCOV_EXCL_START */
174 void notification_delete_event_handler_cb(int priv_id)
177 notification_event_cb_info_s *info;
179 if (__noti_event_cb_list == NULL)
182 __noti_event_cb_list = g_list_first(__noti_event_cb_list);
183 delete_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
184 (GCompareFunc)__priv_id_compare);
186 if (delete_list == NULL)
189 info = g_list_nth_data(delete_list, 0);
190 __noti_event_cb_list = g_list_remove(g_list_first(__noti_event_cb_list), info);
195 if (__noti_event_cb_list == NULL)
196 notification_ipc_event_monitor_fini();
200 /* LCOV_EXCL_START */
201 EXPORT_API int notification_add_deferred_task(
202 void (*deferred_task_cb)(void *data), void *user_data)
204 if (deferred_task_cb == NULL)
205 return NOTIFICATION_ERROR_INVALID_PARAMETER;
207 return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
210 EXPORT_API int notification_del_deferred_task(
211 void (*deferred_task_cb)(void *data))
213 if (deferred_task_cb == NULL)
214 return NOTIFICATION_ERROR_INVALID_PARAMETER;
216 return notification_ipc_del_deffered_task(deferred_task_cb);
220 /* LCOV_EXCL_START */
221 EXPORT_API int notification_resister_changed_cb_for_uid(
222 void (*changed_cb)(void *data, notification_type_e type),
223 void *user_data, uid_t uid)
226 notification_cb_info_s *noti_cb_info_new;
228 if (changed_cb == NULL)
229 return NOTIFICATION_ERROR_INVALID_PARAMETER;
231 if (_noti_cb_hash == NULL)
232 _noti_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
234 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
235 if (noti_cb_info_new == NULL) {
236 ERR("Failed to alloc memory");
237 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
240 noti_cb_info_new->cb_type = NOTIFICATION_CB_NORMAL;
241 noti_cb_info_new->changed_cb = changed_cb;
242 noti_cb_info_new->detailed_changed_cb = NULL;
243 noti_cb_info_new->data = user_data;
245 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
247 if (noti_cb_list == NULL) {
248 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
249 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
251 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
254 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
255 notification_unresister_changed_cb_for_uid(changed_cb, uid);
256 return NOTIFICATION_ERROR_IO_ERROR;
259 return NOTIFICATION_ERROR_NONE;
263 /* LCOV_EXCL_START */
264 EXPORT_API int notification_resister_changed_cb(
265 void (*changed_cb)(void *data, notification_type_e type),
268 return notification_resister_changed_cb_for_uid(changed_cb, user_data, getuid());
271 static gint _noti_changed_compare(gconstpointer a, gconstpointer b)
273 const struct _notification_cb_info *info = NULL;
277 info = (notification_cb_info_s *)a;
279 if (info->changed_cb == b)
285 EXPORT_API int notification_unresister_changed_cb_for_uid(
286 void (*changed_cb)(void *data, notification_type_e type), uid_t uid)
288 notification_cb_info_s *noti_cb_info;
290 GList *delete_cb_list;
292 if (changed_cb == NULL)
293 return NOTIFICATION_ERROR_INVALID_PARAMETER;
295 if (_noti_cb_hash == NULL)
296 return NOTIFICATION_ERROR_INVALID_PARAMETER;
298 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
299 if (noti_cb_list == NULL)
300 return NOTIFICATION_ERROR_INVALID_PARAMETER;
302 noti_cb_list = g_list_first(noti_cb_list);
303 delete_cb_list = g_list_find_custom(noti_cb_list, (gconstpointer)changed_cb,
304 (GCompareFunc)_noti_changed_compare);
305 if (delete_cb_list) {
306 noti_cb_info = g_list_nth_data(delete_cb_list, 0);
307 noti_cb_list = g_list_delete_link(noti_cb_list, delete_cb_list);
308 __free_changed_cb_info(noti_cb_info);
310 if (noti_cb_list == NULL) {
311 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
313 noti_cb_list = g_list_first(noti_cb_list);
314 g_hash_table_replace(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
318 return NOTIFICATION_ERROR_INVALID_PARAMETER;
321 if (g_hash_table_size(_noti_cb_hash) == 0)
322 notification_ipc_monitor_fini();
324 return NOTIFICATION_ERROR_NONE;
327 EXPORT_API int notification_unresister_changed_cb(
328 void (*changed_cb)(void *data, notification_type_e type))
330 return notification_unresister_changed_cb_for_uid(changed_cb, getuid());
333 EXPORT_API int notification_update_progress(notification_h noti,
340 double input_progress;
342 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
344 return NOTIFICATION_ERROR_INVALID_PARAMETER;
346 input_priv_id = noti->priv_id;
348 input_priv_id = priv_id;
352 caller_app_id = notification_get_app_id_by_pid(getpid());
354 caller_app_id = strdup(noti->caller_app_id);
357 input_progress = 0.0;
358 else if (progress > 1.0)
359 input_progress = 1.0;
361 input_progress = progress;
363 ret = notification_ongoing_update_progress(caller_app_id, input_priv_id,
372 EXPORT_API int notification_update_size(notification_h noti,
381 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
383 return NOTIFICATION_ERROR_INVALID_PARAMETER;
385 input_priv_id = noti->priv_id;
387 input_priv_id = priv_id;
391 caller_app_id = notification_get_app_id_by_pid(getpid());
393 caller_app_id = strdup(noti->caller_app_id);
400 ret = notification_ongoing_update_size(caller_app_id, input_priv_id,
409 EXPORT_API int notification_update_content(notification_h noti,
417 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
419 return NOTIFICATION_ERROR_INVALID_PARAMETER;
421 input_priv_id = noti->priv_id;
423 input_priv_id = priv_id;
427 caller_app_id = notification_get_app_id_by_pid(getpid());
429 caller_app_id = strdup(noti->caller_app_id);
431 ret = notification_ongoing_update_content(caller_app_id, input_priv_id,
441 /* notification_set_icon will be removed */
442 /* LCOV_EXCL_START */
443 EXPORT_API int notification_set_icon(notification_h noti,
444 const char *icon_path)
446 return notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
450 /* notification_get_icon will be removed */
451 /* LCOV_EXCL_START */
452 EXPORT_API int notification_get_icon(notification_h noti,
455 int ret = NOTIFICATION_ERROR_NONE;
456 char *ret_image_path = NULL;
458 ret = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
461 if (ret == NOTIFICATION_ERROR_NONE && icon_path != NULL)
462 *icon_path = ret_image_path;
468 /* LCOV_EXCL_START */
469 EXPORT_API int notification_translate_localized_text(notification_h noti)
471 int ret = NOTIFICATION_ERROR_NONE;
472 char *ret_text = NULL;
474 char *bundle_val = NULL;
477 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
479 noti->is_translation = false;
481 for (; type <= NOTIFICATION_TEXT_TYPE_MAX; type++) {
482 ret = notification_get_text(noti, type, &ret_text);
483 if (ret == NOTIFICATION_ERROR_NONE && ret_text) {
484 if (noti->b_text == NULL) {
485 noti->b_text = bundle_create();
486 if (noti->b_text == NULL)
487 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
492 new_text = strdup(ret_text);
494 snprintf(buf_key, sizeof(buf_key), "%d", type);
495 bundle_get_str(b, buf_key, &bundle_val);
496 if (bundle_val != NULL)
497 bundle_del(b, buf_key);
499 bundle_add_str(b, buf_key, new_text);
503 noti->num_format_args = 0;
508 noti->is_translation = true;
514 /* LCOV_EXCL_START */
515 EXPORT_API int notification_set_title(notification_h noti,
517 const char *loc_title)
519 return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
521 NOTIFICATION_VARIABLE_TYPE_NONE);
525 /* LCOV_EXCL_START */
526 EXPORT_API int notification_get_title(notification_h noti,
531 char *ret_text = NULL;
533 ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
539 if (loc_title != NULL)
546 /* LCOV_EXCL_START */
547 EXPORT_API int notification_set_content(notification_h noti,
549 const char *loc_content)
551 return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
552 content, loc_content,
553 NOTIFICATION_VARIABLE_TYPE_NONE);
557 /* LCOV_EXCL_START */
558 EXPORT_API int notification_get_content(notification_h noti,
563 char *ret_text = NULL;
565 ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
571 if (loc_content != NULL)
578 /* LCOV_EXCL_START */
579 EXPORT_API int notification_set_application(notification_h noti,
582 if (noti == NULL || app_id == NULL)
583 return NOTIFICATION_ERROR_INVALID_PARAMETER;
585 if (noti->launch_app_id)
586 free(noti->launch_app_id);
588 noti->launch_app_id = strdup(app_id);
590 return NOTIFICATION_ERROR_NONE;
594 /* LCOV_EXCL_START */
595 EXPORT_API int notification_get_application(notification_h noti,
598 if (noti == NULL || app_id == NULL)
599 return NOTIFICATION_ERROR_INVALID_PARAMETER;
601 if (noti->launch_app_id)
602 *app_id = noti->launch_app_id;
604 *app_id = noti->caller_app_id;
606 return NOTIFICATION_ERROR_NONE;
610 /* LCOV_EXCL_START */
611 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
614 if (noti == NULL || args == NULL)
615 return NOTIFICATION_ERROR_INVALID_PARAMETER;
618 bundle_free(noti->args);
620 noti->args = bundle_dup(args);
622 if (noti->group_args) {
623 bundle_free(noti->group_args);
624 noti->group_args = NULL;
627 if (group_args != NULL)
628 noti->group_args = bundle_dup(group_args);
630 return NOTIFICATION_ERROR_NONE;
634 /* LCOV_EXCL_START */
635 EXPORT_API int notification_get_args(notification_h noti,
639 if (noti == NULL || args == NULL)
640 return NOTIFICATION_ERROR_INVALID_PARAMETER;
647 if (group_args != NULL && noti->group_args)
648 *group_args = noti->group_args;
650 return NOTIFICATION_ERROR_NONE;
654 /* LCOV_EXCL_START */
655 int notification_get_grouping_list_for_uid(notification_type_e type, int count,
656 notification_list_h *list, uid_t uid)
658 notification_list_h get_list = NULL;
662 return NOTIFICATION_ERROR_INVALID_PARAMETER;
664 ret = notification_noti_get_grouping_list(type, 1, count, &get_list, NULL, uid);
665 if (ret != NOTIFICATION_ERROR_NONE)
670 return NOTIFICATION_ERROR_NONE;
673 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
674 notification_list_h *list)
676 return notification_get_grouping_list_for_uid(type, count, list, getuid());
680 /* LCOV_EXCL_START */
681 EXPORT_API int notification_delete_group_by_group_id(const char *app_id,
682 notification_type_e type,
689 caller_app_id = notification_get_app_id_by_pid(getpid());
691 caller_app_id = strdup(app_id);
693 ret = notification_ipc_request_delete_multiple(type, caller_app_id, getuid());
702 /* LCOV_EXCL_START */
703 int notification_delete_group_by_priv_id_for_uid(const char *app_id,
704 notification_type_e type,
705 int priv_id, uid_t uid)
711 caller_app_id = notification_get_app_id_by_pid(getpid());
713 caller_app_id = strdup(app_id);
715 ret = notification_ipc_request_delete_single(type, caller_app_id, priv_id, uid);
724 /* LCOV_EXCL_START */
725 EXPORT_API int notification_delete_group_by_priv_id(const char *app_id,
726 notification_type_e type,
729 return notification_delete_group_by_priv_id_for_uid(app_id, type, priv_id, getuid());
732 int notification_get_count_for_uid(notification_type_e type,
735 int priv_id, int *count,
742 return NOTIFICATION_ERROR_INVALID_PARAMETER;
745 caller_app_id = notification_get_app_id_by_pid(getpid());
747 caller_app_id = strdup(app_id);
749 ret = notification_ipc_request_get_count(
764 /* LCOV_EXCL_START */
765 EXPORT_API int notification_get_count(notification_type_e type,
768 int priv_id, int *count)
770 return notification_get_count_for_uid(type, app_id, group_id, priv_id, count, getuid());
773 int notification_clear_for_uid(notification_type_e type, uid_t uid)
775 if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
776 return NOTIFICATION_ERROR_INVALID_PARAMETER;
778 return notification_ipc_request_delete_multiple(type, NULL, uid);
782 /* LCOV_EXCL_START */
783 EXPORT_API int notification_clear(notification_type_e type)
785 return notification_clear_for_uid(type, getuid());
788 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
791 if (noti_op == NULL || data == NULL)
792 return NOTIFICATION_ERROR_INVALID_PARAMETER;
795 case NOTIFICATION_OP_DATA_TYPE:
796 *((int *)data) = noti_op->type;
798 case NOTIFICATION_OP_DATA_PRIV_ID:
799 *((int *)data) = noti_op->priv_id;
801 case NOTIFICATION_OP_DATA_NOTI:
802 *((notification_h *)data) = noti_op->noti;
804 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
805 *((int *)data) = noti_op->extra_info_1;
807 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
808 *((int *)data) = noti_op->extra_info_2;
811 return NOTIFICATION_ERROR_INVALID_PARAMETER;
814 return NOTIFICATION_ERROR_NONE;
818 /* LCOV_EXCL_START */
819 EXPORT_API int notification_set_pkgname(notification_h noti,
822 return notification_set_app_id(noti, pkgname);
826 /* LCOV_EXCL_START */
827 EXPORT_API int notification_set_app_id(notification_h noti,
830 if (noti == NULL || app_id == NULL)
831 return NOTIFICATION_ERROR_INVALID_PARAMETER;
833 /* Remove previous caller app_id */
834 if (noti->caller_app_id) {
835 free(noti->caller_app_id);
836 noti->caller_app_id = NULL;
839 noti->caller_app_id = strdup(app_id);
841 return NOTIFICATION_ERROR_NONE;
845 /* LCOV_EXCL_START */
846 int notification_delete_all_by_type_for_uid(const char *app_id,
847 notification_type_e type, uid_t uid)
852 if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
853 return NOTIFICATION_ERROR_INVALID_PARAMETER;
856 caller_app_id = notification_get_app_id_by_pid(getpid());
858 caller_app_id = strdup(app_id);
860 ret = notification_ipc_request_delete_multiple(type, caller_app_id, uid);
869 /* LCOV_EXCL_START */
870 EXPORT_API int notification_delete_all_by_type(const char *app_id,
871 notification_type_e type)
873 return notification_delete_all_by_type_for_uid(app_id, type, getuid());
876 int notification_delete_by_priv_id_for_uid(const char *app_id,
877 notification_type_e type,
884 if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
885 return NOTIFICATION_ERROR_INVALID_PARAMETER;
888 caller_app_id = notification_get_app_id_by_pid(getpid());
890 caller_app_id = strdup(app_id);
892 ret = notification_ipc_request_delete_single(type, caller_app_id, priv_id, uid);
901 /* LCOV_EXCL_START */
902 EXPORT_API int notification_delete_by_priv_id(const char *app_id,
903 notification_type_e type,
906 return notification_delete_by_priv_id_for_uid(app_id, type, priv_id, getuid());
909 EXPORT_API int notification_set_execute_option(notification_h noti,
910 notification_execute_type_e type,
913 bundle *service_handle)
915 char buf_key[32] = { 0, };
916 char *ret_val = NULL;
920 return NOTIFICATION_ERROR_INVALID_PARAMETER;
922 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
923 || type > NOTIFICATION_EXECUTE_TYPE_MAX)
924 return NOTIFICATION_ERROR_INVALID_PARAMETER;
926 if (noti->b_execute_option == NULL)
927 noti->b_execute_option = bundle_create();
929 b = noti->b_execute_option;
932 snprintf(buf_key, sizeof(buf_key), "text%d", type);
934 bundle_get_str(b, buf_key, &ret_val);
936 bundle_del(b, buf_key);
938 bundle_add_str(b, buf_key, text);
942 snprintf(buf_key, sizeof(buf_key), "key%d", type);
944 bundle_get_str(b, buf_key, &ret_val);
946 bundle_del(b, buf_key);
948 bundle_add_str(b, buf_key, key);
952 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
953 if (noti->b_service_responding != NULL) {
954 bundle_free(noti->b_service_responding);
955 noti->b_service_responding = NULL;
958 if (service_handle != NULL)
959 noti->b_service_responding = bundle_dup(service_handle);
962 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
963 if (noti->b_service_single_launch != NULL) {
964 bundle_free(noti->b_service_single_launch);
965 noti->b_service_single_launch = NULL;
968 if (service_handle != NULL)
969 noti->b_service_single_launch =
970 bundle_dup(service_handle);
973 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
974 if (noti->b_service_multi_launch != NULL) {
975 bundle_free(noti->b_service_multi_launch);
976 noti->b_service_multi_launch = NULL;
979 if (service_handle != NULL)
980 noti->b_service_multi_launch =
981 bundle_dup(service_handle);
986 return NOTIFICATION_ERROR_NONE;
990 /* LCOV_EXCL_START */
991 EXPORT_API int notification_get_id(notification_h noti,
992 int *group_id, int *priv_id)
995 return NOTIFICATION_ERROR_INVALID_PARAMETER;
998 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
999 *group_id = NOTIFICATION_GROUP_ID_NONE;
1001 *group_id = noti->group_id;
1005 *priv_id = noti->priv_id;
1007 return NOTIFICATION_ERROR_NONE;
1009 /* LCOV_EXCL_STOP */
1011 /* LCOV_EXCL_START */
1012 EXPORT_API int notification_set_priv_id(notification_h noti, int priv_id)
1014 if (noti == NULL || priv_id <= 0)
1015 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1017 noti->priv_id = priv_id;
1019 return NOTIFICATION_ERROR_NONE;
1021 /* LCOV_EXCL_STOP */
1023 /* LCOV_EXCL_START */
1024 notification_h notification_load_for_uid(char *app_id,
1025 int priv_id, uid_t uid)
1028 notification_h noti;
1030 noti = (notification_h)calloc(1, sizeof(struct _notification));
1032 ERR("Failed to alloc memory");
1033 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1037 ret = notification_ipc_request_load_noti_by_priv_id(noti, app_id, priv_id, uid);
1038 if (ret != NOTIFICATION_ERROR_NONE) {
1039 notification_free(noti);
1040 set_last_result(ret);
1044 set_last_result(NOTIFICATION_ERROR_NONE);
1048 /* LCOV_EXCL_STOP */
1050 /* LCOV_EXCL_START */
1051 EXPORT_API notification_h notification_load(char *app_id,
1054 return notification_load_for_uid(app_id, priv_id, getuid());
1056 /* LCOV_EXCL_STOP */
1058 /* LCOV_EXCL_START */
1059 EXPORT_API notification_h notification_new(notification_type_e type,
1060 int group_id, int priv_id)
1062 return notification_create(type);
1065 static void _notification_get_text_domain(notification_h noti)
1068 /* LCOV_EXCL_STOP */
1070 /* LCOV_EXCL_START */
1071 EXPORT_API int notification_get_execute_option(notification_h noti,
1072 notification_execute_type_e type,
1074 bundle **service_handle)
1076 char buf_key[32] = { 0, };
1077 char *ret_val = NULL;
1078 char *get_str = NULL;
1082 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1084 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1085 || type > NOTIFICATION_EXECUTE_TYPE_MAX)
1086 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1089 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1090 b = noti->b_service_responding;
1092 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1093 b = noti->b_service_single_launch;
1095 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1096 b = noti->b_service_multi_launch;
1104 if (noti->domain == NULL || noti->dir == NULL)
1105 _notification_get_text_domain(noti);
1107 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1109 bundle_get_str(b, buf_key, &ret_val);
1110 if (ret_val != NULL && noti->domain != NULL
1111 && noti->dir != NULL) {
1112 bindtextdomain(noti->domain, noti->dir);
1114 get_str = dgettext(noti->domain, ret_val);
1117 } else if (ret_val != NULL) {
1118 get_str = dgettext("sys_string", ret_val);
1122 snprintf(buf_key, sizeof(buf_key), "text%d",
1125 bundle_get_str(b, buf_key, &ret_val);
1132 if (service_handle != NULL)
1133 *service_handle = b;
1135 return NOTIFICATION_ERROR_NONE;
1137 /* LCOV_EXCL_STOP */
1139 /* LCOV_EXCL_START */
1140 EXPORT_API int notification_insert_for_uid(notification_h noti,
1141 int *priv_id, uid_t uid)
1147 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1149 if (noti->type <= NOTIFICATION_TYPE_NONE
1150 || noti->type > NOTIFICATION_TYPE_MAX)
1151 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1154 noti->insert_time = time(NULL);
1156 ret = notification_ipc_request_insert(noti, &id);
1157 if (ret != NOTIFICATION_ERROR_NONE)
1162 /* If priv_id is valid data, set priv_id */
1163 if (priv_id != NULL)
1164 *priv_id = noti->priv_id;
1166 return NOTIFICATION_ERROR_NONE;
1169 EXPORT_API int notification_insert(notification_h noti,
1172 return notification_insert_for_uid(noti, priv_id, getuid());
1175 EXPORT_API int notification_update_async_for_uid(notification_h noti,
1176 void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
1179 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1182 /* Update insert time ? */
1183 noti->insert_time = time(NULL);
1185 return notification_ipc_request_update_async(noti, result_cb, user_data);
1188 EXPORT_API int notification_update_async(notification_h noti,
1189 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1191 return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
1193 /* LCOV_EXCL_STOP */
1195 /* LCOV_EXCL_START */
1196 EXPORT_API int notification_register_detailed_changed_cb_for_uid(
1197 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1198 void *user_data, uid_t uid)
1200 GList *noti_cb_list = NULL;
1201 notification_cb_info_s *noti_cb_info_new = NULL;
1203 if (detailed_changed_cb == NULL)
1204 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1206 if (_noti_cb_hash == NULL)
1207 _noti_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
1209 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
1210 if (noti_cb_info_new == NULL) {
1211 ERR("Failed to alloc memory");
1212 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1215 noti_cb_info_new->cb_type = NOTIFICATION_CB_DETAILED;
1216 noti_cb_info_new->changed_cb = NULL;
1217 noti_cb_info_new->detailed_changed_cb = detailed_changed_cb;
1218 noti_cb_info_new->data = user_data;
1220 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1222 if (noti_cb_list == NULL) {
1223 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1224 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1226 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1229 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
1230 notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, uid);
1231 return NOTIFICATION_ERROR_IO_ERROR;
1234 return NOTIFICATION_ERROR_NONE;
1236 /* LCOV_EXCL_STOP */
1238 /* LCOV_EXCL_START */
1239 EXPORT_API int notification_register_detailed_changed_cb(
1240 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1243 return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1246 static gint _noti_detailed_changed_compare(gconstpointer a, gconstpointer b)
1248 const struct _notification_cb_info *info = NULL;
1252 info = (notification_cb_info_s *)a;
1254 if (info->detailed_changed_cb == b)
1260 EXPORT_API int notification_unregister_detailed_changed_cb_for_uid(
1261 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1262 void *user_data, uid_t uid)
1264 notification_cb_info_s *noti_cb_info;
1265 GList *noti_cb_list;
1266 GList *delete_cb_list;
1268 if (detailed_changed_cb == NULL)
1269 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1271 if (_noti_cb_hash == NULL)
1272 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1274 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1276 if (noti_cb_list == NULL)
1277 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1279 noti_cb_list = g_list_first(noti_cb_list);
1280 delete_cb_list = g_list_find_custom(noti_cb_list, (gconstpointer)detailed_changed_cb,
1281 (GCompareFunc)_noti_detailed_changed_compare);
1283 if (delete_cb_list) {
1284 noti_cb_info = (notification_cb_info_s *)g_list_nth_data(delete_cb_list, 0);
1285 noti_cb_list = g_list_delete_link(noti_cb_list, delete_cb_list);
1286 __free_changed_cb_info(noti_cb_info);
1287 if (noti_cb_list == NULL) {
1288 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
1290 noti_cb_list = g_list_first(noti_cb_list);
1291 g_hash_table_replace(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1295 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1298 if (g_hash_table_size(_noti_cb_hash) == 0)
1299 notification_ipc_monitor_fini();
1301 return NOTIFICATION_ERROR_NONE;
1305 EXPORT_API int notification_unregister_detailed_changed_cb(
1306 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1309 return notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1311 /* LCOV_EXCL_STOP */
1313 /* LCOV_EXCL_START */
1314 EXPORT_API int notification_is_service_ready(void)
1316 return notification_ipc_is_master_ready();
1318 /* LCOV_EXCL_STOP */
1320 /* LCOV_EXCL_START */
1321 EXPORT_API int notification_set_uid(notification_h noti,
1325 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1328 return NOTIFICATION_ERROR_NONE;
1331 EXPORT_API int notification_get_uid(notification_h noti,
1334 if (noti == NULL || uid == NULL)
1335 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1338 return NOTIFICATION_ERROR_NONE;
1341 static GList *__copy_private_file(notification_h noti)
1349 GList *file_list = NULL;
1352 if (noti->b_priv_image_path && noti->b_image_path) {
1353 dst_b = noti->b_priv_image_path;
1354 src_b = noti->b_image_path;
1355 for (i = NOTIFICATION_IMAGE_TYPE_ICON; i <= NOTIFICATION_IMAGE_TYPE_MAX; i++) {
1359 snprintf(buf_key, sizeof(buf_key), "%d", i);
1361 bundle_get_str(dst_b, buf_key, &dst_path);
1362 if (dst_path == NULL)
1365 bundle_get_str(src_b, buf_key, &src_path);
1366 if (src_path == NULL)
1369 ret = notification_copy_private_file(src_path, dst_path);
1370 if (ret == NOTIFICATION_ERROR_NONE)
1371 file_list = g_list_append(file_list, strdup(dst_path));
1374 if (noti->sound_path && noti->priv_sound_path) {
1375 ret = notification_copy_private_file(noti->sound_path,
1376 noti->priv_sound_path);
1377 if (ret == NOTIFICATION_ERROR_NONE)
1378 file_list = g_list_append(file_list,
1379 strdup(noti->priv_sound_path));
1382 if (noti->vibration_path && noti->priv_vibration_path) {
1383 ret = notification_copy_private_file(noti->vibration_path,
1384 noti->priv_vibration_path);
1385 if (ret == NOTIFICATION_ERROR_NONE)
1386 file_list = g_list_append(file_list,
1387 strdup(noti->priv_vibration_path));
1392 /* LCOV_EXCL_STOP */
1394 /* LCOV_EXCL_START */
1395 static void __remove_private_file(gpointer data, gpointer user_data)
1398 char *path = (char *)data;
1400 src = g_file_new_for_path(path);
1402 g_file_delete(src, NULL, NULL);
1403 g_object_unref(src);
1406 /* LCOV_EXCL_STOP */
1408 /* LCOV_EXCL_START */
1409 EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
1416 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1418 if (noti->type <= NOTIFICATION_TYPE_NONE
1419 || noti->type > NOTIFICATION_TYPE_MAX)
1420 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1422 /* Save insert time */
1423 noti->insert_time = time(NULL);
1426 file_list = __copy_private_file(noti);
1427 ret = notification_ipc_request_insert(noti, &id);
1428 if (ret == NOTIFICATION_ERROR_NONE) {
1430 INFO("Posted notification id[%d]", id);
1432 g_list_foreach(file_list, __remove_private_file, NULL);
1436 g_list_free_full(file_list, free);
1441 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
1444 notification_ipc_request_refresh(uid);
1445 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1449 /* Update insert time ? */
1450 noti->insert_time = time(NULL);
1452 return notification_ipc_request_update(noti);
1455 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
1458 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1460 return notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE,
1461 noti->caller_app_id, noti->priv_id, uid);
1464 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
1467 char *caller_app_id = NULL;
1469 if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
1470 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1472 caller_app_id = notification_get_app_id_by_pid(getpid());
1474 ret = notification_ipc_request_delete_multiple(type, caller_app_id, uid);
1477 free(caller_app_id);
1481 /* LCOV_EXCL_STOP */
1483 /* LCOV_EXCL_START */
1484 EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
1487 notification_h noti;
1488 char *caller_app_id;
1492 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1496 caller_app_id = notification_get_app_id_by_pid(getpid());
1497 if (!caller_app_id) {
1498 ERR("Failed to get a package name");
1499 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1503 noti = (notification_h)calloc(1, sizeof(struct _notification));
1505 ERR("Failed to alloc a new notification");
1506 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1507 free(caller_app_id);
1512 ret = notification_ipc_request_load_noti_by_tag(noti, caller_app_id, (char *)tag, uid);
1513 free(caller_app_id);
1515 set_last_result(ret);
1516 if (ret != NOTIFICATION_ERROR_NONE) {
1517 notification_free(noti);
1523 /* LCOV_EXCL_STOP */
1525 /* LCOV_EXCL_START */
1526 EXPORT_API notification_h notification_create_from_package_template(const char *app_id, const char *template_name)
1529 notification_h noti;
1531 if (app_id == NULL || template_name == NULL) {
1532 ERR("Invalid parameter");
1533 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1537 noti = (notification_h)calloc(1, sizeof(struct _notification));
1539 ERR("Failed to alloc memory");
1540 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1544 ret = notification_ipc_request_create_from_package_template(noti, app_id, template_name);
1545 set_last_result(ret);
1546 if (ret != NOTIFICATION_ERROR_NONE) {
1547 notification_free(noti);
1553 /* LCOV_EXCL_STOP */
1555 /* LCOV_EXCL_START */
1556 EXPORT_API int notification_set_default_button(notification_h noti, notification_button_index_e index)
1559 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1561 if (index < 0 || index > NOTIFICATION_BUTTON_6)
1562 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1564 noti->default_button_index = index;
1566 return NOTIFICATION_ERROR_NONE;
1569 EXPORT_API int notification_get_default_button(notification_h noti, notification_button_index_e *index)
1571 if (noti == NULL || index == NULL)
1572 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1574 *index = noti->default_button_index;
1576 return NOTIFICATION_ERROR_NONE;
1579 EXPORT_API int notification_get_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e *type)
1581 if (noti == NULL || type == NULL)
1582 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1584 *type = noti->ongoing_value_type;
1586 return NOTIFICATION_ERROR_NONE;
1589 EXPORT_API int notification_set_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e type)
1592 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1594 if (type < NOTIFICATION_ONGOING_VALUE_TYPE_PERCENT || type > NOTIFICATION_ONGOING_VALUE_TYPE_TIME)
1595 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1597 noti->ongoing_value_type = type;
1599 return NOTIFICATION_ERROR_NONE;
1602 EXPORT_API int notification_get_ongoing_time(notification_h noti, int *current, int *duration)
1604 if (noti == NULL || current == NULL || duration == NULL)
1605 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1607 *current = noti->ongoing_current;
1608 *duration = noti->ongoing_duration;
1610 return NOTIFICATION_ERROR_NONE;
1613 EXPORT_API int notification_set_ongoing_time(notification_h noti, int current, int duration)
1616 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1618 if (current < 0 || duration < 0 || current > duration)
1619 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1621 noti->ongoing_current = current;
1622 noti->ongoing_duration = duration;
1624 return NOTIFICATION_ERROR_NONE;
1627 EXPORT_API int notification_get_hide_timeout(notification_h noti, int *timeout)
1629 if (noti == NULL || timeout == NULL)
1630 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1632 *timeout = noti->hide_timeout;
1634 return NOTIFICATION_ERROR_NONE;
1637 EXPORT_API int notification_set_hide_timeout(notification_h noti, int timeout)
1639 if (noti == NULL || timeout < 0)
1640 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1642 noti->hide_timeout = timeout;
1644 return NOTIFICATION_ERROR_NONE;
1647 EXPORT_API int notification_get_delete_timeout(notification_h noti, int *timeout)
1649 if (noti == NULL || timeout == NULL)
1650 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1652 *timeout = noti->delete_timeout;
1654 return NOTIFICATION_ERROR_NONE;
1657 EXPORT_API int notification_set_delete_timeout(notification_h noti, int timeout)
1659 if (noti == NULL || timeout < 0)
1660 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1662 noti->delete_timeout = timeout;
1664 return NOTIFICATION_ERROR_NONE;
1667 EXPORT_API int notification_get_text_input_max_length(notification_h noti, int *text_input_max_length)
1669 if (noti == NULL || text_input_max_length == NULL)
1670 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1672 *text_input_max_length = noti->text_input_max_length;
1674 return NOTIFICATION_ERROR_NONE;
1676 /* LCOV_EXCL_STOP */
1678 /* LCOV_EXCL_START */
1679 EXPORT_API int notification_post_with_event_cb_for_uid(notification_h noti, event_handler_cb cb,
1680 void *userdata, uid_t uid)
1684 notification_event_cb_info_s *info = NULL;
1687 if (noti == NULL || cb == NULL)
1688 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1690 if (noti->type <= NOTIFICATION_TYPE_NONE || noti->type > NOTIFICATION_TYPE_MAX)
1691 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1693 noti->insert_time = time(NULL);
1694 noti->event_flag = true;
1697 ret = notification_ipc_request_insert(noti, &priv_id);
1698 if (ret != NOTIFICATION_ERROR_NONE)
1701 noti->priv_id = priv_id;
1703 __noti_event_cb_list = g_list_first(__noti_event_cb_list);
1704 find_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
1705 (GCompareFunc)__priv_id_compare);
1708 info = g_list_nth_data(find_list, 0);
1710 info->userdata = userdata;
1712 info = (notification_event_cb_info_s *)malloc(sizeof(notification_event_cb_info_s));
1714 ERR("Failed to alloc memory");
1715 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1717 info->priv_id = priv_id;
1719 info->userdata = userdata;
1720 __noti_event_cb_list = g_list_append(__noti_event_cb_list, info);
1725 /* LCOV_EXCL_STOP */
1727 /* LCOV_EXCL_START */
1728 EXPORT_API int notification_post_with_event_cb(notification_h noti, event_handler_cb cb, void *userdata)
1730 return notification_post_with_event_cb_for_uid(noti, cb, userdata, getuid());
1733 EXPORT_API int notification_send_event(notification_h noti, int event_type)
1739 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1741 if (!((event_type >= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1742 && event_type <= NOTIFICATION_EVENT_TYPE_MAX) ||
1743 (event_type >= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER
1744 && event_type <= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) ||
1745 (event_type >= NOTIFICATION_EVENT_TYPE_PRESSED
1746 && event_type <= NOTIFICATION_EVENT_TYPE_DELETED) ||
1747 (event_type == NOTIFICATION_EVENT_TYPE_CHECK_BOX)))
1748 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1750 ret = notification_get_event_flag(noti, &event_flag);
1751 if (ret != NOTIFICATION_ERROR_NONE || event_flag == false)
1752 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1754 ret = notification_ipc_send_event(noti, event_type, -1);
1759 EXPORT_API int notification_send_event_by_priv_id(int priv_id, int event_type)
1764 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1766 if (!((event_type >= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1767 && event_type <= NOTIFICATION_EVENT_TYPE_MAX) ||
1768 (event_type >= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER
1769 && event_type <= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) ||
1770 (event_type >= NOTIFICATION_EVENT_TYPE_PRESSED
1771 && event_type <= NOTIFICATION_EVENT_TYPE_DELETED) ||
1772 (event_type == NOTIFICATION_EVENT_TYPE_CHECK_BOX)))
1773 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1775 ret = notification_ipc_send_event(NULL, event_type, priv_id);
1779 EXPORT_API int notification_get_event_flag(notification_h noti, bool *flag)
1781 if (noti == NULL || flag == NULL)
1782 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1784 *flag = noti->event_flag;
1786 return NOTIFICATION_ERROR_NONE;
1789 EXPORT_API int notification_check_event_receiver_available(notification_h noti, bool *available)
1794 if (noti == NULL || available == NULL)
1795 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1797 ret = notification_get_id(noti, NULL, &priv_id);
1798 if (ret != NOTIFICATION_ERROR_NONE) {
1799 ERR("Failed to get priv id");
1803 ret = notification_ipc_check_event_receiver(priv_id, available);
1808 static bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
1810 if (string == NULL || string[0] == '\0')
1813 return bundle_decode(string, strlen((char *)string));
1816 EXPORT_API int notification_set_extention_data(notification_h noti, const char *key, bundle *value)
1818 return notification_set_extension_data(noti, key, value);
1821 EXPORT_API int notification_set_extension_data(notification_h noti, const char *key, bundle *value)
1826 bundle_raw *raw = NULL;
1828 if (noti == NULL || key == NULL)
1829 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1831 if (noti->args == NULL)
1832 noti->args = bundle_create();
1834 if (value == NULL) {
1835 ret = bundle_del(noti->args, key);
1836 if (ret == BUNDLE_ERROR_NONE)
1837 return NOTIFICATION_ERROR_NONE;
1839 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1842 bundle_get_str(noti->args, key, &del);
1844 bundle_del(noti->args, key);
1848 bundle_encode(value, &raw, &len);
1849 bundle_add_str(noti->args, key, (const char *)raw);
1850 bundle_free_encoded_rawdata(&raw);
1852 return NOTIFICATION_ERROR_NONE;
1855 EXPORT_API int notification_get_extention_data(notification_h noti, const char *key, bundle **value)
1857 return notification_get_extension_data(noti, key, value);
1860 EXPORT_API int notification_get_extension_data(notification_h noti, const char *key, bundle **value)
1866 if (noti == NULL || key == NULL || value == NULL)
1867 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1869 if (noti->args == NULL)
1870 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1874 ret = bundle_get_str(args, key, &ret_str);
1875 if (ret != BUNDLE_ERROR_NONE)
1876 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1878 *value = _create_bundle_from_bundle_raw((bundle_raw *)ret_str);
1880 return NOTIFICATION_ERROR_IO_ERROR;
1882 return NOTIFICATION_ERROR_NONE;
1884 /* LCOV_EXCL_STOP */
1887 #define EXTENSION_EVENT_KEY "_NOTIFICATION_EXTENSION_EVENT_"
1889 /* LCOV_EXCL_START */
1890 EXPORT_API int notification_set_extension_event_handler(notification_h noti,
1891 notification_event_type_extension_e event,
1892 app_control_h event_handler)
1895 int ret = NOTIFICATION_ERROR_NONE;
1897 bundle *app_control_bundle = NULL;
1898 bundle_raw *b_raw = NULL;
1902 if (noti == NULL || event_handler == NULL) {
1903 ERR("Invalid parameter");
1904 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1907 if (event < NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER ||
1908 event > NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) {
1909 ERR("Invalid event [%d]", event);
1910 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1913 if (noti->args == NULL)
1914 noti->args = bundle_create();
1916 snprintf(key, sizeof(key), "%s%d", EXTENSION_EVENT_KEY, event);
1917 bundle_get_str(noti->args, key, &del);
1919 bundle_del(noti->args, key);
1923 err = app_control_export_as_bundle(event_handler, &app_control_bundle);
1924 if (err != APP_CONTROL_ERROR_NONE) {
1925 ERR("Failed to export app_control to bundle [%d]", err);
1926 ret = NOTIFICATION_ERROR_IO_ERROR;
1930 err = bundle_encode(app_control_bundle, &b_raw, &len);
1931 if (err != BUNDLE_ERROR_NONE) {
1932 ERR("Failed to encode bundle [%d]", err);
1933 ret = NOTIFICATION_ERROR_IO_ERROR;
1937 err = bundle_add_str(noti->args, key, (const char *)b_raw);
1938 if (err != BUNDLE_ERROR_NONE) {
1939 ERR("Failed to add str to bundle [%d]", err);
1940 ret = NOTIFICATION_ERROR_IO_ERROR;
1946 bundle_free_encoded_rawdata(&b_raw);
1947 if (app_control_bundle)
1948 bundle_free(app_control_bundle);
1952 /* LCOV_EXCL_STOP */
1954 /* LCOV_EXCL_START */
1955 EXPORT_API int notification_get_extension_event_handler(notification_h noti,
1956 notification_event_type_extension_e event,
1957 app_control_h *event_handler)
1960 int ret = NOTIFICATION_ERROR_NONE;
1961 char *ret_str = NULL;
1963 bundle *app_control_bundle = NULL;
1964 app_control_h ret_app_control = NULL;
1966 if (noti == NULL || event_handler == NULL) {
1967 ERR("Invalid parameter");
1968 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1971 if (event < NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER ||
1972 event > NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) {
1973 ERR("Invalid event [%d]", event);
1974 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1977 snprintf(key, sizeof(key), "%s%d", EXTENSION_EVENT_KEY, event);
1979 bundle_get_str(noti->args, key, &ret_str);
1980 if (ret_str == NULL) {
1981 ERR("No handler, Invalid event[%d]", event);
1982 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1985 app_control_bundle = _create_bundle_from_bundle_raw((bundle_raw *)ret_str);
1986 if (app_control_bundle == NULL) {
1987 ERR("Failed to create bundle");
1988 return NOTIFICATION_ERROR_IO_ERROR;
1991 err = app_control_create(&ret_app_control);
1992 if (err != APP_CONTROL_ERROR_NONE) {
1993 ERR("Failed to create app control [%d]", err);
1994 ret = NOTIFICATION_ERROR_IO_ERROR;
1998 err = app_control_import_from_bundle(ret_app_control, app_control_bundle);
1999 if (err != APP_CONTROL_ERROR_NONE) {
2000 ERR("Failed to import app control from bundle [%d]", err);
2001 app_control_destroy(ret_app_control);
2002 ret = NOTIFICATION_ERROR_IO_ERROR;
2006 *event_handler = ret_app_control;
2009 if (app_control_bundle)
2010 bundle_free(app_control_bundle);
2014 /* LCOV_EXCL_STOP */
2016 /* LCOV_EXCL_START */
2017 EXPORT_API int notification_get_all_count_for_uid(notification_type_e type, int *count, uid_t uid)
2021 if (count == NULL) {
2022 ERR("Invalid parameter - count is null");
2023 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2026 if (type < NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX) {
2027 ERR("Invalid parameter - wrong type");
2028 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2031 ret = notification_ipc_request_get_all_count(type, count, uid);
2032 if (ret != NOTIFICATION_ERROR_NONE) {
2033 ERR("Failed to get count [%d]", ret);
2040 EXPORT_API int notification_get_all_count(notification_type_e type, int *count)
2042 return notification_get_all_count_for_uid(type, count, getuid());
2045 EXPORT_API int notification_set_app_label(notification_h noti, char *label)
2047 if (noti == NULL || label == NULL)
2048 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2050 if (noti->app_label)
2051 free(noti->app_label);
2053 noti->app_label = strdup(label);
2055 return NOTIFICATION_ERROR_NONE;
2058 EXPORT_API int notification_get_app_label(notification_h noti, char **label)
2060 if (noti == NULL || label == NULL)
2061 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2063 if (noti->app_label)
2064 *label = noti->app_label;
2066 return NOTIFICATION_ERROR_NONE;
2069 static void __set_caller_info(bundle *b, const char *appid, uid_t uid)
2071 pkgmgrinfo_appinfo_h handle;
2076 snprintf(buf, sizeof(buf), "%u", uid);
2077 bundle_del(b, AUL_K_ORG_CALLER_UID);
2078 bundle_add(b, AUL_K_ORG_CALLER_UID, buf);
2080 bundle_del(b, AUL_K_ORG_CALLER_APPID);
2081 bundle_add(b, AUL_K_ORG_CALLER_APPID, appid);
2083 r = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
2084 if (r != PMINFO_R_OK)
2087 pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
2089 bundle_del(b, AUL_K_ORG_CALLER_PKGID);
2090 bundle_add(b, AUL_K_ORG_CALLER_PKGID, pkgid);
2092 pkgmgrinfo_appinfo_destroy_appinfo(handle);
2095 static void __set_indirect_request(bundle *b)
2097 bundle_del(b, AUL_K_REQUEST_TYPE);
2098 bundle_add(b, AUL_K_REQUEST_TYPE, "indirect-request");
2101 EXPORT_API int notification_set_indirect_request(notification_h noti,
2102 pid_t pid, uid_t uid)
2104 char appid[256] = { 0, };
2108 if (noti == NULL || pid <= 1 || uid < REGULAR_UID_MIN)
2109 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2111 r = aul_app_get_appid_bypid(pid, appid, sizeof(appid));
2113 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2115 if (noti->b_service_responding) {
2116 __set_caller_info(noti->b_service_responding, appid, uid);
2117 __set_indirect_request(noti->b_service_responding);
2120 if (noti->b_service_single_launch) {
2121 __set_caller_info(noti->b_service_single_launch, appid, uid);
2122 __set_indirect_request(noti->b_service_single_launch);
2125 if (noti->b_service_multi_launch) {
2126 __set_caller_info(noti->b_service_multi_launch, appid, uid);
2127 __set_indirect_request(noti->b_service_multi_launch);
2130 for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
2131 if (noti->b_event_handler[i]) {
2132 __set_caller_info(noti->b_event_handler[i], appid, uid);
2133 __set_indirect_request(noti->b_event_handler[i]);
2137 return NOTIFICATION_ERROR_NONE;
2141 int notification_delete_by_display_applist_for_uid(int display_applist, uid_t uid)
2143 if (display_applist < NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY)
2144 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2146 return notification_ipc_request_delete_by_display_applist(display_applist, uid);
2149 EXPORT_API int notification_delete_by_display_applist(int display_applist)
2151 return notification_delete_by_display_applist_for_uid(display_applist, getuid());
2154 EXPORT_API int notification_set_check_box(notification_h noti,
2155 bool flag, bool checked)
2158 ERR("Invalid parameter");
2159 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2162 noti->check_box = flag;
2163 noti->check_box_value = checked;
2165 return NOTIFICATION_ERROR_NONE;
2168 EXPORT_API int notification_get_check_box(notification_h noti,
2169 bool *flag, bool *checked)
2171 if (noti == NULL || flag == NULL || checked == NULL) {
2172 ERR("Invalid parameter");
2173 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2176 *flag = noti->check_box;
2177 *checked = noti->check_box_value;
2179 return NOTIFICATION_ERROR_NONE;
2182 EXPORT_API int notification_set_check_box_checked(notification_h noti,
2186 ERR("Invalid parameter");
2187 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2190 noti->check_box_value = checked;
2192 return NOTIFICATION_ERROR_NONE;
2195 EXPORT_API int notification_get_check_box_checked(notification_h noti,
2198 if (noti == NULL || checked == NULL) {
2199 ERR("Invalid parameter");
2200 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2203 if (noti->check_box)
2204 *checked = noti->check_box_value;
2208 return NOTIFICATION_ERROR_NONE;
2210 /* LCOV_EXCL_STOP */