2 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <dbus/dbus.h>
24 #include <dbus/dbus-glib-lowlevel.h>
27 #include <app_internal.h>
28 #include <app_manager.h>
29 #include <app_control_internal.h>
30 #include <package_manager.h>
35 #include <vconf-keys.h>
38 #include <notification.h>
39 #include <notification_list.h>
40 #include <notification_debug.h>
41 #include <notification_private.h>
42 #include <notification_noti.h>
43 #include <notification_ongoing.h>
44 #include <notification_group.h>
45 #include <notification_ipc.h>
46 #include <notification_internal.h>
48 static void (*posted_toast_message_cb) (void *data);
50 #define NOTI_TEXT_RESULT_LEN 2048
51 #define NOTI_PKGNAME_LEN 512
53 char *notification_get_pkgname_by_pid(void)
55 char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
56 int pid = 0, ret = AUL_R_OK;
59 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
63 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
64 if (ret != AUL_R_OK) {
66 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
68 fd = open(buf, O_RDONLY);
72 ret = read(fd, pkgname, sizeof(pkgname) - 1);
81 * "ret" is not able to be larger than "sizeof(pkgname) - 1",
82 * if the system is not going wrong.
85 if (strlen(pkgname) <= 0)
89 dup_pkgname = strdup(pkgname);
91 NOTIFICATION_ERR("Heap: %d\n", errno);
96 EXPORT_API int notification_set_image(notification_h noti,
97 notification_image_type_e type,
98 const char *image_path)
101 char buf_key[32] = { 0, };
102 char *ret_val = NULL;
104 /* Check noti and image_path are valid data */
105 if (noti == NULL || image_path == NULL)
106 return NOTIFICATION_ERROR_INVALID_PARAMETER;
108 /* Check image type is valid type */
109 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
110 || type >= NOTIFICATION_IMAGE_TYPE_MAX)
111 return NOTIFICATION_ERROR_INVALID_PARAMETER;
113 /* Check image path bundle is exist */
114 if (noti->b_image_path) {
115 /* If image path bundle is exist, store local bundle value */
116 b = noti->b_image_path;
118 /* Set image type to key as char string type */
119 snprintf(buf_key, sizeof(buf_key), "%d", type);
121 /* Get value using key */
122 bundle_get_str(b, buf_key, &ret_val);
124 /* If key is exist, remove this value to store new image path */
125 bundle_del(b, buf_key);
127 /* Add new image path with type key */
128 bundle_add_str(b, buf_key, image_path);
130 /* If image path bundle is not exist, create new one */
133 /* Set image type to key as char string type */
134 snprintf(buf_key, sizeof(buf_key), "%d", type);
136 /* Add new image path with type key */
137 bundle_add_str(b, buf_key, image_path);
139 /* Save to image path bundle */
140 noti->b_image_path = b;
143 return NOTIFICATION_ERROR_NONE;
146 EXPORT_API int notification_get_image(notification_h noti,
147 notification_image_type_e type,
151 char buf_key[32] = { 0, };
152 char *ret_val = NULL;
154 /* Check noti and image_path is valid data */
155 if (noti == NULL || image_path == NULL)
156 return NOTIFICATION_ERROR_INVALID_PARAMETER;
158 /* Check image type is valid data */
159 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
160 || type >= NOTIFICATION_IMAGE_TYPE_MAX)
161 return NOTIFICATION_ERROR_INVALID_PARAMETER;
163 /* Check image path bundle exist */
164 if (noti->b_image_path) {
165 /* If image path bundle exist, store local bundle data */
166 b = noti->b_image_path;
168 /* Set image type to key as char string type */
169 snprintf(buf_key, sizeof(buf_key), "%d", type);
171 /* Get value of key */
172 bundle_get_str(b, buf_key, &ret_val);
174 *image_path = ret_val;
176 /* If image path bundle does not exist, image path is NULL */
180 /* If image path is NULL and type is ICON, icon path set from AIL */
181 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
182 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
183 /* Check App icon path is already set */
184 if (noti->app_icon_path != NULL)
185 /* image path will be app icon path */
186 *image_path = noti->app_icon_path;
191 return NOTIFICATION_ERROR_NONE;
194 EXPORT_API int notification_set_time(notification_h noti, time_t input_time)
196 /* Check noti is valid data */
198 return NOTIFICATION_ERROR_INVALID_PARAMETER;
201 /* If input time is 0, set current time */
202 noti->time = time(NULL);
204 /* save input time */
205 noti->time = input_time;
207 return NOTIFICATION_ERROR_NONE;
210 EXPORT_API int notification_get_time(notification_h noti, time_t *ret_time)
212 /* Check noti and time is valid data */
213 if (noti == NULL || ret_time == NULL)
214 return NOTIFICATION_ERROR_INVALID_PARAMETER;
216 /* Set time infomation */
217 *ret_time = noti->time;
219 return NOTIFICATION_ERROR_NONE;
222 EXPORT_API int notification_get_insert_time(notification_h noti,
225 /* Check noti and ret_time is valid data */
226 if (noti == NULL || ret_time == NULL)
227 return NOTIFICATION_ERROR_INVALID_PARAMETER;
229 /* Set insert time information */
230 *ret_time = noti->insert_time;
232 return NOTIFICATION_ERROR_NONE;
235 EXPORT_API int notification_set_text(notification_h noti,
236 notification_text_type_e type, const char *text,
237 const char *key, int args_type, ...)
240 char buf_key[32] = { 0, };
241 char buf_val[1024] = { 0, };
242 char *ret_val = NULL;
244 notification_variable_type_e var_type;
246 int noti_err = NOTIFICATION_ERROR_NONE;
247 int var_value_int = 0;
248 double var_value_double = 0.0;
249 char *var_value_string = NULL;
250 notification_count_pos_type_e var_value_count =
251 NOTIFICATION_COUNT_POS_NONE;
253 /* Check noti is valid data */
255 return NOTIFICATION_ERROR_INVALID_PARAMETER;
257 /* Check text type is valid type */
258 if (type <= NOTIFICATION_TEXT_TYPE_NONE
259 || type >= NOTIFICATION_TEXT_TYPE_MAX)
260 return NOTIFICATION_ERROR_INVALID_PARAMETER;
262 /* Check text bundle exist */
264 if (noti->b_text != NULL) {
265 /* If text bundle exist, store local bundle data */
268 /* Make type to key as char string */
269 snprintf(buf_key, sizeof(buf_key), "%d", type);
271 /* Get value using type key */
272 bundle_get_str(b, buf_key, &ret_val);
275 /* If value exist, remove this to add new value */
276 bundle_del(b, buf_key);
278 snprintf(buf_val, sizeof(buf_val), "%s", text);
280 /* Add new text value */
281 bundle_add_str(b, buf_key, buf_val);
283 /* If text bundle does not exist, create new one */
286 /* Make type to key as char string */
287 snprintf(buf_key, sizeof(buf_key), "%d", type);
289 snprintf(buf_val, sizeof(buf_val), "%s", text);
291 /* Add new text value */
292 bundle_add_str(b, buf_key, buf_val);
294 /* Save text bundle */
298 /* Reset if text is NULL */
299 if (noti->b_text != NULL) {
300 /* If text bundle exist, store local bundle data */
303 /* Make type to key as char string */
304 snprintf(buf_key, sizeof(buf_key), "%d", type);
306 /* Get value using type key */
307 bundle_get_str(b, buf_key, &ret_val);
309 /* If value exist, remove this */
310 bundle_del(b, buf_key);
314 /* Save key if key is valid data */
316 /* Check key bundle exist */
317 if (noti->b_key != NULL) {
318 /* If key bundle exist, store local bundle data */
321 /* Make type to key as char string */
322 snprintf(buf_key, sizeof(buf_key), "%d", type);
324 /* Get value using type key */
325 bundle_get_str(b, buf_key, &ret_val);
327 /* If value exist, remove this to add new value */
328 bundle_del(b, buf_key);
330 snprintf(buf_val, sizeof(buf_val), "%s", key);
332 /* Add new key value */
333 bundle_add_str(b, buf_key, buf_val);
335 /* If key bundle does not exist, create new one */
338 /* Make type to key as char string */
339 snprintf(buf_key, sizeof(buf_key), "%d", type);
341 snprintf(buf_val, sizeof(buf_val), "%s", key);
343 /* Add new key value */
344 bundle_add_str(b, buf_key, buf_val);
346 /* Save key bundle */
350 /* Reset if key is NULL */
351 if (noti->b_key != NULL) {
352 /* If key bundle exist, store local bundle data */
355 /* Make type to key as char string */
356 snprintf(buf_key, sizeof(buf_key), "%d", type);
358 /* Get value using type key */
359 bundle_get_str(b, buf_key, &ret_val);
361 /* If value exist, remove this */
362 bundle_del(b, buf_key);
366 if (noti->b_format_args != NULL)
367 b = noti->b_format_args;
371 va_start(var_args, args_type);
373 var_type = args_type;
376 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
378 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
379 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
381 bundle_get_str(b, buf_key, &ret_val);
383 bundle_del(b, buf_key);
385 bundle_add_str(b, buf_key, buf_val);
388 case NOTIFICATION_VARIABLE_TYPE_INT:
389 var_value_int = va_arg(var_args, int);
392 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
394 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
396 bundle_get_str(b, buf_key, &ret_val);
398 bundle_del(b, buf_key);
400 bundle_add_str(b, buf_key, buf_val);
403 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
404 var_value_double = va_arg(var_args, double);
407 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
409 snprintf(buf_val, sizeof(buf_val), "%.2f",
412 bundle_get_str(b, buf_key, &ret_val);
414 bundle_del(b, buf_key);
416 bundle_add_str(b, buf_key, buf_val);
419 case NOTIFICATION_VARIABLE_TYPE_STRING:
420 var_value_string = va_arg(var_args, char *);
423 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
425 snprintf(buf_val, sizeof(buf_val), "%s",
428 bundle_get_str(b, buf_key, &ret_val);
430 bundle_del(b, buf_key);
432 bundle_add_str(b, buf_key, buf_val);
435 case NOTIFICATION_VARIABLE_TYPE_COUNT:
437 va_arg(var_args, notification_count_pos_type_e);
440 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
442 snprintf(buf_val, sizeof(buf_val), "%d",
445 bundle_get_str(b, buf_key, &ret_val);
447 bundle_del(b, buf_key);
449 bundle_add_str(b, buf_key, buf_val);
453 NOTIFICATION_ERR("Error. invalid variable type. : %d",
455 noti_err = NOTIFICATION_ERROR_INVALID_PARAMETER;
460 var_type = va_arg(var_args, notification_variable_type_e);
464 if (noti_err == NOTIFICATION_ERROR_NONE)
465 noti->num_format_args = num_args;
467 noti->num_format_args = 0;
469 snprintf(buf_key, sizeof(buf_key), "num%d", type);
470 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
472 bundle_get_str(b, buf_key, &ret_val);
474 bundle_del(b, buf_key);
476 bundle_add_str(b, buf_key, buf_val);
478 noti->b_format_args = b;
483 EXPORT_API int notification_get_text(notification_h noti,
484 notification_text_type_e type,
488 char buf_key[32] = { 0, };
489 char *ret_val = NULL;
490 char *get_str = NULL;
491 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
492 /* int display_option_flag = 0; */
494 char *temp_str = NULL;
495 char *translated_str = NULL;
496 char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
497 char buf_str[1024] = { 0, };
499 notification_variable_type_e ret_var_type = 0;
500 int ret_variable_int = 0;
501 double ret_variable_double = 0.0;
505 /* Check noti is valid data */
506 if (noti == NULL || text == NULL)
507 return NOTIFICATION_ERROR_INVALID_PARAMETER;
509 /* Check text type is valid type */
510 if (type <= NOTIFICATION_TEXT_TYPE_NONE
511 || type >= NOTIFICATION_TEXT_TYPE_MAX)
512 return NOTIFICATION_ERROR_INVALID_PARAMETER;
516 if (noti->b_key != NULL) {
519 /* Get text domain and dir */
520 /* _notification_get_text_domain(noti); */
522 snprintf(buf_key, sizeof(buf_key), "%d", type);
524 bundle_get_str(b, buf_key, &ret_val);
525 if (ret_val != NULL && noti->domain != NULL
526 && noti->dir != NULL) {
527 /* Get application string */
528 bindtextdomain(noti->domain, noti->dir);
530 get_str = dgettext(noti->domain, ret_val);
531 } else if (ret_val != NULL) {
532 /* Get system string */
533 get_str = dgettext("sys_string", ret_val);
539 if (get_str == NULL && noti->b_text != NULL) {
542 snprintf(buf_key, sizeof(buf_key), "%d", type);
544 bundle_get_str(b, buf_key, &get_str);
549 if (get_str != NULL) {
550 /* Get number format args */
551 b = noti->b_format_args;
552 noti->num_format_args = 0;
555 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
556 bundle_get_str(b, buf_key, &ret_val);
558 noti->num_format_args = atoi(ret_val);
561 if (noti->num_format_args == 0) {
562 *text = (char *)get_str;
564 /* Check first variable is count, LEFT pos */
565 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
566 check_type, num_args);
567 bundle_get_str(b, buf_key, &ret_val);
569 ret_var_type = atoi(ret_val);
571 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
573 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
574 check_type, num_args);
575 bundle_get_str(b, buf_key, &ret_val);
577 ret_variable_int = atoi(ret_val);
579 if (ret_variable_int ==
580 NOTIFICATION_COUNT_POS_LEFT) {
581 notification_get_count(noti->type,
582 noti->caller_pkgname,
586 snprintf(buf_str, sizeof(buf_str),
587 "%d ", ret_variable_int);
589 src_len = strlen(result_str);
590 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
592 strncat(result_str, buf_str,
598 /* Check variable IN pos */
599 for (temp_str = (char *)get_str; *temp_str != '\0';
601 if (*temp_str != '%') {
602 strncat(result_str, temp_str, 1);
604 if (*(temp_str + 1) == '%') {
605 strncat(result_str, temp_str,
607 } else if (*(temp_str + 1) == 'd') {
609 ret_variable_int = 0;
613 "%dtype%d", check_type,
615 bundle_get_str(b, buf_key, &ret_val);
617 ret_var_type = atoi(ret_val);
620 NOTIFICATION_VARIABLE_TYPE_COUNT) {
621 /* Get notification count */
622 notification_get_count(noti->type,
623 noti->caller_pkgname,
634 bundle_get_str(b, buf_key, &ret_val);
636 ret_variable_int = atoi(ret_val);
640 sizeof(buf_str), "%d",
643 src_len = strlen(result_str);
644 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
646 strncat(result_str, buf_str,
652 } else if (*(temp_str + 1) == 's') {
657 check_type, num_args);
658 bundle_get_str(b, buf_key, &ret_val);
660 if (ret_val != NULL && noti->domain != NULL && noti->dir != NULL) {
661 /* Get application string */
662 bindtextdomain(noti->domain, noti->dir);
663 translated_str = dgettext(noti->domain, ret_val);
664 NOTIFICATION_INFO("translated_str[%s]", translated_str);
665 } else if (ret_val != NULL) {
666 /* Get system string */
667 translated_str = dgettext("sys_string", ret_val);
668 NOTIFICATION_INFO("translated_str[%s]", translated_str);
670 translated_str = NULL;
673 if (translated_str != NULL) {
674 strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
675 src_len = strlen(result_str);
676 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
677 strncat(result_str, buf_str, max_len);
681 } else if (*(temp_str + 1) == 'f') {
686 check_type, num_args);
687 bundle_get_str(b, buf_key, &ret_val);
689 ret_variable_double = atof(ret_val);
694 ret_variable_double);
696 src_len = strlen(result_str);
697 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
698 strncat(result_str, buf_str, max_len);
702 } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
703 if (*(temp_str + 3) == 'd') {
705 ret_variable_int = 0;
709 "%dtype%d", check_type,
710 num_args + *(temp_str + 1) - 49);
711 bundle_get_str(b, buf_key, &ret_val);
713 ret_var_type = atoi(ret_val);
716 NOTIFICATION_VARIABLE_TYPE_COUNT) {
717 /* Get notification count */
718 notification_get_count(noti->type,
719 noti->caller_pkgname,
730 num_args + *(temp_str + 1) - 49);
731 bundle_get_str(b, buf_key, &ret_val);
733 ret_variable_int = atoi(ret_val);
738 sizeof(buf_str), "%d",
741 src_len = strlen(result_str);
742 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
744 strncat(result_str, buf_str, max_len);
747 } else if (*(temp_str + 3) == 's') {
752 check_type, num_args + *(temp_str + 1) - 49);
753 bundle_get_str(b, buf_key, &ret_val);
756 sizeof(buf_str), "%s",
759 src_len = strlen(result_str);
760 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
762 strncat(result_str, buf_str, max_len);
765 } else if (*(temp_str + 3) == 'f') {
770 check_type, num_args + *(temp_str + 1) - 49);
771 bundle_get_str(b, buf_key, &ret_val);
773 ret_variable_double = atof(ret_val);
778 ret_variable_double);
780 src_len = strlen(result_str);
781 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
783 strncat(result_str, buf_str, max_len);
792 /* Check last variable is count, LEFT pos */
793 if (num_args < noti->num_format_args) {
794 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
795 check_type, num_args);
796 bundle_get_str(b, buf_key, &ret_val);
798 ret_var_type = atoi(ret_val);
801 NOTIFICATION_VARIABLE_TYPE_COUNT) {
803 snprintf(buf_key, sizeof(buf_key),
804 "%dvalue%d", check_type,
806 bundle_get_str(b, buf_key, &ret_val);
808 ret_variable_int = atoi(ret_val);
810 if (ret_variable_int ==
811 NOTIFICATION_COUNT_POS_RIGHT) {
812 notification_get_count(noti->type,
813 noti->caller_pkgname,
818 sizeof(buf_str), " %d",
821 src_len = strlen(result_str);
822 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
824 strncat(result_str, buf_str, max_len);
832 switch (check_type) {
833 case NOTIFICATION_TEXT_TYPE_TITLE:
834 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
835 if (noti->temp_title != NULL)
836 free(noti->temp_title);
838 noti->temp_title = strdup(result_str);
840 *text = noti->temp_title;
842 case NOTIFICATION_TEXT_TYPE_CONTENT:
843 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
844 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
845 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
846 if (noti->temp_content !=
848 free(noti->temp_content);
850 noti->temp_content = strdup(result_str);
852 *text = noti->temp_content;
864 return NOTIFICATION_ERROR_NONE;
867 EXPORT_API int notification_set_text_domain(notification_h noti,
871 /* check noti and domain is valid data */
872 if (noti == NULL || domain == NULL || dir == NULL)
873 return NOTIFICATION_ERROR_INVALID_PARAMETER;
877 /* Remove previous domain */
881 noti->domain = strdup(domain);
883 /* Check locale dir */
885 /* Remove previous locale dir */
888 /* Copy locale dir */
889 noti->dir = strdup(dir);
891 return NOTIFICATION_ERROR_NONE;
894 EXPORT_API int notification_get_text_domain(notification_h noti,
898 /* Check noti is valid data */
900 return NOTIFICATION_ERROR_INVALID_PARAMETER;
903 if (domain != NULL && noti->domain != NULL)
904 *domain = noti->domain;
907 if (dir != NULL && noti->dir != NULL)
910 return NOTIFICATION_ERROR_NONE;
913 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
916 int ret = NOTIFICATION_ERROR_NONE;
917 char buf[256] = { 0, };
918 char buf_tag[512] = { 0, };
921 return NOTIFICATION_ERROR_INVALID_PARAMETER;
924 return NOTIFICATION_ERROR_INVALID_PARAMETER;
926 if (type <= NOTIFICATION_TEXT_TYPE_NONE
927 || type >= NOTIFICATION_TEXT_TYPE_MAX)
928 return NOTIFICATION_ERROR_INVALID_PARAMETER;
931 snprintf(buf, sizeof(buf), "%lu", time);
932 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
934 if (ret != NOTIFICATION_ERROR_NONE)
937 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
940 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
943 int ret = NOTIFICATION_ERROR_NONE;
944 char *ret_text = NULL;
948 return NOTIFICATION_ERROR_INVALID_PARAMETER;
951 return NOTIFICATION_ERROR_INVALID_PARAMETER;
953 if (type <= NOTIFICATION_TEXT_TYPE_NONE
954 || type >= NOTIFICATION_TEXT_TYPE_MAX)
955 return NOTIFICATION_ERROR_INVALID_PARAMETER;
957 ret = notification_get_text(noti, type, &ret_text);
959 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL)
960 return NOTIFICATION_ERROR_INVALID_PARAMETER;
962 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID)
963 return NOTIFICATION_ERROR_INVALID_PARAMETER;
965 tag_value = notification_noti_strip_tag(ret_text);
966 if (tag_value == NULL)
967 return NOTIFICATION_ERROR_INVALID_PARAMETER;
969 *time = atol(tag_value);
972 return NOTIFICATION_ERROR_NONE;
975 EXPORT_API int notification_set_sound(notification_h noti,
976 notification_sound_type_e type,
979 /* Check noti is valid data */
981 return NOTIFICATION_ERROR_INVALID_PARAMETER;
984 /* Check type is valid */
985 if (type < NOTIFICATION_SOUND_TYPE_NONE
986 || type >= NOTIFICATION_SOUND_TYPE_MAX)
987 return NOTIFICATION_ERROR_INVALID_PARAMETER;
989 /* Save sound type */
990 noti->sound_type = type;
992 /* Save sound path if user data type */
993 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
994 if (noti->sound_path != NULL)
995 free(noti->sound_path);
997 noti->sound_path = strdup(path);
999 if (noti->sound_path != NULL) {
1000 free(noti->sound_path);
1001 noti->sound_path = NULL;
1003 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1004 noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1005 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1009 return NOTIFICATION_ERROR_NONE;
1012 EXPORT_API int notification_get_sound(notification_h noti,
1013 notification_sound_type_e *type,
1016 /* check noti and type is valid data */
1017 if (noti == NULL || type == NULL)
1018 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1020 /* Set sound type */
1021 *type = noti->sound_type;
1023 /* Set sound path if user data type */
1024 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1026 *path = noti->sound_path;
1028 return NOTIFICATION_ERROR_NONE;
1031 EXPORT_API int notification_set_vibration(notification_h noti,
1032 notification_vibration_type_e type,
1035 /* Check noti is valid data */
1037 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1039 /* Check type is valid */
1040 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1041 || type >= NOTIFICATION_VIBRATION_TYPE_MAX)
1042 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1044 /* Save vibration type */
1045 noti->vibration_type = type;
1047 /* Save sound path if user data type */
1048 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1049 if (noti->vibration_path != NULL)
1050 free(noti->vibration_path);
1052 noti->vibration_path = strdup(path);
1054 if (noti->vibration_path != NULL) {
1055 free(noti->vibration_path);
1056 noti->vibration_path = NULL;
1058 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1059 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1060 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1064 return NOTIFICATION_ERROR_NONE;
1068 EXPORT_API int notification_get_vibration(notification_h noti,
1069 notification_vibration_type_e *type,
1072 /* check noti and type is valid data */
1073 if (noti == NULL || type == NULL)
1074 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1076 /* Set vibration type */
1077 *type = noti->vibration_type;
1079 /* Set sound path if user data type */
1080 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1082 *path = noti->vibration_path;
1084 return NOTIFICATION_ERROR_NONE;
1087 EXPORT_API int notification_set_led(notification_h noti,
1088 notification_led_op_e operation,
1091 /* Check noti is valid data */
1093 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1095 /* Check operation is valid */
1096 if (operation < NOTIFICATION_LED_OP_OFF
1097 || operation >= NOTIFICATION_LED_OP_MAX)
1098 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1100 /* Save led operation */
1101 noti->led_operation = operation;
1103 /* Save led argb if operation is turning on LED with custom color */
1104 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR)
1105 noti->led_argb = led_argb;
1107 return NOTIFICATION_ERROR_NONE;
1110 EXPORT_API int notification_get_led(notification_h noti,
1111 notification_led_op_e *operation,
1114 /* check noti and operation is valid data */
1115 if (noti == NULL || operation == NULL)
1116 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1118 /* Set led operation */
1119 *operation = noti->led_operation;
1121 /* Save led argb if operation is turning on LED with custom color */
1122 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1123 && led_argb != NULL)
1124 *led_argb = noti->led_argb;
1126 return NOTIFICATION_ERROR_NONE;
1129 EXPORT_API int notification_set_led_time_period(notification_h noti,
1130 int on_ms, int off_ms)
1132 /* Check noti is valid data */
1133 if (noti == NULL || on_ms < 0 || off_ms < 0)
1134 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1136 /* Save led operation */
1137 noti->led_on_ms = on_ms;
1138 noti->led_off_ms = off_ms;
1140 return NOTIFICATION_ERROR_NONE;
1143 EXPORT_API int notification_get_led_time_period(notification_h noti,
1144 int *on_ms, int *off_ms)
1146 /* check noti and operation is valid data */
1148 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1151 *(on_ms) = noti->led_on_ms;
1153 *(off_ms) = noti->led_off_ms;
1155 return NOTIFICATION_ERROR_NONE;
1158 EXPORT_API int notification_set_launch_option(notification_h noti,
1159 notification_launch_option_type type, void *option)
1161 int err = NOTIFICATION_ERROR_NONE;
1164 app_control_h app_control = option;
1166 if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1167 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1171 if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1172 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1173 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1177 err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1186 EXPORT_API int notification_get_launch_option(notification_h noti,
1187 notification_launch_option_type type, void *option)
1191 app_control_h *app_control = (app_control_h *)option;
1192 app_control_h app_control_new = NULL;
1195 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1197 if (app_control == NULL)
1198 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1200 if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL)
1201 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1204 ret = notification_get_execute_option(noti,
1205 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1208 if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1209 ret = app_control_create(&app_control_new);
1210 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1211 ret = app_control_import_from_bundle(app_control_new, b);
1212 if (ret == APP_CONTROL_ERROR_NONE) {
1213 *app_control = app_control_new;
1215 app_control_destroy(app_control_new);
1216 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1217 return NOTIFICATION_ERROR_IO_ERROR;
1220 NOTIFICATION_ERR("Failed to create app control:%d", ret);
1221 return NOTIFICATION_ERROR_IO_ERROR;
1224 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1228 return NOTIFICATION_ERROR_NONE;
1231 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1233 int err = NOTIFICATION_ERROR_NONE;
1234 bundle *app_control_bundle = NULL;
1237 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1238 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1242 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1243 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1244 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1245 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1249 if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1250 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1254 if (noti->b_event_handler[event_type] != NULL)
1255 bundle_free(noti->b_event_handler[event_type]);
1257 noti->b_event_handler[event_type] = app_control_bundle;
1263 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1265 int err = NOTIFICATION_ERROR_NONE;
1267 app_control_h app_control_new = NULL;
1270 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1271 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1274 if (event_handler == NULL) {
1275 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1276 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1279 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1280 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1281 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1282 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1286 b = noti->b_event_handler[event_type];
1289 NOTIFICATION_DBG("No event handler\n");
1290 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1294 err = app_control_create(&app_control_new);
1295 if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1296 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1297 err = NOTIFICATION_ERROR_IO_ERROR;
1301 err = app_control_import_from_bundle(app_control_new, b);
1302 if (err == APP_CONTROL_ERROR_NONE) {
1303 *event_handler = app_control_new;
1305 app_control_destroy(app_control_new);
1306 app_control_new = NULL;
1307 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1308 err = NOTIFICATION_ERROR_IO_ERROR;
1314 *event_handler = app_control_new;
1323 EXPORT_API int notification_set_property(notification_h noti,
1326 /* Check noti is valid data */
1328 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1331 noti->flags_for_property = flags;
1333 return NOTIFICATION_ERROR_NONE;
1336 EXPORT_API int notification_get_property(notification_h noti,
1339 /* Check noti and flags are valid data */
1340 if (noti == NULL || flags == NULL)
1341 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1344 *flags = noti->flags_for_property;
1346 return NOTIFICATION_ERROR_NONE;
1349 EXPORT_API int notification_set_display_applist(notification_h noti,
1352 /* Check noti is valid data */
1354 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1358 if (applist == 0xffffffff) /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1359 applist = NOTIFICATION_DISPLAY_APP_ALL;
1361 noti->display_applist = applist;
1363 return NOTIFICATION_ERROR_NONE;
1366 EXPORT_API int notification_get_display_applist(notification_h noti,
1369 /* Check noti and applist are valid data */
1370 if (noti == NULL || applist == NULL)
1371 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1374 *applist = noti->display_applist;
1376 return NOTIFICATION_ERROR_NONE;
1379 EXPORT_API int notification_set_size(notification_h noti,
1382 /* Check noti is valid data */
1384 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1386 /* Save progress size */
1387 noti->progress_size = size;
1389 return NOTIFICATION_ERROR_NONE;
1392 EXPORT_API int notification_get_size(notification_h noti,
1395 /* Check noti and size is valid data */
1396 if (noti == NULL || size == NULL)
1397 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1399 /* Set progress size */
1400 *size = noti->progress_size;
1402 return NOTIFICATION_ERROR_NONE;
1405 EXPORT_API int notification_set_progress(notification_h noti,
1408 /* Check noti is valid data */
1410 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1412 /* Save progress percentage */
1413 noti->progress_percentage = percentage;
1415 return NOTIFICATION_ERROR_NONE;
1418 EXPORT_API int notification_get_progress(notification_h noti,
1421 /* Check noti and percentage are valid data */
1422 if (noti == NULL || percentage == NULL)
1423 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1425 /* Set progress percentage */
1426 *percentage = noti->progress_percentage;
1428 return NOTIFICATION_ERROR_NONE;
1431 EXPORT_API int notification_get_pkgname(notification_h noti,
1434 /* Check noti and pkgname are valid data */
1435 if (noti == NULL || pkgname == NULL)
1436 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1438 /* Get caller pkgname */
1439 if (noti->caller_pkgname)
1440 *pkgname = noti->caller_pkgname;
1444 return NOTIFICATION_ERROR_NONE;
1447 EXPORT_API int notification_set_layout(notification_h noti,
1448 notification_ly_type_e layout)
1450 /* check noti and pkgname are valid data */
1451 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX))
1452 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1454 noti->layout = layout;
1456 return NOTIFICATION_ERROR_NONE;
1459 EXPORT_API int notification_get_layout(notification_h noti,
1460 notification_ly_type_e *layout)
1462 /* Check noti and pkgname are valid data */
1463 if (noti == NULL || layout == NULL)
1464 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1466 *layout = noti->layout;
1468 return NOTIFICATION_ERROR_NONE;
1473 EXPORT_API int notification_get_type(notification_h noti,
1474 notification_type_e *type)
1476 /* Check noti and type is valid data */
1477 if (noti == NULL || type == NULL)
1478 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1483 return NOTIFICATION_ERROR_NONE;
1486 EXPORT_API int notification_post(notification_h noti)
1491 /* Check noti is vaild data */
1493 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1495 /* Check noti type is valid type */
1496 if (noti->type <= NOTIFICATION_TYPE_NONE
1497 || noti->type >= NOTIFICATION_TYPE_MAX)
1498 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1500 /* Save insert time */
1501 noti->insert_time = time(NULL);
1503 ret = notification_ipc_request_insert(noti, &id);
1504 if (ret != NOTIFICATION_ERROR_NONE)
1508 NOTIFICATION_DBG("from master:%d", id);
1510 return NOTIFICATION_ERROR_NONE;
1515 EXPORT_API int notification_update(notification_h noti)
1519 /* Check noti is valid data */
1521 /* Update insert time ? */
1522 noti->insert_time = time(NULL);
1523 ret = notification_ipc_request_update(noti);
1525 notification_ipc_request_refresh();
1526 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1531 EXPORT_API int notification_delete_all(notification_type_e type)
1534 char *caller_pkgname = NULL;
1536 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX)
1537 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1539 caller_pkgname = notification_get_pkgname_by_pid();
1541 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1544 free(caller_pkgname);
1549 EXPORT_API int notification_delete(notification_h noti)
1554 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1556 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1561 static notification_h _notification_create(notification_type_e type)
1563 notification_h noti = NULL;
1564 package_info_h package_info = NULL;
1565 char *app_id = NULL;
1566 char *domain_name = NULL;
1567 char *app_root_path = NULL;
1568 char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1569 int err_app_manager = APP_MANAGER_ERROR_NONE;
1571 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1572 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1573 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1577 noti = (notification_h) calloc(1, sizeof(struct _notification));
1579 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1580 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1586 if (type == NOTIFICATION_TYPE_NOTI)
1587 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1588 else if (type == NOTIFICATION_TYPE_ONGOING)
1589 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1591 noti->caller_pkgname = notification_get_pkgname_by_pid();
1592 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1593 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1594 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1595 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1596 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1597 noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1598 noti->auto_remove = true;
1600 err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1601 if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1602 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]", err_app_manager, app_id);
1606 /* app name is used as domain name */
1607 /* domain_name is allocated by app_get_package_app_name */
1608 err_app_manager = app_get_package_app_name(app_id, &domain_name);
1610 if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1611 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]", err_app_manager, domain_name);
1615 err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1617 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1618 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p] caller_pkgname[%s]",
1619 err_app_manager, package_info, noti->caller_pkgname);
1623 err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1625 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1626 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]", err_app_manager, app_root_path);
1630 snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1632 noti->domain = strdup(domain_name);
1633 noti->dir = strdup(locale_directory);
1643 free(app_root_path);
1646 package_info_destroy(package_info);
1650 * Other fields are already initialized with ZERO.
1652 set_last_result(NOTIFICATION_ERROR_NONE);
1656 EXPORT_API notification_h notification_create(notification_type_e type)
1658 return _notification_create(type);
1661 EXPORT_API notification_h notification_load_by_tag(const char *tag)
1664 notification_h noti = NULL;
1665 char *caller_pkgname = NULL;
1668 NOTIFICATION_ERR("Invalid parameter");
1669 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1673 caller_pkgname = notification_get_pkgname_by_pid();
1674 if (!caller_pkgname) {
1675 NOTIFICATION_ERR("Failed to get a package name");
1676 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1680 noti = (notification_h)calloc(1, sizeof(struct _notification));
1682 NOTIFICATION_ERR("Failed to alloc a new notification");
1683 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1684 free(caller_pkgname);
1689 ret = notification_ipc_request_load_noti_by_tag(noti, caller_pkgname, (char *)tag);
1690 free(caller_pkgname);
1692 set_last_result(ret);
1693 if (ret != NOTIFICATION_ERROR_NONE) {
1694 notification_free(noti);
1701 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1704 notification_h new_noti = NULL;
1706 if (noti == NULL || clone == NULL) {
1707 NOTIFICATION_ERR("INVALID PARAMETER.");
1708 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1711 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1712 if (new_noti == NULL) {
1713 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1714 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1717 new_noti->type = noti->type;
1718 new_noti->layout = noti->layout;
1720 new_noti->group_id = noti->group_id;
1721 new_noti->internal_group_id = noti->internal_group_id;
1722 new_noti->priv_id = noti->priv_id;
1724 if (noti->caller_pkgname != NULL)
1725 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1727 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1729 if (noti->launch_pkgname != NULL)
1730 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1732 new_noti->launch_pkgname = NULL;
1734 if (noti->args != NULL)
1735 new_noti->args = bundle_dup(noti->args);
1737 new_noti->args = NULL;
1739 if (noti->group_args != NULL)
1740 new_noti->group_args = bundle_dup(noti->group_args);
1742 new_noti->group_args = NULL;
1744 if (noti->b_execute_option != NULL)
1745 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1747 new_noti->b_execute_option = NULL;
1749 if (noti->b_service_responding != NULL)
1750 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1752 new_noti->b_service_responding = NULL;
1754 if (noti->b_service_single_launch != NULL)
1755 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1757 new_noti->b_service_single_launch = NULL;
1759 if (noti->b_service_multi_launch != NULL)
1760 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1762 new_noti->b_service_multi_launch = NULL;
1764 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1765 if (noti->b_event_handler[i] != NULL)
1766 new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1768 new_noti->b_event_handler[i] = NULL;
1771 new_noti->sound_type = noti->sound_type;
1772 if (noti->sound_path != NULL)
1773 new_noti->sound_path = strdup(noti->sound_path);
1775 new_noti->sound_path = NULL;
1777 new_noti->vibration_type = noti->vibration_type;
1778 if (noti->vibration_path != NULL)
1779 new_noti->vibration_path = strdup(noti->vibration_path);
1781 new_noti->vibration_path = NULL;
1783 new_noti->led_operation = noti->led_operation;
1784 new_noti->led_argb = noti->led_argb;
1785 new_noti->led_on_ms = noti->led_on_ms;
1786 new_noti->led_off_ms = noti->led_off_ms;
1788 if (noti->domain != NULL)
1789 new_noti->domain = strdup(noti->domain);
1791 new_noti->domain = NULL;
1793 if (noti->dir != NULL)
1794 new_noti->dir = strdup(noti->dir);
1796 new_noti->dir = NULL;
1798 if (noti->b_text != NULL)
1799 new_noti->b_text = bundle_dup(noti->b_text);
1801 new_noti->b_text = NULL;
1803 if (noti->b_key != NULL)
1804 new_noti->b_key = bundle_dup(noti->b_key);
1806 new_noti->b_key = NULL;
1808 if (noti->b_format_args != NULL)
1809 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1811 new_noti->b_format_args = NULL;
1813 new_noti->num_format_args = noti->num_format_args;
1815 if (noti->b_image_path != NULL)
1816 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1818 new_noti->b_image_path = NULL;
1820 new_noti->time = noti->time;
1821 new_noti->insert_time = noti->insert_time;
1823 new_noti->flags_for_property = noti->flags_for_property;
1824 new_noti->display_applist = noti->display_applist;
1826 new_noti->progress_size = noti->progress_size;
1827 new_noti->progress_percentage = noti->progress_percentage;
1829 new_noti->ongoing_flag = noti->ongoing_flag;
1830 new_noti->auto_remove = noti->auto_remove;
1832 new_noti->app_icon_path = NULL;
1833 new_noti->app_name = NULL;
1834 new_noti->temp_title = NULL;
1835 new_noti->temp_content = NULL;
1839 return NOTIFICATION_ERROR_NONE;
1843 EXPORT_API int notification_free(notification_h noti)
1847 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1849 if (noti->caller_pkgname)
1850 free(noti->caller_pkgname);
1852 if (noti->launch_pkgname)
1853 free(noti->launch_pkgname);
1856 bundle_free(noti->args);
1858 if (noti->group_args)
1859 bundle_free(noti->group_args);
1861 if (noti->b_execute_option)
1862 bundle_free(noti->b_execute_option);
1864 if (noti->b_service_responding)
1865 bundle_free(noti->b_service_responding);
1867 if (noti->b_service_single_launch)
1868 bundle_free(noti->b_service_single_launch);
1870 if (noti->b_service_multi_launch)
1871 bundle_free(noti->b_service_multi_launch);
1873 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1874 if (noti->b_event_handler[i] != NULL)
1875 bundle_free(noti->b_event_handler[i]);
1878 if (noti->sound_path)
1879 free(noti->sound_path);
1881 if (noti->vibration_path)
1882 free(noti->vibration_path);
1891 bundle_free(noti->b_text);
1894 bundle_free(noti->b_key);
1896 if (noti->b_format_args)
1897 bundle_free(noti->b_format_args);
1899 if (noti->b_image_path)
1900 bundle_free(noti->b_image_path);
1902 if (noti->app_icon_path)
1903 free(noti->app_icon_path);
1906 free(noti->app_name);
1908 if (noti->temp_title)
1909 free(noti->temp_title);
1911 if (noti->temp_content)
1912 free(noti->temp_content);
1919 return NOTIFICATION_ERROR_NONE;
1922 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
1924 /* Check noti is valid data */
1926 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1929 /* save input TAG */
1930 if (noti->tag != NULL)
1933 noti->tag = strdup(tag);
1936 return NOTIFICATION_ERROR_NONE;
1940 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
1942 /* Check noti is valid data */
1944 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1947 return NOTIFICATION_ERROR_NONE;
1950 void notification_call_posted_toast_cb(const char *message)
1952 if (posted_toast_message_cb != NULL)
1953 posted_toast_message_cb((void *)message);
1956 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
1959 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1961 noti->ongoing_flag = ongoing_flag;
1963 return NOTIFICATION_ERROR_NONE;
1966 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
1968 if (noti == NULL || ongoing_flag == NULL)
1969 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1971 *ongoing_flag = noti->ongoing_flag;
1973 return NOTIFICATION_ERROR_NONE;
1977 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
1979 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
1980 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1982 return NOTIFICATION_ERROR_NONE;
1985 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
1987 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
1988 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1990 if (noti->b_event_handler[button_index - 1]) {
1991 bundle_free(noti->b_event_handler[button_index - 1]);
1992 noti->b_event_handler[button_index - 1] = NULL;
1995 return NOTIFICATION_ERROR_NONE;
1998 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
2001 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2003 noti->auto_remove = auto_remove;
2005 return NOTIFICATION_ERROR_NONE;
2008 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
2010 if (noti == NULL || auto_remove == NULL)
2011 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2013 *auto_remove = noti->auto_remove;
2015 return NOTIFICATION_ERROR_NONE;