diff options
-rw-r--r-- | include/notification_setting.h | 1 | ||||
-rw-r--r-- | src/notification_init.c | 11 | ||||
-rwxr-xr-x | src/notification_setting.c | 87 |
3 files changed, 99 insertions, 0 deletions
diff --git a/include/notification_setting.h b/include/notification_setting.h index 76de7ca..851fbe6 100644 --- a/include/notification_setting.h +++ b/include/notification_setting.h @@ -171,6 +171,7 @@ int notification_setting_update_setting(notification_setting_h setting); int notification_setting_free_notification(notification_setting_h setting); int notification_setting_refresh_setting_table(uid_t uid); +int notification_system_setting_init_system_setting_table(uid_t uid); #ifdef __cplusplus } diff --git a/src/notification_init.c b/src/notification_init.c index c637fde..d2c0101 100644 --- a/src/notification_init.c +++ b/src/notification_init.c @@ -64,5 +64,16 @@ int main(int argc, char *argv[]) if (argc > 2) uid = (uid_t)atoi(argv[2]); ret = notification_setting_refresh_setting_table(uid); + if (ret != NOTIFICATION_ERROR_NONE) { + _E("notification setting table refresh fail."); + return ret; + } + + ret = notification_system_setting_init_system_setting_table(uid); + if (ret != NOTIFICATION_ERROR_NONE) { + _E("notification system setting table init fail."); + return ret; + } + return ret; } diff --git a/src/notification_setting.c b/src/notification_setting.c index 23f680c..f085a63 100755 --- a/src/notification_setting.c +++ b/src/notification_setting.c @@ -824,3 +824,90 @@ EXPORT_API int notification_unregister_system_setting_dnd_changed_cb(dnd_changed { return notification_unregister_system_setting_dnd_changed_cb_for_uid(callback, getuid()); } + +static bool _is_uid_in_system_setting_table(sqlite3 *db, uid_t uid) +{ + bool err = true; + sqlite3_stmt *db_statement = NULL; + int sqlite3_ret = SQLITE_OK; + int field_index = 1; + + sqlite3_ret = sqlite3_prepare_v2(db, "SELECT uid FROM notification_system_setting WHERE uid = ?", -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_int(db_statement, field_index++, uid); + + sqlite3_ret = sqlite3_step(db_statement); + if (sqlite3_ret == SQLITE_DONE) { + NOTIFICATION_INFO("no matched uid found[%d][%d]", uid, sqlite3_ret); + err = false; + goto out; + } + + if (sqlite3_ret != SQLITE_OK && sqlite3_ret != SQLITE_ROW) { + 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; +} + +EXPORT_API int notification_system_setting_init_system_setting_table(uid_t uid) +{ + int err = NOTIFICATION_ERROR_NONE; + int sqlite3_ret = SQLITE_OK; + int field_index = 1; + sqlite3 *db = NULL; + sqlite3_stmt *db_statement = NULL; + + NOTIFICATION_INFO("init system setting table [%d]", uid); + db = notification_db_open(DBPATH); + if (db == NULL) + return get_last_result(); + + /* if notification system setting don't init. */ + if (_is_uid_in_system_setting_table(db, uid) == true) { + NOTIFICATION_DBG("Notification system setting table is already initialized."); + } else { + NOTIFICATION_DBG("Notification system setting table is not initialized yet"); + sqlite3_ret = sqlite3_prepare_v2(db, "INSERT INTO notification_system_setting (uid) VALUES (?) ", -1, &db_statement, NULL); + if (sqlite3_ret != SQLITE_OK) { + NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db)); + err = NOTIFICATION_ERROR_FROM_DB; + goto out; + } + + sqlite3_bind_int(db_statement, field_index++, uid); + + sqlite3_ret = sqlite3_step(db_statement); + if (sqlite3_ret != SQLITE_OK && sqlite3_ret != SQLITE_DONE) { + NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlite3_ret, sqlite3_errmsg(db)); + err = NOTIFICATION_ERROR_FROM_DB; + goto out; + } + } + + NOTIFICATION_DBG("Notification system setting tables initialization is success."); + +out: + if (db) { + if (err == NOTIFICATION_ERROR_NONE) + sqlite3_exec(db, "END;", NULL, NULL, NULL); + else + sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL); + notification_db_close(&db); + } + if (db_statement) + sqlite3_finalize(db_statement); + + return err; +} |