From 246568dcb7f4a1a06241918eacc70b39e7e16e72 Mon Sep 17 00:00:00 2001 From: "seungha.son" Date: Tue, 4 Oct 2016 16:20:31 +0900 Subject: [PATCH] Implement function to support notification dnd changed callback Signed-off-by: seungha.son Change-Id: Ibdc5dc51f4418f16b58451af11e26e2804431fa9 --- include/notification_setting_internal.h | 6 ++- include/notification_setting_service.h | 1 + src/notification_setting_service.c | 51 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/include/notification_setting_internal.h b/include/notification_setting_internal.h index f289ba36..9320bb7e 100644 --- a/include/notification_setting_internal.h +++ b/include/notification_setting_internal.h @@ -1268,7 +1268,8 @@ int notification_system_setting_set_dnd_allow_exceptions(notification_system_set /* * @internal - * @brief Registers a callback for 'Do not disturb' mode setting schedule is start or end. + * @brief Registers a callback for turn on/off 'Do not disturb' mode by user_data + * or 'Do not disturb' mode setting schedule is start or end. * @since_tizen 3.0 * @privlevel public * @privilege %http://tizen.org/privilege/notification @@ -1311,7 +1312,8 @@ int notification_register_system_setting_dnd_changed_cb_for_uid(dnd_changed_cb c /* * @internal - * @brief Unregisters a callback for 'Do not disturb' mode setting schedule is start or end. + * @brief Unregisters a callback for turn on/off 'Do not disturb' mode by user_data + * or 'Do not disturb' mode setting schedule is start or end. * @since_tizen 3.0 * @privlevel public * @privilege %http://tizen.org/privilege/notification diff --git a/include/notification_setting_service.h b/include/notification_setting_service.h index 592cff00..84a44f10 100644 --- a/include/notification_setting_service.h +++ b/include/notification_setting_service.h @@ -39,6 +39,7 @@ int notification_setting_db_update_do_not_disturb(int do_not_disturb, uid_t uid) int noti_setting_service_get_setting_by_package_name(const char *package_name, notification_setting_h *setting, uid_t uid); int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count, uid_t uid); int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting, uid_t uid); +int noti_system_setting_get_do_not_disturb(int *do_not_disturb, uid_t uid); int notification_system_setting_get_dnd_schedule_enabled_uid(uid_t **uids, int *count); int notification_get_dnd_and_allow_to_notify(const char *pkgname, int *do_not_disturb, int *do_not_disturb_except, int *allow_to_notify, uid_t uid); int notification_system_setting_load_dnd_allow_exception(dnd_allow_exception_h *dnd_allow_exception, int *count, uid_t uid); diff --git a/src/notification_setting_service.c b/src/notification_setting_service.c index cdd5415e..a4a3b508 100644 --- a/src/notification_setting_service.c +++ b/src/notification_setting_service.c @@ -788,3 +788,54 @@ out: return ret; } + +EXPORT_API int noti_system_setting_get_do_not_disturb(int *do_not_disturb, uid_t uid) +{ + int ret = NOTIFICATION_ERROR_NONE; + int row_count = 0; + int col_count = 0; + int col_index = 0; + char *query = NULL; + char **query_result = NULL; + sqlite3 *db = NULL; + + db = notification_db_open(DBPATH); + if (db == NULL) + return get_last_result(); + + query = sqlite3_mprintf("SELECT do_not_disturb FROM %s WHERE uid = %d", + NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid); + + if (query == NULL) { + NOTIFICATION_ERR("fail to alloc query"); + ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; + goto out; + } + + ret = sqlite3_get_table(db, query, &query_result, &row_count, &col_count, NULL); + if (ret != SQLITE_OK && ret != -1) { + NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", ret, query); + ret = NOTIFICATION_ERROR_FROM_DB; + goto out; + } + + col_index = col_count; + if (row_count == 0) { + NOTIFICATION_ERR("No system setting found"); + ret = NOTIFICATION_ERROR_INVALID_PARAMETER; + } else { + if (_get_table_field_data_int(query_result, (int *)do_not_disturb, col_index++) == false) + ret = NOTIFICATION_ERROR_FROM_DB; + } + +out: + if (query_result) + sqlite3_free_table(query_result); + if (query) + sqlite3_free(query); + if (db) + notification_db_close(&db); + + return ret; +} + -- 2.34.1