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) {
654 /* Get notification count */
655 notification_noti_get_count
657 noti->caller_pkgname,
668 bundle_get_str(b, buf_key, &ret_val);
669 if (ret_val != NULL) {
670 ret_variable_int = atoi(ret_val);
675 sizeof(buf_str), "%d",
678 int src_len = strlen(result_str);
679 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
681 strncat(result_str, buf_str,
687 } else if (*(temp_str + 1) == 's') {
692 check_type, num_args);
693 bundle_get_str(b, buf_key, &ret_val);
695 if (ret_val != NULL && noti->domain != NULL && noti->dir != NULL) {
696 /* Get application string */
697 bindtextdomain(noti->domain, noti->dir);
698 translated_str = dgettext(noti->domain, ret_val);
699 NOTIFICATION_INFO("translated_str[%s]", translated_str);
700 } else if (ret_val != NULL) {
701 /* Get system string */
702 translated_str = dgettext("sys_string", ret_val);
703 NOTIFICATION_INFO("translated_str[%s]", translated_str);
705 translated_str = NULL;
708 strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
710 int src_len = strlen(result_str);
711 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
713 strncat(result_str, buf_str,
719 } else if (*(temp_str + 1) == 'f') {
724 check_type, num_args);
725 bundle_get_str(b, buf_key, &ret_val);
726 if (ret_val != NULL) {
727 ret_variable_double = atof(ret_val);
733 ret_variable_double);
735 int src_len = strlen(result_str);
736 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
738 strncat(result_str, buf_str,
744 } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
745 if (*(temp_str + 3) == 'd') {
747 ret_variable_int = 0;
751 "%dtype%d", check_type,
752 num_args + *(temp_str + 1) - 49);
753 bundle_get_str(b, buf_key, &ret_val);
754 if (ret_val != NULL) {
755 ret_var_type = atoi(ret_val);
758 NOTIFICATION_VARIABLE_TYPE_COUNT) {
759 /* Get notification count */
760 notification_noti_get_count
762 noti->caller_pkgname,
773 num_args + *(temp_str + 1) - 49);
774 bundle_get_str(b, buf_key, &ret_val);
775 if (ret_val != NULL) {
776 ret_variable_int = atoi(ret_val);
781 sizeof(buf_str), "%d",
784 int src_len = strlen(result_str);
785 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
787 strncat(result_str, buf_str,
791 } else if (*(temp_str + 3) == 's') {
796 check_type, num_args + *(temp_str + 1) - 49);
797 bundle_get_str(b, buf_key, &ret_val);
800 sizeof(buf_str), "%s",
803 int src_len = strlen(result_str);
804 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
806 strncat(result_str, buf_str,
810 } else if (*(temp_str + 3) == 'f') {
815 check_type, num_args + *(temp_str + 1) - 49);
816 bundle_get_str(b, buf_key, &ret_val);
817 if (ret_val != NULL) {
818 ret_variable_double = atof(ret_val);
824 ret_variable_double);
826 int src_len = strlen(result_str);
827 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
829 strncat(result_str, buf_str,
839 /* Check last variable is count, LEFT pos */
840 if (num_args < noti->num_format_args) {
841 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
842 check_type, num_args);
843 bundle_get_str(b, buf_key, &ret_val);
844 if (ret_val != NULL) {
845 ret_var_type = atoi(ret_val);
849 NOTIFICATION_VARIABLE_TYPE_COUNT) {
851 snprintf(buf_key, sizeof(buf_key),
852 "%dvalue%d", check_type,
854 bundle_get_str(b, buf_key, &ret_val);
855 if (ret_val != NULL) {
856 ret_variable_int = atoi(ret_val);
859 if (ret_variable_int ==
860 NOTIFICATION_COUNT_POS_RIGHT) {
861 notification_noti_get_count
863 noti->caller_pkgname,
868 sizeof(buf_str), " %d",
871 int src_len = strlen(result_str);
872 int max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
874 strncat(result_str, buf_str,
883 switch (check_type) {
884 case NOTIFICATION_TEXT_TYPE_TITLE:
885 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
886 if (noti->temp_title != NULL)
887 free(noti->temp_title);
889 noti->temp_title = strdup(result_str);
891 *text = noti->temp_title;
893 case NOTIFICATION_TEXT_TYPE_CONTENT:
894 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
895 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
896 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
897 if (noti->temp_content !=
899 free(noti->temp_content);
901 noti->temp_content = strdup(result_str);
903 *text = noti->temp_content;
915 return NOTIFICATION_ERROR_NONE;
918 EXPORT_API int notification_set_text_domain(notification_h noti,
922 /* check noti and domain is valid data */
923 if (noti == NULL || domain == NULL || dir == NULL) {
924 return NOTIFICATION_ERROR_INVALID_PARAMETER;
929 /* Remove previous domain */
933 noti->domain = strdup(domain);
935 /* Check locale dir */
937 /* Remove previous locale dir */
940 /* Copy locale dir */
941 noti->dir = strdup(dir);
943 return NOTIFICATION_ERROR_NONE;
946 EXPORT_API int notification_get_text_domain(notification_h noti,
950 /* Check noti is valid data */
952 return NOTIFICATION_ERROR_INVALID_PARAMETER;
956 if (domain != NULL && noti->domain != NULL) {
957 *domain = noti->domain;
961 if (dir != NULL && noti->dir != NULL) {
965 return NOTIFICATION_ERROR_NONE;
968 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
971 int ret = NOTIFICATION_ERROR_NONE;
972 char buf[256] = { 0, };
973 char buf_tag[512] = { 0, };
976 return NOTIFICATION_ERROR_INVALID_PARAMETER;
979 return NOTIFICATION_ERROR_INVALID_PARAMETER;
981 if (type <= NOTIFICATION_TEXT_TYPE_NONE
982 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
983 return NOTIFICATION_ERROR_INVALID_PARAMETER;
987 snprintf(buf, sizeof(buf), "%lu", time);
988 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
990 if (ret != NOTIFICATION_ERROR_NONE) {
994 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
997 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
1000 int ret = NOTIFICATION_ERROR_NONE;
1003 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1006 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1008 if (type <= NOTIFICATION_TEXT_TYPE_NONE
1009 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1010 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1013 char *ret_text = NULL;
1014 ret = notification_get_text(noti, type, &ret_text);
1016 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
1017 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1020 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
1021 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1024 char *tag_value = NULL;
1025 tag_value = notification_noti_strip_tag(ret_text);
1026 if (tag_value == NULL) {
1027 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1030 *time = atol(tag_value);
1033 return NOTIFICATION_ERROR_NONE;
1036 EXPORT_API int notification_set_sound(notification_h noti,
1037 notification_sound_type_e type,
1040 /* Check noti is valid data */
1042 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1045 /* Check type is valid */
1046 if (type < NOTIFICATION_SOUND_TYPE_NONE
1047 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1048 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1051 /* Save sound type */
1052 noti->sound_type = type;
1054 /* Save sound path if user data type */
1055 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1056 if (noti->sound_path != NULL) {
1057 free(noti->sound_path);
1060 noti->sound_path = strdup(path);
1062 if (noti->sound_path != NULL) {
1063 free(noti->sound_path);
1064 noti->sound_path = NULL;
1066 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1067 noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1068 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1072 return NOTIFICATION_ERROR_NONE;
1075 EXPORT_API int notification_get_sound(notification_h noti,
1076 notification_sound_type_e *type,
1079 /* check noti and type is valid data */
1080 if (noti == NULL || type == NULL) {
1081 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1084 /* Set sound type */
1085 *type = noti->sound_type;
1087 /* Set sound path if user data type */
1088 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1090 *path = noti->sound_path;
1093 return NOTIFICATION_ERROR_NONE;
1096 EXPORT_API int notification_set_vibration(notification_h noti,
1097 notification_vibration_type_e type,
1100 /* Check noti is valid data */
1102 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1105 /* Check type is valid */
1106 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1107 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1108 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1111 /* Save vibration type */
1112 noti->vibration_type = type;
1114 /* Save sound path if user data type */
1115 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1116 if (noti->vibration_path != NULL) {
1117 free(noti->vibration_path);
1120 noti->vibration_path = strdup(path);
1122 if (noti->vibration_path != NULL) {
1123 free(noti->vibration_path);
1124 noti->vibration_path = NULL;
1126 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1127 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1128 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1132 return NOTIFICATION_ERROR_NONE;
1136 EXPORT_API int notification_get_vibration(notification_h noti,
1137 notification_vibration_type_e *type,
1140 /* check noti and type is valid data */
1141 if (noti == NULL || type == NULL) {
1142 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1145 /* Set vibration type */
1146 *type = noti->vibration_type;
1148 /* Set sound path if user data type */
1149 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1151 *path = noti->vibration_path;
1154 return NOTIFICATION_ERROR_NONE;
1157 EXPORT_API int notification_set_led(notification_h noti,
1158 notification_led_op_e operation,
1161 /* Check noti is valid data */
1163 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1166 /* Check operation is valid */
1167 if (operation < NOTIFICATION_LED_OP_OFF
1168 || operation >= NOTIFICATION_LED_OP_MAX) {
1169 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1172 /* Save led operation */
1173 noti->led_operation = operation;
1175 /* Save led argb if operation is turning on LED with custom color */
1176 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1177 noti->led_argb = led_argb;
1180 return NOTIFICATION_ERROR_NONE;
1183 EXPORT_API int notification_get_led(notification_h noti,
1184 notification_led_op_e *operation,
1187 /* check noti and operation is valid data */
1188 if (noti == NULL || operation == NULL) {
1189 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1192 /* Set led operation */
1193 *operation = noti->led_operation;
1195 /* Save led argb if operation is turning on LED with custom color */
1196 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1197 && led_argb != NULL) {
1198 *led_argb = noti->led_argb;
1201 return NOTIFICATION_ERROR_NONE;
1204 EXPORT_API int notification_set_led_time_period(notification_h noti,
1205 int on_ms, int off_ms)
1207 /* Check noti is valid data */
1208 if (noti == NULL || on_ms < 0 || off_ms < 0) {
1209 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1212 /* Save led operation */
1213 noti->led_on_ms = on_ms;
1214 noti->led_off_ms = off_ms;
1216 return NOTIFICATION_ERROR_NONE;
1219 EXPORT_API int notification_get_led_time_period(notification_h noti,
1220 int *on_ms, int *off_ms)
1222 /* check noti and operation is valid data */
1224 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1228 *(on_ms) = noti->led_on_ms;
1230 *(off_ms) = noti->led_off_ms;
1232 return NOTIFICATION_ERROR_NONE;
1235 EXPORT_API int notification_set_launch_option(notification_h noti,
1236 notification_launch_option_type type, void *option)
1238 int err = NOTIFICATION_ERROR_NONE;
1241 app_control_h app_control = option;
1243 if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1244 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1248 if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1249 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1250 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1254 err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1263 EXPORT_API int notification_get_launch_option(notification_h noti,
1264 notification_launch_option_type type, void *option)
1268 app_control_h *app_control = (app_control_h *)option;
1269 app_control_h app_control_new = NULL;
1272 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1274 if (app_control == NULL) {
1275 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1277 if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1278 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1281 ret = notification_get_execute_option(noti,
1282 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1285 if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1286 ret = app_control_create(&app_control_new);
1287 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1288 ret = app_control_import_from_bundle(app_control_new, b);
1289 if (ret == APP_CONTROL_ERROR_NONE) {
1290 *app_control = app_control_new;
1292 app_control_destroy(app_control_new);
1293 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1294 return NOTIFICATION_ERROR_IO_ERROR;
1297 NOTIFICATION_ERR("Failed to create app control:%d", ret);
1298 return NOTIFICATION_ERROR_IO_ERROR;
1301 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1305 return NOTIFICATION_ERROR_NONE;
1308 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1310 int err = NOTIFICATION_ERROR_NONE;
1311 bundle *app_control_bundle = NULL;
1314 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1315 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1319 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1320 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1321 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1322 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1326 if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1327 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1331 if (noti->b_event_handler[event_type] != NULL) {
1332 bundle_free(noti->b_event_handler[event_type]);
1335 noti->b_event_handler[event_type] = app_control_bundle;
1341 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1343 int err = NOTIFICATION_ERROR_NONE;
1345 app_control_h app_control_new = NULL;
1348 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1349 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1352 if (event_handler == NULL) {
1353 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1354 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1357 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1358 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1359 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1360 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1364 b = noti->b_event_handler[event_type];
1367 NOTIFICATION_DBG("No event handler\n");
1368 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1372 err = app_control_create(&app_control_new);
1373 if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1374 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1375 err = NOTIFICATION_ERROR_IO_ERROR;
1379 err = app_control_import_from_bundle(app_control_new, b);
1380 if (err == APP_CONTROL_ERROR_NONE) {
1381 *event_handler = app_control_new;
1383 app_control_destroy(app_control_new);
1384 app_control_new = NULL;
1385 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1386 err = NOTIFICATION_ERROR_IO_ERROR;
1392 *event_handler = app_control_new;
1401 EXPORT_API int notification_set_property(notification_h noti,
1404 /* Check noti is valid data */
1406 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1410 noti->flags_for_property = flags;
1412 return NOTIFICATION_ERROR_NONE;
1415 EXPORT_API int notification_get_property(notification_h noti,
1418 /* Check noti and flags are valid data */
1419 if (noti == NULL || flags == NULL) {
1420 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1424 *flags = noti->flags_for_property;
1426 return NOTIFICATION_ERROR_NONE;
1429 EXPORT_API int notification_set_display_applist(notification_h noti,
1432 /* Check noti is valid data */
1434 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1438 if (applist == 0xffffffff) { /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1439 applist = NOTIFICATION_DISPLAY_APP_ALL;
1441 noti->display_applist = applist;
1443 return NOTIFICATION_ERROR_NONE;
1446 EXPORT_API int notification_get_display_applist(notification_h noti,
1449 /* Check noti and applist are valid data */
1450 if (noti == NULL || applist == NULL) {
1451 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1455 *applist = noti->display_applist;
1457 return NOTIFICATION_ERROR_NONE;
1460 EXPORT_API int notification_set_size(notification_h noti,
1463 /* Check noti is valid data */
1465 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1468 /* Save progress size */
1469 noti->progress_size = size;
1471 return NOTIFICATION_ERROR_NONE;
1474 EXPORT_API int notification_get_size(notification_h noti,
1477 /* Check noti and size is valid data */
1478 if (noti == NULL || size == NULL) {
1479 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1482 /* Set progress size */
1483 *size = noti->progress_size;
1485 return NOTIFICATION_ERROR_NONE;
1488 EXPORT_API int notification_set_progress(notification_h noti,
1491 /* Check noti is valid data */
1493 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1496 /* Save progress percentage */
1497 noti->progress_percentage = percentage;
1499 return NOTIFICATION_ERROR_NONE;
1502 EXPORT_API int notification_get_progress(notification_h noti,
1505 /* Check noti and percentage are valid data */
1506 if (noti == NULL || percentage == NULL) {
1507 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1510 /* Set progress percentage */
1511 *percentage = noti->progress_percentage;
1513 return NOTIFICATION_ERROR_NONE;
1516 EXPORT_API int notification_get_pkgname(notification_h noti,
1519 /* Check noti and pkgname are valid data */
1520 if (noti == NULL || pkgname == NULL) {
1521 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1524 /* Get caller pkgname */
1525 if (noti->caller_pkgname) {
1526 *pkgname = noti->caller_pkgname;
1531 return NOTIFICATION_ERROR_NONE;
1534 EXPORT_API int notification_set_layout(notification_h noti,
1535 notification_ly_type_e layout)
1537 /* check noti and pkgname are valid data */
1538 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1539 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1542 noti->layout = layout;
1544 return NOTIFICATION_ERROR_NONE;
1547 EXPORT_API int notification_get_layout(notification_h noti,
1548 notification_ly_type_e *layout)
1550 /* Check noti and pkgname are valid data */
1551 if (noti == NULL || layout == NULL) {
1552 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1555 *layout = noti->layout;
1557 return NOTIFICATION_ERROR_NONE;
1562 EXPORT_API int notification_get_type(notification_h noti,
1563 notification_type_e *type)
1565 /* Check noti and type is valid data */
1566 if (noti == NULL || type == NULL) {
1567 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1573 return NOTIFICATION_ERROR_NONE;
1576 EXPORT_API int notification_post(notification_h noti)
1581 /* Check noti is vaild data */
1583 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1586 /* Check noti type is valid type */
1587 if (noti->type <= NOTIFICATION_TYPE_NONE
1588 || noti->type >= NOTIFICATION_TYPE_MAX) {
1589 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1592 /* Save insert time */
1593 noti->insert_time = time(NULL);
1595 ret = notification_ipc_request_insert(noti, &id);
1596 if (ret != NOTIFICATION_ERROR_NONE) {
1600 NOTIFICATION_DBG("from master:%d", id);
1602 return NOTIFICATION_ERROR_NONE;
1607 EXPORT_API int notification_update(notification_h noti)
1611 /* Check noti is valid data */
1613 /* Update insert time ? */
1614 noti->insert_time = time(NULL);
1615 ret = notification_ipc_request_update(noti);
1617 notification_ipc_request_refresh();
1618 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1623 EXPORT_API int notification_delete_all(notification_type_e type)
1626 char *caller_pkgname = NULL;
1628 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1629 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1632 caller_pkgname = notification_get_pkgname_by_pid();
1634 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1636 if (caller_pkgname) {
1637 free(caller_pkgname);
1643 EXPORT_API int notification_delete(notification_h noti)
1648 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1651 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1656 static notification_h _notification_create(notification_type_e type)
1658 notification_h noti = NULL;
1659 package_info_h package_info = NULL;
1660 char *app_id = NULL;
1661 char *domain_name = NULL;
1662 char *app_root_path = NULL;
1663 char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1664 int err_app_manager = APP_MANAGER_ERROR_NONE;
1666 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1667 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1668 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1672 noti = (notification_h) calloc(1, sizeof(struct _notification));
1674 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1675 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1681 if (type == NOTIFICATION_TYPE_NOTI)
1682 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1683 else if (type == NOTIFICATION_TYPE_ONGOING)
1684 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1686 noti->caller_pkgname = notification_get_pkgname_by_pid();
1687 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1688 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1689 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1690 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1691 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1692 noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1693 noti->auto_remove = true;
1695 err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1696 if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1697 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]", err_app_manager, app_id);
1701 /* app name is used as domain name */
1702 /* domain_name is allocated by app_get_package_app_name */
1703 err_app_manager = app_get_package_app_name(app_id, &domain_name);
1705 if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1706 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]", err_app_manager, domain_name);
1710 err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1712 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1713 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p] caller_pkgname[%s]",
1714 err_app_manager, package_info, noti->caller_pkgname);
1718 err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1720 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1721 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]", err_app_manager, app_root_path);
1725 snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1727 noti->domain = strdup(domain_name);
1728 noti->dir = strdup(locale_directory);
1739 if (app_root_path) {
1740 free(app_root_path);
1744 package_info_destroy(package_info);
1749 * Other fields are already initialized with ZERO.
1751 set_last_result(NOTIFICATION_ERROR_NONE);
1755 EXPORT_API notification_h notification_create(notification_type_e type)
1757 return _notification_create(type);
1760 EXPORT_API notification_h notification_load_by_tag(const char *tag)
1763 notification_h noti = NULL;
1764 char *caller_pkgname = NULL;
1767 NOTIFICATION_ERR("Invalid parameter");
1768 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1772 caller_pkgname = notification_get_pkgname_by_pid();
1773 if (!caller_pkgname) {
1774 NOTIFICATION_ERR("Failed to get a package name");
1775 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1779 noti = (notification_h) calloc(1, sizeof(struct _notification));
1781 NOTIFICATION_ERR("Failed to alloc a new notification");
1782 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1783 free(caller_pkgname);
1788 ret = notification_noti_get_by_tag(noti, caller_pkgname, (char*)tag);
1790 free(caller_pkgname);
1792 set_last_result(ret);
1794 if (ret != NOTIFICATION_ERROR_NONE) {
1795 notification_free(noti);
1802 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1805 notification_h new_noti = NULL;
1807 if (noti == NULL || clone == NULL) {
1808 NOTIFICATION_ERR("INVALID PARAMETER.");
1809 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1812 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1813 if (new_noti == NULL) {
1814 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1815 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1818 new_noti->type = noti->type;
1819 new_noti->layout = noti->layout;
1821 new_noti->group_id = noti->group_id;
1822 new_noti->internal_group_id = noti->internal_group_id;
1823 new_noti->priv_id = noti->priv_id;
1825 if (noti->caller_pkgname != NULL) {
1826 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1828 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1830 if (noti->launch_pkgname != NULL) {
1831 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1833 new_noti->launch_pkgname = NULL;
1836 if (noti->args != NULL) {
1837 new_noti->args = bundle_dup(noti->args);
1839 new_noti->args = NULL;
1841 if (noti->group_args != NULL) {
1842 new_noti->group_args = bundle_dup(noti->group_args);
1844 new_noti->group_args = NULL;
1847 if (noti->b_execute_option != NULL) {
1848 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1850 new_noti->b_execute_option = NULL;
1852 if (noti->b_service_responding != NULL) {
1853 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1855 new_noti->b_service_responding = NULL;
1857 if (noti->b_service_single_launch != NULL) {
1858 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1860 new_noti->b_service_single_launch = NULL;
1862 if (noti->b_service_multi_launch != NULL) {
1863 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1865 new_noti->b_service_multi_launch = NULL;
1868 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1869 if (noti->b_event_handler[i] != NULL) {
1870 new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1872 new_noti->b_event_handler[i] = NULL;
1876 new_noti->sound_type = noti->sound_type;
1877 if (noti->sound_path != NULL) {
1878 new_noti->sound_path = strdup(noti->sound_path);
1880 new_noti->sound_path = NULL;
1882 new_noti->vibration_type = noti->vibration_type;
1883 if (noti->vibration_path != NULL) {
1884 new_noti->vibration_path = strdup(noti->vibration_path);
1886 new_noti->vibration_path = NULL;
1888 new_noti->led_operation = noti->led_operation;
1889 new_noti->led_argb = noti->led_argb;
1890 new_noti->led_on_ms = noti->led_on_ms;
1891 new_noti->led_off_ms = noti->led_off_ms;
1893 if (noti->domain != NULL) {
1894 new_noti->domain = strdup(noti->domain);
1896 new_noti->domain = NULL;
1898 if (noti->dir != NULL) {
1899 new_noti->dir = strdup(noti->dir);
1901 new_noti->dir = NULL;
1904 if (noti->b_text != NULL) {
1905 new_noti->b_text = bundle_dup(noti->b_text);
1907 new_noti->b_text = NULL;
1909 if (noti->b_key != NULL) {
1910 new_noti->b_key = bundle_dup(noti->b_key);
1912 new_noti->b_key = NULL;
1914 if (noti->b_format_args != NULL) {
1915 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1917 new_noti->b_format_args = NULL;
1919 new_noti->num_format_args = noti->num_format_args;
1921 if (noti->b_image_path != NULL) {
1922 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1924 new_noti->b_image_path = NULL;
1927 new_noti->time = noti->time;
1928 new_noti->insert_time = noti->insert_time;
1930 new_noti->flags_for_property = noti->flags_for_property;
1931 new_noti->display_applist = noti->display_applist;
1933 new_noti->progress_size = noti->progress_size;
1934 new_noti->progress_percentage = noti->progress_percentage;
1936 new_noti->ongoing_flag = noti->ongoing_flag;
1937 new_noti->auto_remove = noti->auto_remove;
1939 new_noti->app_icon_path = NULL;
1940 new_noti->app_name = NULL;
1941 new_noti->temp_title = NULL;
1942 new_noti->temp_content = NULL;
1946 return NOTIFICATION_ERROR_NONE;
1950 EXPORT_API int notification_free(notification_h noti)
1954 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1957 if (noti->caller_pkgname) {
1958 free(noti->caller_pkgname);
1960 if (noti->launch_pkgname) {
1961 free(noti->launch_pkgname);
1964 bundle_free(noti->args);
1966 if (noti->group_args) {
1967 bundle_free(noti->group_args);
1970 if (noti->b_execute_option) {
1971 bundle_free(noti->b_execute_option);
1973 if (noti->b_service_responding) {
1974 bundle_free(noti->b_service_responding);
1976 if (noti->b_service_single_launch) {
1977 bundle_free(noti->b_service_single_launch);
1979 if (noti->b_service_multi_launch) {
1980 bundle_free(noti->b_service_multi_launch);
1983 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1984 if (noti->b_event_handler[i] != NULL) {
1985 bundle_free(noti->b_event_handler[i]);
1989 if (noti->sound_path) {
1990 free(noti->sound_path);
1992 if (noti->vibration_path) {
1993 free(noti->vibration_path);
2004 bundle_free(noti->b_text);
2007 bundle_free(noti->b_key);
2009 if (noti->b_format_args) {
2010 bundle_free(noti->b_format_args);
2013 if (noti->b_image_path) {
2014 bundle_free(noti->b_image_path);
2017 if (noti->app_icon_path) {
2018 free(noti->app_icon_path);
2020 if (noti->app_name) {
2021 free(noti->app_name);
2023 if (noti->temp_title) {
2024 free(noti->temp_title);
2026 if (noti->temp_content) {
2027 free(noti->temp_content);
2036 return NOTIFICATION_ERROR_NONE;
2039 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
2041 /* Check noti is valid data */
2043 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2047 /* save input TAG */
2048 if (noti->tag != NULL) {
2051 noti->tag = strdup(tag);
2054 return NOTIFICATION_ERROR_NONE;
2058 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
2060 /* Check noti is valid data */
2062 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2066 return NOTIFICATION_ERROR_NONE;
2069 void notification_call_posted_toast_cb(const char *message)
2071 if (posted_toast_message_cb != NULL) {
2072 posted_toast_message_cb((void*)message);
2076 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
2079 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2081 noti->ongoing_flag = ongoing_flag;
2083 return NOTIFICATION_ERROR_NONE;
2086 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
2088 if (noti == NULL || ongoing_flag == NULL)
2089 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2091 *ongoing_flag = noti->ongoing_flag;
2093 return NOTIFICATION_ERROR_NONE;
2097 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
2099 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2100 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2102 return NOTIFICATION_ERROR_NONE;
2105 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
2107 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2108 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2110 if (noti->b_event_handler[button_index - 1]) {
2111 bundle_free(noti->b_event_handler[button_index - 1]);
2112 noti->b_event_handler[button_index - 1] = NULL;
2115 return NOTIFICATION_ERROR_NONE;
2118 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
2121 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2123 noti->auto_remove = auto_remove;
2125 return NOTIFICATION_ERROR_NONE;
2128 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
2130 if (noti == NULL || auto_remove == NULL)
2131 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2133 *auto_remove = noti->auto_remove;
2135 return NOTIFICATION_ERROR_NONE;