4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include <dbus/dbus.h>
29 #include <dbus/dbus-glib-lowlevel.h>
32 #include <app_internal.h>
33 #include <app_manager.h>
34 #include <app_control_internal.h>
35 #include <package_manager.h>
40 #include <vconf-keys.h>
43 #include <notification.h>
44 #include <notification_list.h>
45 #include <notification_debug.h>
46 #include <notification_private.h>
47 #include <notification_noti.h>
48 #include <notification_ongoing.h>
49 #include <notification_group.h>
50 #include <notification_ipc.h>
51 #include <notification_internal.h>
53 static void (*posted_toast_message_cb) (void *data);
55 #define NOTI_TEXT_RESULT_LEN 2048
56 #define NOTI_PKGNAME_LEN 512
58 char *notification_get_pkgname_by_pid(void)
60 char pkgname[NOTI_PKGNAME_LEN + 1] = { 0, };
61 int pid = 0, ret = AUL_R_OK;
67 ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
68 if (ret != AUL_R_OK) {
69 char buf[NOTI_PKGNAME_LEN + 1] = { 0, };
71 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
73 fd = open(buf, O_RDONLY);
78 ret = read(fd, pkgname, sizeof(pkgname) - 1);
88 * "ret" is not able to be larger than "sizeof(pkgname) - 1",
89 * if the system is not going wrong.
92 if (strlen(pkgname) <= 0) {
97 dup_pkgname = strdup(pkgname);
99 NOTIFICATION_ERR("Heap: %d\n", errno);
104 EXPORT_API int notification_set_image(notification_h noti,
105 notification_image_type_e type,
106 const char *image_path)
109 char buf_key[32] = { 0, };
110 char *ret_val = NULL;
112 /* Check noti and image_path are valid data */
113 if (noti == NULL || image_path == NULL) {
114 return NOTIFICATION_ERROR_INVALID_PARAMETER;
117 /* Check image type is valid type */
118 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
119 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
120 return NOTIFICATION_ERROR_INVALID_PARAMETER;
123 /* Check image path bundle is exist */
124 if (noti->b_image_path) {
125 /* If image path bundle is exist, store local bundle value */
126 b = noti->b_image_path;
128 /* Set image type to key as char string type */
129 snprintf(buf_key, sizeof(buf_key), "%d", type);
131 /* Get value using key */
132 bundle_get_str(b, buf_key, &ret_val);
133 if (ret_val != NULL) {
134 /* If key is exist, remove this value to store new image path */
135 bundle_del(b, buf_key);
138 /* Add new image path with type key */
139 bundle_add_str(b, buf_key, image_path);
141 /* If image path bundle is not exist, create new one */
144 /* Set image type to key as char string type */
145 snprintf(buf_key, sizeof(buf_key), "%d", type);
147 /* Add new image path with type key */
148 bundle_add_str(b, buf_key, image_path);
150 /* Save to image path bundle */
151 noti->b_image_path = b;
154 return NOTIFICATION_ERROR_NONE;
157 EXPORT_API int notification_get_image(notification_h noti,
158 notification_image_type_e type,
162 char buf_key[32] = { 0, };
163 char *ret_val = NULL;
165 /* Check noti and image_path is valid data */
166 if (noti == NULL || image_path == NULL) {
167 return NOTIFICATION_ERROR_INVALID_PARAMETER;
170 /* Check image type is valid data */
171 if (type <= NOTIFICATION_IMAGE_TYPE_NONE
172 || type >= NOTIFICATION_IMAGE_TYPE_MAX) {
173 return NOTIFICATION_ERROR_INVALID_PARAMETER;
176 /* Check image path bundle exist */
177 if (noti->b_image_path) {
178 /* If image path bundle exist, store local bundle data */
179 b = noti->b_image_path;
181 /* Set image type to key as char string type */
182 snprintf(buf_key, sizeof(buf_key), "%d", type);
184 /* Get value of key */
185 bundle_get_str(b, buf_key, &ret_val);
187 *image_path = ret_val;
189 /* If image path bundle does not exist, image path is NULL */
193 /* If image path is NULL and type is ICON, icon path set from AIL */
194 /* order : user icon -> launch_pkgname icon -> caller_pkgname icon -> service app icon */
195 if (*image_path == NULL && type == NOTIFICATION_IMAGE_TYPE_ICON) {
196 /* Check App icon path is already set */
197 if (noti->app_icon_path != NULL) {
198 /* image path will be app icon path */
199 *image_path = noti->app_icon_path;
205 return NOTIFICATION_ERROR_NONE;
208 EXPORT_API int notification_set_time(notification_h noti,
211 /* Check noti is valid data */
213 return NOTIFICATION_ERROR_INVALID_PARAMETER;
216 if (input_time == 0) {
217 /* If input time is 0, set current time */
218 noti->time = time(NULL);
220 /* save input time */
221 noti->time = input_time;
224 return NOTIFICATION_ERROR_NONE;
227 EXPORT_API int notification_get_time(notification_h noti,
230 /* Check noti and time is valid data */
231 if (noti == NULL || ret_time == NULL) {
232 return NOTIFICATION_ERROR_INVALID_PARAMETER;
235 /* Set time infomation */
236 *ret_time = noti->time;
238 return NOTIFICATION_ERROR_NONE;
241 EXPORT_API int notification_get_insert_time(notification_h noti,
244 /* Check noti and ret_time is valid data */
245 if (noti == NULL || ret_time == NULL) {
246 return NOTIFICATION_ERROR_INVALID_PARAMETER;
249 /* Set insert time information */
250 *ret_time = noti->insert_time;
252 return NOTIFICATION_ERROR_NONE;
255 EXPORT_API int notification_set_text(notification_h noti,
256 notification_text_type_e type,
262 char buf_key[32] = { 0, };
263 char buf_val[1024] = { 0, };
264 char *ret_val = NULL;
266 notification_variable_type_e var_type;
268 int noti_err = NOTIFICATION_ERROR_NONE;
269 int var_value_int = 0;
270 double var_value_double = 0.0;
271 char *var_value_string = NULL;
272 notification_count_pos_type_e var_value_count =
273 NOTIFICATION_COUNT_POS_NONE;
275 /* Check noti is valid data */
277 return NOTIFICATION_ERROR_INVALID_PARAMETER;
280 /* Check text type is valid type */
281 if (type <= NOTIFICATION_TEXT_TYPE_NONE
282 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
283 return NOTIFICATION_ERROR_INVALID_PARAMETER;
286 /* Check text bundle exist */
288 if (noti->b_text != NULL) {
289 /* If text bundle exist, store local bundle data */
292 /* Make type to key as char string */
293 snprintf(buf_key, sizeof(buf_key), "%d", type);
295 /* Get value using type key */
296 bundle_get_str(b, buf_key, &ret_val);
297 if (ret_val != NULL) {
298 /* If value exist, remove this to add new value */
299 bundle_del(b, buf_key);
302 snprintf(buf_val, sizeof(buf_val), "%s", text);
304 /* Add new text value */
305 bundle_add_str(b, buf_key, buf_val);
307 /* If text bundle does not exist, create new one */
310 /* Make type to key as char string */
311 snprintf(buf_key, sizeof(buf_key), "%d", type);
313 snprintf(buf_val, sizeof(buf_val), "%s", text);
315 /* Add new text value */
316 bundle_add_str(b, buf_key, buf_val);
318 /* Save text bundle */
322 /* Reset if text is NULL */
323 if (noti->b_text != NULL) {
324 /* If text bundle exist, store local bundle data */
327 /* Make type to key as char string */
328 snprintf(buf_key, sizeof(buf_key), "%d", type);
330 /* Get value using type key */
331 bundle_get_str(b, buf_key, &ret_val);
332 if (ret_val != NULL) {
333 /* If value exist, remove this */
334 bundle_del(b, buf_key);
339 /* Save key if key is valid data */
341 /* Check key bundle exist */
342 if (noti->b_key != NULL) {
343 /* If key bundle exist, store local bundle data */
346 /* Make type to key as char string */
347 snprintf(buf_key, sizeof(buf_key), "%d", type);
349 /* Get value using type key */
350 bundle_get_str(b, buf_key, &ret_val);
351 if (ret_val != NULL) {
352 /* If value exist, remove this to add new value */
353 bundle_del(b, buf_key);
356 snprintf(buf_val, sizeof(buf_val), "%s", key);
358 /* Add new key value */
359 bundle_add_str(b, buf_key, buf_val);
361 /* If key bundle does not exist, create new one */
364 /* Make type to key as char string */
365 snprintf(buf_key, sizeof(buf_key), "%d", type);
367 snprintf(buf_val, sizeof(buf_val), "%s", key);
369 /* Add new key value */
370 bundle_add_str(b, buf_key, buf_val);
372 /* Save key bundle */
376 /* Reset if key is NULL */
377 if (noti->b_key != NULL) {
378 /* If key bundle exist, store local bundle data */
381 /* Make type to key as char string */
382 snprintf(buf_key, sizeof(buf_key), "%d", type);
384 /* Get value using type key */
385 bundle_get_str(b, buf_key, &ret_val);
386 if (ret_val != NULL) {
387 /* If value exist, remove this */
388 bundle_del(b, buf_key);
393 if (noti->b_format_args != NULL) {
394 b = noti->b_format_args;
399 va_start(var_args, args_type);
401 var_type = args_type;
404 while (var_type != NOTIFICATION_VARIABLE_TYPE_NONE) {
406 snprintf(buf_key, sizeof(buf_key), "%dtype%d", type, num_args);
407 snprintf(buf_val, sizeof(buf_val), "%d", var_type);
409 bundle_get_str(b, buf_key, &ret_val);
410 if (ret_val != NULL) {
411 bundle_del(b, buf_key);
414 bundle_add_str(b, buf_key, buf_val);
417 case NOTIFICATION_VARIABLE_TYPE_INT:
418 var_value_int = va_arg(var_args, int);
421 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
423 snprintf(buf_val, sizeof(buf_val), "%d", var_value_int);
425 bundle_get_str(b, buf_key, &ret_val);
426 if (ret_val != NULL) {
427 bundle_del(b, buf_key);
430 bundle_add_str(b, buf_key, buf_val);
432 case NOTIFICATION_VARIABLE_TYPE_DOUBLE:
433 var_value_double = va_arg(var_args, double);
436 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
438 snprintf(buf_val, sizeof(buf_val), "%.2f",
441 bundle_get_str(b, buf_key, &ret_val);
442 if (ret_val != NULL) {
443 bundle_del(b, buf_key);
446 bundle_add_str(b, buf_key, buf_val);
448 case NOTIFICATION_VARIABLE_TYPE_STRING:
449 var_value_string = va_arg(var_args, char *);
452 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
454 snprintf(buf_val, sizeof(buf_val), "%s",
457 bundle_get_str(b, buf_key, &ret_val);
458 if (ret_val != NULL) {
459 bundle_del(b, buf_key);
462 bundle_add_str(b, buf_key, buf_val);
464 case NOTIFICATION_VARIABLE_TYPE_COUNT:
466 va_arg(var_args, notification_count_pos_type_e);
469 snprintf(buf_key, sizeof(buf_key), "%dvalue%d", type,
471 snprintf(buf_val, sizeof(buf_val), "%d",
474 bundle_get_str(b, buf_key, &ret_val);
475 if (ret_val != NULL) {
476 bundle_del(b, buf_key);
479 bundle_add_str(b, buf_key, buf_val);
482 NOTIFICATION_ERR("Error. invalid variable type. : %d",
484 noti_err = NOTIFICATION_ERROR_INVALID_PARAMETER;
489 var_type = va_arg(var_args, notification_variable_type_e);
493 if (noti_err == NOTIFICATION_ERROR_NONE) {
494 noti->num_format_args = num_args;
496 noti->num_format_args = 0;
499 snprintf(buf_key, sizeof(buf_key), "num%d", type);
500 snprintf(buf_val, sizeof(buf_val), "%d", noti->num_format_args);
502 bundle_get_str(b, buf_key, &ret_val);
503 if (ret_val != NULL) {
504 bundle_del(b, buf_key);
507 bundle_add_str(b, buf_key, buf_val);
509 noti->b_format_args = b;
514 EXPORT_API int notification_get_text(notification_h noti,
515 notification_text_type_e type,
519 char buf_key[32] = { 0, };
520 char *ret_val = NULL;
521 char *get_str = NULL;
522 notification_text_type_e check_type = NOTIFICATION_TEXT_TYPE_NONE;
523 //int display_option_flag = 0;
525 char *temp_str = NULL;
526 char *translated_str = NULL;
527 char result_str[NOTI_TEXT_RESULT_LEN] = { 0, };
528 char buf_str[1024] = { 0, };
530 notification_variable_type_e ret_var_type = 0;
531 int ret_variable_int = 0;
532 double ret_variable_double = 0.0;
536 /* Check noti is valid data */
537 if (noti == NULL || text == NULL) {
538 return NOTIFICATION_ERROR_INVALID_PARAMETER;
541 /* Check text type is valid type */
542 if (type <= NOTIFICATION_TEXT_TYPE_NONE
543 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
544 return NOTIFICATION_ERROR_INVALID_PARAMETER;
548 if (noti->b_key != NULL) {
551 /* Get text domain and dir */
552 //_notification_get_text_domain(noti);
554 snprintf(buf_key, sizeof(buf_key), "%d", type);
556 bundle_get_str(b, buf_key, &ret_val);
557 if (ret_val != NULL && noti->domain != NULL
558 && noti->dir != NULL) {
559 /* Get application string */
560 bindtextdomain(noti->domain, noti->dir);
562 get_str = dgettext(noti->domain, ret_val);
563 } else if (ret_val != NULL) {
564 /* Get system string */
565 get_str = dgettext("sys_string", ret_val);
571 if (get_str == NULL && noti->b_text != NULL) {
574 snprintf(buf_key, sizeof(buf_key), "%d", type);
576 bundle_get_str(b, buf_key, &get_str);
581 if (get_str != NULL) {
582 /* Get number format args */
583 b = noti->b_format_args;
584 noti->num_format_args = 0;
587 snprintf(buf_key, sizeof(buf_key), "num%d", check_type);
588 bundle_get_str(b, buf_key, &ret_val);
589 if (ret_val != NULL) {
590 noti->num_format_args = atoi(ret_val);
594 if (noti->num_format_args == 0) {
595 *text = (char *)get_str;
597 /* Check first variable is count, LEFT pos */
598 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
599 check_type, num_args);
600 bundle_get_str(b, buf_key, &ret_val);
601 if (ret_val != NULL) {
602 ret_var_type = atoi(ret_val);
605 if (ret_var_type == NOTIFICATION_VARIABLE_TYPE_COUNT) {
607 snprintf(buf_key, sizeof(buf_key), "%dvalue%d",
608 check_type, num_args);
609 bundle_get_str(b, buf_key, &ret_val);
610 if (ret_val != NULL) {
611 ret_variable_int = atoi(ret_val);
614 if (ret_variable_int ==
615 NOTIFICATION_COUNT_POS_LEFT) {
616 notification_noti_get_count(noti->type,
617 noti->caller_pkgname,
621 snprintf(buf_str, sizeof(buf_str),
622 "%d ", ret_variable_int);
624 src_len = strlen(result_str);
625 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
627 strncat(result_str, buf_str,
633 /* Check variable IN pos */
634 for (temp_str = (char *)get_str; *temp_str != '\0';
636 if (*temp_str != '%') {
637 strncat(result_str, temp_str, 1);
639 if (*(temp_str + 1) == '%') {
640 strncat(result_str, temp_str,
642 } else if (*(temp_str + 1) == 'd') {
644 ret_variable_int = 0;
648 "%dtype%d", check_type,
650 bundle_get_str(b, buf_key, &ret_val);
651 if (ret_val != NULL) {
652 ret_var_type = atoi(ret_val);
655 NOTIFICATION_VARIABLE_TYPE_COUNT) {
656 /* Get notification count */
657 notification_noti_get_count
659 noti->caller_pkgname,
670 bundle_get_str(b, buf_key, &ret_val);
671 if (ret_val != NULL) {
672 ret_variable_int = atoi(ret_val);
677 sizeof(buf_str), "%d",
680 src_len = strlen(result_str);
681 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
683 strncat(result_str, buf_str,
689 } else if (*(temp_str + 1) == 's') {
694 check_type, num_args);
695 bundle_get_str(b, buf_key, &ret_val);
697 if (ret_val != NULL && noti->domain != NULL && noti->dir != NULL) {
698 /* Get application string */
699 bindtextdomain(noti->domain, noti->dir);
700 translated_str = dgettext(noti->domain, ret_val);
701 NOTIFICATION_INFO("translated_str[%s]", translated_str);
702 } else if (ret_val != NULL) {
703 /* Get system string */
704 translated_str = dgettext("sys_string", ret_val);
705 NOTIFICATION_INFO("translated_str[%s]", translated_str);
707 translated_str = NULL;
710 if (translated_str != NULL) {
711 strncpy(buf_str, translated_str, sizeof(buf_str) - 1);
712 src_len = strlen(result_str);
713 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
714 strncat(result_str, buf_str, max_len);
718 } else if (*(temp_str + 1) == 'f') {
723 check_type, num_args);
724 bundle_get_str(b, buf_key, &ret_val);
725 if (ret_val != NULL) {
726 ret_variable_double = atof(ret_val);
732 ret_variable_double);
734 src_len = strlen(result_str);
735 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
736 strncat(result_str, buf_str, max_len);
740 } else if (*(temp_str + 1) >= '1' && *(temp_str + 1) <= '9') {
741 if (*(temp_str + 3) == 'd') {
743 ret_variable_int = 0;
747 "%dtype%d", check_type,
748 num_args + *(temp_str + 1) - 49);
749 bundle_get_str(b, buf_key, &ret_val);
750 if (ret_val != NULL) {
751 ret_var_type = atoi(ret_val);
754 NOTIFICATION_VARIABLE_TYPE_COUNT) {
755 /* Get notification count */
756 notification_noti_get_count
758 noti->caller_pkgname,
769 num_args + *(temp_str + 1) - 49);
770 bundle_get_str(b, buf_key, &ret_val);
771 if (ret_val != NULL) {
772 ret_variable_int = atoi(ret_val);
777 sizeof(buf_str), "%d",
780 src_len = strlen(result_str);
781 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
783 strncat(result_str, buf_str, max_len);
786 } else if (*(temp_str + 3) == 's') {
791 check_type, num_args + *(temp_str + 1) - 49);
792 bundle_get_str(b, buf_key, &ret_val);
795 sizeof(buf_str), "%s",
798 src_len = strlen(result_str);
799 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
801 strncat(result_str, buf_str, max_len);
804 } else if (*(temp_str + 3) == 'f') {
809 check_type, num_args + *(temp_str + 1) - 49);
810 bundle_get_str(b, buf_key, &ret_val);
811 if (ret_val != NULL) {
812 ret_variable_double = atof(ret_val);
818 ret_variable_double);
820 src_len = strlen(result_str);
821 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
823 strncat(result_str, buf_str, max_len);
832 /* Check last variable is count, LEFT pos */
833 if (num_args < noti->num_format_args) {
834 snprintf(buf_key, sizeof(buf_key), "%dtype%d",
835 check_type, num_args);
836 bundle_get_str(b, buf_key, &ret_val);
837 if (ret_val != NULL) {
838 ret_var_type = atoi(ret_val);
842 NOTIFICATION_VARIABLE_TYPE_COUNT) {
844 snprintf(buf_key, sizeof(buf_key),
845 "%dvalue%d", check_type,
847 bundle_get_str(b, buf_key, &ret_val);
848 if (ret_val != NULL) {
849 ret_variable_int = atoi(ret_val);
852 if (ret_variable_int ==
853 NOTIFICATION_COUNT_POS_RIGHT) {
854 notification_noti_get_count
856 noti->caller_pkgname,
861 sizeof(buf_str), " %d",
864 src_len = strlen(result_str);
865 max_len = NOTI_TEXT_RESULT_LEN - src_len - 1;
867 strncat(result_str, buf_str, max_len);
875 switch (check_type) {
876 case NOTIFICATION_TEXT_TYPE_TITLE:
877 case NOTIFICATION_TEXT_TYPE_GROUP_TITLE:
878 if (noti->temp_title != NULL)
879 free(noti->temp_title);
881 noti->temp_title = strdup(result_str);
883 *text = noti->temp_title;
885 case NOTIFICATION_TEXT_TYPE_CONTENT:
886 case NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
887 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT:
888 case NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF:
889 if (noti->temp_content !=
891 free(noti->temp_content);
893 noti->temp_content = strdup(result_str);
895 *text = noti->temp_content;
907 return NOTIFICATION_ERROR_NONE;
910 EXPORT_API int notification_set_text_domain(notification_h noti,
914 /* check noti and domain is valid data */
915 if (noti == NULL || domain == NULL || dir == NULL) {
916 return NOTIFICATION_ERROR_INVALID_PARAMETER;
921 /* Remove previous domain */
925 noti->domain = strdup(domain);
927 /* Check locale dir */
929 /* Remove previous locale dir */
932 /* Copy locale dir */
933 noti->dir = strdup(dir);
935 return NOTIFICATION_ERROR_NONE;
938 EXPORT_API int notification_get_text_domain(notification_h noti,
942 /* Check noti is valid data */
944 return NOTIFICATION_ERROR_INVALID_PARAMETER;
948 if (domain != NULL && noti->domain != NULL) {
949 *domain = noti->domain;
953 if (dir != NULL && noti->dir != NULL) {
957 return NOTIFICATION_ERROR_NONE;
960 EXPORT_API int notification_set_time_to_text(notification_h noti, notification_text_type_e type,
963 int ret = NOTIFICATION_ERROR_NONE;
964 char buf[256] = { 0, };
965 char buf_tag[512] = { 0, };
968 return NOTIFICATION_ERROR_INVALID_PARAMETER;
971 return NOTIFICATION_ERROR_INVALID_PARAMETER;
973 if (type <= NOTIFICATION_TEXT_TYPE_NONE
974 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
975 return NOTIFICATION_ERROR_INVALID_PARAMETER;
979 snprintf(buf, sizeof(buf), "%lu", time);
980 ret = notification_noti_set_tag(TAG_TIME, buf, buf_tag, sizeof(buf_tag));
982 if (ret != NOTIFICATION_ERROR_NONE) {
986 return notification_set_text(noti, type, buf_tag, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
989 EXPORT_API int notification_get_time_from_text(notification_h noti, notification_text_type_e type,
992 int ret = NOTIFICATION_ERROR_NONE;
995 return NOTIFICATION_ERROR_INVALID_PARAMETER;
998 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1000 if (type <= NOTIFICATION_TEXT_TYPE_NONE
1001 || type >= NOTIFICATION_TEXT_TYPE_MAX) {
1002 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1005 char *ret_text = NULL;
1006 ret = notification_get_text(noti, type, &ret_text);
1008 if (ret != NOTIFICATION_ERROR_NONE || ret_text == NULL) {
1009 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1012 if (notification_noti_get_tag_type(ret_text) == TAG_TYPE_INVALID) {
1013 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1016 char *tag_value = NULL;
1017 tag_value = notification_noti_strip_tag(ret_text);
1018 if (tag_value == NULL) {
1019 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1022 *time = atol(tag_value);
1025 return NOTIFICATION_ERROR_NONE;
1028 EXPORT_API int notification_set_sound(notification_h noti,
1029 notification_sound_type_e type,
1032 /* Check noti is valid data */
1034 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1037 /* Check type is valid */
1038 if (type < NOTIFICATION_SOUND_TYPE_NONE
1039 || type >= NOTIFICATION_SOUND_TYPE_MAX) {
1040 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1043 /* Save sound type */
1044 noti->sound_type = type;
1046 /* Save sound path if user data type */
1047 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA && path != NULL) {
1048 if (noti->sound_path != NULL) {
1049 free(noti->sound_path);
1052 noti->sound_path = strdup(path);
1054 if (noti->sound_path != NULL) {
1055 free(noti->sound_path);
1056 noti->sound_path = NULL;
1058 if (type == NOTIFICATION_SOUND_TYPE_USER_DATA) {
1059 noti->sound_type = NOTIFICATION_SOUND_TYPE_DEFAULT;
1060 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1064 return NOTIFICATION_ERROR_NONE;
1067 EXPORT_API int notification_get_sound(notification_h noti,
1068 notification_sound_type_e *type,
1071 /* check noti and type is valid data */
1072 if (noti == NULL || type == NULL) {
1073 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1076 /* Set sound type */
1077 *type = noti->sound_type;
1079 /* Set sound path if user data type */
1080 if (noti->sound_type == NOTIFICATION_SOUND_TYPE_USER_DATA
1082 *path = noti->sound_path;
1085 return NOTIFICATION_ERROR_NONE;
1088 EXPORT_API int notification_set_vibration(notification_h noti,
1089 notification_vibration_type_e type,
1092 /* Check noti is valid data */
1094 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1097 /* Check type is valid */
1098 if (type < NOTIFICATION_VIBRATION_TYPE_NONE
1099 || type >= NOTIFICATION_VIBRATION_TYPE_MAX) {
1100 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1103 /* Save vibration type */
1104 noti->vibration_type = type;
1106 /* Save sound path if user data type */
1107 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA && path != NULL) {
1108 if (noti->vibration_path != NULL) {
1109 free(noti->vibration_path);
1112 noti->vibration_path = strdup(path);
1114 if (noti->vibration_path != NULL) {
1115 free(noti->vibration_path);
1116 noti->vibration_path = NULL;
1118 if (type == NOTIFICATION_VIBRATION_TYPE_USER_DATA) {
1119 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1120 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1124 return NOTIFICATION_ERROR_NONE;
1128 EXPORT_API int notification_get_vibration(notification_h noti,
1129 notification_vibration_type_e *type,
1132 /* check noti and type is valid data */
1133 if (noti == NULL || type == NULL) {
1134 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1137 /* Set vibration type */
1138 *type = noti->vibration_type;
1140 /* Set sound path if user data type */
1141 if (noti->vibration_type == NOTIFICATION_VIBRATION_TYPE_USER_DATA
1143 *path = noti->vibration_path;
1146 return NOTIFICATION_ERROR_NONE;
1149 EXPORT_API int notification_set_led(notification_h noti,
1150 notification_led_op_e operation,
1153 /* Check noti is valid data */
1155 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1158 /* Check operation is valid */
1159 if (operation < NOTIFICATION_LED_OP_OFF
1160 || operation >= NOTIFICATION_LED_OP_MAX) {
1161 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1164 /* Save led operation */
1165 noti->led_operation = operation;
1167 /* Save led argb if operation is turning on LED with custom color */
1168 if (operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR) {
1169 noti->led_argb = led_argb;
1172 return NOTIFICATION_ERROR_NONE;
1175 EXPORT_API int notification_get_led(notification_h noti,
1176 notification_led_op_e *operation,
1179 /* check noti and operation is valid data */
1180 if (noti == NULL || operation == NULL) {
1181 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1184 /* Set led operation */
1185 *operation = noti->led_operation;
1187 /* Save led argb if operation is turning on LED with custom color */
1188 if (noti->led_operation == NOTIFICATION_LED_OP_ON_CUSTOM_COLOR
1189 && led_argb != NULL) {
1190 *led_argb = noti->led_argb;
1193 return NOTIFICATION_ERROR_NONE;
1196 EXPORT_API int notification_set_led_time_period(notification_h noti,
1197 int on_ms, int off_ms)
1199 /* Check noti is valid data */
1200 if (noti == NULL || on_ms < 0 || off_ms < 0) {
1201 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1204 /* Save led operation */
1205 noti->led_on_ms = on_ms;
1206 noti->led_off_ms = off_ms;
1208 return NOTIFICATION_ERROR_NONE;
1211 EXPORT_API int notification_get_led_time_period(notification_h noti,
1212 int *on_ms, int *off_ms)
1214 /* check noti and operation is valid data */
1216 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1220 *(on_ms) = noti->led_on_ms;
1222 *(off_ms) = noti->led_off_ms;
1224 return NOTIFICATION_ERROR_NONE;
1227 EXPORT_API int notification_set_launch_option(notification_h noti,
1228 notification_launch_option_type type, void *option)
1230 int err = NOTIFICATION_ERROR_NONE;
1233 app_control_h app_control = option;
1235 if (noti == NULL || app_control == NULL || type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1236 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1240 if ((ret = app_control_export_as_bundle(app_control, &b)) != APP_CONTROL_ERROR_NONE) {
1241 NOTIFICATION_ERR("Failed to convert appcontrol to bundle:%d", ret);
1242 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1246 err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, b);
1255 EXPORT_API int notification_get_launch_option(notification_h noti,
1256 notification_launch_option_type type, void *option)
1260 app_control_h *app_control = (app_control_h *)option;
1261 app_control_h app_control_new = NULL;
1264 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1266 if (app_control == NULL) {
1267 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1269 if (type != NOTIFICATION_LAUNCH_OPTION_APP_CONTROL) {
1270 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1273 ret = notification_get_execute_option(noti,
1274 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH,
1277 if (ret == NOTIFICATION_ERROR_NONE && b != NULL) {
1278 ret = app_control_create(&app_control_new);
1279 if (ret == APP_CONTROL_ERROR_NONE && app_control_new != NULL) {
1280 ret = app_control_import_from_bundle(app_control_new, b);
1281 if (ret == APP_CONTROL_ERROR_NONE) {
1282 *app_control = app_control_new;
1284 app_control_destroy(app_control_new);
1285 NOTIFICATION_ERR("Failed to import app control from bundle:%d", ret);
1286 return NOTIFICATION_ERROR_IO_ERROR;
1289 NOTIFICATION_ERR("Failed to create app control:%d", ret);
1290 return NOTIFICATION_ERROR_IO_ERROR;
1293 NOTIFICATION_ERR("Failed to get execute option:%d", ret);
1297 return NOTIFICATION_ERROR_NONE;
1300 EXPORT_API int notification_set_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h event_handler)
1302 int err = NOTIFICATION_ERROR_NONE;
1303 bundle *app_control_bundle = NULL;
1306 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1307 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1311 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1312 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1313 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1314 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1318 if ((err = app_control_export_as_bundle(event_handler, &app_control_bundle)) != APP_CONTROL_ERROR_NONE) {
1319 NOTIFICATION_ERR("app_control_to_bundle failed [%d]", err);
1323 if (noti->b_event_handler[event_type] != NULL) {
1324 bundle_free(noti->b_event_handler[event_type]);
1327 noti->b_event_handler[event_type] = app_control_bundle;
1333 EXPORT_API int notification_get_event_handler(notification_h noti, notification_event_type_e event_type, app_control_h *event_handler)
1335 int err = NOTIFICATION_ERROR_NONE;
1337 app_control_h app_control_new = NULL;
1340 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1341 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1344 if (event_handler == NULL) {
1345 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1346 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1349 if (event_type < NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1
1350 || event_type > NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL) {
1351 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1352 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
1356 b = noti->b_event_handler[event_type];
1359 NOTIFICATION_DBG("No event handler\n");
1360 err = NOTIFICATION_ERROR_NOT_EXIST_ID;
1364 err = app_control_create(&app_control_new);
1365 if (err != APP_CONTROL_ERROR_NONE || app_control_new == NULL) {
1366 NOTIFICATION_ERR("app_control_create failed [%d]", err);
1367 err = NOTIFICATION_ERROR_IO_ERROR;
1371 err = app_control_import_from_bundle(app_control_new, b);
1372 if (err == APP_CONTROL_ERROR_NONE) {
1373 *event_handler = app_control_new;
1375 app_control_destroy(app_control_new);
1376 app_control_new = NULL;
1377 NOTIFICATION_ERR("Failed to import app control from bundle [%d]", err);
1378 err = NOTIFICATION_ERROR_IO_ERROR;
1384 *event_handler = app_control_new;
1393 EXPORT_API int notification_set_property(notification_h noti,
1396 /* Check noti is valid data */
1398 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1402 noti->flags_for_property = flags;
1404 return NOTIFICATION_ERROR_NONE;
1407 EXPORT_API int notification_get_property(notification_h noti,
1410 /* Check noti and flags are valid data */
1411 if (noti == NULL || flags == NULL) {
1412 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1416 *flags = noti->flags_for_property;
1418 return NOTIFICATION_ERROR_NONE;
1421 EXPORT_API int notification_set_display_applist(notification_h noti,
1424 /* Check noti is valid data */
1426 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1430 if (applist == 0xffffffff) { /* 0xffffffff means old NOTIFICATION_DISPLAY_APP_ALL */
1431 applist = NOTIFICATION_DISPLAY_APP_ALL;
1433 noti->display_applist = applist;
1435 return NOTIFICATION_ERROR_NONE;
1438 EXPORT_API int notification_get_display_applist(notification_h noti,
1441 /* Check noti and applist are valid data */
1442 if (noti == NULL || applist == NULL) {
1443 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1447 *applist = noti->display_applist;
1449 return NOTIFICATION_ERROR_NONE;
1452 EXPORT_API int notification_set_size(notification_h noti,
1455 /* Check noti is valid data */
1457 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1460 /* Save progress size */
1461 noti->progress_size = size;
1463 return NOTIFICATION_ERROR_NONE;
1466 EXPORT_API int notification_get_size(notification_h noti,
1469 /* Check noti and size is valid data */
1470 if (noti == NULL || size == NULL) {
1471 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1474 /* Set progress size */
1475 *size = noti->progress_size;
1477 return NOTIFICATION_ERROR_NONE;
1480 EXPORT_API int notification_set_progress(notification_h noti,
1483 /* Check noti is valid data */
1485 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1488 /* Save progress percentage */
1489 noti->progress_percentage = percentage;
1491 return NOTIFICATION_ERROR_NONE;
1494 EXPORT_API int notification_get_progress(notification_h noti,
1497 /* Check noti and percentage are valid data */
1498 if (noti == NULL || percentage == NULL) {
1499 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1502 /* Set progress percentage */
1503 *percentage = noti->progress_percentage;
1505 return NOTIFICATION_ERROR_NONE;
1508 EXPORT_API int notification_get_pkgname(notification_h noti,
1511 /* Check noti and pkgname are valid data */
1512 if (noti == NULL || pkgname == NULL) {
1513 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1516 /* Get caller pkgname */
1517 if (noti->caller_pkgname) {
1518 *pkgname = noti->caller_pkgname;
1523 return NOTIFICATION_ERROR_NONE;
1526 EXPORT_API int notification_set_layout(notification_h noti,
1527 notification_ly_type_e layout)
1529 /* check noti and pkgname are valid data */
1530 if (noti == NULL || (layout < NOTIFICATION_LY_NONE || layout >= NOTIFICATION_LY_MAX)) {
1531 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1534 noti->layout = layout;
1536 return NOTIFICATION_ERROR_NONE;
1539 EXPORT_API int notification_get_layout(notification_h noti,
1540 notification_ly_type_e *layout)
1542 /* Check noti and pkgname are valid data */
1543 if (noti == NULL || layout == NULL) {
1544 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1547 *layout = noti->layout;
1549 return NOTIFICATION_ERROR_NONE;
1554 EXPORT_API int notification_get_type(notification_h noti,
1555 notification_type_e *type)
1557 /* Check noti and type is valid data */
1558 if (noti == NULL || type == NULL) {
1559 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1565 return NOTIFICATION_ERROR_NONE;
1568 EXPORT_API int notification_post(notification_h noti)
1573 /* Check noti is vaild data */
1575 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1578 /* Check noti type is valid type */
1579 if (noti->type <= NOTIFICATION_TYPE_NONE
1580 || noti->type >= NOTIFICATION_TYPE_MAX) {
1581 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1584 /* Save insert time */
1585 noti->insert_time = time(NULL);
1587 ret = notification_ipc_request_insert(noti, &id);
1588 if (ret != NOTIFICATION_ERROR_NONE) {
1592 NOTIFICATION_DBG("from master:%d", id);
1594 return NOTIFICATION_ERROR_NONE;
1599 EXPORT_API int notification_update(notification_h noti)
1603 /* Check noti is valid data */
1605 /* Update insert time ? */
1606 noti->insert_time = time(NULL);
1607 ret = notification_ipc_request_update(noti);
1609 notification_ipc_request_refresh();
1610 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1615 EXPORT_API int notification_delete_all(notification_type_e type)
1618 char *caller_pkgname = NULL;
1620 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1621 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1624 caller_pkgname = notification_get_pkgname_by_pid();
1626 ret = notification_ipc_request_delete_multiple(type, caller_pkgname);
1628 if (caller_pkgname) {
1629 free(caller_pkgname);
1635 EXPORT_API int notification_delete(notification_h noti)
1640 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1643 ret = notification_ipc_request_delete_single(NOTIFICATION_TYPE_NONE, noti->caller_pkgname, noti->priv_id);
1648 static notification_h _notification_create(notification_type_e type)
1650 notification_h noti = NULL;
1651 package_info_h package_info = NULL;
1652 char *app_id = NULL;
1653 char *domain_name = NULL;
1654 char *app_root_path = NULL;
1655 char locale_directory[PATH_MAX] = { 0, }; /* PATH_MAX 4096 */
1656 int err_app_manager = APP_MANAGER_ERROR_NONE;
1658 if (type <= NOTIFICATION_TYPE_NONE || type >= NOTIFICATION_TYPE_MAX) {
1659 NOTIFICATION_ERR("INVALID TYPE : %d", type);
1660 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1664 noti = (notification_h) calloc(1, sizeof(struct _notification));
1666 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1667 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1673 if (type == NOTIFICATION_TYPE_NOTI)
1674 noti->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
1675 else if (type == NOTIFICATION_TYPE_ONGOING)
1676 noti->layout = NOTIFICATION_LY_ONGOING_PROGRESS;
1678 noti->caller_pkgname = notification_get_pkgname_by_pid();
1679 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
1680 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
1681 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
1682 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1683 noti->led_operation = NOTIFICATION_LED_OP_OFF;
1684 noti->display_applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1685 noti->auto_remove = true;
1687 err_app_manager = app_manager_get_app_id(getpid(), &app_id);
1688 if (err_app_manager != APP_MANAGER_ERROR_NONE || app_id == NULL) {
1689 NOTIFICATION_WARN("app_manager_get_app_id failed err[%d] app_id[%p]", err_app_manager, app_id);
1693 /* app name is used as domain name */
1694 /* domain_name is allocated by app_get_package_app_name */
1695 err_app_manager = app_get_package_app_name(app_id, &domain_name);
1697 if (err_app_manager != APP_ERROR_NONE || domain_name == NULL) {
1698 NOTIFICATION_WARN("app_get_package_app_name failed err[%d] domain_name[%p]", err_app_manager, domain_name);
1702 err_app_manager = package_info_create(noti->caller_pkgname, &package_info);
1704 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
1705 NOTIFICATION_WARN("package_info_create failed err[%d] package_info[%p] caller_pkgname[%s]",
1706 err_app_manager, package_info, noti->caller_pkgname);
1710 err_app_manager = package_info_get_root_path(package_info, &app_root_path);
1712 if (err_app_manager != PACKAGE_MANAGER_ERROR_NONE || app_root_path == NULL) {
1713 NOTIFICATION_WARN("package_info_get_root_path failed err[%d] app_root_path[%p]", err_app_manager, app_root_path);
1717 snprintf(locale_directory, PATH_MAX, "%s/res/locale", app_root_path);
1719 noti->domain = strdup(domain_name);
1720 noti->dir = strdup(locale_directory);
1731 if (app_root_path) {
1732 free(app_root_path);
1736 package_info_destroy(package_info);
1741 * Other fields are already initialized with ZERO.
1743 set_last_result(NOTIFICATION_ERROR_NONE);
1747 EXPORT_API notification_h notification_create(notification_type_e type)
1749 return _notification_create(type);
1752 EXPORT_API notification_h notification_load_by_tag(const char *tag)
1755 notification_h noti = NULL;
1756 char *caller_pkgname = NULL;
1759 NOTIFICATION_ERR("Invalid parameter");
1760 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
1764 caller_pkgname = notification_get_pkgname_by_pid();
1765 if (!caller_pkgname) {
1766 NOTIFICATION_ERR("Failed to get a package name");
1767 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1771 noti = (notification_h) calloc(1, sizeof(struct _notification));
1773 NOTIFICATION_ERR("Failed to alloc a new notification");
1774 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
1775 free(caller_pkgname);
1780 ret = notification_noti_get_by_tag(noti, caller_pkgname, (char*)tag);
1782 free(caller_pkgname);
1784 set_last_result(ret);
1786 if (ret != NOTIFICATION_ERROR_NONE) {
1787 notification_free(noti);
1794 EXPORT_API int notification_clone(notification_h noti, notification_h *clone)
1797 notification_h new_noti = NULL;
1799 if (noti == NULL || clone == NULL) {
1800 NOTIFICATION_ERR("INVALID PARAMETER.");
1801 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1804 new_noti = (notification_h) calloc(1, sizeof(struct _notification));
1805 if (new_noti == NULL) {
1806 NOTIFICATION_ERR("NO MEMORY : noti == NULL");
1807 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1810 new_noti->type = noti->type;
1811 new_noti->layout = noti->layout;
1813 new_noti->group_id = noti->group_id;
1814 new_noti->internal_group_id = noti->internal_group_id;
1815 new_noti->priv_id = noti->priv_id;
1817 if (noti->caller_pkgname != NULL) {
1818 new_noti->caller_pkgname = strdup(noti->caller_pkgname);
1820 new_noti->caller_pkgname = notification_get_pkgname_by_pid();
1822 if (noti->launch_pkgname != NULL) {
1823 new_noti->launch_pkgname = strdup(noti->launch_pkgname);
1825 new_noti->launch_pkgname = NULL;
1828 if (noti->args != NULL) {
1829 new_noti->args = bundle_dup(noti->args);
1831 new_noti->args = NULL;
1833 if (noti->group_args != NULL) {
1834 new_noti->group_args = bundle_dup(noti->group_args);
1836 new_noti->group_args = NULL;
1839 if (noti->b_execute_option != NULL) {
1840 new_noti->b_execute_option = bundle_dup(noti->b_execute_option);
1842 new_noti->b_execute_option = NULL;
1844 if (noti->b_service_responding != NULL) {
1845 new_noti->b_service_responding = bundle_dup(noti->b_service_responding);
1847 new_noti->b_service_responding = NULL;
1849 if (noti->b_service_single_launch != NULL) {
1850 new_noti->b_service_single_launch = bundle_dup(noti->b_service_single_launch);
1852 new_noti->b_service_single_launch = NULL;
1854 if (noti->b_service_multi_launch != NULL) {
1855 new_noti->b_service_multi_launch = bundle_dup(noti->b_service_multi_launch);
1857 new_noti->b_service_multi_launch = NULL;
1860 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1861 if (noti->b_event_handler[i] != NULL) {
1862 new_noti->b_event_handler[i] = bundle_dup(noti->b_event_handler[i]);
1864 new_noti->b_event_handler[i] = NULL;
1868 new_noti->sound_type = noti->sound_type;
1869 if (noti->sound_path != NULL) {
1870 new_noti->sound_path = strdup(noti->sound_path);
1872 new_noti->sound_path = NULL;
1874 new_noti->vibration_type = noti->vibration_type;
1875 if (noti->vibration_path != NULL) {
1876 new_noti->vibration_path = strdup(noti->vibration_path);
1878 new_noti->vibration_path = NULL;
1880 new_noti->led_operation = noti->led_operation;
1881 new_noti->led_argb = noti->led_argb;
1882 new_noti->led_on_ms = noti->led_on_ms;
1883 new_noti->led_off_ms = noti->led_off_ms;
1885 if (noti->domain != NULL) {
1886 new_noti->domain = strdup(noti->domain);
1888 new_noti->domain = NULL;
1890 if (noti->dir != NULL) {
1891 new_noti->dir = strdup(noti->dir);
1893 new_noti->dir = NULL;
1896 if (noti->b_text != NULL) {
1897 new_noti->b_text = bundle_dup(noti->b_text);
1899 new_noti->b_text = NULL;
1901 if (noti->b_key != NULL) {
1902 new_noti->b_key = bundle_dup(noti->b_key);
1904 new_noti->b_key = NULL;
1906 if (noti->b_format_args != NULL) {
1907 new_noti->b_format_args = bundle_dup(noti->b_format_args);
1909 new_noti->b_format_args = NULL;
1911 new_noti->num_format_args = noti->num_format_args;
1913 if (noti->b_image_path != NULL) {
1914 new_noti->b_image_path = bundle_dup(noti->b_image_path);
1916 new_noti->b_image_path = NULL;
1919 new_noti->time = noti->time;
1920 new_noti->insert_time = noti->insert_time;
1922 new_noti->flags_for_property = noti->flags_for_property;
1923 new_noti->display_applist = noti->display_applist;
1925 new_noti->progress_size = noti->progress_size;
1926 new_noti->progress_percentage = noti->progress_percentage;
1928 new_noti->ongoing_flag = noti->ongoing_flag;
1929 new_noti->auto_remove = noti->auto_remove;
1931 new_noti->app_icon_path = NULL;
1932 new_noti->app_name = NULL;
1933 new_noti->temp_title = NULL;
1934 new_noti->temp_content = NULL;
1938 return NOTIFICATION_ERROR_NONE;
1942 EXPORT_API int notification_free(notification_h noti)
1946 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1949 if (noti->caller_pkgname) {
1950 free(noti->caller_pkgname);
1952 if (noti->launch_pkgname) {
1953 free(noti->launch_pkgname);
1956 bundle_free(noti->args);
1958 if (noti->group_args) {
1959 bundle_free(noti->group_args);
1962 if (noti->b_execute_option) {
1963 bundle_free(noti->b_execute_option);
1965 if (noti->b_service_responding) {
1966 bundle_free(noti->b_service_responding);
1968 if (noti->b_service_single_launch) {
1969 bundle_free(noti->b_service_single_launch);
1971 if (noti->b_service_multi_launch) {
1972 bundle_free(noti->b_service_multi_launch);
1975 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1976 if (noti->b_event_handler[i] != NULL) {
1977 bundle_free(noti->b_event_handler[i]);
1981 if (noti->sound_path) {
1982 free(noti->sound_path);
1984 if (noti->vibration_path) {
1985 free(noti->vibration_path);
1996 bundle_free(noti->b_text);
1999 bundle_free(noti->b_key);
2001 if (noti->b_format_args) {
2002 bundle_free(noti->b_format_args);
2005 if (noti->b_image_path) {
2006 bundle_free(noti->b_image_path);
2009 if (noti->app_icon_path) {
2010 free(noti->app_icon_path);
2012 if (noti->app_name) {
2013 free(noti->app_name);
2015 if (noti->temp_title) {
2016 free(noti->temp_title);
2018 if (noti->temp_content) {
2019 free(noti->temp_content);
2028 return NOTIFICATION_ERROR_NONE;
2031 EXPORT_API int notification_set_tag(notification_h noti, const char *tag)
2033 /* Check noti is valid data */
2035 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2039 /* save input TAG */
2040 if (noti->tag != NULL) {
2043 noti->tag = strdup(tag);
2046 return NOTIFICATION_ERROR_NONE;
2050 EXPORT_API int notification_get_tag(notification_h noti, const char **tag)
2052 /* Check noti is valid data */
2054 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2058 return NOTIFICATION_ERROR_NONE;
2061 void notification_call_posted_toast_cb(const char *message)
2063 if (posted_toast_message_cb != NULL) {
2064 posted_toast_message_cb((void*)message);
2068 EXPORT_API int notification_set_ongoing_flag(notification_h noti, bool ongoing_flag)
2071 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2073 noti->ongoing_flag = ongoing_flag;
2075 return NOTIFICATION_ERROR_NONE;
2078 EXPORT_API int notification_get_ongoing_flag(notification_h noti, bool *ongoing_flag)
2080 if (noti == NULL || ongoing_flag == NULL)
2081 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2083 *ongoing_flag = noti->ongoing_flag;
2085 return NOTIFICATION_ERROR_NONE;
2089 EXPORT_API int notification_add_button(notification_h noti, notification_button_index_e button_index)
2091 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2092 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2094 return NOTIFICATION_ERROR_NONE;
2097 EXPORT_API int notification_remove_button(notification_h noti, notification_button_index_e button_index)
2099 if (noti == NULL || button_index < NOTIFICATION_BUTTON_1 || button_index > NOTIFICATION_BUTTON_6)
2100 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2102 if (noti->b_event_handler[button_index - 1]) {
2103 bundle_free(noti->b_event_handler[button_index - 1]);
2104 noti->b_event_handler[button_index - 1] = NULL;
2107 return NOTIFICATION_ERROR_NONE;
2110 EXPORT_API int notification_set_auto_remove(notification_h noti, bool auto_remove)
2113 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2115 noti->auto_remove = auto_remove;
2117 return NOTIFICATION_ERROR_NONE;
2120 EXPORT_API int notification_get_auto_remove(notification_h noti, bool *auto_remove)
2122 if (noti == NULL || auto_remove == NULL)
2123 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2125 *auto_remove = noti->auto_remove;
2127 return NOTIFICATION_ERROR_NONE;