#include "pkgmgr_parser.h"
#include "pkgmgr_parser_internal.h"
-#define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
- "(cert_info text not null, " \
- "cert_id integer, " \
- "cert_ref_count integer, " \
- "PRIMARY KEY(cert_id)) "
-
-#define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
- "(package text not null, " \
- "author_root_cert integer, " \
- "author_im_cert integer, " \
- "author_signer_cert integer, " \
- "dist_root_cert integer, " \
- "dist_im_cert integer, " \
- "dist_signer_cert integer, " \
- "dist2_root_cert integer, " \
- "dist2_im_cert integer, " \
- "dist2_signer_cert integer, " \
- "PRIMARY KEY(package)) "
+#define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
+ "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
+ " cert_info TEXT UNIQUE, " \
+ " cert_id INTEGER PRIMARY KEY, " \
+ " cert_ref_count INTEGER NOT NULL)"
+
+#define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
+ "CREATE TABLE IF NOT EXISTS package_cert_info( " \
+ " package TEXT PRIMARY KEY, " \
+ " author_root_cert INTEGER, " \
+ " author_im_cert INTEGER, " \
+ " author_signer_cert INTEGER, " \
+ " dist_root_cert INTEGER, " \
+ " dist_im_cert INTEGER, " \
+ " dist_signer_cert INTEGER, " \
+ " dist2_root_cert INTEGER, " \
+ " dist2_im_cert INTEGER, " \
+ " dist2_signer_cert INTEGER)"
+
+#define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
+ "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
+ "AFTER DELETE ON package_cert_info " \
+ "BEGIN" \
+ " UPDATE package_cert_index_info SET" \
+ " cert_ref_count = cert_ref_count - 1" \
+ " WHERE cert_id = OLD.author_root_cert" \
+ " OR cert_id = OLD.author_im_cert" \
+ " OR cert_id = OLD.author_signer_cert" \
+ " OR cert_id = OLD.dist_root_cert" \
+ " OR cert_id = OLD.dist_im_cert" \
+ " OR cert_id = OLD.dist_signer_cert" \
+ " OR cert_id = OLD.dist2_root_cert" \
+ " OR cert_id = OLD.dist2_im_cert" \
+ " OR cert_id = OLD.dist2_signer_cert;" \
+ "END;"
+
+#define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
+ "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
+ "AFTER UPDATE ON package_cert_index_info " \
+ "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
+ " WHERE cert_id = OLD.cert_id) = 0) "\
+ "BEGIN" \
+ " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
+ "END;"
+
+#define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
+ "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
+ "AFTER UPDATE ON package_cert_info " \
+ "WHEN (OLD.%s IS NOT NULL) " \
+ "BEGIN" \
+ " UPDATE package_cert_index_info SET" \
+ " cert_ref_count = cert_ref_count - 1" \
+ " WHERE cert_id = OLD.%s;" \
+ "END;"
+
__thread db_handle manifest_db;
__thread db_handle cert_db;
int _check_create_cert_db(sqlite3 *certdb)
{
+ int i;
+ char buf[BUFSIZE];
+ static const char *columns[] = {
+ "author_root_cert", "author_im_cert", "author_signer_cert",
+ "dist_root_cert", "dist_im_cert", "dist_signer_cert",
+ "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
+ NULL};
int ret = 0;
ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
if (ret < 0)
return ret;
ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
+ if (ret < 0)
+ return ret;
+ ret = __exec_db_query(certdb, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO, NULL, NULL);
+ if (ret < 0)
+ return ret;
+ ret = __exec_db_query(certdb, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO, NULL, NULL);
+
+ for (i = 0; columns[i] != NULL; i++) {
+ snprintf(buf, sizeof(buf),
+ QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
+ columns[i], columns[i], columns[i]);
+ ret = __exec_db_query(certdb, buf, NULL, NULL);
+ if (ret < 0)
+ return ret;
+ }
return ret;
}
static gid_t _get_gid(const char *name)
"package_app_share_allowed",
"package_app_app_permission",
"package_app_share_request",
- "package_app_app_svc",
"package_info",
"package_app_data_control",
"package_localized_info",
return 0;
}
+void _save_column_int(sqlite3_stmt *stmt, int idx, int *i)
+{
+ *i = sqlite3_column_int(stmt, idx);
+}
+
void _save_column_str(sqlite3_stmt *stmt, int idx, const char **str)
{
const char *val;
val = (const char *)sqlite3_column_text(stmt, idx);
- /* get string when the result is not null */
- if (val && (strcasecmp(val, "(null)") != 0) && (strcmp(val, "") != 0))
+ if (val)
*str = strdup(val);
}
retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
- val = info->uiapp_info->guestmode_visibility;
+ val = info->app_info->guestmode_visibility;
if (val) {
ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
SQLITE_OPEN_READWRITE, NULL);
/*TODO: Write to DB here*/
if (status == true)
- snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
+ snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->app_info->appid);
else
- snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
+ snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->app_info->appid);
ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg);
sqlite3_close(pkgmgr_parser_db);
{
return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
}
+
+API int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char *pkgid, INSTALL_LOCATION location, uid_t uid)
+{
+ retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
+ int ret = -1;
+ sqlite3 *pkgmgr_parser_db = NULL;
+ char *query = NULL;
+
+ ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
+ SQLITE_OPEN_READWRITE, NULL);
+ retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db failed!");
+
+ /*Begin transaction*/
+ // Setting Manifest DB
+ ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+ tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Failed to begin transaction\n");
+ _LOGD("Transaction Begin\n");
+
+ // pkgcakge_info table
+ query = sqlite3_mprintf("update package_info set installed_storage=%Q where package=%Q", location?"installed_external":"installed_internal", pkgid);
+
+ ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, NULL);
+ tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s\n", query);
+ sqlite3_free(query);
+
+ // package_app_info table
+ query = sqlite3_mprintf("update package_app_info set app_installed_storage=%Q where package=%Q", location?"installed_external":"installed_internal", pkgid);
+
+ ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, NULL);
+ tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s\n", query);
+
+ /*Commit transaction*/
+ ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
+ if (ret != SQLITE_OK) {
+ _LOGE("Failed to commit transaction. Rollback now\n");
+ ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+ tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s\n", query);
+ }
+ _LOGD("Transaction Commit and End\n");
+
+ ret = PMINFO_R_OK;
+catch:
+ sqlite3_close(pkgmgr_parser_db);
+ sqlite3_free(query);
+ return ret;
+}
+
+API int pkgmgrinfo_pkginfo_set_installed_storage(const char *pkgid, INSTALL_LOCATION location)
+{
+ return pkgmgrinfo_pkginfo_set_usr_installed_storage(pkgid, location, GLOBAL_USER);
+}