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;
62 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
64 if (ret != SQLITE_OK) {
65 NOTIFICATION_ERR("Insert text : %s",
66 NOTIFICATION_CHECK_STR(str));
67 return NOTIFICATION_ERROR_FROM_DB;
70 return NOTIFICATION_ERROR_NONE;
73 static int _notification_noti_bind_query_double(sqlite3_stmt *stmt, const char *name,
79 index = sqlite3_bind_parameter_index(stmt, name);
81 NOTIFICATION_ERR("Insert : invalid column name");
82 return NOTIFICATION_ERROR_FROM_DB;
85 ret = sqlite3_bind_double(stmt, index, val);
86 if (ret != SQLITE_OK) {
87 NOTIFICATION_ERR("Insert double : %f", val);
88 return NOTIFICATION_ERROR_FROM_DB;
91 return NOTIFICATION_ERROR_NONE;
94 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 *db)
97 int ret = NOTIFICATION_ERROR_NONE;
99 sqlite3_stmt *stmt = NULL;
101 /* Make query to check priv_id exist */
102 query = sqlite3_mprintf("SELECT count(*) FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
103 noti->caller_pkgname, noti->priv_id);
105 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
109 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
110 if (ret != SQLITE_OK) {
111 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
113 ret = NOTIFICATION_ERROR_FROM_DB;
117 ret = sqlite3_step(stmt);
118 if (ret == SQLITE_ROW)
119 result = sqlite3_column_int(stmt, 0);
123 sqlite3_finalize(stmt);
125 /* If result > 0, there is priv_id in DB */
127 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
136 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
141 sqlite3_stmt *stmt = NULL;
142 int ret = NOTIFICATION_ERROR_NONE, result = 0;
144 query = sqlite3_mprintf("SELECT internal_group_id FROM noti_list WHERE caller_pkgname = '%s' AND priv_id = %d",
147 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
151 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
152 if (ret != SQLITE_OK) {
153 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
155 ret = NOTIFICATION_ERROR_FROM_DB;
159 ret = sqlite3_step(stmt);
160 if (ret == SQLITE_ROW)
161 result = sqlite3_column_int(stmt, 0);
167 sqlite3_finalize(stmt);
172 if (ret != NOTIFICATION_ERROR_NONE)
173 NOTIFICATION_ERR("failed to internal group ID:%d", ret);
178 static int _insertion_query_create(notification_h noti, char **query)
181 int b_encode_len = 0;
183 char *group_args = NULL;
184 char *b_image_path = NULL;
185 char *b_execute_option = NULL;
186 char *b_service_responding = NULL;
187 char *b_service_single_launch = NULL;
188 char *b_service_multi_launch = NULL;
189 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
192 char *b_format_args = NULL;
193 int flag_simmode = 0;
196 return NOTIFICATION_ERROR_INVALID_PARAMETER;
198 /* Decode bundle to insert DB */
200 bundle_encode(noti->args, (bundle_raw **)&args, &b_encode_len);
202 if (noti->group_args)
203 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
206 if (noti->b_execute_option)
207 bundle_encode(noti->b_execute_option,
208 (bundle_raw **)&b_execute_option, &b_encode_len);
210 if (noti->b_service_responding)
211 bundle_encode(noti->b_service_responding,
212 (bundle_raw **)&b_service_responding, &b_encode_len);
214 if (noti->b_service_single_launch)
215 bundle_encode(noti->b_service_single_launch,
216 (bundle_raw **)&b_service_single_launch, &b_encode_len);
218 if (noti->b_service_multi_launch)
219 bundle_encode(noti->b_service_multi_launch,
220 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
223 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
224 if (noti->b_event_handler[i])
225 bundle_encode(noti->b_event_handler[i],
226 (bundle_raw **)&b_event_handler[i], &b_encode_len);
230 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
233 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
235 if (noti->b_format_args)
236 bundle_encode(noti->b_format_args,
237 (bundle_raw **)&b_format_args, &b_encode_len);
239 if (noti->b_image_path)
240 bundle_encode(noti->b_image_path,
241 (bundle_raw **)&b_image_path, &b_encode_len);
243 /* Check only simmode property is enable */
244 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
248 *query = sqlite3_mprintf("INSERT INTO noti_list ("
251 "caller_pkgname, launch_pkgname, "
253 "group_id, internal_group_id,"
255 "b_text, b_key, tag, b_format_args, num_format_args, "
256 "text_domain, text_dir, "
257 "time, insert_time, "
260 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
261 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
262 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
263 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
264 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
265 "flags_for_property, flag_simmode, display_applist, "
266 "progress_size, progress_percentage, ongoing_flag, auto_remove, uid) values ("
273 "'%s', '%s', $tag, '%s', %d, "
282 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
284 "$progress_size, $progress_percentage, %d, %d, %d)",
287 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
288 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
289 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
290 noti->internal_group_id,
291 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
292 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
293 NOTIFICATION_CHECK_STR(noti->domain),
294 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
295 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
296 NOTIFICATION_CHECK_STR(group_args),
297 NOTIFICATION_CHECK_STR(b_execute_option),
298 NOTIFICATION_CHECK_STR(b_service_responding),
299 NOTIFICATION_CHECK_STR(b_service_single_launch),
300 NOTIFICATION_CHECK_STR(b_service_multi_launch),
301 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
302 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
303 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
304 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
305 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
306 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
307 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
308 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
309 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
310 noti->vibration_type,
311 NOTIFICATION_CHECK_STR(noti->vibration_path),
316 noti->flags_for_property, flag_simmode, noti->display_applist,
321 /* Free decoded data */
328 if (b_execute_option)
329 free(b_execute_option);
331 if (b_service_responding)
332 free(b_service_responding);
334 if (b_service_single_launch)
335 free(b_service_single_launch);
337 if (b_service_multi_launch)
338 free(b_service_multi_launch);
353 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
355 return NOTIFICATION_ERROR_NONE;
358 static int _update_query_create(notification_h noti, char **query)
361 int b_encode_len = 0;
363 char *group_args = NULL;
364 char *b_image_path = NULL;
365 char *b_execute_option = NULL;
366 char *b_service_responding = NULL;
367 char *b_service_single_launch = NULL;
368 char *b_service_multi_launch = NULL;
369 char *b_event_handler[NOTIFICATION_EVENT_TYPE_MAX] = { NULL , };
372 char *b_format_args = NULL;
373 int flag_simmode = 0;
376 return NOTIFICATION_ERROR_INVALID_PARAMETER;
378 /* Decode bundle to update DB */
380 bundle_encode(noti->args, (bundle_raw **)&args, &b_encode_len);
382 if (noti->group_args)
383 bundle_encode(noti->group_args, (bundle_raw **)&group_args,
386 if (noti->b_execute_option)
387 bundle_encode(noti->b_execute_option,
388 (bundle_raw **)&b_execute_option, &b_encode_len);
390 if (noti->b_service_responding)
391 bundle_encode(noti->b_service_responding,
392 (bundle_raw **)&b_service_responding, &b_encode_len);
394 if (noti->b_service_single_launch)
395 bundle_encode(noti->b_service_single_launch,
396 (bundle_raw **)&b_service_single_launch, &b_encode_len);
398 if (noti->b_service_multi_launch)
399 bundle_encode(noti->b_service_multi_launch,
400 (bundle_raw **)&b_service_multi_launch, &b_encode_len);
402 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++) {
403 if (noti->b_event_handler[i])
404 bundle_encode(noti->b_event_handler[i],
405 (bundle_raw **)&b_event_handler[i], &b_encode_len);
409 bundle_encode(noti->b_text, (bundle_raw **)&b_text, &b_encode_len);
412 bundle_encode(noti->b_key, (bundle_raw **)&b_key, &b_encode_len);
414 if (noti->b_format_args)
415 bundle_encode(noti->b_format_args,
416 (bundle_raw **)&b_format_args, &b_encode_len);
418 if (noti->b_image_path)
419 bundle_encode(noti->b_image_path,
420 (bundle_raw **)&b_image_path, &b_encode_len);
422 /* Check only simmode property is enable */
423 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE)
427 *query = sqlite3_mprintf("UPDATE noti_list SET "
430 "launch_pkgname = '%s', "
431 "image_path = '%s', "
432 "b_text = '%s', b_key = '%s', tag = $tag, "
433 "b_format_args = '%s', num_format_args = %d, "
434 "text_domain = '%s', text_dir = '%s', "
435 "time = %d, insert_time = %d, "
436 "args = '%s', group_args = '%s', "
437 "b_execute_option = '%s', "
438 "b_service_responding = '%s', "
439 "b_service_single_launch = '%s', "
440 "b_service_multi_launch = '%s', "
441 "b_event_handler_click_on_button_1 = '%s', "
442 "b_event_handler_click_on_button_2= '%s', "
443 "b_event_handler_click_on_button_3= '%s', "
444 "b_event_handler_click_on_button_4= '%s', "
445 "b_event_handler_click_on_button_5= '%s', "
446 "b_event_handler_click_on_button_6= '%s', "
447 "b_event_handler_click_on_icon= '%s', "
448 "b_event_handler_click_on_thumbnail= '%s', "
449 "sound_type = %d, sound_path = '%s', "
450 "vibration_type = %d, vibration_path = '%s', "
451 "led_operation = %d, led_argb = %d, "
452 "led_on_ms = %d, led_off_ms = %d, "
453 "flags_for_property = %d, flag_simmode = %d, "
454 "display_applist = %d, "
455 "progress_size = $progress_size, progress_percentage = $progress_percentage, "
456 "ongoing_flag = %d, auto_remove = %d "
457 "where priv_id = %d ",
460 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
461 NOTIFICATION_CHECK_STR(b_image_path),
462 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
463 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
464 NOTIFICATION_CHECK_STR(noti->domain),
465 NOTIFICATION_CHECK_STR(noti->dir),
466 (int)noti->time, (int)noti->insert_time,
467 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
468 NOTIFICATION_CHECK_STR(b_execute_option),
469 NOTIFICATION_CHECK_STR(b_service_responding),
470 NOTIFICATION_CHECK_STR(b_service_single_launch),
471 NOTIFICATION_CHECK_STR(b_service_multi_launch),
472 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1]),
473 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2]),
474 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3]),
475 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_4]),
476 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_5]),
477 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_6]),
478 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_ICON]),
479 NOTIFICATION_CHECK_STR(b_event_handler[NOTIFICATION_EVENT_TYPE_CLICK_ON_THUMBNAIL]),
480 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
481 noti->vibration_type,
482 NOTIFICATION_CHECK_STR(noti->vibration_path),
487 noti->flags_for_property, flag_simmode, noti->display_applist,
488 noti->ongoing_flag, noti->auto_remove,
491 /* Free decoded data */
498 if (b_execute_option)
499 free(b_execute_option);
501 if (b_service_responding)
502 free(b_service_responding);
504 if (b_service_single_launch)
505 free(b_service_single_launch);
507 if (b_service_multi_launch)
508 free(b_service_multi_launch);
523 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
525 return NOTIFICATION_ERROR_NONE;
528 static void _notification_noti_populate_from_stmt(sqlite3_stmt *stmt, notification_h noti)
533 if (stmt == NULL || noti == NULL)
537 noti->type = sqlite3_column_int(stmt, col++);
538 noti->layout = sqlite3_column_int(stmt, col++);
539 __free_and_set((void **)&(noti->caller_pkgname), notification_db_column_text(stmt, col++));
540 __free_and_set((void **)&(noti->launch_pkgname), notification_db_column_text(stmt, col++));
541 noti->b_image_path = notification_db_column_bundle(stmt, col++);
542 noti->group_id = sqlite3_column_int(stmt, col++);
543 noti->internal_group_id = 0;
544 noti->priv_id = sqlite3_column_int(stmt, col++);
545 __free_and_set((void **)&(noti->tag), notification_db_column_text(stmt, col++));
547 noti->b_text = notification_db_column_bundle(stmt, col++);
548 noti->b_key = notification_db_column_bundle(stmt, col++);
549 noti->b_format_args = notification_db_column_bundle(stmt, col++);
550 noti->num_format_args = sqlite3_column_int(stmt, col++);
552 __free_and_set((void **)&(noti->domain), notification_db_column_text(stmt, col++));
553 __free_and_set((void **)&(noti->dir), notification_db_column_text(stmt, col++));
554 noti->time = sqlite3_column_int(stmt, col++);
555 noti->insert_time = sqlite3_column_int(stmt, col++);
556 noti->args = notification_db_column_bundle(stmt, col++);
557 noti->group_args = notification_db_column_bundle(stmt, col++);
559 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
560 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
561 noti->b_service_single_launch =
562 notification_db_column_bundle(stmt, col++);
563 noti->b_service_multi_launch =
564 notification_db_column_bundle(stmt, col++);
566 for (i = 0; i < NOTIFICATION_EVENT_TYPE_MAX; i++)
567 noti->b_event_handler[i] = notification_db_column_bundle(stmt, col++);
570 noti->sound_type = sqlite3_column_int(stmt, col++);
571 __free_and_set((void **)&(noti->sound_path), notification_db_column_text(stmt, col++));
572 noti->vibration_type = sqlite3_column_int(stmt, col++);
573 __free_and_set((void **)&(noti->vibration_path), notification_db_column_text(stmt, col++));
574 noti->led_operation = sqlite3_column_int(stmt, col++);
575 noti->led_argb = sqlite3_column_int(stmt, col++);
576 noti->led_on_ms = sqlite3_column_int(stmt, col++);
577 noti->led_off_ms = sqlite3_column_int(stmt, col++);
579 noti->flags_for_property = sqlite3_column_int(stmt, col++);
580 noti->display_applist = sqlite3_column_int(stmt, col++);
581 noti->progress_size = sqlite3_column_double(stmt, col++);
582 noti->progress_percentage = sqlite3_column_double(stmt, col++);
584 noti->ongoing_flag = sqlite3_column_int(stmt, col++);
585 noti->auto_remove = sqlite3_column_int(stmt, col++);
587 noti->app_icon_path = NULL;
588 noti->app_name = NULL;
589 noti->temp_title = NULL;
590 noti->temp_content = NULL;
593 static notification_h _notification_noti_get_item(sqlite3_stmt *stmt)
595 notification_h noti = NULL;
597 noti = (notification_h) calloc(1, sizeof(struct _notification));
601 _notification_noti_populate_from_stmt(stmt, noti);
606 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
610 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
612 if (buf_len <= len_total)
613 return NOTIFICATION_ERROR_INVALID_PARAMETER;
615 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
617 return NOTIFICATION_ERROR_NONE;
620 char *notification_noti_strip_tag(const char *tagged_str)
622 if (tagged_str == NULL)
625 int len_total = strlen(tagged_str);
630 char *b_f_e = strstr(tagged_str, ">");
631 char *b_e_s = strstr(tagged_str, "</");
633 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
636 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
639 int notification_noti_get_tag_type(const char *tagged_str)
641 if (tagged_str == NULL)
642 return TAG_TYPE_INVALID;
644 if (strlen(tagged_str) == 0)
645 return TAG_TYPE_INVALID;
647 char *b_f_s = strstr(tagged_str, "<");
648 char *b_f_e = strstr(tagged_str, ">");
650 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
651 return TAG_TYPE_INVALID;
653 char *start = b_f_s + 1;
654 int len_tag = b_f_e - b_f_s - 1;
656 if (strncmp(start, TAG_TIME, len_tag) == 0)
657 return TAG_TYPE_TIME;
659 return TAG_TYPE_INVALID;
662 static int _notification_noti_update_priv_id(sqlite3 *db, int rowid)
664 int ret = NOTIFICATION_ERROR_NONE;
668 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
672 query = sqlite3_mprintf("UPDATE noti_list SET "
673 "priv_id = %d, internal_group_id = %d WHERE rowid = %d",
674 rowid, rowid, rowid);
676 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
680 ret = notification_db_exec(db, query, NULL);
690 static int _get_package_id_by_app_id(const char *app_id, char **package_id)
692 int err = NOTIFICATION_ERROR_NONE;
695 char *pkg_id_dup = NULL;
696 pkgmgrinfo_appinfo_h pkgmgrinfo_appinfo = NULL;
698 if (app_id == NULL || package_id == NULL) {
699 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
700 err = NOTIFICATION_ERROR_INVALID_PARAMETER;
704 if ((retval = pkgmgrinfo_appinfo_get_appinfo(app_id, &pkgmgrinfo_appinfo)) != PMINFO_R_OK) {
705 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_appinfo failed [%d]", retval);
706 err = NOTIFICATION_ERROR_INVALID_OPERATION;
710 if ((retval = pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo, &pkg_id)) != PMINFO_R_OK || pkg_id == NULL) {
711 NOTIFICATION_ERR("pkgmgrinfo_appinfo_get_pkgname failed [%d]", retval);
712 err = NOTIFICATION_ERROR_INVALID_OPERATION;
716 pkg_id_dup = strdup(pkg_id);
718 if (pkg_id_dup == NULL) {
719 NOTIFICATION_ERR("strdup failed");
720 err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
724 *package_id = pkg_id_dup;
727 if (pkgmgrinfo_appinfo)
728 pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo);
733 static bool _is_allowed_to_notify(const char *caller_package_name, uid_t uid)
735 notification_setting_h setting = NULL;
737 char *package_id = NULL;
740 err = noti_setting_service_get_setting_by_package_name(caller_package_name, &setting, uid);
741 if (err != NOTIFICATION_ERROR_NONE) {
742 /* Retry with package id */
743 err = _get_package_id_by_app_id(caller_package_name, &package_id);
745 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
746 NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
749 err = noti_setting_service_get_setting_by_package_name(package_id, &setting, uid);
750 if (err != NOTIFICATION_ERROR_NONE) {
751 NOTIFICATION_ERR("noti_setting_service_get_setting_by_package_name failed [%d]", err);
757 err = notification_setting_get_allow_to_notify(setting, &ret);
758 if (err != NOTIFICATION_ERROR_NONE) {
759 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
764 NOTIFICATION_DBG("[%s] is not allowed to notify", caller_package_name);
771 notification_setting_free_notification(setting);
776 static int _handle_do_not_disturb_option(notification_h noti)
778 int err = NOTIFICATION_ERROR_NONE;
779 bool do_not_disturb = false;
780 bool do_not_disturb_exception = false;
781 char *package_id = NULL;
782 notification_setting_h setting = NULL;
783 notification_system_setting_h system_setting = NULL;
787 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
788 return NOTIFICATION_ERROR_INVALID_PARAMETER;
791 /* Get system setting */
792 err = noti_system_setting_load_system_setting(&system_setting, noti->uid);
793 if (err != NOTIFICATION_ERROR_NONE) {
794 NOTIFICATION_ERR("_load_system_setting failed [%d]", err);
798 err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
799 if (err != NOTIFICATION_ERROR_NONE) {
800 NOTIFICATION_ERR("_get_do_not_disturb failed [%d]", err);
804 NOTIFICATION_DBG("do_not_disturb [%d]", do_not_disturb);
806 if (do_not_disturb) {
807 /* Check exception option of the caller package */
808 err = noti_setting_service_get_setting_by_package_name(noti->caller_pkgname, &setting, noti->uid);
809 if (err != NOTIFICATION_ERROR_NONE) {
810 /* Retry with package id */
811 err = _get_package_id_by_app_id(noti->caller_pkgname, &package_id);
812 if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
813 NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
816 err = noti_setting_service_get_setting_by_package_name(package_id, &setting, noti->uid);
817 if (err != NOTIFICATION_ERROR_NONE) {
818 NOTIFICATION_ERR("_get_setting_by_package_name failed [%d]", err);
824 err = notification_setting_get_do_not_disturb_except(setting, &do_not_disturb_exception);
825 if (err != NOTIFICATION_ERROR_NONE) {
826 NOTIFICATION_ERR("notification_setting_get_allow_to_notify failed [%d]", err);
830 if (do_not_disturb_exception == false) {
831 /* do_not_disturb is ON and do_not_disturb_exception is OFF */
832 /* Then add this notification only on quick panel and indicator*/
833 noti->display_applist = noti->display_applist & (NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR);
834 /* and reset all sound and vibration and led options*/
835 noti->sound_type = NOTIFICATION_SOUND_TYPE_NONE;
836 SAFE_FREE(noti->sound_path);
837 noti->vibration_type = NOTIFICATION_VIBRATION_TYPE_NONE;
838 SAFE_FREE(noti->vibration_path);
839 noti->led_operation = NOTIFICATION_LED_OP_OFF;
842 noti->led_off_ms = 0;
847 SAFE_FREE(package_id);
850 notification_system_setting_free_system_setting(system_setting);
853 notification_setting_free_notification(setting);
858 EXPORT_API int notification_noti_insert(notification_h noti)
862 sqlite3_stmt *stmt = NULL;
864 char buf_key[32] = { 0, };
865 char *title_key = NULL;
868 NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
869 return NOTIFICATION_ERROR_INVALID_PARAMETER;
872 if (_is_allowed_to_notify((const char *)noti->caller_pkgname, noti->uid) == false) {
873 NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
874 return NOTIFICATION_ERROR_PERMISSION_DENIED;
877 if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE)
878 NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
882 db = notification_db_open(DBPATH);
884 return get_last_result();
886 /* Initialize private ID */
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 /* LCOV_EXCL_START */
971 EXPORT_API int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id, uid_t uid)
976 sqlite3_stmt *stmt = NULL;
978 if (priv_id < 0 || noti == NULL) {
979 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
984 db = notification_db_open(DBPATH);
986 return get_last_result();
988 char *base_query = "select "
989 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
990 "tag, b_text, b_key, b_format_args, num_format_args, "
991 "text_domain, text_dir, time, insert_time, args, group_args, "
992 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
993 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
994 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
995 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
996 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
997 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1000 if (pkgname != NULL && strlen(pkgname) != 0)
1001 query = sqlite3_mprintf("%s where caller_pkgname = '%s' and priv_id = %d and uid = %d",
1002 base_query, pkgname, priv_id, uid);
1004 query = sqlite3_mprintf("%s where priv_id = %d and uid = %d", base_query, priv_id, uid);
1006 if (query == NULL) {
1007 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1011 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1012 if (ret != SQLITE_OK) {
1013 NOTIFICATION_ERR("select Query : %s", query);
1014 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
1015 sqlite3_errmsg(db));
1016 ret = NOTIFICATION_ERROR_FROM_DB;
1020 ret = sqlite3_step(stmt);
1021 if (ret == SQLITE_ROW) {
1022 _notification_noti_populate_from_stmt(stmt, noti);
1023 ret = NOTIFICATION_ERROR_NONE;
1025 ret = NOTIFICATION_ERROR_FROM_DB;
1030 sqlite3_free(query);
1033 sqlite3_finalize(stmt);
1037 notification_db_close(&db);
1041 /* LCOV_EXCL_STOP */
1043 EXPORT_API int notification_noti_get_by_tag(notification_h noti, char *pkgname, char* tag, uid_t uid)
1047 sqlite3_stmt *stmt = NULL;
1049 if (tag == NULL || noti == NULL) {
1050 ret = NOTIFICATION_ERROR_INVALID_PARAMETER;
1055 db = notification_db_open(DBPATH);
1057 return get_last_result();
1059 if (pkgname != NULL && strlen(pkgname) != 0) {
1060 ret = sqlite3_prepare_v2(db, "select "
1061 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1062 "tag, b_text, b_key, b_format_args, num_format_args, "
1063 "text_domain, text_dir, time, insert_time, args, group_args, "
1064 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1065 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1066 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1067 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1068 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1069 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1070 "from noti_list where caller_pkgname = ? and tag = ? and uid = ?", -1, &stmt, NULL);
1071 if (ret != SQLITE_OK) {
1072 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1073 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1076 ret = sqlite3_bind_text(stmt, 1, pkgname, -1, SQLITE_TRANSIENT);
1077 if (ret != SQLITE_OK) {
1078 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1082 ret = sqlite3_bind_text(stmt, 2, tag, -1, SQLITE_TRANSIENT);
1083 if (ret != SQLITE_OK) {
1084 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1088 ret = sqlite3_bind_int(stmt, 3, uid);
1089 if (ret != SQLITE_OK) {
1090 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1095 ret = sqlite3_prepare_v2(db, "select "
1096 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1097 "tag, b_text, b_key, b_format_args, num_format_args, "
1098 "text_domain, text_dir, time, insert_time, args, group_args, "
1099 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1100 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1101 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1102 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1103 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1104 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1105 "from noti_list where tag = ? and uid = ?", -1, &stmt, NULL);
1106 if (ret != SQLITE_OK) {
1107 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1108 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1111 ret = sqlite3_bind_text(stmt, 1, tag, -1, SQLITE_TRANSIENT);
1112 if (ret != SQLITE_OK) {
1113 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1117 ret = sqlite3_bind_int(stmt, 2, uid);
1118 if (ret != SQLITE_OK) {
1119 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1124 ret = sqlite3_step(stmt);
1125 if (ret == SQLITE_ROW) {
1126 _notification_noti_populate_from_stmt(stmt, noti);
1127 ret = NOTIFICATION_ERROR_NONE;
1129 ret = NOTIFICATION_ERROR_FROM_DB;
1135 sqlite3_finalize(stmt);
1139 notification_db_close(&db);
1144 EXPORT_API int notification_noti_update(notification_h noti)
1148 sqlite3_stmt *stmt = NULL;
1152 db = notification_db_open(DBPATH);
1154 return get_last_result();
1156 if (_is_allowed_to_notify((const char *)noti->caller_pkgname, noti->uid) == false) {
1157 NOTIFICATION_DBG("[%s] is not allowed to notify", noti->caller_pkgname);
1158 return NOTIFICATION_ERROR_PERMISSION_DENIED;
1161 if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE)
1162 NOTIFICATION_WARN("_handle_do_not_disturb_option failed");
1164 /* Check private ID is exist */
1165 ret = _notification_noti_check_priv_id(noti, db);
1166 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
1167 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1171 /* make update query */
1172 ret = _update_query_create(noti, &query);
1173 if (ret != NOTIFICATION_ERROR_NONE)
1176 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
1177 if (ret != SQLITE_OK) {
1178 NOTIFICATION_ERR("Insert Query : %s", query);
1179 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
1180 sqlite3_errmsg(db));
1181 ret = NOTIFICATION_ERROR_FROM_DB;
1185 ret = _notification_noti_bind_query_text(stmt, "$tag", noti->tag);
1186 if (ret != NOTIFICATION_ERROR_NONE) {
1187 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1191 ret = _notification_noti_bind_query_double(stmt, "$progress_size", noti->progress_size);
1192 if (ret != NOTIFICATION_ERROR_NONE) {
1193 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1197 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage", noti->progress_percentage);
1198 if (ret != NOTIFICATION_ERROR_NONE) {
1199 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
1203 ret = sqlite3_step(stmt);
1204 if (ret == SQLITE_OK || ret == SQLITE_DONE)
1205 ret = NOTIFICATION_ERROR_NONE;
1207 ret = NOTIFICATION_ERROR_FROM_DB;
1211 sqlite3_finalize(stmt);
1215 notification_db_close(&db);
1218 sqlite3_free(query);
1223 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid, uid_t uid)
1225 int ret = NOTIFICATION_ERROR_NONE;
1226 int ret_tmp = NOTIFICATION_ERROR_NONE;
1227 int i = 0, data_cnt = 0;
1229 sqlite3_stmt *stmt = NULL;
1230 char buf[128] = { 0, };
1231 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1232 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1233 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1234 char err_buf[ERR_BUFFER_SIZE];
1237 db = notification_db_open(DBPATH);
1239 return get_last_result();
1241 if (pkgname == NULL || strlen(pkgname) == 0) {
1242 if (type != NOTIFICATION_TYPE_NONE)
1243 snprintf(query_where, sizeof(query_where),
1244 "where type = %d and uid = %d", type, uid);
1247 if (type == NOTIFICATION_TYPE_NONE)
1248 snprintf(query_where, sizeof(query_where),
1249 "where caller_pkgname = '%s' and uid = %d", pkgname, uid);
1251 snprintf(query_where, sizeof(query_where),
1252 "where caller_pkgname = '%s' and type = %d and uid = %d",
1253 pkgname, type, uid);
1257 if (num_deleted != NULL)
1260 if (list_deleted_rowid != NULL) {
1261 *list_deleted_rowid = NULL;
1262 snprintf(query, sizeof(query),
1263 "select priv_id from noti_list %s ", query_where);
1265 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1266 if (ret != SQLITE_OK) {
1267 NOTIFICATION_ERR("Select Query : %s", query);
1268 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1269 sqlite3_errmsg(db));
1271 ret = NOTIFICATION_ERROR_FROM_DB;
1275 while (sqlite3_step(stmt) == SQLITE_ROW) {
1276 if (data_cnt % 8 == 0) {
1279 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1281 *list_deleted_rowid = tmp;
1283 NOTIFICATION_ERR("Heap: %s\n", strerror_r(errno, err_buf, sizeof(err_buf)));
1286 * How can I handle this?
1288 free(*list_deleted_rowid);
1289 *list_deleted_rowid = NULL;
1290 ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
1294 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1299 sqlite3_finalize(stmt);
1304 query_where[0] = '\0';
1305 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1306 for (i = 0; i < data_cnt ; i++) {
1307 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1308 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1309 ret_tmp = notification_db_exec(db, query, NULL);
1310 query_where[0] = '\0';
1311 if (ret == NOTIFICATION_ERROR_NONE)
1315 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1316 strncat(query_where, buf, sizeof(query_where) - strlen(query_where) - 1);
1318 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0)) {
1319 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1320 ret_tmp = notification_db_exec(db, query, NULL);
1321 if (ret == NOTIFICATION_ERROR_NONE)
1325 free(*list_deleted_rowid);
1326 *list_deleted_rowid = NULL;
1329 if (num_deleted != NULL)
1330 *num_deleted = data_cnt;
1333 /* Make main query */
1334 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1335 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1337 ret = notification_db_exec(db, query, NULL);
1339 if (num_deleted != NULL)
1340 *num_deleted = sqlite3_changes(db);
1346 sqlite3_finalize(stmt);
1350 notification_db_close(&db);
1355 /* LCOV_EXCL_START */
1356 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1359 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1362 /* Check pkgname is valid */
1363 if (pkgname == NULL)
1364 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1367 db = notification_db_open(DBPATH);
1369 return get_last_result();
1372 snprintf(query, sizeof(query), "delete from noti_list "
1373 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1377 ret = notification_db_exec(db, query, NULL);
1381 notification_db_close(&db);
1385 /* LCOV_EXCL_STOP */
1387 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes, uid_t uid)
1390 char query[NOTIFICATION_QUERY_MAX] = {0, };
1393 /* Check pkgname is valid */
1394 if (pkgname == NULL || strlen(pkgname) == 0)
1395 return NOTIFICATION_ERROR_INVALID_PARAMETER;
1398 db = notification_db_open(DBPATH);
1400 return get_last_result();
1403 snprintf(query, sizeof(query), "delete from noti_list "
1404 "where caller_pkgname = '%s' and priv_id = %d and uid = %d", pkgname,
1406 NOTIFICATION_DBG("%s", query);
1409 ret = notification_db_exec(db, query, num_changes);
1411 if (num_changes != NULL)
1412 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1416 notification_db_close(&db);
1421 /* todo refactoring */
1422 /* LCOV_EXCL_START */
1423 EXPORT_API int notification_noti_get_count(notification_type_e type,
1424 const char *pkgname,
1425 int group_id, int priv_id,
1426 int *count, uid_t uid)
1429 sqlite3_stmt *stmt = NULL;
1430 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1431 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1432 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1433 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1435 int ret = 0, get_count = 0, internal_group_id = 0;
1436 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1437 int flag_where_more = 0;
1441 db = notification_db_open(DBPATH);
1443 return get_last_result();
1445 /* Check current sim status */
1446 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1449 snprintf(query_base, sizeof(query_base),
1450 "select count(*) from noti_list ");
1452 if (pkgname != NULL && strlen(pkgname) != 0) {
1453 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1454 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1455 snprintf(query_where, sizeof(query_where),
1456 "where caller_pkgname = '%s' and uid = %d ",
1460 _notification_noti_get_internal_group_id_by_priv_id
1461 (pkgname, priv_id, db);
1462 snprintf(query_where, sizeof(query_where),
1463 "where caller_pkgname = '%s' and internal_group_id = %d and uid = %d ",
1464 pkgname, internal_group_id, uid);
1467 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1468 snprintf(query_where, sizeof(query_where),
1469 "where caller_pkgname = '%s' and group_id = %d and uid = %d ",
1470 pkgname, group_id, uid);
1473 _notification_noti_get_internal_group_id_by_priv_id
1474 (pkgname, priv_id, db);
1475 snprintf(query_where, sizeof(query_where),
1476 "where caller_pkgname = '%s' and internal_group_id = %d and uid = %d ",
1477 pkgname, internal_group_id, uid);
1481 snprintf(query_where, sizeof(query_where), "where uid = %d", uid);
1484 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1485 if (type != NOTIFICATION_TYPE_NONE) {
1486 snprintf(query_where_more, sizeof(query_where_more),
1487 "type = %d ", type);
1488 flag_where_more = 1;
1491 if (type != NOTIFICATION_TYPE_NONE) {
1492 snprintf(query_where_more, sizeof(query_where_more),
1493 "type = %d and flag_simmode = 0 ", type);
1494 flag_where_more = 1;
1496 snprintf(query_where_more, sizeof(query_where_more),
1497 "flag_simmode = 0 ");
1498 flag_where_more = 1;
1502 if (flag_where_more == 1) {
1503 snprintf(query, sizeof(query), "%s %s and %s",
1504 query_base, query_where, query_where_more);
1506 snprintf(query, sizeof(query), "%s %s", query_base,
1510 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1511 if (ret != SQLITE_OK) {
1512 NOTIFICATION_ERR("Select Query : %s", query);
1513 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1514 sqlite3_errmsg(db));
1516 ret = NOTIFICATION_ERROR_FROM_DB;
1520 ret = sqlite3_step(stmt);
1521 if (ret == SQLITE_ROW)
1522 get_count = sqlite3_column_int(stmt, 0);
1524 ret = NOTIFICATION_ERROR_NONE;
1528 sqlite3_finalize(stmt);
1533 notification_db_close(&db);
1539 /* LCOV_EXCL_STOP */
1541 EXPORT_API int notification_noti_get_grouping_list(notification_type_e type,
1543 notification_list_h *list,
1547 sqlite3_stmt *stmt = NULL;
1548 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1549 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1550 char query_uid[NOTIFICATION_QUERY_MAX] = { 0, };
1551 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1554 notification_list_h get_list = NULL;
1555 notification_h noti = NULL;
1556 int internal_count = 0;
1560 db = notification_db_open(DBPATH);
1562 return get_last_result();
1564 /* Check current sim status */
1565 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1568 snprintf(query_base, sizeof(query_base), "select "
1569 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1570 "tag, b_text, b_key, b_format_args, num_format_args, "
1571 "text_domain, text_dir, time, insert_time, args, group_args, "
1572 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1573 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1574 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1575 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1576 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1577 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1578 "from noti_list where 1 > 0 ");
1580 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1581 if (type != NOTIFICATION_TYPE_NONE)
1582 snprintf(query_where, sizeof(query_where),
1583 " and type = %d ", type);
1585 if (type != NOTIFICATION_TYPE_NONE)
1586 snprintf(query_where, sizeof(query_where),
1587 " and type = %d and flag_simmode = 0 ", type);
1589 snprintf(query_where, sizeof(query_where),
1590 " and flag_simmode = 0 ");
1593 if (uid != NOTIFICATION_GLOBAL_UID)
1594 snprintf(query_uid, sizeof(query_uid), " and uid = %d ", uid);
1596 snprintf(query, sizeof(query),
1598 "group by internal_group_id "
1599 "order by rowid desc, time desc", query_base, query_where, query_uid);
1601 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1602 if (ret != SQLITE_OK) {
1603 NOTIFICATION_ERR("Select Query : %s", query);
1604 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1605 sqlite3_errmsg(db));
1607 ret = NOTIFICATION_ERROR_FROM_DB;
1611 while (sqlite3_step(stmt) == SQLITE_ROW) {
1612 /* Make notification list */
1613 noti = _notification_noti_get_item(stmt);
1617 get_list = notification_list_append(get_list, noti);
1619 if (count != -1 && internal_count >= count) {
1621 ("internal count %d >= count %d",
1622 internal_count, count);
1628 ret = NOTIFICATION_ERROR_NONE;
1632 sqlite3_finalize(stmt);
1636 notification_db_close(&db);
1638 if (get_list != NULL)
1639 *list = notification_list_get_head(get_list);
1643 EXPORT_API int notification_noti_get_detail_list(const char *pkgname,
1645 int priv_id, int count,
1646 notification_list_h *list,
1650 sqlite3_stmt *stmt = NULL;
1651 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1652 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1654 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1656 notification_list_h get_list = NULL;
1657 notification_h noti = NULL;
1658 int internal_count = 0;
1659 int internal_group_id = 0;
1660 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1663 db = notification_db_open(DBPATH);
1665 return get_last_result();
1667 /* Check current sim status */
1668 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1671 snprintf(query_base, sizeof(query_base), "select "
1672 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1673 "tag, b_text, b_key, b_format_args, num_format_args, "
1674 "text_domain, text_dir, time, insert_time, args, group_args, "
1675 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1676 "b_event_handler_click_on_button_1, b_event_handler_click_on_button_2, b_event_handler_click_on_button_3, "
1677 "b_event_handler_click_on_button_4, b_event_handler_click_on_button_5, b_event_handler_click_on_button_6, "
1678 "b_event_handler_click_on_icon, b_event_handler_click_on_thumbnail, "
1679 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1680 "flags_for_property, display_applist, progress_size, progress_percentage, ongoing_flag, auto_remove "
1683 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1684 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
1685 snprintf(query_where, sizeof(query_where),
1686 "where caller_pkgname = '%s' and uid = %d ", pkgname, uid);
1688 snprintf(query_where, sizeof(query_where),
1689 "where caller_pkgname = '%s' and flag_simmode = 0 and uid = %d ", pkgname, uid);
1693 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1696 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED)
1697 snprintf(query_where, sizeof(query_where),
1698 "where caller_pkgname = '%s' and internal_group_id = %d and uid = %d ",
1699 pkgname, internal_group_id, uid);
1701 snprintf(query_where, sizeof(query_where),
1702 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 and uid = %d ",
1703 pkgname, internal_group_id, uid);
1706 snprintf(query, sizeof(query),
1708 "order by rowid desc, time desc", query_base, query_where);
1710 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1711 if (ret != SQLITE_OK) {
1712 NOTIFICATION_ERR("Select Query : %s", query);
1713 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1714 sqlite3_errmsg(db));
1716 ret = NOTIFICATION_ERROR_FROM_DB;
1720 while (sqlite3_step(stmt) == SQLITE_ROW) {
1721 /* Make notification list */
1722 noti = _notification_noti_get_item(stmt);
1726 get_list = notification_list_append(get_list, noti);
1728 if (count != -1 && internal_count >= count) {
1730 ("internal count %d >= count %d",
1731 internal_count, count);
1737 ret = NOTIFICATION_ERROR_NONE;
1741 sqlite3_finalize(stmt);
1745 notification_db_close(&db);
1747 if (get_list != NULL)
1748 *list = notification_list_get_head(get_list);
1753 EXPORT_API int notification_noti_check_tag(notification_h noti)
1756 int ret = NOTIFICATION_ERROR_NONE;
1758 sqlite3_stmt *stmt = NULL;
1760 if (noti->tag == NULL)
1761 return NOTIFICATION_ERROR_NOT_EXIST_ID;
1764 db = notification_db_open(DBPATH);
1766 return get_last_result();
1768 ret = sqlite3_prepare_v2(db, "SELECT priv_id FROM noti_list WHERE caller_pkgname = ? and tag = ?", -1, &stmt, NULL);
1769 if (ret != SQLITE_OK) {
1770 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1772 notification_db_close(&db);
1773 return NOTIFICATION_ERROR_OUT_OF_MEMORY;
1776 ret = sqlite3_bind_text(stmt, 1, noti->caller_pkgname, -1, SQLITE_TRANSIENT);
1777 if (ret != SQLITE_OK) {
1778 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1782 ret = sqlite3_bind_text(stmt, 2, noti->tag, -1, SQLITE_TRANSIENT);
1783 if (ret != SQLITE_OK) {
1784 NOTIFICATION_ERR("Error: %s\n", sqlite3_errmsg(db));
1788 ret = sqlite3_step(stmt);
1789 if (ret == SQLITE_ROW)
1790 result = sqlite3_column_int(stmt, 0);
1794 sqlite3_finalize(stmt);
1796 /* If result > 0, there is priv_id in DB */
1798 noti->priv_id = result;
1799 ret = NOTIFICATION_ERROR_ALREADY_EXIST_ID;
1801 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
1806 notification_db_close(&db);