2 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <pkgmgr-info.h>
23 #include <package_manager.h>
25 #include <notification.h>
26 #include <notification_db.h>
27 #include <notification_list.h>
28 #include <notification_noti.h>
29 #include <notification_debug.h>
30 #include <notification_private.h>
31 #include <notification_setting.h>
32 #include <notification_setting_internal.h>
33 #include <notification_setting_service.h>
35 #define NOTI_BURST_DELETE_UNIT 10
36 #define ERR_BUFFER_SIZE 1024
38 static void __free_and_set(void **target_ptr, void *new_ptr)
40 if (target_ptr != NULL) {
41 if (*target_ptr != NULL)
44 *target_ptr = new_ptr;
48 static int _notification_noti_bind_query_text(sqlite3_stmt *stmt, const char *name,
54 index = sqlite3_bind_parameter_index(stmt, name);
56 NOTIFICATION_ERR("Insert : invalid column name");
57 return NOTIFICATION_ERROR_FROM_DB;
61 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
63 if (ret != SQLITE_OK) {
64 NOTIFICATION_ERR("Insert text : %s",
65 NOTIFICATION_CHECK_STR(str));
66 return NOTIFICATION_ERROR_FROM_DB;
69 return NOTIFICATION_ERROR_NONE;
72 static int _notification_noti_bind_query_double(sqlite3_stmt *stmt, const char *name,
78 index = sqlite3_bind_parameter_index(stmt, name);
80 NOTIFICATION_ERR("Insert : invalid column name");
81 return NOTIFICATION_ERROR_FROM_DB;
84 ret = sqlite3_bind_double(stmt, index, val);
85 if (ret != SQLITE_OK) {
86 NOTIFICATION_ERR("Insert double : %f", val);
87 return NOTIFICATION_ERROR_FROM_DB;
90 return NOTIFICATION_ERROR_NONE;
93 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 *db)
96 int ret = NOTIFICATION_ERROR_NONE;
98 sqlite3_stmt *stmt = NULL;
100 /* Make query to check priv_id exist */
101 query = sqlite3_mprintf("SELECT count(*) FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
102 noti->caller_pkgname, noti->priv_id);
104 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
108 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
109 if (ret != SQLITE_OK) {
110 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
112 ret = NOTIFICATION_ERROR_FROM_DB;
116 ret = sqlite3_step(stmt);
117 if (ret == SQLITE_ROW)
118 result = sqlite3_column_int(stmt, 0);
122 sqlite3_finalize(stmt);
124 /* If result > 0, there is priv_id in DB */
126 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
135 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
140 sqlite3_stmt *stmt = NULL;
141 int ret = NOTIFICATION_ERROR_NONE, result = 0;
143 query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
146 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
150 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
151 if (ret != SQLITE_OK) {
152 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
154 ret = NOTIFICATION_ERROR_FROM_DB;
158 ret = sqlite3_step(stmt);
159 if (ret == SQLITE_ROW)
160 result = sqlite3_column_int(stmt, 0);
166 sqlite3_finalize(stmt);
171 if (ret != NOTIFICATION_ERROR_NONE)
172 NOTIFICATION_ERR("failed to internal group ID:%d", ret);
177 static int _insertion_query_create(notification_h noti, char **query)
180 int b_encode_len = 0;
182 char *group_args = NULL;
183 char *b_image_path = NULL;
184 char *b_execute_option = NULL;
185 char *b_service_responding = NULL;
186 char *b_service_single_launch = NULL;
187 char *b_service_multi_launch = NULL;
188 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
191 char *b_format_args = NULL;
192 int flag_simmode = 0;
195 return NOTIFICATION_ERROR_INVALID_PARAMETER;
197 /* Decode bundle to insert DB */
199 bundle_encode(noti->args, (bundle_raw **)&args, &b_encode_len);
201 if (noti->group_args)
202 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
205 if (noti->b_execute_option)
206 bundle_encode(noti->b_execute_option,
207 (bundle_raw **)&b_execute_option, &b_encode_len);
209 if (noti->b_service_responding)
210 bundle_encode(noti->b_service_responding,
211 (bundle_raw **)&b_service_responding, &b_encode_len);
213 if (noti->b_service_single_launch)
214 bundle_encode(noti->b_service_single_launch,
215 (bundle_raw **)&b_service_single_launch, &b_encode_len);
217 if (noti->b_service_multi_launch)
218 bundle_encode(noti->b_service_multi_launch,
219 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
222 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
223 if (noti->b_event_handler[i])
224 bundle_encode(noti->b_event_handler[i],
225 (bundle_raw **)&b_event_handler[i], &b_encode_len);
229 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
232 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
234 if (noti->b_format_args)
235 bundle_encode(noti->b_format_args,
236 (bundle_raw **)&b_format_args, &b_encode_len);
238 if (noti->b_image_path)
239 bundle_encode(noti->b_image_path,
240 (bundle_raw **)&b_image_path, &b_encode_len);
242 /* Check only simmode property is enable */
243 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
247 *query = sqlite3_mprintf("INSERT INTO noti_list ("
250 "caller_pkgname, launch_pkgname, "
252 "group_id, internal_group_id, priv_id, "
254 "b_text, b_key, tag, b_format_args, num_format_args, "
255 "text_domain, text_dir, "
256 "time, insert_time, "
259 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
260 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
261 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
262 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
263 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
264 "flags_for_property, flag_simmode, display_applist, "
265 "progress_size, progress_percentage, ongoing_flag, auto_remove) values ("
272 "'%s', '%s', $tag, '%s', %d, "
281 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
283 "$progress_size, $progress_percentage, %d, %d)",
286 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
287 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
288 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
289 noti->internal_group_id, noti->priv_id,
290 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
291 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
292 NOTIFICATION_CHECK_STR(noti->domain),
293 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
294 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
295 NOTIFICATION_CHECK_STR(group_args),
296 NOTIFICATION_CHECK_STR(b_execute_option),
297 NOTIFICATION_CHECK_STR(b_service_responding),
298 NOTIFICATION_CHECK_STR(b_service_single_launch),
299 NOTIFICATION_CHECK_STR(b_service_multi_launch),
300 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
301 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
302 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
303 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
304 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
305 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
306 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
307 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
308 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
309 noti->vibration_type,
310 NOTIFICATION_CHECK_STR(noti->vibration_path),
315 noti->flags_for_property, flag_simmode, noti->display_applist,
319 /* Free decoded data */
326 if (b_execute_option)
327 free(b_execute_option);
329 if (b_service_responding)
330 free(b_service_responding);
332 if (b_service_single_launch)
333 free(b_service_single_launch);
335 if (b_service_multi_launch)
336 free(b_service_multi_launch);
351 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
353 return NOTIFICATION_ERROR_NONE;
356 static int _update_query_create(notification_h noti, char **query)
359 int b_encode_len = 0;
361 char *group_args = NULL;
362 char *b_image_path = NULL;
363 char *b_execute_option = NULL;
364 char *b_service_responding = NULL;
365 char *b_service_single_launch = NULL;
366 char *b_service_multi_launch = NULL;
367 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
370 char *b_format_args = NULL;
371 int flag_simmode = 0;
374 return NOTIFICATION_ERROR_INVALID_PARAMETER;
376 /* Decode bundle to update DB */
378 bundle_encode(noti->args, (bundle_raw **)&args, &b_encode_len);
380 if (noti->group_args)
381 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
384 if (noti->b_execute_option)
385 bundle_encode(noti->b_execute_option,
386 (bundle_raw **)&b_execute_option, &b_encode_len);
388 if (noti->b_service_responding)
389 bundle_encode(noti->b_service_responding,
390 (bundle_raw **)&b_service_responding, &b_encode_len);
392 if (noti->b_service_single_launch)
393 bundle_encode(noti->b_service_single_launch,
394 (bundle_raw **)&b_service_single_launch, &b_encode_len);
396 if (noti->b_service_multi_launch)
397 bundle_encode(noti->b_service_multi_launch,
398 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
400 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
401 if (noti->b_event_handler[i])
402 bundle_encode(noti->b_event_handler[i],
403 (bundle_raw **)&b_event_handler[i], &b_encode_len);
407 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
410 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
412 if (noti->b_format_args)
413 bundle_encode(noti->b_format_args,
414 (bundle_raw **)&b_format_args, &b_encode_len);
416 if (noti->b_image_path)
417 bundle_encode(noti->b_image_path,
418 (bundle_raw **)&b_image_path, &b_encode_len);
420 /* Check only simmode property is enable */
421 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
425 *query = sqlite3_mprintf("UPDATE noti_list SET "
428 "launch_pkgname = '%s', "
429 "image_path = '%s', "
430 "b_text = '%s', b_key = '%s', tag = $tag, "
431 "b_format_args = '%s', num_format_args = %d, "
432 "text_domain = '%s', text_dir = '%s', "
433 "time = %d, insert_time = %d, "
434 "args = '%s', group_args = '%s', "
435 "b_execute_option = '%s', "
436 "b_service_responding = '%s', "
437 "b_service_single_launch = '%s', "
438 "b_service_multi_launch = '%s', "
439 "b_event_handler_click_on_button_1 = '%s', "
440 "b_event_handler_click_on_button_2= '%s', "
441 "b_event_handler_click_on_button_3= '%s', "
442 "b_event_handler_click_on_button_4= '%s', "
443 "b_event_handler_click_on_button_5= '%s', "
444 "b_event_handler_click_on_button_6= '%s', "
445 "b_event_handler_click_on_icon= '%s', "
446 "b_event_handler_click_on_thumbnail= '%s', "
447 "sound_type = %d, sound_path = '%s', "
448 "vibration_type = %d, vibration_path = '%s', "
449 "led_operation = %d, led_argb = %d, "
450 "led_on_ms = %d, led_off_ms = %d, "
451 "flags_for_property = %d, flag_simmode = %d, "
452 "display_applist = %d, "
453 "progress_size = $progress_size, progress_percentage = $progress_percentage, "
454 "ongoing_flag = %d, auto_remove = %d "
455 "where priv_id = %d ",
458 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
459 NOTIFICATION_CHECK_STR(b_image_path),
460 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
461 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
462 NOTIFICATION_CHECK_STR(noti->domain),
463 NOTIFICATION_CHECK_STR(noti->dir),
464 (int)noti->time, (int)noti->insert_time,
465 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
466 NOTIFICATION_CHECK_STR(b_execute_option),
467 NOTIFICATION_CHECK_STR(b_service_responding),
468 NOTIFICATION_CHECK_STR(b_service_single_launch),
469 NOTIFICATION_CHECK_STR(b_service_multi_launch),
470 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
471 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
472 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
473 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
474 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
475 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
476 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
477 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
478 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
479 noti->vibration_type,
480 NOTIFICATION_CHECK_STR(noti->vibration_path),
485 noti->flags_for_property, flag_simmode, noti->display_applist,
486 noti->ongoing_flag, noti->auto_remove,
489 /* Free decoded data */
496 if (b_execute_option)
497 free(b_execute_option);
499 if (b_service_responding)
500 free(b_service_responding);
502 if (b_service_single_launch)
503 free(b_service_single_launch);
505 if (b_service_multi_launch)
506 free(b_service_multi_launch);
521 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
523 return NOTIFICATION_ERROR_NONE;
526 static void _notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notification_h noti)
531 if (stmt == NULL || noti == NULL)
535 noti->type = sqlite3_column_int(stmt, col++);
536 noti->layout = sqlite3_column_int(stmt, col++);
537 __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
538 __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
539 noti->b_image_path = notification_db_column_bundle(stmt, col++);
540 noti->group_id = sqlite3_column_int(stmt, col++);
541 noti->internal_group_id = 0;
542 noti->priv_id = sqlite3_column_int(stmt, col++);
543 __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
545 noti->b_text = notification_db_column_bundle(stmt, col++);
546 noti->b_key = notification_db_column_bundle(stmt, col++);
547 noti->b_format_args = notification_db_column_bundle(stmt, col++);
548 noti->num_format_args = sqlite3_column_int(stmt, col++);
550 __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
551 __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
552 noti->time = sqlite3_column_int(stmt, col++);
553 noti->insert_time = sqlite3_column_int(stmt, col++);
554 noti->args = notification_db_column_bundle(stmt, col++);
555 noti->group_args = notification_db_column_bundle(stmt, col++);
557 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
558 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
559 noti->b_service_single_launch =
560 notification_db_column_bundle(stmt, col++);
561 noti->b_service_multi_launch =
562 notification_db_column_bundle(stmt, col++);
564 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++)
565 noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
568 noti->sound_type = sqlite3_column_int(stmt, col++);
569 __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
570 noti->vibration_type = sqlite3_column_int(stmt, col++);
571 __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
572 noti->led_operation = sqlite3_column_int(stmt, col++);
573 noti->led_argb = sqlite3_column_int(stmt, col++);
574 noti->led_on_ms = sqlite3_column_int(stmt, col++);
575 noti->led_off_ms = sqlite3_column_int(stmt, col++);
577 noti->flags_for_property = sqlite3_column_int(stmt, col++);
578 noti->display_applist = sqlite3_column_int(stmt, col++);
579 noti->progress_size = sqlite3_column_double(stmt, col++);
580 noti->progress_percentage = sqlite3_column_double(stmt, col++);
582 noti->ongoing_flag = sqlite3_column_int(stmt, col++);
583 noti->auto_remove = sqlite3_column_int(stmt, col++);
585 noti->app_icon_path = NULL;
586 noti->app_name = NULL;
587 noti->temp_title = NULL;
588 noti->temp_content = NULL;
591 static notification_h _notification_noti_get_item(sqlite3_stmt *stmt)
593 notification_h noti = NULL;
595 noti = (notification_h) calloc(1, sizeof(struct _notification));
599 _notification_noti_populate_from_stmt(stmt, noti);
604 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
608 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
610 if (buf_len <= len_total)
611 return NOTIFICATION_ERROR_INVALID_PARAMETER;
613 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
615 return NOTIFICATION_ERROR_NONE;
618 char *notification_noti_strip_tag(const char *tagged_str)
620 if (tagged_str == NULL)
623 int len_total = strlen(tagged_str);
628 char *b_f_e = strstr(tagged_str, ">");
629 char *b_e_s = strstr(tagged_str, "</");
631 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
634 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
637 int notification_noti_get_tag_type(const char *tagged_str)
639 if (tagged_str == NULL)
640 return TAG_TYPE_INVALID;
642 if (strlen(tagged_str) == 0)
643 return TAG_TYPE_INVALID;
645 char *b_f_s = strstr(tagged_str, "<");
646 char *b_f_e = strstr(tagged_str, ">");
648 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
649 return TAG_TYPE_INVALID;
651 char *start = b_f_s + 1;
652 int len_tag = b_f_e - b_f_s - 1;
654 if (strncmp(start, TAG_TIME, len_tag) == 0)
655 return TAG_TYPE_TIME;
657 return TAG_TYPE_INVALID;
660 static int _notification_noti_update_priv_id(sqlite3 *db, int rowid)
662 int ret = NOTIFICATION_ERROR_NONE;
666 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
670 query = sqlite3_mprintf("UPDATE noti_list SET "
671 "priv_id = %d, internal_group_id = %d WHERE rowid = %d",
672 rowid, rowid, rowid);
674 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
678 ret = notification_db_exec(db, query, NULL);
688 static int _get_package_id_by_app_id(const char *app_id, char **package_id)
690 int err = NOTIFICATION_ERROR_NONE;
693 char *pkg_id_dup = NULL;
694 pkgmgrinfo_appinfo_h pkgmgrinfo_appinfo = NULL;
696 if (app_id == NULL || package_id == NULL) {
697 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
698 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
702 if ((retval = pkgmgrinfo_appinfo_get_appinfo(app_id, &pkgmgrinfo_appinfo)) != PMINFO_R_OK) {
703 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_appinfo failed [%d]", retval);
704 err = NOTIFICATION_ERROR_INVALID_OPERATION;
708 if ((retval = pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo, &pkg_id)) != PMINFO_R_OK || pkg_id == NULL) {
709 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_pkgname failed [%d]", retval);
710 err = NOTIFICATION_ERROR_INVALID_OPERATION;
714 pkg_id_dup = strdup(pkg_id);
716 if (pkg_id_dup == NULL) {
717 NOTIFICATION_ERR("strdup failed");
718 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
722 *package_id = pkg_id_dup;
725 if (pkgmgrinfo_appinfo)
726 pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
731 static bool _is_allowed_to_notify(const char *caller_package_name)
733 notification_setting_h setting = NULL;
735 char *package_id = NULL;
738 err = noti_setting_service_get_setting_by_package_name(caller_package_name, &setting);
739 if (err != NOTIFICATION_ERROR_NONE) {
740 /* Retry with package id */
741 err = _get_package_id_by_app_id(caller_package_name, &package_id);
743 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
744 NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
747 err = noti_setting_service_get_setting_by_package_name(package_id, &setting);
748 if (err != NOTIFICATION_ERROR_NONE) {
749 NOTIFICATION_ERR("noti_setting_service_get_setting_by_package_name failed [%d]", err);
755 err = notification_setting_get_allow_to_notify(setting, &ret);
756 if (err != NOTIFICATION_ERROR_NONE) {
757 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
762 NOTIFICATION_DBG("[%s] is not allowed to notify", caller_package_name);
769 notification_setting_free_notification(setting);
774 static int _handle_do_not_disturb_option(notification_h noti)
776 int err = NOTIFICATION_ERROR_NONE;
777 bool do_not_disturb = false;
778 bool do_not_disturb_exception = false;
779 char *package_id = NULL;
780 notification_system_setting_h system_setting = NULL;
781 notification_setting_h setting = NULL;
784 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
785 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
789 /* Get system setting */
790 if ((err = noti_system_setting_load_system_setting(&system_setting)) != NOTIFICATION_ERROR_NONE) {
791 NOTIFICATION_ERR("noti_system_setting_load_system_setting failed [%d]", err);
795 if ((err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb)) != NOTIFICATION_ERROR_NONE) {
796 NOTIFICATION_ERR("notification_system_setting_get_do_not_disturb failed [%d]", err);
800 NOTIFICATION_DBG("do_not_disturb [%d]", do_not_disturb);
802 if (do_not_disturb) {
803 /* Check exception option of the caller package */
804 err = noti_setting_service_get_setting_by_package_name(noti->caller_pkgname, &setting);
806 if (err != NOTIFICATION_ERROR_NONE) {
807 /* Retry with package id */
808 err = _get_package_id_by_app_id(noti->caller_pkgname, &package_id);
810 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
811 NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
814 err = noti_setting_service_get_setting_by_package_name(package_id, &setting);
815 if (err != NOTIFICATION_ERROR_NONE) {
816 NOTIFICATION_ERR("noti_setting_service_get_setting_by_package_name failed [%d]", err);
822 err = notification_setting_get_do_not_disturb_except(setting, &do_not_disturb_exception);
823 if (err != NOTIFICATION_ERROR_NONE) {
824 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
828 if (do_not_disturb_exception == false) {
829 /* do_not_disturb is ON and do_not_disturb_exception is OFF */
830 /* Then add this notification only on quick panel and indicator*/
831 noti->display_applist = noti->display_applist & (NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR);
832 /* and reset all sound and vibration and led options*/
833 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
834 SAFE_FREE(noti->sound_path);
835 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
836 SAFE_FREE(noti->vibration_path);
837 noti->led_operation = NOTIFICATION_LED_OP_OFF;
840 noti->led_off_ms = 0;
846 SAFE_FREE(package_id);
849 notification_system_setting_free_system_setting(system_setting);
852 notification_setting_free_notification(setting);
857 EXPORT_API int notification_noti_insert(notification_h noti)
861 sqlite3_stmt *stmt = NULL;
863 char buf_key[32] = { 0, };
864 char *title_key = NULL;
867 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
868 return NOTIFICATION_ERROR_INVALID_PARAMETER;
871 if (_is_allowed_to_notify((const char *)noti->caller_pkgname) == false) {
872 NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
873 return NOTIFICATION_ERROR_PERMISSION_DENIED;
876 if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE)
877 NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
881 db = notification_db_open(DBPATH);
883 return get_last_result();
885 /* Initialize private ID */
886 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
887 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
888 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
891 ret = _insertion_query_create(noti, &query);
892 if (ret != NOTIFICATION_ERROR_NONE)
895 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
896 if (ret != SQLITE_OK) {
897 NOTIFICATION_ERR("Insert Query : %s", query);
898 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
900 ret = NOTIFICATION_ERROR_FROM_DB;
905 if (noti->b_key != NULL) {
906 snprintf(buf_key, sizeof(buf_key), "%d",
907 NOTIFICATION_TEXT_TYPE_TITLE);
909 bundle_get_str(noti->b_key, buf_key, &title_key);
912 if (title_key == NULL && noti->b_text != NULL) {
913 snprintf(buf_key, sizeof(buf_key), "%d",
914 NOTIFICATION_TEXT_TYPE_TITLE);
916 bundle_get_str(noti->b_text, buf_key, &title_key);
919 if (title_key == NULL)
920 title_key = noti->caller_pkgname;
923 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
924 if (ret != NOTIFICATION_ERROR_NONE) {
925 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
928 ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
929 if (ret != NOTIFICATION_ERROR_NONE) {
930 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
933 ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
934 if (ret != NOTIFICATION_ERROR_NONE) {
935 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
938 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
939 if (ret != NOTIFICATION_ERROR_NONE) {
940 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
944 ret = sqlite3_step(stmt);
945 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
946 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
948 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0)
949 ret = NOTIFICATION_ERROR_NONE;
951 ret = NOTIFICATION_ERROR_FROM_DB;
954 ret = NOTIFICATION_ERROR_FROM_DB;
958 sqlite3_finalize(stmt);
962 notification_db_close(&db);
970 EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
975 sqlite3_stmt *stmt = NULL;
977 if (priv_id < 0 || noti == NULL) {
978 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
983 db = notification_db_open(DBPATH);
985 return get_last_result();
987 char *base_query = "select "
988 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
989 "tag, b_text, b_key, b_format_args, num_format_args, "
990 "text_domain, text_dir, time, insert_time, args, group_args, "
991 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
992 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
993 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
994 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
995 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
996 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
999 if (pkgname != NULL && strlen(pkgname) != 0)
1000 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d",
1001 base_query, pkgname, priv_id);
1003 query = sqlite3_mprintf("%s where priv_id = %d", base_query, priv_id);
1005 if (query == NULL) {
1006 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1010 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1011 if (ret != SQLITE_OK) {
1012 NOTIFICATION_ERR("select Query : %s", query);
1013 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
1014 sqlite3_errmsg(db));
1015 ret = NOTIFICATION_ERROR_FROM_DB;
1019 ret = sqlite3_step(stmt);
1020 if (ret == SQLITE_ROW) {
1021 _notification_noti_populate_from_stmt(stmt, noti);
1022 ret = NOTIFICATION_ERROR_NONE;
1024 ret = NOTIFICATION_ERROR_FROM_DB;
1029 sqlite3_free(query);
1032 sqlite3_finalize(stmt);
1036 notification_db_close(&db);
1041 EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag)
1045 sqlite3_stmt *stmt = NULL;
1047 if (tag == NULL || noti == NULL) {
1048 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
1053 db = notification_db_open(DBPATH);
1055 return get_last_result();
1057 if (pkgname != NULL && strlen(pkgname) != 0) {
1058 ret = sqlite3_prepare_v2(db, "select "
1059 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1060 "tag, b_text, b_key, b_format_args, num_format_args, "
1061 "text_domain, text_dir, time, insert_time, args, group_args, "
1062 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1063 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1064 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1065 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1066 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1067 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1068 "from noti_list where caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1069 if (ret != SQLITE_OK) {
1070 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1071 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1074 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
1075 if (ret != SQLITE_OK) {
1076 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1080 ret = sqlite3_bind_text(stmt, 2, tag, -1, SQLITE_TRANSIENT);
1081 if (ret != SQLITE_OK) {
1082 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1086 ret = sqlite3_prepare_v2(db, "select "
1087 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1088 "tag, b_text, b_key, b_format_args, num_format_args, "
1089 "text_domain, text_dir, time, insert_time, args, group_args, "
1090 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1091 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1092 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1093 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1094 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1095 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1096 "from noti_list where tag = ?", -1, &stmt, NULL);
1097 if (ret != SQLITE_OK) {
1098 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1099 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1102 ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
1103 if (ret != SQLITE_OK) {
1104 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1109 ret = sqlite3_step(stmt);
1110 if (ret == SQLITE_ROW) {
1111 _notification_noti_populate_from_stmt(stmt, noti);
1112 ret = NOTIFICATION_ERROR_NONE;
1114 ret = NOTIFICATION_ERROR_FROM_DB;
1120 sqlite3_finalize(stmt);
1124 notification_db_close(&db);
1129 EXPORT_API int notification_noti_update(notification_h noti)
1133 sqlite3_stmt *stmt = NULL;
1137 db = notification_db_open(DBPATH);
1139 return get_last_result();
1141 if (_is_allowed_to_notify((const char *)noti->caller_pkgname) == false) {
1142 NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
1143 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1146 if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE)
1147 NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
1149 /* Check private ID is exist */
1150 ret = _notification_noti_check_priv_id(noti, db);
1151 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
1152 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1156 /* make update query */
1157 ret = _update_query_create(noti, &query);
1158 if (ret != NOTIFICATION_ERROR_NONE)
1161 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1162 if (ret != SQLITE_OK) {
1163 NOTIFICATION_ERR("Insert Query : %s", query);
1164 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
1165 sqlite3_errmsg(db));
1166 ret = NOTIFICATION_ERROR_FROM_DB;
1170 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
1171 if (ret != NOTIFICATION_ERROR_NONE) {
1172 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1176 ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
1177 if (ret != NOTIFICATION_ERROR_NONE) {
1178 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1182 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
1183 if (ret != NOTIFICATION_ERROR_NONE) {
1184 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1188 ret = sqlite3_step(stmt);
1189 if (ret == SQLITE_OK || ret == SQLITE_DONE)
1190 ret = NOTIFICATION_ERROR_NONE;
1192 ret = NOTIFICATION_ERROR_FROM_DB;
1196 sqlite3_finalize(stmt);
1200 notification_db_close(&db);
1203 sqlite3_free(query);
1208 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
1210 int ret = NOTIFICATION_ERROR_NONE;
1211 int ret_tmp = NOTIFICATION_ERROR_NONE;
1212 int i = 0, data_cnt = 0;
1214 sqlite3_stmt *stmt = NULL;
1215 char buf[128] = { 0, };
1216 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1217 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1218 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1219 char err_buf[ERR_BUFFER_SIZE];
1222 db = notification_db_open(DBPATH);
1224 return get_last_result();
1226 if (pkgname == NULL || strlen(pkgname) == 0) {
1227 if (type != NOTIFICATION_TYPE_NONE)
1228 snprintf(query_where, sizeof(query_where),
1229 "where type = %d ", type);
1232 if (type == NOTIFICATION_TYPE_NONE)
1233 snprintf(query_where, sizeof(query_where),
1234 "where caller_pkgname = '%s' ", pkgname);
1236 snprintf(query_where, sizeof(query_where),
1237 "where caller_pkgname = '%s' and type = %d ",
1242 if (num_deleted != NULL)
1245 if (list_deleted_rowid != NULL) {
1246 *list_deleted_rowid = NULL;
1247 snprintf(query, sizeof(query),
1248 "select priv_id from noti_list %s ", query_where);
1250 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1251 if (ret != SQLITE_OK) {
1252 NOTIFICATION_ERR("Select Query : %s", query);
1253 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1254 sqlite3_errmsg(db));
1256 ret = NOTIFICATION_ERROR_FROM_DB;
1260 while (sqlite3_step(stmt) == SQLITE_ROW) {
1261 if (data_cnt % 8 == 0) {
1264 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1266 *list_deleted_rowid = tmp;
1268 NOTIFICATION_ERR("Heap: %s\n", strerror_r(errno, err_buf, sizeof(err_buf)));
1271 * How can I handle this?
1273 free(*list_deleted_rowid);
1274 *list_deleted_rowid = NULL;
1275 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1279 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1284 sqlite3_finalize(stmt);
1289 query_where[0] = '\0';
1290 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1291 for (i = 0; i < data_cnt ; i++) {
1292 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1293 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1294 ret_tmp = notification_db_exec(db, query, NULL);
1295 query_where[0] = '\0';
1296 if (ret == NOTIFICATION_ERROR_NONE)
1300 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1301 strncat(query_where, buf, sizeof(query_where) - strlen(query_where) - 1);
1303 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0)) {
1304 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1305 ret_tmp = notification_db_exec(db, query, NULL);
1306 if (ret == NOTIFICATION_ERROR_NONE)
1310 free(*list_deleted_rowid);
1311 *list_deleted_rowid = NULL;
1314 if (num_deleted != NULL)
1315 *num_deleted = data_cnt;
1318 /* Make main query */
1319 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1320 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1322 ret = notification_db_exec(db, query, NULL);
1324 if (num_deleted != NULL)
1325 *num_deleted = sqlite3_changes(db);
1331 sqlite3_finalize(stmt);
1335 notification_db_close(&db);
1340 int notification_noti_delete_group_by_group_id(const char *pkgname,
1341 int group_id, int *num_deleted, int **list_deleted_rowid)
1343 int ret = NOTIFICATION_ERROR_NONE;
1344 int ret_tmp = NOTIFICATION_ERROR_NONE;
1346 int i = 0, data_cnt = 0;
1347 sqlite3_stmt *stmt = NULL;
1348 char buf[128] = { 0, };
1349 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1350 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1351 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1353 /* Check pkgname is valid */
1354 if (pkgname == NULL)
1355 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1357 snprintf(query_where, sizeof(query_where),
1358 "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
1361 db = notification_db_open(DBPATH);
1363 return get_last_result();
1365 if (num_deleted != NULL)
1368 if (list_deleted_rowid != NULL) {
1369 *list_deleted_rowid = NULL;
1370 snprintf(query, sizeof(query),
1371 "select priv_id from noti_list %s ", query_where);
1373 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1374 if (ret != SQLITE_OK) {
1375 NOTIFICATION_ERR("Select Query : %s", query);
1376 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1377 sqlite3_errmsg(db));
1379 ret = NOTIFICATION_ERROR_FROM_DB;
1383 while (sqlite3_step(stmt) == SQLITE_ROW) {
1384 if (data_cnt % 8 == 0) {
1386 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1388 *list_deleted_rowid = tmp;
1390 free(*list_deleted_rowid);
1391 *list_deleted_rowid = NULL;
1392 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1396 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1401 sqlite3_finalize(stmt);
1406 query_where[0] = '\0';
1407 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1408 for (i = 0; i < data_cnt ; i++) {
1409 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1410 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1411 ret_tmp = notification_db_exec(db, query, NULL);
1412 query_where[0] = '\0';
1413 if (ret == NOTIFICATION_ERROR_NONE)
1416 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1417 strncat(query_where, buf, sizeof(query_where) - strlen(query_where) - 1);
1419 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0)) {
1420 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1421 ret_tmp = notification_db_exec(db, query, NULL);
1422 if (ret == NOTIFICATION_ERROR_NONE)
1426 free(*list_deleted_rowid);
1427 *list_deleted_rowid = NULL;
1430 if (num_deleted != NULL)
1431 *num_deleted = data_cnt;
1435 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1438 ret = notification_db_exec(db, query, NULL);
1443 sqlite3_finalize(stmt);
1447 notification_db_close(&db);
1452 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1455 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1456 int internal_group_id = 0;
1459 /* Check pkgname is valid */
1460 if (pkgname == NULL)
1461 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1464 db = notification_db_open(DBPATH);
1466 return get_last_result();
1468 /* Get internal group id using priv id */
1470 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1474 snprintf(query, sizeof(query), "delete from noti_list "
1475 "where caller_pkgname = '%s' and internal_group_id = %d",
1476 pkgname, internal_group_id);
1479 ret = notification_db_exec(db, query, NULL);
1482 notification_db_close(&db);
1487 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1490 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1493 /* Check pkgname is valid */
1494 if (pkgname == NULL)
1495 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1498 db = notification_db_open(DBPATH);
1500 return get_last_result();
1503 snprintf(query, sizeof(query), "delete from noti_list "
1504 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1508 ret = notification_db_exec(db, query, NULL);
1512 notification_db_close(&db);
1517 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
1520 char query[NOTIFICATION_QUERY_MAX] = {0, };
1523 /* Check pkgname is valid */
1524 if (pkgname == NULL || strlen(pkgname) == 0)
1525 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1528 db = notification_db_open(DBPATH);
1530 return get_last_result();
1533 snprintf(query, sizeof(query), "delete from noti_list "
1534 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1536 NOTIFICATION_DBG("%s", query);
1539 ret = notification_db_exec(db, query, num_changes);
1541 if (num_changes != NULL)
1542 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1546 notification_db_close(&db);
1551 EXPORT_API int notification_noti_get_count(notification_type_e type,
1552 const char *pkgname,
1553 int group_id, int priv_id,
1557 sqlite3_stmt *stmt = NULL;
1558 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1559 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1560 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1561 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1563 int ret = 0, get_count = 0, internal_group_id = 0;
1564 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1566 int flag_where_more = 0;
1570 db = notification_db_open(DBPATH);
1572 return get_last_result();
1574 /* Check current sim status */
1575 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1578 snprintf(query_base, sizeof(query_base),
1579 "select count(*) from noti_list ");
1581 if (pkgname != NULL && strlen(pkgname) != 0) {
1582 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1583 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1584 snprintf(query_where, sizeof(query_where),
1585 "where caller_pkgname = '%s' ",
1590 _notification_noti_get_internal_group_id_by_priv_id
1591 (pkgname, priv_id, db);
1592 snprintf(query_where, sizeof(query_where),
1593 "where caller_pkgname = '%s' and internal_group_id = %d ",
1594 pkgname, internal_group_id);
1598 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1599 snprintf(query_where, sizeof(query_where),
1600 "where caller_pkgname = '%s' and group_id = %d ",
1605 _notification_noti_get_internal_group_id_by_priv_id
1606 (pkgname, priv_id, db);
1607 snprintf(query_where, sizeof(query_where),
1608 "where caller_pkgname = '%s' and internal_group_id = %d ",
1609 pkgname, internal_group_id);
1616 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1617 if (type != NOTIFICATION_TYPE_NONE) {
1618 snprintf(query_where_more, sizeof(query_where_more),
1619 "type = %d ", type);
1620 flag_where_more = 1;
1623 if (type != NOTIFICATION_TYPE_NONE) {
1624 snprintf(query_where_more, sizeof(query_where_more),
1625 "type = %d and flag_simmode = 0 ", type);
1626 flag_where_more = 1;
1628 snprintf(query_where_more, sizeof(query_where_more),
1629 "flag_simmode = 0 ");
1630 flag_where_more = 1;
1634 if (flag_where == 1) {
1635 if (flag_where_more == 1) {
1636 snprintf(query, sizeof(query), "%s %s and %s",
1637 query_base, query_where, query_where_more);
1639 snprintf(query, sizeof(query), "%s %s", query_base,
1644 if (flag_where_more == 1) {
1645 snprintf(query, sizeof(query), "%s where %s",
1646 query_base, query_where_more);
1648 snprintf(query, sizeof(query), "%s", query_base);
1652 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1653 if (ret != SQLITE_OK) {
1654 NOTIFICATION_ERR("Select Query : %s", query);
1655 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1656 sqlite3_errmsg(db));
1658 ret = NOTIFICATION_ERROR_FROM_DB;
1662 ret = sqlite3_step(stmt);
1663 if (ret == SQLITE_ROW)
1664 get_count = sqlite3_column_int(stmt, 0);
1666 ret = NOTIFICATION_ERROR_NONE;
1670 sqlite3_finalize(stmt);
1675 notification_db_close(&db);
1682 EXPORT_API int notification_noti_get_grouping_list(notification_type_e type,
1684 notification_list_h *
1688 sqlite3_stmt *stmt = NULL;
1689 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1690 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1691 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1694 notification_list_h get_list = NULL;
1695 notification_h noti = NULL;
1696 int internal_count = 0;
1700 db = notification_db_open(DBPATH);
1702 return get_last_result();
1704 /* Check current sim status */
1705 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1708 snprintf(query_base, sizeof(query_base), "select "
1709 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1710 "tag, b_text, b_key, b_format_args, num_format_args, "
1711 "text_domain, text_dir, time, insert_time, args, group_args, "
1712 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1713 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1714 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1715 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1716 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1717 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1720 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1721 if (type != NOTIFICATION_TYPE_NONE)
1722 snprintf(query_where, sizeof(query_where),
1723 "where type = %d ", type);
1725 if (type != NOTIFICATION_TYPE_NONE)
1726 snprintf(query_where, sizeof(query_where),
1727 "where type = %d and flag_simmode = 0 ", type);
1729 snprintf(query_where, sizeof(query_where),
1730 "where flag_simmode = 0 ");
1733 snprintf(query, sizeof(query),
1735 "group by internal_group_id "
1736 "order by rowid desc, time desc", query_base, query_where);
1738 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1739 if (ret != SQLITE_OK) {
1740 NOTIFICATION_ERR("Select Query : %s", query);
1741 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1742 sqlite3_errmsg(db));
1744 ret = NOTIFICATION_ERROR_FROM_DB;
1748 while (sqlite3_step(stmt) == SQLITE_ROW) {
1749 /* Make notification list */
1750 noti = _notification_noti_get_item(stmt);
1754 get_list = notification_list_append(get_list, noti);
1756 if (count != -1 && internal_count >= count) {
1758 ("internal count %d >= count %d",
1759 internal_count, count);
1765 ret = NOTIFICATION_ERROR_NONE;
1769 sqlite3_finalize(stmt);
1773 notification_db_close(&db);
1775 if (get_list != NULL)
1776 *list = notification_list_get_head(get_list);
1781 EXPORT_API int notification_noti_get_detail_list(const char *pkgname,
1783 int priv_id, int count,
1784 notification_list_h *list)
1787 sqlite3_stmt *stmt = NULL;
1788 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1789 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1791 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1793 notification_list_h get_list = NULL;
1794 notification_h noti = NULL;
1795 int internal_count = 0;
1796 int internal_group_id = 0;
1797 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1800 db = notification_db_open(DBPATH);
1802 return get_last_result();
1804 /* Check current sim status */
1805 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1808 snprintf(query_base, sizeof(query_base), "select "
1809 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1810 "tag, b_text, b_key, b_format_args, num_format_args, "
1811 "text_domain, text_dir, time, insert_time, args, group_args, "
1812 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1813 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1814 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1815 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1816 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1817 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1820 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1821 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
1822 snprintf(query_where, sizeof(query_where),
1823 "where caller_pkgname = '%s' ", pkgname);
1825 snprintf(query_where, sizeof(query_where),
1826 "where caller_pkgname = '%s' and flag_simmode = 0 ", pkgname);
1830 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1833 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
1834 snprintf(query_where, sizeof(query_where),
1835 "where caller_pkgname = '%s' and internal_group_id = %d ",
1836 pkgname, internal_group_id);
1838 snprintf(query_where, sizeof(query_where),
1839 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1840 pkgname, internal_group_id);
1843 snprintf(query, sizeof(query),
1845 "order by rowid desc, time desc", query_base, query_where);
1847 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1848 if (ret != SQLITE_OK) {
1849 NOTIFICATION_ERR("Select Query : %s", query);
1850 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1851 sqlite3_errmsg(db));
1853 ret = NOTIFICATION_ERROR_FROM_DB;
1857 while (sqlite3_step(stmt) == SQLITE_ROW) {
1858 /* Make notification list */
1859 noti = _notification_noti_get_item(stmt);
1863 get_list = notification_list_append(get_list, noti);
1865 if (count != -1 && internal_count >= count) {
1867 ("internal count %d >= count %d",
1868 internal_count, count);
1874 ret = NOTIFICATION_ERROR_NONE;
1878 sqlite3_finalize(stmt);
1882 notification_db_close(&db);
1884 if (get_list != NULL)
1885 *list = notification_list_get_head(get_list);
1890 EXPORT_API int notification_noti_check_tag(notification_h noti)
1893 int ret = NOTIFICATION_ERROR_NONE;
1895 sqlite3_stmt *stmt = NULL;
1897 if (noti->tag == NULL)
1898 return NOTIFICATION_ERROR_NOT_EXIST_ID;
1901 db = notification_db_open(DBPATH);
1903 return get_last_result();
1905 ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1906 if (ret != SQLITE_OK) {
1907 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1909 notification_db_close(&db);
1910 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1913 ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
1914 if (ret != SQLITE_OK) {
1915 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1919 ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
1920 if (ret != SQLITE_OK) {
1921 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1925 ret = sqlite3_step(stmt);
1926 if (ret == SQLITE_ROW)
1927 result = sqlite3_column_int(stmt, 0);
1931 sqlite3_finalize(stmt);
1933 /* If result > 0, there is priv_id in DB */
1935 noti->priv_id = result;
1936 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
1938 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1943 notification_db_close(&db);