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_internal.h>
27 #include <notification_db.h>
28 #include <notification_list.h>
29 #include <notification_noti.h>
30 #include <notification_debug.h>
31 #include <notification_private.h>
32 #include <notification_setting.h>
33 #include <notification_setting_internal.h>
34 #include <notification_setting_service.h>
36 #define NOTI_BURST_DELETE_UNIT 10
37 #define ERR_BUFFER_SIZE 1024
39 static void __free_and_set(void **target_ptr, void *new_ptr)
41 if (target_ptr != NULL) {
42 if (*target_ptr != NULL)
45 *target_ptr = new_ptr;
49 static int _notification_noti_bind_query_text(sqlite3_stmt *stmt, const char *name,
55 index = sqlite3_bind_parameter_index(stmt, name);
57 NOTIFICATION_ERR("Insert : invalid column name");
58 return NOTIFICATION_ERROR_FROM_DB;
61 ret = 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)
246 *query = sqlite3_mprintf("INSERT INTO noti_list ("
249 "caller_pkgname, launch_pkgname, "
251 "group_id, internal_group_id,"
253 "b_text, b_key, tag, b_format_args, num_format_args, "
254 "text_domain, text_dir, "
255 "time, insert_time, "
258 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
259 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
260 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
261 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
262 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
263 "flags_for_property, flag_simmode, display_applist, "
264 "progress_size, progress_percentage, ongoing_flag, auto_remove, uid) values ("
271 "'%s', '%s', $tag, '%s', %d, "
280 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
282 "$progress_size, $progress_percentage, %d, %d, %d)",
285 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
286 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
287 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
288 noti->internal_group_id,
289 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
290 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
291 NOTIFICATION_CHECK_STR(noti->domain),
292 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
293 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
294 NOTIFICATION_CHECK_STR(group_args),
295 NOTIFICATION_CHECK_STR(b_execute_option),
296 NOTIFICATION_CHECK_STR(b_service_responding),
297 NOTIFICATION_CHECK_STR(b_service_single_launch),
298 NOTIFICATION_CHECK_STR(b_service_multi_launch),
299 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
300 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
301 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
302 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
303 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
304 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
305 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
306 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
307 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
308 noti->vibration_type,
309 NOTIFICATION_CHECK_STR(noti->vibration_path),
314 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)
424 *query = sqlite3_mprintf("UPDATE noti_list SET "
427 "launch_pkgname = '%s', "
428 "image_path = '%s', "
429 "b_text = '%s', b_key = '%s', tag = $tag, "
430 "b_format_args = '%s', num_format_args = %d, "
431 "text_domain = '%s', text_dir = '%s', "
432 "time = %d, insert_time = %d, "
433 "args = '%s', group_args = '%s', "
434 "b_execute_option = '%s', "
435 "b_service_responding = '%s', "
436 "b_service_single_launch = '%s', "
437 "b_service_multi_launch = '%s', "
438 "b_event_handler_click_on_button_1 = '%s', "
439 "b_event_handler_click_on_button_2= '%s', "
440 "b_event_handler_click_on_button_3= '%s', "
441 "b_event_handler_click_on_button_4= '%s', "
442 "b_event_handler_click_on_button_5= '%s', "
443 "b_event_handler_click_on_button_6= '%s', "
444 "b_event_handler_click_on_icon= '%s', "
445 "b_event_handler_click_on_thumbnail= '%s', "
446 "sound_type = %d, sound_path = '%s', "
447 "vibration_type = %d, vibration_path = '%s', "
448 "led_operation = %d, led_argb = %d, "
449 "led_on_ms = %d, led_off_ms = %d, "
450 "flags_for_property = %d, flag_simmode = %d, "
451 "display_applist = %d, "
452 "progress_size = $progress_size, progress_percentage = $progress_percentage, "
453 "ongoing_flag = %d, auto_remove = %d "
454 "where priv_id = %d ",
457 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
458 NOTIFICATION_CHECK_STR(b_image_path),
459 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
460 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
461 NOTIFICATION_CHECK_STR(noti->domain),
462 NOTIFICATION_CHECK_STR(noti->dir),
463 (int)noti->time, (int)noti->insert_time,
464 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
465 NOTIFICATION_CHECK_STR(b_execute_option),
466 NOTIFICATION_CHECK_STR(b_service_responding),
467 NOTIFICATION_CHECK_STR(b_service_single_launch),
468 NOTIFICATION_CHECK_STR(b_service_multi_launch),
469 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
470 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
471 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
472 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
473 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
474 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
475 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
476 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
477 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
478 noti->vibration_type,
479 NOTIFICATION_CHECK_STR(noti->vibration_path),
484 noti->flags_for_property, flag_simmode, noti->display_applist,
485 noti->ongoing_flag, noti->auto_remove,
488 /* Free decoded data */
495 if (b_execute_option)
496 free(b_execute_option);
498 if (b_service_responding)
499 free(b_service_responding);
501 if (b_service_single_launch)
502 free(b_service_single_launch);
504 if (b_service_multi_launch)
505 free(b_service_multi_launch);
520 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
522 return NOTIFICATION_ERROR_NONE;
525 static void _notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notification_h noti)
530 if (stmt == NULL || noti == NULL)
533 noti->type = sqlite3_column_int(stmt, col++);
534 noti->layout = sqlite3_column_int(stmt, col++);
535 __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
536 __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
537 noti->b_image_path = notification_db_column_bundle(stmt, col++);
538 noti->group_id = sqlite3_column_int(stmt, col++);
539 noti->internal_group_id = 0;
540 noti->priv_id = sqlite3_column_int(stmt, col++);
541 __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
543 noti->b_text = notification_db_column_bundle(stmt, col++);
544 noti->b_key = notification_db_column_bundle(stmt, col++);
545 noti->b_format_args = notification_db_column_bundle(stmt, col++);
546 noti->num_format_args = sqlite3_column_int(stmt, col++);
548 __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
549 __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
550 noti->time = sqlite3_column_int(stmt, col++);
551 noti->insert_time = sqlite3_column_int(stmt, col++);
552 noti->args = notification_db_column_bundle(stmt, col++);
553 noti->group_args = notification_db_column_bundle(stmt, col++);
555 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
556 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
557 noti->b_service_single_launch =
558 notification_db_column_bundle(stmt, col++);
559 noti->b_service_multi_launch =
560 notification_db_column_bundle(stmt, col++);
562 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++)
563 noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
566 noti->sound_type = sqlite3_column_int(stmt, col++);
567 __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
568 noti->vibration_type = sqlite3_column_int(stmt, col++);
569 __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
570 noti->led_operation = sqlite3_column_int(stmt, col++);
571 noti->led_argb = sqlite3_column_int(stmt, col++);
572 noti->led_on_ms = sqlite3_column_int(stmt, col++);
573 noti->led_off_ms = sqlite3_column_int(stmt, col++);
575 noti->flags_for_property = sqlite3_column_int(stmt, col++);
576 noti->display_applist = sqlite3_column_int(stmt, col++);
577 noti->progress_size = sqlite3_column_double(stmt, col++);
578 noti->progress_percentage = sqlite3_column_double(stmt, col++);
580 noti->ongoing_flag = sqlite3_column_int(stmt, col++);
581 noti->auto_remove = sqlite3_column_int(stmt, col++);
583 noti->app_icon_path = NULL;
584 noti->app_name = NULL;
585 noti->temp_title = NULL;
586 noti->temp_content = NULL;
589 static notification_h _notification_noti_get_item(sqlite3_stmt *stmt)
591 notification_h noti = NULL;
593 noti = (notification_h) calloc(1, sizeof(struct _notification));
597 _notification_noti_populate_from_stmt(stmt, noti);
602 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
606 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
608 if (buf_len <= len_total)
609 return NOTIFICATION_ERROR_INVALID_PARAMETER;
611 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
613 return NOTIFICATION_ERROR_NONE;
616 char *notification_noti_strip_tag(const char *tagged_str)
618 if (tagged_str == NULL)
621 int len_total = strlen(tagged_str);
626 char *b_f_e = strstr(tagged_str, ">");
627 char *b_e_s = strstr(tagged_str, "</");
629 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
632 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
635 int notification_noti_get_tag_type(const char *tagged_str)
637 if (tagged_str == NULL)
638 return TAG_TYPE_INVALID;
640 if (strlen(tagged_str) == 0)
641 return TAG_TYPE_INVALID;
643 char *b_f_s = strstr(tagged_str, "<");
644 char *b_f_e = strstr(tagged_str, ">");
646 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
647 return TAG_TYPE_INVALID;
649 char *start = b_f_s + 1;
650 int len_tag = b_f_e - b_f_s - 1;
652 if (strncmp(start, TAG_TIME, len_tag) == 0)
653 return TAG_TYPE_TIME;
655 return TAG_TYPE_INVALID;
658 static int _notification_noti_update_priv_id(sqlite3 *db, int rowid)
660 int ret = NOTIFICATION_ERROR_NONE;
664 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
665 return NOTIFICATION_ERROR_INVALID_PARAMETER;
668 query = sqlite3_mprintf("UPDATE noti_list SET "
669 "priv_id = %d, internal_group_id = %d WHERE rowid = %d",
670 rowid, rowid, rowid);
672 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
676 ret = notification_db_exec(db, query, NULL);
686 static int _get_package_id_by_app_id(const char *app_id, char **package_id)
688 int err = NOTIFICATION_ERROR_NONE;
691 char *pkg_id_dup = NULL;
692 pkgmgrinfo_appinfo_h pkgmgrinfo_appinfo = NULL;
694 if (app_id == NULL || package_id == NULL) {
695 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
696 return NOTIFICATION_ERROR_INVALID_PARAMETER;
699 if ((retval = pkgmgrinfo_appinfo_get_appinfo(app_id, &pkgmgrinfo_appinfo)) != PMINFO_R_OK) {
700 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_appinfo failed [%d]", retval);
701 err = NOTIFICATION_ERROR_INVALID_OPERATION;
705 if ((retval = pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo, &pkg_id)) != PMINFO_R_OK || pkg_id == NULL) {
706 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_pkgname failed [%d]", retval);
707 err = NOTIFICATION_ERROR_INVALID_OPERATION;
711 pkg_id_dup = strdup(pkg_id);
713 if (pkg_id_dup == NULL) {
714 NOTIFICATION_ERR("strdup failed");
715 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
719 *package_id = pkg_id_dup;
722 if (pkgmgrinfo_appinfo)
723 pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
728 static bool _is_allowed_to_notify(const char *caller_package_name, uid_t uid)
730 notification_setting_h setting = NULL;
732 char *package_id = NULL;
735 err = noti_setting_service_get_setting_by_package_name(caller_package_name, &setting, uid);
736 if (err != NOTIFICATION_ERROR_NONE) {
737 /* Retry with package id */
738 err = _get_package_id_by_app_id(caller_package_name, &package_id);
740 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
741 NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
744 err = noti_setting_service_get_setting_by_package_name(package_id, &setting, uid);
745 if (err != NOTIFICATION_ERROR_NONE) {
746 NOTIFICATION_ERR("noti_setting_service_get_setting_by_package_name failed [%d]", err);
752 err = notification_setting_get_allow_to_notify(setting, &ret);
753 if (err != NOTIFICATION_ERROR_NONE) {
754 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
759 NOTIFICATION_DBG("[%s] is not allowed to notify", caller_package_name);
766 notification_setting_free_notification(setting);
771 static int _handle_do_not_disturb_option(notification_h noti)
773 int err = NOTIFICATION_ERROR_NONE;
774 bool do_not_disturb = false;
775 bool do_not_disturb_exception = false;
776 char *package_id = NULL;
777 notification_setting_h setting = NULL;
778 notification_system_setting_h system_setting = NULL;
781 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
782 return NOTIFICATION_ERROR_INVALID_PARAMETER;
785 /* Get system setting */
786 err = noti_system_setting_load_system_setting(&system_setting, noti->uid);
787 if (err != NOTIFICATION_ERROR_NONE) {
788 NOTIFICATION_ERR("_load_system_setting failed [%d]", err);
792 err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
793 if (err != NOTIFICATION_ERROR_NONE) {
794 NOTIFICATION_ERR("_get_do_not_disturb failed [%d]", err);
798 NOTIFICATION_DBG("do_not_disturb [%d]", do_not_disturb);
800 if (do_not_disturb) {
801 /* Check exception option of the caller package */
802 err = noti_setting_service_get_setting_by_package_name(noti->caller_pkgname, &setting, noti->uid);
803 if (err != NOTIFICATION_ERROR_NONE) {
804 /* Retry with package id */
805 err = _get_package_id_by_app_id(noti->caller_pkgname, &package_id);
806 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
807 NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
810 err = noti_setting_service_get_setting_by_package_name(package_id, &setting, noti->uid);
811 if (err != NOTIFICATION_ERROR_NONE) {
812 NOTIFICATION_ERR("_get_setting_by_package_name failed [%d]", err);
818 err = notification_setting_get_do_not_disturb_except(setting, &do_not_disturb_exception);
819 if (err != NOTIFICATION_ERROR_NONE) {
820 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
824 if (do_not_disturb_exception == false) {
825 /* do_not_disturb is ON and do_not_disturb_exception is OFF */
826 /* Then add this notification only on quick panel and indicator*/
827 noti->display_applist = noti->display_applist & (NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR);
828 /* and reset all sound and vibration and led options*/
829 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
830 SAFE_FREE(noti->sound_path);
831 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
832 SAFE_FREE(noti->vibration_path);
833 noti->led_operation = NOTIFICATION_LED_OP_OFF;
836 noti->led_off_ms = 0;
841 SAFE_FREE(package_id);
844 notification_system_setting_free_system_setting(system_setting);
847 notification_setting_free_notification(setting);
852 EXPORT_API int notification_noti_insert(notification_h noti)
856 sqlite3_stmt *stmt = NULL;
858 char buf_key[32] = { 0, };
859 char *title_key = NULL;
862 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
863 return NOTIFICATION_ERROR_INVALID_PARAMETER;
866 if (_is_allowed_to_notify((const char *)noti->caller_pkgname, noti->uid) == false) {
867 NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
868 return NOTIFICATION_ERROR_PERMISSION_DENIED;
871 if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE)
872 NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
875 db = notification_db_open(DBPATH);
877 return get_last_result();
879 /* Initialize private ID */
880 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
881 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
883 ret = _insertion_query_create(noti, &query);
884 if (ret != NOTIFICATION_ERROR_NONE)
887 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
888 if (ret != SQLITE_OK) {
889 NOTIFICATION_ERR("Insert Query : %s", query);
890 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
892 ret = NOTIFICATION_ERROR_FROM_DB;
897 if (noti->b_key != NULL) {
898 snprintf(buf_key, sizeof(buf_key), "%d",
899 NOTIFICATION_TEXT_TYPE_TITLE);
901 bundle_get_str(noti->b_key, buf_key, &title_key);
904 if (title_key == NULL && noti->b_text != NULL) {
905 snprintf(buf_key, sizeof(buf_key), "%d",
906 NOTIFICATION_TEXT_TYPE_TITLE);
908 bundle_get_str(noti->b_text, buf_key, &title_key);
911 if (title_key == NULL)
912 title_key = noti->caller_pkgname;
915 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
916 if (ret != NOTIFICATION_ERROR_NONE) {
917 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
920 ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
921 if (ret != NOTIFICATION_ERROR_NONE) {
922 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
925 ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
926 if (ret != NOTIFICATION_ERROR_NONE) {
927 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
930 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
931 if (ret != NOTIFICATION_ERROR_NONE) {
932 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
936 ret = sqlite3_step(stmt);
937 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
938 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
940 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0)
941 ret = NOTIFICATION_ERROR_NONE;
943 ret = NOTIFICATION_ERROR_FROM_DB;
946 ret = NOTIFICATION_ERROR_FROM_DB;
950 sqlite3_finalize(stmt);
953 notification_db_close(&db);
961 /* LCOV_EXCL_START */
962 EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id, uid_t uid)
967 sqlite3_stmt *stmt = NULL;
969 if (priv_id < 0 || noti == NULL) {
970 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
974 db = notification_db_open(DBPATH);
976 return get_last_result();
978 char *base_query = "select "
979 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
980 "tag, b_text, b_key, b_format_args, num_format_args, "
981 "text_domain, text_dir, time, insert_time, args, group_args, "
982 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
983 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
984 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
985 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
986 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
987 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
990 if (pkgname != NULL && strlen(pkgname) != 0)
991 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d and uid = %d",
992 base_query, pkgname, priv_id, uid);
994 query = sqlite3_mprintf("%s where priv_id = %d and uid = %d", base_query, priv_id, uid);
997 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1001 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1002 if (ret != SQLITE_OK) {
1003 NOTIFICATION_ERR("select Query : %s", query);
1004 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
1005 sqlite3_errmsg(db));
1006 ret = NOTIFICATION_ERROR_FROM_DB;
1010 ret = sqlite3_step(stmt);
1011 if (ret == SQLITE_ROW) {
1012 _notification_noti_populate_from_stmt(stmt, noti);
1013 ret = NOTIFICATION_ERROR_NONE;
1015 ret = NOTIFICATION_ERROR_FROM_DB;
1020 sqlite3_free(query);
1023 sqlite3_finalize(stmt);
1026 notification_db_close(&db);
1030 /* LCOV_EXCL_STOP */
1032 EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char *tag, uid_t uid)
1036 sqlite3_stmt *stmt = NULL;
1038 if (tag == NULL || noti == NULL) {
1039 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
1040 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1043 db = notification_db_open(DBPATH);
1045 return get_last_result();
1047 if (pkgname != NULL && strlen(pkgname) != 0) {
1048 ret = sqlite3_prepare_v2(db, "select "
1049 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1050 "tag, b_text, b_key, b_format_args, num_format_args, "
1051 "text_domain, text_dir, time, insert_time, args, group_args, "
1052 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1053 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1054 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1055 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1056 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1057 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1058 "from noti_list where caller_pkgname = ? and tag = ? and uid = ?", -1, &stmt, NULL);
1059 if (ret != SQLITE_OK) {
1060 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1061 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1064 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
1065 if (ret != SQLITE_OK) {
1066 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1070 ret = sqlite3_bind_text(stmt, 2, tag, -1, SQLITE_TRANSIENT);
1071 if (ret != SQLITE_OK) {
1072 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1076 ret = sqlite3_bind_int(stmt, 3, uid);
1077 if (ret != SQLITE_OK) {
1078 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1083 ret = sqlite3_prepare_v2(db, "select "
1084 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1085 "tag, b_text, b_key, b_format_args, num_format_args, "
1086 "text_domain, text_dir, time, insert_time, args, group_args, "
1087 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1088 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1089 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1090 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1091 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1092 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1093 "from noti_list where tag = ? and uid = ?", -1, &stmt, NULL);
1094 if (ret != SQLITE_OK) {
1095 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1096 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1099 ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
1100 if (ret != SQLITE_OK) {
1101 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1105 ret = sqlite3_bind_int(stmt, 2, uid);
1106 if (ret != SQLITE_OK) {
1107 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1112 ret = sqlite3_step(stmt);
1113 if (ret == SQLITE_ROW) {
1114 _notification_noti_populate_from_stmt(stmt, noti);
1115 ret = NOTIFICATION_ERROR_NONE;
1117 ret = NOTIFICATION_ERROR_FROM_DB;
1123 sqlite3_finalize(stmt);
1126 notification_db_close(&db);
1131 EXPORT_API int notification_noti_update(notification_h noti)
1135 sqlite3_stmt *stmt = NULL;
1138 db = notification_db_open(DBPATH);
1140 return get_last_result();
1142 if (_is_allowed_to_notify((const char *)noti->caller_pkgname, noti->uid) == false) {
1143 NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
1144 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1147 if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE)
1148 NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
1150 /* Check private ID is exist */
1151 ret = _notification_noti_check_priv_id(noti, db);
1152 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
1153 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1157 /* make update query */
1158 ret = _update_query_create(noti, &query);
1159 if (ret != NOTIFICATION_ERROR_NONE)
1162 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1163 if (ret != SQLITE_OK) {
1164 NOTIFICATION_ERR("Insert Query : %s", query);
1165 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
1166 sqlite3_errmsg(db));
1167 ret = NOTIFICATION_ERROR_FROM_DB;
1171 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
1172 if (ret != NOTIFICATION_ERROR_NONE) {
1173 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1177 ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
1178 if (ret != NOTIFICATION_ERROR_NONE) {
1179 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1183 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
1184 if (ret != NOTIFICATION_ERROR_NONE) {
1185 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1189 ret = sqlite3_step(stmt);
1190 if (ret == SQLITE_OK || ret == SQLITE_DONE)
1191 ret = NOTIFICATION_ERROR_NONE;
1193 ret = NOTIFICATION_ERROR_FROM_DB;
1197 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, uid_t uid)
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];
1221 db = notification_db_open(DBPATH);
1223 return get_last_result();
1225 if (pkgname == NULL || strlen(pkgname) == 0) {
1226 if (type != NOTIFICATION_TYPE_NONE)
1227 snprintf(query_where, sizeof(query_where),
1228 "where type = %d and uid = %d", type, uid);
1231 if (type == NOTIFICATION_TYPE_NONE)
1232 snprintf(query_where, sizeof(query_where),
1233 "where caller_pkgname = '%s' and uid = %d", pkgname, uid);
1235 snprintf(query_where, sizeof(query_where),
1236 "where caller_pkgname = '%s' and type = %d and uid = %d",
1237 pkgname, type, uid);
1240 if (num_deleted != NULL)
1243 if (list_deleted_rowid != NULL) {
1244 *list_deleted_rowid = NULL;
1245 snprintf(query, sizeof(query),
1246 "select priv_id from noti_list %s ", query_where);
1248 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1249 if (ret != SQLITE_OK) {
1250 NOTIFICATION_ERR("Select Query : %s", query);
1251 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1252 sqlite3_errmsg(db));
1254 ret = NOTIFICATION_ERROR_FROM_DB;
1258 while (sqlite3_step(stmt) == SQLITE_ROW) {
1259 if (data_cnt % 8 == 0) {
1262 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1264 *list_deleted_rowid = tmp;
1266 NOTIFICATION_ERR("Heap: %s\n", strerror_r(errno, err_buf, sizeof(err_buf)));
1269 * How can I handle this?
1271 free(*list_deleted_rowid);
1272 *list_deleted_rowid = NULL;
1273 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1277 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1282 sqlite3_finalize(stmt);
1287 query_where[0] = '\0';
1288 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1289 for (i = 0; i < data_cnt ; i++) {
1290 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1291 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1292 ret_tmp = notification_db_exec(db, query, NULL);
1293 query_where[0] = '\0';
1294 if (ret == NOTIFICATION_ERROR_NONE)
1298 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1299 strncat(query_where, buf, sizeof(query_where) - strlen(query_where) - 1);
1301 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0)) {
1302 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1303 ret_tmp = notification_db_exec(db, query, NULL);
1304 if (ret == NOTIFICATION_ERROR_NONE)
1308 free(*list_deleted_rowid);
1309 *list_deleted_rowid = NULL;
1312 if (num_deleted != NULL)
1313 *num_deleted = data_cnt;
1316 /* Make main query */
1317 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1318 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1320 ret = notification_db_exec(db, query, NULL);
1322 if (num_deleted != NULL)
1323 *num_deleted = sqlite3_changes(db);
1329 sqlite3_finalize(stmt);
1332 notification_db_close(&db);
1337 /* LCOV_EXCL_START */
1338 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1341 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1344 if (pkgname == NULL)
1345 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1347 db = notification_db_open(DBPATH);
1349 return get_last_result();
1351 snprintf(query, sizeof(query), "delete from noti_list "
1352 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1355 ret = notification_db_exec(db, query, NULL);
1358 notification_db_close(&db);
1362 /* LCOV_EXCL_STOP */
1364 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes, uid_t uid)
1367 char query[NOTIFICATION_QUERY_MAX] = {0, };
1370 db = notification_db_open(DBPATH);
1372 return get_last_result();
1374 if (pkgname == NULL || strlen(pkgname) == 0) {
1375 snprintf(query, sizeof(query), "delete from noti_list "
1376 "where priv_id = %d and uid = %d", priv_id, uid);
1378 snprintf(query, sizeof(query), "delete from noti_list "
1379 "where caller_pkgname = '%s' and priv_id = %d and uid = %d",
1380 pkgname, priv_id, uid);
1383 ret = notification_db_exec(db, query, num_changes);
1385 if (num_changes != NULL)
1386 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1389 notification_db_close(&db);
1394 /* todo refactoring */
1395 /* LCOV_EXCL_START */
1396 EXPORT_API int notification_noti_get_count(notification_type_e type,
1397 const char *pkgname,
1398 int group_id, int priv_id,
1399 int *count, uid_t uid)
1402 sqlite3_stmt *stmt = NULL;
1403 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1404 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1405 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1406 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1408 int ret = 0, get_count = 0, internal_group_id = 0;
1409 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1410 int flag_where_more = 0;
1413 db = notification_db_open(DBPATH);
1415 return get_last_result();
1417 /* Check current sim status */
1418 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1420 snprintf(query_base, sizeof(query_base),
1421 "select count(*) from noti_list ");
1423 if (pkgname != NULL && strlen(pkgname) != 0) {
1424 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1425 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1426 snprintf(query_where, sizeof(query_where),
1427 "where caller_pkgname = '%s' and uid = %d ",
1431 _notification_noti_get_internal_group_id_by_priv_id
1432 (pkgname, priv_id, db);
1433 snprintf(query_where, sizeof(query_where),
1434 "where caller_pkgname = '%s' and internal_group_id = %d and uid = %d ",
1435 pkgname, internal_group_id, uid);
1438 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1439 snprintf(query_where, sizeof(query_where),
1440 "where caller_pkgname = '%s' and group_id = %d and uid = %d ",
1441 pkgname, group_id, uid);
1444 _notification_noti_get_internal_group_id_by_priv_id
1445 (pkgname, priv_id, db);
1446 snprintf(query_where, sizeof(query_where),
1447 "where caller_pkgname = '%s' and internal_group_id = %d and uid = %d ",
1448 pkgname, internal_group_id, uid);
1452 snprintf(query_where, sizeof(query_where), "where uid = %d", uid);
1455 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1456 if (type != NOTIFICATION_TYPE_NONE) {
1457 snprintf(query_where_more, sizeof(query_where_more),
1458 "type = %d ", type);
1459 flag_where_more = 1;
1462 if (type != NOTIFICATION_TYPE_NONE) {
1463 snprintf(query_where_more, sizeof(query_where_more),
1464 "type = %d and flag_simmode = 0 ", type);
1465 flag_where_more = 1;
1467 snprintf(query_where_more, sizeof(query_where_more),
1468 "flag_simmode = 0 ");
1469 flag_where_more = 1;
1473 if (flag_where_more == 1) {
1474 snprintf(query, sizeof(query), "%s %s and %s",
1475 query_base, query_where, query_where_more);
1477 snprintf(query, sizeof(query), "%s %s", query_base,
1481 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1482 if (ret != SQLITE_OK) {
1483 NOTIFICATION_ERR("Select Query : %s", query);
1484 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1485 sqlite3_errmsg(db));
1487 ret = NOTIFICATION_ERROR_FROM_DB;
1491 ret = sqlite3_step(stmt);
1492 if (ret == SQLITE_ROW)
1493 get_count = sqlite3_column_int(stmt, 0);
1495 ret = NOTIFICATION_ERROR_NONE;
1499 sqlite3_finalize(stmt);
1503 notification_db_close(&db);
1509 /* LCOV_EXCL_STOP */
1511 EXPORT_API int notification_noti_get_grouping_list(notification_type_e type,
1513 notification_list_h *list,
1517 sqlite3_stmt *stmt = NULL;
1518 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1519 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1520 char query_uid[NOTIFICATION_QUERY_MAX] = { 0, };
1521 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1524 notification_list_h get_list = NULL;
1525 notification_h noti = NULL;
1526 int internal_count = 0;
1529 db = notification_db_open(DBPATH);
1531 return get_last_result();
1533 /* Check current sim status */
1534 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1536 snprintf(query_base, sizeof(query_base), "select "
1537 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1538 "tag, b_text, b_key, b_format_args, num_format_args, "
1539 "text_domain, text_dir, time, insert_time, args, group_args, "
1540 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1541 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1542 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1543 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1544 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1545 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1546 "from noti_list where 1 > 0 ");
1548 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1549 if (type != NOTIFICATION_TYPE_NONE)
1550 snprintf(query_where, sizeof(query_where),
1551 " and type = %d ", type);
1553 if (type != NOTIFICATION_TYPE_NONE)
1554 snprintf(query_where, sizeof(query_where),
1555 " and type = %d and flag_simmode = 0 ", type);
1557 snprintf(query_where, sizeof(query_where),
1558 " and flag_simmode = 0 ");
1561 if (uid != NOTIFICATION_GLOBAL_UID)
1562 snprintf(query_uid, sizeof(query_uid), " and uid = %d ", uid);
1564 snprintf(query, sizeof(query),
1566 "group by internal_group_id "
1567 "order by rowid desc, time desc", query_base, query_where, query_uid);
1569 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1570 if (ret != SQLITE_OK) {
1571 NOTIFICATION_ERR("Select Query : %s", query);
1572 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1573 sqlite3_errmsg(db));
1575 ret = NOTIFICATION_ERROR_FROM_DB;
1579 while (sqlite3_step(stmt) == SQLITE_ROW) {
1580 /* Make notification list */
1581 noti = _notification_noti_get_item(stmt);
1585 get_list = notification_list_append(get_list, noti);
1587 if (count != -1 && internal_count >= count) {
1589 ("internal count %d >= count %d",
1590 internal_count, count);
1596 ret = NOTIFICATION_ERROR_NONE;
1600 sqlite3_finalize(stmt);
1603 notification_db_close(&db);
1605 if (get_list != NULL)
1606 *list = notification_list_get_head(get_list);
1611 EXPORT_API int notification_noti_get_detail_list(const char *pkgname,
1613 int priv_id, int count,
1614 notification_list_h *list,
1618 sqlite3_stmt *stmt = NULL;
1619 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1620 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1622 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1624 notification_list_h get_list = NULL;
1625 notification_h noti = NULL;
1626 int internal_count = 0;
1627 int internal_group_id = 0;
1628 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1630 db = notification_db_open(DBPATH);
1632 return get_last_result();
1634 /* Check current sim status */
1635 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1637 snprintf(query_base, sizeof(query_base), "select "
1638 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1639 "tag, b_text, b_key, b_format_args, num_format_args, "
1640 "text_domain, text_dir, time, insert_time, args, group_args, "
1641 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1642 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1643 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1644 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1645 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1646 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1649 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1650 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
1651 snprintf(query_where, sizeof(query_where),
1652 "where caller_pkgname = '%s' and uid = %d ", pkgname, uid);
1654 snprintf(query_where, sizeof(query_where),
1655 "where caller_pkgname = '%s' and flag_simmode = 0 and uid = %d ", pkgname, uid);
1659 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1662 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
1663 snprintf(query_where, sizeof(query_where),
1664 "where caller_pkgname = '%s' and internal_group_id = %d and uid = %d ",
1665 pkgname, internal_group_id, uid);
1667 snprintf(query_where, sizeof(query_where),
1668 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 and uid = %d ",
1669 pkgname, internal_group_id, uid);
1672 snprintf(query, sizeof(query),
1674 "order by rowid desc, time desc", query_base, query_where);
1676 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1677 if (ret != SQLITE_OK) {
1678 NOTIFICATION_ERR("Select Query : %s", query);
1679 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1680 sqlite3_errmsg(db));
1682 ret = NOTIFICATION_ERROR_FROM_DB;
1686 while (sqlite3_step(stmt) == SQLITE_ROW) {
1687 /* Make notification list */
1688 noti = _notification_noti_get_item(stmt);
1692 get_list = notification_list_append(get_list, noti);
1694 if (count != -1 && internal_count >= count) {
1696 ("internal count %d >= count %d",
1697 internal_count, count);
1703 ret = NOTIFICATION_ERROR_NONE;
1707 sqlite3_finalize(stmt);
1710 notification_db_close(&db);
1712 if (get_list != NULL)
1713 *list = notification_list_get_head(get_list);
1718 EXPORT_API int notification_noti_check_tag(notification_h noti)
1721 int ret = NOTIFICATION_ERROR_NONE;
1723 sqlite3_stmt *stmt = NULL;
1725 if (noti->tag == NULL)
1726 return NOTIFICATION_ERROR_NOT_EXIST_ID;
1728 db = notification_db_open(DBPATH);
1730 return get_last_result();
1732 ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1733 if (ret != SQLITE_OK) {
1734 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1736 notification_db_close(&db);
1737 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1740 ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
1741 if (ret != SQLITE_OK) {
1742 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1746 ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
1747 if (ret != SQLITE_OK) {
1748 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1752 ret = sqlite3_step(stmt);
1753 if (ret == SQLITE_ROW)
1754 result = sqlite3_column_int(stmt, 0);
1758 sqlite3_finalize(stmt);
1760 /* If result > 0, there is priv_id in DB */
1762 noti->priv_id = result;
1763 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
1765 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1770 notification_db_close(&db);
1775 EXPORT_API int notification_noti_check_count_for_template(notification_h noti, int *count)
1778 int ret = NOTIFICATION_ERROR_NONE;
1780 sqlite3_stmt *stmt = NULL;
1782 if (noti == NULL || count == NULL)
1783 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1785 db = notification_db_open(DBPATH);
1787 return get_last_result();
1789 ret = sqlite3_prepare_v2(db, "SELECT COUNT(caller_pkgname) FROM noti_template WHERE caller_pkgname = ?", -1, &stmt, NULL);
1790 if (ret != SQLITE_OK) {
1791 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1793 notification_db_close(&db);
1794 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1797 ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
1798 if (ret != SQLITE_OK) {
1799 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1803 ret = sqlite3_step(stmt);
1804 if (ret == SQLITE_ROW)
1805 result = sqlite3_column_int(stmt, 0);
1811 sqlite3_finalize(stmt);
1814 notification_db_close(&db);
1819 static int _template_query_create(notification_h noti, char *template_name, char **query)
1822 int b_encode_len = 0;
1824 char *group_args = NULL;
1825 char *b_image_path = NULL;
1826 char *b_execute_option = NULL;
1827 char *b_service_responding = NULL;
1828 char *b_service_single_launch = NULL;
1829 char *b_service_multi_launch = NULL;
1830 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
1831 char *b_text = NULL;
1833 char *b_format_args = NULL;
1834 int flag_simmode = 0;
1836 if (query == NULL || template_name == NULL)
1837 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1839 /* Decode bundle to insert DB */
1841 bundle_encode(noti->args, (bundle_raw **)&args, &b_encode_len);
1843 if (noti->group_args)
1844 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
1847 if (noti->b_execute_option)
1848 bundle_encode(noti->b_execute_option,
1849 (bundle_raw **)&b_execute_option, &b_encode_len);
1851 if (noti->b_service_responding)
1852 bundle_encode(noti->b_service_responding,
1853 (bundle_raw **)&b_service_responding, &b_encode_len);
1855 if (noti->b_service_single_launch)
1856 bundle_encode(noti->b_service_single_launch,
1857 (bundle_raw **)&b_service_single_launch, &b_encode_len);
1859 if (noti->b_service_multi_launch)
1860 bundle_encode(noti->b_service_multi_launch,
1861 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
1864 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
1865 if (noti->b_event_handler[i])
1866 bundle_encode(noti->b_event_handler[i],
1867 (bundle_raw **)&b_event_handler[i], &b_encode_len);
1871 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
1874 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
1876 if (noti->b_format_args)
1877 bundle_encode(noti->b_format_args,
1878 (bundle_raw **)&b_format_args, &b_encode_len);
1880 if (noti->b_image_path)
1881 bundle_encode(noti->b_image_path,
1882 (bundle_raw **)&b_image_path, &b_encode_len);
1884 /* Check only simmode property is enable */
1885 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
1888 *query = sqlite3_mprintf("INSERT OR REPLACE INTO noti_template ("
1891 "caller_pkgname, launch_pkgname, "
1893 "group_id, internal_group_id,"
1895 "b_text, b_key, tag, b_format_args, num_format_args, "
1896 "text_domain, text_dir, "
1897 "time, insert_time, "
1898 "args, group_args, "
1899 "b_execute_option, "
1900 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
1901 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1902 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1903 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1904 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1905 "flags_for_property, flag_simmode, display_applist, "
1906 "progress_size, progress_percentage, ongoing_flag, auto_remove, uid, template_name) values ("
1913 "'%s', '%s', $tag, '%s', %d, "
1918 "'%s', '%s', '%s', "
1919 "'%s', '%s', '%s', "
1920 "'%s', '%s', '%s', "
1922 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
1924 "$progress_size, $progress_percentage, %d, %d, %d, '%s')",
1927 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
1928 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
1929 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
1930 noti->internal_group_id,
1931 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
1932 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
1933 NOTIFICATION_CHECK_STR(noti->domain),
1934 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
1935 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
1936 NOTIFICATION_CHECK_STR(group_args),
1937 NOTIFICATION_CHECK_STR(b_execute_option),
1938 NOTIFICATION_CHECK_STR(b_service_responding),
1939 NOTIFICATION_CHECK_STR(b_service_single_launch),
1940 NOTIFICATION_CHECK_STR(b_service_multi_launch),
1941 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
1942 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
1943 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
1944 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
1945 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
1946 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
1947 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
1948 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
1949 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
1950 noti->vibration_type,
1951 NOTIFICATION_CHECK_STR(noti->vibration_path),
1952 noti->led_operation,
1956 noti->flags_for_property, flag_simmode, noti->display_applist,
1962 /* Free decoded data */
1969 if (b_execute_option)
1970 free(b_execute_option);
1972 if (b_service_responding)
1973 free(b_service_responding);
1975 if (b_service_single_launch)
1976 free(b_service_single_launch);
1978 if (b_service_multi_launch)
1979 free(b_service_multi_launch);
1988 free(b_format_args);
1994 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1996 return NOTIFICATION_ERROR_NONE;
1999 EXPORT_API int notification_noti_add_template(notification_h noti, char *template_name)
2003 sqlite3_stmt *stmt = NULL;
2005 char buf_key[32] = { 0, };
2006 char *title_key = NULL;
2008 if (noti == NULL || template_name == NULL) {
2009 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
2010 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2013 db = notification_db_open(DBPATH);
2015 return get_last_result();
2017 /* Initialize private ID */
2018 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
2019 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
2021 ret = _template_query_create(noti, template_name, &query);
2022 if (ret != NOTIFICATION_ERROR_NONE)
2025 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
2026 if (ret != SQLITE_OK) {
2027 NOTIFICATION_ERR("Insert Query : %s", query);
2028 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
2029 sqlite3_errmsg(db));
2030 ret = NOTIFICATION_ERROR_FROM_DB;
2035 if (noti->b_key != NULL) {
2036 snprintf(buf_key, sizeof(buf_key), "%d",
2037 NOTIFICATION_TEXT_TYPE_TITLE);
2039 bundle_get_str(noti->b_key, buf_key, &title_key);
2042 if (title_key == NULL && noti->b_text != NULL) {
2043 snprintf(buf_key, sizeof(buf_key), "%d",
2044 NOTIFICATION_TEXT_TYPE_TITLE);
2046 bundle_get_str(noti->b_text, buf_key, &title_key);
2049 if (title_key == NULL)
2050 title_key = noti->caller_pkgname;
2053 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
2054 if (ret != NOTIFICATION_ERROR_NONE) {
2055 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
2058 ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
2059 if (ret != NOTIFICATION_ERROR_NONE) {
2060 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
2063 ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
2064 if (ret != NOTIFICATION_ERROR_NONE) {
2065 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
2068 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
2069 if (ret != NOTIFICATION_ERROR_NONE) {
2070 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
2074 ret = sqlite3_step(stmt);
2075 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
2076 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
2078 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0)
2079 ret = NOTIFICATION_ERROR_NONE;
2081 ret = NOTIFICATION_ERROR_FROM_DB;
2084 ret = NOTIFICATION_ERROR_FROM_DB;
2088 sqlite3_finalize(stmt);
2091 notification_db_close(&db);
2094 sqlite3_free(query);
2099 EXPORT_API int notification_noti_get_package_template(notification_h noti, char *pkgname, char *template_name)
2103 sqlite3_stmt *stmt = NULL;
2105 if (noti == NULL || pkgname == NULL || template_name == NULL) {
2106 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
2107 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2110 db = notification_db_open(DBPATH);
2112 return get_last_result();
2114 ret = sqlite3_prepare_v2(db, "select "
2115 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
2116 "tag, b_text, b_key, b_format_args, num_format_args, "
2117 "text_domain, text_dir, time, insert_time, args, group_args, "
2118 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
2119 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
2120 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
2121 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
2122 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
2123 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
2124 "from noti_template where caller_pkgname = ? and template_name = ?", -1, &stmt, NULL);
2125 if (ret != SQLITE_OK) {
2126 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
2127 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
2130 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
2131 if (ret != SQLITE_OK) {
2132 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
2136 ret = sqlite3_bind_text(stmt, 2, template_name, -1, SQLITE_TRANSIENT);
2137 if (ret != SQLITE_OK) {
2138 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
2142 ret = sqlite3_step(stmt);
2143 if (ret == SQLITE_ROW) {
2144 _notification_noti_populate_from_stmt(stmt, noti);
2145 ret = NOTIFICATION_ERROR_NONE;
2147 NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB");
2148 ret = NOTIFICATION_ERROR_FROM_DB;
2154 sqlite3_finalize(stmt);
2157 notification_db_close(&db);
2162 EXPORT_API int notification_noti_delete_template(const char *pkgname)
2165 char query[NOTIFICATION_QUERY_MAX] = { 0, };
2168 if (pkgname == NULL)
2169 return NOTIFICATION_ERROR_INVALID_PARAMETER;
2171 db = notification_db_open(DBPATH);
2173 return get_last_result();
2175 snprintf(query, sizeof(query), "delete from noti_template "
2176 "where caller_pkgname = '%s'", pkgname);
2178 ret = notification_db_exec(db, query, NULL);
2181 notification_db_close(&db);