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 char *notification_get_pkgname_by_pid(void)
54 char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
55 int pid = 0, ret = AUL_R_OK;
58 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
62 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
63 if (ret != AUL_R_OK) {
65 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
67 fd = open(buf, O_RDONLY);
71 ret = read(fd, pkgname, sizeof(pkgname) - 1);
80 * "ret" is not able to be larger than "sizeof(pkgname) - 1",
81 * if the system is not going wrong.
84 if (strlen(pkgname) <= 0)
88 dup_pkgname = strdup(pkgname);
90 NOTIFICATION_ERR("Heap: %d\n", errno);
95 EXPORT_API int notification_set_image(notification_h noti,
96 notification_image_type_e type,
97 const char *image_path)
100 char buf_key[32] = { 0, };
101 char *ret_val = NULL;
103 /* Check noti and image_path are valid data */
104 if (noti == NULL || image_path == NULL)
105 return NOTIFICATION_ERROR_INVALID_PARAMETER;
107 /* Check image type is valid type */
108 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
109 || type >= NOTIFICATION_IMAGE_TYPE_MAX)
110 return NOTIFICATION_ERROR_INVALID_PARAMETER;
112 /* Check image path bundle is exist */
113 if (noti->b_image_path) {
114 /* If image path bundle is exist, store local bundle value */
115 b = noti->b_image_path;
117 /* Set image type to key as char string type */
118 snprintf(buf_key, sizeof(buf_key), "%d", type);
120 /* Get value using key */
121 bundle_get_str(b, buf_key, &ret_val);
123 /* If key is exist, remove this value to store new image path */
124 bundle_del(b, buf_key);
126 /* Add new image path with type key */
127 bundle_add_str(b, buf_key, image_path);
129 /* If image path bundle is not exist, create new one */
132 /* Set image type to key as char string type */
133 snprintf(buf_key, sizeof(buf_key), "%d", type);
135 /* Add new image path with type key */
136 bundle_add_str(b, buf_key, image_path);
138 /* Save to image path bundle */
139 noti->b_image_path = b;
142 return NOTIFICATION_ERROR_NONE;
145 EXPORT_API int notification_get_image(notification_h noti,
146 notification_image_type_e type,
150 char buf_key[32] = { 0, };
151 char *ret_val = NULL;
153 /* Check noti and image_path is valid data */
154 if (noti == NULL || image_path == NULL)
155 return NOTIFICATION_ERROR_INVALID_PARAMETER;
157 /* Check image type is valid data */
158 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
159 || type >= NOTIFICATION_IMAGE_TYPE_MAX)
160 return NOTIFICATION_ERROR_INVALID_PARAMETER;
162 /* Check image path bundle exist */
163 if (noti->b_image_path) {
164 /* If image path bundle exist, store local bundle data */
165 b = noti->b_image_path;
167 /* Set image type to key as char string type */
168 snprintf(buf_key, sizeof(buf_key), "%d", type);
170 /* Get value of key */
171 bundle_get_str(b, buf_key, &ret_val);
173 *image_path = ret_val;
175 /* If image path bundle does not exist, image path is NULL */
179 /* If image path is NULL and type is ICON, icon path set from AIL */
180 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
181 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
182 /* Check App icon path is already set */
183 if (noti->app_icon_path != NULL)
184 /* image path will be app icon path */
185 *image_path = noti->app_icon_path;
190 return NOTIFICATION_ERROR_NONE;
193 EXPORT_API int notification_set_time(notification_h noti, time_t input_time)
195 /* Check noti is valid data */
197 return NOTIFICATION_ERROR_INVALID_PARAMETER;
200 /* If input time is 0, set current time */
201 noti->time = time(NULL);
203 /* save input time */
204 noti->time = input_time;
206 return NOTIFICATION_ERROR_NONE;
209 EXPORT_API int notification_get_time(notification_h noti, time_t *ret_time)
211 /* Check noti and time is valid data */
212 if (noti == NULL || ret_time == NULL)
213 return NOTIFICATION_ERROR_INVALID_PARAMETER;
215 /* Set time infomation */
216 *ret_time = noti->time;
218 return NOTIFICATION_ERROR_NONE;
221 EXPORT_API int notification_get_insert_time(notification_h noti,
224 /* Check noti and ret_time is valid data */
225 if (noti == NULL || ret_time == NULL)
226 return NOTIFICATION_ERROR_INVALID_PARAMETER;
228 /* Set insert time information */
229 *ret_time = noti->insert_time;
231 return NOTIFICATION_ERROR_NONE;
234 EXPORT_API int notification_set_text(notification_h noti,
235 notification_text_type_e type, const char *text,
236 const char *key, int args_type, ...)
239 char buf_key[32] = { 0, };
240 char buf_val[1024] = { 0, };
241 char *ret_val = NULL;
243 notification_variable_type_e var_type;
245 int noti_err = NOTIFICATION_ERROR_NONE;
246 int var_value_int = 0;
247 double var_value_double = 0.0;
248 char *var_value_string = NULL;
249 notification_count_pos_type_e var_value_count =
250 NOTIFICATION_COUNT_POS_NONE;
252 /* Check noti is valid data */
254 return NOTIFICATION_ERROR_INVALID_PARAMETER;
256 /* Check text type is valid type */
257 if (type <= NOTIFICATION_TEXT_TYPE_NONE
258 || type >= NOTIFICATION_TEXT_TYPE_MAX)
259 return NOTIFICATION_ERROR_INVALID_PARAMETER;
261 /* Check text bundle exist */
263 if (noti->b_text != NULL) {
264 /* If text bundle exist, store local bundle data */
267 /* Make type to key as char string */
268 snprintf(buf_key, sizeof(buf_key), "%d", type);
270 /* Get value using type key */
271 bundle_get_str(b, buf_key, &ret_val);
274 /* If value exist, remove this to add new value */
275 bundle_del(b, buf_key);
277 snprintf(buf_val, sizeof(buf_val), "%s", text);
279 /* Add new text value */
280 bundle_add_str(b, buf_key, buf_val);
282 /* If text bundle does not exist, create new one */
285 /* Make type to key as char string */
286 snprintf(buf_key, sizeof(buf_key), "%d", type);
288 snprintf(buf_val, sizeof(buf_val), "%s", text);
290 /* Add new text value */
291 bundle_add_str(b, buf_key, buf_val);
293 /* Save text bundle */
297 /* Reset if text is NULL */
298 if (noti->b_text != NULL) {
299 /* If text bundle exist, store local bundle data */
302 /* Make type to key as char string */
303 snprintf(buf_key, sizeof(buf_key), "%d", type);
305 /* Get value using type key */
306 bundle_get_str(b, buf_key, &ret_val);
308 /* If value exist, remove this */
309 bundle_del(b, buf_key);
313 /* Save key if key is valid data */
315 /* Check key bundle exist */
316 if (noti->b_key != NULL) {
317 /* If key bundle exist, store local bundle data */
320 /* Make type to key as char string */
321 snprintf(buf_key, sizeof(buf_key), "%d", type);
323 /* Get value using type key */
324 bundle_get_str(b, buf_key, &ret_val);
326 /* If value exist, remove this to add new value */
327 bundle_del(b, buf_key);
329 snprintf(buf_val, sizeof(buf_val), "%s", key);
331 /* Add new key value */
332 bundle_add_str(b, buf_key, buf_val);
334 /* If key bundle does not exist, create new one */
337 /* Make type to key as char string */
338 snprintf(buf_key, sizeof(buf_key), "%d", type);
340 snprintf(buf_val, sizeof(buf_val), "%s", key);
342 /* Add new key value */
343 bundle_add_str(b, buf_key, buf_val);
345 /* Save key bundle */
349 /* Reset if key is NULL */
350 if (noti->b_key != NULL) {
351 /* If key bundle exist, store local bundle data */
354 /* Make type to key as char string */
355 snprintf(buf_key, sizeof(buf_key), "%d", type);
357 /* Get value using type key */
358 bundle_get_str(b, buf_key, &ret_val);
360 /* If value exist, remove this */
361 bundle_del(b, buf_key);
365 if (noti->b_format_args != NULL)
366 b = noti->b_format_args;
370 va_start(var_args, args_type);
372 var_type = args_type;
375 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
377 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
378 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
380 bundle_get_str(b, buf_key, &ret_val);
382 bundle_del(b, buf_key);
384 bundle_add_str(b, buf_key, buf_val);
387 case NOTIFICATION_VARIABLE_TYPE_INT:
388 var_value_int = va_arg(var_args, int);
391 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
393 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
395 bundle_get_str(b, buf_key, &ret_val);
397 bundle_del(b, buf_key);
399 bundle_add_str(b, buf_key, buf_val);
402 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
403 var_value_double = va_arg(var_args, double);
406 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
408 snprintf(buf_val, sizeof(buf_val), "%.2f",
411 bundle_get_str(b, buf_key, &ret_val);
413 bundle_del(b, buf_key);
415 bundle_add_str(b, buf_key, buf_val);
418 case NOTIFICATION_VARIABLE_TYPE_STRING:
419 var_value_string = va_arg(var_args, char *);
422 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
424 snprintf(buf_val, sizeof(buf_val), "%s",
427 bundle_get_str(b, buf_key, &ret_val);
429 bundle_del(b, buf_key);
431 bundle_add_str(b, buf_key, buf_val);
434 case NOTIFICATION_VARIABLE_TYPE_COUNT:
436 va_arg(var_args, notification_count_pos_type_e);
439 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
441 snprintf(buf_val, sizeof(buf_val), "%d",
444 bundle_get_str(b, buf_key, &ret_val);
446 bundle_del(b, buf_key);
448 bundle_add_str(b, buf_key, buf_val);
452 NOTIFICATION_ERR("Error. invalid variable type. : %d",
454 noti_err = NOTIFICATION_ERROR_INVALID_PARAMETER;
459 var_type = va_arg(var_args, notification_variable_type_e);
463 if (noti_err == NOTIFICATION_ERROR_NONE)
464 noti->num_format_args = num_args;
466 noti->num_format_args = 0;
468 snprintf(buf_key, sizeof(buf_key), "num%d", type);
469 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
471 bundle_get_str(b, buf_key, &ret_val);
473 bundle_del(b, buf_key);
475 bundle_add_str(b, buf_key, buf_val);
477 noti->b_format_args = b;
482 EXPORT_API int notification_get_text(notification_h noti,
483 notification_text_type_e type,
487 char buf_key[32] = { 0, };
488 char *ret_val = NULL;
489 char *get_str = NULL;
490 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
491 /* int display_option_flag = 0; */
493 char *temp_str = NULL;
494 char *translated_str = NULL;
495 char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
496 char buf_str[1024] = { 0, };
498 notification_variable_type_e ret_var_type = 0;
499 int ret_variable_int = 0;
500 double ret_variable_double = 0.0;
504 /* Check noti is valid data */
505 if (noti == NULL || text == NULL)
506 return NOTIFICATION_ERROR_INVALID_PARAMETER;
508 /* Check text type is valid type */
509 if (type <= NOTIFICATION_TEXT_TYPE_NONE
510 || type >= NOTIFICATION_TEXT_TYPE_MAX)
511 return NOTIFICATION_ERROR_INVALID_PARAMETER;
515 if (noti->b_key != NULL) {
518 /* Get text domain and dir */
519 /* _notification_get_text_domain(noti); */
521 snprintf(buf_key, sizeof(buf_key), "%d", type);
523 bundle_get_str(b, buf_key, &ret_val);
524 if (ret_val != NULL && noti->domain != NULL
525 && noti->dir != NULL) {
526 /* Get application string */
527 bindtextdomain(noti->domain, noti->dir);
529 get_str = dgettext(noti->domain, ret_val);
530 if (get_str == ret_val) /* not found */
532 } else if (ret_val != NULL) {
533 /* Get system string */
534 get_str = dgettext("sys_string", ret_val);
535 if (get_str == ret_val) /* not found */
542 if (get_str == NULL && noti->b_text != NULL) {
545 snprintf(buf_key, sizeof(buf_key), "%d", type);
547 bundle_get_str(b, buf_key, &get_str);
550 if (get_str == NULL && ret_val != NULL)
551 get_str = ret_val; /* fallback for printing anything */
555 if (get_str != NULL) {
556 /* Get number format args */
557 b = noti->b_format_args;
558 noti->num_format_args = 0;
561 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
562 bundle_get_str(b, buf_key, &ret_val);
564 noti->num_format_args = atoi(ret_val);
567 if (noti->num_format_args == 0) {
568 *text = (char *)get_str;
570 /* Check first variable is count, LEFT pos */
571 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
572 check_type, num_args);
573 bundle_get_str(b, buf_key, &ret_val);
575 ret_var_type = atoi(ret_val);
577 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
579 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
580 check_type, num_args);
581 bundle_get_str(b, buf_key, &ret_val);
583 ret_variable_int = atoi(ret_val);
585 if (ret_variable_int ==
586 NOTIFICATION_COUNT_POS_LEFT) {
587 notification_get_count(noti->type,
588 noti->caller_pkgname,
592 snprintf(buf_str, sizeof(buf_str),
593 "%d ", ret_variable_int);
595 src_len = strlen(result_str);
596 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
598 strncat(result_str, buf_str,
604 /* Check variable IN pos */
605 for (temp_str = (char *)get_str; *temp_str != '\0';
607 if (*temp_str != '%') {
608 strncat(result_str, temp_str, 1);
610 if (*(temp_str + 1) == '%') {
611 strncat(result_str, temp_str,
613 } else if (*(temp_str + 1) == 'd') {
615 ret_variable_int = 0;
619 "%dtype%d", check_type,
621 bundle_get_str(b, buf_key, &ret_val);
623 ret_var_type = atoi(ret_val);
626 NOTIFICATION_VARIABLE_TYPE_COUNT) {
627 /* Get notification count */
628 notification_get_count(noti->type,
629 noti->caller_pkgname,
640 bundle_get_str(b, buf_key, &ret_val);
642 ret_variable_int = atoi(ret_val);
646 sizeof(buf_str), "%d",
649 src_len = strlen(result_str);
650 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
652 strncat(result_str, buf_str,
658 } else if (*(temp_str + 1) == 's') {
663 check_type, num_args);
664 bundle_get_str(b, buf_key, &ret_val);
666 if (ret_val != NULL && noti->domain != NULL && noti->dir != NULL) {
667 /* Get application string */
668 bindtextdomain(noti->domain, noti->dir);
669 translated_str = dgettext(noti->domain, ret_val);
670 NOTIFICATION_INFO("translated_str[%s]", translated_str);
671 } else if (ret_val != NULL) {
672 /* Get system string */
673 translated_str = dgettext("sys_string", ret_val);
674 NOTIFICATION_INFO("translated_str[%s]", translated_str);
676 translated_str = NULL;
679 if (translated_str != NULL) {
680 strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
681 src_len = strlen(result_str);
682 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
683 strncat(result_str, buf_str, max_len);
687 } else if (*(temp_str + 1) == 'f') {
692 check_type, num_args);
693 bundle_get_str(b, buf_key, &ret_val);
695 ret_variable_double = atof(ret_val);
700 ret_variable_double);
702 src_len = strlen(result_str);
703 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
704 strncat(result_str, buf_str, max_len);
708 } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
709 if (*(temp_str + 3) == 'd') {
711 ret_variable_int = 0;
715 "%dtype%d", check_type,
716 num_args + *(temp_str + 1) - 49);
717 bundle_get_str(b, buf_key, &ret_val);
719 ret_var_type = atoi(ret_val);
722 NOTIFICATION_VARIABLE_TYPE_COUNT) {
723 /* Get notification count */
724 notification_get_count(noti->type,
725 noti->caller_pkgname,
736 num_args + *(temp_str + 1) - 49);
737 bundle_get_str(b, buf_key, &ret_val);
739 ret_variable_int = atoi(ret_val);
744 sizeof(buf_str), "%d",
747 src_len = strlen(result_str);
748 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
750 strncat(result_str, buf_str, max_len);
753 } else if (*(temp_str + 3) == 's') {
758 check_type, num_args + *(temp_str + 1) - 49);
759 bundle_get_str(b, buf_key, &ret_val);
762 sizeof(buf_str), "%s",
765 src_len = strlen(result_str);
766 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
768 strncat(result_str, buf_str, max_len);
771 } else if (*(temp_str + 3) == 'f') {
776 check_type, num_args + *(temp_str + 1) - 49);
777 bundle_get_str(b, buf_key, &ret_val);
779 ret_variable_double = atof(ret_val);
784 ret_variable_double);
786 src_len = strlen(result_str);
787 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
789 strncat(result_str, buf_str, max_len);
798 /* Check last variable is count, LEFT pos */
799 if (num_args < noti->num_format_args) {
800 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
801 check_type, num_args);
802 bundle_get_str(b, buf_key, &ret_val);
804 ret_var_type = atoi(ret_val);
807 NOTIFICATION_VARIABLE_TYPE_COUNT) {
809 snprintf(buf_key, sizeof(buf_key),
810 "%dvalue%d", check_type,
812 bundle_get_str(b, buf_key, &ret_val);
814 ret_variable_int = atoi(ret_val);
816 if (ret_variable_int ==
817 NOTIFICATION_COUNT_POS_RIGHT) {
818 notification_get_count(noti->type,
819 noti->caller_pkgname,
824 sizeof(buf_str), " %d",
827 src_len = strlen(result_str);
828 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
830 strncat(result_str, buf_str, max_len);
838 switch (check_type) {
839 case NOTIFICATION_TEXT_TYPE_TITLE:
840 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
841 if (noti->temp_title != NULL)
842 free(noti->temp_title);
844 noti->temp_title = strdup(result_str);
846 *text = noti->temp_title;
848 case NOTIFICATION_TEXT_TYPE_CONTENT:
849 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
850 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
851 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
852 if (noti->temp_content !=
854 free(noti->temp_content);
856 noti->temp_content = strdup(result_str);
858 *text = noti->temp_content;
870 return NOTIFICATION_ERROR_NONE;
873 EXPORT_API int notification_set_text_domain(notification_h noti,
877 /* check noti and domain is valid data */
878 if (noti == NULL || domain == NULL || dir == NULL)
879 return NOTIFICATION_ERROR_INVALID_PARAMETER;
883 /* Remove previous domain */
887 noti->domain = strdup(domain);
889 /* Check locale dir */
891 /* Remove previous locale dir */
894 /* Copy locale dir */
895 noti->dir = strdup(dir);
897 return NOTIFICATION_ERROR_NONE;
900 EXPORT_API int notification_get_text_domain(notification_h noti,
904 /* Check noti is valid data */
906 return NOTIFICATION_ERROR_INVALID_PARAMETER;
909 if (domain != NULL && noti->domain != NULL)
910 *domain = noti->domain;
913 if (dir != NULL && noti->dir != NULL)
916 return NOTIFICATION_ERROR_NONE;
919 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
922 int ret = NOTIFICATION_ERROR_NONE;
923 char buf[256] = { 0, };
924 char buf_tag[512] = { 0, };
927 return NOTIFICATION_ERROR_INVALID_PARAMETER;
930 return NOTIFICATION_ERROR_INVALID_PARAMETER;
932 if (type <= NOTIFICATION_TEXT_TYPE_NONE
933 || type >= NOTIFICATION_TEXT_TYPE_MAX)
934 return NOTIFICATION_ERROR_INVALID_PARAMETER;
937 snprintf(buf, sizeof(buf), "%lu", time);
938 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
940 if (ret != NOTIFICATION_ERROR_NONE)
943 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
946 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
949 int ret = NOTIFICATION_ERROR_NONE;
950 char *ret_text = NULL;
954 return NOTIFICATION_ERROR_INVALID_PARAMETER;
957 return NOTIFICATION_ERROR_INVALID_PARAMETER;
959 if (type <= NOTIFICATION_TEXT_TYPE_NONE
960 || type >= NOTIFICATION_TEXT_TYPE_MAX)
961 return NOTIFICATION_ERROR_INVALID_PARAMETER;
963 ret = notification_get_text(noti, type, &ret_text);
965 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL)
966 return NOTIFICATION_ERROR_INVALID_PARAMETER;
968 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID)
969 return NOTIFICATION_ERROR_INVALID_PARAMETER;
971 tag_value = notification_noti_strip_tag(ret_text);
972 if (tag_value == NULL)
973 return NOTIFICATION_ERROR_INVALID_PARAMETER;
975 *time = atol(tag_value);
978 return NOTIFICATION_ERROR_NONE;
981 EXPORT_API int notification_set_sound(notification_h noti,
982 notification_sound_type_e type,
985 /* Check noti is valid data */
987 return NOTIFICATION_ERROR_INVALID_PARAMETER;
990 /* Check type is valid */
991 if (type < NOTIFICATION_SOUND_TYPE_NONE
992 || type >= NOTIFICATION_SOUND_TYPE_MAX)
993 return NOTIFICATION_ERROR_INVALID_PARAMETER;
995 /* Save sound type */
996 noti->sound_type = type;
998 /* Save sound path if user data type */
999 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1000 if (noti->sound_path != NULL)
1001 free(noti->sound_path);
1003 noti->sound_path = strdup(path);
1005 if (noti->sound_path != NULL) {
1006 free(noti->sound_path);
1007 noti->sound_path = NULL;
1009 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1010 noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1011 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1015 return NOTIFICATION_ERROR_NONE;
1018 EXPORT_API int notification_get_sound(notification_h noti,
1019 notification_sound_type_e *type,
1022 /* check noti and type is valid data */
1023 if (noti == NULL || type == NULL)
1024 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1026 /* Set sound type */
1027 *type = noti->sound_type;
1029 /* Set sound path if user data type */
1030 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1032 *path = noti->sound_path;
1034 return NOTIFICATION_ERROR_NONE;
1037 EXPORT_API int notification_set_vibration(notification_h noti,
1038 notification_vibration_type_e type,
1041 /* Check noti is valid data */
1043 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1045 /* Check type is valid */
1046 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1047 || type >= NOTIFICATION_VIBRATION_TYPE_MAX)
1048 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1050 /* Save vibration type */
1051 noti->vibration_type = type;
1053 /* Save sound path if user data type */
1054 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1055 if (noti->vibration_path != NULL)
1056 free(noti->vibration_path);
1058 noti->vibration_path = strdup(path);
1060 if (noti->vibration_path != NULL) {
1061 free(noti->vibration_path);
1062 noti->vibration_path = NULL;
1064 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1065 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1066 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1070 return NOTIFICATION_ERROR_NONE;
1074 EXPORT_API int notification_get_vibration(notification_h noti,
1075 notification_vibration_type_e *type,
1078 /* check noti and type is valid data */
1079 if (noti == NULL || type == NULL)
1080 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1082 /* Set vibration type */
1083 *type = noti->vibration_type;
1085 /* Set sound path if user data type */
1086 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1088 *path = noti->vibration_path;
1090 return NOTIFICATION_ERROR_NONE;
1093 EXPORT_API int notification_set_led(notification_h noti,
1094 notification_led_op_e operation,
1097 /* Check noti is valid data */
1099 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1101 /* Check operation is valid */
1102 if (operation < NOTIFICATION_LED_OP_OFF
1103 || operation >= NOTIFICATION_LED_OP_MAX)
1104 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1106 /* Save led operation */
1107 noti->led_operation = operation;
1109 /* Save led argb if operation is turning on LED with custom color */
1110 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR)
1111 noti->led_argb = led_argb;
1113 return NOTIFICATION_ERROR_NONE;
1116 EXPORT_API int notification_get_led(notification_h noti,
1117 notification_led_op_e *operation,
1120 /* check noti and operation is valid data */
1121 if (noti == NULL || operation == NULL)
1122 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1124 /* Set led operation */
1125 *operation = noti->led_operation;
1127 /* Save led argb if operation is turning on LED with custom color */
1128 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1129 && led_argb != NULL)
1130 *led_argb = noti->led_argb;
1132 return NOTIFICATION_ERROR_NONE;
1135 EXPORT_API int notification_set_led_time_period(notification_h noti,
1136 int on_ms, int off_ms)
1138 /* Check noti is valid data */
1139 if (noti == NULL || on_ms < 0 || off_ms < 0)
1140 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1142 /* Save led operation */
1143 noti->led_on_ms = on_ms;
1144 noti->led_off_ms = off_ms;
1146 return NOTIFICATION_ERROR_NONE;
1149 EXPORT_API int notification_get_led_time_period(notification_h noti,
1150 int *on_ms, int *off_ms)
1152 /* check noti and operation is valid data */
1154 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1157 *(on_ms) = noti->led_on_ms;
1159 *(off_ms) = noti->led_off_ms;
1161 return NOTIFICATION_ERROR_NONE;
1164 EXPORT_API int notification_set_launch_option(notification_h noti,
1165 notification_launch_option_type type, void *option)
1167 int err = NOTIFICATION_ERROR_NONE;
1170 app_control_h app_control = option;
1172 if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1173 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1177 if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1178 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1179 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1183 err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1192 EXPORT_API int notification_get_launch_option(notification_h noti,
1193 notification_launch_option_type type, void *option)
1197 app_control_h *app_control = (app_control_h *)option;
1198 app_control_h app_control_new = NULL;
1201 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1203 if (app_control == NULL)
1204 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1206 if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL)
1207 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1210 ret = notification_get_execute_option(noti,
1211 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1214 if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1215 ret = app_control_create(&app_control_new);
1216 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1217 ret = app_control_import_from_bundle(app_control_new, b);
1218 if (ret == APP_CONTROL_ERROR_NONE) {
1219 *app_control = app_control_new;
1221 app_control_destroy(app_control_new);
1222 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1223 return NOTIFICATION_ERROR_IO_ERROR;
1226 NOTIFICATION_ERR("Failed to create app control:%d", ret);
1227 return NOTIFICATION_ERROR_IO_ERROR;
1230 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1234 return NOTIFICATION_ERROR_NONE;
1237 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1239 int err = NOTIFICATION_ERROR_NONE;
1240 bundle *app_control_bundle = NULL;
1243 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1244 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1248 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1249 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1250 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1251 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1255 if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1256 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1260 if (noti->b_event_handler[event_type] != NULL)
1261 bundle_free(noti->b_event_handler[event_type]);
1263 noti->b_event_handler[event_type] = app_control_bundle;
1269 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1271 int err = NOTIFICATION_ERROR_NONE;
1273 app_control_h app_control_new = NULL;
1276 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1277 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1280 if (event_handler == NULL) {
1281 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1282 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1285 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1286 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1287 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1288 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1292 b = noti->b_event_handler[event_type];
1295 NOTIFICATION_DBG("No event handler\n");
1296 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1300 err = app_control_create(&app_control_new);
1301 if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1302 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1303 err = NOTIFICATION_ERROR_IO_ERROR;
1307 err = app_control_import_from_bundle(app_control_new, b);
1308 if (err == APP_CONTROL_ERROR_NONE) {
1309 *event_handler = app_control_new;
1311 app_control_destroy(app_control_new);
1312 app_control_new = NULL;
1313 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1314 err = NOTIFICATION_ERROR_IO_ERROR;
1320 *event_handler = app_control_new;
1329 EXPORT_API int notification_set_property(notification_h noti,
1332 /* Check noti is valid data */
1334 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1337 noti->flags_for_property = flags;
1339 return NOTIFICATION_ERROR_NONE;
1342 EXPORT_API int notification_get_property(notification_h noti,
1345 /* Check noti and flags are valid data */
1346 if (noti == NULL || flags == NULL)
1347 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1350 *flags = noti->flags_for_property;
1352 return NOTIFICATION_ERROR_NONE;
1355 EXPORT_API int notification_set_display_applist(notification_h noti,
1358 /* Check noti is valid data */
1360 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1364 if (applist == 0xffffffff) /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1365 applist = NOTIFICATION_DISPLAY_APP_ALL;
1367 noti->display_applist = applist;
1369 return NOTIFICATION_ERROR_NONE;
1372 EXPORT_API int notification_get_display_applist(notification_h noti,
1375 /* Check noti and applist are valid data */
1376 if (noti == NULL || applist == NULL)
1377 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1380 *applist = noti->display_applist;
1382 return NOTIFICATION_ERROR_NONE;
1385 EXPORT_API int notification_set_size(notification_h noti,
1388 /* Check noti is valid data */
1390 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1392 /* Save progress size */
1393 noti->progress_size = size;
1395 return NOTIFICATION_ERROR_NONE;
1398 EXPORT_API int notification_get_size(notification_h noti,
1401 /* Check noti and size is valid data */
1402 if (noti == NULL || size == NULL)
1403 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1405 /* Set progress size */
1406 *size = noti->progress_size;
1408 return NOTIFICATION_ERROR_NONE;
1411 EXPORT_API int notification_set_progress(notification_h noti,
1414 /* Check noti is valid data */
1416 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1418 /* Save progress percentage */
1419 noti->progress_percentage = percentage;
1421 return NOTIFICATION_ERROR_NONE;
1424 EXPORT_API int notification_get_progress(notification_h noti,
1427 /* Check noti and percentage are valid data */
1428 if (noti == NULL || percentage == NULL)
1429 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1431 /* Set progress percentage */
1432 *percentage = noti->progress_percentage;
1434 return NOTIFICATION_ERROR_NONE;
1437 EXPORT_API int notification_get_pkgname(notification_h noti,
1440 /* Check noti and pkgname are valid data */
1441 if (noti == NULL || pkgname == NULL)
1442 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1444 /* Get caller pkgname */
1445 if (noti->caller_pkgname)
1446 *pkgname = noti->caller_pkgname;
1450 return NOTIFICATION_ERROR_NONE;
1453 EXPORT_API int notification_set_layout(notification_h noti,
1454 notification_ly_type_e layout)
1456 /* check noti and pkgname are valid data */
1457 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX))
1458 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1460 noti->layout = layout;
1462 return NOTIFICATION_ERROR_NONE;
1465 EXPORT_API int notification_get_layout(notification_h noti,
1466 notification_ly_type_e *layout)
1468 /* Check noti and pkgname are valid data */
1469 if (noti == NULL || layout == NULL)
1470 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1472 *layout = noti->layout;
1474 return NOTIFICATION_ERROR_NONE;
1479 EXPORT_API int notification_get_type(notification_h noti,
1480 notification_type_e *type)
1482 /* Check noti and type is valid data */
1483 if (noti == NULL || type == NULL)
1484 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1489 return NOTIFICATION_ERROR_NONE;
1492 EXPORT_API int notification_post(notification_h noti)
1494 return notification_post_for_uid(noti, getuid());
1497 EXPORT_API int notification_update(notification_h noti)
1499 return notification_update_for_uid(noti, getuid());
1502 EXPORT_API int notification_delete_all(notification_type_e type)
1504 return notification_delete_all_for_uid(type, getuid());
1507 EXPORT_API int notification_delete(notification_h noti)
1509 return notification_delete_for_uid(noti, getuid());
1512 static notification_h _notification_create(notification_type_e type)
1514 notification_h noti = NULL;
1515 package_info_h package_info = NULL;
1516 char *app_id = NULL;
1517 char *domain_name = NULL;
1518 char *app_root_path = NULL;
1519 char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1520 int err_app_manager = APP_MANAGER_ERROR_NONE;
1522 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1523 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1524 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1528 noti = (notification_h) calloc(1, sizeof(struct _notification));
1530 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1531 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1537 if (type == NOTIFICATION_TYPE_NOTI)
1538 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1539 else if (type == NOTIFICATION_TYPE_ONGOING)
1540 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1542 noti->caller_pkgname = notification_get_pkgname_by_pid();
1543 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1544 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1545 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1546 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1547 noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1548 noti->auto_remove = true;
1549 noti->ongoing_flag = false;
1551 err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1552 if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1553 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]", err_app_manager, app_id);
1557 /* app name is used as domain name */
1558 /* domain_name is allocated by app_get_package_app_name */
1559 err_app_manager = app_get_package_app_name(app_id, &domain_name);
1561 if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1562 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]", err_app_manager, domain_name);
1566 err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1568 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1569 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p] caller_pkgname[%s]",
1570 err_app_manager, package_info, noti->caller_pkgname);
1574 err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1576 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1577 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]", err_app_manager, app_root_path);
1581 snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1583 noti->domain = strdup(domain_name);
1584 noti->dir = strdup(locale_directory);
1594 free(app_root_path);
1597 package_info_destroy(package_info);
1601 * Other fields are already initialized with ZERO.
1603 set_last_result(NOTIFICATION_ERROR_NONE);
1607 EXPORT_API notification_h notification_create(notification_type_e type)
1609 return _notification_create(type);
1612 EXPORT_API notification_h notification_load_by_tag(const char *tag)
1614 return notification_load_by_tag_for_uid(tag, getuid());
1617 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1620 notification_h new_noti = NULL;
1622 if (noti == NULL || clone == NULL) {
1623 NOTIFICATION_ERR("INVALID PARAMETER.");
1624 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1627 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1628 if (new_noti == NULL) {
1629 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1630 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1633 new_noti->type = noti->type;
1634 new_noti->layout = noti->layout;
1636 new_noti->group_id = noti->group_id;
1637 new_noti->internal_group_id = noti->internal_group_id;
1638 new_noti->priv_id = noti->priv_id;
1640 if (noti->caller_pkgname != NULL)
1641 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1643 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1645 if (noti->launch_pkgname != NULL)
1646 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1648 new_noti->launch_pkgname = NULL;
1650 if (noti->args != NULL)
1651 new_noti->args = bundle_dup(noti->args);
1653 new_noti->args = NULL;
1655 if (noti->group_args != NULL)
1656 new_noti->group_args = bundle_dup(noti->group_args);
1658 new_noti->group_args = NULL;
1660 if (noti->b_execute_option != NULL)
1661 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1663 new_noti->b_execute_option = NULL;
1665 if (noti->b_service_responding != NULL)
1666 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1668 new_noti->b_service_responding = NULL;
1670 if (noti->b_service_single_launch != NULL)
1671 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1673 new_noti->b_service_single_launch = NULL;
1675 if (noti->b_service_multi_launch != NULL)
1676 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1678 new_noti->b_service_multi_launch = NULL;
1680 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1681 if (noti->b_event_handler[i] != NULL)
1682 new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1684 new_noti->b_event_handler[i] = NULL;
1687 new_noti->sound_type = noti->sound_type;
1688 if (noti->sound_path != NULL)
1689 new_noti->sound_path = strdup(noti->sound_path);
1691 new_noti->sound_path = NULL;
1693 new_noti->vibration_type = noti->vibration_type;
1694 if (noti->vibration_path != NULL)
1695 new_noti->vibration_path = strdup(noti->vibration_path);
1697 new_noti->vibration_path = NULL;
1699 new_noti->led_operation = noti->led_operation;
1700 new_noti->led_argb = noti->led_argb;
1701 new_noti->led_on_ms = noti->led_on_ms;
1702 new_noti->led_off_ms = noti->led_off_ms;
1704 if (noti->domain != NULL)
1705 new_noti->domain = strdup(noti->domain);
1707 new_noti->domain = NULL;
1709 if (noti->dir != NULL)
1710 new_noti->dir = strdup(noti->dir);
1712 new_noti->dir = NULL;
1714 if (noti->b_text != NULL)
1715 new_noti->b_text = bundle_dup(noti->b_text);
1717 new_noti->b_text = NULL;
1719 if (noti->b_key != NULL)
1720 new_noti->b_key = bundle_dup(noti->b_key);
1722 new_noti->b_key = NULL;
1724 if (noti->tag != NULL)
1725 new_noti->tag = strdup(noti->tag);
1727 new_noti->tag = NULL;
1729 if (noti->b_format_args != NULL)
1730 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1732 new_noti->b_format_args = NULL;
1734 new_noti->num_format_args = noti->num_format_args;
1736 if (noti->b_image_path != NULL)
1737 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1739 new_noti->b_image_path = NULL;
1741 new_noti->time = noti->time;
1742 new_noti->insert_time = noti->insert_time;
1744 new_noti->flags_for_property = noti->flags_for_property;
1745 new_noti->display_applist = noti->display_applist;
1747 new_noti->progress_size = noti->progress_size;
1748 new_noti->progress_percentage = noti->progress_percentage;
1750 new_noti->ongoing_flag = noti->ongoing_flag;
1751 new_noti->auto_remove = noti->auto_remove;
1752 new_noti->uid = noti->uid;
1754 new_noti->app_icon_path = NULL;
1755 new_noti->app_name = NULL;
1756 new_noti->temp_title = NULL;
1757 new_noti->temp_content = NULL;
1761 return NOTIFICATION_ERROR_NONE;
1765 EXPORT_API int notification_free(notification_h noti)
1769 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1771 if (noti->caller_pkgname)
1772 free(noti->caller_pkgname);
1774 if (noti->launch_pkgname)
1775 free(noti->launch_pkgname);
1778 bundle_free(noti->args);
1780 if (noti->group_args)
1781 bundle_free(noti->group_args);
1783 if (noti->b_execute_option)
1784 bundle_free(noti->b_execute_option);
1786 if (noti->b_service_responding)
1787 bundle_free(noti->b_service_responding);
1789 if (noti->b_service_single_launch)
1790 bundle_free(noti->b_service_single_launch);
1792 if (noti->b_service_multi_launch)
1793 bundle_free(noti->b_service_multi_launch);
1795 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1796 if (noti->b_event_handler[i] != NULL)
1797 bundle_free(noti->b_event_handler[i]);
1800 if (noti->sound_path)
1801 free(noti->sound_path);
1803 if (noti->vibration_path)
1804 free(noti->vibration_path);
1813 bundle_free(noti->b_text);
1816 bundle_free(noti->b_key);
1818 if (noti->b_format_args)
1819 bundle_free(noti->b_format_args);
1821 if (noti->b_image_path)
1822 bundle_free(noti->b_image_path);
1824 if (noti->app_icon_path)
1825 free(noti->app_icon_path);
1828 free(noti->app_name);
1830 if (noti->temp_title)
1831 free(noti->temp_title);
1833 if (noti->temp_content)
1834 free(noti->temp_content);
1841 return NOTIFICATION_ERROR_NONE;
1844 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
1846 /* Check noti is valid data */
1848 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1851 /* save input TAG */
1852 if (noti->tag != NULL)
1855 noti->tag = strdup(tag);
1858 return NOTIFICATION_ERROR_NONE;
1862 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
1864 /* Check noti is valid data */
1866 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1869 return NOTIFICATION_ERROR_NONE;
1872 /* LCOV_EXCL_START */
1873 void notification_call_posted_toast_cb(const char *message)
1875 if (posted_toast_message_cb != NULL)
1876 posted_toast_message_cb((void *)message);
1878 /* LCOV_EXCL_STOP */
1880 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
1883 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1885 noti->ongoing_flag = ongoing_flag;
1887 return NOTIFICATION_ERROR_NONE;
1890 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
1892 if (noti == NULL || ongoing_flag == NULL)
1893 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1895 *ongoing_flag = noti->ongoing_flag;
1897 return NOTIFICATION_ERROR_NONE;
1901 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
1903 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
1904 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1906 return NOTIFICATION_ERROR_NONE;
1909 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
1911 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
1912 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1914 if (noti->b_event_handler[button_index - 1]) {
1915 bundle_free(noti->b_event_handler[button_index - 1]);
1916 noti->b_event_handler[button_index - 1] = NULL;
1919 return NOTIFICATION_ERROR_NONE;
1922 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
1925 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1927 noti->auto_remove = auto_remove;
1929 return NOTIFICATION_ERROR_NONE;
1932 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
1934 if (noti == NULL || auto_remove == NULL)
1935 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1937 *auto_remove = noti->auto_remove;
1939 return NOTIFICATION_ERROR_NONE;