4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include <dbus/dbus.h>
29 #include <dbus/dbus-glib-lowlevel.h>
32 #include <app_internal.h>
33 #include <app_manager.h>
34 #include <app_control_internal.h>
35 #include <package_manager.h>
40 #include <vconf-keys.h>
43 #include <notification.h>
44 #include <notification_list.h>
45 #include <notification_debug.h>
46 #include <notification_private.h>
47 #include <notification_noti.h>
48 #include <notification_ongoing.h>
49 #include <notification_group.h>
50 #include <notification_ipc.h>
51 #include <notification_internal.h>
53 static void (*posted_toast_message_cb) (void *data);
55 #define NOTI_TEXT_RESULT_LEN 2048
56 #define NOTI_PKGNAME_LEN 512
58 char *notification_get_pkgname_by_pid(void)
60 char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
61 int pid = 0, ret = AUL_R_OK;
67 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
68 if (ret != AUL_R_OK) {
69 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
71 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
73 fd = open(buf, O_RDONLY);
78 ret = read(fd, pkgname, sizeof(pkgname) - 1);
88 * "ret" is not able to be larger than "sizeof(pkgname) - 1",
89 * if the system is not going wrong.
92 if (strlen(pkgname) <= 0) {
97 dup_pkgname = strdup(pkgname);
99 NOTIFICATION_ERR("Heap: %d\n", errno);
104 EXPORT_API int notification_set_image(notification_h noti,
105 notification_image_type_e type,
106 const char *image_path)
109 char buf_key[32] = { 0, };
110 char *ret_val = NULL;
112 /* Check noti and image_path are valid data */
113 if (noti == NULL || image_path == NULL) {
114 return NOTIFICATION_ERROR_INVALID_PARAMETER;
117 /* Check image type is valid type */
118 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
119 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
120 return NOTIFICATION_ERROR_INVALID_PARAMETER;
123 /* Check image path bundle is exist */
124 if (noti->b_image_path) {
125 /* If image path bundle is exist, store local bundle value */
126 b = noti->b_image_path;
128 /* Set image type to key as char string type */
129 snprintf(buf_key, sizeof(buf_key), "%d", type);
131 /* Get value using key */
132 bundle_get_str(b, buf_key, &ret_val);
133 if (ret_val != NULL) {
134 /* If key is exist, remove this value to store new image path */
135 bundle_del(b, buf_key);
138 /* Add new image path with type key */
139 bundle_add_str(b, buf_key, image_path);
141 /* If image path bundle is not exist, create new one */
144 /* Set image type to key as char string type */
145 snprintf(buf_key, sizeof(buf_key), "%d", type);
147 /* Add new image path with type key */
148 bundle_add_str(b, buf_key, image_path);
150 /* Save to image path bundle */
151 noti->b_image_path = b;
154 return NOTIFICATION_ERROR_NONE;
157 EXPORT_API int notification_get_image(notification_h noti,
158 notification_image_type_e type,
162 char buf_key[32] = { 0, };
163 char *ret_val = NULL;
165 /* Check noti and image_path is valid data */
166 if (noti == NULL || image_path == NULL) {
167 return NOTIFICATION_ERROR_INVALID_PARAMETER;
170 /* Check image type is valid data */
171 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
172 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
173 return NOTIFICATION_ERROR_INVALID_PARAMETER;
176 /* Check image path bundle exist */
177 if (noti->b_image_path) {
178 /* If image path bundle exist, store local bundle data */
179 b = noti->b_image_path;
181 /* Set image type to key as char string type */
182 snprintf(buf_key, sizeof(buf_key), "%d", type);
184 /* Get value of key */
185 bundle_get_str(b, buf_key, &ret_val);
187 *image_path = ret_val;
189 /* If image path bundle does not exist, image path is NULL */
193 /* If image path is NULL and type is ICON, icon path set from AIL */
194 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
195 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
196 /* Check App icon path is already set */
197 if (noti->app_icon_path != NULL) {
198 /* image path will be app icon path */
199 *image_path = noti->app_icon_path;
205 return NOTIFICATION_ERROR_NONE;
208 EXPORT_API int notification_set_time(notification_h noti,
211 /* Check noti is valid data */
213 return NOTIFICATION_ERROR_INVALID_PARAMETER;
216 if (input_time == 0) {
217 /* If input time is 0, set current time */
218 noti->time = time(NULL);
220 /* save input time */
221 noti->time = input_time;
224 return NOTIFICATION_ERROR_NONE;
227 EXPORT_API int notification_get_time(notification_h noti,
230 /* Check noti and time is valid data */
231 if (noti == NULL || ret_time == NULL) {
232 return NOTIFICATION_ERROR_INVALID_PARAMETER;
235 /* Set time infomation */
236 *ret_time = noti->time;
238 return NOTIFICATION_ERROR_NONE;
241 EXPORT_API int notification_get_insert_time(notification_h noti,
244 /* Check noti and ret_time is valid data */
245 if (noti == NULL || ret_time == NULL) {
246 return NOTIFICATION_ERROR_INVALID_PARAMETER;
249 /* Set insert time information */
250 *ret_time = noti->insert_time;
252 return NOTIFICATION_ERROR_NONE;
255 EXPORT_API int notification_set_text(notification_h noti,
256 notification_text_type_e type,
262 char buf_key[32] = { 0, };
263 char buf_val[1024] = { 0, };
264 char *ret_val = NULL;
266 notification_variable_type_e var_type;
268 int noti_err = NOTIFICATION_ERROR_NONE;
269 int var_value_int = 0;
270 double var_value_double = 0.0;
271 char *var_value_string = NULL;
272 notification_count_pos_type_e var_value_count =
273 NOTIFICATION_COUNT_POS_NONE;
275 /* Check noti is valid data */
277 return NOTIFICATION_ERROR_INVALID_PARAMETER;
280 /* Check text type is valid type */
281 if (type <= NOTIFICATION_TEXT_TYPE_NONE
282 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
283 return NOTIFICATION_ERROR_INVALID_PARAMETER;
286 /* Check text bundle exist */
288 if (noti->b_text != NULL) {
289 /* If text bundle exist, store local bundle data */
292 /* Make type to key as char string */
293 snprintf(buf_key, sizeof(buf_key), "%d", type);
295 /* Get value using type key */
296 bundle_get_str(b, buf_key, &ret_val);
297 if (ret_val != NULL) {
298 /* If value exist, remove this to add new value */
299 bundle_del(b, buf_key);
302 snprintf(buf_val, sizeof(buf_val), "%s", text);
304 /* Add new text value */
305 bundle_add_str(b, buf_key, buf_val);
307 /* If text bundle does not exist, create new one */
310 /* Make type to key as char string */
311 snprintf(buf_key, sizeof(buf_key), "%d", type);
313 snprintf(buf_val, sizeof(buf_val), "%s", text);
315 /* Add new text value */
316 bundle_add_str(b, buf_key, buf_val);
318 /* Save text bundle */
322 /* Reset if text is NULL */
323 if (noti->b_text != NULL) {
324 /* If text bundle exist, store local bundle data */
327 /* Make type to key as char string */
328 snprintf(buf_key, sizeof(buf_key), "%d", type);
330 /* Get value using type key */
331 bundle_get_str(b, buf_key, &ret_val);
332 if (ret_val != NULL) {
333 /* If value exist, remove this */
334 bundle_del(b, buf_key);
339 /* Save key if key is valid data */
341 /* Check key bundle exist */
342 if (noti->b_key != NULL) {
343 /* If key bundle exist, store local bundle data */
346 /* Make type to key as char string */
347 snprintf(buf_key, sizeof(buf_key), "%d", type);
349 /* Get value using type key */
350 bundle_get_str(b, buf_key, &ret_val);
351 if (ret_val != NULL) {
352 /* If value exist, remove this to add new value */
353 bundle_del(b, buf_key);
356 snprintf(buf_val, sizeof(buf_val), "%s", key);
358 /* Add new key value */
359 bundle_add_str(b, buf_key, buf_val);
361 /* If key bundle does not exist, create new one */
364 /* Make type to key as char string */
365 snprintf(buf_key, sizeof(buf_key), "%d", type);
367 snprintf(buf_val, sizeof(buf_val), "%s", key);
369 /* Add new key value */
370 bundle_add_str(b, buf_key, buf_val);
372 /* Save key bundle */
376 /* Reset if key is NULL */
377 if (noti->b_key != NULL) {
378 /* If key bundle exist, store local bundle data */
381 /* Make type to key as char string */
382 snprintf(buf_key, sizeof(buf_key), "%d", type);
384 /* Get value using type key */
385 bundle_get_str(b, buf_key, &ret_val);
386 if (ret_val != NULL) {
387 /* If value exist, remove this */
388 bundle_del(b, buf_key);
393 if (noti->b_format_args != NULL) {
394 b = noti->b_format_args;
399 va_start(var_args, args_type);
401 var_type = args_type;
404 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
406 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
407 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
409 bundle_get_str(b, buf_key, &ret_val);
410 if (ret_val != NULL) {
411 bundle_del(b, buf_key);
414 bundle_add_str(b, buf_key, buf_val);
417 case NOTIFICATION_VARIABLE_TYPE_INT:
418 var_value_int = va_arg(var_args, int);
421 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
423 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
425 bundle_get_str(b, buf_key, &ret_val);
426 if (ret_val != NULL) {
427 bundle_del(b, buf_key);
430 bundle_add_str(b, buf_key, buf_val);
432 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
433 var_value_double = va_arg(var_args, double);
436 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
438 snprintf(buf_val, sizeof(buf_val), "%.2f",
441 bundle_get_str(b, buf_key, &ret_val);
442 if (ret_val != NULL) {
443 bundle_del(b, buf_key);
446 bundle_add_str(b, buf_key, buf_val);
448 case NOTIFICATION_VARIABLE_TYPE_STRING:
449 var_value_string = va_arg(var_args, char *);
452 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
454 snprintf(buf_val, sizeof(buf_val), "%s",
457 bundle_get_str(b, buf_key, &ret_val);
458 if (ret_val != NULL) {
459 bundle_del(b, buf_key);
462 bundle_add_str(b, buf_key, buf_val);
464 case NOTIFICATION_VARIABLE_TYPE_COUNT:
466 va_arg(var_args, notification_count_pos_type_e);
469 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
471 snprintf(buf_val, sizeof(buf_val), "%d",
474 bundle_get_str(b, buf_key, &ret_val);
475 if (ret_val != NULL) {
476 bundle_del(b, buf_key);
479 bundle_add_str(b, buf_key, buf_val);
482 NOTIFICATION_ERR("Error. invalid variable type. : %d",
484 noti_err = NOTIFICATION_ERROR_INVALID_PARAMETER;
489 var_type = va_arg(var_args, notification_variable_type_e);
493 if (noti_err == NOTIFICATION_ERROR_NONE) {
494 noti->num_format_args = num_args;
496 noti->num_format_args = 0;
499 snprintf(buf_key, sizeof(buf_key), "num%d", type);
500 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
502 bundle_get_str(b, buf_key, &ret_val);
503 if (ret_val != NULL) {
504 bundle_del(b, buf_key);
507 bundle_add_str(b, buf_key, buf_val);
509 noti->b_format_args = b;
514 EXPORT_API int notification_get_text(notification_h noti,
515 notification_text_type_e type,
519 char buf_key[32] = { 0, };
520 char *ret_val = NULL;
521 char *get_str = NULL;
522 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
523 //int display_option_flag = 0;
525 char *temp_str = NULL;
526 char *translated_str = NULL;
527 char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
528 char buf_str[1024] = { 0, };
530 notification_variable_type_e ret_var_type = 0;
531 int ret_variable_int = 0;
532 double ret_variable_double = 0.0;
534 /* Check noti is valid data */
535 if (noti == NULL || text == NULL) {
536 return NOTIFICATION_ERROR_INVALID_PARAMETER;
539 /* Check text type is valid type */
540 if (type <= NOTIFICATION_TEXT_TYPE_NONE
541 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
542 return NOTIFICATION_ERROR_INVALID_PARAMETER;
546 if (noti->b_key != NULL) {
549 /* Get text domain and dir */
550 //_notification_get_text_domain(noti);
552 snprintf(buf_key, sizeof(buf_key), "%d", type);
554 bundle_get_str(b, buf_key, &ret_val);
555 if (ret_val != NULL && noti->domain != NULL
556 && noti->dir != NULL) {
557 /* Get application string */
558 bindtextdomain(noti->domain, noti->dir);
560 get_str = dgettext(noti->domain, ret_val);
561 } else if (ret_val != NULL) {
562 /* Get system string */
563 get_str = dgettext("sys_string", ret_val);
569 if (get_str == NULL && noti->b_text != NULL) {
572 snprintf(buf_key, sizeof(buf_key), "%d", type);
574 bundle_get_str(b, buf_key, &get_str);
579 if (get_str != NULL) {
580 /* Get number format args */
581 b = noti->b_format_args;
582 noti->num_format_args = 0;
585 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
586 bundle_get_str(b, buf_key, &ret_val);
587 if (ret_val != NULL) {
588 noti->num_format_args = atoi(ret_val);
592 if (noti->num_format_args == 0) {
593 *text = (char *)get_str;
595 /* Check first variable is count, LEFT pos */
596 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
597 check_type, num_args);
598 bundle_get_str(b, buf_key, &ret_val);
599 if (ret_val != NULL) {
600 ret_var_type = atoi(ret_val);
603 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
605 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
606 check_type, num_args);
607 bundle_get_str(b, buf_key, &ret_val);
608 if (ret_val != NULL) {
609 ret_variable_int = atoi(ret_val);
612 if (ret_variable_int ==
613 NOTIFICATION_COUNT_POS_LEFT) {
614 notification_noti_get_count(noti->type,
615 noti->caller_pkgname,
619 snprintf(buf_str, sizeof(buf_str),
620 "%d ", ret_variable_int);
622 int src_len = strlen(result_str);
623 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
625 strncat(result_str, buf_str,
631 /* Check variable IN pos */
632 for (temp_str = (char *)get_str; *temp_str != '\0';
634 if (*temp_str != '%') {
635 strncat(result_str, temp_str, 1);
637 if (*(temp_str + 1) == '%') {
638 strncat(result_str, temp_str,
640 } else if (*(temp_str + 1) == 'd') {
642 ret_variable_int = 0;
646 "%dtype%d", check_type,
648 bundle_get_str(b, buf_key, &ret_val);
649 if (ret_val != NULL) {
650 ret_var_type = atoi(ret_val);
653 NOTIFICATION_VARIABLE_TYPE_COUNT)
655 /* Get notification count */
656 notification_noti_get_count
658 noti->caller_pkgname,
669 bundle_get_str(b, buf_key, &ret_val);
670 if (ret_val != NULL) {
671 ret_variable_int = atoi(ret_val);
676 sizeof(buf_str), "%d",
679 int src_len = strlen(result_str);
680 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
682 strncat(result_str, buf_str,
688 } else if (*(temp_str + 1) == 's') {
693 check_type, num_args);
694 bundle_get_str(b, buf_key, &ret_val);
696 if (ret_val != NULL && noti->domain != NULL && noti->dir != NULL) {
697 /* Get application string */
698 bindtextdomain(noti->domain, noti->dir);
699 translated_str = dgettext(noti->domain, ret_val);
700 NOTIFICATION_INFO("translated_str[%s]", translated_str);
701 } else if (ret_val != NULL) {
702 /* Get system string */
703 translated_str = dgettext("sys_string", ret_val);
704 NOTIFICATION_INFO("translated_str[%s]", translated_str);
706 translated_str = NULL;
709 strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
711 int src_len = strlen(result_str);
712 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
714 strncat(result_str, buf_str,
720 } else if (*(temp_str + 1) == 'f') {
725 check_type, num_args);
726 bundle_get_str(b, buf_key, &ret_val);
727 if (ret_val != NULL) {
728 ret_variable_double = atof(ret_val);
734 ret_variable_double);
736 int src_len = strlen(result_str);
737 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
739 strncat(result_str, buf_str,
745 } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
746 if (*(temp_str + 3) == 'd') {
748 ret_variable_int = 0;
752 "%dtype%d", check_type,
753 num_args + *(temp_str + 1) - 49);
754 bundle_get_str(b, buf_key, &ret_val);
755 if (ret_val != NULL) {
756 ret_var_type = atoi(ret_val);
759 NOTIFICATION_VARIABLE_TYPE_COUNT)
761 /* Get notification count */
762 notification_noti_get_count
764 noti->caller_pkgname,
775 num_args + *(temp_str + 1) - 49);
776 bundle_get_str(b, buf_key, &ret_val);
777 if (ret_val != NULL) {
778 ret_variable_int = atoi(ret_val);
783 sizeof(buf_str), "%d",
786 int src_len = strlen(result_str);
787 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
789 strncat(result_str, buf_str,
793 } else if (*(temp_str + 3) == 's') {
798 check_type, num_args + *(temp_str + 1) - 49);
799 bundle_get_str(b, buf_key, &ret_val);
802 sizeof(buf_str), "%s",
805 int src_len = strlen(result_str);
806 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
808 strncat(result_str, buf_str,
812 } else if (*(temp_str + 3) == 'f') {
817 check_type, num_args + *(temp_str + 1) - 49);
818 bundle_get_str(b, buf_key, &ret_val);
819 if (ret_val != NULL) {
820 ret_variable_double = atof(ret_val);
826 ret_variable_double);
828 int src_len = strlen(result_str);
829 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
831 strncat(result_str, buf_str,
841 /* Check last variable is count, LEFT pos */
842 if (num_args < noti->num_format_args) {
843 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
844 check_type, num_args);
845 bundle_get_str(b, buf_key, &ret_val);
846 if (ret_val != NULL) {
847 ret_var_type = atoi(ret_val);
851 NOTIFICATION_VARIABLE_TYPE_COUNT) {
853 snprintf(buf_key, sizeof(buf_key),
854 "%dvalue%d", check_type,
856 bundle_get_str(b, buf_key, &ret_val);
857 if (ret_val != NULL) {
858 ret_variable_int = atoi(ret_val);
861 if (ret_variable_int ==
862 NOTIFICATION_COUNT_POS_RIGHT) {
863 notification_noti_get_count
865 noti->caller_pkgname,
870 sizeof(buf_str), " %d",
873 int src_len = strlen(result_str);
874 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
876 strncat(result_str, buf_str,
885 switch (check_type) {
886 case NOTIFICATION_TEXT_TYPE_TITLE:
887 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
888 if (noti->temp_title != NULL)
889 free(noti->temp_title);
891 noti->temp_title = strdup(result_str);
893 *text = noti->temp_title;
895 case NOTIFICATION_TEXT_TYPE_CONTENT:
896 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
897 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
898 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
899 if (noti->temp_content !=
901 free(noti->temp_content);
903 noti->temp_content = strdup(result_str);
905 *text = noti->temp_content;
917 return NOTIFICATION_ERROR_NONE;
920 EXPORT_API int notification_set_text_domain(notification_h noti,
924 /* check noti and domain is valid data */
925 if (noti == NULL || domain == NULL || dir == NULL) {
926 return NOTIFICATION_ERROR_INVALID_PARAMETER;
931 /* Remove previous domain */
935 noti->domain = strdup(domain);
937 /* Check locale dir */
939 /* Remove previous locale dir */
942 /* Copy locale dir */
943 noti->dir = strdup(dir);
945 return NOTIFICATION_ERROR_NONE;
948 EXPORT_API int notification_get_text_domain(notification_h noti,
952 /* Check noti is valid data */
954 return NOTIFICATION_ERROR_INVALID_PARAMETER;
958 if (domain != NULL && noti->domain != NULL) {
959 *domain = noti->domain;
963 if (dir != NULL && noti->dir != NULL) {
967 return NOTIFICATION_ERROR_NONE;
970 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
973 int ret = NOTIFICATION_ERROR_NONE;
974 char buf[256] = { 0, };
975 char buf_tag[512] = { 0, };
978 return NOTIFICATION_ERROR_INVALID_PARAMETER;
981 return NOTIFICATION_ERROR_INVALID_PARAMETER;
983 if (type <= NOTIFICATION_TEXT_TYPE_NONE
984 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
985 return NOTIFICATION_ERROR_INVALID_PARAMETER;
989 snprintf(buf, sizeof(buf), "%lu", time);
990 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
992 if (ret != NOTIFICATION_ERROR_NONE) {
996 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
999 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
1002 int ret = NOTIFICATION_ERROR_NONE;
1005 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1008 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1010 if (type <= NOTIFICATION_TEXT_TYPE_NONE
1011 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1012 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1015 char *ret_text = NULL;
1016 ret = notification_get_text(noti, type, &ret_text);
1018 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
1019 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1022 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
1023 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1026 char *tag_value = NULL;
1027 tag_value = notification_noti_strip_tag(ret_text);
1028 if (tag_value == NULL) {
1029 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1032 *time = atol(tag_value);
1035 return NOTIFICATION_ERROR_NONE;
1038 EXPORT_API int notification_set_sound(notification_h noti,
1039 notification_sound_type_e type,
1042 /* Check noti is valid data */
1044 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1047 /* Check type is valid */
1048 if (type < NOTIFICATION_SOUND_TYPE_NONE
1049 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1050 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1053 /* Save sound type */
1054 noti->sound_type = type;
1056 /* Save sound path if user data type */
1057 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1058 if (noti->sound_path != NULL) {
1059 free(noti->sound_path);
1062 noti->sound_path = strdup(path);
1064 if (noti->sound_path != NULL) {
1065 free(noti->sound_path);
1066 noti->sound_path = NULL;
1068 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1069 noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1070 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1074 return NOTIFICATION_ERROR_NONE;
1077 EXPORT_API int notification_get_sound(notification_h noti,
1078 notification_sound_type_e *type,
1081 /* check noti and type is valid data */
1082 if (noti == NULL || type == NULL) {
1083 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1086 /* Set sound type */
1087 *type = noti->sound_type;
1089 /* Set sound path if user data type */
1090 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1092 *path = noti->sound_path;
1095 return NOTIFICATION_ERROR_NONE;
1098 EXPORT_API int notification_set_vibration(notification_h noti,
1099 notification_vibration_type_e type,
1102 /* Check noti is valid data */
1104 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1107 /* Check type is valid */
1108 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1109 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1110 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1113 /* Save vibration type */
1114 noti->vibration_type = type;
1116 /* Save sound path if user data type */
1117 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1118 if (noti->vibration_path != NULL) {
1119 free(noti->vibration_path);
1122 noti->vibration_path = strdup(path);
1124 if (noti->vibration_path != NULL) {
1125 free(noti->vibration_path);
1126 noti->vibration_path = NULL;
1128 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1129 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1130 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1134 return NOTIFICATION_ERROR_NONE;
1138 EXPORT_API int notification_get_vibration(notification_h noti,
1139 notification_vibration_type_e *type,
1142 /* check noti and type is valid data */
1143 if (noti == NULL || type == NULL) {
1144 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1147 /* Set vibration type */
1148 *type = noti->vibration_type;
1150 /* Set sound path if user data type */
1151 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1153 *path = noti->vibration_path;
1156 return NOTIFICATION_ERROR_NONE;
1159 EXPORT_API int notification_set_led(notification_h noti,
1160 notification_led_op_e operation,
1163 /* Check noti is valid data */
1165 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1168 /* Check operation is valid */
1169 if (operation < NOTIFICATION_LED_OP_OFF
1170 || operation >= NOTIFICATION_LED_OP_MAX) {
1171 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1174 /* Save led operation */
1175 noti->led_operation = operation;
1177 /* Save led argb if operation is turning on LED with custom color */
1178 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1179 noti->led_argb = led_argb;
1182 return NOTIFICATION_ERROR_NONE;
1185 EXPORT_API int notification_get_led(notification_h noti,
1186 notification_led_op_e *operation,
1189 /* check noti and operation is valid data */
1190 if (noti == NULL || operation == NULL) {
1191 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1194 /* Set led operation */
1195 *operation = noti->led_operation;
1197 /* Save led argb if operation is turning on LED with custom color */
1198 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1199 && led_argb != NULL) {
1200 *led_argb = noti->led_argb;
1203 return NOTIFICATION_ERROR_NONE;
1206 EXPORT_API int notification_set_led_time_period(notification_h noti,
1207 int on_ms, int off_ms)
1209 /* Check noti is valid data */
1210 if (noti == NULL || on_ms < 0 || off_ms < 0) {
1211 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1214 /* Save led operation */
1215 noti->led_on_ms = on_ms;
1216 noti->led_off_ms = off_ms;
1218 return NOTIFICATION_ERROR_NONE;
1221 EXPORT_API int notification_get_led_time_period(notification_h noti,
1222 int *on_ms, int *off_ms)
1224 /* check noti and operation is valid data */
1226 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1230 *(on_ms) = noti->led_on_ms;
1232 *(off_ms) = noti->led_off_ms;
1234 return NOTIFICATION_ERROR_NONE;
1237 EXPORT_API int notification_set_launch_option(notification_h noti,
1238 notification_launch_option_type type, void *option)
1240 int err = NOTIFICATION_ERROR_NONE;
1243 app_control_h app_control = option;
1245 if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1246 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1250 if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1251 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1252 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1256 err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1265 EXPORT_API int notification_get_launch_option(notification_h noti,
1266 notification_launch_option_type type, void *option)
1270 app_control_h *app_control = (app_control_h *)option;
1271 app_control_h app_control_new = NULL;
1274 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1276 if (app_control == NULL) {
1277 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1279 if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1280 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1283 ret = notification_get_execute_option(noti,
1284 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1287 if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1288 ret = app_control_create(&app_control_new);
1289 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1290 ret = app_control_import_from_bundle(app_control_new, b);
1291 if (ret == APP_CONTROL_ERROR_NONE) {
1292 *app_control = app_control_new;
1294 app_control_destroy(app_control_new);
1295 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1296 return NOTIFICATION_ERROR_IO_ERROR;
1299 NOTIFICATION_ERR("Failed to create app control:%d", ret);
1300 return NOTIFICATION_ERROR_IO_ERROR;
1303 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1307 return NOTIFICATION_ERROR_NONE;
1310 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1312 int err = NOTIFICATION_ERROR_NONE;
1313 bundle *app_control_bundle = NULL;
1316 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1317 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1321 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1322 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1323 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1324 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1328 if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1329 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1333 if (noti->b_event_handler[event_type] != NULL) {
1334 bundle_free(noti->b_event_handler[event_type]);
1337 noti->b_event_handler[event_type] = app_control_bundle;
1343 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1345 int err = NOTIFICATION_ERROR_NONE;
1347 app_control_h app_control_new = NULL;
1350 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1351 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1354 if (event_handler == NULL) {
1355 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1356 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1359 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1360 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1361 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1362 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1366 b = noti->b_event_handler[event_type];
1369 NOTIFICATION_DBG("No event handler\n");
1370 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1374 err = app_control_create(&app_control_new);
1375 if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1376 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1377 err = NOTIFICATION_ERROR_IO_ERROR;
1381 err = app_control_import_from_bundle(app_control_new, b);
1382 if (err == APP_CONTROL_ERROR_NONE) {
1383 *event_handler = app_control_new;
1386 app_control_destroy(app_control_new);
1387 app_control_new = NULL;
1388 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1389 err = NOTIFICATION_ERROR_IO_ERROR;
1395 *event_handler = app_control_new;
1404 EXPORT_API int notification_set_property(notification_h noti,
1407 /* Check noti is valid data */
1409 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1413 noti->flags_for_property = flags;
1415 return NOTIFICATION_ERROR_NONE;
1418 EXPORT_API int notification_get_property(notification_h noti,
1421 /* Check noti and flags are valid data */
1422 if (noti == NULL || flags == NULL) {
1423 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1427 *flags = noti->flags_for_property;
1429 return NOTIFICATION_ERROR_NONE;
1432 EXPORT_API int notification_set_display_applist(notification_h noti,
1435 /* Check noti is valid data */
1437 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1441 if (applist == 0xffffffff) { /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1442 applist = NOTIFICATION_DISPLAY_APP_ALL;
1444 noti->display_applist = applist;
1446 return NOTIFICATION_ERROR_NONE;
1449 EXPORT_API int notification_get_display_applist(notification_h noti,
1452 /* Check noti and applist are valid data */
1453 if (noti == NULL || applist == NULL) {
1454 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1458 *applist = noti->display_applist;
1460 return NOTIFICATION_ERROR_NONE;
1463 EXPORT_API int notification_set_size(notification_h noti,
1466 /* Check noti is valid data */
1468 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1471 /* Save progress size */
1472 noti->progress_size = size;
1474 return NOTIFICATION_ERROR_NONE;
1477 EXPORT_API int notification_get_size(notification_h noti,
1480 /* Check noti and size is valid data */
1481 if (noti == NULL || size == NULL) {
1482 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1485 /* Set progress size */
1486 *size = noti->progress_size;
1488 return NOTIFICATION_ERROR_NONE;
1491 EXPORT_API int notification_set_progress(notification_h noti,
1494 /* Check noti is valid data */
1496 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1499 /* Save progress percentage */
1500 noti->progress_percentage = percentage;
1502 return NOTIFICATION_ERROR_NONE;
1505 EXPORT_API int notification_get_progress(notification_h noti,
1508 /* Check noti and percentage are valid data */
1509 if (noti == NULL || percentage == NULL) {
1510 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1513 /* Set progress percentage */
1514 *percentage = noti->progress_percentage;
1516 return NOTIFICATION_ERROR_NONE;
1519 EXPORT_API int notification_get_pkgname(notification_h noti,
1522 /* Check noti and pkgname are valid data */
1523 if (noti == NULL || pkgname == NULL) {
1524 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1527 /* Get caller pkgname */
1528 if (noti->caller_pkgname) {
1529 *pkgname = noti->caller_pkgname;
1534 return NOTIFICATION_ERROR_NONE;
1537 EXPORT_API int notification_set_layout(notification_h noti,
1538 notification_ly_type_e layout)
1540 /* check noti and pkgname are valid data */
1541 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1542 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1545 noti->layout = layout;
1547 return NOTIFICATION_ERROR_NONE;
1550 EXPORT_API int notification_get_layout(notification_h noti,
1551 notification_ly_type_e *layout)
1553 /* Check noti and pkgname are valid data */
1554 if (noti == NULL || layout == NULL) {
1555 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1558 *layout = noti->layout;
1560 return NOTIFICATION_ERROR_NONE;
1565 EXPORT_API int notification_get_type(notification_h noti,
1566 notification_type_e *type)
1568 /* Check noti and type is valid data */
1569 if (noti == NULL || type == NULL) {
1570 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1576 return NOTIFICATION_ERROR_NONE;
1579 EXPORT_API int notification_post(notification_h noti)
1584 /* Check noti is vaild data */
1586 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1589 /* Check noti type is valid type */
1590 if (noti->type <= NOTIFICATION_TYPE_NONE
1591 || noti->type >= NOTIFICATION_TYPE_MAX) {
1592 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1595 /* Save insert time */
1596 noti->insert_time = time(NULL);
1598 ret = notification_ipc_request_insert(noti, &id);
1599 if (ret != NOTIFICATION_ERROR_NONE) {
1603 NOTIFICATION_DBG("from master:%d", id);
1605 return NOTIFICATION_ERROR_NONE;
1610 EXPORT_API int notification_update(notification_h noti)
1614 /* Check noti is valid data */
1616 /* Update insert time ? */
1617 noti->insert_time = time(NULL);
1618 ret = notification_ipc_request_update(noti);
1620 notification_ipc_request_refresh();
1621 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1626 EXPORT_API int notification_delete_all(notification_type_e type)
1629 char *caller_pkgname = NULL;
1631 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1632 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1635 caller_pkgname = notification_get_pkgname_by_pid();
1637 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1639 if (caller_pkgname) {
1640 free(caller_pkgname);
1646 EXPORT_API int notification_delete(notification_h noti)
1651 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1654 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1659 static notification_h _notification_create(notification_type_e type)
1661 notification_h noti = NULL;
1662 package_info_h package_info = NULL;
1663 char *app_id = NULL;
1664 char *domain_name = NULL;
1665 char *app_root_path = NULL;
1666 char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1667 int err_app_manager = APP_MANAGER_ERROR_NONE;
1669 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1670 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1671 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1675 noti = (notification_h) calloc(1, sizeof(struct _notification));
1677 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1678 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1684 if (type == NOTIFICATION_TYPE_NOTI)
1685 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1686 else if (type == NOTIFICATION_TYPE_ONGOING)
1687 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1689 noti->caller_pkgname = notification_get_pkgname_by_pid();
1690 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1691 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1692 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1693 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1694 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1695 noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1696 noti->auto_remove = true;
1698 err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1699 if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1700 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]", err_app_manager, app_id);
1704 /* app name is used as domain name */
1705 /* domain_name is allocated by app_get_package_app_name */
1706 err_app_manager = app_get_package_app_name(app_id, &domain_name);
1708 if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1709 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]", err_app_manager, domain_name);
1713 err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1715 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1716 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p] caller_pkgname[%s]",
1717 err_app_manager, package_info, noti->caller_pkgname);
1721 err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1723 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1724 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]", err_app_manager, app_root_path);
1728 snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1730 noti->domain = strdup(domain_name);
1731 noti->dir = strdup(locale_directory);
1742 if (app_root_path) {
1743 free(app_root_path);
1747 package_info_destroy(package_info);
1752 * Other fields are already initialized with ZERO.
1754 set_last_result(NOTIFICATION_ERROR_NONE);
1758 EXPORT_API notification_h notification_create(notification_type_e type)
1760 return _notification_create(type);
1763 EXPORT_API notification_h notification_load_by_tag(const char *tag)
1766 notification_h noti = NULL;
1767 char *caller_pkgname = NULL;
1770 NOTIFICATION_ERR("Invalid parameter");
1771 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1775 caller_pkgname = notification_get_pkgname_by_pid();
1776 if (!caller_pkgname) {
1777 NOTIFICATION_ERR("Failed to get a package name");
1778 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1782 noti = (notification_h) calloc(1, sizeof(struct _notification));
1784 NOTIFICATION_ERR("Failed to alloc a new notification");
1785 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1786 free(caller_pkgname);
1791 ret = notification_noti_get_by_tag(noti, caller_pkgname, (char*)tag);
1793 free(caller_pkgname);
1795 set_last_result(ret);
1797 if (ret != NOTIFICATION_ERROR_NONE) {
1798 notification_free(noti);
1805 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1808 notification_h new_noti = NULL;
1810 if (noti == NULL || clone == NULL) {
1811 NOTIFICATION_ERR("INVALID PARAMETER.");
1812 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1815 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1816 if (new_noti == NULL) {
1817 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1818 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1821 new_noti->type = noti->type;
1822 new_noti->layout = noti->layout;
1824 new_noti->group_id = noti->group_id;
1825 new_noti->internal_group_id = noti->internal_group_id;
1826 new_noti->priv_id = noti->priv_id;
1828 if(noti->caller_pkgname != NULL) {
1829 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1831 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1833 if(noti->launch_pkgname != NULL) {
1834 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1836 new_noti->launch_pkgname = NULL;
1839 if(noti->args != NULL) {
1840 new_noti->args = bundle_dup(noti->args);
1842 new_noti->args = NULL;
1844 if(noti->group_args != NULL) {
1845 new_noti->group_args = bundle_dup(noti->group_args);
1847 new_noti->group_args = NULL;
1850 if(noti->b_execute_option != NULL) {
1851 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1853 new_noti->b_execute_option = NULL;
1855 if(noti->b_service_responding != NULL) {
1856 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1858 new_noti->b_service_responding = NULL;
1860 if(noti->b_service_single_launch != NULL) {
1861 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1863 new_noti->b_service_single_launch = NULL;
1865 if(noti->b_service_multi_launch != NULL) {
1866 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1868 new_noti->b_service_multi_launch = NULL;
1871 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1872 if(noti->b_event_handler[i] != NULL) {
1873 new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1875 new_noti->b_event_handler[i] = NULL;
1879 new_noti->sound_type = noti->sound_type;
1880 if(noti->sound_path != NULL) {
1881 new_noti->sound_path = strdup(noti->sound_path);
1883 new_noti->sound_path = NULL;
1885 new_noti->vibration_type = noti->vibration_type;
1886 if(noti->vibration_path != NULL) {
1887 new_noti->vibration_path = strdup(noti->vibration_path);
1889 new_noti->vibration_path = NULL;
1891 new_noti->led_operation = noti->led_operation;
1892 new_noti->led_argb = noti->led_argb;
1893 new_noti->led_on_ms = noti->led_on_ms;
1894 new_noti->led_off_ms = noti->led_off_ms;
1896 if(noti->domain != NULL) {
1897 new_noti->domain = strdup(noti->domain);
1899 new_noti->domain = NULL;
1901 if(noti->dir != NULL) {
1902 new_noti->dir = strdup(noti->dir);
1904 new_noti->dir = NULL;
1907 if(noti->b_text != NULL) {
1908 new_noti->b_text = bundle_dup(noti->b_text);
1910 new_noti->b_text = NULL;
1912 if(noti->b_key != NULL) {
1913 new_noti->b_key = bundle_dup(noti->b_key);
1915 new_noti->b_key = NULL;
1917 if(noti->b_format_args != NULL) {
1918 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1920 new_noti->b_format_args = NULL;
1922 new_noti->num_format_args = noti->num_format_args;
1924 if(noti->b_image_path != NULL) {
1925 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1927 new_noti->b_image_path = NULL;
1930 new_noti->time = noti->time;
1931 new_noti->insert_time = noti->insert_time;
1933 new_noti->flags_for_property = noti->flags_for_property;
1934 new_noti->display_applist = noti->display_applist;
1936 new_noti->progress_size = noti->progress_size;
1937 new_noti->progress_percentage = noti->progress_percentage;
1939 new_noti->ongoing_flag = noti->ongoing_flag;
1940 new_noti->auto_remove = noti->auto_remove;
1942 new_noti->app_icon_path = NULL;
1943 new_noti->app_name = NULL;
1944 new_noti->temp_title = NULL;
1945 new_noti->temp_content = NULL;
1949 return NOTIFICATION_ERROR_NONE;
1953 EXPORT_API int notification_free(notification_h noti)
1957 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1960 if (noti->caller_pkgname) {
1961 free(noti->caller_pkgname);
1963 if (noti->launch_pkgname) {
1964 free(noti->launch_pkgname);
1967 bundle_free(noti->args);
1969 if (noti->group_args) {
1970 bundle_free(noti->group_args);
1973 if (noti->b_execute_option) {
1974 bundle_free(noti->b_execute_option);
1976 if (noti->b_service_responding) {
1977 bundle_free(noti->b_service_responding);
1979 if (noti->b_service_single_launch) {
1980 bundle_free(noti->b_service_single_launch);
1982 if (noti->b_service_multi_launch) {
1983 bundle_free(noti->b_service_multi_launch);
1986 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1987 if(noti->b_event_handler[i] != NULL) {
1988 bundle_free(noti->b_event_handler[i]);
1992 if (noti->sound_path) {
1993 free(noti->sound_path);
1995 if (noti->vibration_path) {
1996 free(noti->vibration_path);
2007 bundle_free(noti->b_text);
2010 bundle_free(noti->b_key);
2012 if (noti->b_format_args) {
2013 bundle_free(noti->b_format_args);
2016 if (noti->b_image_path) {
2017 bundle_free(noti->b_image_path);
2020 if (noti->app_icon_path) {
2021 free(noti->app_icon_path);
2023 if (noti->app_name) {
2024 free(noti->app_name);
2026 if (noti->temp_title) {
2027 free(noti->temp_title);
2029 if (noti->temp_content) {
2030 free(noti->temp_content);
2039 return NOTIFICATION_ERROR_NONE;
2042 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
2044 /* Check noti is valid data */
2046 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2050 /* save input TAG */
2051 if (noti->tag != NULL) {
2054 noti->tag = strdup(tag);
2057 return NOTIFICATION_ERROR_NONE;
2061 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
2063 /* Check noti is valid data */
2065 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2069 return NOTIFICATION_ERROR_NONE;
2072 void notification_call_posted_toast_cb(const char *message)
2074 if (posted_toast_message_cb != NULL) {
2075 posted_toast_message_cb((void*)message);
2079 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
2082 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2084 noti->ongoing_flag = ongoing_flag;
2086 return NOTIFICATION_ERROR_NONE;
2089 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
2091 if (noti == NULL || ongoing_flag == NULL)
2092 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2094 *ongoing_flag = noti->ongoing_flag;
2096 return NOTIFICATION_ERROR_NONE;
2100 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
2102 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2103 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2105 return NOTIFICATION_ERROR_NONE;
2108 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
2110 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2111 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2113 if (noti->b_event_handler[button_index - 1]) {
2114 bundle_free(noti->b_event_handler[button_index - 1]);
2115 noti->b_event_handler[button_index - 1] = NULL;
2118 return NOTIFICATION_ERROR_NONE;
2121 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
2124 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2126 noti->auto_remove = auto_remove;
2128 return NOTIFICATION_ERROR_NONE;
2131 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
2133 if (noti == NULL || auto_remove == NULL)
2134 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2136 *auto_remove = noti->auto_remove;
2138 return NOTIFICATION_ERROR_NONE;