return PMINFO_R_OK;
}
+static int _pkginfo_get_appdefined_privilege(sqlite3 *db, const char *pkgid,
+ GList **privileges)
+{
+ static const char query_raw[] =
+ "SELECT DISTINCT privilege, license, type FROM "
+ "package_appdefined_privilege_info WHERE package=%Q";
+ int ret;
+ char *query;
+ sqlite3_stmt *stmt;
+ appdefined_privilege_x *privilege;
+
+ query = sqlite3_mprintf(query_raw, pkgid);
+ if (query == NULL) {
+ LOGE("out of memory");
+ return PMINFO_R_ERROR;
+ }
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query),
+ &stmt, NULL);
+ sqlite3_free(query);
+ if (ret != SQLITE_OK) {
+ LOGE("prepare failed: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ privilege = calloc(1, sizeof(appdefined_privilege_x));
+ if (!privilege) {
+ LOGE("failed to alloc memory");
+ return PMINFO_R_ERROR;
+ }
+ _save_column_str(stmt, 0, &privilege->value);
+ _save_column_str(stmt, 1, &privilege->license);
+ _save_column_str(stmt, 2, &privilege->type);
+ *privileges = g_list_append(*privileges,
+ (gpointer)privilege);
+ }
+
+ sqlite3_finalize(stmt);
+
+ return PMINFO_R_OK;
+}
+
static const char join_localized_info[] =
" LEFT OUTER JOIN package_localized_info"
" ON pi.package=package_localized_info.package"
char buf[MAX_QUERY_LEN] = { '\0' };
char buf2[MAX_QUERY_LEN] = { '\0' };
char *condition = NULL;
- size_t len = 0;
GSList *list = NULL;
if (filter == NULL)
return PMINFO_R_OK;
- strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
- len += strlen(" WHERE 1=1 ");
+ snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
for (list = filter->list; list; list = list->next) {
joined |= __get_filter_condition(list->data, uid, &condition,
bind_params);
if (condition == NULL)
continue;
- strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
- len += strlen(" AND ");
+ strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
- strncat(buf, condition, sizeof(buf) - len - 1);
- len += strlen(condition);
+ strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
free(condition);
condition = NULL;
}
if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
- strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1);
- len += strlen(join_localized_info);
+ strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1);
*bind_params = g_list_append(*bind_params, strdup(locale));
}
- if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) {
- strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1);
- len += strlen(join_privilege_info);
- }
- strncat(buf2, buf, MAX_QUERY_LEN - len - 1);
+ if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
+ strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
+ strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
*query = strdup(buf2);
if (*query == NULL)
static const char query_from_clause[] = " FROM package_info as pi";
int ret = PMINFO_R_ERROR;
int idx = 0;
- int query_len = 0;
char *dbpath;
char *tmp_record = NULL;
char *constraints = NULL;
ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
- _LOGD("failed to open db: %d", ret);
+ _LOGD("failed to open db(%s): %d", dbpath, ret);
free(dbpath);
return PMINFO_R_ERROR;
}
is_check_storage = __check_package_storage_status(tmp_filter);
- query_len = strlen(query_raw);
snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
- if (flag & PMINFO_APPINFO_GET_BASICINFO) {
- strncat(query, query_basic, MAX_QUERY_LEN - query_len - 1);
- query_len += strlen(query_basic);
- }
- if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
- strncat(query, query_author, MAX_QUERY_LEN - query_len - 1);
- query_len += strlen(query_author);
- }
+ if (flag & PMINFO_APPINFO_GET_BASICINFO)
+ strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
+ if (flag & PMINFO_PKGINFO_GET_AUTHOR)
+ strncat(query, query_author, sizeof(query) - strlen(query) - 1);
if (flag & PMINFO_PKGINFO_GET_LABEL) {
- strncat(query, query_label, MAX_QUERY_LEN - query_len - 1);
- query_len += strlen(query_label);
+ strncat(query, query_label, sizeof(query) - strlen(query) - 1);
bind_params = g_list_append(bind_params, strdup(locale));
}
if (flag & PMINFO_PKGINFO_GET_ICON) {
- strncat(query, query_icon, MAX_QUERY_LEN - query_len - 1);
- query_len += strlen(query_icon);
+ strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
bind_params = g_list_append(bind_params, strdup(locale));
}
if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
- strncat(query, query_description, MAX_QUERY_LEN - query_len - 1);
- query_len += strlen(query_description);
+ strncat(query, query_description, sizeof(query) - strlen(query) - 1);
bind_params = g_list_append(bind_params, strdup(locale));
}
- strncat(query, query_from_clause, MAX_QUERY_LEN - query_len - 1);
- query_len += strlen(query_from_clause);
+ strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
if (ret != PMINFO_R_OK) {
}
if (constraints)
- strncat(query, constraints, MAX_QUERY_LEN - query_len - 1);
+ strncat(query, constraints, sizeof(query) - strlen(query) - 1);
ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
if (ret != SQLITE_OK) {
}
}
+ if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
+ if (_pkginfo_get_appdefined_privilege(db, info->package,
+ &info->appdefined_privileges)) {
+ ret = PMINFO_R_ERROR;
+ goto catch;
+ }
+ }
+
if (is_check_storage &&
__pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
ret = PMINFO_R_ERROR;
if (ret != PMINFO_R_OK) {
_LOGE("Failed to create filter");
g_hash_table_destroy(list);
+ free(locale);
return PMINFO_R_ERROR;
}
}
- if (__check_disable_filter_exist(tmp_filter) == false)
- pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
+ if (__check_disable_filter_exist(tmp_filter) == false) {
+ ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
+ if (ret != PMINFO_R_OK) {
+ _LOGE("Failed to add filter");
+ g_hash_table_destroy(list);
+ free(locale);
+ if (filter == NULL)
+ pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
+ return PMINFO_R_ERROR;
+ }
+ }
ret = _pkginfo_get_packages(uid, locale, tmp_filter,
flag | PMINFO_PKGINFO_GET_BASICINFO, list);
if (locale == NULL)
return PMINFO_R_ERROR;
- list = g_hash_table_new(g_str_hash, g_str_equal);
+ list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ __free_packages);
if (list == NULL) {
free(locale);
return PMINFO_R_ERROR;
ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
PMINFO_PKGINFO_GET_ALL, list);
+ if (ret != PMINFO_R_OK) {
+ g_hash_table_destroy(list);
+ free(locale);
+ return ret;
+ }
+
if (!g_hash_table_size(list)) {
- _LOGI("pkginfo for [%s] is not existed for user [%d]",
+ _LOGD("pkginfo for [%s] is not existed for user [%d]",
pkgid, uid);
g_hash_table_destroy(list);
free(locale);
info->locale = locale;
/* just free list only */
+ g_hash_table_steal(list, (gconstpointer)pkgid);
g_hash_table_destroy(list);
*handle = info;
return PMINFO_R_ERROR;
}
- list = g_hash_table_new(g_str_hash, g_str_equal);
+ list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ __free_packages);
if (list == NULL) {
pkgmgrinfo_pkginfo_filter_destroy(filter);
free(locale);
}
if (!g_hash_table_size(list)) {
- _LOGI("disabled pkginfo for [%s] is not existed for user [%d]",
+ _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
pkgid, uid);
g_hash_table_destroy(list);
free(locale);
info->locale = locale;
/* just free list only */
+ g_hash_table_steal(list, (gconstpointer)pkgid);
g_hash_table_destroy(list);
*handle = info;
*storage = PMINFO_INTERNAL_STORAGE;
else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
*storage = PMINFO_EXTERNAL_STORAGE;
+ else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
+ *storage = PMINFO_EXTENDED_STORAGE;
else
return PMINFO_R_ERROR;
val = (char *)info->pkg_info->installlocation;
if (strcmp(val, "internal-only") == 0)
*movable = 0;
- else if (strcmp(val, "prefer-external") == 0)
- *movable = 1;
else
*movable = 1;
return PMINFO_R_OK;
}
+API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
+ pkgmgrinfo_pkginfo_h handle,
+ pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
+ void *user_data)
+{
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
+ retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
+ "Callback function is NULL");
+ int ret;
+ appdefined_privilege_x *privilege;
+ GList *tmp;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+ if (info->pkg_info == NULL)
+ return PMINFO_R_ERROR;
+
+ for (tmp = info->pkg_info->appdefined_privileges; tmp;
+ tmp = tmp->next) {
+ privilege = (appdefined_privilege_x *)tmp->data;
+ if (privilege == NULL)
+ continue;
+ ret = privilege_func(privilege->value, privilege->license,
+ user_data);
+ if (ret < 0)
+ break;
+ }
+ return PMINFO_R_OK;
+}
+
int __compare_package_version(const char *version, int *major,
int *minor, int *macro, int *nano)
{