- The user can set notification block state in Setting application.
The user can get notification block state that allow or block
notifications by using this function.
The "Block" means wether or not the ability to post notifications is
blocked. But 'Do not disturb mode' means that Only notification on
notification panel is allowed.
Signed-off-by: seungha.son <seungha.son@samsung.com>
Change-Id: Id19d9b9d4a89d4693b2ae37a74c15b2543b0758a
*/
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);
+
/**
* @}
*/
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
}
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
NOTIFICATION_PERMISSION_TYPE_UPDATE = 2,
} 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;
+
/**
* @}
*/
return err;
}
-
-
-
-
EXPORT_API int notification_set_property(notification_h noti,
int flags)
{
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;
+}
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");
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;
+}