summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xinclude/notification.h38
-rwxr-xr-xinclude/notification_ipc.h4
-rw-r--r--include/notification_setting_service.h1
-rw-r--r--include/notification_type.h10
-rwxr-xr-xsrc/notification.c39
-rwxr-xr-xsrc/notification_ipc.c44
-rw-r--r--src/notification_setting_service.c78
7 files changed, 208 insertions, 6 deletions
diff --git a/include/notification.h b/include/notification.h
index 52593eb..2a48877 100755
--- a/include/notification.h
+++ b/include/notification.h
@@ -1519,6 +1519,44 @@ int notification_save_as_template(notification_h noti, const char *template_name
notification_h notification_create_from_template(const char *template_name);
/**
+ * @brief Gets notification block state.
+ * @details The user can set the notification block state in settings.
+ * The block state indicates whether or not notifications can be posted.
+ * Additionally only notifications to the notification panel are
+ * allowed in "Do not disturb mode". Sound, Vibrate and
+ * Active/Instant notifications are blocked.
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/notification
+ * @param[out] state Notification block state
+ * @return #NOTIFICATION_ERROR_NONE On success, other value on failure
+ * @retval #NOTIFICATION_ERROR_NONE Success
+ * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #NOTIFICATION_ERROR_OUT_OF_MEMORY out of memory
+ * @retval #NOTIFICATION_ERROR_IO_ERROR I/O Error
+ * @retval #NOTIFICATION_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #NOTIFICATION_ERROR_SERVICE_NOT_READY No response from notification service
+ * @see #notification_block_state_e
+ * @par Sample code:
+ * @code
+#include <notification.h>
+...
+{
+ int noti_err = NOTIFICATION_ERROR_NONE;
+ notification_block_state_e state;
+
+ ...
+
+ noti_err = notification_get_noti_block_state(&state);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ return;
+ }
+}
+ * @endcode
+ */
+int notification_get_noti_block_state(notification_block_state_e *state);
+
+/**
* @}
*/
diff --git a/include/notification_ipc.h b/include/notification_ipc.h
index fda5f95..db14a28 100755
--- a/include/notification_ipc.h
+++ b/include/notification_ipc.h
@@ -87,8 +87,8 @@ int notification_ipc_request_save_as_template(notification_h noti, const char *t
int notification_ipc_request_create_from_template(notification_h noti, const char *template_name);
int notification_ipc_request_create_from_package_template(notification_h noti,
const char *pkgname, const char *template_name);
-
-
+int notification_ipc_get_noti_block_state(const char *pkgname, int *do_not_disturb, int *do_not_disturb_except,
+ int *allow_to_notify, uid_t uid);
#ifdef __cplusplus
}
diff --git a/include/notification_setting_service.h b/include/notification_setting_service.h
index 6de7bab..1d810b2 100644
--- a/include/notification_setting_service.h
+++ b/include/notification_setting_service.h
@@ -39,6 +39,7 @@ int noti_setting_service_get_setting_by_package_name(const char *package_name, n
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 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);
#ifdef __cplusplus
}
#endif
diff --git a/include/notification_type.h b/include/notification_type.h
index 67db1f2..43e0252 100644
--- a/include/notification_type.h
+++ b/include/notification_type.h
@@ -423,6 +423,16 @@ typedef enum notification_permission_type {
} notification_permission_type_e;
/**
+ * @brief Enumeration for notification block state.
+ * @since_tizen 3.0
+ */
+typedef enum notification_block_state {
+ NOTIFICATION_BLOCK_STATE_ALLOWED = 0, /**< The app is allowed to post notifications */
+ NOTIFICATION_BLOCK_STATE_BLOCKED, /**< The app is not allowed to post any notifications */
+ NOTIFICATION_BLOCK_STATE_DO_NOT_DISTURB /**< User set do not disturb mode */
+} notification_block_state_e;
+
+/**
* @}
*/
diff --git a/src/notification.c b/src/notification.c
index 1cc9f04..480fc19 100755
--- a/src/notification.c
+++ b/src/notification.c
@@ -1231,10 +1231,6 @@ out:
return err;
}
-
-
-
-
EXPORT_API int notification_set_property(notification_h noti,
int flags)
{
@@ -1867,3 +1863,38 @@ EXPORT_API notification_h notification_create_from_template(const char *template
return noti;
}
+
+EXPORT_API int notification_get_noti_block_state(notification_block_state_e *state)
+{
+ int ret;
+ char *pkgname;
+ int do_not_disturb;
+ int do_not_disturb_except;
+ int allow_to_notify;
+
+ if (state == NULL)
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+ pkgname = notification_get_pkgname_by_pid();
+
+ ret = notification_ipc_get_noti_block_state(pkgname, &do_not_disturb, &do_not_disturb_except, &allow_to_notify, getuid());
+
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ if (pkgname)
+ free(pkgname);
+ return ret;
+ }
+
+ if (allow_to_notify) {
+ *state = NOTIFICATION_BLOCK_STATE_ALLOWED;
+ if (do_not_disturb && !do_not_disturb_except)
+ *state = NOTIFICATION_BLOCK_STATE_DO_NOT_DISTURB;
+ } else {
+ *state = NOTIFICATION_BLOCK_STATE_BLOCKED;
+ }
+
+ if (pkgname)
+ free(pkgname);
+
+ return ret;
+}
diff --git a/src/notification_ipc.c b/src/notification_ipc.c
index 1dddb16..3fbb1d3 100755
--- a/src/notification_ipc.c
+++ b/src/notification_ipc.c
@@ -1423,6 +1423,50 @@ int notification_ipc_request_create_from_package_template(notification_h noti, c
return result;
}
+int notification_ipc_get_noti_block_state(const char *pkgname, int *do_not_disturb,
+ int *do_not_disturb_except, int *allow_to_notify,
+ uid_t uid)
+{
+ int ret;
+ int dnd;
+ int dnd_except;
+ int allow;
+ GDBusMessage *reply = NULL;
+ GVariant *body;
+ GVariant *reply_body;
+ GVariant *result_body;
+
+ if (pkgname == NULL)
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+ ret = _dbus_init();
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ NOTIFICATION_ERR("Can't init dbus %d", ret);
+ return ret;
+ }
+
+ body = g_variant_new("(si)", pkgname, uid);
+
+ ret = _send_sync_noti(body, &reply, "get_noti_block_state");
+
+ if (ret == NOTIFICATION_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(v)", &result_body);
+ g_variant_get(result_body, "(iii)", &dnd, &dnd_except, &allow);
+ *do_not_disturb = dnd;
+ *do_not_disturb_except = dnd_except;
+ *allow_to_notify = allow;
+ g_variant_unref(result_body);
+ }
+
+ if (reply)
+ g_object_unref(reply);
+
+ NOTIFICATION_DBG("notification_ipc_get_noti_block_state done");
+
+ return ret;
+}
+
EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti, bool translate)
{
NOTIFICATION_DBG("make gvariant from noti");
diff --git a/src/notification_setting_service.c b/src/notification_setting_service.c
index 61c3a0a..9202ce5 100644
--- a/src/notification_setting_service.c
+++ b/src/notification_setting_service.c
@@ -568,3 +568,81 @@ err:
return ret;
}
+
+EXPORT_API 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 ret = NOTIFICATION_ERROR_NONE;
+ int sql_ret;
+ int row_count;
+ int col_count;
+ int col_index;
+ sqlite3 *db;
+ char *query_setting = NULL;
+ char **query_setting_result = NULL;
+ char *query_system_setting = NULL;
+ char **query_system_setting_result = NULL;
+
+ if (pkgname == NULL)
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+ db = notification_db_open(DBPATH);
+ if (db == NULL)
+ return get_last_result();
+
+ query_setting = sqlite3_mprintf("SELECT allow_to_notify, do_not_disturb_except "
+ "FROM %s WHERE package_name = %Q AND uid = %d",
+ NOTIFICATION_SETTING_DB_TABLE, pkgname, uid);
+ if (query_setting == NULL) {
+ NOTIFICATION_ERR("fail to alloc query");
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ query_system_setting = sqlite3_mprintf("SELECT do_not_disturb FROM %s WHERE uid = %d",
+ NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
+
+ if (query_system_setting == NULL) {
+ NOTIFICATION_ERR("fail to alloc query");
+ ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ sql_ret = sqlite3_get_table(db, query_setting, &query_setting_result, &row_count, &col_count, NULL);
+ if (sql_ret != SQLITE_OK && sql_ret != -1) {
+ NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_ret, query_setting);
+ ret = NOTIFICATION_ERROR_FROM_DB;
+ goto out;
+ }
+
+ col_index = col_count;
+ _get_table_field_data_int(query_setting_result, (int *)allow_to_notify, col_index++);
+ _get_table_field_data_int(query_setting_result, (int *)do_not_disturb_except, col_index++);
+
+ sql_ret = sqlite3_get_table(db, query_system_setting, &query_system_setting_result, &row_count, &col_count, NULL);
+ if (sql_ret != SQLITE_OK && sql_ret != -1) {
+ NOTIFICATION_ERR("NOTIFICATION_ERROR_FROM_DB failed [%d][%s]", sql_ret, query_setting);
+ ret = NOTIFICATION_ERROR_FROM_DB;
+ goto out;
+ }
+
+ col_index = col_count;
+ _get_table_field_data_int(query_system_setting_result, (int *)do_not_disturb, col_index++);
+
+out:
+ if (query_setting_result)
+ sqlite3_free_table(query_setting_result);
+ if (query_system_setting_result)
+ sqlite3_free_table(query_system_setting_result);
+ if (query_setting)
+ sqlite3_free(query_setting);
+ if (query_system_setting)
+ sqlite3_free(query_system_setting);
+ if (db)
+ notification_db_close(&db);
+
+ return ret;
+}