2 * Copyright (c) 2000 - 2016 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>
24 #include <dbus/dbus-glib-lowlevel.h>
27 #include <app_control_internal.h>
31 #include <vconf-keys.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>
44 typedef struct _notification_cb_list notification_cb_list_s;
46 typedef enum __notification_cb_type {
47 NOTIFICATION_CB_NORMAL = 1,
48 NOTIFICATION_CB_DETAILED,
49 } _notification_cb_type_e;
51 struct _notification_cb_list {
52 notification_cb_list_s *prev;
53 notification_cb_list_s *next;
55 _notification_cb_type_e cb_type;
56 void (*changed_cb) (void *data, notification_type_e type);
57 void (*detailed_changed_cb) (void *data, notification_type_e type, notification_op *op_list, int num_op);
61 static notification_cb_list_s *g_notification_cb_list = NULL;
63 void notification_call_changed_cb(notification_op *op_list, int op_num)
65 notification_cb_list_s *noti_cb_list = NULL;
66 notification_type_e type = 0;
68 if (g_notification_cb_list == NULL)
71 noti_cb_list = g_notification_cb_list;
73 while (noti_cb_list->prev != NULL)
74 noti_cb_list = noti_cb_list->prev;
77 if (op_list == NULL) {
78 NOTIFICATION_ERR("invalid data");
82 notification_get_type(op_list->noti, &type);
84 while (noti_cb_list != NULL) {
85 if (noti_cb_list->cb_type == NOTIFICATION_CB_NORMAL && noti_cb_list->changed_cb) {
86 noti_cb_list->changed_cb(noti_cb_list->data,
89 if (noti_cb_list->cb_type == NOTIFICATION_CB_DETAILED && noti_cb_list->detailed_changed_cb) {
90 noti_cb_list->detailed_changed_cb(noti_cb_list->data,
91 type, op_list, op_num);
94 noti_cb_list = noti_cb_list->next;
98 EXPORT_API int notification_add_deferred_task(
99 void (*deferred_task_cb)(void *data), void *user_data)
101 if (deferred_task_cb == NULL)
102 return NOTIFICATION_ERROR_INVALID_PARAMETER;
104 return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
107 EXPORT_API int notification_del_deferred_task(
108 void (*deferred_task_cb)(void *data))
110 if (deferred_task_cb == NULL)
111 return NOTIFICATION_ERROR_INVALID_PARAMETER;
113 return notification_ipc_del_deffered_task(deferred_task_cb);
117 EXPORT_API int notification_resister_changed_cb_for_uid(
118 void (*changed_cb)(void *data, notification_type_e type),
119 void *user_data, uid_t uid)
121 notification_cb_list_s *noti_cb_list_new = NULL;
122 notification_cb_list_s *noti_cb_list = NULL;
124 if (changed_cb == NULL)
125 return NOTIFICATION_ERROR_INVALID_PARAMETER;
128 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
130 if (noti_cb_list_new == NULL) {
131 NOTIFICATION_ERR("malloc failed");
132 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
135 noti_cb_list_new->next = NULL;
136 noti_cb_list_new->prev = NULL;
138 noti_cb_list_new->cb_type = NOTIFICATION_CB_NORMAL;
139 noti_cb_list_new->changed_cb = changed_cb;
140 noti_cb_list_new->detailed_changed_cb = NULL;
141 noti_cb_list_new->data = user_data;
143 if (g_notification_cb_list == NULL) {
144 g_notification_cb_list = noti_cb_list_new;
146 noti_cb_list = g_notification_cb_list;
148 while (noti_cb_list->next != NULL)
149 noti_cb_list = noti_cb_list->next;
152 noti_cb_list->next = noti_cb_list_new;
153 noti_cb_list_new->prev = noti_cb_list;
156 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
157 notification_unresister_changed_cb(changed_cb);
158 return NOTIFICATION_ERROR_IO_ERROR;
161 return NOTIFICATION_ERROR_NONE;
164 EXPORT_API int notification_resister_changed_cb(
165 void (*changed_cb)(void *data, notification_type_e type),
168 return notification_resister_changed_cb_for_uid(
169 changed_cb, user_data, getuid());
172 EXPORT_API int notification_unresister_changed_cb(
173 void (*changed_cb)(void *data, notification_type_e type))
175 notification_cb_list_s *noti_cb_list = NULL;
176 notification_cb_list_s *noti_cb_list_prev = NULL;
177 notification_cb_list_s *noti_cb_list_next = NULL;
179 noti_cb_list = g_notification_cb_list;
181 if (changed_cb == NULL)
182 return NOTIFICATION_ERROR_INVALID_PARAMETER;
184 if (noti_cb_list == NULL)
185 return NOTIFICATION_ERROR_INVALID_PARAMETER;
187 while (noti_cb_list->prev != NULL)
188 noti_cb_list = noti_cb_list->prev;
192 if (noti_cb_list->changed_cb == changed_cb) {
193 noti_cb_list_prev = noti_cb_list->prev;
194 noti_cb_list_next = noti_cb_list->next;
196 if (noti_cb_list_prev == NULL)
197 g_notification_cb_list = noti_cb_list_next;
199 noti_cb_list_prev->next = noti_cb_list_next;
201 if (noti_cb_list_next == NULL) {
202 if (noti_cb_list_prev != NULL)
203 noti_cb_list_prev->next = NULL;
206 noti_cb_list_next->prev = noti_cb_list_prev;
211 if (g_notification_cb_list == NULL)
212 notification_ipc_monitor_fini();
214 return NOTIFICATION_ERROR_NONE;
216 noti_cb_list = noti_cb_list->next;
217 } while (noti_cb_list != NULL);
219 return NOTIFICATION_ERROR_INVALID_PARAMETER;
222 EXPORT_API int notification_update_progress(notification_h noti,
226 char *caller_pkgname = NULL;
227 int input_priv_id = 0;
229 double input_progress = 0.0;
231 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
233 return NOTIFICATION_ERROR_INVALID_PARAMETER;
235 input_priv_id = noti->priv_id;
238 input_priv_id = priv_id;
242 caller_pkgname = notification_get_pkgname_by_pid();
244 caller_pkgname = strdup(noti->caller_pkgname);
247 input_progress = 0.0;
248 else if (progress > 1.0)
249 input_progress = 1.0;
251 input_progress = progress;
253 ret = notification_ongoing_update_progress(caller_pkgname, input_priv_id,
257 free(caller_pkgname);
262 EXPORT_API int notification_update_size(notification_h noti,
266 char *caller_pkgname = NULL;
267 int input_priv_id = 0;
269 double input_size = 0.0;
271 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
273 return NOTIFICATION_ERROR_INVALID_PARAMETER;
275 input_priv_id = noti->priv_id;
277 input_priv_id = priv_id;
281 caller_pkgname = notification_get_pkgname_by_pid();
283 caller_pkgname = strdup(noti->caller_pkgname);
290 ret = notification_ongoing_update_size(caller_pkgname, input_priv_id,
294 free(caller_pkgname);
299 EXPORT_API int notification_update_content(notification_h noti,
303 char *caller_pkgname = NULL;
304 int input_priv_id = 0;
307 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
309 return NOTIFICATION_ERROR_INVALID_PARAMETER;
311 input_priv_id = noti->priv_id;
314 input_priv_id = priv_id;
318 caller_pkgname = notification_get_pkgname_by_pid();
320 caller_pkgname = strdup(noti->caller_pkgname);
322 ret = notification_ongoing_update_content(caller_pkgname, input_priv_id,
326 free(caller_pkgname);
331 /* notification_set_icon will be removed */
332 /* LCOV_EXCL_START */
333 EXPORT_API int notification_set_icon(notification_h noti,
334 const char *icon_path)
336 int ret_err = NOTIFICATION_ERROR_NONE;
339 notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
346 /* notification_get_icon will be removed */
347 /* LCOV_EXCL_START */
348 EXPORT_API int notification_get_icon(notification_h noti,
351 int ret_err = NOTIFICATION_ERROR_NONE;
352 char *ret_image_path = NULL;
355 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
358 if (ret_err == NOTIFICATION_ERROR_NONE && icon_path != NULL)
359 *icon_path = ret_image_path;
365 EXPORT_API int notification_translate_localized_text(notification_h noti)
367 int noti_err = NOTIFICATION_ERROR_NONE;
368 char *ret_text = NULL;
370 char *bundle_val = NULL;
373 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
375 for (; type < NOTIFICATION_TEXT_TYPE_MAX; type++) {
376 noti_err = notification_get_text(noti, type, &ret_text);
377 if (noti_err == NOTIFICATION_ERROR_NONE && ret_text) {
378 if (noti->b_text == NULL) {
379 noti->b_text = bundle_create();
380 if (noti->b_text == NULL)
381 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
386 new_text = strdup(ret_text);
388 snprintf(buf_key, sizeof(buf_key), "%d", type);
389 bundle_get_str(b, buf_key, &bundle_val);
390 if (bundle_val != NULL)
391 bundle_del(b, buf_key);
393 bundle_add_str(b, buf_key, new_text);
397 noti->num_format_args = 0;
403 bundle_free(noti->b_key);
410 /* LCOV_EXCL_START */
411 EXPORT_API int notification_set_title(notification_h noti,
413 const char *loc_title)
415 int noti_err = NOTIFICATION_ERROR_NONE;
417 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
419 NOTIFICATION_VARIABLE_TYPE_NONE);
425 /* LCOV_EXCL_START */
426 EXPORT_API int notification_get_title(notification_h noti,
430 int noti_err = NOTIFICATION_ERROR_NONE;
431 char *ret_text = NULL;
434 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
440 if (loc_title != NULL)
447 /* LCOV_EXCL_START */
448 EXPORT_API int notification_set_content(notification_h noti,
450 const char *loc_content)
452 int noti_err = NOTIFICATION_ERROR_NONE;
454 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
455 content, loc_content,
456 NOTIFICATION_VARIABLE_TYPE_NONE);
462 /* LCOV_EXCL_START */
463 EXPORT_API int notification_get_content(notification_h noti,
467 int noti_err = NOTIFICATION_ERROR_NONE;
468 char *ret_text = NULL;
471 notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
477 if (loc_content != NULL)
485 (VCONFKEY_SETAPPL_STATE_TICKER_NOTI_DISPLAY_CONTENT_BOOL, &boolval);
487 if (ret == -1 || boolval == 0) {
488 if (content != NULL && noti->default_content != NULL)
489 *content = noti->default_content;
491 if (loc_content != NULL && noti->loc_default_content != NULL)
492 *loc_content = noti->loc_default_content;
498 /* LCOV_EXCL_START */
499 EXPORT_API int notification_set_application(notification_h noti,
502 if (noti == NULL || pkgname == NULL)
503 return NOTIFICATION_ERROR_INVALID_PARAMETER;
505 if (noti->launch_pkgname)
506 free(noti->launch_pkgname);
508 noti->launch_pkgname = strdup(pkgname);
510 return NOTIFICATION_ERROR_NONE;
514 /* LCOV_EXCL_START */
515 EXPORT_API int notification_get_application(notification_h noti,
518 if (noti == NULL || pkgname == NULL)
519 return NOTIFICATION_ERROR_INVALID_PARAMETER;
521 if (noti->launch_pkgname)
522 *pkgname = noti->launch_pkgname;
524 *pkgname = noti->caller_pkgname;
526 return NOTIFICATION_ERROR_NONE;
530 /* LCOV_EXCL_START */
531 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
534 if (noti == NULL || args == NULL)
535 return NOTIFICATION_ERROR_INVALID_PARAMETER;
538 bundle_free(noti->args);
540 noti->args = bundle_dup(args);
542 if (noti->group_args) {
543 bundle_free(noti->group_args);
544 noti->group_args = NULL;
547 if (group_args != NULL)
548 noti->group_args = bundle_dup(group_args);
550 return NOTIFICATION_ERROR_NONE;
554 /* LCOV_EXCL_START */
555 EXPORT_API int notification_get_args(notification_h noti,
559 if (noti == NULL || args == NULL)
560 return NOTIFICATION_ERROR_INVALID_PARAMETER;
567 if (group_args != NULL && noti->group_args)
568 *group_args = noti->group_args;
570 return NOTIFICATION_ERROR_NONE;
574 /* LCOV_EXCL_START */
575 int notification_get_grouping_list_for_uid(notification_type_e type, int count,
576 notification_list_h *list, uid_t uid)
578 notification_list_h get_list = NULL;
582 return NOTIFICATION_ERROR_INVALID_PARAMETER;
584 ret = notification_noti_get_grouping_list(type, count, &get_list, uid);
585 if (ret != NOTIFICATION_ERROR_NONE)
590 return NOTIFICATION_ERROR_NONE;
593 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
594 notification_list_h *list)
596 return notification_get_grouping_list_for_uid(type, count, list, getuid());
600 /* LCOV_EXCL_START */
601 EXPORT_API int notification_delete_group_by_group_id(const char *pkgname,
602 notification_type_e type,
606 char *caller_pkgname = NULL;
609 caller_pkgname = notification_get_pkgname_by_pid();
611 caller_pkgname = strdup(pkgname);
613 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, getuid());
616 free(caller_pkgname);
622 /* LCOV_EXCL_START */
623 int notification_delete_group_by_priv_id_for_uid(const char *pkgname,
624 notification_type_e type,
625 int priv_id, uid_t uid)
628 char *caller_pkgname = NULL;
631 caller_pkgname = notification_get_pkgname_by_pid();
633 caller_pkgname = strdup(pkgname);
635 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
638 free(caller_pkgname);
644 /* LCOV_EXCL_START */
645 EXPORT_API int notification_delete_group_by_priv_id(const char *pkgname,
646 notification_type_e type,
649 return notification_delete_group_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
652 int notification_get_count_for_uid(notification_type_e type,
655 int priv_id, int *count,
659 char *caller_pkgname = NULL;
662 return NOTIFICATION_ERROR_INVALID_PARAMETER;
665 caller_pkgname = notification_get_pkgname_by_pid();
667 caller_pkgname = strdup(pkgname);
669 ret = notification_ipc_request_get_count(
678 free(caller_pkgname);
684 /* LCOV_EXCL_START */
685 EXPORT_API int notification_get_count(notification_type_e type,
688 int priv_id, int *count)
690 return notification_get_count_for_uid(type, pkgname, group_id, priv_id, count, getuid());
693 int notification_clear_for_uid(notification_type_e type, uid_t uid)
697 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
698 return NOTIFICATION_ERROR_INVALID_PARAMETER;
700 ret = notification_ipc_request_delete_multiple(type, NULL, uid);
706 /* LCOV_EXCL_START */
707 EXPORT_API int notification_clear(notification_type_e type)
709 return notification_clear_for_uid(type, getuid());
712 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
715 if (noti_op == NULL || data == NULL)
716 return NOTIFICATION_ERROR_INVALID_PARAMETER;
719 case NOTIFICATION_OP_DATA_TYPE:
720 *((int *)data) = noti_op->type;
722 case NOTIFICATION_OP_DATA_PRIV_ID:
723 *((int *)data) = noti_op->priv_id;
725 case NOTIFICATION_OP_DATA_NOTI:
726 *((notification_h *)data) = noti_op->noti;
728 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
729 *((int *)data) = noti_op->extra_info_1;
731 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
732 *((int *)data) = noti_op->extra_info_2;
735 return NOTIFICATION_ERROR_INVALID_PARAMETER;
739 return NOTIFICATION_ERROR_NONE;
743 /* LCOV_EXCL_START */
744 EXPORT_API int notification_set_pkgname(notification_h noti,
747 /* check noti and pkgname are valid data */
748 if (noti == NULL || pkgname == NULL)
749 return NOTIFICATION_ERROR_INVALID_PARAMETER;
751 /* Remove previous caller pkgname */
752 if (noti->caller_pkgname) {
753 free(noti->caller_pkgname);
754 noti->caller_pkgname = NULL;
757 noti->caller_pkgname = strdup(pkgname);
759 return NOTIFICATION_ERROR_NONE;
763 /* LCOV_EXCL_START */
764 int notification_delete_all_by_type_for_uid(const char *pkgname,
765 notification_type_e type, uid_t uid)
768 char *caller_pkgname = NULL;
770 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
771 return NOTIFICATION_ERROR_INVALID_PARAMETER;
774 caller_pkgname = notification_get_pkgname_by_pid();
776 caller_pkgname = strdup(pkgname);
778 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
781 free(caller_pkgname);
787 /* LCOV_EXCL_START */
788 EXPORT_API int notification_delete_all_by_type(const char *pkgname,
789 notification_type_e type)
791 return notification_delete_all_by_type_for_uid(pkgname, type, getuid());
794 int notification_delete_by_priv_id_for_uid(const char *pkgname,
795 notification_type_e type,
800 char *caller_pkgname = NULL;
802 if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
803 return NOTIFICATION_ERROR_INVALID_PARAMETER;
806 caller_pkgname = notification_get_pkgname_by_pid();
808 caller_pkgname = strdup(pkgname);
810 ret = notification_ipc_request_delete_single(type, caller_pkgname, priv_id, uid);
813 free(caller_pkgname);
819 /* LCOV_EXCL_START */
820 EXPORT_API int notification_delete_by_priv_id(const char *pkgname,
821 notification_type_e type,
824 return notification_delete_by_priv_id_for_uid(pkgname, type, priv_id, getuid());
827 EXPORT_API int notification_set_execute_option(notification_h noti,
828 notification_execute_type_e type,
831 bundle *service_handle)
833 char buf_key[32] = { 0, };
834 char *ret_val = NULL;
838 return NOTIFICATION_ERROR_INVALID_PARAMETER;
840 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
841 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
842 return NOTIFICATION_ERROR_INVALID_PARAMETER;
844 /* Create execute option bundle if does not exist */
845 if (noti->b_execute_option == NULL)
846 noti->b_execute_option = bundle_create();
848 b = noti->b_execute_option;
853 snprintf(buf_key, sizeof(buf_key), "text%d", type);
855 /* Check text key exist */
856 bundle_get_str(b, buf_key, &ret_val);
858 /* Remove previous data */
859 bundle_del(b, buf_key);
862 bundle_add_str(b, buf_key, text);
868 snprintf(buf_key, sizeof(buf_key), "key%d", type);
870 /* Check key key exist */
871 bundle_get_str(b, buf_key, &ret_val);
873 /* Remove previous data */
874 bundle_del(b, buf_key);
877 bundle_add_str(b, buf_key, key);
881 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
882 /* Remove previous data if exist */
883 if (noti->b_service_responding != NULL) {
884 bundle_free(noti->b_service_responding);
885 noti->b_service_responding = NULL;
888 /* Save service handle */
889 if (service_handle != NULL)
890 noti->b_service_responding = bundle_dup(service_handle);
893 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
894 /* Remove previous data if exist */
895 if (noti->b_service_single_launch != NULL) {
896 bundle_free(noti->b_service_single_launch);
897 noti->b_service_single_launch = NULL;
900 /* Save service handle */
901 if (service_handle != NULL)
902 noti->b_service_single_launch =
903 bundle_dup(service_handle);
906 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
907 /* Remove previous data if exist */
908 if (noti->b_service_multi_launch != NULL) {
909 bundle_free(noti->b_service_multi_launch);
910 noti->b_service_multi_launch = NULL;
913 /* Save service handle */
914 if (service_handle != NULL)
915 noti->b_service_multi_launch =
916 bundle_dup(service_handle);
921 return NOTIFICATION_ERROR_NONE;
925 /* LCOV_EXCL_START */
926 EXPORT_API int notification_get_id(notification_h noti,
927 int *group_id, int *priv_id)
929 /* check noti is valid data */
931 return NOTIFICATION_ERROR_INVALID_PARAMETER;
933 /* Check group_id is valid data */
936 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
937 *group_id = NOTIFICATION_GROUP_ID_NONE;
939 *group_id = noti->group_id;
942 /* Check priv_id is valid data */
945 *priv_id = noti->priv_id;
947 return NOTIFICATION_ERROR_NONE;
951 /* LCOV_EXCL_START */
952 notification_h notification_load_for_uid(char *pkgname,
953 int priv_id, uid_t uid)
956 notification_h noti = NULL;
958 noti = (notification_h)calloc(1, sizeof(struct _notification));
960 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
964 ret = notification_ipc_request_load_noti_by_priv_id(noti, pkgname, priv_id, uid);
965 if (ret != NOTIFICATION_ERROR_NONE) {
966 notification_free(noti);
974 EXPORT_API notification_h notification_load(char *pkgname,
977 return notification_load_for_uid(pkgname, priv_id, getuid());
980 /* LCOV_EXCL_START */
981 EXPORT_API notification_h notification_new(notification_type_e type,
982 int group_id, int priv_id)
984 return notification_create(type);
987 static void _notification_get_text_domain(notification_h noti)
992 /* LCOV_EXCL_START */
993 EXPORT_API int notification_get_execute_option(notification_h noti,
994 notification_execute_type_e type,
996 bundle **service_handle)
998 char buf_key[32] = { 0, };
999 char *ret_val = NULL;
1000 char *get_str = NULL;
1004 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1006 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1007 || type >= NOTIFICATION_EXECUTE_TYPE_MAX)
1008 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1012 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1013 b = noti->b_service_responding;
1015 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1016 b = noti->b_service_single_launch;
1018 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1019 b = noti->b_service_multi_launch;
1028 /* Get text domain and dir */
1029 if (noti->domain == NULL || noti->dir == NULL)
1030 _notification_get_text_domain(noti);
1033 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1035 /* Check key key exist */
1036 bundle_get_str(b, buf_key, &ret_val);
1037 if (ret_val != NULL && noti->domain != NULL
1038 && noti->dir != NULL) {
1039 /* Get application string */
1040 bindtextdomain(noti->domain, noti->dir);
1042 get_str = dgettext(noti->domain, ret_val);
1045 } else if (ret_val != NULL) {
1046 /* Get system string */
1047 get_str = dgettext("sys_string", ret_val);
1051 /* Get basic text */
1052 snprintf(buf_key, sizeof(buf_key), "text%d",
1055 bundle_get_str(b, buf_key, &ret_val);
1062 if (service_handle != NULL)
1063 *service_handle = b;
1065 return NOTIFICATION_ERROR_NONE;
1067 /* LCOV_EXCL_STOP */
1069 EXPORT_API int notification_insert_for_uid(notification_h noti,
1070 int *priv_id, uid_t uid)
1075 /* Check noti is vaild data */
1077 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1079 /* Check noti type is valid type */
1080 if (noti->type <= NOTIFICATION_TYPE_NONE
1081 || noti->type >= NOTIFICATION_TYPE_MAX)
1082 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1085 /* Save insert time */
1086 noti->insert_time = time(NULL);
1087 ret = notification_ipc_request_insert(noti, &id);
1088 if (ret != NOTIFICATION_ERROR_NONE)
1092 NOTIFICATION_DBG("from master:%d", id);
1094 /* If priv_id is valid data, set priv_id */
1095 if (priv_id != NULL)
1096 *priv_id = noti->priv_id;
1098 return NOTIFICATION_ERROR_NONE;
1101 EXPORT_API int notification_insert(notification_h noti,
1104 return notification_insert_for_uid(noti, priv_id, getuid());
1107 EXPORT_API int notification_update_async_for_uid(notification_h noti,
1108 void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
1112 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1115 /* Update insert time ? */
1116 noti->insert_time = time(NULL);
1117 ret = notification_ipc_request_update_async(noti, result_cb, user_data);
1122 EXPORT_API int notification_update_async(notification_h noti,
1123 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1125 return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
1128 EXPORT_API int notification_register_detailed_changed_cb_for_uid(
1129 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1130 void *user_data, uid_t uid)
1132 notification_cb_list_s *noti_cb_list_new = NULL;
1133 notification_cb_list_s *noti_cb_list = NULL;
1135 if (detailed_changed_cb == NULL)
1136 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1138 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE)
1139 return NOTIFICATION_ERROR_IO_ERROR;
1142 (notification_cb_list_s *) malloc(sizeof(notification_cb_list_s));
1144 if (noti_cb_list_new == NULL) {
1145 NOTIFICATION_ERR("malloc failed");
1146 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1149 noti_cb_list_new->next = NULL;
1150 noti_cb_list_new->prev = NULL;
1152 noti_cb_list_new->cb_type = NOTIFICATION_CB_DETAILED;
1153 noti_cb_list_new->changed_cb = NULL;
1154 noti_cb_list_new->detailed_changed_cb = detailed_changed_cb;
1155 noti_cb_list_new->data = user_data;
1157 if (g_notification_cb_list == NULL) {
1158 g_notification_cb_list = noti_cb_list_new;
1160 noti_cb_list = g_notification_cb_list;
1162 while (noti_cb_list->next != NULL)
1163 noti_cb_list = noti_cb_list->next;
1166 noti_cb_list->next = noti_cb_list_new;
1167 noti_cb_list_new->prev = noti_cb_list;
1169 return NOTIFICATION_ERROR_NONE;
1172 EXPORT_API int notification_register_detailed_changed_cb(
1173 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1176 return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1179 EXPORT_API int notification_unregister_detailed_changed_cb(
1180 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1183 notification_cb_list_s *noti_cb_list = NULL;
1184 notification_cb_list_s *noti_cb_list_prev = NULL;
1185 notification_cb_list_s *noti_cb_list_next = NULL;
1187 noti_cb_list = g_notification_cb_list;
1189 if (detailed_changed_cb == NULL)
1190 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1192 if (noti_cb_list == NULL)
1193 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1196 while (noti_cb_list->prev != NULL)
1197 noti_cb_list = noti_cb_list->prev;
1201 if (noti_cb_list->detailed_changed_cb == detailed_changed_cb) {
1202 noti_cb_list_prev = noti_cb_list->prev;
1203 noti_cb_list_next = noti_cb_list->next;
1205 if (noti_cb_list_prev == NULL)
1206 g_notification_cb_list = noti_cb_list_next;
1208 noti_cb_list_prev->next = noti_cb_list_next;
1210 if (noti_cb_list_next == NULL) {
1211 if (noti_cb_list_prev != NULL)
1212 noti_cb_list_prev->next = NULL;
1215 noti_cb_list_next->prev = noti_cb_list_prev;
1220 if (g_notification_cb_list == NULL)
1221 notification_ipc_monitor_fini();
1223 return NOTIFICATION_ERROR_NONE;
1225 noti_cb_list = noti_cb_list->next;
1226 } while (noti_cb_list != NULL);
1228 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1231 EXPORT_API int notification_is_service_ready(void)
1233 return notification_ipc_is_master_ready();
1236 EXPORT_API int notification_set_uid(notification_h noti,
1240 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1243 return NOTIFICATION_ERROR_NONE;
1246 EXPORT_API int notification_get_uid(notification_h noti,
1249 if (noti == NULL || uid == NULL)
1250 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1253 return NOTIFICATION_ERROR_NONE;
1256 EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
1261 /* Check noti is vaild data */
1263 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1265 /* Check noti type is valid type */
1266 if (noti->type <= NOTIFICATION_TYPE_NONE
1267 || noti->type >= NOTIFICATION_TYPE_MAX)
1268 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1270 /* Save insert time */
1271 noti->insert_time = time(NULL);
1274 ret = notification_ipc_request_insert(noti, &id);
1275 if (ret != NOTIFICATION_ERROR_NONE)
1279 NOTIFICATION_DBG("from master:%d", id);
1281 return NOTIFICATION_ERROR_NONE;
1284 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
1288 /* Check noti is valid data */
1291 /* Update insert time ? */
1292 noti->insert_time = time(NULL);
1293 ret = notification_ipc_request_update(noti);
1295 notification_ipc_request_refresh(uid);
1296 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1302 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
1307 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1309 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id, uid);
1314 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
1317 char *caller_pkgname = NULL;
1319 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
1320 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1322 caller_pkgname = notification_get_pkgname_by_pid();
1324 ret = notification_ipc_request_delete_multiple(type, caller_pkgname, uid);
1327 free(caller_pkgname);
1332 EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
1335 notification_h noti = NULL;
1336 char *caller_pkgname = NULL;
1339 NOTIFICATION_ERR("Invalid parameter");
1340 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1344 caller_pkgname = notification_get_pkgname_by_pid();
1345 if (!caller_pkgname) {
1346 NOTIFICATION_ERR("Failed to get a package name");
1347 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1351 noti = (notification_h)calloc(1, sizeof(struct _notification));
1353 NOTIFICATION_ERR("Failed to alloc a new notification");
1354 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1355 free(caller_pkgname);
1360 ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char *)tag, uid);
1361 free(caller_pkgname);
1363 set_last_result(ret);
1364 if (ret != NOTIFICATION_ERROR_NONE) {
1365 notification_free(noti);