X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgrinfo_pkginfo.c;h=8d7a8a3cfb7bad6f4258c76fd5fc99d43c04cdd5;hb=f4e7e9f55c123b2eee4d27d35f3707df30f69129;hp=de8bda6e3f2ba1b526da0268f0931a75ba8e5eea;hpb=9c016615e5b5612c8359b1394cf955221d695fe8;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgrinfo_pkginfo.c b/src/pkgmgrinfo_pkginfo.c index de8bda6..8d7a8a3 100644 --- a/src/pkgmgrinfo_pkginfo.c +++ b/src/pkgmgrinfo_pkginfo.c @@ -29,16 +29,15 @@ #include #include #include -#include #include -#include #include #include "pkgmgrinfo_basic.h" #include "pkgmgrinfo_private.h" #include "pkgmgrinfo_debug.h" #include "pkgmgr-info.h" +#include "manager/pkginfo_manager.h" static bool _get_bool_value(const char *str) { @@ -70,22 +69,6 @@ static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2) return 1; } -static void __destroy_each_node(gpointer data, gpointer user_data) -{ - ret_if(data == NULL); - pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data; - if (node->value) { - free(node->value); - node->value = NULL; - } - if (node->key) { - free(node->key); - node->key = NULL; - } - free(node); - node = NULL; -} - static void __destroy_metadata_node(gpointer data) { pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data; @@ -110,303 +93,6 @@ static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data) return; } -long long _pkgmgr_calculate_dir_size(char *dirname) -{ - long long total = 0; - long long ret = 0; - int q = 0; /*quotient*/ - int r = 0; /*remainder*/ - DIR *dp = NULL; - struct dirent *ep; - struct stat fileinfo; - char abs_filename[FILENAME_MAX] = { 0, }; - retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL"); - - dp = opendir(dirname); - if (dp == NULL) { - _LOGE("Couldn't open the directory\n"); - return -1; - } - - for (ep = readdir(dp); ep != NULL; ep = readdir(dp)) { - if (!strcmp(ep->d_name, ".") || - !strcmp(ep->d_name, "..")) { - continue; - } - snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, - ep->d_name); - if (lstat(abs_filename, &fileinfo) < 0) - perror(abs_filename); - else { - if (S_ISDIR(fileinfo.st_mode)) { - total += fileinfo.st_size; - if (strcmp(ep->d_name, ".") - && strcmp(ep->d_name, "..")) { - ret = _pkgmgr_calculate_dir_size - (abs_filename); - total = total + ret; - } - } else if (S_ISLNK(fileinfo.st_mode)) { - continue; - } else { - /*It is a file. Calculate the actual - size occupied (in terms of 4096 blocks)*/ - q = (fileinfo.st_size / BLOCK_SIZE); - r = (fileinfo.st_size % BLOCK_SIZE); - if (r) - q = q + 1; - total += q * BLOCK_SIZE; - } - } - } - (void)closedir(dp); - return total; - -} - -static int _pkginfo_add_description_info_into_list(const char *locale, - char *record, GList **description) -{ - description_x *info; - - info = calloc(1, sizeof(description_x)); - if (info == NULL) { - LOGE("out of memory"); - return PMINFO_R_ERROR; - } - info->lang = strdup(locale); - info->text = record; - *description = g_list_prepend(*description, info); - - return PMINFO_R_OK; -} - -static int _pkginfo_get_plugin_execution_info(sqlite3 *db, const char *pkgid, - GList **plugins) -{ - static const char query_raw[] = - "SELECT appid, plugin_type, plugin_name FROM package_plugin_info " - "WHERE pkgid=%Q"; - int ret; - char *query; - sqlite3_stmt *stmt; - plugin_x *plugin; - - 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) { - plugin = calloc(1, sizeof(plugin_x)); - if (!plugin) { - LOGE("out of memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - plugin->pkgid = strdup(pkgid); - _save_column_str(stmt, 0, &plugin->appid); - _save_column_str(stmt, 1, &plugin->plugin_type); - _save_column_str(stmt, 2, &plugin->plugin_name); - *plugins = g_list_prepend(*plugins, - (gpointer)plugin); - } - - sqlite3_finalize(stmt); - - return PMINFO_R_OK; -} - -static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid, - GList **privileges) -{ - static const char query_raw[] = - "SELECT DISTINCT privilege, type FROM package_privilege_info " - "WHERE package=%Q"; - int ret; - char *query; - sqlite3_stmt *stmt; - 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(privilege_x)); - if (!privilege) { - LOGE("failed to alloc memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - _save_column_str(stmt, 0, &privilege->value); - _save_column_str(stmt, 1, &privilege->type); - *privileges = g_list_prepend(*privileges, - (gpointer)privilege); - } - - sqlite3_finalize(stmt); - - 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"); - sqlite3_finalize(stmt); - 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_prepend(*privileges, - (gpointer)privilege); - } - - sqlite3_finalize(stmt); - - return PMINFO_R_OK; -} - -static int _pkginfo_get_dependency(sqlite3 *db, const char *pkgid, - GList **dependencies) -{ - static const char query_raw[] = - "SELECT DISTINCT depends_on, type, required_version " - "FROM package_dependency_info WHERE package=%Q"; - int ret; - char *query; - sqlite3_stmt *stmt; - dependency_x *dependency; - - 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) { - dependency = calloc(1, sizeof(dependency_x)); - if (!dependency) { - LOGE("failed to alloc memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - _save_column_str(stmt, 0, &dependency->depends_on); - _save_column_str(stmt, 1, &dependency->type); - _save_column_str(stmt, 2, &dependency->required_version); - *dependencies = g_list_prepend(*dependencies, - (gpointer)dependency); - } - - 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" - " AND package_localized_info.package_locale=?"; -static const char join_privilege_info[] = - " LEFT OUTER JOIN package_privilege_info" - " ON pi.package=package_privilege_info.package"; - -static int _get_filtered_query(pkgmgrinfo_filter_x *filter, - const char *locale, uid_t uid, char **query, GList **bind_params) -{ - int joined = 0; - int size; - char buf[MAX_QUERY_LEN] = { '\0' }; - char buf2[MAX_QUERY_LEN] = { '\0' }; - char *condition = NULL; - GSList *list = NULL; - - if (filter == NULL) - return PMINFO_R_OK; - - 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 ", sizeof(buf) - strlen(buf) - 1); - - 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, 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, sizeof(buf2) - strlen(buf2) - 1); - - size = strlen(buf2) + strlen(buf) + 1; - *query = (char *)calloc(1, size); - if (*query == NULL) - return PMINFO_R_ERROR; - snprintf(*query, size, "%s%s", buf2, buf); - - return PMINFO_R_OK; -} - static void __free_packages(gpointer data) { pkgmgrinfo_basic_free_package((package_x *)data); @@ -426,360 +112,36 @@ static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter) return false; } -static int __bind_params(sqlite3_stmt *stmt, GList *params) -{ - GList *tmp_list = NULL; - int idx = 0; - int ret; - - if (stmt == NULL || params == NULL) - return PMINFO_R_EINVAL; - - tmp_list = params; - while (tmp_list) { - ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC); - if (ret != SQLITE_OK) - return PMINFO_R_ERROR; - tmp_list = tmp_list->next; - } - - return PMINFO_R_OK; -} - -static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter) -{ - GSList *tmp_list = NULL; - pkgmgrinfo_node_x *tmp_node = NULL; - int property = -1; - - property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE); - for (tmp_list = tmp_filter->list; tmp_list != NULL; - tmp_list = g_slist_next(tmp_list)) { - tmp_node = (pkgmgrinfo_node_x *)tmp_list->data; - if (property == tmp_node->prop) { - if (strcmp(tmp_node->value, "true") == 0) - return true; - else - return false; - } - } - return true; -} - -static int _pkginfo_get_packages(uid_t uid, const char *locale, - pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages) -{ - static const char query_raw[] = - "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path"; - static const char query_basic[] = - ", pi.package_version, pi.install_location, " - "pi.package_removable, pi.package_preload, pi.package_readonly, " - "pi.package_update, pi.package_appsetting, pi.package_system, " - "pi.package_type, pi.package_size, pi.installed_time, " - "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, " - "pi.csc_path, pi.package_nodisplay, pi.package_api_version, " - "pi.package_support_disable, pi.package_tep_name, " - "pi.package_zip_mount_file, pi.package_support_mode"; - static const char query_author[] = - ", pi.author_name, pi.author_email, pi.author_href"; - static const char query_label[] = - ", COALESCE(" - "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), " - "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))"; - static const char query_icon[] = - ", COALESCE(" - "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), " - "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))"; - static const char query_description[] = - ", COALESCE(" - "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), " - "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))"; - static const char query_from_clause[] = " FROM package_info as pi"; - int ret = PMINFO_R_ERROR; - int idx = 0; - char *dbpath; - char *tmp_record = NULL; - char *constraints = NULL; - char query[MAX_QUERY_LEN] = { '\0' }; - package_x *info = NULL; - author_x *author = NULL; - GList *bind_params = NULL; - sqlite3 *db; - sqlite3_stmt *stmt = NULL; - pkgmgrinfo_filter_x *tmp_filter = NULL; - bool is_check_storage = true; - const uid_t global_user_uid = GLOBAL_USER; - - dbpath = getUserPkgParserDBPathUID(uid); - if (dbpath == NULL) - return PMINFO_R_ERROR; - - ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); - if (ret != SQLITE_OK) { - _LOGD("failed to open db(%s): %d", dbpath, ret); - free(dbpath); - return PMINFO_R_ERROR; - } - free(dbpath); - - if (filter != NULL) { - tmp_filter = filter; - } else { - ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter); - if (ret != PMINFO_R_OK) { - _LOGE("Failed to create filter"); - return PMINFO_R_ERROR; - } - } - - is_check_storage = __check_package_storage_status(tmp_filter); - - snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw); - 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, sizeof(query) - strlen(query) - 1); - bind_params = g_list_append(bind_params, strdup(locale)); - } - if (flag & PMINFO_PKGINFO_GET_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, sizeof(query) - strlen(query) - 1); - bind_params = g_list_append(bind_params, strdup(locale)); - } - - 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) { - LOGE("Failed to get WHERE clause"); - goto catch; - } - - if (constraints) - strncat(query, constraints, sizeof(query) - strlen(query) - 1); - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); - ret = PMINFO_R_ERROR; - goto catch; - } - - ret = __bind_params(stmt, bind_params); - if (ret != SQLITE_OK) { - LOGE("Failed to bind parameters"); - goto catch; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - info = calloc(1, sizeof(package_x)); - if (info == NULL) { - LOGE("out of memory"); - ret = PMINFO_R_ERROR; - goto catch; - } - idx = 0; - _save_column_str(stmt, idx++, &info->package); - _save_column_str(stmt, idx++, &info->installed_storage); - _save_column_str(stmt, idx++, &info->external_path); - - if (flag & PMINFO_APPINFO_GET_BASICINFO) { - _save_column_str(stmt, idx++, &info->version); - _save_column_str(stmt, idx++, &info->installlocation); - _save_column_str(stmt, idx++, &info->removable); - _save_column_str(stmt, idx++, &info->preload); - _save_column_str(stmt, idx++, &info->readonly); - _save_column_str(stmt, idx++, &info->update); - _save_column_str(stmt, idx++, &info->appsetting); - _save_column_str(stmt, idx++, &info->system); - _save_column_str(stmt, idx++, &info->type); - _save_column_str(stmt, idx++, &info->package_size); - _save_column_str(stmt, idx++, &info->installed_time); - _save_column_str(stmt, idx++, &info->storeclient_id); - _save_column_str(stmt, idx++, &info->mainapp_id); - _save_column_str(stmt, idx++, &info->package_url); - _save_column_str(stmt, idx++, &info->root_path); - _save_column_str(stmt, idx++, &info->csc_path); - _save_column_str(stmt, idx++, &info->nodisplay_setting); - _save_column_str(stmt, idx++, &info->api_version); - _save_column_str(stmt, idx++, &info->support_disable); - _save_column_str(stmt, idx++, &info->tep_name); - _save_column_str(stmt, idx++, &info->zip_mount_file); - _save_column_str(stmt, idx++, &info->support_mode); - } - - info->for_all_users = - strdup((uid != global_user_uid) ? "false" : "true"); - - if (_pkginfo_get_plugin_execution_info(db, info->package, &info->plugin)) { - ret = PMINFO_R_ERROR; - goto catch; - } - - if (flag & PMINFO_PKGINFO_GET_AUTHOR) { - /* TODO : author should be retrieved at package_localized_info */ - author = calloc(1, sizeof(author_x)); - if (author == NULL) { - ret = PMINFO_R_ERROR; - goto catch; - } - _save_column_str(stmt, idx++, &author->text); - _save_column_str(stmt, idx++, &author->email); - _save_column_str(stmt, idx++, &author->href); - info->author = g_list_prepend(info->author, author); - } - - if (flag & PMINFO_PKGINFO_GET_LABEL) { - tmp_record = NULL; - _save_column_str(stmt, idx++, &tmp_record); - - if (_add_label_info_into_list(locale, tmp_record, &info->label)) { - ret = PMINFO_R_ERROR; - goto catch; - } - } - - if (flag & PMINFO_PKGINFO_GET_ICON) { - tmp_record = NULL; - _save_column_str(stmt, idx++, &tmp_record); - if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) { - ret = PMINFO_R_ERROR; - goto catch; - } - } - - if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) { - tmp_record = NULL; - _save_column_str(stmt, idx++, &tmp_record); - if (_pkginfo_add_description_info_into_list(locale, tmp_record, - &info->description)) { - ret = PMINFO_R_ERROR; - goto catch; - } - } - - if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) { - if (_pkginfo_get_privilege(db, info->package, - &info->privileges)) { - ret = PMINFO_R_ERROR; - goto catch; - } - } - - 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 (flag & PMINFO_PKGINFO_GET_DEPENDENCY) { - if (_pkginfo_get_dependency(db, info->package, - &info->dependencies)) { - ret = PMINFO_R_ERROR; - goto catch; - } - } - - if (is_check_storage && - __pkginfo_check_installed_storage(info) != PMINFO_R_OK) { - ret = PMINFO_R_ERROR; - pkgmgrinfo_basic_free_package(info); - info = NULL; - continue; - } - - g_hash_table_insert(packages, (gpointer)info->package, - (gpointer)info); - } - - ret = PMINFO_R_OK; - -catch: - sqlite3_finalize(stmt); - sqlite3_close_v2(db); - - if (constraints) - free(constraints); - - if (ret != PMINFO_R_OK && info != NULL) - pkgmgrinfo_basic_free_package(info); - - if (filter == NULL) - pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); - - g_list_free_full(bind_params, free); - - return ret; -} - static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid, pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data) { int ret; - char *locale; package_x *pkg; pkgmgr_pkginfo_x info; - pkgmgrinfo_filter_x *tmp_filter = NULL; GHashTable *list; GHashTableIter iter; gpointer value; - locale = _get_system_locale(); - if (locale == NULL) - return PMINFO_R_ERROR; - list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __free_packages); - if (list == NULL) { - free(locale); + if (list == NULL) return PMINFO_R_ERROR; - } - if (filter != NULL) { - tmp_filter = (pkgmgrinfo_filter_x *)filter; - } else { - ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter); - 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) { - ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, + if (__check_disable_filter_exist(filter) == false) { + ret = pkgmgrinfo_pkginfo_filter_add_bool(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 (ret == PMINFO_R_OK && uid != GLOBAL_USER) - ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter, - flag | PMINFO_PKGINFO_GET_BASICINFO, list); - - if (ret != PMINFO_R_OK) { + ret = _pkginfo_get_packages(uid, filter, flag, list); + if (ret == PMINFO_R_ERROR) { g_hash_table_destroy(list); - free(locale); - if (filter == NULL) - pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); - return PMINFO_R_ERROR; + return ret; } g_hash_table_iter_init(&iter, list); @@ -787,16 +149,12 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid, pkg = (package_x *)value; info.uid = uid; info.pkg_info = pkg; - info.locale = locale; + info.locale = pkg->locale; if (pkg_list_cb(&info, user_data) < 0) break; } g_hash_table_destroy(list); - free(locale); - - if (filter == NULL) - pkgmgrinfo_pkginfo_filter_destroy(tmp_filter); return PMINFO_R_OK; } @@ -805,7 +163,6 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle) { int ret; - char *locale; GHashTable *list; pkgmgr_pkginfo_x *info; @@ -814,34 +171,21 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid, return PMINFO_R_EINVAL; } - locale = _get_system_locale(); - if (locale == NULL) - return PMINFO_R_ERROR; - list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __free_packages); - if (list == NULL) { - free(locale); + if (list == NULL) return PMINFO_R_ERROR; - } - - ret = _pkginfo_get_packages(uid, locale, filter, - PMINFO_PKGINFO_GET_ALL, list); - if (!g_hash_table_size(list) && uid != GLOBAL_USER) - ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter, - PMINFO_PKGINFO_GET_ALL, list); + ret = _pkginfo_get_packages(uid, 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)) { + if (!g_hash_table_size(list) || !g_hash_table_lookup(list, pkgid)) { _LOGD("pkginfo for [%s] is not existed for user [%d]", pkgid, uid); g_hash_table_destroy(list); - free(locale); return PMINFO_R_ENOENT; } @@ -849,13 +193,18 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid, if (info == NULL) { _LOGE("out of memory"); g_hash_table_destroy(list); - free(locale); return PMINFO_R_ERROR; } info->uid = uid; info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid); - info->locale = locale; + info->locale = strdup(info->pkg_info->locale); + if (info->locale == NULL) { + _LOGE("Out of memory"); + g_hash_table_destroy(list); + free(info); + return PMINFO_R_ERROR; + } /* just free list only */ g_hash_table_steal(list, (gconstpointer)pkgid); @@ -894,7 +243,6 @@ API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_filter_destroy(filter); return PMINFO_R_ERROR; } - ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle); pkgmgrinfo_pkginfo_filter_destroy(filter); @@ -911,23 +259,15 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle) { int ret; - char *locale; - GHashTable *list; pkgmgrinfo_pkginfo_filter_h filter; - pkgmgr_pkginfo_x *info; if (pkgid == NULL || handle == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - locale = _get_system_locale(); - if (locale == NULL) - return PMINFO_R_ERROR; - ret = pkgmgrinfo_pkginfo_filter_create(&filter); if (ret != PMINFO_R_OK) { - free(locale); return ret; } @@ -935,7 +275,6 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid, PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid); if (ret != PMINFO_R_OK) { pkgmgrinfo_pkginfo_filter_destroy(filter); - free(locale); return PMINFO_R_ERROR; } @@ -943,64 +282,20 @@ API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true); if (ret != PMINFO_R_OK) { pkgmgrinfo_pkginfo_filter_destroy(filter); - free(locale); - return PMINFO_R_ERROR; - } - - 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); return PMINFO_R_ERROR; } - ret = _pkginfo_get_packages(uid, locale, filter, - PMINFO_PKGINFO_GET_ALL, list); - if (!g_hash_table_size(list) && uid != GLOBAL_USER) - ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter, - PMINFO_PKGINFO_GET_ALL, list); - - pkgmgrinfo_pkginfo_filter_destroy(filter); - if (ret != PMINFO_R_OK) { - g_hash_table_destroy(list); - free(locale); - return ret; - } - - if (!g_hash_table_size(list)) { - _LOGD("disabled pkginfo for [%s] is not existed for user [%d]", + ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle); + if (ret == PMINFO_R_ENOENT) + LOGE("disabled pkginfo for [%s] is not existed for user [%d]", pkgid, uid); - g_hash_table_destroy(list); - free(locale); - return PMINFO_R_ENOENT; - } - - info = calloc(1, sizeof(pkgmgr_pkginfo_x)); - if (info == NULL) { - _LOGE("out of memory"); - g_hash_table_destroy(list); - free(locale); - return PMINFO_R_ERROR; - } - - info->uid = uid; - info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid); - info->locale = locale; - - /* just free list only */ - g_hash_table_steal(list, (gconstpointer)pkgid); - g_hash_table_destroy(list); - - *handle = info; - + pkgmgrinfo_pkginfo_filter_destroy(filter); return ret; } API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle) { - int ret; pkgmgrinfo_pkginfo_filter_h filter; @@ -1589,6 +884,65 @@ API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path return PMINFO_R_OK; } +API int pkgmgrinfo_pkginfo_get_res_type(pkgmgrinfo_pkginfo_h handle, + char **res_type) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(res_type == NULL, PMINFO_R_EINVAL, + "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + if (info->pkg_info->res_type == NULL) + return PMINFO_R_ENOENT; + + *res_type = (char *)info->pkg_info->res_type; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_get_res_version(pkgmgrinfo_pkginfo_h handle, + char **res_version) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(res_version == NULL, PMINFO_R_EINVAL, + "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + if (info->pkg_info->res_version == NULL) + return PMINFO_R_ENOENT; + + *res_version = (char *)info->pkg_info->res_version; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_get_light_user_switch_mode(pkgmgrinfo_pkginfo_h handle, char **mode) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(mode == NULL, PMINFO_R_EINVAL, + "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + if (info->pkg_info->light_user_switch_mode == NULL) + return PMINFO_R_ERROR; + + *mode = (char *)info->pkg_info->light_user_switch_mode; + + return PMINFO_R_OK; +} + API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode) { retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); @@ -1795,6 +1149,22 @@ API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *f return pkgmgrinfo_pkginfo_is_global(handle, for_all_users); } +API int pkgmgrinfo_pkginfo_is_lib(pkgmgrinfo_pkginfo_h handle, bool *lib) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(lib == NULL, PMINFO_R_EINVAL, + "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL || info->pkg_info->lib == NULL) + return PMINFO_R_ERROR; + + *lib = _get_bool_value(info->pkg_info->lib); + + return PMINFO_R_OK; +} + API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle) { pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; @@ -1829,12 +1199,16 @@ API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle) retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n"); - if (filter->list) { - g_slist_foreach(filter->list, __destroy_each_node, NULL); - g_slist_free(filter->list); - } + if (filter->list) + g_slist_free_full(filter->list, + (GDestroyNotify)_pkgmgrinfo_node_destroy); - g_slist_free_full(filter->list_metadata, __destroy_metadata_node); + if (filter->list_metadata) + g_slist_free_full(filter->list_metadata, + __destroy_metadata_node); + if (filter->list_pkg_metadata) + g_slist_free_full(filter->list_pkg_metadata, + __destroy_metadata_node); free(filter); @@ -1877,8 +1251,10 @@ API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle, /*If API is called multiple times for same property, we should override the previous values. Last value set will be used for filtering.*/ link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func); - if (link) + if (link) { + _pkgmgrinfo_node_destroy(link->data); filter->list = g_slist_delete_link(filter->list, link); + } filter->list = g_slist_append(filter->list, (gpointer)node); return PMINFO_R_OK; @@ -1921,8 +1297,10 @@ API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle, /*If API is called multiple times for same property, we should override the previous values. Last value set will be used for filtering.*/ link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func); - if (link) + if (link) { + _pkgmgrinfo_node_destroy(link->data); filter->list = g_slist_delete_link(filter->list, link); + } filter->list = g_slist_append(filter->list, (gpointer)node); return PMINFO_R_OK; @@ -1974,8 +1352,10 @@ API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle, /*If API is called multiple times for same property, we should override the previous values. Last value set will be used for filtering.*/ link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func); - if (link) + if (link) { + _pkgmgrinfo_node_destroy(link->data); filter->list = g_slist_delete_link(filter->list, link); + } filter->list = g_slist_append(filter->list, (gpointer)node); return PMINFO_R_OK; @@ -1984,7 +1364,7 @@ API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle, API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid) { int ret; - char *locale; + int query_count; GHashTable *list = NULL; if (handle == NULL || count == NULL) { @@ -1992,44 +1372,26 @@ API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, return PMINFO_R_EINVAL; } - locale = _get_system_locale(); - if (locale == NULL) - return PMINFO_R_ERROR; - list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __free_packages); - if (list == NULL) { - free(locale); + if (list == NULL) return PMINFO_R_ERROR; - } if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) { ret = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false); if (ret != PMINFO_R_OK) { - free(locale); g_hash_table_destroy(list); return PMINFO_R_ERROR; } } - ret = _pkginfo_get_packages(uid, locale, - (pkgmgrinfo_filter_x *)handle, 0, list); - if (ret == PMINFO_R_OK && uid != GLOBAL_USER) - ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0, - list); - - if (ret != PMINFO_R_OK) { - g_hash_table_destroy(list); - free(locale); - return PMINFO_R_ERROR; - } - - *count = g_hash_table_size(list); - + ret = _pkginfo_get_packages(uid, handle, PMINFO_PKGINFO_GET_BASICINFO, list); + query_count = g_hash_table_size(list); g_hash_table_destroy(list); - free(locale); - + if (ret == PMINFO_R_ERROR) + return ret; + *count = query_count; return PMINFO_R_OK; } @@ -2179,160 +1541,113 @@ API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle, return PMINFO_R_OK; } -struct depends_on { - char *from; - char *to; - char *type; - char *version; -}; +static void __free_depends_on(gpointer data) +{ + dependency_x *dep = (dependency_x *)data; + pkgmgrinfo_basic_free_dependency(dep); +} -static int _get_depends_on(sqlite3 *db, const char *pkgid, GQueue **queue, - GHashTable **table, GList **pkg_list) +/* This API is not exported at the header file */ +API int pkgmgrinfo_pkginfo_foreach_depends_on_by_pkgid(const char *pkgid, + pkgmgrinfo_pkg_dependency_list_cb dependency_cb, + void *user_data, uid_t uid) { - static const char query[] = - "SELECT package, depends_on, type, required_version " - "FROM package_dependency_info WHERE depends_on=?"; int ret; - sqlite3_stmt *stmt; - struct depends_on *req; - - /* already checked */ - if (!g_hash_table_insert(*table, strdup(pkgid), GINT_TO_POINTER(1))) - return PMINFO_R_OK; + GList *pkg_list = NULL; + GList *l; + dependency_x *dep; - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return PMINFO_R_ERROR; + if (pkgid == NULL || dependency_cb == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; } - ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC); - if (ret != SQLITE_OK) { - LOGE("bind failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); + ret = _pkginfo_get_depends_on(uid, pkgid, &pkg_list); + if (ret != PMINFO_R_OK) return PMINFO_R_ERROR; + + for (l = pkg_list; l != NULL; l = g_list_next(l)) { + dep = (dependency_x *)l->data; + ret = dependency_cb(dep->pkgid, dep->depends_on, + dep->type, dep->required_version, user_data); + if (ret < 0) + break; } + g_list_free_full(pkg_list, __free_depends_on); - while (sqlite3_step(stmt) == SQLITE_ROW) { - req = calloc(1, sizeof(struct depends_on)); - if (req == NULL) { - LOGE("out of memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - _save_column_str(stmt, 0, &req->from); - _save_column_str(stmt, 1, &req->to); - _save_column_str(stmt, 2, &req->type); - _save_column_str(stmt, 3, &req->version); + return PMINFO_R_OK; +} - *pkg_list = g_list_prepend(*pkg_list, req); - g_queue_push_tail(*queue, strdup(req->from)); - } +API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_pkg_dependency_list_cb dependency_cb, + void *user_data) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; - sqlite3_finalize(stmt); + if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } - return PMINFO_R_OK; + return pkgmgrinfo_pkginfo_foreach_depends_on_by_pkgid( + info->pkg_info->package, dependency_cb, user_data, + info->uid); } -static int _pkginfo_foreach_depends_on(uid_t uid, const char *pkgid, - GList **pkg_list) +API int pkgmgrinfo_pkginfo_foreach_res_allowed_package( + pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_res_allowed_package_list_cb res_allowed_package_cb, + void *user_data) { int ret; - char *dbpath; - sqlite3 *db; - GQueue *queue; - GHashTable *table; - char *item; - - dbpath = getUserPkgParserDBPathUID(uid); - if (dbpath == NULL) - return PMINFO_R_ERROR; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + GList *res_pkgs; + res_allowed_package_x *res_allowed_package; - ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); - if (ret != SQLITE_OK) { - LOGD("failed to open db(%s): %d", dbpath, ret); - free(dbpath); - return PMINFO_R_ERROR; + if (handle == NULL || res_allowed_package_cb == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; } - free(dbpath); - queue = g_queue_new(); - if (queue == NULL) { - LOGE("out of memory"); - sqlite3_close_v2(db); + if (info->pkg_info == NULL) return PMINFO_R_ERROR; - } - table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL); + for (res_pkgs = info->pkg_info->res_allowed_packages; res_pkgs; + res_pkgs = res_pkgs->next) { + res_allowed_package = (res_allowed_package_x *)res_pkgs->data; + if (res_allowed_package == NULL) + continue; - g_queue_push_tail(queue, strdup(pkgid)); - while (!g_queue_is_empty(queue)) { - item = g_queue_pop_head(queue); - ret = _get_depends_on(db, item, &queue, &table, pkg_list); - free(item); - if (ret != PMINFO_R_OK) { - LOGE("failed to get pkgs depends on %s", pkgid); - g_hash_table_destroy(table); - g_queue_free_full(queue, free); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; - } + ret = res_allowed_package_cb( + res_allowed_package->allowed_package, + res_allowed_package->required_privileges, + user_data); + if (ret < 0) + return PMINFO_R_OK; } - g_hash_table_destroy(table); - g_queue_free_full(queue, free); - sqlite3_close_v2(db); - return PMINFO_R_OK; } -static void __free_depends_on(gpointer data) -{ - struct depends_on *dep = (struct depends_on *)data; - - free(dep->from); - free(dep->to); - free(dep->type); - free(dep->version); - free(dep); -} - -API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle, - pkgmgrinfo_pkg_dependency_list_cb dependency_cb, +API int pkgmgrinfo_pkginfo_foreach_required_privilege( + required_privilege_h handle, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data) { int ret; - pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; - GList *pkg_list = NULL; - GList *l; - struct depends_on *dep; + GList *privs; - if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) { + if (privilege_func == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - ret = _pkginfo_foreach_depends_on(info->uid, info->pkg_info->package, - &pkg_list); - if (ret == PMINFO_R_OK && info->uid != GLOBAL_USER) - ret = _pkginfo_foreach_depends_on(GLOBAL_USER, - info->pkg_info->package, &pkg_list); - - if (ret != PMINFO_R_OK) { - g_list_free_full(pkg_list, __free_depends_on); - return ret; - } - - for (l = pkg_list; l != NULL; l = l->next) { - dep = (struct depends_on *)l->data; - ret = dependency_cb(dep->from, dep->to, dep->type, dep->version, - user_data); + for (privs = (GList *)handle; privs; privs = privs->next) { + ret = privilege_func((char *)privs->data, user_data); if (ret < 0) - break; + return PMINFO_R_OK; } - g_list_free_full(pkg_list, __free_depends_on); - return PMINFO_R_OK; } @@ -2458,3 +1773,102 @@ API int pkgmgrinfo_compare_package_version(const char *current_version, return PMINFO_R_OK; } + +API int pkgmgrinfo_pkginfo_foreach_metadata(pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_pkg_metadata_list_cb metadata_func, void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL"); + retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, + "Callback function is NULL"); + int ret = -1; + metadata_x *ptr; + GList *tmp; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->pkg_info->metadata; tmp; tmp = tmp->next) { + ptr = (metadata_x *)tmp->data; + if (ptr == NULL) + continue; + if (ptr->key) { + ret = metadata_func(ptr->key, ptr->value ? + ptr->value : "", user_data); + if (ret < 0) + break; + } + } + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_metadata_filter_create( + pkgmgrinfo_pkginfo_metadata_filter_h *handle) +{ + return pkgmgrinfo_pkginfo_filter_create(handle); +} + +API int pkgmgrinfo_pkginfo_metadata_filter_destroy( + pkgmgrinfo_pkginfo_metadata_filter_h handle) +{ + return pkgmgrinfo_pkginfo_filter_destroy(handle); +} + +API int pkgmgrinfo_pkginfo_metadata_filter_add( + pkgmgrinfo_pkginfo_metadata_filter_h handle, + const char *key, const char *value) +{ + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_metadata_node_x *node; + + /* value can be NULL. + * In that case all pkgs with specified key should be displayed + */ + if (handle == NULL || key == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x)); + if (node == NULL) { + LOGE("out of memory"); + return PMINFO_R_ERROR; + } + + node->key = strdup(key); + if (value && strlen(value)) + node->value = strdup(value); + + filter->list_pkg_metadata = g_slist_append(filter->list_pkg_metadata, + (gpointer)node); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_usr_metadata_filter_foreach( + pkgmgrinfo_pkginfo_metadata_filter_h handle, + pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid) +{ + if (handle == NULL || pkg_cb == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + + if (pkgmgrinfo_pkginfo_filter_add_bool(filter, + PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false)) + return PMINFO_R_ERROR; + + return _pkginfo_get_filtered_foreach_pkginfo(uid, handle, + PMINFO_PKGINFO_GET_ALL, pkg_cb, + user_data); +} + +API int pkgmgrinfo_pkginfo_metadata_filter_foreach( + pkgmgrinfo_pkginfo_metadata_filter_h handle, + pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data) +{ + return pkgmgrinfo_pkginfo_usr_metadata_filter_foreach(handle, pkg_cb, + user_data, _getuid()); +}