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;
141 WARN("src id [%d] dst id [%d]", GPOINTER_TO_INT(b), info->priv_id);
143 if (info->priv_id == GPOINTER_TO_INT(b))
149 void notification_call_event_handler_cb(notification_h noti, int event_type)
154 notification_event_cb_info_s *info;
156 WARN("call noti id [%d] event[%d]", info->priv_id, event_type);
158 if (__noti_event_cb_list == NULL)
161 ret = notification_get_id(noti, NULL, &priv_id);
162 if (ret != NOTIFICATION_ERROR_NONE)
165 __noti_event_cb_list = g_list_first(__noti_event_cb_list);
166 find_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
167 (GCompareFunc)__priv_id_compare);
168 if (find_list == NULL)
171 info = g_list_nth_data(find_list, 0);
172 info->cb(noti, event_type, info->userdata);
177 /* LCOV_EXCL_START */
178 void notification_delete_event_handler_cb(int priv_id)
181 notification_event_cb_info_s *info;
183 WARN("delete noti id [%d]", priv_id);
185 if (__noti_event_cb_list == NULL)
188 __noti_event_cb_list = g_list_first(__noti_event_cb_list);
189 delete_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
190 (GCompareFunc)__priv_id_compare);
192 if (delete_list == NULL)
195 info = g_list_nth_data(delete_list, 0);
196 __noti_event_cb_list = g_list_remove(g_list_first(__noti_event_cb_list), info);
201 if (__noti_event_cb_list == NULL)
202 notification_ipc_event_monitor_fini();
207 /* LCOV_EXCL_START */
208 EXPORT_API int notification_add_deferred_task(
209 void (*deferred_task_cb)(void *data), void *user_data)
211 if (deferred_task_cb == NULL)
212 return NOTIFICATION_ERROR_INVALID_PARAMETER;
214 return notification_ipc_add_deffered_task(deferred_task_cb, user_data);
217 EXPORT_API int notification_del_deferred_task(
218 void (*deferred_task_cb)(void *data))
220 if (deferred_task_cb == NULL)
221 return NOTIFICATION_ERROR_INVALID_PARAMETER;
223 return notification_ipc_del_deffered_task(deferred_task_cb);
227 /* LCOV_EXCL_START */
228 EXPORT_API int notification_resister_changed_cb_for_uid(
229 void (*changed_cb)(void *data, notification_type_e type),
230 void *user_data, uid_t uid)
233 notification_cb_info_s *noti_cb_info_new;
235 if (changed_cb == NULL)
236 return NOTIFICATION_ERROR_INVALID_PARAMETER;
238 if (_noti_cb_hash == NULL)
239 _noti_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
241 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
242 if (noti_cb_info_new == NULL) {
243 ERR("Failed to alloc memory");
244 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
247 noti_cb_info_new->cb_type = NOTIFICATION_CB_NORMAL;
248 noti_cb_info_new->changed_cb = changed_cb;
249 noti_cb_info_new->detailed_changed_cb = NULL;
250 noti_cb_info_new->data = user_data;
252 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
254 if (noti_cb_list == NULL) {
255 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
256 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
258 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
261 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
262 notification_unresister_changed_cb_for_uid(changed_cb, uid);
263 return NOTIFICATION_ERROR_IO_ERROR;
266 return NOTIFICATION_ERROR_NONE;
270 /* LCOV_EXCL_START */
271 EXPORT_API int notification_resister_changed_cb(
272 void (*changed_cb)(void *data, notification_type_e type),
275 return notification_resister_changed_cb_for_uid(changed_cb, user_data, getuid());
278 static gint _noti_changed_compare(gconstpointer a, gconstpointer b)
280 const struct _notification_cb_info *info = NULL;
284 info = (notification_cb_info_s *)a;
286 if (info->changed_cb == b)
292 EXPORT_API int notification_unresister_changed_cb_for_uid(
293 void (*changed_cb)(void *data, notification_type_e type), uid_t uid)
295 notification_cb_info_s *noti_cb_info;
297 GList *delete_cb_list;
299 if (changed_cb == NULL)
300 return NOTIFICATION_ERROR_INVALID_PARAMETER;
302 if (_noti_cb_hash == NULL)
303 return NOTIFICATION_ERROR_INVALID_PARAMETER;
305 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
306 if (noti_cb_list == NULL)
307 return NOTIFICATION_ERROR_INVALID_PARAMETER;
309 noti_cb_list = g_list_first(noti_cb_list);
310 delete_cb_list = g_list_find_custom(noti_cb_list, (gconstpointer)changed_cb,
311 (GCompareFunc)_noti_changed_compare);
312 if (delete_cb_list) {
313 noti_cb_info = g_list_nth_data(delete_cb_list, 0);
314 noti_cb_list = g_list_delete_link(noti_cb_list, delete_cb_list);
315 __free_changed_cb_info(noti_cb_info);
317 if (noti_cb_list == NULL) {
318 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
320 noti_cb_list = g_list_first(noti_cb_list);
321 g_hash_table_replace(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
325 return NOTIFICATION_ERROR_INVALID_PARAMETER;
328 if (g_hash_table_size(_noti_cb_hash) == 0)
329 notification_ipc_monitor_fini();
331 return NOTIFICATION_ERROR_NONE;
334 EXPORT_API int notification_unresister_changed_cb(
335 void (*changed_cb)(void *data, notification_type_e type))
337 return notification_unresister_changed_cb_for_uid(changed_cb, getuid());
340 EXPORT_API int notification_update_progress(notification_h noti,
347 double input_progress;
349 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
351 return NOTIFICATION_ERROR_INVALID_PARAMETER;
353 input_priv_id = noti->priv_id;
355 input_priv_id = priv_id;
359 caller_app_id = notification_get_app_id_by_pid(getpid());
361 caller_app_id = strdup(noti->caller_app_id);
364 input_progress = 0.0;
365 else if (progress > 1.0)
366 input_progress = 1.0;
368 input_progress = progress;
370 ret = notification_ongoing_update_progress(caller_app_id, input_priv_id,
379 EXPORT_API int notification_update_size(notification_h noti,
388 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
390 return NOTIFICATION_ERROR_INVALID_PARAMETER;
392 input_priv_id = noti->priv_id;
394 input_priv_id = priv_id;
398 caller_app_id = notification_get_app_id_by_pid(getpid());
400 caller_app_id = strdup(noti->caller_app_id);
407 ret = notification_ongoing_update_size(caller_app_id, input_priv_id,
416 EXPORT_API int notification_update_content(notification_h noti,
424 if (priv_id <= NOTIFICATION_PRIV_ID_NONE) {
426 return NOTIFICATION_ERROR_INVALID_PARAMETER;
428 input_priv_id = noti->priv_id;
430 input_priv_id = priv_id;
434 caller_app_id = notification_get_app_id_by_pid(getpid());
436 caller_app_id = strdup(noti->caller_app_id);
438 ret = notification_ongoing_update_content(caller_app_id, input_priv_id,
448 /* notification_set_icon will be removed */
449 /* LCOV_EXCL_START */
450 EXPORT_API int notification_set_icon(notification_h noti,
451 const char *icon_path)
453 return notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
457 /* notification_get_icon will be removed */
458 /* LCOV_EXCL_START */
459 EXPORT_API int notification_get_icon(notification_h noti,
462 int ret = NOTIFICATION_ERROR_NONE;
463 char *ret_image_path = NULL;
465 ret = notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
468 if (ret == NOTIFICATION_ERROR_NONE && icon_path != NULL)
469 *icon_path = ret_image_path;
475 /* LCOV_EXCL_START */
476 EXPORT_API int notification_translate_localized_text(notification_h noti)
478 int ret = NOTIFICATION_ERROR_NONE;
479 char *ret_text = NULL;
481 char *bundle_val = NULL;
484 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
486 noti->is_translation = false;
488 for (; type <= NOTIFICATION_TEXT_TYPE_MAX; type++) {
489 ret = notification_get_text(noti, type, &ret_text);
490 if (ret == NOTIFICATION_ERROR_NONE && ret_text) {
491 if (noti->b_text == NULL) {
492 noti->b_text = bundle_create();
493 if (noti->b_text == NULL)
494 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
499 new_text = strdup(ret_text);
501 snprintf(buf_key, sizeof(buf_key), "%d", type);
502 bundle_get_str(b, buf_key, &bundle_val);
503 if (bundle_val != NULL)
504 bundle_del(b, buf_key);
506 bundle_add_str(b, buf_key, new_text);
510 noti->num_format_args = 0;
515 noti->is_translation = true;
521 /* LCOV_EXCL_START */
522 EXPORT_API int notification_set_title(notification_h noti,
524 const char *loc_title)
526 return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
528 NOTIFICATION_VARIABLE_TYPE_NONE);
532 /* LCOV_EXCL_START */
533 EXPORT_API int notification_get_title(notification_h noti,
538 char *ret_text = NULL;
540 ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
546 if (loc_title != NULL)
553 /* LCOV_EXCL_START */
554 EXPORT_API int notification_set_content(notification_h noti,
556 const char *loc_content)
558 return notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
559 content, loc_content,
560 NOTIFICATION_VARIABLE_TYPE_NONE);
564 /* LCOV_EXCL_START */
565 EXPORT_API int notification_get_content(notification_h noti,
570 char *ret_text = NULL;
572 ret = notification_get_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
578 if (loc_content != NULL)
585 /* LCOV_EXCL_START */
586 EXPORT_API int notification_set_application(notification_h noti,
589 if (noti == NULL || app_id == NULL)
590 return NOTIFICATION_ERROR_INVALID_PARAMETER;
592 if (noti->launch_app_id)
593 free(noti->launch_app_id);
595 noti->launch_app_id = strdup(app_id);
597 return NOTIFICATION_ERROR_NONE;
601 /* LCOV_EXCL_START */
602 EXPORT_API int notification_get_application(notification_h noti,
605 if (noti == NULL || app_id == NULL)
606 return NOTIFICATION_ERROR_INVALID_PARAMETER;
608 if (noti->launch_app_id)
609 *app_id = noti->launch_app_id;
611 *app_id = noti->caller_app_id;
613 return NOTIFICATION_ERROR_NONE;
617 /* LCOV_EXCL_START */
618 EXPORT_API int notification_set_args(notification_h noti, bundle *args,
621 if (noti == NULL || args == NULL)
622 return NOTIFICATION_ERROR_INVALID_PARAMETER;
625 bundle_free(noti->args);
627 noti->args = bundle_dup(args);
629 if (noti->group_args) {
630 bundle_free(noti->group_args);
631 noti->group_args = NULL;
634 if (group_args != NULL)
635 noti->group_args = bundle_dup(group_args);
637 return NOTIFICATION_ERROR_NONE;
641 /* LCOV_EXCL_START */
642 EXPORT_API int notification_get_args(notification_h noti,
646 if (noti == NULL || args == NULL)
647 return NOTIFICATION_ERROR_INVALID_PARAMETER;
654 if (group_args != NULL && noti->group_args)
655 *group_args = noti->group_args;
657 return NOTIFICATION_ERROR_NONE;
661 /* LCOV_EXCL_START */
662 int notification_get_grouping_list_for_uid(notification_type_e type, int count,
663 notification_list_h *list, uid_t uid)
665 notification_list_h get_list = NULL;
669 return NOTIFICATION_ERROR_INVALID_PARAMETER;
671 ret = notification_noti_get_grouping_list(type, 1, count, &get_list, NULL, uid);
672 if (ret != NOTIFICATION_ERROR_NONE)
677 return NOTIFICATION_ERROR_NONE;
680 EXPORT_API int notification_get_grouping_list(notification_type_e type, int count,
681 notification_list_h *list)
683 return notification_get_grouping_list_for_uid(type, count, list, getuid());
687 /* LCOV_EXCL_START */
688 EXPORT_API int notification_delete_group_by_group_id(const char *app_id,
689 notification_type_e type,
696 caller_app_id = notification_get_app_id_by_pid(getpid());
698 caller_app_id = strdup(app_id);
700 ret = notification_ipc_request_delete_multiple(type, caller_app_id, getuid());
709 /* LCOV_EXCL_START */
710 int notification_delete_group_by_priv_id_for_uid(const char *app_id,
711 notification_type_e type,
712 int priv_id, uid_t uid)
718 caller_app_id = notification_get_app_id_by_pid(getpid());
720 caller_app_id = strdup(app_id);
722 ret = notification_ipc_request_delete_single(type, caller_app_id, priv_id, uid);
731 /* LCOV_EXCL_START */
732 EXPORT_API int notification_delete_group_by_priv_id(const char *app_id,
733 notification_type_e type,
736 return notification_delete_group_by_priv_id_for_uid(app_id, type, priv_id, getuid());
739 int notification_get_count_for_uid(notification_type_e type,
742 int priv_id, int *count,
749 return NOTIFICATION_ERROR_INVALID_PARAMETER;
752 caller_app_id = notification_get_app_id_by_pid(getpid());
754 caller_app_id = strdup(app_id);
756 ret = notification_ipc_request_get_count(
771 /* LCOV_EXCL_START */
772 EXPORT_API int notification_get_count(notification_type_e type,
775 int priv_id, int *count)
777 return notification_get_count_for_uid(type, app_id, group_id, priv_id, count, getuid());
780 int notification_clear_for_uid(notification_type_e type, uid_t uid)
782 if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
783 return NOTIFICATION_ERROR_INVALID_PARAMETER;
785 return notification_ipc_request_delete_multiple(type, NULL, uid);
789 /* LCOV_EXCL_START */
790 EXPORT_API int notification_clear(notification_type_e type)
792 return notification_clear_for_uid(type, getuid());
795 EXPORT_API int notification_op_get_data(notification_op *noti_op, notification_op_data_type_e type,
798 if (noti_op == NULL || data == NULL)
799 return NOTIFICATION_ERROR_INVALID_PARAMETER;
802 case NOTIFICATION_OP_DATA_TYPE:
803 *((int *)data) = noti_op->type;
805 case NOTIFICATION_OP_DATA_PRIV_ID:
806 *((int *)data) = noti_op->priv_id;
808 case NOTIFICATION_OP_DATA_NOTI:
809 *((notification_h *)data) = noti_op->noti;
811 case NOTIFICATION_OP_DATA_EXTRA_INFO_1:
812 *((int *)data) = noti_op->extra_info_1;
814 case NOTIFICATION_OP_DATA_EXTRA_INFO_2:
815 *((int *)data) = noti_op->extra_info_2;
818 return NOTIFICATION_ERROR_INVALID_PARAMETER;
821 return NOTIFICATION_ERROR_NONE;
825 /* LCOV_EXCL_START */
826 EXPORT_API int notification_set_pkgname(notification_h noti,
829 return notification_set_app_id(noti, pkgname);
833 /* LCOV_EXCL_START */
834 EXPORT_API int notification_set_app_id(notification_h noti,
837 if (noti == NULL || app_id == NULL)
838 return NOTIFICATION_ERROR_INVALID_PARAMETER;
840 /* Remove previous caller app_id */
841 if (noti->caller_app_id) {
842 free(noti->caller_app_id);
843 noti->caller_app_id = NULL;
846 noti->caller_app_id = strdup(app_id);
848 return NOTIFICATION_ERROR_NONE;
852 /* LCOV_EXCL_START */
853 int notification_delete_all_by_type_for_uid(const char *app_id,
854 notification_type_e type, uid_t uid)
859 if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
860 return NOTIFICATION_ERROR_INVALID_PARAMETER;
863 caller_app_id = notification_get_app_id_by_pid(getpid());
865 caller_app_id = strdup(app_id);
867 ret = notification_ipc_request_delete_multiple(type, caller_app_id, uid);
876 /* LCOV_EXCL_START */
877 EXPORT_API int notification_delete_all_by_type(const char *app_id,
878 notification_type_e type)
880 return notification_delete_all_by_type_for_uid(app_id, type, getuid());
883 int notification_delete_by_priv_id_for_uid(const char *app_id,
884 notification_type_e type,
891 if (priv_id <= NOTIFICATION_PRIV_ID_NONE)
892 return NOTIFICATION_ERROR_INVALID_PARAMETER;
895 caller_app_id = notification_get_app_id_by_pid(getpid());
897 caller_app_id = strdup(app_id);
899 ret = notification_ipc_request_delete_single(type, caller_app_id, priv_id, uid);
908 /* LCOV_EXCL_START */
909 EXPORT_API int notification_delete_by_priv_id(const char *app_id,
910 notification_type_e type,
913 return notification_delete_by_priv_id_for_uid(app_id, type, priv_id, getuid());
916 EXPORT_API int notification_set_execute_option(notification_h noti,
917 notification_execute_type_e type,
920 bundle *service_handle)
922 char buf_key[32] = { 0, };
923 char *ret_val = NULL;
927 return NOTIFICATION_ERROR_INVALID_PARAMETER;
929 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
930 || type > NOTIFICATION_EXECUTE_TYPE_MAX)
931 return NOTIFICATION_ERROR_INVALID_PARAMETER;
933 if (noti->b_execute_option == NULL)
934 noti->b_execute_option = bundle_create();
936 b = noti->b_execute_option;
939 snprintf(buf_key, sizeof(buf_key), "text%d", type);
941 bundle_get_str(b, buf_key, &ret_val);
943 bundle_del(b, buf_key);
945 bundle_add_str(b, buf_key, text);
949 snprintf(buf_key, sizeof(buf_key), "key%d", type);
951 bundle_get_str(b, buf_key, &ret_val);
953 bundle_del(b, buf_key);
955 bundle_add_str(b, buf_key, key);
959 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
960 if (noti->b_service_responding != NULL) {
961 bundle_free(noti->b_service_responding);
962 noti->b_service_responding = NULL;
965 if (service_handle != NULL)
966 noti->b_service_responding = bundle_dup(service_handle);
969 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
970 if (noti->b_service_single_launch != NULL) {
971 bundle_free(noti->b_service_single_launch);
972 noti->b_service_single_launch = NULL;
975 if (service_handle != NULL)
976 noti->b_service_single_launch =
977 bundle_dup(service_handle);
980 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
981 if (noti->b_service_multi_launch != NULL) {
982 bundle_free(noti->b_service_multi_launch);
983 noti->b_service_multi_launch = NULL;
986 if (service_handle != NULL)
987 noti->b_service_multi_launch =
988 bundle_dup(service_handle);
993 return NOTIFICATION_ERROR_NONE;
997 /* LCOV_EXCL_START */
998 EXPORT_API int notification_get_id(notification_h noti,
999 int *group_id, int *priv_id)
1002 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1005 if (noti->group_id < NOTIFICATION_GROUP_ID_NONE)
1006 *group_id = NOTIFICATION_GROUP_ID_NONE;
1008 *group_id = noti->group_id;
1012 *priv_id = noti->priv_id;
1014 return NOTIFICATION_ERROR_NONE;
1016 /* LCOV_EXCL_STOP */
1018 /* LCOV_EXCL_START */
1019 EXPORT_API int notification_set_priv_id(notification_h noti, int priv_id)
1021 if (noti == NULL || priv_id <= 0)
1022 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1024 noti->priv_id = priv_id;
1026 return NOTIFICATION_ERROR_NONE;
1028 /* LCOV_EXCL_STOP */
1030 /* LCOV_EXCL_START */
1031 notification_h notification_load_for_uid(char *app_id,
1032 int priv_id, uid_t uid)
1035 notification_h noti;
1037 noti = (notification_h)calloc(1, sizeof(struct _notification));
1039 ERR("Failed to alloc memory");
1040 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1044 ret = notification_ipc_request_load_noti_by_priv_id(noti, app_id, priv_id, uid);
1045 if (ret != NOTIFICATION_ERROR_NONE) {
1046 notification_free(noti);
1047 set_last_result(ret);
1051 set_last_result(NOTIFICATION_ERROR_NONE);
1055 /* LCOV_EXCL_STOP */
1057 /* LCOV_EXCL_START */
1058 EXPORT_API notification_h notification_load(char *app_id,
1061 return notification_load_for_uid(app_id, priv_id, getuid());
1063 /* LCOV_EXCL_STOP */
1065 /* LCOV_EXCL_START */
1066 EXPORT_API notification_h notification_new(notification_type_e type,
1067 int group_id, int priv_id)
1069 return notification_create(type);
1072 static void _notification_get_text_domain(notification_h noti)
1075 /* LCOV_EXCL_STOP */
1077 /* LCOV_EXCL_START */
1078 EXPORT_API int notification_get_execute_option(notification_h noti,
1079 notification_execute_type_e type,
1081 bundle **service_handle)
1083 char buf_key[32] = { 0, };
1084 char *ret_val = NULL;
1085 char *get_str = NULL;
1089 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1091 if (type <= NOTIFICATION_EXECUTE_TYPE_NONE
1092 || type > NOTIFICATION_EXECUTE_TYPE_MAX)
1093 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1096 case NOTIFICATION_EXECUTE_TYPE_RESPONDING:
1097 b = noti->b_service_responding;
1099 case NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH:
1100 b = noti->b_service_single_launch;
1102 case NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH:
1103 b = noti->b_service_multi_launch;
1111 if (noti->domain == NULL || noti->dir == NULL)
1112 _notification_get_text_domain(noti);
1114 snprintf(buf_key, sizeof(buf_key), "key%d", type);
1116 bundle_get_str(b, buf_key, &ret_val);
1117 if (ret_val != NULL && noti->domain != NULL
1118 && noti->dir != NULL) {
1119 bindtextdomain(noti->domain, noti->dir);
1121 get_str = dgettext(noti->domain, ret_val);
1124 } else if (ret_val != NULL) {
1125 get_str = dgettext("sys_string", ret_val);
1129 snprintf(buf_key, sizeof(buf_key), "text%d",
1132 bundle_get_str(b, buf_key, &ret_val);
1139 if (service_handle != NULL)
1140 *service_handle = b;
1142 return NOTIFICATION_ERROR_NONE;
1144 /* LCOV_EXCL_STOP */
1146 /* LCOV_EXCL_START */
1147 EXPORT_API int notification_insert_for_uid(notification_h noti,
1148 int *priv_id, uid_t uid)
1154 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1156 if (noti->type <= NOTIFICATION_TYPE_NONE
1157 || noti->type > NOTIFICATION_TYPE_MAX)
1158 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1161 noti->insert_time = time(NULL);
1163 ret = notification_ipc_request_insert(noti, &id);
1164 if (ret != NOTIFICATION_ERROR_NONE)
1169 /* If priv_id is valid data, set priv_id */
1170 if (priv_id != NULL)
1171 *priv_id = noti->priv_id;
1173 return NOTIFICATION_ERROR_NONE;
1176 EXPORT_API int notification_insert(notification_h noti,
1179 return notification_insert_for_uid(noti, priv_id, getuid());
1182 EXPORT_API int notification_update_async_for_uid(notification_h noti,
1183 void (*result_cb)(int priv_id, int result, void *data), void *user_data, uid_t uid)
1186 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1189 /* Update insert time ? */
1190 noti->insert_time = time(NULL);
1192 return notification_ipc_request_update_async(noti, result_cb, user_data);
1195 EXPORT_API int notification_update_async(notification_h noti,
1196 void (*result_cb)(int priv_id, int result, void *data), void *user_data)
1198 return notification_update_async_for_uid(noti, result_cb, user_data, getuid());
1200 /* LCOV_EXCL_STOP */
1202 /* LCOV_EXCL_START */
1203 EXPORT_API int notification_register_detailed_changed_cb_for_uid(
1204 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1205 void *user_data, uid_t uid)
1207 GList *noti_cb_list = NULL;
1208 notification_cb_info_s *noti_cb_info_new = NULL;
1210 if (detailed_changed_cb == NULL)
1211 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1213 if (_noti_cb_hash == NULL)
1214 _noti_cb_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
1216 noti_cb_info_new = (notification_cb_info_s *)malloc(sizeof(notification_cb_info_s));
1217 if (noti_cb_info_new == NULL) {
1218 ERR("Failed to alloc memory");
1219 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1222 noti_cb_info_new->cb_type = NOTIFICATION_CB_DETAILED;
1223 noti_cb_info_new->changed_cb = NULL;
1224 noti_cb_info_new->detailed_changed_cb = detailed_changed_cb;
1225 noti_cb_info_new->data = user_data;
1227 noti_cb_list = g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1229 if (noti_cb_list == NULL) {
1230 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1231 g_hash_table_insert(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1233 noti_cb_list = g_list_append(noti_cb_list, noti_cb_info_new);
1236 if (notification_ipc_monitor_init(uid) != NOTIFICATION_ERROR_NONE) {
1237 notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, uid);
1238 return NOTIFICATION_ERROR_IO_ERROR;
1241 return NOTIFICATION_ERROR_NONE;
1243 /* LCOV_EXCL_STOP */
1245 /* LCOV_EXCL_START */
1246 EXPORT_API int notification_register_detailed_changed_cb(
1247 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1250 return notification_register_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1253 static gint _noti_detailed_changed_compare(gconstpointer a, gconstpointer b)
1255 const struct _notification_cb_info *info = NULL;
1259 info = (notification_cb_info_s *)a;
1261 if (info->detailed_changed_cb == b)
1267 EXPORT_API int notification_unregister_detailed_changed_cb_for_uid(
1268 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1269 void *user_data, uid_t uid)
1271 notification_cb_info_s *noti_cb_info;
1272 GList *noti_cb_list;
1273 GList *delete_cb_list;
1275 if (detailed_changed_cb == NULL)
1276 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1278 if (_noti_cb_hash == NULL)
1279 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1281 noti_cb_list = (GList *)g_hash_table_lookup(_noti_cb_hash, GUINT_TO_POINTER(uid));
1283 if (noti_cb_list == NULL)
1284 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1286 noti_cb_list = g_list_first(noti_cb_list);
1287 delete_cb_list = g_list_find_custom(noti_cb_list, (gconstpointer)detailed_changed_cb,
1288 (GCompareFunc)_noti_detailed_changed_compare);
1290 if (delete_cb_list) {
1291 noti_cb_info = (notification_cb_info_s *)g_list_nth_data(delete_cb_list, 0);
1292 noti_cb_list = g_list_delete_link(noti_cb_list, delete_cb_list);
1293 __free_changed_cb_info(noti_cb_info);
1294 if (noti_cb_list == NULL) {
1295 g_hash_table_steal(_noti_cb_hash, GUINT_TO_POINTER(uid));
1297 noti_cb_list = g_list_first(noti_cb_list);
1298 g_hash_table_replace(_noti_cb_hash, GUINT_TO_POINTER(uid), noti_cb_list);
1302 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1305 if (g_hash_table_size(_noti_cb_hash) == 0)
1306 notification_ipc_monitor_fini();
1308 return NOTIFICATION_ERROR_NONE;
1312 EXPORT_API int notification_unregister_detailed_changed_cb(
1313 void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
1316 return notification_unregister_detailed_changed_cb_for_uid(detailed_changed_cb, user_data, getuid());
1318 /* LCOV_EXCL_STOP */
1320 /* LCOV_EXCL_START */
1321 EXPORT_API int notification_is_service_ready(void)
1323 return notification_ipc_is_master_ready();
1325 /* LCOV_EXCL_STOP */
1327 /* LCOV_EXCL_START */
1328 EXPORT_API int notification_set_uid(notification_h noti,
1332 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1335 return NOTIFICATION_ERROR_NONE;
1338 EXPORT_API int notification_get_uid(notification_h noti,
1341 if (noti == NULL || uid == NULL)
1342 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1345 return NOTIFICATION_ERROR_NONE;
1348 static GList *__copy_private_file(notification_h noti)
1356 GList *file_list = NULL;
1359 if (noti->b_priv_image_path && noti->b_image_path) {
1360 dst_b = noti->b_priv_image_path;
1361 src_b = noti->b_image_path;
1362 for (i = NOTIFICATION_IMAGE_TYPE_ICON; i <= NOTIFICATION_IMAGE_TYPE_MAX; i++) {
1366 snprintf(buf_key, sizeof(buf_key), "%d", i);
1368 bundle_get_str(dst_b, buf_key, &dst_path);
1369 if (dst_path == NULL)
1372 bundle_get_str(src_b, buf_key, &src_path);
1373 if (src_path == NULL)
1376 ret = notification_copy_private_file(src_path, dst_path);
1377 if (ret == NOTIFICATION_ERROR_NONE)
1378 file_list = g_list_append(file_list, strdup(dst_path));
1381 if (noti->sound_path && noti->priv_sound_path) {
1382 ret = notification_copy_private_file(noti->sound_path,
1383 noti->priv_sound_path);
1384 if (ret == NOTIFICATION_ERROR_NONE)
1385 file_list = g_list_append(file_list,
1386 strdup(noti->priv_sound_path));
1389 if (noti->vibration_path && noti->priv_vibration_path) {
1390 ret = notification_copy_private_file(noti->vibration_path,
1391 noti->priv_vibration_path);
1392 if (ret == NOTIFICATION_ERROR_NONE)
1393 file_list = g_list_append(file_list,
1394 strdup(noti->priv_vibration_path));
1399 /* LCOV_EXCL_STOP */
1401 /* LCOV_EXCL_START */
1402 static void __remove_private_file(gpointer data, gpointer user_data)
1405 char *path = (char *)data;
1407 src = g_file_new_for_path(path);
1409 g_file_delete(src, NULL, NULL);
1410 g_object_unref(src);
1413 /* LCOV_EXCL_STOP */
1415 /* LCOV_EXCL_START */
1416 EXPORT_API int notification_post_for_uid(notification_h noti, uid_t uid)
1423 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1425 if (noti->type <= NOTIFICATION_TYPE_NONE
1426 || noti->type > NOTIFICATION_TYPE_MAX)
1427 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1429 /* Save insert time */
1430 noti->insert_time = time(NULL);
1433 file_list = __copy_private_file(noti);
1434 ret = notification_ipc_request_insert(noti, &id);
1435 if (ret == NOTIFICATION_ERROR_NONE) {
1437 INFO("Posted notification id[%d]", id);
1439 g_list_foreach(file_list, __remove_private_file, NULL);
1443 g_list_free_full(file_list, free);
1448 EXPORT_API int notification_update_for_uid(notification_h noti, uid_t uid)
1451 notification_ipc_request_refresh(uid);
1452 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1456 /* Update insert time ? */
1457 noti->insert_time = time(NULL);
1458 WARN("updated notification id[%d]", noti->priv_id);
1460 return notification_ipc_request_update(noti);
1463 EXPORT_API int notification_delete_for_uid(notification_h noti, uid_t uid)
1466 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1468 return notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE,
1469 noti->caller_app_id, noti->priv_id, uid);
1472 EXPORT_API int notification_delete_all_for_uid(notification_type_e type, uid_t uid)
1475 char *caller_app_id = NULL;
1477 if (type <= NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX)
1478 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1480 caller_app_id = notification_get_app_id_by_pid(getpid());
1482 ret = notification_ipc_request_delete_multiple(type, caller_app_id, uid);
1485 free(caller_app_id);
1489 /* LCOV_EXCL_STOP */
1491 /* LCOV_EXCL_START */
1492 EXPORT_API notification_h notification_load_by_tag_for_uid(const char *tag, uid_t uid)
1495 notification_h noti;
1496 char *caller_app_id;
1500 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1504 caller_app_id = notification_get_app_id_by_pid(getpid());
1505 if (!caller_app_id) {
1506 ERR("Failed to get a package name");
1507 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1511 noti = (notification_h)calloc(1, sizeof(struct _notification));
1513 ERR("Failed to alloc a new notification");
1514 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1515 free(caller_app_id);
1520 ret = notification_ipc_request_load_noti_by_tag(noti, caller_app_id, (char *)tag, uid);
1521 free(caller_app_id);
1523 set_last_result(ret);
1524 if (ret != NOTIFICATION_ERROR_NONE) {
1525 notification_free(noti);
1531 /* LCOV_EXCL_STOP */
1533 /* LCOV_EXCL_START */
1534 EXPORT_API notification_h notification_create_from_package_template(const char *app_id, const char *template_name)
1537 notification_h noti;
1539 if (app_id == NULL || template_name == NULL) {
1540 ERR("Invalid parameter");
1541 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1545 noti = (notification_h)calloc(1, sizeof(struct _notification));
1547 ERR("Failed to alloc memory");
1548 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1552 ret = notification_ipc_request_create_from_package_template(noti, app_id, template_name);
1553 set_last_result(ret);
1554 if (ret != NOTIFICATION_ERROR_NONE) {
1555 notification_free(noti);
1561 /* LCOV_EXCL_STOP */
1563 /* LCOV_EXCL_START */
1564 EXPORT_API int notification_set_default_button(notification_h noti, notification_button_index_e index)
1567 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1569 if (index < 0 || index > NOTIFICATION_BUTTON_6)
1570 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1572 noti->default_button_index = index;
1574 return NOTIFICATION_ERROR_NONE;
1577 EXPORT_API int notification_get_default_button(notification_h noti, notification_button_index_e *index)
1579 if (noti == NULL || index == NULL)
1580 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1582 *index = noti->default_button_index;
1584 return NOTIFICATION_ERROR_NONE;
1587 EXPORT_API int notification_get_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e *type)
1589 if (noti == NULL || type == NULL)
1590 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1592 *type = noti->ongoing_value_type;
1594 return NOTIFICATION_ERROR_NONE;
1597 EXPORT_API int notification_set_ongoing_value_type(notification_h noti, notification_ongoing_value_type_e type)
1600 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1602 if (type < NOTIFICATION_ONGOING_VALUE_TYPE_PERCENT || type > NOTIFICATION_ONGOING_VALUE_TYPE_TIME)
1603 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1605 noti->ongoing_value_type = type;
1607 return NOTIFICATION_ERROR_NONE;
1610 EXPORT_API int notification_get_ongoing_time(notification_h noti, int *current, int *duration)
1612 if (noti == NULL || current == NULL || duration == NULL)
1613 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1615 *current = noti->ongoing_current;
1616 *duration = noti->ongoing_duration;
1618 return NOTIFICATION_ERROR_NONE;
1621 EXPORT_API int notification_set_ongoing_time(notification_h noti, int current, int duration)
1624 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1626 if (current < 0 || duration < 0 || current > duration)
1627 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1629 noti->ongoing_current = current;
1630 noti->ongoing_duration = duration;
1632 return NOTIFICATION_ERROR_NONE;
1635 EXPORT_API int notification_get_hide_timeout(notification_h noti, int *timeout)
1637 if (noti == NULL || timeout == NULL)
1638 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1640 *timeout = noti->hide_timeout;
1642 return NOTIFICATION_ERROR_NONE;
1645 EXPORT_API int notification_set_hide_timeout(notification_h noti, int timeout)
1647 if (noti == NULL || timeout < 0)
1648 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1650 noti->hide_timeout = timeout;
1652 return NOTIFICATION_ERROR_NONE;
1655 EXPORT_API int notification_get_delete_timeout(notification_h noti, int *timeout)
1657 if (noti == NULL || timeout == NULL)
1658 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1660 *timeout = noti->delete_timeout;
1662 return NOTIFICATION_ERROR_NONE;
1665 EXPORT_API int notification_set_delete_timeout(notification_h noti, int timeout)
1667 if (noti == NULL || timeout < 0)
1668 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1670 noti->delete_timeout = timeout;
1672 return NOTIFICATION_ERROR_NONE;
1675 EXPORT_API int notification_get_text_input_max_length(notification_h noti, int *text_input_max_length)
1677 if (noti == NULL || text_input_max_length == NULL)
1678 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1680 *text_input_max_length = noti->text_input_max_length;
1682 return NOTIFICATION_ERROR_NONE;
1684 /* LCOV_EXCL_STOP */
1686 /* LCOV_EXCL_START */
1687 EXPORT_API int notification_post_with_event_cb_for_uid(notification_h noti, event_handler_cb cb,
1688 void *userdata, uid_t uid)
1692 notification_event_cb_info_s *info = NULL;
1695 if (noti == NULL || cb == NULL)
1696 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1698 if (noti->type <= NOTIFICATION_TYPE_NONE || noti->type > NOTIFICATION_TYPE_MAX)
1699 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1701 noti->insert_time = time(NULL);
1702 noti->event_flag = true;
1705 ret = notification_ipc_request_insert(noti, &priv_id);
1706 if (ret != NOTIFICATION_ERROR_NONE)
1709 noti->priv_id = priv_id;
1711 WARN("Posted notification id[%d]", priv_id);
1713 __noti_event_cb_list = g_list_first(__noti_event_cb_list);
1714 find_list = g_list_find_custom(__noti_event_cb_list, GINT_TO_POINTER(priv_id),
1715 (GCompareFunc)__priv_id_compare);
1718 info = g_list_nth_data(find_list, 0);
1720 info->userdata = userdata;
1721 WARN("event cb is existed id[%d]", priv_id);
1723 info = (notification_event_cb_info_s *)malloc(sizeof(notification_event_cb_info_s));
1725 ERR("Failed to alloc memory");
1726 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1728 info->priv_id = priv_id;
1730 info->userdata = userdata;
1731 __noti_event_cb_list = g_list_append(__noti_event_cb_list, info);
1732 WARN("new event cb appended id[%d]", priv_id);
1737 /* LCOV_EXCL_STOP */
1739 /* LCOV_EXCL_START */
1740 EXPORT_API int notification_post_with_event_cb(notification_h noti, event_handler_cb cb, void *userdata)
1742 return notification_post_with_event_cb_for_uid(noti, cb, userdata, getuid());
1745 EXPORT_API int notification_send_event(notification_h noti, int event_type)
1751 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1753 if (!((event_type >= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1754 && event_type <= NOTIFICATION_EVENT_TYPE_MAX) ||
1755 (event_type >= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER
1756 && event_type <= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) ||
1757 (event_type >= NOTIFICATION_EVENT_TYPE_PRESSED
1758 && event_type <= NOTIFICATION_EVENT_TYPE_DELETED) ||
1759 (event_type == NOTIFICATION_EVENT_TYPE_CHECK_BOX)))
1760 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1762 ret = notification_get_event_flag(noti, &event_flag);
1763 if (ret != NOTIFICATION_ERROR_NONE || event_flag == false)
1764 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1766 ret = notification_ipc_send_event(noti, event_type, -1);
1771 EXPORT_API int notification_send_event_by_priv_id(int priv_id, int event_type)
1776 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1778 if (!((event_type >= NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1779 && event_type <= NOTIFICATION_EVENT_TYPE_MAX) ||
1780 (event_type >= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER
1781 && event_type <= NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) ||
1782 (event_type >= NOTIFICATION_EVENT_TYPE_PRESSED
1783 && event_type <= NOTIFICATION_EVENT_TYPE_DELETED) ||
1784 (event_type == NOTIFICATION_EVENT_TYPE_CHECK_BOX)))
1785 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1787 ret = notification_ipc_send_event(NULL, event_type, priv_id);
1791 EXPORT_API int notification_get_event_flag(notification_h noti, bool *flag)
1793 if (noti == NULL || flag == NULL)
1794 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1796 *flag = noti->event_flag;
1798 return NOTIFICATION_ERROR_NONE;
1801 EXPORT_API int notification_check_event_receiver_available(notification_h noti, bool *available)
1806 if (noti == NULL || available == NULL)
1807 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1809 ret = notification_get_id(noti, NULL, &priv_id);
1810 if (ret != NOTIFICATION_ERROR_NONE) {
1811 ERR("Failed to get priv id");
1815 ret = notification_ipc_check_event_receiver(priv_id, available);
1820 static bundle *_create_bundle_from_bundle_raw(bundle_raw *string)
1822 if (string == NULL || string[0] == '\0')
1825 return bundle_decode(string, strlen((char *)string));
1828 EXPORT_API int notification_set_extention_data(notification_h noti, const char *key, bundle *value)
1830 return notification_set_extension_data(noti, key, value);
1833 EXPORT_API int notification_set_extension_data(notification_h noti, const char *key, bundle *value)
1838 bundle_raw *raw = NULL;
1840 if (noti == NULL || key == NULL)
1841 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1843 if (noti->args == NULL)
1844 noti->args = bundle_create();
1846 if (value == NULL) {
1847 ret = bundle_del(noti->args, key);
1848 if (ret == BUNDLE_ERROR_NONE)
1849 return NOTIFICATION_ERROR_NONE;
1851 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1854 bundle_get_str(noti->args, key, &del);
1856 bundle_del(noti->args, key);
1860 bundle_encode(value, &raw, &len);
1861 bundle_add_str(noti->args, key, (const char *)raw);
1862 bundle_free_encoded_rawdata(&raw);
1864 return NOTIFICATION_ERROR_NONE;
1867 EXPORT_API int notification_get_extention_data(notification_h noti, const char *key, bundle **value)
1869 return notification_get_extension_data(noti, key, value);
1872 EXPORT_API int notification_get_extension_data(notification_h noti, const char *key, bundle **value)
1878 if (noti == NULL || key == NULL || value == NULL)
1879 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1881 if (noti->args == NULL)
1882 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1886 ret = bundle_get_str(args, key, &ret_str);
1887 if (ret != BUNDLE_ERROR_NONE)
1888 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1890 *value = _create_bundle_from_bundle_raw((bundle_raw *)ret_str);
1892 return NOTIFICATION_ERROR_IO_ERROR;
1894 return NOTIFICATION_ERROR_NONE;
1896 /* LCOV_EXCL_STOP */
1899 #define EXTENSION_EVENT_KEY "_NOTIFICATION_EXTENSION_EVENT_"
1901 /* LCOV_EXCL_START */
1902 EXPORT_API int notification_set_extension_event_handler(notification_h noti,
1903 notification_event_type_extension_e event,
1904 app_control_h event_handler)
1907 int ret = NOTIFICATION_ERROR_NONE;
1909 bundle *app_control_bundle = NULL;
1910 bundle_raw *b_raw = NULL;
1914 if (noti == NULL || event_handler == NULL) {
1915 ERR("Invalid parameter");
1916 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1919 if (event < NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER ||
1920 event > NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) {
1921 ERR("Invalid event [%d]", event);
1922 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1925 if (noti->args == NULL)
1926 noti->args = bundle_create();
1928 snprintf(key, sizeof(key), "%s%d", EXTENSION_EVENT_KEY, event);
1929 bundle_get_str(noti->args, key, &del);
1931 bundle_del(noti->args, key);
1935 err = app_control_export_as_bundle(event_handler, &app_control_bundle);
1936 if (err != APP_CONTROL_ERROR_NONE) {
1937 ERR("Failed to export app_control to bundle [%d]", err);
1938 ret = NOTIFICATION_ERROR_IO_ERROR;
1942 err = bundle_encode(app_control_bundle, &b_raw, &len);
1943 if (err != BUNDLE_ERROR_NONE) {
1944 ERR("Failed to encode bundle [%d]", err);
1945 ret = NOTIFICATION_ERROR_IO_ERROR;
1949 err = bundle_add_str(noti->args, key, (const char *)b_raw);
1950 if (err != BUNDLE_ERROR_NONE) {
1951 ERR("Failed to add str to bundle [%d]", err);
1952 ret = NOTIFICATION_ERROR_IO_ERROR;
1958 bundle_free_encoded_rawdata(&b_raw);
1959 if (app_control_bundle)
1960 bundle_free(app_control_bundle);
1964 /* LCOV_EXCL_STOP */
1966 /* LCOV_EXCL_START */
1967 EXPORT_API int notification_get_extension_event_handler(notification_h noti,
1968 notification_event_type_extension_e event,
1969 app_control_h *event_handler)
1972 int ret = NOTIFICATION_ERROR_NONE;
1973 char *ret_str = NULL;
1975 bundle *app_control_bundle = NULL;
1976 app_control_h ret_app_control = NULL;
1978 if (noti == NULL || event_handler == NULL) {
1979 ERR("Invalid parameter");
1980 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1983 if (event < NOTIFICATION_EVENT_TYPE_HIDDEN_BY_USER ||
1984 event > NOTIFICATION_EVENT_TYPE_HIDDEN_BY_EXTERNAL) {
1985 ERR("Invalid event [%d]", event);
1986 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1989 snprintf(key, sizeof(key), "%s%d", EXTENSION_EVENT_KEY, event);
1991 bundle_get_str(noti->args, key, &ret_str);
1992 if (ret_str == NULL) {
1993 ERR("No handler, Invalid event[%d]", event);
1994 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1997 app_control_bundle = _create_bundle_from_bundle_raw((bundle_raw *)ret_str);
1998 if (app_control_bundle == NULL) {
1999 ERR("Failed to create bundle");
2000 return NOTIFICATION_ERROR_IO_ERROR;
2003 err = app_control_create(&ret_app_control);
2004 if (err != APP_CONTROL_ERROR_NONE) {
2005 ERR("Failed to create app control [%d]", err);
2006 ret = NOTIFICATION_ERROR_IO_ERROR;
2010 err = app_control_import_from_bundle(ret_app_control, app_control_bundle);
2011 if (err != APP_CONTROL_ERROR_NONE) {
2012 ERR("Failed to import app control from bundle [%d]", err);
2013 app_control_destroy(ret_app_control);
2014 ret = NOTIFICATION_ERROR_IO_ERROR;
2018 *event_handler = ret_app_control;
2021 if (app_control_bundle)
2022 bundle_free(app_control_bundle);
2026 /* LCOV_EXCL_STOP */
2028 /* LCOV_EXCL_START */
2029 EXPORT_API int notification_get_all_count_for_uid(notification_type_e type, int *count, uid_t uid)
2033 if (count == NULL) {
2034 ERR("Invalid parameter - count is null");
2035 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2038 if (type < NOTIFICATION_TYPE_NONE || type > NOTIFICATION_TYPE_MAX) {
2039 ERR("Invalid parameter - wrong type");
2040 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2043 ret = notification_ipc_request_get_all_count(type, count, uid);
2044 if (ret != NOTIFICATION_ERROR_NONE) {
2045 ERR("Failed to get count [%d]", ret);
2052 EXPORT_API int notification_get_all_count(notification_type_e type, int *count)
2054 return notification_get_all_count_for_uid(type, count, getuid());
2057 EXPORT_API int notification_set_app_label(notification_h noti, char *label)
2059 if (noti == NULL || label == NULL)
2060 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2062 if (noti->app_label)
2063 free(noti->app_label);
2065 noti->app_label = strdup(label);
2067 return NOTIFICATION_ERROR_NONE;
2070 EXPORT_API int notification_get_app_label(notification_h noti, char **label)
2072 if (noti == NULL || label == NULL)
2073 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2075 if (noti->app_label)
2076 *label = noti->app_label;
2078 return NOTIFICATION_ERROR_NONE;
2081 static void __set_caller_info(bundle *b, const char *appid, uid_t uid)
2083 pkgmgrinfo_appinfo_h handle;
2088 snprintf(buf, sizeof(buf), "%u", uid);
2089 bundle_del(b, AUL_K_ORG_CALLER_UID);
2090 bundle_add(b, AUL_K_ORG_CALLER_UID, buf);
2092 bundle_del(b, AUL_K_ORG_CALLER_APPID);
2093 bundle_add(b, AUL_K_ORG_CALLER_APPID, appid);
2095 r = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
2096 if (r != PMINFO_R_OK)
2099 pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
2101 bundle_del(b, AUL_K_ORG_CALLER_PKGID);
2102 bundle_add(b, AUL_K_ORG_CALLER_PKGID, pkgid);
2104 pkgmgrinfo_appinfo_destroy_appinfo(handle);
2107 static void __set_indirect_request(bundle *b)
2109 bundle_del(b, AUL_K_REQUEST_TYPE);
2110 bundle_add(b, AUL_K_REQUEST_TYPE, "indirect-request");
2113 EXPORT_API int notification_set_indirect_request(notification_h noti,
2114 pid_t pid, uid_t uid)
2116 char appid[256] = { 0, };
2120 if (noti == NULL || pid <= 1 || uid < REGULAR_UID_MIN)
2121 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2123 r = aul_app_get_appid_bypid(pid, appid, sizeof(appid));
2125 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2127 if (noti->b_service_responding) {
2128 __set_caller_info(noti->b_service_responding, appid, uid);
2129 __set_indirect_request(noti->b_service_responding);
2132 if (noti->b_service_single_launch) {
2133 __set_caller_info(noti->b_service_single_launch, appid, uid);
2134 __set_indirect_request(noti->b_service_single_launch);
2137 if (noti->b_service_multi_launch) {
2138 __set_caller_info(noti->b_service_multi_launch, appid, uid);
2139 __set_indirect_request(noti->b_service_multi_launch);
2142 for (i = 0; i <= NOTIFICATION_EVENT_TYPE_MAX; i++) {
2143 if (noti->b_event_handler[i]) {
2144 __set_caller_info(noti->b_event_handler[i], appid, uid);
2145 __set_indirect_request(noti->b_event_handler[i]);
2149 return NOTIFICATION_ERROR_NONE;
2153 int notification_delete_by_display_applist_for_uid(int display_applist, uid_t uid)
2155 if (display_applist < NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY)
2156 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2158 return notification_ipc_request_delete_by_display_applist(display_applist, uid);
2161 EXPORT_API int notification_delete_by_display_applist(int display_applist)
2163 return notification_delete_by_display_applist_for_uid(display_applist, getuid());
2166 EXPORT_API int notification_set_check_box(notification_h noti,
2167 bool flag, bool checked)
2170 ERR("Invalid parameter");
2171 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2174 noti->check_box = flag;
2175 noti->check_box_value = checked;
2177 return NOTIFICATION_ERROR_NONE;
2180 EXPORT_API int notification_get_check_box(notification_h noti,
2181 bool *flag, bool *checked)
2183 if (noti == NULL || flag == NULL || checked == NULL) {
2184 ERR("Invalid parameter");
2185 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2188 *flag = noti->check_box;
2189 *checked = noti->check_box_value;
2191 return NOTIFICATION_ERROR_NONE;
2194 EXPORT_API int notification_set_check_box_checked(notification_h noti,
2198 ERR("Invalid parameter");
2199 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2202 noti->check_box_value = checked;
2204 return NOTIFICATION_ERROR_NONE;
2207 EXPORT_API int notification_get_check_box_checked(notification_h noti,
2210 if (noti == NULL || checked == NULL) {
2211 ERR("Invalid parameter");
2212 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2215 if (noti->check_box)
2216 *checked = noti->check_box_value;
2220 return NOTIFICATION_ERROR_NONE;
2222 /* LCOV_EXCL_STOP */