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_internal.h>
28 #include <app_manager.h>
29 #include <app_control_internal.h>
30 #include <package_manager.h>
34 #include <vconf-keys.h>
37 #include <notification.h>
38 #include <notification_list.h>
39 #include <notification_debug.h>
40 #include <notification_private.h>
41 #include <notification_noti.h>
42 #include <notification_ongoing.h>
43 #include <notification_group.h>
44 #include <notification_ipc.h>
45 #include <notification_internal.h>
47 static void (*posted_toast_message_cb) (void *data);
49 #define NOTI_TEXT_RESULT_LEN 2048
50 #define NOTI_PKGNAME_LEN 512
52 #define REGULAR_UID_MIN 5000
54 char *notification_get_pkgname_by_pid(void)
56 char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
57 int pid = 0, ret = AUL_R_OK;
60 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
64 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
65 if (ret != AUL_R_OK) {
67 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
69 fd = open(buf, O_RDONLY);
73 ret = read(fd, pkgname, sizeof(pkgname) - 1);
82 * "ret" is not able to be larger than "sizeof(pkgname) - 1",
83 * if the system is not going wrong.
86 if (strlen(pkgname) <= 0)
90 dup_pkgname = strdup(pkgname);
92 NOTIFICATION_ERR("Heap: %d\n", errno);
97 EXPORT_API int notification_set_image(notification_h noti,
98 notification_image_type_e type,
99 const char *image_path)
102 char buf_key[32] = { 0, };
103 char *ret_val = NULL;
105 if (noti == NULL || image_path == NULL)
106 return NOTIFICATION_ERROR_INVALID_PARAMETER;
108 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
109 || type >= NOTIFICATION_IMAGE_TYPE_MAX)
110 return NOTIFICATION_ERROR_INVALID_PARAMETER;
112 if (noti->b_image_path) {
113 b = noti->b_image_path;
115 snprintf(buf_key, sizeof(buf_key), "%d", type);
117 bundle_get_str(b, buf_key, &ret_val);
119 bundle_del(b, buf_key);
121 bundle_add_str(b, buf_key, image_path);
125 snprintf(buf_key, sizeof(buf_key), "%d", type);
127 bundle_add_str(b, buf_key, image_path);
129 noti->b_image_path = b;
132 return NOTIFICATION_ERROR_NONE;
135 EXPORT_API int notification_get_image(notification_h noti,
136 notification_image_type_e type,
140 char buf_key[32] = { 0, };
141 char *ret_val = NULL;
143 if (noti == NULL || image_path == NULL)
144 return NOTIFICATION_ERROR_INVALID_PARAMETER;
146 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
147 || type >= NOTIFICATION_IMAGE_TYPE_MAX)
148 return NOTIFICATION_ERROR_INVALID_PARAMETER;
150 if (noti->b_image_path) {
151 b = noti->b_image_path;
153 snprintf(buf_key, sizeof(buf_key), "%d", type);
155 bundle_get_str(b, buf_key, &ret_val);
157 *image_path = ret_val;
159 /* If image path bundle does not exist, image path is NULL */
163 /* If image path is NULL and type is ICON, icon path set from AIL */
164 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
165 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
166 if (noti->app_icon_path != NULL)
167 *image_path = noti->app_icon_path;
172 return NOTIFICATION_ERROR_NONE;
175 EXPORT_API int notification_set_time(notification_h noti, time_t input_time)
178 return NOTIFICATION_ERROR_INVALID_PARAMETER;
181 noti->time = time(NULL);
183 noti->time = input_time;
185 return NOTIFICATION_ERROR_NONE;
188 EXPORT_API int notification_get_time(notification_h noti, time_t *ret_time)
190 if (noti == NULL || ret_time == NULL)
191 return NOTIFICATION_ERROR_INVALID_PARAMETER;
193 *ret_time = noti->time;
195 return NOTIFICATION_ERROR_NONE;
198 EXPORT_API int notification_get_insert_time(notification_h noti,
201 if (noti == NULL || ret_time == NULL)
202 return NOTIFICATION_ERROR_INVALID_PARAMETER;
204 *ret_time = noti->insert_time;
206 return NOTIFICATION_ERROR_NONE;
209 EXPORT_API int notification_set_text(notification_h noti,
210 notification_text_type_e type, const char *text,
211 const char *key, int args_type, ...)
214 char buf_key[32] = { 0, };
215 char buf_val[1024] = { 0, };
216 char *ret_val = NULL;
218 notification_variable_type_e var_type;
220 int noti_err = NOTIFICATION_ERROR_NONE;
221 int var_value_int = 0;
222 double var_value_double = 0.0;
223 char *var_value_string = NULL;
224 notification_count_pos_type_e var_value_count =
225 NOTIFICATION_COUNT_POS_NONE;
228 return NOTIFICATION_ERROR_INVALID_PARAMETER;
230 if (type <= NOTIFICATION_TEXT_TYPE_NONE
231 || type >= NOTIFICATION_TEXT_TYPE_MAX)
232 return NOTIFICATION_ERROR_INVALID_PARAMETER;
235 if (noti->b_text != NULL) {
238 snprintf(buf_key, sizeof(buf_key), "%d", type);
240 bundle_get_str(b, buf_key, &ret_val);
243 bundle_del(b, buf_key);
245 snprintf(buf_val, sizeof(buf_val), "%s", text);
247 bundle_add_str(b, buf_key, buf_val);
251 snprintf(buf_key, sizeof(buf_key), "%d", type);
252 snprintf(buf_val, sizeof(buf_val), "%s", text);
254 bundle_add_str(b, buf_key, buf_val);
259 if (noti->b_text != NULL) {
262 snprintf(buf_key, sizeof(buf_key), "%d", type);
264 bundle_get_str(b, buf_key, &ret_val);
266 bundle_del(b, buf_key);
271 if (noti->b_key != NULL) {
274 snprintf(buf_key, sizeof(buf_key), "%d", type);
276 bundle_get_str(b, buf_key, &ret_val);
278 bundle_del(b, buf_key);
280 snprintf(buf_val, sizeof(buf_val), "%s", key);
282 bundle_add_str(b, buf_key, buf_val);
286 snprintf(buf_key, sizeof(buf_key), "%d", type);
288 snprintf(buf_val, sizeof(buf_val), "%s", key);
290 bundle_add_str(b, buf_key, buf_val);
295 if (noti->b_key != NULL) {
298 snprintf(buf_key, sizeof(buf_key), "%d", type);
300 bundle_get_str(b, buf_key, &ret_val);
302 bundle_del(b, buf_key);
306 if (noti->b_format_args != NULL)
307 b = noti->b_format_args;
311 va_start(var_args, args_type);
313 var_type = args_type;
316 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
318 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
319 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
321 bundle_get_str(b, buf_key, &ret_val);
323 bundle_del(b, buf_key);
325 bundle_add_str(b, buf_key, buf_val);
328 case NOTIFICATION_VARIABLE_TYPE_INT:
329 var_value_int = va_arg(var_args, int);
332 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
334 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
336 bundle_get_str(b, buf_key, &ret_val);
338 bundle_del(b, buf_key);
340 bundle_add_str(b, buf_key, buf_val);
343 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
344 var_value_double = va_arg(var_args, double);
347 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
349 snprintf(buf_val, sizeof(buf_val), "%.2f",
352 bundle_get_str(b, buf_key, &ret_val);
354 bundle_del(b, buf_key);
356 bundle_add_str(b, buf_key, buf_val);
359 case NOTIFICATION_VARIABLE_TYPE_STRING:
360 var_value_string = va_arg(var_args, char *);
363 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
365 snprintf(buf_val, sizeof(buf_val), "%s",
368 bundle_get_str(b, buf_key, &ret_val);
370 bundle_del(b, buf_key);
372 bundle_add_str(b, buf_key, buf_val);
375 case NOTIFICATION_VARIABLE_TYPE_COUNT:
377 va_arg(var_args, notification_count_pos_type_e);
380 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
382 snprintf(buf_val, sizeof(buf_val), "%d",
385 bundle_get_str(b, buf_key, &ret_val);
387 bundle_del(b, buf_key);
389 bundle_add_str(b, buf_key, buf_val);
393 NOTIFICATION_ERR("Error. invalid variable type. : %d",
395 noti_err = NOTIFICATION_ERROR_INVALID_PARAMETER;
400 var_type = va_arg(var_args, notification_variable_type_e);
404 if (noti_err == NOTIFICATION_ERROR_NONE)
405 noti->num_format_args = num_args;
407 noti->num_format_args = 0;
409 snprintf(buf_key, sizeof(buf_key), "num%d", type);
410 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
412 bundle_get_str(b, buf_key, &ret_val);
414 bundle_del(b, buf_key);
416 bundle_add_str(b, buf_key, buf_val);
418 noti->b_format_args = b;
423 EXPORT_API int notification_get_text(notification_h noti,
424 notification_text_type_e type,
428 char buf_key[32] = { 0, };
429 char *ret_val = NULL;
430 char *get_str = NULL;
431 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
433 char *temp_str = NULL;
434 char *translated_str = NULL;
435 char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
436 char buf_str[1024] = { 0, };
438 notification_variable_type_e ret_var_type = 0;
439 int ret_variable_int = 0;
440 double ret_variable_double = 0.0;
444 if (noti == NULL || text == NULL)
445 return NOTIFICATION_ERROR_INVALID_PARAMETER;
447 if (type <= NOTIFICATION_TEXT_TYPE_NONE
448 || type >= NOTIFICATION_TEXT_TYPE_MAX)
449 return NOTIFICATION_ERROR_INVALID_PARAMETER;
452 if (noti->b_key != NULL) {
455 /* Get text domain and dir */
456 /* _notification_get_text_domain(noti); */
458 snprintf(buf_key, sizeof(buf_key), "%d", type);
460 bundle_get_str(b, buf_key, &ret_val);
461 if (ret_val != NULL && noti->domain != NULL
462 && noti->dir != NULL) {
463 /* Get application string */
464 bindtextdomain(noti->domain, noti->dir);
466 get_str = dgettext(noti->domain, ret_val);
467 if (get_str == ret_val) /* not found */
469 } else if (ret_val != NULL) {
470 /* Get system string */
471 get_str = dgettext("sys_string", ret_val);
472 if (get_str == ret_val) /* not found */
479 if (get_str == NULL && noti->b_text != NULL) {
482 snprintf(buf_key, sizeof(buf_key), "%d", type);
484 bundle_get_str(b, buf_key, &get_str);
487 if (get_str == NULL && ret_val != NULL)
488 get_str = ret_val; /* fallback for printing anything */
492 if (get_str != NULL) {
493 /* Get number format args */
494 b = noti->b_format_args;
495 noti->num_format_args = 0;
498 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
499 bundle_get_str(b, buf_key, &ret_val);
501 noti->num_format_args = atoi(ret_val);
504 if (noti->num_format_args == 0) {
505 *text = (char *)get_str;
507 /* Check first variable is count, LEFT pos */
508 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
509 check_type, num_args);
510 bundle_get_str(b, buf_key, &ret_val);
512 ret_var_type = atoi(ret_val);
514 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
516 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
517 check_type, num_args);
518 bundle_get_str(b, buf_key, &ret_val);
520 ret_variable_int = atoi(ret_val);
522 if (ret_variable_int ==
523 NOTIFICATION_COUNT_POS_LEFT) {
524 notification_get_count(noti->type,
525 noti->caller_pkgname,
529 snprintf(buf_str, sizeof(buf_str),
530 "%d ", ret_variable_int);
532 src_len = strlen(result_str);
533 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
535 strncat(result_str, buf_str,
541 /* Check variable IN pos */
542 for (temp_str = (char *)get_str; *temp_str != '\0';
544 if (*temp_str != '%') {
545 strncat(result_str, temp_str, 1);
547 if (*(temp_str + 1) == '%') {
548 strncat(result_str, temp_str,
550 } else if (*(temp_str + 1) == 'd') {
552 ret_variable_int = 0;
556 "%dtype%d", check_type,
558 bundle_get_str(b, buf_key, &ret_val);
560 ret_var_type = atoi(ret_val);
563 NOTIFICATION_VARIABLE_TYPE_COUNT) {
564 /* Get notification count */
565 notification_get_count(noti->type,
566 noti->caller_pkgname,
577 bundle_get_str(b, buf_key, &ret_val);
579 ret_variable_int = atoi(ret_val);
583 sizeof(buf_str), "%d",
586 src_len = strlen(result_str);
587 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
589 strncat(result_str, buf_str,
595 } else if (*(temp_str + 1) == 's') {
600 check_type, num_args);
601 bundle_get_str(b, buf_key, &ret_val);
603 if (ret_val != NULL && noti->domain != NULL && noti->dir != NULL) {
604 /* Get application string */
605 bindtextdomain(noti->domain, noti->dir);
606 translated_str = dgettext(noti->domain, ret_val);
607 NOTIFICATION_INFO("translated_str[%s]", translated_str);
608 } else if (ret_val != NULL) {
609 /* Get system string */
610 translated_str = dgettext("sys_string", ret_val);
611 NOTIFICATION_INFO("translated_str[%s]", translated_str);
613 translated_str = NULL;
616 if (translated_str != NULL) {
617 strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
618 src_len = strlen(result_str);
619 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
620 strncat(result_str, buf_str, max_len);
624 } else if (*(temp_str + 1) == 'f') {
629 check_type, num_args);
630 bundle_get_str(b, buf_key, &ret_val);
632 ret_variable_double = atof(ret_val);
637 ret_variable_double);
639 src_len = strlen(result_str);
640 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
641 strncat(result_str, buf_str, max_len);
645 } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
646 if (*(temp_str + 3) == 'd') {
648 ret_variable_int = 0;
652 "%dtype%d", check_type,
653 num_args + *(temp_str + 1) - 49);
654 bundle_get_str(b, buf_key, &ret_val);
656 ret_var_type = atoi(ret_val);
659 NOTIFICATION_VARIABLE_TYPE_COUNT) {
660 /* Get notification count */
661 notification_get_count(noti->type,
662 noti->caller_pkgname,
673 num_args + *(temp_str + 1) - 49);
674 bundle_get_str(b, buf_key, &ret_val);
676 ret_variable_int = atoi(ret_val);
681 sizeof(buf_str), "%d",
684 src_len = strlen(result_str);
685 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
687 strncat(result_str, buf_str, max_len);
690 } else if (*(temp_str + 3) == 's') {
695 check_type, num_args + *(temp_str + 1) - 49);
696 bundle_get_str(b, buf_key, &ret_val);
699 sizeof(buf_str), "%s",
702 src_len = strlen(result_str);
703 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
705 strncat(result_str, buf_str, max_len);
708 } else if (*(temp_str + 3) == 'f') {
713 check_type, num_args + *(temp_str + 1) - 49);
714 bundle_get_str(b, buf_key, &ret_val);
716 ret_variable_double = atof(ret_val);
721 ret_variable_double);
723 src_len = strlen(result_str);
724 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
726 strncat(result_str, buf_str, max_len);
735 /* Check last variable is count, LEFT pos */
736 if (num_args < noti->num_format_args) {
737 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
738 check_type, num_args);
739 bundle_get_str(b, buf_key, &ret_val);
741 ret_var_type = atoi(ret_val);
744 NOTIFICATION_VARIABLE_TYPE_COUNT) {
746 snprintf(buf_key, sizeof(buf_key),
747 "%dvalue%d", check_type,
749 bundle_get_str(b, buf_key, &ret_val);
751 ret_variable_int = atoi(ret_val);
753 if (ret_variable_int ==
754 NOTIFICATION_COUNT_POS_RIGHT) {
755 notification_get_count(noti->type,
756 noti->caller_pkgname,
761 sizeof(buf_str), " %d",
764 src_len = strlen(result_str);
765 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
767 strncat(result_str, buf_str, max_len);
775 switch (check_type) {
776 case NOTIFICATION_TEXT_TYPE_TITLE:
777 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
778 if (noti->temp_title != NULL)
779 free(noti->temp_title);
781 noti->temp_title = strdup(result_str);
783 *text = noti->temp_title;
785 case NOTIFICATION_TEXT_TYPE_CONTENT:
786 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
787 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
788 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
789 if (noti->temp_content !=
791 free(noti->temp_content);
793 noti->temp_content = strdup(result_str);
795 *text = noti->temp_content;
807 return NOTIFICATION_ERROR_NONE;
810 EXPORT_API int notification_set_text_domain(notification_h noti,
814 if (noti == NULL || domain == NULL || dir == NULL)
815 return NOTIFICATION_ERROR_INVALID_PARAMETER;
820 noti->domain = strdup(domain);
825 noti->dir = strdup(dir);
827 return NOTIFICATION_ERROR_NONE;
830 EXPORT_API int notification_get_text_domain(notification_h noti,
835 return NOTIFICATION_ERROR_INVALID_PARAMETER;
837 if (domain != NULL && noti->domain != NULL)
838 *domain = noti->domain;
840 if (dir != NULL && noti->dir != NULL)
843 return NOTIFICATION_ERROR_NONE;
846 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
849 int ret = NOTIFICATION_ERROR_NONE;
850 char buf[256] = { 0, };
851 char buf_tag[512] = { 0, };
854 return NOTIFICATION_ERROR_INVALID_PARAMETER;
857 return NOTIFICATION_ERROR_INVALID_PARAMETER;
859 if (type <= NOTIFICATION_TEXT_TYPE_NONE
860 || type >= NOTIFICATION_TEXT_TYPE_MAX)
861 return NOTIFICATION_ERROR_INVALID_PARAMETER;
864 snprintf(buf, sizeof(buf), "%lu", time);
865 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
867 if (ret != NOTIFICATION_ERROR_NONE)
870 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
873 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
876 int ret = NOTIFICATION_ERROR_NONE;
877 char *ret_text = NULL;
881 return NOTIFICATION_ERROR_INVALID_PARAMETER;
884 return NOTIFICATION_ERROR_INVALID_PARAMETER;
886 if (type <= NOTIFICATION_TEXT_TYPE_NONE
887 || type >= NOTIFICATION_TEXT_TYPE_MAX)
888 return NOTIFICATION_ERROR_INVALID_PARAMETER;
890 ret = notification_get_text(noti, type, &ret_text);
892 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL)
893 return NOTIFICATION_ERROR_INVALID_PARAMETER;
895 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID)
896 return NOTIFICATION_ERROR_INVALID_PARAMETER;
898 tag_value = notification_noti_strip_tag(ret_text);
899 if (tag_value == NULL)
900 return NOTIFICATION_ERROR_INVALID_PARAMETER;
902 *time = atol(tag_value);
905 return NOTIFICATION_ERROR_NONE;
908 EXPORT_API int notification_set_sound(notification_h noti,
909 notification_sound_type_e type,
913 return NOTIFICATION_ERROR_INVALID_PARAMETER;
915 if (type < NOTIFICATION_SOUND_TYPE_NONE
916 || type >= NOTIFICATION_SOUND_TYPE_MAX)
917 return NOTIFICATION_ERROR_INVALID_PARAMETER;
919 noti->sound_type = type;
921 /* Save sound path if user data type */
922 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
923 if (noti->sound_path != NULL)
924 free(noti->sound_path);
926 noti->sound_path = strdup(path);
928 if (noti->sound_path != NULL) {
929 free(noti->sound_path);
930 noti->sound_path = NULL;
932 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
933 noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
934 return NOTIFICATION_ERROR_INVALID_PARAMETER;
938 return NOTIFICATION_ERROR_NONE;
941 EXPORT_API int notification_get_sound(notification_h noti,
942 notification_sound_type_e *type,
945 if (noti == NULL || type == NULL)
946 return NOTIFICATION_ERROR_INVALID_PARAMETER;
948 *type = noti->sound_type;
950 /* Set sound path if user data type */
951 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
953 *path = noti->sound_path;
955 return NOTIFICATION_ERROR_NONE;
958 EXPORT_API int notification_set_vibration(notification_h noti,
959 notification_vibration_type_e type,
963 return NOTIFICATION_ERROR_INVALID_PARAMETER;
965 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
966 || type >= NOTIFICATION_VIBRATION_TYPE_MAX)
967 return NOTIFICATION_ERROR_INVALID_PARAMETER;
969 noti->vibration_type = type;
971 /* Save sound path if user data type */
972 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
973 if (noti->vibration_path != NULL)
974 free(noti->vibration_path);
976 noti->vibration_path = strdup(path);
978 if (noti->vibration_path != NULL) {
979 free(noti->vibration_path);
980 noti->vibration_path = NULL;
982 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
983 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
984 return NOTIFICATION_ERROR_INVALID_PARAMETER;
988 return NOTIFICATION_ERROR_NONE;
992 EXPORT_API int notification_get_vibration(notification_h noti,
993 notification_vibration_type_e *type,
996 if (noti == NULL || type == NULL)
997 return NOTIFICATION_ERROR_INVALID_PARAMETER;
999 *type = noti->vibration_type;
1001 /* Set sound path if user data type */
1002 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1004 *path = noti->vibration_path;
1006 return NOTIFICATION_ERROR_NONE;
1009 EXPORT_API int notification_set_led(notification_h noti,
1010 notification_led_op_e operation,
1014 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1016 if (operation < NOTIFICATION_LED_OP_OFF
1017 || operation >= NOTIFICATION_LED_OP_MAX)
1018 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1020 noti->led_operation = operation;
1022 /* Save led argb if operation is turning on LED with custom color */
1023 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR)
1024 noti->led_argb = led_argb;
1026 return NOTIFICATION_ERROR_NONE;
1029 EXPORT_API int notification_get_led(notification_h noti,
1030 notification_led_op_e *operation,
1033 if (noti == NULL || operation == NULL)
1034 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1036 *operation = noti->led_operation;
1038 /* Save led argb if operation is turning on LED with custom color */
1039 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1040 && led_argb != NULL)
1041 *led_argb = noti->led_argb;
1043 return NOTIFICATION_ERROR_NONE;
1046 EXPORT_API int notification_set_led_time_period(notification_h noti,
1047 int on_ms, int off_ms)
1049 if (noti == NULL || on_ms < 0 || off_ms < 0)
1050 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1052 noti->led_on_ms = on_ms;
1053 noti->led_off_ms = off_ms;
1055 return NOTIFICATION_ERROR_NONE;
1058 EXPORT_API int notification_get_led_time_period(notification_h noti,
1059 int *on_ms, int *off_ms)
1062 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1065 *(on_ms) = noti->led_on_ms;
1067 *(off_ms) = noti->led_off_ms;
1069 return NOTIFICATION_ERROR_NONE;
1072 EXPORT_API int notification_set_launch_option(notification_h noti,
1073 notification_launch_option_type type, void *option)
1075 int err = NOTIFICATION_ERROR_NONE;
1078 app_control_h app_control = option;
1080 if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1081 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1085 if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1086 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1087 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1091 err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1100 EXPORT_API int notification_get_launch_option(notification_h noti,
1101 notification_launch_option_type type, void *option)
1105 app_control_h *app_control = (app_control_h *)option;
1106 app_control_h app_control_new = NULL;
1109 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1111 if (app_control == NULL)
1112 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1114 if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL)
1115 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1118 ret = notification_get_execute_option(noti,
1119 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1122 if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1123 ret = app_control_create(&app_control_new);
1124 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1125 ret = app_control_import_from_bundle(app_control_new, b);
1126 if (ret == APP_CONTROL_ERROR_NONE) {
1127 *app_control = app_control_new;
1129 app_control_destroy(app_control_new);
1130 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1131 return NOTIFICATION_ERROR_IO_ERROR;
1134 NOTIFICATION_ERR("Failed to create app control:%d", ret);
1135 return NOTIFICATION_ERROR_IO_ERROR;
1138 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1142 return NOTIFICATION_ERROR_NONE;
1145 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1147 int err = NOTIFICATION_ERROR_NONE;
1148 bundle *app_control_bundle = NULL;
1151 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1152 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1156 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1157 || event_type >= NOTIFICATION_EVENT_TYPE_MAX) {
1158 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1159 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1163 if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1164 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1168 if (noti->b_event_handler[event_type] != NULL)
1169 bundle_free(noti->b_event_handler[event_type]);
1171 noti->b_event_handler[event_type] = app_control_bundle;
1177 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1179 int err = NOTIFICATION_ERROR_NONE;
1181 app_control_h app_control_new = NULL;
1184 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1185 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1189 if (event_handler == NULL) {
1190 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1191 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1195 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1196 || event_type >= NOTIFICATION_EVENT_TYPE_MAX) {
1197 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1198 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1202 b = noti->b_event_handler[event_type];
1204 NOTIFICATION_DBG("No event handler\n");
1205 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1209 err = app_control_create(&app_control_new);
1210 if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1211 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1212 err = NOTIFICATION_ERROR_IO_ERROR;
1216 err = app_control_import_from_bundle(app_control_new, b);
1217 if (err == APP_CONTROL_ERROR_NONE) {
1218 *event_handler = app_control_new;
1220 app_control_destroy(app_control_new);
1221 app_control_new = NULL;
1222 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1223 err = NOTIFICATION_ERROR_IO_ERROR;
1229 *event_handler = app_control_new;
1234 EXPORT_API int notification_set_property(notification_h noti,
1238 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1240 noti->flags_for_property = flags;
1242 return NOTIFICATION_ERROR_NONE;
1245 EXPORT_API int notification_get_property(notification_h noti,
1248 if (noti == NULL || flags == NULL)
1249 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1251 *flags = noti->flags_for_property;
1253 return NOTIFICATION_ERROR_NONE;
1256 EXPORT_API int notification_set_display_applist(notification_h noti,
1260 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1262 if (applist == 0xffffffff) /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1263 applist = NOTIFICATION_DISPLAY_APP_ALL;
1265 noti->display_applist = applist;
1267 return NOTIFICATION_ERROR_NONE;
1270 EXPORT_API int notification_get_display_applist(notification_h noti,
1273 if (noti == NULL || applist == NULL)
1274 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1276 *applist = noti->display_applist;
1278 return NOTIFICATION_ERROR_NONE;
1281 EXPORT_API int notification_set_size(notification_h noti,
1285 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1287 noti->progress_size = size;
1289 return NOTIFICATION_ERROR_NONE;
1292 EXPORT_API int notification_get_size(notification_h noti,
1295 if (noti == NULL || size == NULL)
1296 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1298 *size = noti->progress_size;
1300 return NOTIFICATION_ERROR_NONE;
1303 EXPORT_API int notification_set_progress(notification_h noti,
1307 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1309 noti->progress_percentage = percentage;
1311 return NOTIFICATION_ERROR_NONE;
1314 EXPORT_API int notification_get_progress(notification_h noti,
1317 if (noti == NULL || percentage == NULL)
1318 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1320 *percentage = noti->progress_percentage;
1322 return NOTIFICATION_ERROR_NONE;
1325 EXPORT_API int notification_get_pkgname(notification_h noti,
1328 if (noti == NULL || pkgname == NULL)
1329 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1331 if (noti->caller_pkgname)
1332 *pkgname = noti->caller_pkgname;
1336 return NOTIFICATION_ERROR_NONE;
1339 EXPORT_API int notification_set_layout(notification_h noti,
1340 notification_ly_type_e layout)
1342 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX))
1343 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1345 noti->layout = layout;
1347 return NOTIFICATION_ERROR_NONE;
1350 EXPORT_API int notification_get_layout(notification_h noti,
1351 notification_ly_type_e *layout)
1353 if (noti == NULL || layout == NULL)
1354 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1356 *layout = noti->layout;
1358 return NOTIFICATION_ERROR_NONE;
1363 EXPORT_API int notification_get_type(notification_h noti,
1364 notification_type_e *type)
1366 if (noti == NULL || type == NULL)
1367 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1371 return NOTIFICATION_ERROR_NONE;
1374 EXPORT_API int notification_post(notification_h noti)
1376 return notification_post_for_uid(noti, getuid());
1379 EXPORT_API int notification_update(notification_h noti)
1381 return notification_update_for_uid(noti, getuid());
1384 EXPORT_API int notification_delete_all(notification_type_e type)
1386 return notification_delete_all_for_uid(type, getuid());
1389 EXPORT_API int notification_delete(notification_h noti)
1391 return notification_delete_for_uid(noti, getuid());
1394 static notification_h _notification_create(notification_type_e type)
1396 notification_h noti = NULL;
1397 package_info_h package_info = NULL;
1398 char *app_id = NULL;
1399 char *domain_name = NULL;
1400 char *app_root_path = NULL;
1401 char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1402 int err_app_manager = APP_MANAGER_ERROR_NONE;
1404 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1405 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1406 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1410 noti = (notification_h)calloc(1, sizeof(struct _notification));
1412 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1413 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1419 if (type == NOTIFICATION_TYPE_NOTI)
1420 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1421 else if (type == NOTIFICATION_TYPE_ONGOING)
1422 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1424 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1425 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1426 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1427 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1428 noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1429 noti->auto_remove = true;
1430 noti->ongoing_flag = false;
1431 noti->default_button_index = 0;
1432 noti->type = NOTIFICATION_ONGOING_VALUE_TYPE_PERCENT;
1435 if (getuid() >= REGULAR_UID_MIN) {
1436 noti->caller_pkgname = notification_get_pkgname_by_pid();
1438 err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1439 if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1440 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]",
1441 err_app_manager, app_id);
1445 /* app name is used as domain name */
1446 /* domain_name is allocated by app_get_package_app_name */
1447 err_app_manager = app_get_package_app_name(app_id, &domain_name);
1449 if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1450 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]",
1451 err_app_manager, domain_name);
1455 err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1457 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1458 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p] caller_pkgname[%s]",
1459 err_app_manager, package_info, noti->caller_pkgname);
1463 err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1465 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1466 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]",
1467 err_app_manager, app_root_path);
1471 snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1473 noti->domain = strdup(domain_name);
1474 noti->dir = strdup(locale_directory);
1485 free(app_root_path);
1488 package_info_destroy(package_info);
1492 * Other fields are already initialized with ZERO.
1494 set_last_result(NOTIFICATION_ERROR_NONE);
1498 EXPORT_API notification_h notification_create(notification_type_e type)
1500 return _notification_create(type);
1503 EXPORT_API notification_h notification_load_by_tag(const char *tag)
1505 return notification_load_by_tag_for_uid(tag, getuid());
1508 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1511 notification_h new_noti = NULL;
1513 if (noti == NULL || clone == NULL) {
1514 NOTIFICATION_ERR("INVALID PARAMETER.");
1515 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1518 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1519 if (new_noti == NULL) {
1520 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1521 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1524 new_noti->type = noti->type;
1525 new_noti->layout = noti->layout;
1527 new_noti->group_id = noti->group_id;
1528 new_noti->internal_group_id = noti->internal_group_id;
1529 new_noti->priv_id = noti->priv_id;
1531 if (noti->caller_pkgname != NULL)
1532 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1534 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1536 if (noti->launch_pkgname != NULL)
1537 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1539 new_noti->launch_pkgname = NULL;
1541 if (noti->args != NULL)
1542 new_noti->args = bundle_dup(noti->args);
1544 new_noti->args = NULL;
1546 if (noti->group_args != NULL)
1547 new_noti->group_args = bundle_dup(noti->group_args);
1549 new_noti->group_args = NULL;
1551 if (noti->b_execute_option != NULL)
1552 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1554 new_noti->b_execute_option = NULL;
1556 if (noti->b_service_responding != NULL)
1557 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1559 new_noti->b_service_responding = NULL;
1561 if (noti->b_service_single_launch != NULL)
1562 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1564 new_noti->b_service_single_launch = NULL;
1566 if (noti->b_service_multi_launch != NULL)
1567 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1569 new_noti->b_service_multi_launch = NULL;
1571 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1572 if (noti->b_event_handler[i] != NULL)
1573 new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1575 new_noti->b_event_handler[i] = NULL;
1578 new_noti->sound_type = noti->sound_type;
1579 if (noti->sound_path != NULL)
1580 new_noti->sound_path = strdup(noti->sound_path);
1582 new_noti->sound_path = NULL;
1584 new_noti->vibration_type = noti->vibration_type;
1585 if (noti->vibration_path != NULL)
1586 new_noti->vibration_path = strdup(noti->vibration_path);
1588 new_noti->vibration_path = NULL;
1590 new_noti->led_operation = noti->led_operation;
1591 new_noti->led_argb = noti->led_argb;
1592 new_noti->led_on_ms = noti->led_on_ms;
1593 new_noti->led_off_ms = noti->led_off_ms;
1595 if (noti->domain != NULL)
1596 new_noti->domain = strdup(noti->domain);
1598 new_noti->domain = NULL;
1600 if (noti->dir != NULL)
1601 new_noti->dir = strdup(noti->dir);
1603 new_noti->dir = NULL;
1605 if (noti->b_text != NULL)
1606 new_noti->b_text = bundle_dup(noti->b_text);
1608 new_noti->b_text = NULL;
1610 if (noti->b_key != NULL)
1611 new_noti->b_key = bundle_dup(noti->b_key);
1613 new_noti->b_key = NULL;
1615 if (noti->tag != NULL)
1616 new_noti->tag = strdup(noti->tag);
1618 new_noti->tag = NULL;
1620 if (noti->b_format_args != NULL)
1621 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1623 new_noti->b_format_args = NULL;
1625 new_noti->num_format_args = noti->num_format_args;
1627 if (noti->b_image_path != NULL)
1628 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1630 new_noti->b_image_path = NULL;
1632 new_noti->time = noti->time;
1633 new_noti->insert_time = noti->insert_time;
1635 new_noti->flags_for_property = noti->flags_for_property;
1636 new_noti->display_applist = noti->display_applist;
1638 new_noti->progress_size = noti->progress_size;
1639 new_noti->progress_percentage = noti->progress_percentage;
1641 new_noti->ongoing_flag = noti->ongoing_flag;
1642 new_noti->ongoing_value_type = noti->ongoing_value_type;
1643 new_noti->ongoing_current = noti->ongoing_current;
1644 new_noti->ongoing_duration = noti->ongoing_duration;
1645 new_noti->auto_remove = noti->auto_remove;
1646 new_noti->default_button_index = noti->default_button_index;
1647 new_noti->timeout = noti->timeout;
1648 new_noti->text_input_max_length = noti->text_input_max_length;
1649 new_noti->uid = noti->uid;
1651 new_noti->app_icon_path = NULL;
1652 new_noti->app_name = NULL;
1653 new_noti->temp_title = NULL;
1654 new_noti->temp_content = NULL;
1658 return NOTIFICATION_ERROR_NONE;
1662 EXPORT_API int notification_free(notification_h noti)
1666 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1668 if (noti->caller_pkgname)
1669 free(noti->caller_pkgname);
1671 if (noti->launch_pkgname)
1672 free(noti->launch_pkgname);
1675 bundle_free(noti->args);
1677 if (noti->group_args)
1678 bundle_free(noti->group_args);
1680 if (noti->b_execute_option)
1681 bundle_free(noti->b_execute_option);
1683 if (noti->b_service_responding)
1684 bundle_free(noti->b_service_responding);
1686 if (noti->b_service_single_launch)
1687 bundle_free(noti->b_service_single_launch);
1689 if (noti->b_service_multi_launch)
1690 bundle_free(noti->b_service_multi_launch);
1692 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1693 if (noti->b_event_handler[i] != NULL)
1694 bundle_free(noti->b_event_handler[i]);
1697 if (noti->sound_path)
1698 free(noti->sound_path);
1700 if (noti->vibration_path)
1701 free(noti->vibration_path);
1710 bundle_free(noti->b_text);
1713 bundle_free(noti->b_key);
1715 if (noti->b_format_args)
1716 bundle_free(noti->b_format_args);
1718 if (noti->b_image_path)
1719 bundle_free(noti->b_image_path);
1721 if (noti->app_icon_path)
1722 free(noti->app_icon_path);
1725 free(noti->app_name);
1727 if (noti->temp_title)
1728 free(noti->temp_title);
1730 if (noti->temp_content)
1731 free(noti->temp_content);
1738 return NOTIFICATION_ERROR_NONE;
1741 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
1744 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1747 if (noti->tag != NULL)
1750 noti->tag = strdup(tag);
1753 return NOTIFICATION_ERROR_NONE;
1757 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
1760 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1763 return NOTIFICATION_ERROR_NONE;
1766 /* LCOV_EXCL_START */
1767 void notification_call_posted_toast_cb(const char *message)
1769 if (posted_toast_message_cb != NULL)
1770 posted_toast_message_cb((void *)message);
1772 /* LCOV_EXCL_STOP */
1774 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
1777 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1779 noti->ongoing_flag = ongoing_flag;
1781 return NOTIFICATION_ERROR_NONE;
1784 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
1786 if (noti == NULL || ongoing_flag == NULL)
1787 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1789 *ongoing_flag = noti->ongoing_flag;
1791 return NOTIFICATION_ERROR_NONE;
1795 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
1797 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
1798 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1800 return NOTIFICATION_ERROR_NONE;
1803 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
1805 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
1806 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1808 if (noti->b_event_handler[button_index - 1]) {
1809 bundle_free(noti->b_event_handler[button_index - 1]);
1810 noti->b_event_handler[button_index - 1] = NULL;
1813 return NOTIFICATION_ERROR_NONE;
1816 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
1819 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1821 noti->auto_remove = auto_remove;
1823 return NOTIFICATION_ERROR_NONE;
1826 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
1828 if (noti == NULL || auto_remove == NULL)
1829 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1831 *auto_remove = noti->auto_remove;
1833 return NOTIFICATION_ERROR_NONE;
1836 EXPORT_API int notification_save_as_template(notification_h noti, const char *template_name)
1838 if (noti == NULL || template_name == NULL) {
1839 NOTIFICATION_ERR("Invalid parameter");
1840 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1843 return notification_ipc_request_save_as_template(noti, template_name);
1846 EXPORT_API notification_h notification_create_from_template(const char *template_name)
1849 notification_h noti = NULL;
1851 if (template_name == NULL) {
1852 NOTIFICATION_ERR("Invalid parameter");
1853 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1857 noti = (notification_h)calloc(1, sizeof(struct _notification));
1859 NOTIFICATION_ERR("Failed to alloc a new notification");
1860 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1864 ret = notification_ipc_request_create_from_template(noti, template_name);
1866 set_last_result(ret);
1867 if (ret != NOTIFICATION_ERROR_NONE) {
1868 notification_free(noti);
1875 EXPORT_API int notification_get_noti_block_state(notification_block_state_e *state)
1880 int do_not_disturb_except;
1881 int allow_to_notify;
1884 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1886 pkgname = notification_get_pkgname_by_pid();
1888 ret = notification_ipc_get_noti_block_state(pkgname, &do_not_disturb, &do_not_disturb_except, &allow_to_notify, getuid());
1890 if (ret != NOTIFICATION_ERROR_NONE) {
1896 if (allow_to_notify) {
1897 *state = NOTIFICATION_BLOCK_STATE_ALLOWED;
1898 if (do_not_disturb && !do_not_disturb_except)
1899 *state = NOTIFICATION_BLOCK_STATE_DO_NOT_DISTURB;
1901 *state = NOTIFICATION_BLOCK_STATE_BLOCKED;
1910 EXPORT_API int notification_set_text_input(notification_h noti, int text_input_max_length)
1913 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1915 noti->text_input_max_length = text_input_max_length;
1917 return NOTIFICATION_ERROR_NONE;