#include <vconf.h>
#include <pkgmgr-info.h>
#include <tzplatform_config.h>
+#include <inttypes.h>
#include <string.h>
#include <list>
" root_id TEXT NOT NULL,\n" \
" app_id TEXT NOT NULL,\n" \
" uid INTEGER,\n" \
- " priv_id INTEGER,\n" \
+ " priv_id INTEGER PRIMARY KEY,\n" \
" pkg_id TEXT,\n" \
" policy INTEGER,\n" \
" data TEXT NOT NULL,\n" \
" insert_time INTEGER,\n" \
" hide_list TEXT,\n" \
- " PRIMARY KEY (root_id, app_id, uid));\n" \
+ " UNIQUE (root_id, app_id, uid));\n" \
"CREATE TABLE IF NOT EXISTS receiver_list (\n" \
" root_id TEXT NOT NULL,\n" \
" app_id TEXT NOT NULL,\n" \
return ret;
}
+int DBManager::GetSequence(sqlite3* db, int64_t* seq) {
+ int ret = ERROR_NONE;
+ sqlite3_stmt *stmt;
+
+ if (db == nullptr || seq == nullptr)
+ return ERROR_INVALID_PARAMETER;
+
+ string query = "SELECT IFNULL(MIN(priv_id), 0), IFNULL(MAX(priv_id), 0)"
+ " FROM noti_ex_list";
+ sqlite3_prepare_v2(db, query.c_str(), query.size(), &stmt, nullptr);
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ int64_t min_p = sqlite3_column_int64(stmt, 0);
+ if (min_p > 1)
+ *seq = min_p - 1;
+ else
+ *seq = sqlite3_column_int64(stmt, 1) + 1;
+ ret = ERROR_NONE;
+ } else {
+ /* LCOV_EXCL_START */
+ LOGE("Sqlite err [%d][%s]", ret, sqlite3_errmsg(db));
+ ret = ERROR_FROM_DB;
+ /* LCOV_EXCL_STOP */
+ }
+
+ sqlite3_finalize(stmt);
+ return ret;
+}
+
int DBManager::CheckDBIntegrity(void* user_data, int argc,
char** argv, char** notUsed) {
bool* is_db_corrupted = static_cast<bool*>(user_data);
int ret = ERROR_NONE;
int count;
char* query;
+ int64_t seq;
sqlite3* db = OpenDB();
if (db == nullptr)
for (auto& i : addedItem) {
int uid = static_pointer_cast<IItemInfoInternal>(i->GetInfo())->GetUid();
- ret = GetCount(i->GetId(), i->GetSenderAppId(), uid, &count);
+ ret = GetCount(0, i->GetId(), i->GetSenderAppId(), uid, &count);
if (ret != ERROR_NONE)
break;
break;
}
+ ret = GetSequence(db, &seq);
+ if (ret != ERROR_NONE)
+ break;
+
+ static_pointer_cast<IItemInfoInternal>(i->GetInfo())->SetPrivateId(seq);
Bundle b = i->Serialize();
query = sqlite3_mprintf("INSERT INTO noti_ex_list"
" (root_id, app_id, uid, priv_id, pkg_id, policy, data, insert_time)"
- " VALUES (%Q, %Q, %d, %d, %Q, %d, %Q, %d)",
+ " VALUES (%Q, %Q, %d, %" PRId64 ", %Q, %d, %Q, %d)",
i->GetId().c_str(),
i->GetSenderAppId().c_str(),
uid,
- util::GetQuarkFromString(i->GetId()),
+ static_pointer_cast<IItemInfoInternal>(i->GetInfo())->GetPrivateId(),
GetPkgId(i->GetSenderAppId(),uid).c_str(),
static_cast<int>(i->GetPolicy()),
reinterpret_cast<char*>(b.ToRaw().first.get()),
}
int DBManager::GetCount(const string& app_id, int uid, int* count) {
- return GetCount(string(), app_id, uid, count);
+ return GetCount(0, string(), app_id, uid, count);
}
-int DBManager::GetCount(const string& root_id, const string& app_id,
+int DBManager::GetCount(int64_t priv_id, const string& root_id, const string& app_id,
int uid, int* count) {
int ret;
char* query;
sqlite3_stmt *stmt;
sqlite3* db;
- if (root_id.empty()) {
+ if (priv_id != 0) {
+ query = sqlite3_mprintf("SELECT count(*) FROM noti_ex_list"
+ " WHERE priv_id = %" PRId64 "", priv_id);
+ } else if (root_id.empty()) {
query = sqlite3_mprintf("SELECT count(*) FROM noti_ex_list"
" WHERE app_id = %Q AND uid = %d", app_id.c_str(), uid);
} else {
int DBManager::UpdateNotification(shared_ptr<item::AbstractItem> updatedItem) {
int count, ret;
char* query;
- int uid = static_pointer_cast<IItemInfoInternal>(updatedItem->GetInfo())->GetUid();
+ int uid = static_pointer_cast<IItemInfoInternal>(
+ updatedItem->GetInfo())->GetUid();
+ int64_t priv_id = static_pointer_cast<IItemInfoInternal>(
+ updatedItem->GetInfo())->GetPrivateId();
- ret = GetCount(updatedItem->GetId(), updatedItem->GetSenderAppId(), uid, &count);
+ ret = GetCount(priv_id, updatedItem->GetId(), updatedItem->GetSenderAppId(),
+ uid, &count);
if (ret != ERROR_NONE) {
LOGE("fail to get count");
return ret;
}
if (count <= 0) {
- LOGE("not exist id(%s) for appid(%s)",
+ LOGE("not exist priv_id(%" PRId64 ") id(%s) for appid(%s)", priv_id,
updatedItem->GetId().c_str(), updatedItem->GetSenderAppId().c_str());
return ERROR_NOT_EXIST_ID;
}
Bundle b = updatedItem->Serialize();
query = sqlite3_mprintf("UPDATE noti_ex_list SET"
- " priv_id = %d, pkg_id = %Q, policy = %d, data = %Q, insert_time = %d"
- " WHERE root_id = %Q AND app_id = %Q AND uid = %d",
- util::GetQuarkFromString(updatedItem->GetId()),
+ " pkg_id = %Q, policy = %d, data = %Q, insert_time = %d"
+ " WHERE priv_id = %" PRId64 "",
GetPkgId(updatedItem->GetSenderAppId(), uid).c_str(),
static_cast<int>(updatedItem->GetPolicy()),
reinterpret_cast<char*>(b.ToRaw().first.get()),
static_pointer_cast<IItemInfo>(updatedItem->GetInfo())->GetTime(),
- updatedItem->GetId().c_str(),
- updatedItem->GetSenderAppId().c_str(),
- uid);
+ priv_id);
if (!query) {
LOGE("OOM - sql query");
return item_list;
}
+list<shared_ptr<item::AbstractItem>> DBManager::GetNotificationList
+ (string app_id, int64_t priv_id, int uid) {
+ char* query;
+ list<shared_ptr<item::AbstractItem>> item_list;
+
+ query = sqlite3_mprintf("SELECT data FROM noti_ex_list"
+ " WHERE uid = %d AND app_id = %Q AND priv_id = %" PRId64 "",
+ uid, app_id.c_str(), priv_id);
+
+ if (!query) {
+ LOGE("OOM - sql query");
+ return item_list;
+ }
+
+ item_list = ExecuteGetList(query);
+ sqlite3_free(query);
+
+ return item_list;
+}
+
list<shared_ptr<item::AbstractItem>> DBManager::GetNotificationList(int uid) {
int ret, sim_mode;
char* query;
int DBManager::DeleteNotification(shared_ptr<item::AbstractItem> deletedItem) {
int ret;
char* query;
- int uid = static_pointer_cast<IItemInfoInternal>(deletedItem->GetInfo())->GetUid();
+ int64_t priv_id = static_pointer_cast<IItemInfoInternal>(
+ deletedItem->GetInfo())->GetPrivateId();
- query = sqlite3_mprintf("DELETE FROM noti_ex_list"
- " WHERE root_id = %Q AND app_id = %Q AND uid = %d",
- deletedItem->GetId().c_str(), deletedItem->GetSenderAppId().c_str(),
- uid);
+ query = sqlite3_mprintf("DELETE FROM noti_ex_list WHERE priv_id = %" PRId64 "",
+ priv_id);
if (!query) {
LOGE("OOM - sql query");
return ERROR_OUT_OF_MEMORY;
ret = ExecuteQuery(query, nullptr);
sqlite3_free(query);
- if (ret != ERROR_NONE)
- return ret;
-
- query = sqlite3_mprintf("DELETE FROM receiver_list"
- " WHERE root_id = %Q AND app_id = %Q AND uid = %d",
- deletedItem->GetId().c_str(), deletedItem->GetSenderAppId().c_str(),
- uid);
- if (!query) {
- LOGE("OOM - sql query");
- return ERROR_OUT_OF_MEMORY;
- }
-
- ret = ExecuteQuery(query, nullptr);
- sqlite3_free(query);
-
return ret;
}
static std::map<std::string, std::string> GetHideMap();
static int UpdateHideList(std::shared_ptr<item::AbstractItem> updatedItem, const std::string& hide_list);
static int UpdateNotification(std::shared_ptr<item::AbstractItem> updatedItem);
- static int GetCount(const std::string& root_id, const std::string& app_id, int uid, int* count);
+ static int GetCount(int64_t priv_id, const std::string& root_id, const std::string& app_id, int uid, int* count);
static int GetCount(const std::string& app_id, int uid, int* count);
static int DeleteNotification(std::shared_ptr<item::AbstractItem> deletedItem);
static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(int uid);
static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(std::string app_id, int uid);
static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(std::string app_id, std::string root_id, int uid);
+ static std::list<std::shared_ptr<item::AbstractItem>> GetNotificationList(std::string app_id, int64_t private_id, int uid);
private:
DBManager(); /* LCOV_EXCL_LINE */
static int RecoverCorruptedDB(sqlite3* db);
static int ExecuteQuery(const char* query, int* num_changes);
static int ExecuteQuery(sqlite3* db, const char* query, int* num_changes);
+ static int GetSequence(sqlite3* db, int64_t* seq);
static std::string GetPkgId(const std::string& app_id, int uid);
static void CheckLimit(std::shared_ptr<item::AbstractItem> addedItem, sqlite3* db);
static int UpdateReceiverList(std::shared_ptr<item::AbstractItem> updatedItem, sqlite3* db);
notification_h notification;
int ret, i;
char *id;
+ int64_t priv_id;
if (item == NULL || noti == NULL) {
ERR("Invalid param");
return ret;
}
- noti_ex_item_get_id(item, &id);
- ret = notification_set_priv_id(notification, g_quark_from_string(id));
- free(id);
+ noti_ex_item_get_private_id(item, &priv_id);
+ ret = notification_set_priv_id(notification, priv_id);
if (ret != NOTI_EX_ERROR_NONE) {
ERR("failed to convert(%d)", ret);
goto out;
noti_ex_item_h group_item;
const char *id = NULL;
const char *tag = NULL;
- char *priv_id;
+ int legacy_priv_id;
if (noti == NULL || item == NULL) {
ERR("Invalid param");
return NOTIFICATION_ERROR_INVALID_PARAMETER;
}
- if (noti->priv_id > 0) { /* case of update */
- id = g_quark_to_string(noti->priv_id);
- } else { /* case of insert */
+ /* Legacy tag was legacy notification's Root ID
+ * If legacy notification does not has a tag then auto ID generated by
+ * abstract item will be used as Root ID
+ */
+ if (noti->tag) {
notification_get_tag(noti, &tag);
if (tag != NULL)
id = tag;
ret = noti_ex_item_set_sender_app_id(group_item, id);
if (ret != NOTI_EX_ERROR_NONE) {
ERR("failed to convert(%d)", ret);
- goto out;
+ noti_ex_item_destroy(group_item);
+ return notification_convert_to_legacy_error(ret);
}
+ notification_get_id(noti, NULL, &legacy_priv_id);
+ noti_ex_item_set_private_id(group_item, legacy_priv_id);
for (i = 0; i < sizeof(convert_to_ex_arr) / sizeof(convert_to_ex_arr[0]); i++) {
ret = convert_to_ex_arr[i](noti, group_item);
if (ret != NOTI_EX_ERROR_NONE) {
ERR("failed (%d)(%d)", i, ret);
- goto out;
- }
- }
-
-out:
- if (ret == NOTI_EX_ERROR_NONE) {
- if (noti->priv_id <= 0) {
- ret = noti_ex_item_get_id(group_item, &priv_id);
- if (ret != NOTI_EX_ERROR_NONE) {
- ERR("failed to convert(%d)", ret);
- noti_ex_item_destroy(group_item);
- return notification_convert_to_legacy_error(ret);
- }
- notification_set_priv_id(noti, g_quark_from_string(priv_id));
- free(priv_id);
+ noti_ex_item_destroy(group_item);
+ return notification_convert_to_legacy_error(ret);
}
-
- *item = group_item;
- } else {
- noti_ex_item_destroy(group_item);
}
-
+ *item = group_item;
return notification_convert_to_legacy_error(ret);
}