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 <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);
252 notification_db_close(&db);
254 return NOTIFICATION_ERROR_FROM_DB;
258 if (ret_title != NULL) {
260 _notification_noti_bind_query(stmt, "$title_key",
261 NOTIFICATION_CHECK_STR
263 if (ret != NOTIFICATION_ERROR_NONE) {
264 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
269 ret = sqlite3_step(stmt);
270 if (ret == SQLITE_ROW) {
271 result = sqlite3_column_int(stmt, 0);
273 /* If there is not internal_group_id, create new one */
274 result = _notification_noti_get_max_internal_group_id(noti, db);
278 sqlite3_finalize(stmt);
280 noti->internal_group_id = result;
282 return NOTIFICATION_ERROR_NONE;
285 static int _notification_noti_make_query(notification_h noti, char *query,
289 char *group_args = NULL;
290 char *b_image_path = NULL;
291 char *b_execute_option = NULL;
292 char *b_service_responding = NULL;
293 char *b_service_single_launch = NULL;
294 char *b_service_multi_launch = NULL;
297 char *b_format_args = NULL;
298 int flag_simmode = 0;
300 /* Decode bundle to insert DB */
302 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
304 if (noti->group_args) {
305 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
309 if (noti->b_execute_option) {
310 bundle_encode(noti->b_execute_option,
311 (bundle_raw **) & b_execute_option, NULL);
313 if (noti->b_service_responding) {
314 bundle_encode(noti->b_service_responding,
315 (bundle_raw **) & b_service_responding, NULL);
317 if (noti->b_service_single_launch) {
318 bundle_encode(noti->b_service_single_launch,
319 (bundle_raw **) & b_service_single_launch, NULL);
321 if (noti->b_service_multi_launch) {
322 bundle_encode(noti->b_service_multi_launch,
323 (bundle_raw **) & b_service_multi_launch, NULL);
327 bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL);
330 bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL);
332 if (noti->b_format_args) {
333 bundle_encode(noti->b_format_args,
334 (bundle_raw **) & b_format_args, NULL);
337 if (noti->b_image_path) {
338 bundle_encode(noti->b_image_path,
339 (bundle_raw **) & b_image_path, NULL);
342 /* Check only simmode property is enable */
343 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
348 snprintf(query, query_size, "insert into noti_list ("
350 "caller_pkgname, launch_pkgname, "
352 "group_id, internal_group_id, priv_id, "
354 "b_text, b_key, b_format_args, num_format_args, "
355 "text_domain, text_dir, "
356 "time, insert_time, "
359 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
360 "sound_type, sound_path, vibration_type, vibration_path, "
361 "flags_for_property, flag_simmode, display_applist, "
362 "progress_size, progress_percentage) values ("
368 "'%s', '%s', '%s', %d, "
374 "%d, '%s', %d, '%s', "
378 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
379 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
380 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
381 noti->internal_group_id, noti->priv_id,
382 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
383 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
384 NOTIFICATION_CHECK_STR(noti->domain),
385 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
386 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
387 NOTIFICATION_CHECK_STR(group_args),
388 NOTIFICATION_CHECK_STR(b_execute_option),
389 NOTIFICATION_CHECK_STR(b_service_responding),
390 NOTIFICATION_CHECK_STR(b_service_single_launch),
391 NOTIFICATION_CHECK_STR(b_service_multi_launch),
392 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
393 noti->vibration_type,
394 NOTIFICATION_CHECK_STR(noti->vibration_path),
395 noti->flags_for_property, flag_simmode, noti->display_applist,
396 noti->progress_size, noti->progress_percentage);
398 /* Free decoded data */
406 if (b_execute_option) {
407 free(b_execute_option);
409 if (b_service_responding) {
410 free(b_service_responding);
412 if (b_service_single_launch) {
413 free(b_service_single_launch);
415 if (b_service_multi_launch) {
416 free(b_service_multi_launch);
433 return NOTIFICATION_ERROR_NONE;
436 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
438 notification_h noti = NULL;
441 noti = malloc(sizeof(struct _notification));
446 noti->type = sqlite3_column_int(stmt, col++);
447 noti->caller_pkgname = notification_db_column_text(stmt, col++);
448 noti->launch_pkgname = notification_db_column_text(stmt, col++);
449 noti->b_image_path = notification_db_column_bundle(stmt, col++);
450 noti->group_id = sqlite3_column_int(stmt, col++);
451 noti->internal_group_id = 0;
452 noti->priv_id = sqlite3_column_int(stmt, col++);
454 noti->b_text = notification_db_column_bundle(stmt, col++);
455 noti->b_key = notification_db_column_bundle(stmt, col++);
456 noti->b_format_args = notification_db_column_bundle(stmt, col++);
457 noti->num_format_args = sqlite3_column_int(stmt, col++);
459 noti->domain = notification_db_column_text(stmt, col++);
460 noti->dir = notification_db_column_text(stmt, col++);
461 noti->time = sqlite3_column_int(stmt, col++);
462 noti->insert_time = sqlite3_column_int(stmt, col++);
463 noti->args = notification_db_column_bundle(stmt, col++);
464 noti->group_args = notification_db_column_bundle(stmt, col++);
466 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
467 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
468 noti->b_service_single_launch =
469 notification_db_column_bundle(stmt, col++);
470 noti->b_service_multi_launch =
471 notification_db_column_bundle(stmt, col++);
473 noti->sound_type = sqlite3_column_int(stmt, col++);
474 noti->sound_path = notification_db_column_text(stmt, col++);
475 noti->vibration_type = sqlite3_column_int(stmt, col++);
476 noti->vibration_path = notification_db_column_text(stmt, col++);
478 noti->flags_for_property = sqlite3_column_int(stmt, col++);
479 noti->display_applist = sqlite3_column_int(stmt, col++);
480 noti->progress_size = sqlite3_column_double(stmt, col++);
481 noti->progress_percentage = sqlite3_column_double(stmt, col++);
483 noti->app_icon_path = NULL;
484 noti->app_name = NULL;
485 noti->temp_title = NULL;
486 noti->temp_content = NULL;
490 int notification_noti_insert(notification_h noti)
493 sqlite3_stmt *stmt = NULL;
494 char query[NOTIFICATION_QUERY_MAX] = { 0, };
495 int ret = 0, result = 0;
496 char buf_key[32] = { 0, };
497 const char *title_key = NULL;
500 db = notification_db_open(DBPATH);
503 if (noti->priv_id == NOTIFICATION_PRIV_ID_NONE) {
504 ret = _notification_noti_get_priv_id(noti, db);
506 ret = _notification_noti_check_priv_id(noti, db);
507 if (ret != NOTIFICATION_ERROR_NONE) {
512 /* Get internal group ID */
513 ret = _notification_noti_get_internal_group_id(noti, db);
514 if (ret != NOTIFICATION_ERROR_NONE) {
519 ret = _notification_noti_make_query(noti, query, sizeof(query));
520 if (ret != NOTIFICATION_ERROR_NONE) {
524 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
525 if (ret != SQLITE_OK) {
526 NOTIFICATION_ERR("Insert Query : %s", query);
527 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
530 sqlite3_finalize(stmt);
534 notification_db_close(&db);
536 return NOTIFICATION_ERROR_FROM_DB;
540 if (noti->b_key != NULL) {
541 snprintf(buf_key, sizeof(buf_key), "%d",
542 NOTIFICATION_TEXT_TYPE_TITLE);
544 title_key = bundle_get_val(noti->b_key, buf_key);
547 if (title_key == NULL && noti->b_text != NULL) {
548 snprintf(buf_key, sizeof(buf_key), "%d",
549 NOTIFICATION_TEXT_TYPE_TITLE);
551 title_key = bundle_get_val(noti->b_text, buf_key);
554 if (title_key == NULL) {
555 title_key = noti->caller_pkgname;
559 ret = _notification_noti_bind_query(stmt, "$title_key", title_key);
560 if (ret != NOTIFICATION_ERROR_NONE) {
561 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
565 ret = sqlite3_step(stmt);
566 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
567 result = NOTIFICATION_ERROR_NONE;
569 result = NOTIFICATION_ERROR_FROM_DB;
573 sqlite3_finalize(stmt);
578 notification_db_close(&db);
584 int notification_noti_delete_all(notification_type_e type, const char *pkgname)
587 char query[NOTIFICATION_QUERY_MAX] = { 0, };
588 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
589 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
592 db = notification_db_open(DBPATH);
595 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
597 if (pkgname == NULL) {
598 if (type != NOTIFICATION_TYPE_NONE) {
599 snprintf(query_where, sizeof(query_where),
600 "where type = %d ", type);
603 if (type == NOTIFICATION_TYPE_NONE) {
604 snprintf(query_where, sizeof(query_where),
605 "where caller_pkgname = '%s' ", pkgname);
607 snprintf(query_where, sizeof(query_where),
608 "where caller_pkgname = '%s' and type = %d ",
613 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
615 //NOTIFICATION_INFO("Delete All : [%s]", query);
618 notification_db_exec(db, query);
622 notification_db_close(&db);
625 return NOTIFICATION_ERROR_NONE;
628 int notification_noti_delete_group_by_group_id(const char *pkgname,
632 char query[NOTIFICATION_QUERY_MAX] = { 0, };
634 /* Check pkgname is valid */
635 if (pkgname == NULL) {
636 return NOTIFICATION_ERROR_INVALID_DATA;
640 db = notification_db_open(DBPATH);
643 snprintf(query, sizeof(query), "delete from noti_list "
644 "where caller_pkgname = '%s' and group_id = %d", pkgname,
648 notification_db_exec(db, query);
652 notification_db_close(&db);
655 return NOTIFICATION_ERROR_NONE;
658 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
661 char query[NOTIFICATION_QUERY_MAX] = { 0, };
662 int internal_group_id = 0;
664 /* Check pkgname is valid */
665 if (pkgname == NULL) {
666 return NOTIFICATION_ERROR_INVALID_DATA;
670 db = notification_db_open(DBPATH);
672 /* Get internal group id using priv id */
674 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
678 snprintf(query, sizeof(query), "delete from noti_list "
679 "where caller_pkgname = '%s' and internal_group_id = %d",
680 pkgname, internal_group_id);
683 notification_db_exec(db, query);
687 notification_db_close(&db);
690 return NOTIFICATION_ERROR_NONE;
693 int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
696 char query[NOTIFICATION_QUERY_MAX] = { 0, };
698 /* Check pkgname is valid */
699 if (pkgname == NULL) {
700 return NOTIFICATION_ERROR_INVALID_DATA;
704 db = notification_db_open(DBPATH);
707 snprintf(query, sizeof(query), "delete from noti_list "
708 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
712 notification_db_exec(db, query);
716 notification_db_close(&db);
719 return NOTIFICATION_ERROR_NONE;
722 notification_error_e notification_noti_get_count(notification_type_e type,
724 int group_id, int priv_id,
728 sqlite3_stmt *stmt = NULL;
729 char query[NOTIFICATION_QUERY_MAX] = { 0, };
730 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
731 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
732 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
734 int ret = 0, get_count = 0, internal_group_id = 0;
735 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
737 int flag_where_more = 0;
740 db = notification_db_open(DBPATH);
742 /* Check current sim status */
743 vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
746 snprintf(query_base, sizeof(query_base),
747 "select count(*) from noti_list ");
749 if (pkgname != NULL) {
750 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
751 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
752 snprintf(query_where, sizeof(query_where),
753 "where caller_pkgname = '%s' ",
758 _notification_noti_get_internal_group_id_by_priv_id
759 (pkgname, priv_id, db);
760 snprintf(query_where, sizeof(query_where),
761 "where caller_pkgname = '%s' and internal_group_id = %d ",
762 pkgname, internal_group_id);
766 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
767 snprintf(query_where, sizeof(query_where),
768 "where caller_pkgname = '%s' and group_id = %d ",
773 _notification_noti_get_internal_group_id_by_priv_id
774 (pkgname, priv_id, db);
775 snprintf(query_where, sizeof(query_where),
776 "where caller_pkgname = '%s' and internal_group_id = %d ",
777 pkgname, internal_group_id);
784 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
785 if (type != NOTIFICATION_TYPE_NONE) {
786 snprintf(query_where_more, sizeof(query_where_more),
791 if (type != NOTIFICATION_TYPE_NONE) {
792 snprintf(query_where_more, sizeof(query_where_more),
793 "type = %d and flag_simmode = 0 ", type);
796 snprintf(query_where_more, sizeof(query_where_more),
797 "flag_simmode = 0 ");
802 if (flag_where == 1) {
803 if (flag_where_more == 1) {
804 snprintf(query, sizeof(query), "%s %s and %s",
805 query_base, query_where, query_where_more);
807 snprintf(query, sizeof(query), "%s %s", query_base,
812 if (flag_where_more == 1) {
813 snprintf(query, sizeof(query), "%s where %s",
814 query_base, query_where_more);
816 snprintf(query, sizeof(query), "%s", query_base);
820 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
821 if (ret != SQLITE_OK) {
822 NOTIFICATION_ERR("Select Query : %s", query);
823 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
826 return NOTIFICATION_ERROR_FROM_DB;
829 ret = sqlite3_step(stmt);
830 if (ret == SQLITE_ROW) {
831 get_count = sqlite3_column_int(stmt, 0);
834 sqlite3_finalize(stmt);
838 notification_db_close(&db);
843 return NOTIFICATION_ERROR_NONE;
846 notification_error_e notification_noti_get_grouping_list(notification_type_e type,
848 notification_list_h *
852 sqlite3_stmt *stmt = NULL;
853 char query[NOTIFICATION_QUERY_MAX] = { 0, };
854 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
855 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
858 notification_list_h get_list = NULL;
859 notification_h noti = NULL;
860 int internal_count = 0;
864 db = notification_db_open(DBPATH);
866 /* Check current sim status */
867 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
870 snprintf(query_base, sizeof(query_base), "select "
871 "type, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
872 "b_text, b_key, b_format_args, num_format_args, "
873 "text_domain, text_dir, time, insert_time, args, group_args, "
874 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
875 "sound_type, sound_path, vibration_type, vibration_path, "
876 "flags_for_property, display_applist, progress_size, progress_percentage "
879 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
880 if (type != NOTIFICATION_TYPE_NONE) {
881 snprintf(query_where, sizeof(query_where),
882 "where type = %d ", type);
885 if (type != NOTIFICATION_TYPE_NONE) {
886 snprintf(query_where, sizeof(query_where),
887 "where type = %d and flag_simmode = 0 ", type);
889 snprintf(query_where, sizeof(query_where),
890 "where flag_simmode = 0 ");
894 snprintf(query, sizeof(query),
896 "group by internal_group_id "
897 "order by rowid desc, time desc", query_base, query_where);
899 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
900 if (ret != SQLITE_OK) {
901 NOTIFICATION_ERR("Select Query : %s", query);
902 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
905 return NOTIFICATION_ERROR_FROM_DB;
908 ret = sqlite3_step(stmt);
909 while (ret == SQLITE_ROW) {
910 /* Make notification list */
911 noti = _notification_noti_get_item(stmt);
915 get_list = notification_list_append(get_list, noti);
917 if (count != -1 && internal_count >= count) {
919 ("internal count %d >= count %d",
920 internal_count, count);
925 ret = sqlite3_step(stmt);
928 sqlite3_finalize(stmt);
932 notification_db_close(&db);
935 if (get_list != NULL) {
936 *list = notification_list_get_head(get_list);
939 return NOTIFICATION_ERROR_NONE;
942 notification_error_e notification_noti_get_detail_list(const char *pkgname,
944 int priv_id, int count,
945 notification_list_h *list)
948 sqlite3_stmt *stmt = NULL;
949 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
950 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
952 char query[NOTIFICATION_QUERY_MAX] = { 0, };
954 notification_list_h get_list = NULL;
955 notification_h noti = NULL;
956 int internal_count = 0;
957 int internal_group_id = 0;
961 db = notification_db_open(DBPATH);
963 /* Check current sim status */
964 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
967 snprintf(query_base, sizeof(query_base), "select "
968 "type, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
969 "b_text, b_key, b_format_args, num_format_args, "
970 "text_domain, text_dir, time, insert_time, args, group_args, "
971 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
972 "sound_type, sound_path, vibration_type, vibration_path, "
973 "flags_for_property, display_applist, progress_size, progress_percentage "
977 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
980 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
981 snprintf(query_where, sizeof(query_where),
982 "where caller_pkgname = '%s' and internal_group_id = %d ",
983 pkgname, internal_group_id);
985 snprintf(query_where, sizeof(query_where),
986 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
987 pkgname, internal_group_id);
990 snprintf(query, sizeof(query),
992 "order by rowid desc, time desc", query_base, query_where);
994 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
995 if (ret != SQLITE_OK) {
996 NOTIFICATION_ERR("Select Query : %s", query);
997 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1000 return NOTIFICATION_ERROR_FROM_DB;
1003 ret = sqlite3_step(stmt);
1004 while (ret == SQLITE_ROW) {
1005 /* Make notification list */
1006 noti = _notification_noti_get_item(stmt);
1010 get_list = notification_list_append(get_list, noti);
1012 if (count != -1 && internal_count >= count) {
1014 ("internal count %d >= count %d",
1015 internal_count, count);
1020 ret = sqlite3_step(stmt);
1023 sqlite3_finalize(stmt);
1027 notification_db_close(&db);
1030 if (get_list != NULL) {
1031 *list = notification_list_get_head(get_list);
1034 return NOTIFICATION_ERROR_NONE;