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.
27 #include <notification.h>
30 #include <app_service_private.h>
36 #define LOG_TAG "CAPI_APPFW_APPLICATION_UI_NOTIFICATION"
38 struct ui_notification_s {
39 notification_h raw_handle;
52 static int ui_notification_error_handler(int error, const char *func, const char *on_error)
59 case NOTIFICATION_ERROR_NONE:
60 retcode = UI_NOTIFICATION_ERROR_NONE;
63 case NOTIFICATION_ERROR_INVALID_DATA:
64 retcode = UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
65 error_msg = "INVALID_PARAMETER";
68 case NOTIFICATION_ERROR_NO_MEMORY:
69 retcode = UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
70 error_msg = "OUT_OF_MEMORY";
73 case NOTIFICATION_ERROR_FROM_DB:
74 retcode = UI_NOTIFICATION_ERROR_DB_FAILED;
75 error_msg = "DB_FAILED";
78 case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
79 case NOTIFICATION_ERROR_NOT_EXIST_ID:
80 retcode = UI_NOTIFICATION_ERROR_INVALID_STATE;
81 error_msg = "INVALID_STATE";
85 retcode = UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
86 error_msg = "INVALID_PARAMETER";
89 if (retcode != UI_NOTIFICATION_ERROR_NONE)
91 LOGE("[%s] %s(0x%08x) : %s", func, error_msg, retcode, on_error);
98 int ui_notification_create(bool ongoing, ui_notification_h *notification)
100 ui_notification_h notification_out;
102 if (notification == NULL)
104 LOGE("INVALID_PARAMETER(0x%08x) : invalid output param", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
105 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
108 notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s));
110 if (notification_out == NULL)
112 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
113 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
116 notification_out->raw_handle = NULL;
117 notification_out->ongoing = ongoing;
118 notification_out->posted = false;
119 notification_out->removed = false;
120 notification_out->icon = NULL;
121 notification_out->time = NULL;
122 notification_out->title = NULL;
123 notification_out->content = NULL;
124 notification_out->service = NULL;
125 notification_out->sound = NULL;
126 notification_out->vibration = false;
128 *notification = notification_out;
130 return UI_NOTIFICATION_ERROR_NONE;
133 static int ui_notification_construct(bool ongoing, notification_h raw_handle, ui_notification_h *notification)
136 ui_notification_h notification_out;
141 bundle *service_data;
142 const char *sound = NULL;
143 notification_sound_type_e sound_type;
144 notification_vibration_type_e vib_type;
146 if (notification == NULL)
148 LOGE("INVALID_PARAMETER(0x%08x) : invalid output param", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
149 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
152 notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s));
154 if (notification_out == NULL)
156 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
157 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
160 retcode = ui_notification_error_handler(notification_clone(raw_handle, &(notification_out->raw_handle)),\
161 __FUNCTION__, "failed to clone the notification handle");
163 if (retcode != NOTIFICATION_ERROR_NONE)
165 free(notification_out);
169 notification_out->ongoing = ongoing;
171 notification_out->posted = true;
173 notification_out->removed = false;
175 if (!notification_get_image(raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, &icon) && icon)
177 notification_out->icon = strdup(icon);
180 if (!notification_get_time(raw_handle, &time))
182 notification_out->time = malloc(sizeof(struct tm));
184 if (notification_out->time == NULL)
186 ui_notification_destroy(notification_out);
187 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
188 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
191 localtime_r(&time, notification_out->time);
194 if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, &title) && title)
196 notification_out->title = strdup(title);
199 if (!notification_get_text(raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &content) && content)
201 notification_out->content = strdup(content);
204 if (!notification_get_sound(raw_handle, &sound_type, &sound) && sound)
206 notification_out->sound = strdup(sound);
209 if (!notification_get_vibration(raw_handle, &vib_type, NULL))
211 if (vib_type == NOTIFICATION_VIBRATION_TYPE_DEFAULT)
213 notification_out->vibration = true;
217 if (!notification_get_execute_option(raw_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, &service_data))
221 if (!service_create_request(service_data, &service))
223 notification_out->service = service;
227 *notification = notification_out;
229 return UI_NOTIFICATION_ERROR_NONE;
232 int ui_notification_destroy(ui_notification_h notification)
234 if (notification == NULL)
236 LOGE("INVALID_PARAMETER(0x%08x) : invalid handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
237 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
240 if (notification->raw_handle)
241 notification_free(notification->raw_handle);
243 if (notification->icon)
244 free(notification->icon);
246 if (notification->time)
247 free(notification->time);
249 if (notification->title)
250 free(notification->title);
252 if (notification->content)
253 free(notification->content);
255 if (notification->sound)
256 free(notification->sound);
258 if (notification->service)
259 service_destroy(notification->service);
263 return UI_NOTIFICATION_ERROR_NONE;
266 int ui_notification_get_id(ui_notification_h notification, int *id)
268 notification_h raw_handle = NULL;
270 if (notification == NULL || id == NULL)
272 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
273 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
275 if (notification->raw_handle == NULL)
277 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
278 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
281 raw_handle = notification->raw_handle;
282 if (notification_get_id(raw_handle, NULL, id) != NOTIFICATION_ERROR_NONE) {
283 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
284 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
287 return UI_NOTIFICATION_ERROR_NONE;
290 int ui_notification_clone(ui_notification_h *clone, ui_notification_h notification)
292 ui_notification_h notification_out;
295 if (clone == NULL || notification == NULL)
297 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
298 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
301 notification_out = (ui_notification_h)calloc(1, sizeof(struct ui_notification_s));
303 if (notification_out == NULL)
305 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
306 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
309 if (notification->raw_handle != NULL)
311 retcode = notification_clone(notification->raw_handle, &(notification_out->raw_handle));
315 free(notification_out);
316 return ui_notification_error_handler(retcode, __FUNCTION__, "failed to clone the handle");
320 notification_out->ongoing = notification->ongoing;
322 notification_out->posted = notification->posted;
324 notification_out->removed = notification->removed;
326 if (notification->icon)
328 notification_out->icon = strdup(notification->icon);
331 if (notification->time)
333 notification_out->time = malloc(sizeof(struct tm));
334 if (notification_out->time != NULL)
336 memcpy(notification_out->time, notification->time, sizeof(struct tm));
340 if (notification->title)
342 notification_out->title = strdup(notification->title);
345 if (notification->content)
347 notification_out->content = strdup(notification->content);
350 if (notification->sound)
352 notification_out->sound = strdup(notification->sound);
355 notification_out->vibration = notification->vibration;
357 if (notification->service)
359 service_clone(&(notification_out->service), notification->service);
362 *clone = notification_out;
364 return UI_NOTIFICATION_ERROR_NONE;
367 int ui_notification_is_ongoing(ui_notification_h notification, bool *ongoing)
369 if (notification == NULL || ongoing == NULL)
371 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
372 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
375 *ongoing = notification->ongoing;
377 return UI_NOTIFICATION_ERROR_NONE;
380 int ui_notification_set_icon(ui_notification_h notification, const char *path)
382 char *path_dup = NULL;
384 if (notification == NULL)
386 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
387 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
392 path_dup = strdup(path);
394 if (path_dup == NULL)
396 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
397 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
401 if (notification->icon != NULL)
403 free(notification->icon);
406 notification->icon = path_dup;
408 return UI_NOTIFICATION_ERROR_NONE;
411 int ui_notification_get_icon(ui_notification_h notification, char **path)
413 char *path_dup = NULL;
415 if (notification == NULL || path == NULL)
417 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
418 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
421 if (notification->icon != NULL)
423 path_dup = strdup(notification->icon);
425 if (path_dup == NULL)
427 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
428 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
434 return UI_NOTIFICATION_ERROR_NONE;
437 int ui_notification_set_time(ui_notification_h notification, struct tm *time)
439 struct tm *time_dup = NULL;
441 if (notification == NULL)
443 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
444 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
449 time_dup = malloc(sizeof(struct tm));
451 if (time_dup == NULL)
453 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
454 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
457 memcpy(time_dup, time, sizeof(struct tm));
460 if (notification->time != NULL)
462 free(notification->time);
465 notification->time = time_dup;
467 return UI_NOTIFICATION_ERROR_NONE;
470 int ui_notification_get_time(ui_notification_h notification, struct tm **time)
472 struct tm *time_dup = NULL;
474 if (notification == NULL || time == NULL)
476 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
477 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
480 if (notification->time != NULL)
482 time_dup = malloc(sizeof(struct tm));
484 if (time_dup == NULL)
486 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
487 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
490 memcpy(time_dup, notification->time, sizeof(struct tm));
495 return UI_NOTIFICATION_ERROR_NONE;
498 int ui_notification_set_title(ui_notification_h notification, const char *title)
500 char *title_dup = NULL;
502 if (notification == NULL)
504 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
505 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
510 title_dup = strdup(title);
512 if (title_dup == NULL)
514 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
515 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
519 if (notification->title != NULL)
521 free(notification->title);
524 notification->title = title_dup;
526 return UI_NOTIFICATION_ERROR_NONE;
529 int ui_notification_get_title(ui_notification_h notification, char **title)
531 char *title_dup = NULL;
533 if (notification == NULL || title == NULL)
535 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
536 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
539 if (notification->title != NULL)
541 title_dup = strdup(notification->title);
543 if (title_dup == NULL)
545 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
546 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
552 return UI_NOTIFICATION_ERROR_NONE;
556 int ui_notification_set_content(ui_notification_h notification, const char *content)
558 char *content_dup = NULL;
560 if (notification == NULL)
562 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
563 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
568 content_dup = strdup(content);
570 if (content_dup == NULL)
572 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
573 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
577 if (notification->content != NULL)
579 free(notification->content);
582 notification->content = content_dup;
584 return UI_NOTIFICATION_ERROR_NONE;
587 int ui_notification_get_content(ui_notification_h notification, char **content)
589 char *content_dup = NULL;
591 if (notification == NULL || content == NULL)
593 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
594 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
597 if (notification->content != NULL)
599 content_dup = strdup(notification->content);
601 if (content_dup == NULL)
603 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
604 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
608 *content = content_dup;
610 return UI_NOTIFICATION_ERROR_NONE;
614 int ui_notification_set_service(ui_notification_h notification, service_h service)
617 service_h service_dup = NULL;
619 if (notification == NULL)
621 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
622 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
627 retcode = service_clone(&service_dup, service);
629 if (retcode != SERVICE_ERROR_NONE)
631 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
633 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
634 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
638 LOGE("INVALID_PARAMETER(0x%08x) : invalid service handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
639 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
644 if (notification->service != NULL)
646 service_destroy(notification->service);
649 notification->service = service_dup;
651 return UI_NOTIFICATION_ERROR_NONE;
654 int ui_notification_get_service(ui_notification_h notification, service_h *service)
657 service_h service_dup = NULL;
659 if (notification == NULL || service == NULL)
661 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
662 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
665 if (notification->service != NULL)
667 retcode = service_clone(&service_dup, notification->service);
669 if (retcode != SERVICE_ERROR_NONE)
671 if (retcode == SERVICE_ERROR_OUT_OF_MEMORY)
673 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
674 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
678 LOGE("INVALID_PARAMETER(0x%08x) : invalid service handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
679 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
684 *service = service_dup;
686 return UI_NOTIFICATION_ERROR_NONE;
689 int ui_notification_set_sound(ui_notification_h notification, const char *path)
691 char *path_dup = NULL;
693 if (notification == NULL)
695 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
696 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
701 path_dup = strdup(path);
703 if (path_dup == NULL)
705 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
706 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
710 if (notification->sound != NULL)
712 free(notification->sound);
715 notification->sound = path_dup;
717 return UI_NOTIFICATION_ERROR_NONE;
720 int ui_notification_get_sound(ui_notification_h notification, char **path)
722 char *path_dup = NULL;
724 if (notification == NULL || path == NULL)
726 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
727 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
730 if (notification->sound != NULL)
732 path_dup = strdup(notification->sound);
734 if (path_dup == NULL)
736 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
739 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
745 return UI_NOTIFICATION_ERROR_NONE;
748 int ui_notification_set_vibration(ui_notification_h notification, bool value)
750 if (notification == NULL)
752 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
753 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
756 notification->vibration = value;
758 return UI_NOTIFICATION_ERROR_NONE;
761 int ui_notification_get_vibration(ui_notification_h notification, bool *value)
763 if (notification == NULL || value == NULL)
765 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
766 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
769 *value = notification->vibration;
771 return UI_NOTIFICATION_ERROR_NONE;
774 static int ui_notification_build_attributes(ui_notification_h notification)
776 bundle *service_data;
778 if (notification == NULL)
780 LOGE("INVALID_PARAMETER(0x%08x) : invalid handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
781 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
784 if (notification->icon != NULL)
788 if (stat(notification->icon, &st) < 0)
790 LOGE("NO_SUCH_FILE(0x%08x) : invalid icon", UI_NOTIFICATION_ERROR_NO_SUCH_FILE);
791 return UI_NOTIFICATION_ERROR_NO_SUCH_FILE;
794 notification_set_image(notification->raw_handle, NOTIFICATION_IMAGE_TYPE_ICON, notification->icon);
797 if (notification->time != NULL)
799 notification_set_time(notification->raw_handle, mktime(notification->time));
802 if (notification->title != NULL)
804 notification_set_text(notification->raw_handle, NOTIFICATION_TEXT_TYPE_TITLE, notification->title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
807 if (notification->content != NULL)
809 notification_set_text(notification->raw_handle, NOTIFICATION_TEXT_TYPE_CONTENT, notification->content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
812 if (notification->service != NULL && service_to_bundle(notification->service, &service_data) == SERVICE_ERROR_NONE)
814 notification_set_property(notification->raw_handle, 0);
815 notification_set_execute_option(notification->raw_handle, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
819 notification_set_property(notification->raw_handle, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
822 if (notification->sound != NULL)
826 if (stat(notification->sound, &st) < 0)
828 LOGE("NO_SUCH_FILE(0x%08x) : invalid sound file", UI_NOTIFICATION_ERROR_NO_SUCH_FILE);
829 return UI_NOTIFICATION_ERROR_NO_SUCH_FILE;
831 notification_set_sound(notification->raw_handle, NOTIFICATION_SOUND_TYPE_USER_DATA, notification->sound);
834 if (notification->vibration)
836 notification_set_vibration(notification->raw_handle, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
839 return UI_NOTIFICATION_ERROR_NONE;
842 int ui_notification_post(ui_notification_h notification)
846 if (notification == NULL)
848 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
849 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
852 if (notification->posted == true)
854 LOGE("INVALID_STATE(0x%08x) : the notification was already posted", UI_NOTIFICATION_ERROR_INVALID_STATE);
855 return UI_NOTIFICATION_ERROR_INVALID_STATE;
858 if (notification->ongoing == true)
860 notification->raw_handle = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
864 notification->raw_handle = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
867 if (notification->raw_handle == NULL)
869 LOGE("OUT_OF_MEMORY(0x%08x)", UI_NOTIFICATION_ERROR_OUT_OF_MEMORY);
870 return UI_NOTIFICATION_ERROR_OUT_OF_MEMORY;
873 retcode = ui_notification_build_attributes(notification);
875 if (retcode != UI_NOTIFICATION_ERROR_NONE)
880 retcode = ui_notification_error_handler(notification_insert(notification->raw_handle, NULL), __FUNCTION__, "failed to post a notification");
882 if (retcode == UI_NOTIFICATION_ERROR_NONE)
884 notification->posted = true;
890 int ui_notification_update(ui_notification_h notification)
894 if (notification == NULL)
896 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
897 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
900 if (notification->posted == false)
902 LOGE("INVALID_STATE(0x%08x) : the notification was not posted", UI_NOTIFICATION_ERROR_INVALID_STATE);
903 return UI_NOTIFICATION_ERROR_INVALID_STATE;
906 if (notification->removed == true)
908 LOGE("INVALID_STATE(0x%08x) : the notification was canceled or cleared", UI_NOTIFICATION_ERROR_INVALID_STATE);
909 return UI_NOTIFICATION_ERROR_INVALID_STATE;
912 retcode = ui_notification_build_attributes(notification);
914 if (retcode != UI_NOTIFICATION_ERROR_NONE)
919 retcode = ui_notification_error_handler(notification_update(notification->raw_handle), __FUNCTION__, "failed to post a notification");
921 if (retcode == UI_NOTIFICATION_ERROR_INVALID_STATE)
923 notification->removed = true;
929 int ui_notification_update_progress(ui_notification_h notification, ui_notification_progress_type_e type, double value)
933 if (notification == NULL)
935 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
936 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
939 if (notification->raw_handle == NULL)
941 LOGE("INVALID_PARAMETER(0x%08x) : invalid handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
942 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
945 if (notification->posted == false)
947 LOGE("INVALID_STATE(0x%08x) : the notification was not posted", UI_NOTIFICATION_ERROR_INVALID_STATE);
948 return UI_NOTIFICATION_ERROR_INVALID_STATE;
951 if (notification->removed == true)
953 LOGE("INVALID_STATE(0x%08x) : the notification was canceled or cleared", UI_NOTIFICATION_ERROR_INVALID_STATE);
954 return UI_NOTIFICATION_ERROR_INVALID_STATE;
959 LOGE("INVALID_PARAMETER(0x%08x) : the value must be greater than or equal to zero.", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
960 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
965 case UI_NOTIFICATION_PROGRESS_TYPE_SIZE:
966 retcode = ui_notification_error_handler(
967 notification_update_size(notification->raw_handle, NOTIFICATION_PRIV_ID_NONE, value),
968 __FUNCTION__, "failed to update the progress");
971 case UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE:
972 retcode = ui_notification_error_handler(
973 notification_update_progress(notification->raw_handle, NOTIFICATION_PRIV_ID_NONE, value),
974 __FUNCTION__, "failed to update the progress");
978 LOGE("INVALID_PARAMETER(0x%08x) : invalid progress type", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
979 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
982 if (retcode == UI_NOTIFICATION_ERROR_INVALID_STATE)
984 notification->removed = true;
990 int ui_notification_cancel(ui_notification_h notification)
994 if (notification == NULL)
996 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
997 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
1000 if (notification->raw_handle == NULL)
1002 LOGE("INVALID_PARAMETER(0x%08x) : invalid handle", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
1003 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
1006 if (notification->posted == false)
1008 LOGE("INVALID_STATE(0x%08x) : the notification was not posted", UI_NOTIFICATION_ERROR_INVALID_STATE);
1009 return UI_NOTIFICATION_ERROR_INVALID_STATE;
1012 if (notification->removed == true)
1014 LOGE("INVALID_STATE(0x%08x) : the notification was canceled or cleared", UI_NOTIFICATION_ERROR_INVALID_STATE);
1015 return UI_NOTIFICATION_ERROR_INVALID_STATE;
1018 retcode = ui_notification_error_handler(notification_delete(notification->raw_handle), __FUNCTION__, "failed to cancel the notification");
1020 if (retcode == UI_NOTIFICATION_ERROR_NONE)
1022 notification->removed = true;
1028 void ui_notification_cancel_all(void)
1030 notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NONE);
1033 void ui_notification_cancel_all_by_type(bool ongoing)
1035 notification_type_e type = NOTIFICATION_TYPE_NONE;
1038 type = NOTIFICATION_TYPE_ONGOING;
1040 type = NOTIFICATION_TYPE_NOTI;
1042 notification_delete_all_by_type(NULL, type);
1045 void ui_notification_cancel_all_by_package(const char *package, bool ongoing)
1047 notification_type_e type = NOTIFICATION_TYPE_NONE;
1050 type = NOTIFICATION_TYPE_ONGOING;
1052 type = NOTIFICATION_TYPE_NOTI;
1054 notification_delete_all_by_type(package, type);
1057 int ui_notification_cancel_all_by_app_id(const char *app_id, bool ongoing)
1059 notification_type_e type = NOTIFICATION_TYPE_NONE;
1063 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
1064 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
1068 type = NOTIFICATION_TYPE_ONGOING;
1070 type = NOTIFICATION_TYPE_NOTI;
1072 notification_delete_all_by_type(app_id, type);
1074 return UI_NOTIFICATION_ERROR_NONE;
1077 static bool ui_notification_package_equal(notification_h handle)
1079 char *package = NULL;
1080 char *handle_package = NULL;
1081 char cmdline[512] = {0,};
1082 char buf[64] = {0,};
1084 if (notification_get_pkgname(handle, &handle_package))
1089 if (app_get_package(&package))
1095 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
1097 fd = open(buf, O_RDONLY);
1102 ret = read(fd, cmdline, sizeof(cmdline) - 1);
1111 if (strlen(cmdline) == strlen(handle_package))
1113 if (!strncmp(cmdline, handle_package, strlen(cmdline)))
1121 if (strlen(package) == strlen(handle_package))
1123 if (!strncmp(package, handle_package, strlen(package)))
1133 int ui_notification_foreach_notification_posted(bool ongoing, ui_notification_cb callback, void *user_data)
1135 notification_list_h raw_handle_list;
1136 notification_h raw_handle;
1137 notification_type_e notification_type = ongoing ? NOTIFICATION_TYPE_ONGOING : NOTIFICATION_TYPE_NOTI;
1138 ui_notification_h notification = NULL;
1139 bool iterate_next = true;
1141 if (callback == NULL)
1143 LOGE("INVALID_PARAMETER(0x%08x)", UI_NOTIFICATION_ERROR_INVALID_PARAMETER);
1144 return UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
1147 if (notification_get_grouping_list(notification_type, -1, &raw_handle_list))
1149 LOGE("DB_FAILED(0x%08x) : failed to get a notification list", UI_NOTIFICATION_ERROR_DB_FAILED);
1150 return UI_NOTIFICATION_ERROR_DB_FAILED;
1153 while (raw_handle_list != NULL)
1155 raw_handle = notification_list_get_data(raw_handle_list);
1157 if (raw_handle != NULL && ui_notification_package_equal(raw_handle))
1159 if (!ui_notification_construct(ongoing, raw_handle, ¬ification))
1161 iterate_next = callback(notification, user_data);
1163 ui_notification_destroy(notification);
1165 if (iterate_next == false)
1172 raw_handle_list = notification_list_get_next(raw_handle_list);
1175 notification_free_list(raw_handle_list);
1177 return UI_NOTIFICATION_ERROR_NONE;