Name: notification
Summary: notification library
-Version: 0.2.33
+Version: 0.2.34
Release: 1
Group: TBD
License: Apache
UNIQUE (caller_pkgname, priv_id)
);
CREATE TABLE IF NOT EXISTS notification_setting (
- priv_id INTERGER PRIMARY KEY,
+ priv_id INTEGER PRIMARY KEY AUTOINCREMENT,
package_name TEXT NOT NULL,
allow_to_notify INTEGER DEFAULT 1,
do_not_disturb_except INTEGER DEFAULT 0,
UNIQUE (priv_id)
);
- INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (1, "org.tizen.photos", 1, 0, 0);
- INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (2, "org.tizen.email", 1, 0, 0);
- INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (3, "org.tizen.message", 1, 0, 0);
- INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (4, "org.tizen.internet", 1, 0, 0);
- INSERT INTO notification_setting (priv_id, package_name, allow_to_notify, do_not_disturb_except, visibility_class) VALUES (5, "org.tizen.games", 1, 0, 0);
INSERT INTO notification_system_setting (priv_id, do_not_disturb, visibility_class) VALUES (0, 0, 0);
CREATE UNIQUE INDEX package_name_idx1 ON notification_setting (package_name);
#include <string.h>
#include <stdlib.h>
#include <db-util.h>
+#include <package_manager.h>
+#include <tizen_type.h>
#include <notification.h>
#include <notification_db.h>
SAFE_FREE(setting->package_name);
-
/* add codes to free all properties */
SAFE_FREE(setting);
return err;
}
+static bool _is_package_in_setting_table(sqlite3 *db, const char *package_name)
+{
+ sqlite3_stmt *db_statement = NULL;
+ int sqlite3_ret = SQLITE_OK;
+ int err = true;
+ int field_index = 1;
+
+ sqlite3_ret = sqlite3_prepare_v2(db, "SELECT package_name FROM notification_setting WHERE package_name = ?", -1, &db_statement, NULL);
+
+ if (sqlite3_ret != SQLITE_OK) {
+ NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
+ err = false;
+ goto out;
+ }
+
+ sqlite3_bind_text(db_statement, field_index++, package_name, -1, SQLITE_TRANSIENT);
+
+ sqlite3_ret = sqlite3_step(db_statement);
+
+ if (sqlite3_ret == SQLITE_DONE) {
+ NOTIFICATION_INFO("no matched package_name found[%s][%d]", package_name, sqlite3_ret);
+ err = false;
+ goto out;
+ }
+
+ if (sqlite3_ret != SQLITE_OK) {
+ NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
+ err = false;
+ goto out;
+ }
+out:
+ if (db_statement) {
+ sqlite3_finalize(db_statement);
+ }
+
+ return err;
+}
+
+static bool foreach_package_info_callback(package_info_h package_info, void *user_data)
+{
+ sqlite3 *db = user_data;
+ sqlite3_stmt *db_statement = NULL;
+ char *package_name = NULL;
+ int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
+ int sqlite3_ret = SQLITE_OK;
+ int field_index = 1;
+ int err = true;
+
+ if ((pkgmgr_ret = package_info_get_package(package_info, &package_name)) != PACKAGE_MANAGER_ERROR_NONE) {
+ NOTIFICATION_ERR("package_info_get_package failed [%d]", pkgmgr_ret);
+ err = false;
+ goto out;
+ }
+
+ if (_is_package_in_setting_table(db, package_name) == true) {
+ NOTIFICATION_INFO("[%s] is exist", package_name);
+ goto out;
+ }
+
+ NOTIFICATION_INFO("[%s] will be inserted", package_name);
+
+ sqlite3_ret = sqlite3_prepare_v2(db, "INSERT INTO notification_setting (package_name) VALUES (?) ", -1, &db_statement, NULL);
+
+ if (sqlite3_ret != SQLITE_OK) {
+ NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
+ err = false;
+ goto out;
+ }
+
+ sqlite3_bind_text(db_statement, field_index++, package_name, -1, SQLITE_TRANSIENT);
+
+ sqlite3_ret = sqlite3_step(db_statement);
+
+ NOTIFICATION_INFO("sqlite3_step returns[%d]", sqlite3_ret);
+
+ if (sqlite3_ret != SQLITE_OK && sqlite3_ret != SQLITE_DONE) {
+ NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db));
+ err = false;
+ }
+
+out:
+ if (db_statement) {
+ sqlite3_finalize(db_statement);
+ }
+
+ if(package_name) {
+ free(package_name);
+ }
+
+ NOTIFICATION_INFO("foreach_package_info_callback returns[%d]", err);
+ return err;
+}
+
+EXPORT_API int notification_setting_refresh_setting_table()
+{
+ int err = NOTIFICATION_ERROR_NONE;
+ sqlite3 *db = NULL;
+ int sqlite3_ret = SQLITE_OK;
+ int pkgmgr_ret = PACKAGE_MANAGER_ERROR_NONE;
+
+ sqlite3_ret = db_util_open(DBPATH, &db, 0);
+
+ if (sqlite3_ret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlite3_ret);
+ err = NOTIFICATION_ERROR_FROM_DB;
+ goto out;
+ }
+
+ sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
+
+ pkgmgr_ret = package_manager_foreach_package_info(foreach_package_info_callback, db);
+ if (pkgmgr_ret != PACKAGE_MANAGER_ERROR_NONE) {
+ NOTIFICATION_ERR("package_manager_filter_foreach_package_info failed [%d]", pkgmgr_ret);
+ err = NOTIFICATION_ERROR_FROM_DB;
+ goto out;
+ }
+
+out:
+
+ if (db) {
+ if (err == NOTIFICATION_ERROR_NONE) {
+ sqlite3_exec(db, "END;", NULL, NULL, NULL);
+ }
+ else {
+ sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
+ }
+
+ if ((sqlite3_ret = db_util_close(db)) != SQLITE_OK) {
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlite3_ret);
+ }
+ }
+
+ NOTIFICATION_INFO("notification_setting_refresh_setting_table returns [%d]", err);
+
+ return err;
+}
+
/* system setting --------------------------------*/
EXPORT_API int notification_system_setting_load_system_setting(notification_system_setting_h *system_setting)
{
int err = NOTIFICATION_ERROR_NONE;
int sqlret;
- int field_index = 0;
+ int field_index = 1;
sqlite3 *db = NULL;
sqlite3_stmt *db_statement = NULL;
testapp_print (" 1. Get setting list\n");
testapp_print (" 2. Update setting\n");
testapp_print (" 3. Update system setting\n");
+ testapp_print (" 4. Refresh setting table\n");
testapp_print ("------------------------------------------\n");
break;
default:
int visibility_class;
notification_system_setting_h system_setting = NULL;
-
err = notification_system_setting_load_system_setting(&system_setting);
if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
return err;
}
+static int testapp_test_refresh_setting_table()
+{
+ int err = NOTIFICATION_ERROR_NONE;
+ err = notification_setting_refresh_setting_table();
+
+ if (err != NOTIFICATION_ERROR_NONE) {
+ testapp_print("notification_setting_refresh_setting_table failed [%d]\n", err);
+ goto out;
+ }
+
+out:
+
+ return err;
+}
+
static gboolean testapp_interpret_command_setting_test (int selected_number)
{
gboolean go_to_loop = TRUE;
testapp_test_update_system_setting();
break;
+ case 4:
+ testapp_test_refresh_setting_table();
+ break;
+
case 0:
go_to_loop = FALSE;
break;