Add new api to get notification block state 06/84006/22
authorseungha.son <seungha.son@samsung.com>
Tue, 16 Aug 2016 08:11:25 +0000 (17:11 +0900)
committerseungha.son <seungha.son@samsung.com>
Fri, 26 Aug 2016 02:27:52 +0000 (11:27 +0900)
 - 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

include/notification.h
include/notification_ipc.h
include/notification_setting_service.h
include/notification_type.h
src/notification.c
src/notification_ipc.c
src/notification_setting_service.c

index 52593eb7308dcedf9c5ea70459d5b3f88ac5fc6e..2a488779e009c6f64372fb360bca207294c60b7f 100755 (executable)
@@ -1518,6 +1518,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);
+
 /**
  * @}
  */
index fda5f9586d4a31c9461a52fd47670e88783dcaa8..db14a28b9f67fff736081857a5220fa8f9c57b1d 100755 (executable)
@@ -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
 }
index 6de7bab39d82bcb2422447eda6783d364ef57b83..1d810b24a0b8ee93574c93e7f502d55575712107 100644 (file)
@@ -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
index 67db1f2965aa392404c2fa91bad2450f9d3c49a6..43e0252932224bc1e2515ca282df3fec35f707fb 100644 (file)
@@ -422,6 +422,16 @@ typedef enum notification_permission_type {
        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;
+
 /**
  * @}
  */
index 1cc9f0426c66cd726d450cf1011d58fe11b85dbb..480fc1926ca5c7c94924870d7d7abfc676d13d4e 100755 (executable)
@@ -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;
+}
index 1dddb1636deadccb413103f89dccf66c73002459..3fbb1d35655d925458b14059cec2f3a235bf1e0a 100755 (executable)
@@ -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");
index 61c3a0af192c86c9fa35bd3f61ea7bca75005787..9202ce5860b74c040215d4c92978f8d660d5cefa 100644 (file)
@@ -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;
+}