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 <Elementary.h>
30 #include <pkgmgr-info.h>
31 #include <package_manager.h>
33 #include <notification.h>
34 #include <notification_db.h>
35 #include <notification_list.h>
36 #include <notification_noti.h>
37 #include <notification_debug.h>
38 #include <notification_private.h>
39 #include <notification_setting.h>
40 #include <notification_setting_internal.h>
42 #define NOTI_BURST_DELETE_UNIT 10
44 static void __free_and_set(void **target_ptr, void *new_ptr) {
45 if (target_ptr != NULL) {
46 if (*target_ptr != NULL) {
49 *target_ptr = new_ptr;
53 static int _notification_noti_bind_query_text(sqlite3_stmt * stmt, const char *name,
59 index = sqlite3_bind_parameter_index(stmt, name);
61 NOTIFICATION_ERR("Insert : invalid column name");
62 return NOTIFICATION_ERROR_FROM_DB;
66 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
68 if (ret != SQLITE_OK) {
69 NOTIFICATION_ERR("Insert text : %s",
70 NOTIFICATION_CHECK_STR(str));
71 return NOTIFICATION_ERROR_FROM_DB;
74 return NOTIFICATION_ERROR_NONE;
77 static int _notification_noti_bind_query_double(sqlite3_stmt * stmt, const char *name,
83 index = sqlite3_bind_parameter_index(stmt, name);
85 NOTIFICATION_ERR("Insert : invalid column name");
86 return NOTIFICATION_ERROR_FROM_DB;
89 ret = sqlite3_bind_double(stmt, index, val);
90 if (ret != SQLITE_OK) {
91 NOTIFICATION_ERR("Insert double : %f", val);
92 return NOTIFICATION_ERROR_FROM_DB;
95 return NOTIFICATION_ERROR_NONE;
98 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
101 int ret = NOTIFICATION_ERROR_NONE;
103 sqlite3_stmt *stmt = NULL;
105 /* Make query to check priv_id exist */
106 query = sqlite3_mprintf("SELECT count(*) FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
107 noti->caller_pkgname, noti->priv_id);
109 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
113 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
114 if (ret != SQLITE_OK) {
115 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
117 ret = NOTIFICATION_ERROR_FROM_DB;
121 ret = sqlite3_step(stmt);
122 if (ret == SQLITE_ROW) {
123 result = sqlite3_column_int(stmt, 0);
128 sqlite3_finalize(stmt);
130 /* If result > 0, there is priv_id in DB */
132 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
143 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
148 sqlite3_stmt *stmt = NULL;
149 int ret = NOTIFICATION_ERROR_NONE, result = 0;
151 query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
154 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
158 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
159 if (ret != SQLITE_OK) {
160 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
162 ret = NOTIFICATION_ERROR_FROM_DB;
166 ret = sqlite3_step(stmt);
167 if (ret == SQLITE_ROW) {
168 result = sqlite3_column_int(stmt, 0);
175 sqlite3_finalize(stmt);
182 if (ret != NOTIFICATION_ERROR_NONE) {
183 NOTIFICATION_ERR("failed to internal group ID:%d", ret);
189 static int _insertion_query_create(notification_h noti, char **query)
192 int b_encode_len = 0;
194 char *group_args = NULL;
195 char *b_image_path = NULL;
196 char *b_execute_option = NULL;
197 char *b_service_responding = NULL;
198 char *b_service_single_launch = NULL;
199 char *b_service_multi_launch = NULL;
200 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
203 char *b_format_args = NULL;
204 int flag_simmode = 0;
207 return NOTIFICATION_ERROR_INVALID_PARAMETER;
210 /* Decode bundle to insert DB */
212 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
214 if (noti->group_args) {
215 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
219 if (noti->b_execute_option) {
220 bundle_encode(noti->b_execute_option,
221 (bundle_raw **) & b_execute_option, &b_encode_len);
223 if (noti->b_service_responding) {
224 bundle_encode(noti->b_service_responding,
225 (bundle_raw **) & b_service_responding, &b_encode_len);
227 if (noti->b_service_single_launch) {
228 bundle_encode(noti->b_service_single_launch,
229 (bundle_raw **) & b_service_single_launch, &b_encode_len);
231 if (noti->b_service_multi_launch) {
232 bundle_encode(noti->b_service_multi_launch,
233 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
236 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
237 if (noti->b_event_handler[i]) {
238 bundle_encode(noti->b_event_handler[i],
239 (bundle_raw **) & b_event_handler[i], &b_encode_len);
244 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
247 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
249 if (noti->b_format_args) {
250 bundle_encode(noti->b_format_args,
251 (bundle_raw **) & b_format_args, &b_encode_len);
254 if (noti->b_image_path) {
255 bundle_encode(noti->b_image_path,
256 (bundle_raw **) & b_image_path, &b_encode_len);
259 /* Check only simmode property is enable */
260 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
265 *query = sqlite3_mprintf("INSERT INTO noti_list ("
268 "caller_pkgname, launch_pkgname, "
270 "group_id, internal_group_id, priv_id, "
272 "b_text, b_key, tag, b_format_args, num_format_args, "
273 "text_domain, text_dir, "
274 "time, insert_time, "
277 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
278 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
279 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
280 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
281 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
282 "flags_for_property, flag_simmode, display_applist, "
283 "progress_size, progress_percentage, ongoing_flag, auto_remove) values ("
290 "'%s', '%s', $tag, '%s', %d, "
299 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
301 "$progress_size, $progress_percentage, %d, %d)",
304 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
305 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
306 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
307 noti->internal_group_id, noti->priv_id,
308 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
309 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
310 NOTIFICATION_CHECK_STR(noti->domain),
311 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
312 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
313 NOTIFICATION_CHECK_STR(group_args),
314 NOTIFICATION_CHECK_STR(b_execute_option),
315 NOTIFICATION_CHECK_STR(b_service_responding),
316 NOTIFICATION_CHECK_STR(b_service_single_launch),
317 NOTIFICATION_CHECK_STR(b_service_multi_launch),
318 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
319 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
320 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
321 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
322 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
323 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
324 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
325 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
326 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
327 noti->vibration_type,
328 NOTIFICATION_CHECK_STR(noti->vibration_path),
333 noti->flags_for_property, flag_simmode, noti->display_applist,
337 /* Free decoded data */
345 if (b_execute_option) {
346 free(b_execute_option);
348 if (b_service_responding) {
349 free(b_service_responding);
351 if (b_service_single_launch) {
352 free(b_service_single_launch);
354 if (b_service_multi_launch) {
355 free(b_service_multi_launch);
372 if (*query == NULL) {
373 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
376 return NOTIFICATION_ERROR_NONE;
380 static int _update_query_create(notification_h noti, char **query)
383 int b_encode_len = 0;
385 char *group_args = NULL;
386 char *b_image_path = NULL;
387 char *b_execute_option = NULL;
388 char *b_service_responding = NULL;
389 char *b_service_single_launch = NULL;
390 char *b_service_multi_launch = NULL;
391 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
394 char *b_format_args = NULL;
395 int flag_simmode = 0;
398 return NOTIFICATION_ERROR_INVALID_PARAMETER;
401 /* Decode bundle to update DB */
403 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
405 if (noti->group_args) {
406 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
410 if (noti->b_execute_option) {
411 bundle_encode(noti->b_execute_option,
412 (bundle_raw **) & b_execute_option, &b_encode_len);
414 if (noti->b_service_responding) {
415 bundle_encode(noti->b_service_responding,
416 (bundle_raw **) & b_service_responding, &b_encode_len);
418 if (noti->b_service_single_launch) {
419 bundle_encode(noti->b_service_single_launch,
420 (bundle_raw **) & b_service_single_launch, &b_encode_len);
422 if (noti->b_service_multi_launch) {
423 bundle_encode(noti->b_service_multi_launch,
424 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
427 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
428 if (noti->b_event_handler[i]) {
429 bundle_encode(noti->b_event_handler[i],
430 (bundle_raw **) & b_event_handler[i], &b_encode_len);
435 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
438 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
440 if (noti->b_format_args) {
441 bundle_encode(noti->b_format_args,
442 (bundle_raw **) & b_format_args, &b_encode_len);
445 if (noti->b_image_path) {
446 bundle_encode(noti->b_image_path,
447 (bundle_raw **) & b_image_path, &b_encode_len);
450 /* Check only simmode property is enable */
451 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
456 *query = sqlite3_mprintf("UPDATE noti_list SET "
459 "launch_pkgname = '%s', "
460 "image_path = '%s', "
461 "b_text = '%s', b_key = '%s', tag = $tag, "
462 "b_format_args = '%s', num_format_args = %d, "
463 "text_domain = '%s', text_dir = '%s', "
464 "time = %d, insert_time = %d, "
465 "args = '%s', group_args = '%s', "
466 "b_execute_option = '%s', "
467 "b_service_responding = '%s', "
468 "b_service_single_launch = '%s', "
469 "b_service_multi_launch = '%s', "
470 "b_event_handler_click_on_button_1 = '%s', "
471 "b_event_handler_click_on_button_2= '%s', "
472 "b_event_handler_click_on_button_3= '%s', "
473 "b_event_handler_click_on_button_4= '%s', "
474 "b_event_handler_click_on_button_5= '%s', "
475 "b_event_handler_click_on_button_6= '%s', "
476 "b_event_handler_click_on_icon= '%s', "
477 "b_event_handler_click_on_thumbnail= '%s', "
478 "sound_type = %d, sound_path = '%s', "
479 "vibration_type = %d, vibration_path = '%s', "
480 "led_operation = %d, led_argb = %d, "
481 "led_on_ms = %d, led_off_ms = %d, "
482 "flags_for_property = %d, flag_simmode = %d, "
483 "display_applist = %d, "
484 "progress_size = $progress_size, progress_percentage = $progress_percentage, "
485 "ongoing_flag = %d, auto_remove = %d "
486 "where priv_id = %d ",
489 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
490 NOTIFICATION_CHECK_STR(b_image_path),
491 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
492 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
493 NOTIFICATION_CHECK_STR(noti->domain),
494 NOTIFICATION_CHECK_STR(noti->dir),
495 (int)noti->time, (int)noti->insert_time,
496 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
497 NOTIFICATION_CHECK_STR(b_execute_option),
498 NOTIFICATION_CHECK_STR(b_service_responding),
499 NOTIFICATION_CHECK_STR(b_service_single_launch),
500 NOTIFICATION_CHECK_STR(b_service_multi_launch),
501 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
502 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
503 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
504 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
505 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
506 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
507 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
508 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
509 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
510 noti->vibration_type,
511 NOTIFICATION_CHECK_STR(noti->vibration_path),
516 noti->flags_for_property, flag_simmode, noti->display_applist,
517 noti->ongoing_flag, noti->auto_remove,
520 /* Free decoded data */
528 if (b_execute_option) {
529 free(b_execute_option);
531 if (b_service_responding) {
532 free(b_service_responding);
534 if (b_service_single_launch) {
535 free(b_service_single_launch);
537 if (b_service_multi_launch) {
538 free(b_service_multi_launch);
555 if (*query == NULL) {
556 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
559 return NOTIFICATION_ERROR_NONE;
562 static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) {
566 if (stmt == NULL || noti == NULL) {
570 noti->type = sqlite3_column_int(stmt, col++);
571 noti->layout = sqlite3_column_int(stmt, col++);
572 __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
573 __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
574 noti->b_image_path = notification_db_column_bundle(stmt, col++);
575 noti->group_id = sqlite3_column_int(stmt, col++);
576 noti->internal_group_id = 0;
577 noti->priv_id = sqlite3_column_int(stmt, col++);
578 __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
580 noti->b_text = notification_db_column_bundle(stmt, col++);
581 noti->b_key = notification_db_column_bundle(stmt, col++);
582 noti->b_format_args = notification_db_column_bundle(stmt, col++);
583 noti->num_format_args = sqlite3_column_int(stmt, col++);
585 __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
586 __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
587 noti->time = sqlite3_column_int(stmt, col++);
588 noti->insert_time = sqlite3_column_int(stmt, col++);
589 noti->args = notification_db_column_bundle(stmt, col++);
590 noti->group_args = notification_db_column_bundle(stmt, col++);
592 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
593 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
594 noti->b_service_single_launch =
595 notification_db_column_bundle(stmt, col++);
596 noti->b_service_multi_launch =
597 notification_db_column_bundle(stmt, col++);
599 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
600 noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
603 noti->sound_type = sqlite3_column_int(stmt, col++);
604 __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
605 noti->vibration_type = sqlite3_column_int(stmt, col++);
606 __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
607 noti->led_operation = sqlite3_column_int(stmt, col++);
608 noti->led_argb = sqlite3_column_int(stmt, col++);
609 noti->led_on_ms = sqlite3_column_int(stmt, col++);
610 noti->led_off_ms = sqlite3_column_int(stmt, col++);
612 noti->flags_for_property = sqlite3_column_int(stmt, col++);
613 noti->display_applist = sqlite3_column_int(stmt, col++);
614 noti->progress_size = sqlite3_column_double(stmt, col++);
615 noti->progress_percentage = sqlite3_column_double(stmt, col++);
617 noti->ongoing_flag = sqlite3_column_int(stmt, col++);
618 noti->auto_remove = sqlite3_column_int(stmt, col++);
620 noti->app_icon_path = NULL;
621 noti->app_name = NULL;
622 noti->temp_title = NULL;
623 noti->temp_content = NULL;
626 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
628 notification_h noti = NULL;
630 noti = (notification_h) calloc(1, sizeof(struct _notification));
635 _notification_noti_populate_from_stmt(stmt, noti);
640 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
644 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
646 if (buf_len <= len_total)
647 return NOTIFICATION_ERROR_INVALID_PARAMETER;
649 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
651 return NOTIFICATION_ERROR_NONE;
654 char *notification_noti_strip_tag(const char *tagged_str)
656 if (tagged_str == NULL)
659 int len_total = strlen(tagged_str);
664 char *b_f_e = strstr(tagged_str, ">");
665 char *b_e_s = strstr(tagged_str, "</");
667 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
670 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
673 int notification_noti_get_tag_type(const char *tagged_str)
675 if (tagged_str == NULL)
676 return TAG_TYPE_INVALID;
678 if (strlen(tagged_str)== 0)
679 return TAG_TYPE_INVALID;
681 char *b_f_s = strstr(tagged_str, "<");
682 char *b_f_e = strstr(tagged_str, ">");
684 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
685 return TAG_TYPE_INVALID;
687 char *start = b_f_s + 1;
688 int len_tag = b_f_e - b_f_s - 1;
690 if (strncmp(start,TAG_TIME,len_tag) == 0) {
691 return TAG_TYPE_TIME;
694 return TAG_TYPE_INVALID;
697 static int _notification_noti_update_priv_id(sqlite3 * db, int rowid)
699 int ret = NOTIFICATION_ERROR_NONE;
703 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
707 query = sqlite3_mprintf("UPDATE noti_list SET "
708 "priv_id = %d, internal_group_id = %d WHERE rowid = %d",
709 rowid, rowid, rowid);
711 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
715 ret = notification_db_exec(db, query, NULL);
726 static int _get_package_id_by_app_id(const char *app_id, char **package_id)
728 int err = NOTIFICATION_ERROR_NONE;
731 char *pkg_id_dup = NULL;
732 pkgmgrinfo_appinfo_h pkgmgrinfo_appinfo = NULL;
734 if (app_id == NULL || package_id == NULL) {
735 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
736 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
740 if ((retval = pkgmgrinfo_appinfo_get_appinfo(app_id, &pkgmgrinfo_appinfo)) != PMINFO_R_OK) {
741 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_appinfo failed [%d]", retval);
742 err = NOTIFICATION_ERROR_INVALID_OPERATION;
746 if ((retval = pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo, &pkg_id)) != PMINFO_R_OK || pkg_id == NULL) {
747 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_pkgname failed [%d]", retval);
748 err = NOTIFICATION_ERROR_INVALID_OPERATION;
752 pkg_id_dup = strdup(pkg_id);
754 if (pkg_id_dup == NULL) {
755 NOTIFICATION_ERR("strdup failed");
756 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
760 *package_id = pkg_id_dup;
763 if (pkgmgrinfo_appinfo)
764 pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
769 static bool _is_allowed_to_notify(const char *caller_package_name)
771 notification_setting_h setting = NULL;
773 char *package_id = NULL;
776 err = notification_setting_get_setting_by_package_name(caller_package_name, &setting);
777 if (err != NOTIFICATION_ERROR_NONE) {
778 /* Retry with package id */
779 err = _get_package_id_by_app_id (caller_package_name, &package_id);
781 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
782 NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
786 err = notification_setting_get_setting_by_package_name(package_id, &setting);
787 if (err != NOTIFICATION_ERROR_NONE) {
788 NOTIFICATION_ERR("notification_setting_get_setting_by_package_name failed [%d]", err);
794 err = notification_setting_get_allow_to_notify(setting, &ret);
795 if (err != NOTIFICATION_ERROR_NONE) {
796 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
801 NOTIFICATION_DBG("[%s] is not allowed to notify", caller_package_name);
810 notification_setting_free_notification(setting);
816 static int _handle_do_not_disturb_option(notification_h noti)
818 int err = NOTIFICATION_ERROR_NONE;
819 bool do_not_disturb = false;
820 bool do_not_disturb_exception = false;
821 char *package_id = NULL;
822 notification_system_setting_h system_setting = NULL;
823 notification_setting_h setting = NULL;
826 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
827 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
831 /* Get system setting */
832 if ((err = notification_system_setting_load_system_setting(&system_setting)) != NOTIFICATION_ERROR_NONE) {
833 NOTIFICATION_ERR("notification_system_setting_load_system_setting failed [%d]", err);
837 if ((err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb)) != NOTIFICATION_ERROR_NONE) {
838 NOTIFICATION_ERR("notification_system_setting_get_do_not_disturb failed [%d]", err);
842 NOTIFICATION_DBG("do_not_disturb [%d]", do_not_disturb);
844 if (do_not_disturb) {
845 /* Check exception option of the caller package */
846 err = notification_setting_get_setting_by_package_name(noti->caller_pkgname, &setting);
848 if (err != NOTIFICATION_ERROR_NONE) {
849 /* Retry with package id */
850 err = _get_package_id_by_app_id (noti->caller_pkgname, &package_id);
852 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
853 NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
857 err = notification_setting_get_setting_by_package_name(package_id, &setting);
858 if (err != NOTIFICATION_ERROR_NONE) {
859 NOTIFICATION_ERR("notification_setting_get_setting_by_package_name failed [%d]", err);
865 err = notification_setting_get_do_not_disturb_except(setting, &do_not_disturb_exception);
866 if (err != NOTIFICATION_ERROR_NONE) {
867 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
871 if (do_not_disturb_exception == false) {
872 /* do_not_disturb is ON and do_not_disturb_exception is OFF */
873 /* Then add this notification only on quick panel and indicator*/
874 noti->display_applist = noti->display_applist & (NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR);
875 /* and reset all sound and vibration and led options*/
876 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
877 SAFE_FREE(noti->sound_path);
878 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
879 SAFE_FREE(noti->vibration_path);
880 noti->led_operation = NOTIFICATION_LED_OP_OFF;
883 noti->led_off_ms = 0;
889 SAFE_FREE(package_id);
891 if (system_setting) {
892 notification_system_setting_free_system_setting(system_setting);
896 notification_setting_free_notification(setting);
902 EXPORT_API int notification_noti_insert(notification_h noti)
906 sqlite3_stmt *stmt = NULL;
908 char buf_key[32] = { 0, };
909 char *title_key = NULL;
912 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
913 return NOTIFICATION_ERROR_INVALID_PARAMETER;
916 if (_is_allowed_to_notify((const char*)noti->caller_pkgname) == false) {
917 NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
918 return NOTIFICATION_ERROR_PERMISSION_DENIED;
921 if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE) {
922 NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
926 db = notification_db_open(DBPATH);
928 return get_last_result();
931 /* Initialize private ID */
932 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
933 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
934 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
937 ret = _insertion_query_create(noti, &query);
938 if (ret != NOTIFICATION_ERROR_NONE) {
942 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
943 if (ret != SQLITE_OK) {
944 NOTIFICATION_ERR("Insert Query : %s", query);
945 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
947 ret = NOTIFICATION_ERROR_FROM_DB;
952 if (noti->b_key != NULL) {
953 snprintf(buf_key, sizeof(buf_key), "%d",
954 NOTIFICATION_TEXT_TYPE_TITLE);
956 bundle_get_str(noti->b_key, buf_key, &title_key);
959 if (title_key == NULL && noti->b_text != NULL) {
960 snprintf(buf_key, sizeof(buf_key), "%d",
961 NOTIFICATION_TEXT_TYPE_TITLE);
963 bundle_get_str(noti->b_text, buf_key, &title_key);
966 if (title_key == NULL) {
967 title_key = noti->caller_pkgname;
971 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
972 if (ret != NOTIFICATION_ERROR_NONE) {
973 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
976 ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
977 if (ret != NOTIFICATION_ERROR_NONE) {
978 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
981 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
982 if (ret != NOTIFICATION_ERROR_NONE) {
983 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
985 sqlite3_finalize(stmt);
989 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
990 if (ret != NOTIFICATION_ERROR_NONE) {
991 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
993 sqlite3_finalize(stmt);
998 ret = sqlite3_step(stmt);
999 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
1000 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
1001 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0) {
1002 ret = NOTIFICATION_ERROR_NONE;
1004 ret = NOTIFICATION_ERROR_FROM_DB;
1007 ret = NOTIFICATION_ERROR_FROM_DB;
1011 sqlite3_finalize(stmt);
1016 notification_db_close(&db);
1020 sqlite3_free(query);
1026 int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
1031 sqlite3_stmt *stmt = NULL;
1033 if (priv_id < 0 || noti == NULL) {
1034 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
1039 db = notification_db_open(DBPATH);
1041 return get_last_result();
1044 char *base_query = "select "
1045 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1046 "tag, b_text, b_key, b_format_args, num_format_args, "
1047 "text_domain, text_dir, time, insert_time, args, group_args, "
1048 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1049 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1050 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1051 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1052 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1053 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1056 if (pkgname != NULL) {
1057 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d",
1058 base_query ,pkgname, priv_id);
1060 query = sqlite3_mprintf("%s where priv_id = %d", base_query, priv_id);
1062 if (query == NULL) {
1063 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1067 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1068 if (ret != SQLITE_OK) {
1069 NOTIFICATION_ERR("select Query : %s", query);
1070 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
1071 sqlite3_errmsg(db));
1072 ret = NOTIFICATION_ERROR_FROM_DB;
1076 ret = sqlite3_step(stmt);
1077 if (ret == SQLITE_ROW) {
1078 _notification_noti_populate_from_stmt(stmt, noti);
1079 ret = NOTIFICATION_ERROR_NONE;
1081 ret = NOTIFICATION_ERROR_FROM_DB;
1085 sqlite3_free(query);
1089 sqlite3_finalize(stmt);
1094 notification_db_close(&db);
1100 EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag)
1104 sqlite3_stmt *stmt = NULL;
1106 if (tag == NULL || noti == NULL) {
1107 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
1112 db = notification_db_open(DBPATH);
1114 return get_last_result();
1117 if (pkgname != NULL) {
1118 ret = sqlite3_prepare_v2(db, "select "
1119 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1120 "tag, b_text, b_key, b_format_args, num_format_args, "
1121 "text_domain, text_dir, time, insert_time, args, group_args, "
1122 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1123 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1124 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1125 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1126 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1127 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1128 "from noti_list where caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1129 if (ret != SQLITE_OK) {
1130 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1131 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1134 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
1135 if (ret != SQLITE_OK) {
1136 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1140 ret = sqlite3_bind_text(stmt, 2, tag, -1, SQLITE_TRANSIENT);
1141 if (ret != SQLITE_OK) {
1142 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1146 ret = sqlite3_prepare_v2(db, "select "
1147 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1148 "tag, b_text, b_key, b_format_args, num_format_args, "
1149 "text_domain, text_dir, time, insert_time, args, group_args, "
1150 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1151 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1152 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1153 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1154 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1155 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1156 "from noti_list where tag = ?", -1, &stmt, NULL);
1157 if (ret != SQLITE_OK) {
1158 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1159 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1162 ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
1163 if (ret != SQLITE_OK) {
1164 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1169 ret = sqlite3_step(stmt);
1170 if (ret == SQLITE_ROW) {
1171 _notification_noti_populate_from_stmt(stmt, noti);
1172 ret = NOTIFICATION_ERROR_NONE;
1174 ret = NOTIFICATION_ERROR_FROM_DB;
1180 sqlite3_finalize(stmt);
1185 notification_db_close(&db);
1191 EXPORT_API int notification_noti_update(notification_h noti)
1195 sqlite3_stmt *stmt = NULL;
1199 db = notification_db_open(DBPATH);
1201 return get_last_result();
1204 if (_is_allowed_to_notify((const char*)noti->caller_pkgname) == false) {
1205 NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
1206 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1209 if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE) {
1210 NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
1213 /* Check private ID is exist */
1214 ret = _notification_noti_check_priv_id(noti, db);
1215 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
1216 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1220 /* make update query */
1221 ret = _update_query_create(noti, &query);
1222 if (ret != NOTIFICATION_ERROR_NONE) {
1226 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1227 if (ret != SQLITE_OK) {
1228 NOTIFICATION_ERR("Insert Query : %s", query);
1229 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
1230 sqlite3_errmsg(db));
1231 ret = NOTIFICATION_ERROR_FROM_DB;
1235 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
1236 if (ret != NOTIFICATION_ERROR_NONE) {
1237 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1240 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
1241 if (ret != NOTIFICATION_ERROR_NONE) {
1242 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1245 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
1246 if (ret != NOTIFICATION_ERROR_NONE) {
1247 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1251 ret = sqlite3_step(stmt);
1252 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
1253 ret = NOTIFICATION_ERROR_NONE;
1255 ret = NOTIFICATION_ERROR_FROM_DB;
1259 sqlite3_finalize(stmt);
1264 notification_db_close(&db);
1268 sqlite3_free(query);
1274 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
1276 int ret = NOTIFICATION_ERROR_NONE;
1277 int ret_tmp = NOTIFICATION_ERROR_NONE;
1278 int i = 0, data_cnt = 0;
1280 sqlite3_stmt *stmt = NULL;
1281 char buf[128] = { 0, };
1282 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1283 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1284 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1287 db = notification_db_open(DBPATH);
1289 return get_last_result();
1292 if (pkgname == NULL) {
1293 if (type != NOTIFICATION_TYPE_NONE) {
1294 snprintf(query_where, sizeof(query_where),
1295 "where type = %d ", type);
1298 if (type == NOTIFICATION_TYPE_NONE) {
1299 snprintf(query_where, sizeof(query_where),
1300 "where caller_pkgname = '%s' ", pkgname);
1302 snprintf(query_where, sizeof(query_where),
1303 "where caller_pkgname = '%s' and type = %d ",
1308 if (num_deleted != NULL) {
1311 if (list_deleted_rowid != NULL) {
1312 *list_deleted_rowid = NULL;
1313 snprintf(query, sizeof(query),
1314 "select priv_id from noti_list %s ", query_where);
1316 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1317 if (ret != SQLITE_OK) {
1318 NOTIFICATION_ERR("Select Query : %s", query);
1319 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1320 sqlite3_errmsg(db));
1322 ret = NOTIFICATION_ERROR_FROM_DB;
1326 while(sqlite3_step(stmt) == SQLITE_ROW) {
1327 if (data_cnt % 8 == 0) {
1330 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1332 *list_deleted_rowid = tmp;
1334 NOTIFICATION_ERR("Heap: %s\n", strerror(errno));
1337 * How can I handle this?
1339 free(*list_deleted_rowid);
1340 *list_deleted_rowid = NULL;
1341 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1345 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1350 sqlite3_finalize(stmt);
1355 query_where[0] = '\0';
1356 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1357 for (i = 0; i < data_cnt ; i++) {
1358 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1359 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1360 ret_tmp = notification_db_exec(db, query, NULL);
1361 query_where[0] = '\0';
1362 if (ret == NOTIFICATION_ERROR_NONE) {
1366 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1367 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1369 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1370 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1371 ret_tmp = notification_db_exec(db, query, NULL);
1372 if (ret == NOTIFICATION_ERROR_NONE) {
1377 free(*list_deleted_rowid);
1378 *list_deleted_rowid = NULL;
1381 if (num_deleted != NULL) {
1382 *num_deleted = data_cnt;
1385 /* Make main query */
1386 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1387 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1389 ret = notification_db_exec(db, query, NULL);
1391 if (num_deleted != NULL) {
1392 *num_deleted = sqlite3_changes(db);
1398 sqlite3_finalize(stmt);
1402 notification_db_close(&db);
1408 int notification_noti_delete_group_by_group_id(const char *pkgname,
1409 int group_id, int *num_deleted, int **list_deleted_rowid)
1411 int ret = NOTIFICATION_ERROR_NONE;
1412 int ret_tmp = NOTIFICATION_ERROR_NONE;
1414 int i = 0, data_cnt = 0;
1415 sqlite3_stmt *stmt = NULL;
1416 char buf[128] = { 0, };
1417 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1418 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1419 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1421 /* Check pkgname is valid */
1422 if (pkgname == NULL) {
1423 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1426 snprintf(query_where, sizeof(query_where),
1427 "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
1430 db = notification_db_open(DBPATH);
1432 return get_last_result();
1435 if (num_deleted != NULL) {
1438 if (list_deleted_rowid != NULL) {
1439 *list_deleted_rowid = NULL;
1440 snprintf(query, sizeof(query),
1441 "select priv_id from noti_list %s ", query_where);
1443 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1444 if (ret != SQLITE_OK) {
1445 NOTIFICATION_ERR("Select Query : %s", query);
1446 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1447 sqlite3_errmsg(db));
1449 ret = NOTIFICATION_ERROR_FROM_DB;
1453 while(sqlite3_step(stmt) == SQLITE_ROW) {
1454 if (data_cnt % 8 == 0) {
1456 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1458 *list_deleted_rowid = tmp;
1460 free(*list_deleted_rowid);
1461 *list_deleted_rowid = NULL;
1462 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1466 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1471 sqlite3_finalize(stmt);
1476 query_where[0] = '\0';
1477 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1478 for (i = 0; i < data_cnt ; i++) {
1479 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1480 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1481 ret_tmp = notification_db_exec(db, query, NULL);
1482 query_where[0] = '\0';
1483 if (ret == NOTIFICATION_ERROR_NONE) {
1487 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1488 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1490 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1491 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1492 ret_tmp = notification_db_exec(db, query, NULL);
1493 if (ret == NOTIFICATION_ERROR_NONE) {
1498 free(*list_deleted_rowid);
1499 *list_deleted_rowid = NULL;
1502 if (num_deleted != NULL) {
1503 *num_deleted = data_cnt;
1507 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1510 ret = notification_db_exec(db, query, NULL);
1515 sqlite3_finalize(stmt);
1519 notification_db_close(&db);
1525 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1528 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1529 int internal_group_id = 0;
1532 /* Check pkgname is valid */
1533 if (pkgname == NULL) {
1534 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1538 db = notification_db_open(DBPATH);
1540 return get_last_result();
1543 /* Get internal group id using priv id */
1545 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1549 snprintf(query, sizeof(query), "delete from noti_list "
1550 "where caller_pkgname = '%s' and internal_group_id = %d",
1551 pkgname, internal_group_id);
1554 ret = notification_db_exec(db, query, NULL);
1557 notification_db_close(&db);
1562 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1565 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1568 /* Check pkgname is valid */
1569 if (pkgname == NULL) {
1570 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1574 db = notification_db_open(DBPATH);
1576 return get_last_result();
1580 snprintf(query, sizeof(query), "delete from noti_list "
1581 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1585 ret = notification_db_exec(db, query, NULL);
1589 notification_db_close(&db);
1595 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
1598 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1601 /* Check pkgname is valid */
1602 if (pkgname == NULL) {
1603 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1607 db = notification_db_open(DBPATH);
1609 return get_last_result();
1613 snprintf(query, sizeof(query), "delete from noti_list "
1614 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1618 ret = notification_db_exec(db, query, num_changes);
1620 if (num_changes != NULL) {
1621 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1626 notification_db_close(&db);
1632 int notification_noti_get_count(notification_type_e type,
1633 const char *pkgname,
1634 int group_id, int priv_id,
1638 sqlite3_stmt *stmt = NULL;
1639 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1640 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1641 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1642 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1644 int ret = 0, get_count = 0, internal_group_id = 0;
1645 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1647 int flag_where_more = 0;
1651 db = notification_db_open(DBPATH);
1653 return get_last_result();
1656 /* Check current sim status */
1657 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1660 snprintf(query_base, sizeof(query_base),
1661 "select count(*) from noti_list ");
1663 if (pkgname != NULL) {
1664 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1665 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1666 snprintf(query_where, sizeof(query_where),
1667 "where caller_pkgname = '%s' ",
1672 _notification_noti_get_internal_group_id_by_priv_id
1673 (pkgname, priv_id, db);
1674 snprintf(query_where, sizeof(query_where),
1675 "where caller_pkgname = '%s' and internal_group_id = %d ",
1676 pkgname, internal_group_id);
1680 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1681 snprintf(query_where, sizeof(query_where),
1682 "where caller_pkgname = '%s' and group_id = %d ",
1687 _notification_noti_get_internal_group_id_by_priv_id
1688 (pkgname, priv_id, db);
1689 snprintf(query_where, sizeof(query_where),
1690 "where caller_pkgname = '%s' and internal_group_id = %d ",
1691 pkgname, internal_group_id);
1698 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1699 if (type != NOTIFICATION_TYPE_NONE) {
1700 snprintf(query_where_more, sizeof(query_where_more),
1701 "type = %d ", type);
1702 flag_where_more = 1;
1705 if (type != NOTIFICATION_TYPE_NONE) {
1706 snprintf(query_where_more, sizeof(query_where_more),
1707 "type = %d and flag_simmode = 0 ", type);
1708 flag_where_more = 1;
1710 snprintf(query_where_more, sizeof(query_where_more),
1711 "flag_simmode = 0 ");
1712 flag_where_more = 1;
1716 if (flag_where == 1) {
1717 if (flag_where_more == 1) {
1718 snprintf(query, sizeof(query), "%s %s and %s",
1719 query_base, query_where, query_where_more);
1721 snprintf(query, sizeof(query), "%s %s", query_base,
1726 if (flag_where_more == 1) {
1727 snprintf(query, sizeof(query), "%s where %s",
1728 query_base, query_where_more);
1730 snprintf(query, sizeof(query), "%s", query_base);
1734 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1735 if (ret != SQLITE_OK) {
1736 NOTIFICATION_ERR("Select Query : %s", query);
1737 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1738 sqlite3_errmsg(db));
1740 ret = NOTIFICATION_ERROR_FROM_DB;
1744 ret = sqlite3_step(stmt);
1745 if (ret == SQLITE_ROW) {
1746 get_count = sqlite3_column_int(stmt, 0);
1749 ret = NOTIFICATION_ERROR_NONE;
1753 sqlite3_finalize(stmt);
1758 notification_db_close(&db);
1766 int notification_noti_get_grouping_list(notification_type_e type,
1768 notification_list_h *
1772 sqlite3_stmt *stmt = NULL;
1773 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1774 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1775 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1778 notification_list_h get_list = NULL;
1779 notification_h noti = NULL;
1780 int internal_count = 0;
1784 db = notification_db_open(DBPATH);
1786 return get_last_result();
1789 /* Check current sim status */
1790 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1793 snprintf(query_base, sizeof(query_base), "select "
1794 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1795 "tag, b_text, b_key, b_format_args, num_format_args, "
1796 "text_domain, text_dir, time, insert_time, args, group_args, "
1797 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1798 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1799 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1800 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1801 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1802 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1805 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1806 if (type != NOTIFICATION_TYPE_NONE) {
1807 snprintf(query_where, sizeof(query_where),
1808 "where type = %d ", type);
1811 if (type != NOTIFICATION_TYPE_NONE) {
1812 snprintf(query_where, sizeof(query_where),
1813 "where type = %d and flag_simmode = 0 ", type);
1815 snprintf(query_where, sizeof(query_where),
1816 "where flag_simmode = 0 ");
1820 snprintf(query, sizeof(query),
1822 "group by internal_group_id "
1823 "order by rowid desc, time desc", query_base, query_where);
1825 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1826 if (ret != SQLITE_OK) {
1827 NOTIFICATION_ERR("Select Query : %s", query);
1828 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1829 sqlite3_errmsg(db));
1831 ret = NOTIFICATION_ERROR_FROM_DB;
1835 while (sqlite3_step(stmt) == SQLITE_ROW) {
1836 /* Make notification list */
1837 noti = _notification_noti_get_item(stmt);
1841 get_list = notification_list_append(get_list, noti);
1843 if (count != -1 && internal_count >= count) {
1845 ("internal count %d >= count %d",
1846 internal_count, count);
1852 ret = NOTIFICATION_ERROR_NONE;
1856 sqlite3_finalize(stmt);
1861 notification_db_close(&db);
1864 if (get_list != NULL) {
1865 *list = notification_list_get_head(get_list);
1871 int notification_noti_get_detail_list(const char *pkgname,
1873 int priv_id, int count,
1874 notification_list_h *list)
1877 sqlite3_stmt *stmt = NULL;
1878 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1879 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1881 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1883 notification_list_h get_list = NULL;
1884 notification_h noti = NULL;
1885 int internal_count = 0;
1886 int internal_group_id = 0;
1887 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1890 db = notification_db_open(DBPATH);
1892 return get_last_result();
1895 /* Check current sim status */
1896 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1899 snprintf(query_base, sizeof(query_base), "select "
1900 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1901 "tag, b_text, b_key, b_format_args, num_format_args, "
1902 "text_domain, text_dir, time, insert_time, args, group_args, "
1903 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1904 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1905 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1906 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1907 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1908 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1911 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1912 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1913 snprintf(query_where, sizeof(query_where),
1914 "where caller_pkgname = '%s' ", pkgname);
1916 snprintf(query_where, sizeof(query_where),
1917 "where caller_pkgname = '%s' and flag_simmode = 0 ", pkgname);
1921 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1924 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1925 snprintf(query_where, sizeof(query_where),
1926 "where caller_pkgname = '%s' and internal_group_id = %d ",
1927 pkgname, internal_group_id);
1929 snprintf(query_where, sizeof(query_where),
1930 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1931 pkgname, internal_group_id);
1935 snprintf(query, sizeof(query),
1937 "order by rowid desc, time desc", query_base, query_where);
1939 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1940 if (ret != SQLITE_OK) {
1941 NOTIFICATION_ERR("Select Query : %s", query);
1942 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1943 sqlite3_errmsg(db));
1945 ret = NOTIFICATION_ERROR_FROM_DB;
1949 while (sqlite3_step(stmt) == SQLITE_ROW) {
1950 /* Make notification list */
1951 noti = _notification_noti_get_item(stmt);
1955 get_list = notification_list_append(get_list, noti);
1957 if (count != -1 && internal_count >= count) {
1959 ("internal count %d >= count %d",
1960 internal_count, count);
1966 ret = NOTIFICATION_ERROR_NONE;
1970 sqlite3_finalize(stmt);
1975 notification_db_close(&db);
1978 if (get_list != NULL) {
1979 *list = notification_list_get_head(get_list);
1985 EXPORT_API int notification_noti_check_tag(notification_h noti)
1988 int ret = NOTIFICATION_ERROR_NONE;
1990 sqlite3_stmt *stmt = NULL;
1992 if (noti->tag == NULL) {
1993 return NOTIFICATION_ERROR_NOT_EXIST_ID;
1997 db = notification_db_open(DBPATH);
1999 return get_last_result();
2002 ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
2003 if (ret != SQLITE_OK) {
2004 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
2005 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
2008 ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
2009 if (ret != SQLITE_OK) {
2010 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
2014 ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
2015 if (ret != SQLITE_OK) {
2016 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
2020 ret = sqlite3_step(stmt);
2021 if (ret == SQLITE_ROW) {
2022 result = sqlite3_column_int(stmt, 0);
2027 sqlite3_finalize(stmt);
2029 /* If result > 0, there is priv_id in DB */
2031 noti->priv_id = result;
2032 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
2034 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;