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>, Youngsub Ko <ys4610.ko@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 <notification.h>
29 #include <notification_db.h>
30 #include <notification_noti.h>
31 #include <notification_debug.h>
32 #include <notification_internal.h>
34 static int _notification_noti_bind_query(sqlite3_stmt * stmt, const char *name,
40 index = sqlite3_bind_parameter_index(stmt, name);
42 NOTIFICATION_ERR("Insert : invalid column name");
43 return NOTIFICATION_ERROR_FROM_DB;
47 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
49 if (ret != SQLITE_OK) {
50 NOTIFICATION_ERR("Insert text : %s",
51 NOTIFICATION_CHECK_STR(str));
52 return NOTIFICATION_ERROR_FROM_DB;
55 return NOTIFICATION_ERROR_NONE;
58 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
60 sqlite3_stmt *stmt = NULL;
61 char query[NOTIFICATION_QUERY_MAX] = { 0, };
62 int ret = NOTIFICATION_ERROR_NONE, result = 0;
64 /* Make query to check priv_id exist */
65 snprintf(query, sizeof(query),
66 "select count(*) from noti_list where caller_pkgname = '%s' and priv_id = %d",
67 noti->caller_pkgname, noti->priv_id);
69 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
70 if (ret != SQLITE_OK) {
71 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
73 return NOTIFICATION_ERROR_FROM_DB;
76 ret = sqlite3_step(stmt);
77 if (ret == SQLITE_ROW) {
78 result = sqlite3_column_int(stmt, 0);
83 sqlite3_finalize(stmt);
85 /* If result > 0, there is priv_id in DB */
87 return NOTIFICATION_ERROR_ALREADY_EXIST_ID;
90 return NOTIFICATION_ERROR_NONE;
93 static int _notification_noti_get_priv_id(notification_h noti, sqlite3 * db)
95 sqlite3_stmt *stmt = NULL;
96 char query[NOTIFICATION_QUERY_MAX] = { 0, };
97 int ret = NOTIFICATION_ERROR_NONE, result = 0;
99 /* Make query to get max priv_id */
100 snprintf(query, sizeof(query),
101 "select max(priv_id) from noti_list where caller_pkgname = '%s'",
102 noti->caller_pkgname);
104 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
105 if (ret != SQLITE_OK) {
106 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
108 return NOTIFICATION_ERROR_FROM_DB;
111 ret = sqlite3_step(stmt);
112 if (ret == SQLITE_ROW) {
113 result = sqlite3_column_int(stmt, 0);
118 sqlite3_finalize(stmt);
121 return NOTIFICATION_ERROR_FROM_DB;
124 /* Increase result(max priv_id value) for next priv_id */
125 noti->priv_id = result + 1;
127 return NOTIFICATION_ERROR_NONE;
130 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
134 sqlite3_stmt *stmt = NULL;
135 char query[NOTIFICATION_QUERY_MAX] = { 0, };
136 int ret = NOTIFICATION_ERROR_NONE, result = 0;
138 snprintf(query, sizeof(query),
139 "select internal_group_id from noti_list where caller_pkgname = '%s' and priv_id = %d",
142 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
143 if (ret != SQLITE_OK) {
144 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
146 return NOTIFICATION_ERROR_FROM_DB;
149 ret = sqlite3_step(stmt);
150 if (ret == SQLITE_ROW) {
151 result = sqlite3_column_int(stmt, 0);
156 sqlite3_finalize(stmt);
161 static int _notification_noti_get_max_internal_group_id(notification_h noti,
164 sqlite3_stmt *stmt = NULL;
165 char query[NOTIFICATION_QUERY_MAX] = { 0, };
166 int ret = NOTIFICATION_ERROR_NONE, result = 0;
168 /* Get max internal group id */
169 snprintf(query, sizeof(query),
170 "select max(internal_group_id) from noti_list");
172 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
173 if (ret != SQLITE_OK) {
174 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
176 return NOTIFICATION_ERROR_FROM_DB;
179 ret = sqlite3_step(stmt);
180 if (ret == SQLITE_ROW) {
181 result = sqlite3_column_int(stmt, 0);
186 sqlite3_finalize(stmt);
191 static int _notification_noti_get_internal_group_id(notification_h noti,
194 sqlite3_stmt *stmt = NULL;
195 char query[NOTIFICATION_QUERY_MAX] = { 0, };
196 int ret = NOTIFICATION_ERROR_NONE, result = 0;
197 const char *ret_title = NULL;
198 char buf_key[32] = { 0, };
200 if (noti->group_id == NOTIFICATION_GROUP_ID_NONE) {
201 /* If Group ID is NONE Get max internal group ID */
202 result = _notification_noti_get_max_internal_group_id(noti, db);
204 return NOTIFICATION_ERROR_FROM_DB;
207 /* Internal Group ID is max internal group ID + 1 */
208 noti->internal_group_id = result + 1;
210 return NOTIFICATION_ERROR_NONE;
211 } else if (noti->group_id == NOTIFICATION_GROUP_ID_DEFAULT) {
212 /* If Group ID is DEFAULT, Get internal group id if it exist */
213 if (noti->b_key != NULL) {
214 snprintf(buf_key, sizeof(buf_key), "%d",
215 NOTIFICATION_TEXT_TYPE_TITLE);
217 ret_title = bundle_get_val(noti->b_key, buf_key);
220 if (ret_title == NULL && noti->b_text != NULL) {
221 snprintf(buf_key, sizeof(buf_key), "%d",
222 NOTIFICATION_TEXT_TYPE_TITLE);
224 ret_title = bundle_get_val(noti->b_text, buf_key);
227 if (ret_title == NULL) {
228 ret_title = noti->caller_pkgname;
231 snprintf(query, sizeof(query),
232 "select internal_group_id from noti_list where title_key = $title_key and group_id = %d",
233 NOTIFICATION_GROUP_ID_DEFAULT);
235 /* If Group ID is > DEFAULT, Get internal group id if it exit */
236 snprintf(query, sizeof(query),
237 "select internal_group_id from noti_list where caller_pkgname = '%s' and group_id = %d",
238 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
242 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
243 if (ret != SQLITE_OK) {
244 NOTIFICATION_ERR("Select Query : %s", query);
245 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
248 sqlite3_finalize(stmt);
250 return NOTIFICATION_ERROR_FROM_DB;
254 if (ret_title != NULL) {
256 _notification_noti_bind_query(stmt, "$title_key",
257 NOTIFICATION_CHECK_STR
259 if (ret != NOTIFICATION_ERROR_NONE) {
260 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
262 sqlite3_finalize(stmt);
268 ret = sqlite3_step(stmt);
269 if (ret == SQLITE_ROW) {
270 result = sqlite3_column_int(stmt, 0);
272 /* If there is not internal_group_id, create new one */
273 result = _notification_noti_get_max_internal_group_id(noti, db);
277 sqlite3_finalize(stmt);
279 noti->internal_group_id = result;
281 return NOTIFICATION_ERROR_NONE;
284 static int _notification_noti_make_query(notification_h noti, char *query,
288 char *group_args = NULL;
289 char *b_image_path = NULL;
290 char *b_execute_option = NULL;
291 char *b_service_responding = NULL;
292 char *b_service_single_launch = NULL;
293 char *b_service_multi_launch = NULL;
296 char *b_format_args = NULL;
297 int flag_simmode = 0;
299 /* Decode bundle to insert DB */
301 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
303 if (noti->group_args) {
304 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
308 if (noti->b_execute_option) {
309 bundle_encode(noti->b_execute_option,
310 (bundle_raw **) & b_execute_option, NULL);
312 if (noti->b_service_responding) {
313 bundle_encode(noti->b_service_responding,
314 (bundle_raw **) & b_service_responding, NULL);
316 if (noti->b_service_single_launch) {
317 bundle_encode(noti->b_service_single_launch,
318 (bundle_raw **) & b_service_single_launch, NULL);
320 if (noti->b_service_multi_launch) {
321 bundle_encode(noti->b_service_multi_launch,
322 (bundle_raw **) & b_service_multi_launch, NULL);
326 bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL);
329 bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL);
331 if (noti->b_format_args) {
332 bundle_encode(noti->b_format_args,
333 (bundle_raw **) & b_format_args, NULL);
336 if (noti->b_image_path) {
337 bundle_encode(noti->b_image_path,
338 (bundle_raw **) & b_image_path, NULL);
341 /* Check only simmode property is enable */
342 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
347 snprintf(query, query_size, "insert into noti_list ("
349 "caller_pkgname, launch_pkgname, "
351 "group_id, internal_group_id, priv_id, "
353 "b_text, b_key, b_format_args, num_format_args, "
354 "text_domain, text_dir, "
355 "time, insert_time, "
358 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
359 "sound_type, sound_path, vibration_type, vibration_path, "
360 "flags_for_property, flag_simmode, display_applist, "
361 "progress_size, progress_percentage) values ("
367 "'%s', '%s', '%s', %d, "
373 "%d, '%s', %d, '%s', "
377 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
378 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
379 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
380 noti->internal_group_id, noti->priv_id,
381 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
382 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
383 NOTIFICATION_CHECK_STR(noti->domain),
384 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
385 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
386 NOTIFICATION_CHECK_STR(group_args),
387 NOTIFICATION_CHECK_STR(b_execute_option),
388 NOTIFICATION_CHECK_STR(b_service_responding),
389 NOTIFICATION_CHECK_STR(b_service_single_launch),
390 NOTIFICATION_CHECK_STR(b_service_multi_launch),
391 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
392 noti->vibration_type,
393 NOTIFICATION_CHECK_STR(noti->vibration_path),
394 noti->flags_for_property, flag_simmode, noti->display_applist,
395 noti->progress_size, noti->progress_percentage);
397 /* Free decoded data */
405 if (b_execute_option) {
406 free(b_execute_option);
408 if (b_service_responding) {
409 free(b_service_responding);
411 if (b_service_single_launch) {
412 free(b_service_single_launch);
414 if (b_service_multi_launch) {
415 free(b_service_multi_launch);
432 return NOTIFICATION_ERROR_NONE;
436 static int _notification_noti_make_update_query(notification_h noti, char *query,
440 char *group_args = NULL;
441 char *b_image_path = NULL;
442 char *b_execute_option = NULL;
443 char *b_service_responding = NULL;
444 char *b_service_single_launch = NULL;
445 char *b_service_multi_launch = NULL;
448 char *b_format_args = NULL;
449 int flag_simmode = 0;
451 /* Decode bundle to update DB */
453 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
455 if (noti->group_args) {
456 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
460 if (noti->b_execute_option) {
461 bundle_encode(noti->b_execute_option,
462 (bundle_raw **) & b_execute_option, NULL);
464 if (noti->b_service_responding) {
465 bundle_encode(noti->b_service_responding,
466 (bundle_raw **) & b_service_responding, NULL);
468 if (noti->b_service_single_launch) {
469 bundle_encode(noti->b_service_single_launch,
470 (bundle_raw **) & b_service_single_launch, NULL);
472 if (noti->b_service_multi_launch) {
473 bundle_encode(noti->b_service_multi_launch,
474 (bundle_raw **) & b_service_multi_launch, NULL);
478 bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL);
481 bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL);
483 if (noti->b_format_args) {
484 bundle_encode(noti->b_format_args,
485 (bundle_raw **) & b_format_args, NULL);
488 if (noti->b_image_path) {
489 bundle_encode(noti->b_image_path,
490 (bundle_raw **) & b_image_path, NULL);
493 /* Check only simmode property is enable */
494 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
499 snprintf(query, query_size, "update noti_list set "
501 "launch_pkgname = '%s', "
502 "image_path = '%s', "
503 "b_text = '%s', b_key = '%s', "
504 "b_format_args = '%s', num_format_args = %d, "
505 "text_domain = '%s', text_dir = '%s', "
506 "time = %d, insert_time = %d, "
507 "args = '%s', group_args = '%s', "
508 "b_execute_option = '%s', "
509 "b_service_responding = '%s', "
510 "b_service_single_launch = '%s', "
511 "b_service_multi_launch = '%s', "
512 "sound_type = %d, sound_path = '%s', "
513 "vibration_type = %d, vibration_path = '%s', "
514 "flags_for_property = %d, flag_simmode = %d, "
515 "display_applist = %d, "
516 "progress_size = %f, progress_percentage = %f "
517 "where priv_id = %d ",
519 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
520 NOTIFICATION_CHECK_STR(b_image_path),
521 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
522 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
523 NOTIFICATION_CHECK_STR(noti->domain),
524 NOTIFICATION_CHECK_STR(noti->dir),
525 (int)noti->time, (int)noti->insert_time,
526 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
527 NOTIFICATION_CHECK_STR(b_execute_option),
528 NOTIFICATION_CHECK_STR(b_service_responding),
529 NOTIFICATION_CHECK_STR(b_service_single_launch),
530 NOTIFICATION_CHECK_STR(b_service_multi_launch),
531 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
532 noti->vibration_type,
533 NOTIFICATION_CHECK_STR(noti->vibration_path),
534 noti->flags_for_property, flag_simmode, noti->display_applist,
535 noti->progress_size, noti->progress_percentage,
538 /* Free decoded data */
546 if (b_execute_option) {
547 free(b_execute_option);
549 if (b_service_responding) {
550 free(b_service_responding);
552 if (b_service_single_launch) {
553 free(b_service_single_launch);
555 if (b_service_multi_launch) {
556 free(b_service_multi_launch);
573 return NOTIFICATION_ERROR_NONE;
576 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
578 notification_h noti = NULL;
581 noti = malloc(sizeof(struct _notification));
586 noti->type = sqlite3_column_int(stmt, col++);
587 noti->caller_pkgname = notification_db_column_text(stmt, col++);
588 noti->launch_pkgname = notification_db_column_text(stmt, col++);
589 noti->b_image_path = notification_db_column_bundle(stmt, col++);
590 noti->group_id = sqlite3_column_int(stmt, col++);
591 noti->internal_group_id = 0;
592 noti->priv_id = sqlite3_column_int(stmt, col++);
594 noti->b_text = notification_db_column_bundle(stmt, col++);
595 noti->b_key = notification_db_column_bundle(stmt, col++);
596 noti->b_format_args = notification_db_column_bundle(stmt, col++);
597 noti->num_format_args = sqlite3_column_int(stmt, col++);
599 noti->domain = notification_db_column_text(stmt, col++);
600 noti->dir = notification_db_column_text(stmt, col++);
601 noti->time = sqlite3_column_int(stmt, col++);
602 noti->insert_time = sqlite3_column_int(stmt, col++);
603 noti->args = notification_db_column_bundle(stmt, col++);
604 noti->group_args = notification_db_column_bundle(stmt, col++);
606 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
607 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
608 noti->b_service_single_launch =
609 notification_db_column_bundle(stmt, col++);
610 noti->b_service_multi_launch =
611 notification_db_column_bundle(stmt, col++);
613 noti->sound_type = sqlite3_column_int(stmt, col++);
614 noti->sound_path = notification_db_column_text(stmt, col++);
615 noti->vibration_type = sqlite3_column_int(stmt, col++);
616 noti->vibration_path = notification_db_column_text(stmt, col++);
618 noti->flags_for_property = sqlite3_column_int(stmt, col++);
619 noti->display_applist = sqlite3_column_int(stmt, col++);
620 noti->progress_size = sqlite3_column_double(stmt, col++);
621 noti->progress_percentage = sqlite3_column_double(stmt, col++);
623 noti->app_icon_path = NULL;
624 noti->app_name = NULL;
625 noti->temp_title = NULL;
626 noti->temp_content = NULL;
630 int notification_noti_insert(notification_h noti)
633 sqlite3_stmt *stmt = NULL;
634 char query[NOTIFICATION_QUERY_MAX] = { 0, };
636 char buf_key[32] = { 0, };
637 const char *title_key = NULL;
640 db = notification_db_open(DBPATH);
643 if (noti->priv_id == NOTIFICATION_PRIV_ID_NONE) {
644 ret = _notification_noti_get_priv_id(noti, db);
646 ret = _notification_noti_check_priv_id(noti, db);
647 if (ret != NOTIFICATION_ERROR_NONE) {
652 /* Get internal group ID */
653 ret = _notification_noti_get_internal_group_id(noti, db);
654 if (ret != NOTIFICATION_ERROR_NONE) {
659 ret = _notification_noti_make_query(noti, query, sizeof(query));
660 if (ret != NOTIFICATION_ERROR_NONE) {
664 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
665 if (ret != SQLITE_OK) {
666 NOTIFICATION_ERR("Insert Query : %s", query);
667 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
669 ret = NOTIFICATION_ERROR_FROM_DB;
674 if (noti->b_key != NULL) {
675 snprintf(buf_key, sizeof(buf_key), "%d",
676 NOTIFICATION_TEXT_TYPE_TITLE);
678 title_key = bundle_get_val(noti->b_key, buf_key);
681 if (title_key == NULL && noti->b_text != NULL) {
682 snprintf(buf_key, sizeof(buf_key), "%d",
683 NOTIFICATION_TEXT_TYPE_TITLE);
685 title_key = bundle_get_val(noti->b_text, buf_key);
688 if (title_key == NULL) {
689 title_key = noti->caller_pkgname;
693 ret = _notification_noti_bind_query(stmt, "$title_key", title_key);
694 if (ret != NOTIFICATION_ERROR_NONE) {
695 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
699 ret = sqlite3_step(stmt);
700 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
701 ret = NOTIFICATION_ERROR_NONE;
703 ret = NOTIFICATION_ERROR_FROM_DB;
707 sqlite3_finalize(stmt);
712 notification_db_close(&db);
719 int notification_noti_update(notification_h noti)
722 sqlite3_stmt *stmt = NULL;
723 char query[NOTIFICATION_QUERY_MAX] = { 0, };
727 db = notification_db_open(DBPATH);
729 /* Check private ID is exist */
730 ret = _notification_noti_check_priv_id(noti, db);
731 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
732 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
736 /* make update query */
737 ret = _notification_noti_make_update_query(noti, query, sizeof(query));
738 if (ret != NOTIFICATION_ERROR_NONE) {
742 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
743 if (ret != SQLITE_OK) {
744 NOTIFICATION_ERR("Insert Query : %s", query);
745 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
747 ret = NOTIFICATION_ERROR_FROM_DB;
751 ret = sqlite3_step(stmt);
752 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
753 ret = NOTIFICATION_ERROR_NONE;
755 ret = NOTIFICATION_ERROR_FROM_DB;
759 sqlite3_finalize(stmt);
764 notification_db_close(&db);
770 int notification_noti_delete_all(notification_type_e type, const char *pkgname)
773 char query[NOTIFICATION_QUERY_MAX] = { 0, };
774 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
775 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
778 db = notification_db_open(DBPATH);
781 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
783 if (pkgname == NULL) {
784 if (type != NOTIFICATION_TYPE_NONE) {
785 snprintf(query_where, sizeof(query_where),
786 "where type = %d ", type);
789 if (type == NOTIFICATION_TYPE_NONE) {
790 snprintf(query_where, sizeof(query_where),
791 "where caller_pkgname = '%s' ", pkgname);
793 snprintf(query_where, sizeof(query_where),
794 "where caller_pkgname = '%s' and type = %d ",
799 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
801 //NOTIFICATION_INFO("Delete All : [%s]", query);
804 notification_db_exec(db, query);
808 notification_db_close(&db);
811 return NOTIFICATION_ERROR_NONE;
814 int notification_noti_delete_group_by_group_id(const char *pkgname,
818 char query[NOTIFICATION_QUERY_MAX] = { 0, };
820 /* Check pkgname is valid */
821 if (pkgname == NULL) {
822 return NOTIFICATION_ERROR_INVALID_DATA;
826 db = notification_db_open(DBPATH);
829 snprintf(query, sizeof(query), "delete from noti_list "
830 "where caller_pkgname = '%s' and group_id = %d", pkgname,
834 notification_db_exec(db, query);
838 notification_db_close(&db);
841 return NOTIFICATION_ERROR_NONE;
844 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
847 char query[NOTIFICATION_QUERY_MAX] = { 0, };
848 int internal_group_id = 0;
850 /* Check pkgname is valid */
851 if (pkgname == NULL) {
852 return NOTIFICATION_ERROR_INVALID_DATA;
856 db = notification_db_open(DBPATH);
858 /* Get internal group id using priv id */
860 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
864 snprintf(query, sizeof(query), "delete from noti_list "
865 "where caller_pkgname = '%s' and internal_group_id = %d",
866 pkgname, internal_group_id);
869 notification_db_exec(db, query);
873 notification_db_close(&db);
876 return NOTIFICATION_ERROR_NONE;
879 int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
882 char query[NOTIFICATION_QUERY_MAX] = { 0, };
884 /* Check pkgname is valid */
885 if (pkgname == NULL) {
886 return NOTIFICATION_ERROR_INVALID_DATA;
890 db = notification_db_open(DBPATH);
893 snprintf(query, sizeof(query), "delete from noti_list "
894 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
898 notification_db_exec(db, query);
902 notification_db_close(&db);
905 return NOTIFICATION_ERROR_NONE;
908 notification_error_e notification_noti_get_count(notification_type_e type,
910 int group_id, int priv_id,
914 sqlite3_stmt *stmt = NULL;
915 char query[NOTIFICATION_QUERY_MAX] = { 0, };
916 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
917 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
918 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
920 int ret = 0, get_count = 0, internal_group_id = 0;
921 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
923 int flag_where_more = 0;
926 db = notification_db_open(DBPATH);
928 /* Check current sim status */
929 vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
932 snprintf(query_base, sizeof(query_base),
933 "select count(*) from noti_list ");
935 if (pkgname != NULL) {
936 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
937 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
938 snprintf(query_where, sizeof(query_where),
939 "where caller_pkgname = '%s' ",
944 _notification_noti_get_internal_group_id_by_priv_id
945 (pkgname, priv_id, db);
946 snprintf(query_where, sizeof(query_where),
947 "where caller_pkgname = '%s' and internal_group_id = %d ",
948 pkgname, internal_group_id);
952 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
953 snprintf(query_where, sizeof(query_where),
954 "where caller_pkgname = '%s' and group_id = %d ",
959 _notification_noti_get_internal_group_id_by_priv_id
960 (pkgname, priv_id, db);
961 snprintf(query_where, sizeof(query_where),
962 "where caller_pkgname = '%s' and internal_group_id = %d ",
963 pkgname, internal_group_id);
970 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
971 if (type != NOTIFICATION_TYPE_NONE) {
972 snprintf(query_where_more, sizeof(query_where_more),
977 if (type != NOTIFICATION_TYPE_NONE) {
978 snprintf(query_where_more, sizeof(query_where_more),
979 "type = %d and flag_simmode = 0 ", type);
982 snprintf(query_where_more, sizeof(query_where_more),
983 "flag_simmode = 0 ");
988 if (flag_where == 1) {
989 if (flag_where_more == 1) {
990 snprintf(query, sizeof(query), "%s %s and %s",
991 query_base, query_where, query_where_more);
993 snprintf(query, sizeof(query), "%s %s", query_base,
998 if (flag_where_more == 1) {
999 snprintf(query, sizeof(query), "%s where %s",
1000 query_base, query_where_more);
1002 snprintf(query, sizeof(query), "%s", query_base);
1006 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1007 if (ret != SQLITE_OK) {
1008 NOTIFICATION_ERR("Select Query : %s", query);
1009 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1010 sqlite3_errmsg(db));
1012 ret = NOTIFICATION_ERROR_FROM_DB;
1016 ret = sqlite3_step(stmt);
1017 if (ret == SQLITE_ROW) {
1018 get_count = sqlite3_column_int(stmt, 0);
1021 ret = NOTIFICATION_ERROR_NONE;
1025 sqlite3_finalize(stmt);
1030 notification_db_close(&db);
1038 notification_error_e notification_noti_get_grouping_list(notification_type_e type,
1040 notification_list_h *
1044 sqlite3_stmt *stmt = NULL;
1045 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1046 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1047 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1050 notification_list_h get_list = NULL;
1051 notification_h noti = NULL;
1052 int internal_count = 0;
1056 db = notification_db_open(DBPATH);
1058 /* Check current sim status */
1059 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1062 snprintf(query_base, sizeof(query_base), "select "
1063 "type, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1064 "b_text, b_key, b_format_args, num_format_args, "
1065 "text_domain, text_dir, time, insert_time, args, group_args, "
1066 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1067 "sound_type, sound_path, vibration_type, vibration_path, "
1068 "flags_for_property, display_applist, progress_size, progress_percentage "
1071 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1072 if (type != NOTIFICATION_TYPE_NONE) {
1073 snprintf(query_where, sizeof(query_where),
1074 "where type = %d ", type);
1077 if (type != NOTIFICATION_TYPE_NONE) {
1078 snprintf(query_where, sizeof(query_where),
1079 "where type = %d and flag_simmode = 0 ", type);
1081 snprintf(query_where, sizeof(query_where),
1082 "where flag_simmode = 0 ");
1086 snprintf(query, sizeof(query),
1088 "group by internal_group_id "
1089 "order by rowid desc, time desc", query_base, query_where);
1091 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1092 if (ret != SQLITE_OK) {
1093 NOTIFICATION_ERR("Select Query : %s", query);
1094 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1095 sqlite3_errmsg(db));
1097 ret = NOTIFICATION_ERROR_FROM_DB;
1101 ret = sqlite3_step(stmt);
1102 while (ret == SQLITE_ROW) {
1103 /* Make notification list */
1104 noti = _notification_noti_get_item(stmt);
1108 get_list = notification_list_append(get_list, noti);
1110 if (count != -1 && internal_count >= count) {
1112 ("internal count %d >= count %d",
1113 internal_count, count);
1118 ret = sqlite3_step(stmt);
1121 ret = NOTIFICATION_ERROR_NONE;
1125 sqlite3_finalize(stmt);
1130 notification_db_close(&db);
1133 if (get_list != NULL) {
1134 *list = notification_list_get_head(get_list);
1140 notification_error_e notification_noti_get_detail_list(const char *pkgname,
1142 int priv_id, int count,
1143 notification_list_h *list)
1146 sqlite3_stmt *stmt = NULL;
1147 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1148 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1150 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1152 notification_list_h get_list = NULL;
1153 notification_h noti = NULL;
1154 int internal_count = 0;
1155 int internal_group_id = 0;
1159 db = notification_db_open(DBPATH);
1161 /* Check current sim status */
1162 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1165 snprintf(query_base, sizeof(query_base), "select "
1166 "type, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1167 "b_text, b_key, b_format_args, num_format_args, "
1168 "text_domain, text_dir, time, insert_time, args, group_args, "
1169 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1170 "sound_type, sound_path, vibration_type, vibration_path, "
1171 "flags_for_property, display_applist, progress_size, progress_percentage "
1175 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1178 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1179 snprintf(query_where, sizeof(query_where),
1180 "where caller_pkgname = '%s' and internal_group_id = %d ",
1181 pkgname, internal_group_id);
1183 snprintf(query_where, sizeof(query_where),
1184 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1185 pkgname, internal_group_id);
1188 snprintf(query, sizeof(query),
1190 "order by rowid desc, time desc", query_base, query_where);
1192 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1193 if (ret != SQLITE_OK) {
1194 NOTIFICATION_ERR("Select Query : %s", query);
1195 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1196 sqlite3_errmsg(db));
1198 ret = NOTIFICATION_ERROR_FROM_DB;
1202 ret = sqlite3_step(stmt);
1203 while (ret == SQLITE_ROW) {
1204 /* Make notification list */
1205 noti = _notification_noti_get_item(stmt);
1209 get_list = notification_list_append(get_list, noti);
1211 if (count != -1 && internal_count >= count) {
1213 ("internal count %d >= count %d",
1214 internal_count, count);
1219 ret = sqlite3_step(stmt);
1222 ret = NOTIFICATION_ERROR_NONE;
1226 sqlite3_finalize(stmt);
1231 notification_db_close(&db);
1234 if (get_list != NULL) {
1235 *list = notification_list_get_head(get_list);