#define BADGE_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".badge.db")
#define BADGE_SETTING_DB_TABLE "badge_setting"
+#define BADGE_TABLE_NAME "badge_data"
+#define BADGE_OPTION_TABLE_NAME "badge_option"
int badge_db_insert(const char *pkgname, const char *writable_pkg, const char *caller, uid_t uid);
int badge_db_delete(const char *pkgname, const char *caller_pkg, uid_t uid, pid_t pid);
int badge_setting_refresh_setting_table(uid_t uid);
int badge_db_update_setting(char *pkgname, char *appid, int allow_to_display, uid_t uid);
int badge_setting_is_existed_appid(const char *appid, bool *is_existed, uid_t uid);
+int badge_setting_arrange_tables(uid_t uid);
/**
* @}
return ret;
}
+EXPORT_API int badge_setting_arrange_tables(uid_t uid)
+{
+ int ret = BADGE_ERROR_NONE;
+ int sqlret;
+ sqlite3 *db = NULL;
+ char *sqlbuf = NULL;
+
+ sqlret = db_util_open(BADGE_DB_PATH, &db, 0);
+ if (sqlret != SQLITE_OK || !db) {
+ ERR("Failed to db_util_open [%d]", sqlret);
+ if (sqlret == SQLITE_PERM)
+ return BADGE_ERROR_PERMISSION_DENIED;
+ return BADGE_ERROR_FROM_DB;
+ }
+
+ sqlbuf = sqlite3_mprintf("DELETE FROM %Q WHERE pkgname not in "
+ "(SELECT pkgname FROM %Q) AND uid = %d",
+ BADGE_TABLE_NAME, BADGE_SETTING_DB_TABLE, uid);
+ if (sqlbuf == NULL) {
+ /* LCOV_EXCL_START */
+ ERR("Failed to alloc query");
+ ret = BADGE_ERROR_OUT_OF_MEMORY;
+ goto out;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = badge_db_exec(db, sqlbuf, NULL);
+ if (ret != BADGE_ERROR_NONE)
+ goto out;
+
+ if (sqlbuf) {
+ sqlite3_free(sqlbuf);
+ sqlbuf = NULL;
+ }
+
+ sqlbuf = sqlite3_mprintf("DELETE FROM %Q WHERE pkgname not in "
+ "(SELECT pkgname FROM %Q) AND uid = %d",
+ BADGE_OPTION_TABLE_NAME, BADGE_SETTING_DB_TABLE,
+ uid);
+ if (sqlbuf == NULL) {
+ /* LCOV_EXCL_START */
+ ERR("Failed to alloc query");
+ ret = BADGE_ERROR_OUT_OF_MEMORY;
+ goto out;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = badge_db_exec(db, sqlbuf, NULL);
+
+out:
+ if (sqlbuf)
+ sqlite3_free(sqlbuf);
+
+ if (db) {
+ sqlret = db_util_close(db);
+ if (sqlret != SQLITE_OK)
+ WARN("Failed to db_util_close [%d]", sqlret);
+ }
+
+ return ret;
+}