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;
64 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
68 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
69 if (ret != AUL_R_OK) {
71 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
73 fd = open(buf, O_RDONLY);
77 ret = read(fd, pkgname, sizeof(pkgname) - 1);
86 * "ret" is not able to be larger than "sizeof(pkgname) - 1",
87 * if the system is not going wrong.
90 if (strlen(pkgname) <= 0)
94 dup_pkgname = strdup(pkgname);
96 NOTIFICATION_ERR("Heap: %d\n", errno);
101 EXPORT_API int notification_set_image(notification_h noti,
102 notification_image_type_e type,
103 const char *image_path)
106 char buf_key[32] = { 0, };
107 char *ret_val = NULL;
109 /* Check noti and image_path are valid data */
110 if (noti == NULL || image_path == NULL)
111 return NOTIFICATION_ERROR_INVALID_PARAMETER;
113 /* Check image type is valid type */
114 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
115 || type >= NOTIFICATION_IMAGE_TYPE_MAX)
116 return NOTIFICATION_ERROR_INVALID_PARAMETER;
118 /* Check image path bundle is exist */
119 if (noti->b_image_path) {
120 /* If image path bundle is exist, store local bundle value */
121 b = noti->b_image_path;
123 /* Set image type to key as char string type */
124 snprintf(buf_key, sizeof(buf_key), "%d", type);
126 /* Get value using key */
127 bundle_get_str(b, buf_key, &ret_val);
129 /* If key is exist, remove this value to store new image path */
130 bundle_del(b, buf_key);
132 /* Add new image path with type key */
133 bundle_add_str(b, buf_key, image_path);
135 /* If image path bundle is not exist, create new one */
138 /* Set image type to key as char string type */
139 snprintf(buf_key, sizeof(buf_key), "%d", type);
141 /* Add new image path with type key */
142 bundle_add_str(b, buf_key, image_path);
144 /* Save to image path bundle */
145 noti->b_image_path = b;
148 return NOTIFICATION_ERROR_NONE;
151 EXPORT_API int notification_get_image(notification_h noti,
152 notification_image_type_e type,
156 char buf_key[32] = { 0, };
157 char *ret_val = NULL;
159 /* Check noti and image_path is valid data */
160 if (noti == NULL || image_path == NULL)
161 return NOTIFICATION_ERROR_INVALID_PARAMETER;
163 /* Check image type is valid data */
164 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
165 || type >= NOTIFICATION_IMAGE_TYPE_MAX)
166 return NOTIFICATION_ERROR_INVALID_PARAMETER;
168 /* Check image path bundle exist */
169 if (noti->b_image_path) {
170 /* If image path bundle exist, store local bundle data */
171 b = noti->b_image_path;
173 /* Set image type to key as char string type */
174 snprintf(buf_key, sizeof(buf_key), "%d", type);
176 /* Get value of key */
177 bundle_get_str(b, buf_key, &ret_val);
179 *image_path = ret_val;
181 /* If image path bundle does not exist, image path is NULL */
185 /* If image path is NULL and type is ICON, icon path set from AIL */
186 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
187 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
188 /* Check App icon path is already set */
189 if (noti->app_icon_path != NULL)
190 /* image path will be app icon path */
191 *image_path = noti->app_icon_path;
196 return NOTIFICATION_ERROR_NONE;
199 EXPORT_API int notification_set_time(notification_h noti,
202 /* Check noti is valid data */
204 return NOTIFICATION_ERROR_INVALID_PARAMETER;
207 /* If input time is 0, set current time */
208 noti->time = time(NULL);
210 /* save input time */
211 noti->time = input_time;
213 return NOTIFICATION_ERROR_NONE;
216 EXPORT_API int notification_get_time(notification_h noti,
219 /* Check noti and time is valid data */
220 if (noti == NULL || ret_time == NULL)
221 return NOTIFICATION_ERROR_INVALID_PARAMETER;
223 /* Set time infomation */
224 *ret_time = noti->time;
226 return NOTIFICATION_ERROR_NONE;
229 EXPORT_API int notification_get_insert_time(notification_h noti,
232 /* Check noti and ret_time is valid data */
233 if (noti == NULL || ret_time == NULL)
234 return NOTIFICATION_ERROR_INVALID_PARAMETER;
236 /* Set insert time information */
237 *ret_time = noti->insert_time;
239 return NOTIFICATION_ERROR_NONE;
242 EXPORT_API int notification_set_text(notification_h noti,
243 notification_text_type_e type,
249 char buf_key[32] = { 0, };
250 char buf_val[1024] = { 0, };
251 char *ret_val = NULL;
253 notification_variable_type_e var_type;
255 int noti_err = NOTIFICATION_ERROR_NONE;
256 int var_value_int = 0;
257 double var_value_double = 0.0;
258 char *var_value_string = NULL;
259 notification_count_pos_type_e var_value_count =
260 NOTIFICATION_COUNT_POS_NONE;
262 /* Check noti is valid data */
264 return NOTIFICATION_ERROR_INVALID_PARAMETER;
266 /* Check text type is valid type */
267 if (type <= NOTIFICATION_TEXT_TYPE_NONE
268 || type >= NOTIFICATION_TEXT_TYPE_MAX)
269 return NOTIFICATION_ERROR_INVALID_PARAMETER;
271 /* Check text bundle exist */
273 if (noti->b_text != NULL) {
274 /* If text bundle exist, store local bundle data */
277 /* Make type to key as char string */
278 snprintf(buf_key, sizeof(buf_key), "%d", type);
280 /* Get value using type key */
281 bundle_get_str(b, buf_key, &ret_val);
284 /* If value exist, remove this to add new value */
285 bundle_del(b, buf_key);
287 snprintf(buf_val, sizeof(buf_val), "%s", text);
289 /* Add new text value */
290 bundle_add_str(b, buf_key, buf_val);
292 /* If text bundle does not exist, create new one */
295 /* Make type to key as char string */
296 snprintf(buf_key, sizeof(buf_key), "%d", type);
298 snprintf(buf_val, sizeof(buf_val), "%s", text);
300 /* Add new text value */
301 bundle_add_str(b, buf_key, buf_val);
303 /* Save text bundle */
307 /* Reset if text is NULL */
308 if (noti->b_text != NULL) {
309 /* If text bundle exist, store local bundle data */
312 /* Make type to key as char string */
313 snprintf(buf_key, sizeof(buf_key), "%d", type);
315 /* Get value using type key */
316 bundle_get_str(b, buf_key, &ret_val);
318 /* If value exist, remove this */
319 bundle_del(b, buf_key);
323 /* Save key if key is valid data */
325 /* Check key bundle exist */
326 if (noti->b_key != NULL) {
327 /* If key bundle exist, store local bundle data */
330 /* Make type to key as char string */
331 snprintf(buf_key, sizeof(buf_key), "%d", type);
333 /* Get value using type key */
334 bundle_get_str(b, buf_key, &ret_val);
336 /* If value exist, remove this to add new value */
337 bundle_del(b, buf_key);
339 snprintf(buf_val, sizeof(buf_val), "%s", key);
341 /* Add new key value */
342 bundle_add_str(b, buf_key, buf_val);
344 /* If key bundle does not exist, create new one */
347 /* Make type to key as char string */
348 snprintf(buf_key, sizeof(buf_key), "%d", type);
350 snprintf(buf_val, sizeof(buf_val), "%s", key);
352 /* Add new key value */
353 bundle_add_str(b, buf_key, buf_val);
355 /* Save key bundle */
359 /* Reset if key is NULL */
360 if (noti->b_key != NULL) {
361 /* If key bundle exist, store local bundle data */
364 /* Make type to key as char string */
365 snprintf(buf_key, sizeof(buf_key), "%d", type);
367 /* Get value using type key */
368 bundle_get_str(b, buf_key, &ret_val);
370 /* If value exist, remove this */
371 bundle_del(b, buf_key);
375 if (noti->b_format_args != NULL)
376 b = noti->b_format_args;
380 va_start(var_args, args_type);
382 var_type = args_type;
385 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
387 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
388 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
390 bundle_get_str(b, buf_key, &ret_val);
392 bundle_del(b, buf_key);
394 bundle_add_str(b, buf_key, buf_val);
397 case NOTIFICATION_VARIABLE_TYPE_INT:
398 var_value_int = va_arg(var_args, int);
401 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
403 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
405 bundle_get_str(b, buf_key, &ret_val);
407 bundle_del(b, buf_key);
409 bundle_add_str(b, buf_key, buf_val);
412 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
413 var_value_double = va_arg(var_args, double);
416 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
418 snprintf(buf_val, sizeof(buf_val), "%.2f",
421 bundle_get_str(b, buf_key, &ret_val);
423 bundle_del(b, buf_key);
425 bundle_add_str(b, buf_key, buf_val);
428 case NOTIFICATION_VARIABLE_TYPE_STRING:
429 var_value_string = va_arg(var_args, char *);
432 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
434 snprintf(buf_val, sizeof(buf_val), "%s",
437 bundle_get_str(b, buf_key, &ret_val);
439 bundle_del(b, buf_key);
441 bundle_add_str(b, buf_key, buf_val);
444 case NOTIFICATION_VARIABLE_TYPE_COUNT:
446 va_arg(var_args, notification_count_pos_type_e);
449 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
451 snprintf(buf_val, sizeof(buf_val), "%d",
454 bundle_get_str(b, buf_key, &ret_val);
456 bundle_del(b, buf_key);
458 bundle_add_str(b, buf_key, buf_val);
462 NOTIFICATION_ERR("Error. invalid variable type. : %d",
464 noti_err = NOTIFICATION_ERROR_INVALID_PARAMETER;
469 var_type = va_arg(var_args, notification_variable_type_e);
473 if (noti_err == NOTIFICATION_ERROR_NONE)
474 noti->num_format_args = num_args;
476 noti->num_format_args = 0;
478 snprintf(buf_key, sizeof(buf_key), "num%d", type);
479 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
481 bundle_get_str(b, buf_key, &ret_val);
483 bundle_del(b, buf_key);
485 bundle_add_str(b, buf_key, buf_val);
487 noti->b_format_args = b;
492 EXPORT_API int notification_get_text(notification_h noti,
493 notification_text_type_e type,
497 char buf_key[32] = { 0, };
498 char *ret_val = NULL;
499 char *get_str = NULL;
500 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
501 /* int display_option_flag = 0; */
503 char *temp_str = NULL;
504 char *translated_str = NULL;
505 char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
506 char buf_str[1024] = { 0, };
508 notification_variable_type_e ret_var_type = 0;
509 int ret_variable_int = 0;
510 double ret_variable_double = 0.0;
514 /* Check noti is valid data */
515 if (noti == NULL || text == NULL)
516 return NOTIFICATION_ERROR_INVALID_PARAMETER;
518 /* Check text type is valid type */
519 if (type <= NOTIFICATION_TEXT_TYPE_NONE
520 || type >= NOTIFICATION_TEXT_TYPE_MAX)
521 return NOTIFICATION_ERROR_INVALID_PARAMETER;
525 if (noti->b_key != NULL) {
528 /* Get text domain and dir */
529 /* _notification_get_text_domain(noti); */
531 snprintf(buf_key, sizeof(buf_key), "%d", type);
533 bundle_get_str(b, buf_key, &ret_val);
534 if (ret_val != NULL && noti->domain != NULL
535 && noti->dir != NULL) {
536 /* Get application string */
537 bindtextdomain(noti->domain, noti->dir);
539 get_str = dgettext(noti->domain, ret_val);
540 } else if (ret_val != NULL) {
541 /* Get system string */
542 get_str = dgettext("sys_string", ret_val);
548 if (get_str == NULL && noti->b_text != NULL) {
551 snprintf(buf_key, sizeof(buf_key), "%d", type);
553 bundle_get_str(b, buf_key, &get_str);
558 if (get_str != NULL) {
559 /* Get number format args */
560 b = noti->b_format_args;
561 noti->num_format_args = 0;
564 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
565 bundle_get_str(b, buf_key, &ret_val);
567 noti->num_format_args = atoi(ret_val);
570 if (noti->num_format_args == 0) {
571 *text = (char *)get_str;
573 /* Check first variable is count, LEFT pos */
574 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
575 check_type, num_args);
576 bundle_get_str(b, buf_key, &ret_val);
578 ret_var_type = atoi(ret_val);
580 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
582 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
583 check_type, num_args);
584 bundle_get_str(b, buf_key, &ret_val);
586 ret_variable_int = atoi(ret_val);
588 if (ret_variable_int ==
589 NOTIFICATION_COUNT_POS_LEFT) {
590 notification_noti_get_count(noti->type,
591 noti->caller_pkgname,
595 snprintf(buf_str, sizeof(buf_str),
596 "%d ", ret_variable_int);
598 src_len = strlen(result_str);
599 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
601 strncat(result_str, buf_str,
607 /* Check variable IN pos */
608 for (temp_str = (char *)get_str; *temp_str != '\0';
610 if (*temp_str != '%') {
611 strncat(result_str, temp_str, 1);
613 if (*(temp_str + 1) == '%') {
614 strncat(result_str, temp_str,
616 } else if (*(temp_str + 1) == 'd') {
618 ret_variable_int = 0;
622 "%dtype%d", check_type,
624 bundle_get_str(b, buf_key, &ret_val);
626 ret_var_type = atoi(ret_val);
629 NOTIFICATION_VARIABLE_TYPE_COUNT) {
630 /* Get notification count */
631 notification_noti_get_count
633 noti->caller_pkgname,
644 bundle_get_str(b, buf_key, &ret_val);
646 ret_variable_int = atoi(ret_val);
650 sizeof(buf_str), "%d",
653 src_len = strlen(result_str);
654 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
656 strncat(result_str, buf_str,
662 } else if (*(temp_str + 1) == 's') {
667 check_type, num_args);
668 bundle_get_str(b, buf_key, &ret_val);
670 if (ret_val != NULL && noti->domain != NULL && noti->dir != NULL) {
671 /* Get application string */
672 bindtextdomain(noti->domain, noti->dir);
673 translated_str = dgettext(noti->domain, ret_val);
674 NOTIFICATION_INFO("translated_str[%s]", translated_str);
675 } else if (ret_val != NULL) {
676 /* Get system string */
677 translated_str = dgettext("sys_string", ret_val);
678 NOTIFICATION_INFO("translated_str[%s]", translated_str);
680 translated_str = NULL;
683 if (translated_str != NULL) {
684 strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
685 src_len = strlen(result_str);
686 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
687 strncat(result_str, buf_str, max_len);
691 } else if (*(temp_str + 1) == 'f') {
696 check_type, num_args);
697 bundle_get_str(b, buf_key, &ret_val);
699 ret_variable_double = atof(ret_val);
704 ret_variable_double);
706 src_len = strlen(result_str);
707 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
708 strncat(result_str, buf_str, max_len);
712 } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
713 if (*(temp_str + 3) == 'd') {
715 ret_variable_int = 0;
719 "%dtype%d", check_type,
720 num_args + *(temp_str + 1) - 49);
721 bundle_get_str(b, buf_key, &ret_val);
723 ret_var_type = atoi(ret_val);
726 NOTIFICATION_VARIABLE_TYPE_COUNT) {
727 /* Get notification count */
728 notification_noti_get_count
730 noti->caller_pkgname,
741 num_args + *(temp_str + 1) - 49);
742 bundle_get_str(b, buf_key, &ret_val);
744 ret_variable_int = atoi(ret_val);
749 sizeof(buf_str), "%d",
752 src_len = strlen(result_str);
753 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
755 strncat(result_str, buf_str, max_len);
758 } else if (*(temp_str + 3) == 's') {
763 check_type, num_args + *(temp_str + 1) - 49);
764 bundle_get_str(b, buf_key, &ret_val);
767 sizeof(buf_str), "%s",
770 src_len = strlen(result_str);
771 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
773 strncat(result_str, buf_str, max_len);
776 } else if (*(temp_str + 3) == 'f') {
781 check_type, num_args + *(temp_str + 1) - 49);
782 bundle_get_str(b, buf_key, &ret_val);
784 ret_variable_double = atof(ret_val);
789 ret_variable_double);
791 src_len = strlen(result_str);
792 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
794 strncat(result_str, buf_str, max_len);
803 /* Check last variable is count, LEFT pos */
804 if (num_args < noti->num_format_args) {
805 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
806 check_type, num_args);
807 bundle_get_str(b, buf_key, &ret_val);
809 ret_var_type = atoi(ret_val);
812 NOTIFICATION_VARIABLE_TYPE_COUNT) {
814 snprintf(buf_key, sizeof(buf_key),
815 "%dvalue%d", check_type,
817 bundle_get_str(b, buf_key, &ret_val);
819 ret_variable_int = atoi(ret_val);
821 if (ret_variable_int ==
822 NOTIFICATION_COUNT_POS_RIGHT) {
823 notification_noti_get_count
825 noti->caller_pkgname,
830 sizeof(buf_str), " %d",
833 src_len = strlen(result_str);
834 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
836 strncat(result_str, buf_str, max_len);
844 switch (check_type) {
845 case NOTIFICATION_TEXT_TYPE_TITLE:
846 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
847 if (noti->temp_title != NULL)
848 free(noti->temp_title);
850 noti->temp_title = strdup(result_str);
852 *text = noti->temp_title;
854 case NOTIFICATION_TEXT_TYPE_CONTENT:
855 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
856 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
857 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
858 if (noti->temp_content !=
860 free(noti->temp_content);
862 noti->temp_content = strdup(result_str);
864 *text = noti->temp_content;
876 return NOTIFICATION_ERROR_NONE;
879 EXPORT_API int notification_set_text_domain(notification_h noti,
883 /* check noti and domain is valid data */
884 if (noti == NULL || domain == NULL || dir == NULL)
885 return NOTIFICATION_ERROR_INVALID_PARAMETER;
889 /* Remove previous domain */
893 noti->domain = strdup(domain);
895 /* Check locale dir */
897 /* Remove previous locale dir */
900 /* Copy locale dir */
901 noti->dir = strdup(dir);
903 return NOTIFICATION_ERROR_NONE;
906 EXPORT_API int notification_get_text_domain(notification_h noti,
910 /* Check noti is valid data */
912 return NOTIFICATION_ERROR_INVALID_PARAMETER;
915 if (domain != NULL && noti->domain != NULL)
916 *domain = noti->domain;
919 if (dir != NULL && noti->dir != NULL)
922 return NOTIFICATION_ERROR_NONE;
925 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
928 int ret = NOTIFICATION_ERROR_NONE;
929 char buf[256] = { 0, };
930 char buf_tag[512] = { 0, };
933 return NOTIFICATION_ERROR_INVALID_PARAMETER;
936 return NOTIFICATION_ERROR_INVALID_PARAMETER;
938 if (type <= NOTIFICATION_TEXT_TYPE_NONE
939 || type >= NOTIFICATION_TEXT_TYPE_MAX)
940 return NOTIFICATION_ERROR_INVALID_PARAMETER;
943 snprintf(buf, sizeof(buf), "%lu", time);
944 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
946 if (ret != NOTIFICATION_ERROR_NONE)
949 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
952 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
955 int ret = NOTIFICATION_ERROR_NONE;
956 char *ret_text = NULL;
960 return NOTIFICATION_ERROR_INVALID_PARAMETER;
963 return NOTIFICATION_ERROR_INVALID_PARAMETER;
965 if (type <= NOTIFICATION_TEXT_TYPE_NONE
966 || type >= NOTIFICATION_TEXT_TYPE_MAX)
967 return NOTIFICATION_ERROR_INVALID_PARAMETER;
969 ret = notification_get_text(noti, type, &ret_text);
971 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL)
972 return NOTIFICATION_ERROR_INVALID_PARAMETER;
974 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID)
975 return NOTIFICATION_ERROR_INVALID_PARAMETER;
977 tag_value = notification_noti_strip_tag(ret_text);
978 if (tag_value == NULL)
979 return NOTIFICATION_ERROR_INVALID_PARAMETER;
981 *time = atol(tag_value);
984 return NOTIFICATION_ERROR_NONE;
987 EXPORT_API int notification_set_sound(notification_h noti,
988 notification_sound_type_e type,
991 /* Check noti is valid data */
993 return NOTIFICATION_ERROR_INVALID_PARAMETER;
996 /* Check type is valid */
997 if (type < NOTIFICATION_SOUND_TYPE_NONE
998 || type >= NOTIFICATION_SOUND_TYPE_MAX)
999 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1001 /* Save sound type */
1002 noti->sound_type = type;
1004 /* Save sound path if user data type */
1005 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1006 if (noti->sound_path != NULL)
1007 free(noti->sound_path);
1009 noti->sound_path = strdup(path);
1011 if (noti->sound_path != NULL) {
1012 free(noti->sound_path);
1013 noti->sound_path = NULL;
1015 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1016 noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1017 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1021 return NOTIFICATION_ERROR_NONE;
1024 EXPORT_API int notification_get_sound(notification_h noti,
1025 notification_sound_type_e *type,
1028 /* check noti and type is valid data */
1029 if (noti == NULL || type == NULL)
1030 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1032 /* Set sound type */
1033 *type = noti->sound_type;
1035 /* Set sound path if user data type */
1036 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1038 *path = noti->sound_path;
1040 return NOTIFICATION_ERROR_NONE;
1043 EXPORT_API int notification_set_vibration(notification_h noti,
1044 notification_vibration_type_e type,
1047 /* Check noti is valid data */
1049 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1051 /* Check type is valid */
1052 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1053 || type >= NOTIFICATION_VIBRATION_TYPE_MAX)
1054 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1056 /* Save vibration type */
1057 noti->vibration_type = type;
1059 /* Save sound path if user data type */
1060 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1061 if (noti->vibration_path != NULL)
1062 free(noti->vibration_path);
1064 noti->vibration_path = strdup(path);
1066 if (noti->vibration_path != NULL) {
1067 free(noti->vibration_path);
1068 noti->vibration_path = NULL;
1070 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1071 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1072 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1076 return NOTIFICATION_ERROR_NONE;
1080 EXPORT_API int notification_get_vibration(notification_h noti,
1081 notification_vibration_type_e *type,
1084 /* check noti and type is valid data */
1085 if (noti == NULL || type == NULL)
1086 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1088 /* Set vibration type */
1089 *type = noti->vibration_type;
1091 /* Set sound path if user data type */
1092 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1094 *path = noti->vibration_path;
1096 return NOTIFICATION_ERROR_NONE;
1099 EXPORT_API int notification_set_led(notification_h noti,
1100 notification_led_op_e operation,
1103 /* Check noti is valid data */
1105 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1107 /* Check operation is valid */
1108 if (operation < NOTIFICATION_LED_OP_OFF
1109 || operation >= NOTIFICATION_LED_OP_MAX)
1110 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1112 /* Save led operation */
1113 noti->led_operation = operation;
1115 /* Save led argb if operation is turning on LED with custom color */
1116 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR)
1117 noti->led_argb = led_argb;
1119 return NOTIFICATION_ERROR_NONE;
1122 EXPORT_API int notification_get_led(notification_h noti,
1123 notification_led_op_e *operation,
1126 /* check noti and operation is valid data */
1127 if (noti == NULL || operation == NULL)
1128 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1130 /* Set led operation */
1131 *operation = noti->led_operation;
1133 /* Save led argb if operation is turning on LED with custom color */
1134 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1135 && led_argb != NULL)
1136 *led_argb = noti->led_argb;
1138 return NOTIFICATION_ERROR_NONE;
1141 EXPORT_API int notification_set_led_time_period(notification_h noti,
1142 int on_ms, int off_ms)
1144 /* Check noti is valid data */
1145 if (noti == NULL || on_ms < 0 || off_ms < 0)
1146 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1148 /* Save led operation */
1149 noti->led_on_ms = on_ms;
1150 noti->led_off_ms = off_ms;
1152 return NOTIFICATION_ERROR_NONE;
1155 EXPORT_API int notification_get_led_time_period(notification_h noti,
1156 int *on_ms, int *off_ms)
1158 /* check noti and operation is valid data */
1160 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1163 *(on_ms) = noti->led_on_ms;
1165 *(off_ms) = noti->led_off_ms;
1167 return NOTIFICATION_ERROR_NONE;
1170 EXPORT_API int notification_set_launch_option(notification_h noti,
1171 notification_launch_option_type type, void *option)
1173 int err = NOTIFICATION_ERROR_NONE;
1176 app_control_h app_control = option;
1178 if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1179 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1183 if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1184 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1185 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1189 err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1198 EXPORT_API int notification_get_launch_option(notification_h noti,
1199 notification_launch_option_type type, void *option)
1203 app_control_h *app_control = (app_control_h *)option;
1204 app_control_h app_control_new = NULL;
1207 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1209 if (app_control == NULL)
1210 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1212 if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL)
1213 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1216 ret = notification_get_execute_option(noti,
1217 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1220 if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1221 ret = app_control_create(&app_control_new);
1222 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1223 ret = app_control_import_from_bundle(app_control_new, b);
1224 if (ret == APP_CONTROL_ERROR_NONE) {
1225 *app_control = app_control_new;
1227 app_control_destroy(app_control_new);
1228 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1229 return NOTIFICATION_ERROR_IO_ERROR;
1232 NOTIFICATION_ERR("Failed to create app control:%d", ret);
1233 return NOTIFICATION_ERROR_IO_ERROR;
1236 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1240 return NOTIFICATION_ERROR_NONE;
1243 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1245 int err = NOTIFICATION_ERROR_NONE;
1246 bundle *app_control_bundle = NULL;
1249 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1250 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1254 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1255 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1256 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1257 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1261 if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1262 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1266 if (noti->b_event_handler[event_type] != NULL)
1267 bundle_free(noti->b_event_handler[event_type]);
1269 noti->b_event_handler[event_type] = app_control_bundle;
1275 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1277 int err = NOTIFICATION_ERROR_NONE;
1279 app_control_h app_control_new = NULL;
1282 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1283 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1286 if (event_handler == NULL) {
1287 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1288 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1291 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1292 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1293 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1294 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1298 b = noti->b_event_handler[event_type];
1301 NOTIFICATION_DBG("No event handler\n");
1302 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1306 err = app_control_create(&app_control_new);
1307 if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1308 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1309 err = NOTIFICATION_ERROR_IO_ERROR;
1313 err = app_control_import_from_bundle(app_control_new, b);
1314 if (err == APP_CONTROL_ERROR_NONE) {
1315 *event_handler = app_control_new;
1317 app_control_destroy(app_control_new);
1318 app_control_new = NULL;
1319 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1320 err = NOTIFICATION_ERROR_IO_ERROR;
1326 *event_handler = app_control_new;
1335 EXPORT_API int notification_set_property(notification_h noti,
1338 /* Check noti is valid data */
1340 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1343 noti->flags_for_property = flags;
1345 return NOTIFICATION_ERROR_NONE;
1348 EXPORT_API int notification_get_property(notification_h noti,
1351 /* Check noti and flags are valid data */
1352 if (noti == NULL || flags == NULL)
1353 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1356 *flags = noti->flags_for_property;
1358 return NOTIFICATION_ERROR_NONE;
1361 EXPORT_API int notification_set_display_applist(notification_h noti,
1364 /* Check noti is valid data */
1366 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1370 if (applist == 0xffffffff) /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1371 applist = NOTIFICATION_DISPLAY_APP_ALL;
1373 noti->display_applist = applist;
1375 return NOTIFICATION_ERROR_NONE;
1378 EXPORT_API int notification_get_display_applist(notification_h noti,
1381 /* Check noti and applist are valid data */
1382 if (noti == NULL || applist == NULL)
1383 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1386 *applist = noti->display_applist;
1388 return NOTIFICATION_ERROR_NONE;
1391 EXPORT_API int notification_set_size(notification_h noti,
1394 /* Check noti is valid data */
1396 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1398 /* Save progress size */
1399 noti->progress_size = size;
1401 return NOTIFICATION_ERROR_NONE;
1404 EXPORT_API int notification_get_size(notification_h noti,
1407 /* Check noti and size is valid data */
1408 if (noti == NULL || size == NULL)
1409 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1411 /* Set progress size */
1412 *size = noti->progress_size;
1414 return NOTIFICATION_ERROR_NONE;
1417 EXPORT_API int notification_set_progress(notification_h noti,
1420 /* Check noti is valid data */
1422 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1424 /* Save progress percentage */
1425 noti->progress_percentage = percentage;
1427 return NOTIFICATION_ERROR_NONE;
1430 EXPORT_API int notification_get_progress(notification_h noti,
1433 /* Check noti and percentage are valid data */
1434 if (noti == NULL || percentage == NULL)
1435 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1437 /* Set progress percentage */
1438 *percentage = noti->progress_percentage;
1440 return NOTIFICATION_ERROR_NONE;
1443 EXPORT_API int notification_get_pkgname(notification_h noti,
1446 /* Check noti and pkgname are valid data */
1447 if (noti == NULL || pkgname == NULL)
1448 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1450 /* Get caller pkgname */
1451 if (noti->caller_pkgname)
1452 *pkgname = noti->caller_pkgname;
1456 return NOTIFICATION_ERROR_NONE;
1459 EXPORT_API int notification_set_layout(notification_h noti,
1460 notification_ly_type_e layout)
1462 /* check noti and pkgname are valid data */
1463 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX))
1464 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1466 noti->layout = layout;
1468 return NOTIFICATION_ERROR_NONE;
1471 EXPORT_API int notification_get_layout(notification_h noti,
1472 notification_ly_type_e *layout)
1474 /* Check noti and pkgname are valid data */
1475 if (noti == NULL || layout == NULL)
1476 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1478 *layout = noti->layout;
1480 return NOTIFICATION_ERROR_NONE;
1485 EXPORT_API int notification_get_type(notification_h noti,
1486 notification_type_e *type)
1488 /* Check noti and type is valid data */
1489 if (noti == NULL || type == NULL)
1490 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1495 return NOTIFICATION_ERROR_NONE;
1498 EXPORT_API int notification_post(notification_h noti)
1503 /* Check noti is vaild data */
1505 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1507 /* Check noti type is valid type */
1508 if (noti->type <= NOTIFICATION_TYPE_NONE
1509 || noti->type >= NOTIFICATION_TYPE_MAX)
1510 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1512 /* Save insert time */
1513 noti->insert_time = time(NULL);
1515 ret = notification_ipc_request_insert(noti, &id);
1516 if (ret != NOTIFICATION_ERROR_NONE)
1520 NOTIFICATION_DBG("from master:%d", id);
1522 return NOTIFICATION_ERROR_NONE;
1527 EXPORT_API int notification_update(notification_h noti)
1531 /* Check noti is valid data */
1533 /* Update insert time ? */
1534 noti->insert_time = time(NULL);
1535 ret = notification_ipc_request_update(noti);
1537 notification_ipc_request_refresh();
1538 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1543 EXPORT_API int notification_delete_all(notification_type_e type)
1546 char *caller_pkgname = NULL;
1548 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
1549 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1551 caller_pkgname = notification_get_pkgname_by_pid();
1553 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1556 free(caller_pkgname);
1561 EXPORT_API int notification_delete(notification_h noti)
1566 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1568 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1573 static notification_h _notification_create(notification_type_e type)
1575 notification_h noti = NULL;
1576 package_info_h package_info = NULL;
1577 char *app_id = NULL;
1578 char *domain_name = NULL;
1579 char *app_root_path = NULL;
1580 char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1581 int err_app_manager = APP_MANAGER_ERROR_NONE;
1583 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1584 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1585 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1589 noti = (notification_h) calloc(1, sizeof(struct _notification));
1591 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1592 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1598 if (type == NOTIFICATION_TYPE_NOTI)
1599 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1600 else if (type == NOTIFICATION_TYPE_ONGOING)
1601 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1603 noti->caller_pkgname = notification_get_pkgname_by_pid();
1604 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1605 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1606 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1607 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1608 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1609 noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1610 noti->auto_remove = true;
1612 err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1613 if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1614 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]", err_app_manager, app_id);
1618 /* app name is used as domain name */
1619 /* domain_name is allocated by app_get_package_app_name */
1620 err_app_manager = app_get_package_app_name(app_id, &domain_name);
1622 if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1623 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]", err_app_manager, domain_name);
1627 err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1629 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1630 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p] caller_pkgname[%s]",
1631 err_app_manager, package_info, noti->caller_pkgname);
1635 err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1637 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1638 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]", err_app_manager, app_root_path);
1642 snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1644 noti->domain = strdup(domain_name);
1645 noti->dir = strdup(locale_directory);
1655 free(app_root_path);
1658 package_info_destroy(package_info);
1662 * Other fields are already initialized with ZERO.
1664 set_last_result(NOTIFICATION_ERROR_NONE);
1668 EXPORT_API notification_h notification_create(notification_type_e type)
1670 return _notification_create(type);
1673 EXPORT_API notification_h notification_load_by_tag(const char *tag)
1676 notification_h noti = NULL;
1677 char *caller_pkgname = NULL;
1680 NOTIFICATION_ERR("Invalid parameter");
1681 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1685 caller_pkgname = notification_get_pkgname_by_pid();
1686 if (!caller_pkgname) {
1687 NOTIFICATION_ERR("Failed to get a package name");
1688 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1692 noti = (notification_h) calloc(1, sizeof(struct _notification));
1694 NOTIFICATION_ERR("Failed to alloc a new notification");
1695 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1696 free(caller_pkgname);
1701 ret = notification_noti_get_by_tag(noti, caller_pkgname, (char*)tag);
1703 free(caller_pkgname);
1705 set_last_result(ret);
1707 if (ret != NOTIFICATION_ERROR_NONE) {
1708 notification_free(noti);
1715 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1718 notification_h new_noti = NULL;
1720 if (noti == NULL || clone == NULL) {
1721 NOTIFICATION_ERR("INVALID PARAMETER.");
1722 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1725 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1726 if (new_noti == NULL) {
1727 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1728 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1731 new_noti->type = noti->type;
1732 new_noti->layout = noti->layout;
1734 new_noti->group_id = noti->group_id;
1735 new_noti->internal_group_id = noti->internal_group_id;
1736 new_noti->priv_id = noti->priv_id;
1738 if (noti->caller_pkgname != NULL)
1739 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1741 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1743 if (noti->launch_pkgname != NULL)
1744 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1746 new_noti->launch_pkgname = NULL;
1748 if (noti->args != NULL)
1749 new_noti->args = bundle_dup(noti->args);
1751 new_noti->args = NULL;
1753 if (noti->group_args != NULL)
1754 new_noti->group_args = bundle_dup(noti->group_args);
1756 new_noti->group_args = NULL;
1758 if (noti->b_execute_option != NULL)
1759 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1761 new_noti->b_execute_option = NULL;
1763 if (noti->b_service_responding != NULL)
1764 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1766 new_noti->b_service_responding = NULL;
1768 if (noti->b_service_single_launch != NULL)
1769 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1771 new_noti->b_service_single_launch = NULL;
1773 if (noti->b_service_multi_launch != NULL)
1774 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1776 new_noti->b_service_multi_launch = NULL;
1778 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1779 if (noti->b_event_handler[i] != NULL)
1780 new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1782 new_noti->b_event_handler[i] = NULL;
1785 new_noti->sound_type = noti->sound_type;
1786 if (noti->sound_path != NULL)
1787 new_noti->sound_path = strdup(noti->sound_path);
1789 new_noti->sound_path = NULL;
1791 new_noti->vibration_type = noti->vibration_type;
1792 if (noti->vibration_path != NULL)
1793 new_noti->vibration_path = strdup(noti->vibration_path);
1795 new_noti->vibration_path = NULL;
1797 new_noti->led_operation = noti->led_operation;
1798 new_noti->led_argb = noti->led_argb;
1799 new_noti->led_on_ms = noti->led_on_ms;
1800 new_noti->led_off_ms = noti->led_off_ms;
1802 if (noti->domain != NULL)
1803 new_noti->domain = strdup(noti->domain);
1805 new_noti->domain = NULL;
1807 if (noti->dir != NULL)
1808 new_noti->dir = strdup(noti->dir);
1810 new_noti->dir = NULL;
1812 if (noti->b_text != NULL)
1813 new_noti->b_text = bundle_dup(noti->b_text);
1815 new_noti->b_text = NULL;
1817 if (noti->b_key != NULL)
1818 new_noti->b_key = bundle_dup(noti->b_key);
1820 new_noti->b_key = NULL;
1822 if (noti->b_format_args != NULL)
1823 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1825 new_noti->b_format_args = NULL;
1827 new_noti->num_format_args = noti->num_format_args;
1829 if (noti->b_image_path != NULL)
1830 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1832 new_noti->b_image_path = NULL;
1834 new_noti->time = noti->time;
1835 new_noti->insert_time = noti->insert_time;
1837 new_noti->flags_for_property = noti->flags_for_property;
1838 new_noti->display_applist = noti->display_applist;
1840 new_noti->progress_size = noti->progress_size;
1841 new_noti->progress_percentage = noti->progress_percentage;
1843 new_noti->ongoing_flag = noti->ongoing_flag;
1844 new_noti->auto_remove = noti->auto_remove;
1846 new_noti->app_icon_path = NULL;
1847 new_noti->app_name = NULL;
1848 new_noti->temp_title = NULL;
1849 new_noti->temp_content = NULL;
1853 return NOTIFICATION_ERROR_NONE;
1857 EXPORT_API int notification_free(notification_h noti)
1861 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1863 if (noti->caller_pkgname)
1864 free(noti->caller_pkgname);
1866 if (noti->launch_pkgname)
1867 free(noti->launch_pkgname);
1870 bundle_free(noti->args);
1872 if (noti->group_args)
1873 bundle_free(noti->group_args);
1875 if (noti->b_execute_option)
1876 bundle_free(noti->b_execute_option);
1878 if (noti->b_service_responding)
1879 bundle_free(noti->b_service_responding);
1881 if (noti->b_service_single_launch)
1882 bundle_free(noti->b_service_single_launch);
1884 if (noti->b_service_multi_launch)
1885 bundle_free(noti->b_service_multi_launch);
1887 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1888 if (noti->b_event_handler[i] != NULL)
1889 bundle_free(noti->b_event_handler[i]);
1892 if (noti->sound_path)
1893 free(noti->sound_path);
1895 if (noti->vibration_path)
1896 free(noti->vibration_path);
1905 bundle_free(noti->b_text);
1908 bundle_free(noti->b_key);
1910 if (noti->b_format_args)
1911 bundle_free(noti->b_format_args);
1913 if (noti->b_image_path)
1914 bundle_free(noti->b_image_path);
1916 if (noti->app_icon_path)
1917 free(noti->app_icon_path);
1920 free(noti->app_name);
1922 if (noti->temp_title)
1923 free(noti->temp_title);
1925 if (noti->temp_content)
1926 free(noti->temp_content);
1933 return NOTIFICATION_ERROR_NONE;
1936 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
1938 /* Check noti is valid data */
1940 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1943 /* save input TAG */
1944 if (noti->tag != NULL)
1947 noti->tag = strdup(tag);
1950 return NOTIFICATION_ERROR_NONE;
1954 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
1956 /* Check noti is valid data */
1958 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1961 return NOTIFICATION_ERROR_NONE;
1964 void notification_call_posted_toast_cb(const char *message)
1966 if (posted_toast_message_cb != NULL)
1967 posted_toast_message_cb((void*)message);
1970 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
1973 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1975 noti->ongoing_flag = ongoing_flag;
1977 return NOTIFICATION_ERROR_NONE;
1980 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
1982 if (noti == NULL || ongoing_flag == NULL)
1983 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1985 *ongoing_flag = noti->ongoing_flag;
1987 return NOTIFICATION_ERROR_NONE;
1991 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
1993 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
1994 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1996 return NOTIFICATION_ERROR_NONE;
1999 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
2001 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2002 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2004 if (noti->b_event_handler[button_index - 1]) {
2005 bundle_free(noti->b_event_handler[button_index - 1]);
2006 noti->b_event_handler[button_index - 1] = NULL;
2009 return NOTIFICATION_ERROR_NONE;
2012 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
2015 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2017 noti->auto_remove = auto_remove;
2019 return NOTIFICATION_ERROR_NONE;
2022 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
2024 if (noti == NULL || auto_remove == NULL)
2025 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2027 *auto_remove = noti->auto_remove;
2029 return NOTIFICATION_ERROR_NONE;