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)
46 if (target_ptr != NULL) {
47 if (*target_ptr != NULL) {
50 *target_ptr = new_ptr;
54 static int _notification_noti_bind_query_text(sqlite3_stmt * stmt, const char *name,
60 index = sqlite3_bind_parameter_index(stmt, name);
62 NOTIFICATION_ERR("Insert : invalid column name");
63 return NOTIFICATION_ERROR_FROM_DB;
67 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
69 if (ret != SQLITE_OK) {
70 NOTIFICATION_ERR("Insert text : %s",
71 NOTIFICATION_CHECK_STR(str));
72 return NOTIFICATION_ERROR_FROM_DB;
75 return NOTIFICATION_ERROR_NONE;
78 static int _notification_noti_bind_query_double(sqlite3_stmt * stmt, const char *name,
84 index = sqlite3_bind_parameter_index(stmt, name);
86 NOTIFICATION_ERR("Insert : invalid column name");
87 return NOTIFICATION_ERROR_FROM_DB;
90 ret = sqlite3_bind_double(stmt, index, val);
91 if (ret != SQLITE_OK) {
92 NOTIFICATION_ERR("Insert double : %f", val);
93 return NOTIFICATION_ERROR_FROM_DB;
96 return NOTIFICATION_ERROR_NONE;
99 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
102 int ret = NOTIFICATION_ERROR_NONE;
104 sqlite3_stmt *stmt = NULL;
106 /* Make query to check priv_id exist */
107 query = sqlite3_mprintf("SELECT count(*) FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
108 noti->caller_pkgname, noti->priv_id);
110 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
114 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
115 if (ret != SQLITE_OK) {
116 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
118 ret = NOTIFICATION_ERROR_FROM_DB;
122 ret = sqlite3_step(stmt);
123 if (ret == SQLITE_ROW) {
124 result = sqlite3_column_int(stmt, 0);
129 sqlite3_finalize(stmt);
131 /* If result > 0, there is priv_id in DB */
133 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
144 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
149 sqlite3_stmt *stmt = NULL;
150 int ret = NOTIFICATION_ERROR_NONE, result = 0;
152 query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
155 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
159 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
160 if (ret != SQLITE_OK) {
161 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
163 ret = NOTIFICATION_ERROR_FROM_DB;
167 ret = sqlite3_step(stmt);
168 if (ret == SQLITE_ROW) {
169 result = sqlite3_column_int(stmt, 0);
176 sqlite3_finalize(stmt);
183 if (ret != NOTIFICATION_ERROR_NONE) {
184 NOTIFICATION_ERR("failed to internal group ID:%d", ret);
190 static int _insertion_query_create(notification_h noti, char **query)
193 int b_encode_len = 0;
195 char *group_args = NULL;
196 char *b_image_path = NULL;
197 char *b_execute_option = NULL;
198 char *b_service_responding = NULL;
199 char *b_service_single_launch = NULL;
200 char *b_service_multi_launch = NULL;
201 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
204 char *b_format_args = NULL;
205 int flag_simmode = 0;
208 return NOTIFICATION_ERROR_INVALID_PARAMETER;
211 /* Decode bundle to insert DB */
213 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
215 if (noti->group_args) {
216 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
220 if (noti->b_execute_option) {
221 bundle_encode(noti->b_execute_option,
222 (bundle_raw **) & b_execute_option, &b_encode_len);
224 if (noti->b_service_responding) {
225 bundle_encode(noti->b_service_responding,
226 (bundle_raw **) & b_service_responding, &b_encode_len);
228 if (noti->b_service_single_launch) {
229 bundle_encode(noti->b_service_single_launch,
230 (bundle_raw **) & b_service_single_launch, &b_encode_len);
232 if (noti->b_service_multi_launch) {
233 bundle_encode(noti->b_service_multi_launch,
234 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
237 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
238 if (noti->b_event_handler[i]) {
239 bundle_encode(noti->b_event_handler[i],
240 (bundle_raw **) & b_event_handler[i], &b_encode_len);
245 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
248 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
250 if (noti->b_format_args) {
251 bundle_encode(noti->b_format_args,
252 (bundle_raw **) & b_format_args, &b_encode_len);
255 if (noti->b_image_path) {
256 bundle_encode(noti->b_image_path,
257 (bundle_raw **) & b_image_path, &b_encode_len);
260 /* Check only simmode property is enable */
261 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
266 *query = sqlite3_mprintf("INSERT INTO noti_list ("
269 "caller_pkgname, launch_pkgname, "
271 "group_id, internal_group_id, priv_id, "
273 "b_text, b_key, tag, b_format_args, num_format_args, "
274 "text_domain, text_dir, "
275 "time, insert_time, "
278 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
279 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
280 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
281 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
282 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
283 "flags_for_property, flag_simmode, display_applist, "
284 "progress_size, progress_percentage, ongoing_flag, auto_remove) values ("
291 "'%s', '%s', $tag, '%s', %d, "
300 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
302 "$progress_size, $progress_percentage, %d, %d)",
305 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
306 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
307 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
308 noti->internal_group_id, noti->priv_id,
309 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
310 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
311 NOTIFICATION_CHECK_STR(noti->domain),
312 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
313 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
314 NOTIFICATION_CHECK_STR(group_args),
315 NOTIFICATION_CHECK_STR(b_execute_option),
316 NOTIFICATION_CHECK_STR(b_service_responding),
317 NOTIFICATION_CHECK_STR(b_service_single_launch),
318 NOTIFICATION_CHECK_STR(b_service_multi_launch),
319 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
320 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
321 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
322 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
323 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
324 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
325 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
326 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
327 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
328 noti->vibration_type,
329 NOTIFICATION_CHECK_STR(noti->vibration_path),
334 noti->flags_for_property, flag_simmode, noti->display_applist,
338 /* Free decoded data */
346 if (b_execute_option) {
347 free(b_execute_option);
349 if (b_service_responding) {
350 free(b_service_responding);
352 if (b_service_single_launch) {
353 free(b_service_single_launch);
355 if (b_service_multi_launch) {
356 free(b_service_multi_launch);
373 if (*query == NULL) {
374 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
377 return NOTIFICATION_ERROR_NONE;
381 static int _update_query_create(notification_h noti, char **query)
384 int b_encode_len = 0;
386 char *group_args = NULL;
387 char *b_image_path = NULL;
388 char *b_execute_option = NULL;
389 char *b_service_responding = NULL;
390 char *b_service_single_launch = NULL;
391 char *b_service_multi_launch = NULL;
392 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
395 char *b_format_args = NULL;
396 int flag_simmode = 0;
399 return NOTIFICATION_ERROR_INVALID_PARAMETER;
402 /* Decode bundle to update DB */
404 bundle_encode(noti->args, (bundle_raw **) & args, &b_encode_len);
406 if (noti->group_args) {
407 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
411 if (noti->b_execute_option) {
412 bundle_encode(noti->b_execute_option,
413 (bundle_raw **) & b_execute_option, &b_encode_len);
415 if (noti->b_service_responding) {
416 bundle_encode(noti->b_service_responding,
417 (bundle_raw **) & b_service_responding, &b_encode_len);
419 if (noti->b_service_single_launch) {
420 bundle_encode(noti->b_service_single_launch,
421 (bundle_raw **) & b_service_single_launch, &b_encode_len);
423 if (noti->b_service_multi_launch) {
424 bundle_encode(noti->b_service_multi_launch,
425 (bundle_raw **) & b_service_multi_launch, &b_encode_len);
428 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
429 if (noti->b_event_handler[i]) {
430 bundle_encode(noti->b_event_handler[i],
431 (bundle_raw **) & b_event_handler[i], &b_encode_len);
436 bundle_encode(noti->b_text, (bundle_raw **) & b_text, &b_encode_len);
439 bundle_encode(noti->b_key, (bundle_raw **) & b_key, &b_encode_len);
441 if (noti->b_format_args) {
442 bundle_encode(noti->b_format_args,
443 (bundle_raw **) & b_format_args, &b_encode_len);
446 if (noti->b_image_path) {
447 bundle_encode(noti->b_image_path,
448 (bundle_raw **) & b_image_path, &b_encode_len);
451 /* Check only simmode property is enable */
452 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
457 *query = sqlite3_mprintf("UPDATE noti_list SET "
460 "launch_pkgname = '%s', "
461 "image_path = '%s', "
462 "b_text = '%s', b_key = '%s', tag = $tag, "
463 "b_format_args = '%s', num_format_args = %d, "
464 "text_domain = '%s', text_dir = '%s', "
465 "time = %d, insert_time = %d, "
466 "args = '%s', group_args = '%s', "
467 "b_execute_option = '%s', "
468 "b_service_responding = '%s', "
469 "b_service_single_launch = '%s', "
470 "b_service_multi_launch = '%s', "
471 "b_event_handler_click_on_button_1 = '%s', "
472 "b_event_handler_click_on_button_2= '%s', "
473 "b_event_handler_click_on_button_3= '%s', "
474 "b_event_handler_click_on_button_4= '%s', "
475 "b_event_handler_click_on_button_5= '%s', "
476 "b_event_handler_click_on_button_6= '%s', "
477 "b_event_handler_click_on_icon= '%s', "
478 "b_event_handler_click_on_thumbnail= '%s', "
479 "sound_type = %d, sound_path = '%s', "
480 "vibration_type = %d, vibration_path = '%s', "
481 "led_operation = %d, led_argb = %d, "
482 "led_on_ms = %d, led_off_ms = %d, "
483 "flags_for_property = %d, flag_simmode = %d, "
484 "display_applist = %d, "
485 "progress_size = $progress_size, progress_percentage = $progress_percentage, "
486 "ongoing_flag = %d, auto_remove = %d "
487 "where priv_id = %d ",
490 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
491 NOTIFICATION_CHECK_STR(b_image_path),
492 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
493 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
494 NOTIFICATION_CHECK_STR(noti->domain),
495 NOTIFICATION_CHECK_STR(noti->dir),
496 (int)noti->time, (int)noti->insert_time,
497 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
498 NOTIFICATION_CHECK_STR(b_execute_option),
499 NOTIFICATION_CHECK_STR(b_service_responding),
500 NOTIFICATION_CHECK_STR(b_service_single_launch),
501 NOTIFICATION_CHECK_STR(b_service_multi_launch),
502 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
503 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
504 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
505 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
506 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
507 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
508 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
509 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
510 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
511 noti->vibration_type,
512 NOTIFICATION_CHECK_STR(noti->vibration_path),
517 noti->flags_for_property, flag_simmode, noti->display_applist,
518 noti->ongoing_flag, noti->auto_remove,
521 /* Free decoded data */
529 if (b_execute_option) {
530 free(b_execute_option);
532 if (b_service_responding) {
533 free(b_service_responding);
535 if (b_service_single_launch) {
536 free(b_service_single_launch);
538 if (b_service_multi_launch) {
539 free(b_service_multi_launch);
556 if (*query == NULL) {
557 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
560 return NOTIFICATION_ERROR_NONE;
563 static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti)
568 if (stmt == NULL || noti == NULL) {
572 noti->type = sqlite3_column_int(stmt, col++);
573 noti->layout = sqlite3_column_int(stmt, col++);
574 __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
575 __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
576 noti->b_image_path = notification_db_column_bundle(stmt, col++);
577 noti->group_id = sqlite3_column_int(stmt, col++);
578 noti->internal_group_id = 0;
579 noti->priv_id = sqlite3_column_int(stmt, col++);
580 __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
582 noti->b_text = notification_db_column_bundle(stmt, col++);
583 noti->b_key = notification_db_column_bundle(stmt, col++);
584 noti->b_format_args = notification_db_column_bundle(stmt, col++);
585 noti->num_format_args = sqlite3_column_int(stmt, col++);
587 __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
588 __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
589 noti->time = sqlite3_column_int(stmt, col++);
590 noti->insert_time = sqlite3_column_int(stmt, col++);
591 noti->args = notification_db_column_bundle(stmt, col++);
592 noti->group_args = notification_db_column_bundle(stmt, col++);
594 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
595 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
596 noti->b_service_single_launch =
597 notification_db_column_bundle(stmt, col++);
598 noti->b_service_multi_launch =
599 notification_db_column_bundle(stmt, col++);
601 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
602 noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
605 noti->sound_type = sqlite3_column_int(stmt, col++);
606 __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
607 noti->vibration_type = sqlite3_column_int(stmt, col++);
608 __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
609 noti->led_operation = sqlite3_column_int(stmt, col++);
610 noti->led_argb = sqlite3_column_int(stmt, col++);
611 noti->led_on_ms = sqlite3_column_int(stmt, col++);
612 noti->led_off_ms = sqlite3_column_int(stmt, col++);
614 noti->flags_for_property = sqlite3_column_int(stmt, col++);
615 noti->display_applist = sqlite3_column_int(stmt, col++);
616 noti->progress_size = sqlite3_column_double(stmt, col++);
617 noti->progress_percentage = sqlite3_column_double(stmt, col++);
619 noti->ongoing_flag = sqlite3_column_int(stmt, col++);
620 noti->auto_remove = sqlite3_column_int(stmt, col++);
622 noti->app_icon_path = NULL;
623 noti->app_name = NULL;
624 noti->temp_title = NULL;
625 noti->temp_content = NULL;
628 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
630 notification_h noti = NULL;
632 noti = (notification_h) calloc(1, sizeof(struct _notification));
637 _notification_noti_populate_from_stmt(stmt, noti);
642 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
646 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
648 if (buf_len <= len_total)
649 return NOTIFICATION_ERROR_INVALID_PARAMETER;
651 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
653 return NOTIFICATION_ERROR_NONE;
656 char *notification_noti_strip_tag(const char *tagged_str)
658 if (tagged_str == NULL)
661 int len_total = strlen(tagged_str);
666 char *b_f_e = strstr(tagged_str, ">");
667 char *b_e_s = strstr(tagged_str, "</");
669 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
672 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
675 int notification_noti_get_tag_type(const char *tagged_str)
677 if (tagged_str == NULL)
678 return TAG_TYPE_INVALID;
680 if (strlen(tagged_str) == 0)
681 return TAG_TYPE_INVALID;
683 char *b_f_s = strstr(tagged_str, "<");
684 char *b_f_e = strstr(tagged_str, ">");
686 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
687 return TAG_TYPE_INVALID;
689 char *start = b_f_s + 1;
690 int len_tag = b_f_e - b_f_s - 1;
692 if (strncmp(start, TAG_TIME, len_tag) == 0) {
693 return TAG_TYPE_TIME;
696 return TAG_TYPE_INVALID;
699 static int _notification_noti_update_priv_id(sqlite3 * db, int rowid)
701 int ret = NOTIFICATION_ERROR_NONE;
705 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
709 query = sqlite3_mprintf("UPDATE noti_list SET "
710 "priv_id = %d, internal_group_id = %d WHERE rowid = %d",
711 rowid, rowid, rowid);
713 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
717 ret = notification_db_exec(db, query, NULL);
728 static int _get_package_id_by_app_id(const char *app_id, char **package_id)
730 int err = NOTIFICATION_ERROR_NONE;
733 char *pkg_id_dup = NULL;
734 pkgmgrinfo_appinfo_h pkgmgrinfo_appinfo = NULL;
736 if (app_id == NULL || package_id == NULL) {
737 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
738 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
742 if ((retval = pkgmgrinfo_appinfo_get_appinfo(app_id, &pkgmgrinfo_appinfo)) != PMINFO_R_OK) {
743 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_appinfo failed [%d]", retval);
744 err = NOTIFICATION_ERROR_INVALID_OPERATION;
748 if ((retval = pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo, &pkg_id)) != PMINFO_R_OK || pkg_id == NULL) {
749 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_pkgname failed [%d]", retval);
750 err = NOTIFICATION_ERROR_INVALID_OPERATION;
754 pkg_id_dup = strdup(pkg_id);
756 if (pkg_id_dup == NULL) {
757 NOTIFICATION_ERR("strdup failed");
758 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
762 *package_id = pkg_id_dup;
765 if (pkgmgrinfo_appinfo)
766 pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
771 static bool _is_allowed_to_notify(const char *caller_package_name)
773 notification_setting_h setting = NULL;
775 char *package_id = NULL;
778 err = notification_setting_get_setting_by_package_name(caller_package_name, &setting);
779 if (err != NOTIFICATION_ERROR_NONE) {
780 /* Retry with package id */
781 err = _get_package_id_by_app_id(caller_package_name, &package_id);
783 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
784 NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
787 err = notification_setting_get_setting_by_package_name(package_id, &setting);
788 if (err != NOTIFICATION_ERROR_NONE) {
789 NOTIFICATION_ERR("notification_setting_get_setting_by_package_name failed [%d]", err);
795 err = notification_setting_get_allow_to_notify(setting, &ret);
796 if (err != NOTIFICATION_ERROR_NONE) {
797 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
802 NOTIFICATION_DBG("[%s] is not allowed to notify", caller_package_name);
811 notification_setting_free_notification(setting);
817 static int _handle_do_not_disturb_option(notification_h noti)
819 int err = NOTIFICATION_ERROR_NONE;
820 bool do_not_disturb = false;
821 bool do_not_disturb_exception = false;
822 char *package_id = NULL;
823 notification_system_setting_h system_setting = NULL;
824 notification_setting_h setting = NULL;
827 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
828 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
832 /* Get system setting */
833 if ((err = notification_system_setting_load_system_setting(&system_setting)) != NOTIFICATION_ERROR_NONE) {
834 NOTIFICATION_ERR("notification_system_setting_load_system_setting failed [%d]", err);
838 if ((err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb)) != NOTIFICATION_ERROR_NONE) {
839 NOTIFICATION_ERR("notification_system_setting_get_do_not_disturb failed [%d]", err);
843 NOTIFICATION_DBG("do_not_disturb [%d]", do_not_disturb);
845 if (do_not_disturb) {
846 /* Check exception option of the caller package */
847 err = notification_setting_get_setting_by_package_name(noti->caller_pkgname, &setting);
849 if (err != NOTIFICATION_ERROR_NONE) {
850 /* Retry with package id */
851 err = _get_package_id_by_app_id(noti->caller_pkgname, &package_id);
853 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
854 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;