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;
48 static int ui_notification_error_handler(int error, const char *func, const char *on_error)
55 case NOTIFICATION_ERROR_NONE:
56 retcode = UI_NOTIFICATION_ERROR_NONE;
59 case NOTIFICATION_ERROR_INVALID_DATA:
60 retcode = UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
61 error_msg = "INVALID_PARAMETER";
64 case NOTIFICATION_ERROR_NO_MEMORY:
65 retcode = UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
66 error_msg = "OUT_OF_MEMORY";
69 case NOTIFICATION_ERROR_FROM_DB:
70 retcode = UI_NOTIFICATION_ERROR_DB_FAILED;
71 error_msg = "DB_FAILED";
74 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
75 case NOTIFICATION_ERROR_NOT_EXIST_ID:
76 retcode = UI_NOTIFICATION_ERROR_INVALID_STATE;
77 error_msg = "INVALID_STATE";
81 retcode = UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
82 error_msg = "INVALID_PARAMETER";
85 if (retcode != UI_NOTIFICATION_ERROR_NONE)
87 LOGE("[%s] %s(0x%08x) : %s", func, error_msg, retcode, on_error);
94 int ui_notification_create(bool ongoing, ui_notification_h *notification)
96 ui_notification_h notification_out;
98 if (notification == NULL)
100 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
101 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
104 notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s));
106 if (notification_out == NULL)
108 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
109 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
112 notification_out->raw_handle = NULL;
113 notification_out->ongoing = ongoing;
114 notification_out->posted = false;
115 notification_out->removed = false;
116 notification_out->icon = NULL;
117 notification_out->time = NULL;
118 notification_out->title = NULL;
119 notification_out->content = NULL;
120 notification_out->service = NULL;
122 *notification = notification_out;
124 return UI_NOTIFICATION_ERROR_NONE;
127 static int ui_notification_construct(bool ongoing, notification_h raw_handle, ui_notification_h *notification)
130 ui_notification_h notification_out;
135 bundle *service_data;
137 if (notification == NULL)
139 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
140 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
143 notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s));
145 if (notification_out == NULL)
147 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
148 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
151 retcode = ui_notification_error_handler(notification_clone(raw_handle, &(notification_out->raw_handle)),\
152 __FUNCTION__, "failed to clone the notification handle");
154 if (retcode != NOTIFICATION_ERROR_NONE)
159 notification_out->ongoing = ongoing;
161 notification_out->posted = true;
163 notification_out->removed = false;
165 if (!notification_get_image(raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, &icon))
167 notification_out->icon = icon;
170 if (!notification_get_time(raw_handle, &time))
172 notification_out->time = malloc(sizeof(struct tm));
174 if (notification_out->time == NULL)
176 ui_notification_destroy(notification_out);
177 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
178 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
181 localtime_r(&time, notification_out->time);
184 if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, &title))
186 notification_out->title = title;
189 if (! notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &content))
191 notification_out->content = content;
194 if (!notification_get_execute_option(raw_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &service_data))
198 if (!service_create_request(service_data, &service))
200 notification_out->service = service;
204 *notification = notification_out;
206 return UI_NOTIFICATION_ERROR_NONE;
209 int ui_notification_destroy(ui_notification_h notification)
211 if (notification == NULL)
213 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
214 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
217 if (notification->raw_handle)
218 notification_free(notification->raw_handle);
220 if (notification->icon)
221 free(notification->icon);
223 if (notification->time)
224 free(notification->time);
226 if (notification->title)
227 free(notification->title);
229 if (notification->content)
230 free(notification->content);
232 if (notification->service)
233 service_destroy(notification->service);
237 return UI_NOTIFICATION_ERROR_NONE;
240 int ui_notification_clone(ui_notification_h *clone, ui_notification_h notification)
242 ui_notification_h notification_out;
245 if (clone == NULL || notification == NULL)
247 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
248 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
251 notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s));
253 if (notification->raw_handle != NULL)
255 retcode = notification_clone(notification->raw_handle, &(notification_out->raw_handle));
259 return ui_notification_error_handler(retcode, __FUNCTION__, "failed to clone the handle");
263 notification_out->ongoing = notification->ongoing;
265 notification_out->posted = notification->posted;
267 notification_out->removed = notification->removed;
269 if (notification->icon)
271 notification_out->icon = strdup(notification->icon);
274 if (notification->time)
276 notification_out->time = malloc(sizeof(struct tm));
277 if (notification_out->time != NULL)
279 memcpy(notification_out->time, notification->time, sizeof(struct tm));
283 if (notification->title)
285 notification_out->title = strdup(notification->title);
288 if (notification->content)
290 notification_out->content = strdup(notification->content);
293 if (notification->service)
295 service_clone(&(notification_out->service), notification->service);
298 *clone = notification_out;
300 return UI_NOTIFICATION_ERROR_NONE;
303 int ui_notification_is_ongoing(ui_notification_h notification, bool *ongoing)
305 if (notification == NULL || ongoing == NULL)
307 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
308 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
311 *ongoing = notification->ongoing;
313 return UI_NOTIFICATION_ERROR_NONE;
316 int ui_notification_set_icon(ui_notification_h notification, const char *path)
318 char *path_dup = NULL;
320 if (notification == NULL)
322 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
323 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
328 path_dup = strdup(path);
330 if (path_dup == NULL)
332 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
333 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
337 if (notification->icon != NULL)
339 free(notification->icon);
342 notification->icon = path_dup;
344 return UI_NOTIFICATION_ERROR_NONE;
347 int ui_notification_get_icon(ui_notification_h notification, char **path)
349 char *path_dup = NULL;
351 if (notification == NULL || path == NULL)
353 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
354 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
357 if (notification->icon != NULL)
359 path_dup = strdup(notification->icon);
361 if (path_dup == NULL)
363 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
364 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
370 return UI_NOTIFICATION_ERROR_NONE;
373 int ui_notification_set_time(ui_notification_h notification, struct tm *time)
375 struct tm *time_dup = NULL;
377 if (notification == NULL)
379 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
380 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
385 time_dup = malloc(sizeof(struct tm));
387 if (time_dup == NULL)
389 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
390 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
393 memcpy(time_dup, time, sizeof(struct tm));
396 if (notification->time != NULL)
398 free(notification->time);
401 notification->time = time_dup;
403 return UI_NOTIFICATION_ERROR_NONE;
406 int ui_notification_get_time(ui_notification_h notification, struct tm **time)
408 struct tm *time_dup = NULL;
410 if (notification == NULL || time == NULL)
412 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
413 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
416 if (notification->time != NULL)
418 time_dup = malloc(sizeof(struct tm));
420 if (time_dup == NULL)
422 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
423 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
426 memcpy(time_dup, notification->time, sizeof(struct tm));
431 return UI_NOTIFICATION_ERROR_NONE;
434 int ui_notification_set_title(ui_notification_h notification, const char *title)
436 char *title_dup = NULL;
438 if (notification == NULL)
440 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
441 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
446 title_dup = strdup(title);
448 if (title_dup == NULL)
450 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
451 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
455 if (notification->title != NULL)
457 free(notification->title);
460 notification->title = title_dup;
462 return UI_NOTIFICATION_ERROR_NONE;
465 int ui_notification_get_title(ui_notification_h notification, char **title)
467 char *title_dup = NULL;
469 if (notification == NULL || title == NULL)
471 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
472 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
475 if (notification->title != NULL)
477 title_dup = strdup(notification->title);
479 if (title_dup == NULL)
481 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
482 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
488 return UI_NOTIFICATION_ERROR_NONE;
492 int ui_notification_set_content(ui_notification_h notification, const char *content)
494 char *content_dup = NULL;
496 if (notification == NULL)
498 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
499 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
504 content_dup = strdup(content);
506 if (content_dup == NULL)
508 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
509 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
513 if (notification->content != NULL)
515 free(notification->content);
518 notification->content = content_dup;
520 return UI_NOTIFICATION_ERROR_NONE;
523 int ui_notification_get_content(ui_notification_h notification, char **content)
525 char *content_dup = NULL;
527 if (notification == NULL || content == NULL)
529 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
530 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
533 if (notification->content != NULL)
535 content_dup = strdup(notification->content);
537 if (content_dup == NULL)
539 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
540 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
544 *content = content_dup;
546 return UI_NOTIFICATION_ERROR_NONE;
550 int ui_notification_set_service(ui_notification_h notification, service_h service)
553 service_h service_dup = NULL;
555 if (notification == NULL)
557 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
558 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
563 retcode = service_clone(&service_dup, service);
565 if (retcode != SERVICE_ERROR_NONE)
567 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
569 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
570 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
574 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid service handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
575 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
580 if (notification->service != NULL)
582 service_destroy(notification->service);
585 notification->service = service_dup;
587 return UI_NOTIFICATION_ERROR_NONE;
590 int ui_notification_get_service(ui_notification_h notification, service_h *service)
593 service_h service_dup = NULL;
595 if (notification == NULL || service == NULL)
597 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
598 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
601 if (notification->service != NULL)
603 retcode = service_clone(&service_dup, notification->service);
605 if (retcode != SERVICE_ERROR_NONE)
607 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
609 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
610 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
614 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid service handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
615 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
620 *service = service_dup;
622 return UI_NOTIFICATION_ERROR_NONE;
625 static int ui_notification_build_attributes(ui_notification_h notification)
627 bundle *service_data;
629 if (notification == NULL)
631 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
632 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
635 if (notification->icon != NULL)
639 if (stat(notification->icon, &st) < 0)
641 LOGE("[%s] NO_SUCH_FILE(0x%08x) : invalid icon", __FUNCTION__, UI_NOTIFICATION_ERROR_NO_SUCH_FILE);
642 return UI_NOTIFICATION_ERROR_NO_SUCH_FILE;
645 notification_set_image(notification->raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, notification->icon);
648 if (notification->time != NULL)
650 notification_set_time(notification->raw_handle, mktime(notification->time));
653 if (notification->title != NULL)
655 notification_set_text(notification->raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, notification->title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
658 if (notification->content != NULL)
660 notification_set_text(notification->raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, notification->content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
663 if (notification->service != NULL && service_to_bundle(notification->service, &service_data) == SERVICE_ERROR_NONE)
665 notification_set_property(notification->raw_handle, 0);
666 notification_set_execute_option(notification->raw_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
670 notification_set_property(notification->raw_handle, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
673 return UI_NOTIFICATION_ERROR_NONE;
676 int ui_notification_post(ui_notification_h notification)
680 if (notification == NULL)
682 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
683 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
686 if (notification->posted == true)
688 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was already posted", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
689 return UI_NOTIFICATION_ERROR_INVALID_STATE;
692 if (notification->ongoing == true)
694 notification->raw_handle = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
698 notification->raw_handle = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
701 if (notification->raw_handle == NULL)
703 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
704 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
707 retcode = ui_notification_build_attributes(notification);
709 if (retcode != UI_NOTIFICATION_ERROR_NONE)
714 retcode = ui_notification_error_handler(notification_insert(notification->raw_handle, NULL), __FUNCTION__, "failed to post a notification");
716 if (retcode == UI_NOTIFICATION_ERROR_NONE)
718 notification->posted = true;
724 int ui_notification_update(ui_notification_h notification)
728 if (notification == NULL)
730 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
731 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
734 if (notification->posted == false)
736 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was not posted", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
737 return UI_NOTIFICATION_ERROR_INVALID_STATE;
740 if (notification->removed == true)
742 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was canceled or cleared", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
743 return UI_NOTIFICATION_ERROR_INVALID_STATE;
746 retcode = ui_notification_build_attributes(notification);
748 if (retcode != UI_NOTIFICATION_ERROR_NONE)
753 retcode = ui_notification_error_handler(notification_update(notification->raw_handle), __FUNCTION__, "failed to post a notification");
755 if (retcode == UI_NOTIFICATION_ERROR_INVALID_STATE)
757 notification->removed = true;
763 int ui_notification_update_progress(ui_notification_h notification, ui_notification_progress_type_e type, double value)
767 if (notification == NULL)
769 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
770 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
773 if (notification->raw_handle == NULL)
775 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
776 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
779 if (notification->posted == false)
781 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was not posted", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
782 return UI_NOTIFICATION_ERROR_INVALID_STATE;
785 if (notification->removed == true)
787 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was canceled or cleared", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
788 return UI_NOTIFICATION_ERROR_INVALID_STATE;
793 LOGE("[%s] INVALID_PARAMETER(0x%08x) : the value must be greater than or equal to zero.", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
794 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
799 case UI_NOTIFICATION_PROGRESS_TYPE_SIZE:
800 retcode = ui_notification_error_handler(
801 notification_update_size(notification->raw_handle, NOTIFICATION_PRIV_ID_NONE, value),
802 __FUNCTION__, "failed to update the progress");
805 case UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE:
806 retcode = ui_notification_error_handler(
807 notification_update_progress(notification->raw_handle, NOTIFICATION_PRIV_ID_NONE, value),
808 __FUNCTION__, "failed to update the progress");
812 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid progress type", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
813 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
816 if (retcode == UI_NOTIFICATION_ERROR_INVALID_STATE)
818 notification->removed = true;
824 int ui_notification_cancel(ui_notification_h notification)
828 if (notification == NULL)
830 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
831 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
834 if (notification->raw_handle == NULL)
836 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
837 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
840 if (notification->posted == false)
842 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was not posted", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
843 return UI_NOTIFICATION_ERROR_INVALID_STATE;
846 if (notification->removed == true)
848 LOGE("[%s] INVALID_STATE(0x%08x) : the notification was canceled or cleared", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_STATE);
849 return UI_NOTIFICATION_ERROR_INVALID_STATE;
852 retcode = ui_notification_error_handler(notification_delete(notification->raw_handle), __FUNCTION__, "failed to cancel the notification");
854 if (retcode == UI_NOTIFICATION_ERROR_NONE)
856 notification->removed = true;
862 void ui_notification_cancel_all(void)
864 notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NONE);
867 static bool ui_notification_package_equal(notification_h handle)
869 char *package = NULL;
870 char *handle_package = NULL;
872 if (app_get_package(&package))
877 if (notification_get_pkgname(handle, &handle_package))
882 if (strlen(package) == strlen(handle_package))
884 if (!strncmp(package, handle_package, strlen(package)))
893 int ui_notification_foreach_notification_posted(bool ongoing, ui_notification_cb callback, void *user_data)
895 notification_list_h raw_handle_list;
896 notification_h raw_handle;
897 notification_type_e notification_type = ongoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
898 ui_notification_h notification = NULL;
899 bool iterate_next = true;
901 if (callback == NULL)
903 LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
904 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
907 if (notification_get_grouping_list(notification_type, -1, &raw_handle_list))
909 LOGE("[%s] DB_FAILED(0x%08x) : failed to get a notification list", __FUNCTION__, UI_NOTIFICATION_ERROR_DB_FAILED);
910 return UI_NOTIFICATION_ERROR_DB_FAILED;
913 while (raw_handle_list != NULL)
915 raw_handle = notification_list_get_data(raw_handle_list);
917 if (raw_handle != NULL && ui_notification_package_equal(raw_handle))
919 if (!ui_notification_construct(ongoing, raw_handle, ¬ification))
921 iterate_next = callback(notification, user_data);
923 ui_notification_destroy(notification);
925 if (iterate_next == false)
932 raw_handle_list = notification_list_get_next(raw_handle_list);
935 notification_free_list(raw_handle_list);
937 return UI_NOTIFICATION_ERROR_NONE;