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_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_get_count(noti->type,
632 noti->caller_pkgname,
643 bundle_get_str(b, buf_key, &ret_val);
645 ret_variable_int = atoi(ret_val);
649 sizeof(buf_str), "%d",
652 src_len = strlen(result_str);
653 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
655 strncat(result_str, buf_str,
661 } else if (*(temp_str + 1) == 's') {
666 check_type, num_args);
667 bundle_get_str(b, buf_key, &ret_val);
669 if (ret_val != NULL && noti->domain != NULL && noti->dir != NULL) {
670 /* Get application string */
671 bindtextdomain(noti->domain, noti->dir);
672 translated_str = dgettext(noti->domain, ret_val);
673 NOTIFICATION_INFO("translated_str[%s]", translated_str);
674 } else if (ret_val != NULL) {
675 /* Get system string */
676 translated_str = dgettext("sys_string", ret_val);
677 NOTIFICATION_INFO("translated_str[%s]", translated_str);
679 translated_str = NULL;
682 if (translated_str != NULL) {
683 strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
684 src_len = strlen(result_str);
685 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
686 strncat(result_str, buf_str, max_len);
690 } else if (*(temp_str + 1) == 'f') {
695 check_type, num_args);
696 bundle_get_str(b, buf_key, &ret_val);
698 ret_variable_double = atof(ret_val);
703 ret_variable_double);
705 src_len = strlen(result_str);
706 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
707 strncat(result_str, buf_str, max_len);
711 } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
712 if (*(temp_str + 3) == 'd') {
714 ret_variable_int = 0;
718 "%dtype%d", check_type,
719 num_args + *(temp_str + 1) - 49);
720 bundle_get_str(b, buf_key, &ret_val);
722 ret_var_type = atoi(ret_val);
725 NOTIFICATION_VARIABLE_TYPE_COUNT) {
726 /* Get notification count */
727 notification_get_count(noti->type,
728 noti->caller_pkgname,
739 num_args + *(temp_str + 1) - 49);
740 bundle_get_str(b, buf_key, &ret_val);
742 ret_variable_int = atoi(ret_val);
747 sizeof(buf_str), "%d",
750 src_len = strlen(result_str);
751 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
753 strncat(result_str, buf_str, max_len);
756 } else if (*(temp_str + 3) == 's') {
761 check_type, num_args + *(temp_str + 1) - 49);
762 bundle_get_str(b, buf_key, &ret_val);
765 sizeof(buf_str), "%s",
768 src_len = strlen(result_str);
769 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
771 strncat(result_str, buf_str, max_len);
774 } else if (*(temp_str + 3) == 'f') {
779 check_type, num_args + *(temp_str + 1) - 49);
780 bundle_get_str(b, buf_key, &ret_val);
782 ret_variable_double = atof(ret_val);
787 ret_variable_double);
789 src_len = strlen(result_str);
790 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
792 strncat(result_str, buf_str, max_len);
801 /* Check last variable is count, LEFT pos */
802 if (num_args < noti->num_format_args) {
803 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
804 check_type, num_args);
805 bundle_get_str(b, buf_key, &ret_val);
807 ret_var_type = atoi(ret_val);
810 NOTIFICATION_VARIABLE_TYPE_COUNT) {
812 snprintf(buf_key, sizeof(buf_key),
813 "%dvalue%d", check_type,
815 bundle_get_str(b, buf_key, &ret_val);
817 ret_variable_int = atoi(ret_val);
819 if (ret_variable_int ==
820 NOTIFICATION_COUNT_POS_RIGHT) {
821 notification_get_count(noti->type,
822 noti->caller_pkgname,
827 sizeof(buf_str), " %d",
830 src_len = strlen(result_str);
831 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
833 strncat(result_str, buf_str, max_len);
841 switch (check_type) {
842 case NOTIFICATION_TEXT_TYPE_TITLE:
843 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
844 if (noti->temp_title != NULL)
845 free(noti->temp_title);
847 noti->temp_title = strdup(result_str);
849 *text = noti->temp_title;
851 case NOTIFICATION_TEXT_TYPE_CONTENT:
852 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
853 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
854 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
855 if (noti->temp_content !=
857 free(noti->temp_content);
859 noti->temp_content = strdup(result_str);
861 *text = noti->temp_content;
873 return NOTIFICATION_ERROR_NONE;
876 EXPORT_API int notification_set_text_domain(notification_h noti,
880 /* check noti and domain is valid data */
881 if (noti == NULL || domain == NULL || dir == NULL)
882 return NOTIFICATION_ERROR_INVALID_PARAMETER;
886 /* Remove previous domain */
890 noti->domain = strdup(domain);
892 /* Check locale dir */
894 /* Remove previous locale dir */
897 /* Copy locale dir */
898 noti->dir = strdup(dir);
900 return NOTIFICATION_ERROR_NONE;
903 EXPORT_API int notification_get_text_domain(notification_h noti,
907 /* Check noti is valid data */
909 return NOTIFICATION_ERROR_INVALID_PARAMETER;
912 if (domain != NULL && noti->domain != NULL)
913 *domain = noti->domain;
916 if (dir != NULL && noti->dir != NULL)
919 return NOTIFICATION_ERROR_NONE;
922 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
925 int ret = NOTIFICATION_ERROR_NONE;
926 char buf[256] = { 0, };
927 char buf_tag[512] = { 0, };
930 return NOTIFICATION_ERROR_INVALID_PARAMETER;
933 return NOTIFICATION_ERROR_INVALID_PARAMETER;
935 if (type <= NOTIFICATION_TEXT_TYPE_NONE
936 || type >= NOTIFICATION_TEXT_TYPE_MAX)
937 return NOTIFICATION_ERROR_INVALID_PARAMETER;
940 snprintf(buf, sizeof(buf), "%lu", time);
941 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
943 if (ret != NOTIFICATION_ERROR_NONE)
946 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
949 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
952 int ret = NOTIFICATION_ERROR_NONE;
953 char *ret_text = NULL;
957 return NOTIFICATION_ERROR_INVALID_PARAMETER;
960 return NOTIFICATION_ERROR_INVALID_PARAMETER;
962 if (type <= NOTIFICATION_TEXT_TYPE_NONE
963 || type >= NOTIFICATION_TEXT_TYPE_MAX)
964 return NOTIFICATION_ERROR_INVALID_PARAMETER;
966 ret = notification_get_text(noti, type, &ret_text);
968 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL)
969 return NOTIFICATION_ERROR_INVALID_PARAMETER;
971 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID)
972 return NOTIFICATION_ERROR_INVALID_PARAMETER;
974 tag_value = notification_noti_strip_tag(ret_text);
975 if (tag_value == NULL)
976 return NOTIFICATION_ERROR_INVALID_PARAMETER;
978 *time = atol(tag_value);
981 return NOTIFICATION_ERROR_NONE;
984 EXPORT_API int notification_set_sound(notification_h noti,
985 notification_sound_type_e type,
988 /* Check noti is valid data */
990 return NOTIFICATION_ERROR_INVALID_PARAMETER;
993 /* Check type is valid */
994 if (type < NOTIFICATION_SOUND_TYPE_NONE
995 || type >= NOTIFICATION_SOUND_TYPE_MAX)
996 return NOTIFICATION_ERROR_INVALID_PARAMETER;
998 /* Save sound type */
999 noti->sound_type = type;
1001 /* Save sound path if user data type */
1002 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1003 if (noti->sound_path != NULL)
1004 free(noti->sound_path);
1006 noti->sound_path = strdup(path);
1008 if (noti->sound_path != NULL) {
1009 free(noti->sound_path);
1010 noti->sound_path = NULL;
1012 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1013 noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1014 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1018 return NOTIFICATION_ERROR_NONE;
1021 EXPORT_API int notification_get_sound(notification_h noti,
1022 notification_sound_type_e *type,
1025 /* check noti and type is valid data */
1026 if (noti == NULL || type == NULL)
1027 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1029 /* Set sound type */
1030 *type = noti->sound_type;
1032 /* Set sound path if user data type */
1033 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1035 *path = noti->sound_path;
1037 return NOTIFICATION_ERROR_NONE;
1040 EXPORT_API int notification_set_vibration(notification_h noti,
1041 notification_vibration_type_e type,
1044 /* Check noti is valid data */
1046 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1048 /* Check type is valid */
1049 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1050 || type >= NOTIFICATION_VIBRATION_TYPE_MAX)
1051 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1053 /* Save vibration type */
1054 noti->vibration_type = type;
1056 /* Save sound path if user data type */
1057 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1058 if (noti->vibration_path != NULL)
1059 free(noti->vibration_path);
1061 noti->vibration_path = strdup(path);
1063 if (noti->vibration_path != NULL) {
1064 free(noti->vibration_path);
1065 noti->vibration_path = NULL;
1067 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1068 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1069 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1073 return NOTIFICATION_ERROR_NONE;
1077 EXPORT_API int notification_get_vibration(notification_h noti,
1078 notification_vibration_type_e *type,
1081 /* check noti and type is valid data */
1082 if (noti == NULL || type == NULL)
1083 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1085 /* Set vibration type */
1086 *type = noti->vibration_type;
1088 /* Set sound path if user data type */
1089 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1091 *path = noti->vibration_path;
1093 return NOTIFICATION_ERROR_NONE;
1096 EXPORT_API int notification_set_led(notification_h noti,
1097 notification_led_op_e operation,
1100 /* Check noti is valid data */
1102 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1104 /* Check operation is valid */
1105 if (operation < NOTIFICATION_LED_OP_OFF
1106 || operation >= NOTIFICATION_LED_OP_MAX)
1107 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1109 /* Save led operation */
1110 noti->led_operation = operation;
1112 /* Save led argb if operation is turning on LED with custom color */
1113 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR)
1114 noti->led_argb = led_argb;
1116 return NOTIFICATION_ERROR_NONE;
1119 EXPORT_API int notification_get_led(notification_h noti,
1120 notification_led_op_e *operation,
1123 /* check noti and operation is valid data */
1124 if (noti == NULL || operation == NULL)
1125 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1127 /* Set led operation */
1128 *operation = noti->led_operation;
1130 /* Save led argb if operation is turning on LED with custom color */
1131 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1132 && led_argb != NULL)
1133 *led_argb = noti->led_argb;
1135 return NOTIFICATION_ERROR_NONE;
1138 EXPORT_API int notification_set_led_time_period(notification_h noti,
1139 int on_ms, int off_ms)
1141 /* Check noti is valid data */
1142 if (noti == NULL || on_ms < 0 || off_ms < 0)
1143 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1145 /* Save led operation */
1146 noti->led_on_ms = on_ms;
1147 noti->led_off_ms = off_ms;
1149 return NOTIFICATION_ERROR_NONE;
1152 EXPORT_API int notification_get_led_time_period(notification_h noti,
1153 int *on_ms, int *off_ms)
1155 /* check noti and operation is valid data */
1157 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1160 *(on_ms) = noti->led_on_ms;
1162 *(off_ms) = noti->led_off_ms;
1164 return NOTIFICATION_ERROR_NONE;
1167 EXPORT_API int notification_set_launch_option(notification_h noti,
1168 notification_launch_option_type type, void *option)
1170 int err = NOTIFICATION_ERROR_NONE;
1173 app_control_h app_control = option;
1175 if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1176 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1180 if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1181 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1182 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1186 err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1195 EXPORT_API int notification_get_launch_option(notification_h noti,
1196 notification_launch_option_type type, void *option)
1200 app_control_h *app_control = (app_control_h *)option;
1201 app_control_h app_control_new = NULL;
1204 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1206 if (app_control == NULL)
1207 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1209 if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL)
1210 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1213 ret = notification_get_execute_option(noti,
1214 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1217 if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1218 ret = app_control_create(&app_control_new);
1219 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1220 ret = app_control_import_from_bundle(app_control_new, b);
1221 if (ret == APP_CONTROL_ERROR_NONE) {
1222 *app_control = app_control_new;
1224 app_control_destroy(app_control_new);
1225 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1226 return NOTIFICATION_ERROR_IO_ERROR;
1229 NOTIFICATION_ERR("Failed to create app control:%d", ret);
1230 return NOTIFICATION_ERROR_IO_ERROR;
1233 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1237 return NOTIFICATION_ERROR_NONE;
1240 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1242 int err = NOTIFICATION_ERROR_NONE;
1243 bundle *app_control_bundle = NULL;
1246 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1247 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1251 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1252 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1253 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1254 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1258 if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1259 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1263 if (noti->b_event_handler[event_type] != NULL)
1264 bundle_free(noti->b_event_handler[event_type]);
1266 noti->b_event_handler[event_type] = app_control_bundle;
1272 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1274 int err = NOTIFICATION_ERROR_NONE;
1276 app_control_h app_control_new = NULL;
1279 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1280 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1283 if (event_handler == NULL) {
1284 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1285 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1288 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1289 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1290 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1291 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1295 b = noti->b_event_handler[event_type];
1298 NOTIFICATION_DBG("No event handler\n");
1299 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1303 err = app_control_create(&app_control_new);
1304 if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1305 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1306 err = NOTIFICATION_ERROR_IO_ERROR;
1310 err = app_control_import_from_bundle(app_control_new, b);
1311 if (err == APP_CONTROL_ERROR_NONE) {
1312 *event_handler = app_control_new;
1314 app_control_destroy(app_control_new);
1315 app_control_new = NULL;
1316 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1317 err = NOTIFICATION_ERROR_IO_ERROR;
1323 *event_handler = app_control_new;
1332 EXPORT_API int notification_set_property(notification_h noti,
1335 /* Check noti is valid data */
1337 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1340 noti->flags_for_property = flags;
1342 return NOTIFICATION_ERROR_NONE;
1345 EXPORT_API int notification_get_property(notification_h noti,
1348 /* Check noti and flags are valid data */
1349 if (noti == NULL || flags == NULL)
1350 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1353 *flags = noti->flags_for_property;
1355 return NOTIFICATION_ERROR_NONE;
1358 EXPORT_API int notification_set_display_applist(notification_h noti,
1361 /* Check noti is valid data */
1363 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1367 if (applist == 0xffffffff) /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1368 applist = NOTIFICATION_DISPLAY_APP_ALL;
1370 noti->display_applist = applist;
1372 return NOTIFICATION_ERROR_NONE;
1375 EXPORT_API int notification_get_display_applist(notification_h noti,
1378 /* Check noti and applist are valid data */
1379 if (noti == NULL || applist == NULL)
1380 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1383 *applist = noti->display_applist;
1385 return NOTIFICATION_ERROR_NONE;
1388 EXPORT_API int notification_set_size(notification_h noti,
1391 /* Check noti is valid data */
1393 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1395 /* Save progress size */
1396 noti->progress_size = size;
1398 return NOTIFICATION_ERROR_NONE;
1401 EXPORT_API int notification_get_size(notification_h noti,
1404 /* Check noti and size is valid data */
1405 if (noti == NULL || size == NULL)
1406 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1408 /* Set progress size */
1409 *size = noti->progress_size;
1411 return NOTIFICATION_ERROR_NONE;
1414 EXPORT_API int notification_set_progress(notification_h noti,
1417 /* Check noti is valid data */
1419 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1421 /* Save progress percentage */
1422 noti->progress_percentage = percentage;
1424 return NOTIFICATION_ERROR_NONE;
1427 EXPORT_API int notification_get_progress(notification_h noti,
1430 /* Check noti and percentage are valid data */
1431 if (noti == NULL || percentage == NULL)
1432 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1434 /* Set progress percentage */
1435 *percentage = noti->progress_percentage;
1437 return NOTIFICATION_ERROR_NONE;
1440 EXPORT_API int notification_get_pkgname(notification_h noti,
1443 /* Check noti and pkgname are valid data */
1444 if (noti == NULL || pkgname == NULL)
1445 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1447 /* Get caller pkgname */
1448 if (noti->caller_pkgname)
1449 *pkgname = noti->caller_pkgname;
1453 return NOTIFICATION_ERROR_NONE;
1456 EXPORT_API int notification_set_layout(notification_h noti,
1457 notification_ly_type_e layout)
1459 /* check noti and pkgname are valid data */
1460 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX))
1461 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1463 noti->layout = layout;
1465 return NOTIFICATION_ERROR_NONE;
1468 EXPORT_API int notification_get_layout(notification_h noti,
1469 notification_ly_type_e *layout)
1471 /* Check noti and pkgname are valid data */
1472 if (noti == NULL || layout == NULL)
1473 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1475 *layout = noti->layout;
1477 return NOTIFICATION_ERROR_NONE;
1482 EXPORT_API int notification_get_type(notification_h noti,
1483 notification_type_e *type)
1485 /* Check noti and type is valid data */
1486 if (noti == NULL || type == NULL)
1487 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1492 return NOTIFICATION_ERROR_NONE;
1495 EXPORT_API int notification_post(notification_h noti)
1500 /* Check noti is vaild data */
1502 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1504 /* Check noti type is valid type */
1505 if (noti->type <= NOTIFICATION_TYPE_NONE
1506 || noti->type >= NOTIFICATION_TYPE_MAX)
1507 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1509 /* Save insert time */
1510 noti->insert_time = time(NULL);
1512 ret = notification_ipc_request_insert(noti, &id);
1513 if (ret != NOTIFICATION_ERROR_NONE)
1517 NOTIFICATION_DBG("from master:%d", id);
1519 return NOTIFICATION_ERROR_NONE;
1524 EXPORT_API int notification_update(notification_h noti)
1528 /* Check noti is valid data */
1530 /* Update insert time ? */
1531 noti->insert_time = time(NULL);
1532 ret = notification_ipc_request_update(noti);
1534 notification_ipc_request_refresh();
1535 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1540 EXPORT_API int notification_delete_all(notification_type_e type)
1543 char *caller_pkgname = NULL;
1545 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
1546 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1548 caller_pkgname = notification_get_pkgname_by_pid();
1550 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1553 free(caller_pkgname);
1558 EXPORT_API int notification_delete(notification_h noti)
1563 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1565 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1570 static notification_h _notification_create(notification_type_e type)
1572 notification_h noti = NULL;
1573 package_info_h package_info = NULL;
1574 char *app_id = NULL;
1575 char *domain_name = NULL;
1576 char *app_root_path = NULL;
1577 char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1578 int err_app_manager = APP_MANAGER_ERROR_NONE;
1580 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1581 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1582 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1586 noti = (notification_h) calloc(1, sizeof(struct _notification));
1588 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1589 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1595 if (type == NOTIFICATION_TYPE_NOTI)
1596 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1597 else if (type == NOTIFICATION_TYPE_ONGOING)
1598 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1600 noti->caller_pkgname = notification_get_pkgname_by_pid();
1601 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1602 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1603 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1604 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1605 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1606 noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1607 noti->auto_remove = true;
1609 err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1610 if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1611 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]", err_app_manager, app_id);
1615 /* app name is used as domain name */
1616 /* domain_name is allocated by app_get_package_app_name */
1617 err_app_manager = app_get_package_app_name(app_id, &domain_name);
1619 if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1620 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]", err_app_manager, domain_name);
1624 err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1626 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1627 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p] caller_pkgname[%s]",
1628 err_app_manager, package_info, noti->caller_pkgname);
1632 err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1634 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1635 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]", err_app_manager, app_root_path);
1639 snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1641 noti->domain = strdup(domain_name);
1642 noti->dir = strdup(locale_directory);
1652 free(app_root_path);
1655 package_info_destroy(package_info);
1659 * Other fields are already initialized with ZERO.
1661 set_last_result(NOTIFICATION_ERROR_NONE);
1665 EXPORT_API notification_h notification_create(notification_type_e type)
1667 return _notification_create(type);
1670 EXPORT_API notification_h notification_load_by_tag(const char *tag)
1673 notification_h noti = NULL;
1674 char *caller_pkgname = NULL;
1677 NOTIFICATION_ERR("Invalid parameter");
1678 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1682 caller_pkgname = notification_get_pkgname_by_pid();
1683 if (!caller_pkgname) {
1684 NOTIFICATION_ERR("Failed to get a package name");
1685 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1689 noti = (notification_h)calloc(1, sizeof(struct _notification));
1691 NOTIFICATION_ERR("Failed to alloc a new notification");
1692 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1693 free(caller_pkgname);
1698 ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char*)tag);
1699 free(caller_pkgname);
1701 set_last_result(ret);
1702 if (ret != NOTIFICATION_ERROR_NONE) {
1703 notification_free(noti);
1710 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1713 notification_h new_noti = NULL;
1715 if (noti == NULL || clone == NULL) {
1716 NOTIFICATION_ERR("INVALID PARAMETER.");
1717 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1720 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1721 if (new_noti == NULL) {
1722 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1723 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1726 new_noti->type = noti->type;
1727 new_noti->layout = noti->layout;
1729 new_noti->group_id = noti->group_id;
1730 new_noti->internal_group_id = noti->internal_group_id;
1731 new_noti->priv_id = noti->priv_id;
1733 if (noti->caller_pkgname != NULL)
1734 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1736 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1738 if (noti->launch_pkgname != NULL)
1739 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1741 new_noti->launch_pkgname = NULL;
1743 if (noti->args != NULL)
1744 new_noti->args = bundle_dup(noti->args);
1746 new_noti->args = NULL;
1748 if (noti->group_args != NULL)
1749 new_noti->group_args = bundle_dup(noti->group_args);
1751 new_noti->group_args = NULL;
1753 if (noti->b_execute_option != NULL)
1754 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1756 new_noti->b_execute_option = NULL;
1758 if (noti->b_service_responding != NULL)
1759 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1761 new_noti->b_service_responding = NULL;
1763 if (noti->b_service_single_launch != NULL)
1764 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1766 new_noti->b_service_single_launch = NULL;
1768 if (noti->b_service_multi_launch != NULL)
1769 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1771 new_noti->b_service_multi_launch = NULL;
1773 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1774 if (noti->b_event_handler[i] != NULL)
1775 new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1777 new_noti->b_event_handler[i] = NULL;
1780 new_noti->sound_type = noti->sound_type;
1781 if (noti->sound_path != NULL)
1782 new_noti->sound_path = strdup(noti->sound_path);
1784 new_noti->sound_path = NULL;
1786 new_noti->vibration_type = noti->vibration_type;
1787 if (noti->vibration_path != NULL)
1788 new_noti->vibration_path = strdup(noti->vibration_path);
1790 new_noti->vibration_path = NULL;
1792 new_noti->led_operation = noti->led_operation;
1793 new_noti->led_argb = noti->led_argb;
1794 new_noti->led_on_ms = noti->led_on_ms;
1795 new_noti->led_off_ms = noti->led_off_ms;
1797 if (noti->domain != NULL)
1798 new_noti->domain = strdup(noti->domain);
1800 new_noti->domain = NULL;
1802 if (noti->dir != NULL)
1803 new_noti->dir = strdup(noti->dir);
1805 new_noti->dir = NULL;
1807 if (noti->b_text != NULL)
1808 new_noti->b_text = bundle_dup(noti->b_text);
1810 new_noti->b_text = NULL;
1812 if (noti->b_key != NULL)
1813 new_noti->b_key = bundle_dup(noti->b_key);
1815 new_noti->b_key = NULL;
1817 if (noti->b_format_args != NULL)
1818 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1820 new_noti->b_format_args = NULL;
1822 new_noti->num_format_args = noti->num_format_args;
1824 if (noti->b_image_path != NULL)
1825 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1827 new_noti->b_image_path = NULL;
1829 new_noti->time = noti->time;
1830 new_noti->insert_time = noti->insert_time;
1832 new_noti->flags_for_property = noti->flags_for_property;
1833 new_noti->display_applist = noti->display_applist;
1835 new_noti->progress_size = noti->progress_size;
1836 new_noti->progress_percentage = noti->progress_percentage;
1838 new_noti->ongoing_flag = noti->ongoing_flag;
1839 new_noti->auto_remove = noti->auto_remove;
1841 new_noti->app_icon_path = NULL;
1842 new_noti->app_name = NULL;
1843 new_noti->temp_title = NULL;
1844 new_noti->temp_content = NULL;
1848 return NOTIFICATION_ERROR_NONE;
1852 EXPORT_API int notification_free(notification_h noti)
1856 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1858 if (noti->caller_pkgname)
1859 free(noti->caller_pkgname);
1861 if (noti->launch_pkgname)
1862 free(noti->launch_pkgname);
1865 bundle_free(noti->args);
1867 if (noti->group_args)
1868 bundle_free(noti->group_args);
1870 if (noti->b_execute_option)
1871 bundle_free(noti->b_execute_option);
1873 if (noti->b_service_responding)
1874 bundle_free(noti->b_service_responding);
1876 if (noti->b_service_single_launch)
1877 bundle_free(noti->b_service_single_launch);
1879 if (noti->b_service_multi_launch)
1880 bundle_free(noti->b_service_multi_launch);
1882 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1883 if (noti->b_event_handler[i] != NULL)
1884 bundle_free(noti->b_event_handler[i]);
1887 if (noti->sound_path)
1888 free(noti->sound_path);
1890 if (noti->vibration_path)
1891 free(noti->vibration_path);
1900 bundle_free(noti->b_text);
1903 bundle_free(noti->b_key);
1905 if (noti->b_format_args)
1906 bundle_free(noti->b_format_args);
1908 if (noti->b_image_path)
1909 bundle_free(noti->b_image_path);
1911 if (noti->app_icon_path)
1912 free(noti->app_icon_path);
1915 free(noti->app_name);
1917 if (noti->temp_title)
1918 free(noti->temp_title);
1920 if (noti->temp_content)
1921 free(noti->temp_content);
1928 return NOTIFICATION_ERROR_NONE;
1931 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
1933 /* Check noti is valid data */
1935 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1938 /* save input TAG */
1939 if (noti->tag != NULL)
1942 noti->tag = strdup(tag);
1945 return NOTIFICATION_ERROR_NONE;
1949 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
1951 /* Check noti is valid data */
1953 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1956 return NOTIFICATION_ERROR_NONE;
1959 void notification_call_posted_toast_cb(const char *message)
1961 if (posted_toast_message_cb != NULL)
1962 posted_toast_message_cb((void*)message);
1965 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
1968 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1970 noti->ongoing_flag = ongoing_flag;
1972 return NOTIFICATION_ERROR_NONE;
1975 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
1977 if (noti == NULL || ongoing_flag == NULL)
1978 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1980 *ongoing_flag = noti->ongoing_flag;
1982 return NOTIFICATION_ERROR_NONE;
1986 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
1988 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
1989 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1991 return NOTIFICATION_ERROR_NONE;
1994 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
1996 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
1997 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1999 if (noti->b_event_handler[button_index - 1]) {
2000 bundle_free(noti->b_event_handler[button_index - 1]);
2001 noti->b_event_handler[button_index - 1] = NULL;
2004 return NOTIFICATION_ERROR_NONE;
2007 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
2010 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2012 noti->auto_remove = auto_remove;
2014 return NOTIFICATION_ERROR_NONE;
2017 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
2019 if (noti == NULL || auto_remove == NULL)
2020 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2022 *auto_remove = noti->auto_remove;
2024 return NOTIFICATION_ERROR_NONE;