From: seungha.son Date: Mon, 29 Aug 2016 06:35:14 +0000 (+0900) Subject: Add API for gets/sets notification setting details from individual application X-Git-Tag: accepted/tizen/common/20160905.171403^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae69c98b06bb37d125e5f66801f0478a5f8f4683;p=platform%2Fcore%2Fapi%2Fnotification.git Add API for gets/sets notification setting details from individual application - Pop-up notification : Active notification from the app is not allowed when 'Pop-up notification' is off. - Notification on lock screen : Notifications from the app show/hide contests or hide the notification on the lock screen. Signed-off-by: seungha.son Change-Id: I00b72be2e993d33d4d18455d5df743a956ba8ceb --- diff --git a/include/notification_setting_internal.h b/include/notification_setting_internal.h index 6cca9c5..9294887 100644 --- a/include/notification_setting_internal.h +++ b/include/notification_setting_internal.h @@ -62,7 +62,9 @@ struct notification_setting { char *package_name; bool allow_to_notify; bool do_not_disturb_except; + bool pop_up_notification; int visibility_class; + lock_screen_content_level_e lock_screen_content_level; }; /* System setting */ @@ -266,7 +268,7 @@ int notification_setting_get_allow_to_notify(notification_setting_h setting, boo /* * @internal * @brief Sets value which whether allow notification from individual applications. - * @details After notification_setting_update_setting() call, the allow_to_notify is not updated. + * @details After notification_setting_update_setting() call, the allow_to_notify is updated. * @since_tizen @if wearable 2.3.1 @elseif mobile 2.3 @endif * @param[in] setting The notification setting handle * @param[in] value The value whether allow to notification @@ -340,11 +342,10 @@ int notification_setting_get_do_not_disturb_except(notification_setting_h settin /* * @internal * @brief Sets value which whether do not disturb notification or not. - * @details After notification_setting_update_setting() call, the do_not_disturb value is not updated. + * @details After notification_setting_update_setting() call, the do_not_disturb value is updated. * @since_tizen @if wearable 2.3.1 @elseif mobile 2.3 @endif * @param[in] setting The notification setting handle * @param[in] value The value which do not disturb notification or not - * * @return #NOTIFICATION_ERROR_NONE on success, * otherwise any other value on failure * @retval #NOTIFICATION_ERROR_NONE Success @@ -378,6 +379,156 @@ int notification_setting_set_do_not_disturb_except(notification_setting_h settin /* * @internal + * @brief Gets value whether Pop up notification is allowed or not. + * @since_tizen 3.0 + * @param[in] setting The notification setting handle + * @param[in] value The value + * @return #NOTIFICATION_ERROR_NONE on success, + * otherwise any other value on failure + * @retval #NOTIFICATION_ERROR_NONE Success + * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @par sample code: + * @code +#include +... +{ + int noti_err = 0; + bool value; + notification_setting_h setting = NULL; + + ... + + value = true; // or false + + noti_err = notifiacation_setting_get_pop_up_notification(setting, value); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + notification_setting_free_notification(setting); + + return 0; + +} + * @endcode + */ +int notification_setting_get_pop_up_notification(notification_setting_h setting, bool *value); + +/* + * @internal + * @brief Sets value which Pop up notification allow or block. + * @details After notification_setting_update_setting() call, the pop_up_notification value is updated. + * @since_tizen 3.0 + * @param[in] setting The notification setting handle + * @param[in] value The value + * @return #NOTIFICATION_ERROR_NONE on success, + * otherwise any other value on failure + * @retval #NOTIFICATION_ERROR_NONE Success + * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @par sample code: + * @code +#include +... +{ + int noti_err = 0; + bool value; + notification_setting_h setting = NULL; + + ... + + value = true; // or false + + noti_err = notifiacation_setting_get_pop_up_notification(setting, value); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + notification_setting_free_notification(setting); + + return 0; + +} + * @endcode + */ +int notification_setting_set_pop_up_notification(notification_setting_h setting, bool value); + +/* + * @internal + * @brief Gets displaying level that notification's information on lock screen from individual application. + * @since_tizen 3.0 + * @param[in] setting The notification setting handle + * @param[out] level The displaying level of notification's information on lock screen + * @return #NOTIFICATION_ERROR_NONE on success, + * otherwise any other value on failure + * @retval #NOTIFICATION_ERROR_NONE Success + * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @see #lock_screen_content_level_e + * @par sample code: + * @code +#include +... +{ + int noti_err = 0; + notification_setting_h setting = NULL; + lock_screen_content_level_e level; + + ... + + noti_err = notifiacation_setting_get_lock_screen_content(setting, &level); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + notification_setting_free_notification(setting); + + return 0; + +} + * @endcode + */ +int notification_setting_get_lock_screen_content(notification_setting_h setting, lock_screen_content_level_e *level); + +/* + * @internal + * @brief Sets displaying level that notification's information on lock screen from individual application. + * @details After notification_setting_update_setting() call, the lock_screen_content_level value is updated. + * @since_tizen 3.0 + * @param[in] setting The notification setting handle + * @param[out] level The displaying level of notification's information on lock screen + * @return #NOTIFICATION_ERROR_NONE on success, + * otherwise any other value on failure + * @retval #NOTIFICATION_ERROR_NONE Success + * @retval #NOTIFICATION_ERROR_INVALID_PARAMETER Invalid parameter + * @see #lock_screen_content_level_e + * @par sample code: + * @code +#include +... +{ + int noti_err = 0; + notification_setting_h setting = NULL; + lock_screen_content_level_e level; + + ... + + level = SHOW_ALL_CONTENT; // or HIDE_SENSITIVE_CONTENT or DO_NOT_SHOW_NOTIFICATIONS; + + noti_err = notifiacation_setting_get_lock_screen_content(setting, level); + if(noti_err != NOTIFICATION_ERROR_NONE) { + return; + } + + notification_setting_free_notification(setting); + + return 0; + +} + * @endcode + */ +int notification_setting_set_lock_screen_content(notification_setting_h setting, lock_screen_content_level_e level); + +/* + * @internal * @brief Gets the notification system setting handle. * @since_tizen @if wearable 2.3.1 @elseif mobile 2.3 @endif * @privlevel public diff --git a/include/notification_setting_service.h b/include/notification_setting_service.h index 1d810b2..2ec8f45 100644 --- a/include/notification_setting_service.h +++ b/include/notification_setting_service.h @@ -27,7 +27,8 @@ extern "C" { int notification_setting_db_set(const char *pkgname, const char *property, const char *value); int notification_setting_db_get(const char *pkgname, const char *property, char **value); -int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class, uid_t uid); +int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class, + int pop_up_notification, int lock_screen_content_level, uid_t uid); int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class, int dnd_schedule_enabled, int dnd_schedule_day, int dnd_start_hour, int dnd_start_min, diff --git a/src/notification_db.c b/src/notification_db.c index 9dbd342..156ad78 100755 --- a/src/notification_db.c +++ b/src/notification_db.c @@ -124,6 +124,8 @@ create table if not exists noti_list ( \ allow_to_notify INTEGER DEFAULT 1, \ do_not_disturb_except INTEGER DEFAULT 0, \ visibility_class INTEGER DEFAULT 0, \ + pop_up_notification INTEGER DEFAULT 1, \ + lock_screen_content_level INTEGER DEFAULT 0, \ UNIQUE (uid, package_name) \ ); \ CREATE TABLE IF NOT EXISTS notification_system_setting ( \ diff --git a/src/notification_ipc.c b/src/notification_ipc.c index be7b43c..940ce70 100755 --- a/src/notification_ipc.c +++ b/src/notification_ipc.c @@ -1275,11 +1275,13 @@ int notification_ipc_update_setting(notification_setting_h setting, uid_t uid) return result; } - body = g_variant_new("(siiii)", + body = g_variant_new("(siiiiii)", setting->package_name, (int)(setting->allow_to_notify), (int)(setting->do_not_disturb_except), (int)(setting->visibility_class), + (int)(setting->pop_up_notification), + (int)(setting->lock_screen_content_level), uid); result = _send_sync_noti(body, &reply, "update_noti_setting"); @@ -1915,11 +1917,13 @@ EXPORT_API GVariant *notification_ipc_make_gvariant_from_setting(struct notifica { GVariant *body = NULL; - body = g_variant_new("(siii)", + body = g_variant_new("(siiiii)", noti_setting->package_name, noti_setting->allow_to_notify, noti_setting->do_not_disturb_except, - noti_setting->visibility_class); + noti_setting->visibility_class, + noti_setting->pop_up_notification, + noti_setting->lock_screen_content_level); return body; } @@ -1932,17 +1936,21 @@ EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_s int allow_to_notify; int do_not_disturb_except; int visibility_class; + int pop_up_notification; + int lock_screen_content_level; if (noti_setting == NULL || variant == NULL) { NOTIFICATION_ERR("invalid data"); return NOTIFICATION_ERROR_INVALID_PARAMETER; } g_variant_get(variant, - "(&siii)", + "(&siiiii)", &pkgname, &allow_to_notify, &do_not_disturb_except, - &visibility_class); + &visibility_class, + &pop_up_notification, + &lock_screen_content_level); NOTIFICATION_DBG("setting from variant %s !!", pkgname); @@ -1950,6 +1958,8 @@ EXPORT_API int notification_ipc_make_setting_from_gvariant(struct notification_s noti_setting->allow_to_notify = allow_to_notify; noti_setting->do_not_disturb_except = do_not_disturb_except; noti_setting->visibility_class = visibility_class; + noti_setting->pop_up_notification = pop_up_notification; + noti_setting->lock_screen_content_level = lock_screen_content_level; NOTIFICATION_DBG("setting from variant %s, %s", noti_setting->package_name, pkgname); diff --git a/src/notification_noti.c b/src/notification_noti.c index 114b893..31ea558 100755 --- a/src/notification_noti.c +++ b/src/notification_noti.c @@ -849,6 +849,37 @@ out: return err; } +static bool _is_pop_up_notification(const char *caller_package_name, uid_t uid) +{ + int err; + char *package_id = NULL; + bool ret = true; + notification_setting_h setting = NULL; + + err = noti_setting_service_get_setting_by_package_name(caller_package_name, &setting, uid); + if (err != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("noti_setting_service_get_setting_by_package_name failed [%d]", err); + goto out; + } + + err = notification_setting_get_pop_up_notification(setting, &ret); + if (err != NOTIFICATION_ERROR_NONE) { + NOTIFICATION_ERR("notification_setting_get_pop_up_notification failed"); + goto out; + } + + if (ret != true) + NOTIFICATION_DBG("[%s] is not allowed Pop-up notification", caller_package_name); + +out: + if (package_id) + free(package_id); + if (setting) + notification_setting_free_notification(setting); + + return ret; +} + EXPORT_API int notification_noti_insert(notification_h noti) { int ret = 0; @@ -871,6 +902,10 @@ EXPORT_API int notification_noti_insert(notification_h noti) if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE) NOTIFICATION_WARN("_handle_do_not_disturb_option failed"); + if (_is_pop_up_notification((const char *)noti->caller_pkgname, noti->uid) == false) { + noti->display_applist = (noti->display_applist & (~NOTIFICATION_DISPLAY_APP_ACTIVE)); + NOTIFICATION_DBG("notification display applist - pkgname [%s], applist [%d]", noti->caller_pkgname, noti->display_applist); + } db = notification_db_open(DBPATH); if (!db) @@ -1147,6 +1182,11 @@ EXPORT_API int notification_noti_update(notification_h noti) if (_handle_do_not_disturb_option(noti) != NOTIFICATION_ERROR_NONE) NOTIFICATION_WARN("_handle_do_not_disturb_option failed"); + if (_is_pop_up_notification((const char *)noti->caller_pkgname, noti->uid) == false) { + noti->display_applist = (noti->display_applist & (~NOTIFICATION_DISPLAY_APP_ACTIVE)); + NOTIFICATION_DBG("notification display applist - pkgname [%s], applist [%d]", noti->caller_pkgname, noti->display_applist); + } + /* Check private ID is exist */ ret = _notification_noti_check_priv_id(noti, db); if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) { diff --git a/src/notification_setting.c b/src/notification_setting.c index f085a63..0be8062 100755 --- a/src/notification_setting.c +++ b/src/notification_setting.c @@ -205,6 +205,50 @@ EXPORT_API int notification_setting_set_visibility_class(notification_setting_h return NOTIFICATION_ERROR_NONE; } +EXPORT_API int notification_setting_get_pop_up_notification(notification_setting_h setting, bool *value) +{ + if (setting == NULL || value == NULL) { + NOTIFICATION_ERR("Invalid parameter"); + return NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + *value = setting->pop_up_notification; + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API int notification_setting_set_pop_up_notification(notification_setting_h setting, bool value) +{ + if (setting == NULL) { + NOTIFICATION_ERR("Invalid parameter"); + return NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + setting->pop_up_notification = value; + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API int notification_setting_get_lock_screen_content(notification_setting_h setting, lock_screen_content_level_e *level) +{ + if (setting == NULL || level == NULL) { + NOTIFICATION_ERR("Invalid parameter"); + return NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + *level = setting->lock_screen_content_level; + return NOTIFICATION_ERROR_NONE; +} + +EXPORT_API int notification_setting_set_lock_screen_content(notification_setting_h setting, lock_screen_content_level_e level) +{ + if (setting == NULL) { + NOTIFICATION_ERR("Invalid parameter"); + return NOTIFICATION_ERROR_INVALID_PARAMETER; + } + + setting->lock_screen_content_level = level; + return NOTIFICATION_ERROR_NONE; +} + EXPORT_API int notification_setting_update_setting_for_uid(notification_setting_h setting, uid_t uid) { if (setting == NULL) { diff --git a/src/notification_setting_service.c b/src/notification_setting_service.c index 9202ce5..768250a 100644 --- a/src/notification_setting_service.c +++ b/src/notification_setting_service.c @@ -116,9 +116,9 @@ int noti_setting_service_get_setting_by_package_name(const char *package_name, n goto out; } - sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class " - "FROM %s " - "WHERE package_name = %Q AND uid = %d", NOTIFICATION_SETTING_DB_TABLE, package_name, uid); + sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class, " + "pop_up_notification, lock_screen_content_level FROM %s " + "WHERE package_name = %Q AND uid = %d", NOTIFICATION_SETTING_DB_TABLE, package_name, uid); if (!sql_query) { NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */ @@ -156,6 +156,8 @@ int noti_setting_service_get_setting_by_package_name(const char *package_name, n _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].allow_to_notify), col_index++); _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].do_not_disturb_except), col_index++); _get_table_field_data_int(query_result, &(result_setting_array[i].visibility_class), col_index++); + _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].pop_up_notification), col_index++); + _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].lock_screen_content_level), col_index++); *setting = result_setting_array; @@ -203,9 +205,9 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c goto out; } - sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class " - "FROM %s WHERE uid = %d " - "ORDER BY package_name", NOTIFICATION_SETTING_DB_TABLE, uid); + sql_query = sqlite3_mprintf("SELECT package_name, allow_to_notify, do_not_disturb_except, visibility_class, " + "pop_up_notification, lock_screen_content_level FROM %s WHERE uid = %d " + "ORDER BY package_name", NOTIFICATION_SETTING_DB_TABLE, uid); if (!sql_query) { NOTIFICATION_ERR("fail to alloc query"); /* LCOV_EXCL_LINE */ @@ -241,6 +243,8 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].allow_to_notify), col_index++); _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].do_not_disturb_except), col_index++); _get_table_field_data_int(query_result, &(result_setting_array[i].visibility_class), col_index++); + _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].pop_up_notification), col_index++); + _get_table_field_data_int(query_result, (int *)&(result_setting_array[i].lock_screen_content_level), col_index++); } *setting_array = result_setting_array; @@ -248,7 +252,7 @@ int noti_setting_get_setting_array(notification_setting_h *setting_array, int *c out: if (query_result) - sqlite3_free_table(query_result); + sqlite3_free_table(query_result); if (sql_query) sqlite3_free(sql_query); @@ -362,7 +366,10 @@ out: } EXPORT_API -int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class, uid_t uid) +int notification_setting_db_update(const char *package_name, int allow_to_notify, + int do_not_disturb_except, int visibility_class, + int pop_up_notification, int lock_screen_content_level, + uid_t uid) { int err = NOTIFICATION_ERROR_NONE; sqlite3 *db = NULL; @@ -378,9 +385,11 @@ int notification_setting_db_update(const char *package_name, int allow_to_notify return NOTIFICATION_ERROR_FROM_DB; } - sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, do_not_disturb_except = %d, visibility_class = %d " \ + sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, do_not_disturb_except = %d, visibility_class = %d, " \ + "pop_up_notification = %d, lock_screen_content_level = %d " \ "WHERE package_name = %Q AND uid = %d", - NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class, package_name, uid); + NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class, + pop_up_notification, lock_screen_content_level, package_name, uid); if (!sqlbuf) { NOTIFICATION_ERR("fail to alloc query"); err = NOTIFICATION_ERROR_OUT_OF_MEMORY; diff --git a/test-app/main.c b/test-app/main.c index 36833c6..8c93e97 100755 --- a/test-app/main.c +++ b/test-app/main.c @@ -674,6 +674,8 @@ static int testapp_test_get_setting_list() bool allow_to_notify = false; bool do_not_disturb_except = false; int visibility_class = false; + bool pop_up_notification = false; + lock_screen_content_level_e level = 0; notification_setting_h setting_array = NULL; notification_setting_get_setting_array(&setting_array, &count); @@ -685,9 +687,10 @@ static int testapp_test_get_setting_list() notification_setting_get_allow_to_notify(setting_array + i, &allow_to_notify); notification_setting_get_do_not_disturb_except(setting_array + i, &do_not_disturb_except); notification_setting_get_visibility_class(setting_array + i, &visibility_class); - - testapp_print("[%d] : package_name[%s], allow_to_notify[%d], do_not_disturb_except[%d], visibility_class[%d]\n" - , i, package_name, allow_to_notify, do_not_disturb_except, visibility_class); + notification_setting_get_pop_up_notification(setting_array + i, &pop_up_notification); + notification_setting_get_lock_screen_content(setting_array + i, &level); + testapp_print("[%d] : package_name[%s], allow_to_notify[%d], do_not_disturb_except[%d], visibility_class[%d], notification_pop_up[%d], lock_content_level[%d]\n" + , i, package_name, allow_to_notify, do_not_disturb_except, visibility_class, pop_up_notification, level); free(package_name); }