2 * Copyright (c) 2011 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.
25 #include <notification.h>
28 #include <app_service_private.h>
34 #define LOG_TAG "TIZEN_N_UI_NOTIFICATION"
36 struct ui_notification_s {
37 notification_h raw_handle;
50 static int ui_notification_error_handler(int error, const char *func, const char *on_error)
57 case NOTIFICATION_ERROR_NONE:
58 retcode = UI_NOTIFICATION_ERROR_NONE;
61 case NOTIFICATION_ERROR_INVALID_DATA:
62 retcode = UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
63 error_msg = "INVALID_PARAMETER";
66 case NOTIFICATION_ERROR_NO_MEMORY:
67 retcode = UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
68 error_msg = "OUT_OF_MEMORY";
71 case NOTIFICATION_ERROR_FROM_DB:
72 retcode = UI_NOTIFICATION_ERROR_DB_FAILED;
73 error_msg = "DB_FAILED";
76 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
77 case NOTIFICATION_ERROR_NOT_EXIST_ID:
78 retcode = UI_NOTIFICATION_ERROR_INVALID_STATE;
79 error_msg = "INVALID_STATE";
83 retcode = UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
84 error_msg = "INVALID_PARAMETER";
87 if (retcode != UI_NOTIFICATION_ERROR_NONE)
89 LOGE("[%s] %s(0x%08x) : %s", func, error_msg, retcode, on_error);
96 int ui_notification_create(bool ongoing, ui_notification_h *notification)
98 ui_notification_h notification_out;
100 if (notification == NULL)
102 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
103 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
106 notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s));
108 if (notification_out == NULL)
110 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
111 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
114 notification_out->raw_handle = NULL;
115 notification_out->ongoing = ongoing;
116 notification_out->posted = false;
117 notification_out->removed = false;
118 notification_out->icon = NULL;
119 notification_out->time = NULL;
120 notification_out->title = NULL;
121 notification_out->content = NULL;
122 notification_out->service = NULL;
123 notification_out->sound = NULL;
124 notification_out->vibration = false;
126 *notification = notification_out;
128 return UI_NOTIFICATION_ERROR_NONE;
131 static int ui_notification_construct(bool ongoing, notification_h raw_handle, ui_notification_h *notification)
134 ui_notification_h notification_out;
139 bundle *service_data;
140 const char *sound = NULL;
141 notification_sound_type_e sound_type;
142 notification_vibration_type_e vib_type;
144 if (notification == NULL)
146 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
147 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
150 notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s));
152 if (notification_out == NULL)
154 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
155 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
158 retcode = ui_notification_error_handler(notification_clone(raw_handle, &(notification_out->raw_handle)),\
159 __FUNCTION__, "failed to clone the notification handle");
161 if (retcode != NOTIFICATION_ERROR_NONE)
166 notification_out->ongoing = ongoing;
168 notification_out->posted = true;
170 notification_out->removed = false;
172 if (!notification_get_image(raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, &icon) && icon)
174 notification_out->icon = strdup(icon);
177 if (!notification_get_time(raw_handle, &time))
179 notification_out->time = malloc(sizeof(struct tm));
181 if (notification_out->time == NULL)
183 ui_notification_destroy(notification_out);
184 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
185 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
188 localtime_r(&time, notification_out->time);
191 if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, &title) && title)
193 notification_out->title = strdup(title);
196 if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) && content)
198 notification_out->content = strdup(content);
201 if (!notification_get_sound(raw_handle, &sound_type, &sound) && sound)
203 notification_out->sound = strdup(sound);
206 if (!notification_get_vibration(raw_handle, &vib_type, NULL))
208 if (vib_type == NOTIFICATION_VIBRATION_TYPE_DEFAULT)
210 notification_out->vibration = true;
214 if (!notification_get_execute_option(raw_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &service_data))
218 if (!service_create_request(service_data, &service))
220 notification_out->service = service;
224 *notification = notification_out;
226 return UI_NOTIFICATION_ERROR_NONE;
229 int ui_notification_destroy(ui_notification_h notification)
231 if (notification == NULL)
233 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
234 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
237 if (notification->raw_handle)
238 notification_free(notification->raw_handle);
240 if (notification->icon)
241 free(notification->icon);
243 if (notification->time)
244 free(notification->time);
246 if (notification->title)
247 free(notification->title);
249 if (notification->content)
250 free(notification->content);
252 if (notification->sound)
253 free(notification->sound);
255 if (notification->service)
256 service_destroy(notification->service);
260 return UI_NOTIFICATION_ERROR_NONE;
263 int ui_notification_clone(ui_notification_h *clone, ui_notification_h notification)
265 ui_notification_h notification_out;
268 if (clone == NULL || notification == NULL)
270 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
271 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
274 notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s));
276 if (notification->raw_handle != NULL)
278 retcode = notification_clone(notification->raw_handle, &(notification_out->raw_handle));
282 return ui_notification_error_handler(retcode, __FUNCTION__, "failed to clone the handle");
286 notification_out->ongoing = notification->ongoing;
288 notification_out->posted = notification->posted;
290 notification_out->removed = notification->removed;
292 if (notification->icon)
294 notification_out->icon = strdup(notification->icon);
297 if (notification->time)
299 notification_out->time = malloc(sizeof(struct tm));
300 if (notification_out->time != NULL)
302 memcpy(notification_out->time, notification->time, sizeof(struct tm));
306 if (notification->title)
308 notification_out->title = strdup(notification->title);
311 if (notification->content)
313 notification_out->content = strdup(notification->content);
316 if (notification->sound)
318 notification_out->sound = strdup(notification->sound);
321 notification_out->vibration = notification->vibration;
323 if (notification->service)
325 service_clone(&(notification_out->service), notification->service);
328 *clone = notification_out;
330 return UI_NOTIFICATION_ERROR_NONE;
333 int ui_notification_is_ongoing(ui_notification_h notification, bool *ongoing)
335 if (notification == NULL || ongoing == NULL)
337 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
338 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
341 *ongoing = notification->ongoing;
343 return UI_NOTIFICATION_ERROR_NONE;
346 int ui_notification_set_icon(ui_notification_h notification, const char *path)
348 char *path_dup = NULL;
350 if (notification == NULL)
352 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
353 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
358 path_dup = strdup(path);
360 if (path_dup == NULL)
362 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
363 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
367 if (notification->icon != NULL)
369 free(notification->icon);
372 notification->icon = path_dup;
374 return UI_NOTIFICATION_ERROR_NONE;
377 int ui_notification_get_icon(ui_notification_h notification, char **path)
379 char *path_dup = NULL;
381 if (notification == NULL || path == NULL)
383 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
384 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
387 if (notification->icon != NULL)
389 path_dup = strdup(notification->icon);
391 if (path_dup == NULL)
393 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
394 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
400 return UI_NOTIFICATION_ERROR_NONE;
403 int ui_notification_set_time(ui_notification_h notification, struct tm *time)
405 struct tm *time_dup = NULL;
407 if (notification == NULL)
409 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
410 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
415 time_dup = malloc(sizeof(struct tm));
417 if (time_dup == NULL)
419 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
420 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
423 memcpy(time_dup, time, sizeof(struct tm));
426 if (notification->time != NULL)
428 free(notification->time);
431 notification->time = time_dup;
433 return UI_NOTIFICATION_ERROR_NONE;
436 int ui_notification_get_time(ui_notification_h notification, struct tm **time)
438 struct tm *time_dup = NULL;
440 if (notification == NULL || time == NULL)
442 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
443 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
446 if (notification->time != NULL)
448 time_dup = malloc(sizeof(struct tm));
450 if (time_dup == NULL)
452 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
453 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
456 memcpy(time_dup, notification->time, sizeof(struct tm));
461 return UI_NOTIFICATION_ERROR_NONE;
464 int ui_notification_set_title(ui_notification_h notification, const char *title)
466 char *title_dup = NULL;
468 if (notification == NULL)
470 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
471 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
476 title_dup = strdup(title);
478 if (title_dup == NULL)
480 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
481 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
485 if (notification->title != NULL)
487 free(notification->title);
490 notification->title = title_dup;
492 return UI_NOTIFICATION_ERROR_NONE;
495 int ui_notification_get_title(ui_notification_h notification, char **title)
497 char *title_dup = NULL;
499 if (notification == NULL || title == NULL)
501 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
502 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
505 if (notification->title != NULL)
507 title_dup = strdup(notification->title);
509 if (title_dup == NULL)
511 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
512 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
518 return UI_NOTIFICATION_ERROR_NONE;
522 int ui_notification_set_content(ui_notification_h notification, const char *content)
524 char *content_dup = NULL;
526 if (notification == NULL)
528 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
529 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
534 content_dup = strdup(content);
536 if (content_dup == NULL)
538 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
539 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
543 if (notification->content != NULL)
545 free(notification->content);
548 notification->content = content_dup;
550 return UI_NOTIFICATION_ERROR_NONE;
553 int ui_notification_get_content(ui_notification_h notification, char **content)
555 char *content_dup = NULL;
557 if (notification == NULL || content == NULL)
559 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
560 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
563 if (notification->content != NULL)
565 content_dup = strdup(notification->content);
567 if (content_dup == NULL)
569 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
570 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
574 *content = content_dup;
576 return UI_NOTIFICATION_ERROR_NONE;
580 int ui_notification_set_service(ui_notification_h notification, service_h service)
583 service_h service_dup = NULL;
585 if (notification == NULL)
587 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
588 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
593 retcode = service_clone(&service_dup, service);
595 if (retcode != SERVICE_ERROR_NONE)
597 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
599 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
600 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
604 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid service handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
605 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
610 if (notification->service != NULL)
612 service_destroy(notification->service);
615 notification->service = service_dup;
617 return UI_NOTIFICATION_ERROR_NONE;
620 int ui_notification_get_service(ui_notification_h notification, service_h *service)
623 service_h service_dup = NULL;
625 if (notification == NULL || service == NULL)
627 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
628 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
631 if (notification->service != NULL)
633 retcode = service_clone(&service_dup, notification->service);
635 if (retcode != SERVICE_ERROR_NONE)
637 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
639 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
640 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
644 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid service handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
645 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
650 *service = service_dup;
652 return UI_NOTIFICATION_ERROR_NONE;
655 int ui_notification_set_sound(ui_notification_h notification, const char *path)
657 char *path_dup = NULL;
659 if (notification == NULL)
661 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
662 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
667 path_dup = strdup(path);
669 if (path_dup == NULL)
671 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
672 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
676 if (notification->sound != NULL)
678 free(notification->sound);
681 notification->sound = path_dup;
683 return UI_NOTIFICATION_ERROR_NONE;
686 int ui_notification_get_sound(ui_notification_h notification, char **path)
688 char *path_dup = NULL;
690 if (notification == NULL || path == NULL)
692 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
693 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
696 if (notification->sound != NULL)
698 path_dup = strdup(notification->sound);
700 if (path_dup == NULL)
702 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
705 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
711 return UI_NOTIFICATION_ERROR_NONE;
714 int ui_notification_set_vibration(ui_notification_h notification, bool value)
716 if (notification == NULL)
718 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
719 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
722 notification->vibration = value;
724 return UI_NOTIFICATION_ERROR_NONE;
727 int ui_notification_get_vibration(ui_notification_h notification, bool *value)
729 if (notification == NULL || value == NULL)
731 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
732 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
735 *value = notification->vibration;
737 return UI_NOTIFICATION_ERROR_NONE;
740 static int ui_notification_build_attributes(ui_notification_h notification)
742 bundle *service_data;
744 if (notification == NULL)
746 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
747 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
750 if (notification->icon != NULL)
754 if (stat(notification->icon, &st) < 0)
756 LOGE("[%s] NO_SUCH_FILE(0x%08x) : invalid icon", __FUNCTION__, UI_NOTIFICATION_ERROR_NO_SUCH_FILE);
757 return UI_NOTIFICATION_ERROR_NO_SUCH_FILE;
760 notification_set_image(notification->raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, notification->icon);
763 if (notification->time != NULL)
765 notification_set_time(notification->raw_handle, mktime(notification->time));
768 if (notification->title != NULL)
770 notification_set_text(notification->raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, notification->title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
773 if (notification->content != NULL)
775 notification_set_text(notification->raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, notification->content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
778 if (notification->service != NULL && service_to_bundle(notification->service, &service_data) == SERVICE_ERROR_NONE)
780 notification_set_property(notification->raw_handle, 0);
781 notification_set_execute_option(notification->raw_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
785 notification_set_property(notification->raw_handle, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
788 if (notification->sound != NULL)
792 if (stat(notification->sound, &st) < 0)
794 LOGE("[%s] NO_SUCH_FILE(0x%08x) : invalid sound file", __FUNCTION__, UI_NOTIFICATION_ERROR_NO_SUCH_FILE);
795 return UI_NOTIFICATION_ERROR_NO_SUCH_FILE;
797 notification_set_sound(notification->raw_handle, NOTIFICATION_SOUND_TYPE_USER_DATA, notification->sound);
800 if (notification->vibration)
802 notification_set_vibration(notification->raw_handle, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
805 return UI_NOTIFICATION_ERROR_NONE;
808 int ui_notification_post(ui_notification_h notification)
812 if (notification == NULL)
814 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
815 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
818 if (notification->posted == true)
820 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was already posted", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
821 return UI_NOTIFICATION_ERROR_INVALID_STATE;
824 if (notification->ongoing == true)
826 notification->raw_handle = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
830 notification->raw_handle = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
833 if (notification->raw_handle == NULL)
835 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
836 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
839 retcode = ui_notification_build_attributes(notification);
841 if (retcode != UI_NOTIFICATION_ERROR_NONE)
846 retcode = ui_notification_error_handler(notification_insert(notification->raw_handle, NULL), __FUNCTION__, "failed to post a notification");
848 if (retcode == UI_NOTIFICATION_ERROR_NONE)
850 notification->posted = true;
856 int ui_notification_update(ui_notification_h notification)
860 if (notification == NULL)
862 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
863 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
866 if (notification->posted == false)
868 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was not posted", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
869 return UI_NOTIFICATION_ERROR_INVALID_STATE;
872 if (notification->removed == true)
874 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was canceled or cleared", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
875 return UI_NOTIFICATION_ERROR_INVALID_STATE;
878 retcode = ui_notification_build_attributes(notification);
880 if (retcode != UI_NOTIFICATION_ERROR_NONE)
885 retcode = ui_notification_error_handler(notification_update(notification->raw_handle), __FUNCTION__, "failed to post a notification");
887 if (retcode == UI_NOTIFICATION_ERROR_INVALID_STATE)
889 notification->removed = true;
895 int ui_notification_update_progress(ui_notification_h notification, ui_notification_progress_type_e type, double value)
899 if (notification == NULL)
901 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
902 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
905 if (notification->raw_handle == NULL)
907 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
908 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
911 if (notification->posted == false)
913 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was not posted", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
914 return UI_NOTIFICATION_ERROR_INVALID_STATE;
917 if (notification->removed == true)
919 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was canceled or cleared", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
920 return UI_NOTIFICATION_ERROR_INVALID_STATE;
925 LOGE("[%s] INVALID_PARAMETER(0x%08x) : the value must be greater than or equal to zero.", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
926 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
931 case UI_NOTIFICATION_PROGRESS_TYPE_SIZE:
932 retcode = ui_notification_error_handler(
933 notification_update_size(notification->raw_handle, NOTIFICATION_PRIV_ID_NONE, value),
934 __FUNCTION__, "failed to update the progress");
937 case UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE:
938 retcode = ui_notification_error_handler(
939 notification_update_progress(notification->raw_handle, NOTIFICATION_PRIV_ID_NONE, value),
940 __FUNCTION__, "failed to update the progress");
944 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid progress type", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
945 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
948 if (retcode == UI_NOTIFICATION_ERROR_INVALID_STATE)
950 notification->removed = true;
956 int ui_notification_cancel(ui_notification_h notification)
960 if (notification == NULL)
962 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
963 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
966 if (notification->raw_handle == NULL)
968 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
969 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
972 if (notification->posted == false)
974 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was not posted", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
975 return UI_NOTIFICATION_ERROR_INVALID_STATE;
978 if (notification->removed == true)
980 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was canceled or cleared", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
981 return UI_NOTIFICATION_ERROR_INVALID_STATE;
984 retcode = ui_notification_error_handler(notification_delete(notification->raw_handle), __FUNCTION__, "failed to cancel the notification");
986 if (retcode == UI_NOTIFICATION_ERROR_NONE)
988 notification->removed = true;
994 void ui_notification_cancel_all(void)
996 notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NONE);
999 void ui_notification_cancel_all_by_type(bool ongoing)
1001 notification_type_e type = NOTIFICATION_TYPE_NONE;
1004 type = NOTIFICATION_TYPE_ONGOING;
1006 type = NOTIFICATION_TYPE_NOTI;
1008 notification_delete_all_by_type(NULL, type);
1011 void ui_notification_cancel_all_by_package(const char *package, bool ongoing)
1013 notification_type_e type = NOTIFICATION_TYPE_NONE;
1016 type = NOTIFICATION_TYPE_ONGOING;
1018 type = NOTIFICATION_TYPE_NOTI;
1020 notification_delete_all_by_type(package, type);
1023 int ui_notification_cancel_all_by_app_id(const char *app_id, bool ongoing)
1025 notification_type_e type = NOTIFICATION_TYPE_NONE;
1029 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
1030 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
1034 type = NOTIFICATION_TYPE_ONGOING;
1036 type = NOTIFICATION_TYPE_NOTI;
1038 notification_delete_all_by_type(app_id, type);
1040 return UI_NOTIFICATION_ERROR_NONE;
1043 static bool ui_notification_package_equal(notification_h handle)
1045 char *package = NULL;
1046 char *handle_package = NULL;
1048 if (app_get_package(&package))
1053 if (notification_get_pkgname(handle, &handle_package))
1058 if (strlen(package) == strlen(handle_package))
1060 if (!strncmp(package, handle_package, strlen(package)))
1069 int ui_notification_foreach_notification_posted(bool ongoing, ui_notification_cb callback, void *user_data)
1071 notification_list_h raw_handle_list;
1072 notification_h raw_handle;
1073 notification_type_e notification_type = ongoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
1074 ui_notification_h notification = NULL;
1075 bool iterate_next = true;
1077 if (callback == NULL)
1079 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
1080 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
1083 if (notification_get_grouping_list(notification_type, -1, &raw_handle_list))
1085 LOGE("[%s] DB_FAILED(0x%08x) : failed to get a notification list", __FUNCTION__, UI_NOTIFICATION_ERROR_DB_FAILED);
1086 return UI_NOTIFICATION_ERROR_DB_FAILED;
1089 while (raw_handle_list != NULL)
1091 raw_handle = notification_list_get_data(raw_handle_list);
1093 if (raw_handle != NULL && ui_notification_package_equal(raw_handle))
1095 if (!ui_notification_construct(ongoing, raw_handle, ¬ification))
1097 iterate_next = callback(notification, user_data);
1099 ui_notification_destroy(notification);
1101 if (iterate_next == false)
1108 raw_handle_list = notification_list_get_next(raw_handle_list);
1111 notification_free_list(raw_handle_list);
1113 return UI_NOTIFICATION_ERROR_NONE;