#include <ctype.h>
#include <sys/smack.h>
#include <linux/limits.h>
-#include <libgen.h>
#include <sys/stat.h>
-#include <sqlite3.h>
#include <glib.h>
#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)
{
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;
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_append(*description, info);
-
- 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));
- _save_column_str(stmt, 0, &privilege->value);
- _save_column_str(stmt, 1, &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"
- " 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;
- 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);
- strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
-
- *query = strdup(buf2);
- if (*query == NULL)
- return PMINFO_R_ERROR;
-
- return PMINFO_R_OK;
-}
-
static void __free_packages(gpointer data)
{
pkgmgrinfo_basic_free_package((package_x *)data);
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 (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_append(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 (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:
- 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);
- sqlite3_close_v2(db);
- if (stmt)
- sqlite3_finalize(stmt);
-
- 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 (__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 create filter");
+ _LOGE("Failed to add filter");
g_hash_table_destroy(list);
return PMINFO_R_ERROR;
}
}
- if (__check_disable_filter_exist(tmp_filter) == false)
- pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
- PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
-
- 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);
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;
}
pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
{
int ret;
- char *locale;
GHashTable *list;
pkgmgr_pkginfo_x *info;
return PMINFO_R_EINVAL;
}
- locale = _get_system_locale();
- if (locale == NULL)
+ list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ __free_packages);
+ if (list == NULL)
return PMINFO_R_ERROR;
- list = g_hash_table_new(g_str_hash, g_str_equal);
- if (list == NULL) {
- free(locale);
- return PMINFO_R_ERROR;
+ ret = _pkginfo_get_packages(uid, filter, PMINFO_PKGINFO_GET_ALL, list);
+ if (ret != PMINFO_R_OK) {
+ g_hash_table_destroy(list);
+ return ret;
}
- 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);
-
- 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;
}
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);
g_hash_table_destroy(list);
*handle = info;
pkgmgrinfo_pkginfo_filter_destroy(filter);
return PMINFO_R_ERROR;
}
-
ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
pkgmgrinfo_pkginfo_filter_destroy(filter);
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;
}
PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_pkginfo_filter_destroy(filter);
- free(locale);
return PMINFO_R_ERROR;
}
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(g_str_hash, g_str_equal);
- 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_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;
*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;
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");
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;
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);
/*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;
/*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;
/*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;
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) {
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;
}
retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
int ret;
privilege_x *privilege;
+ appdefined_privilege_x *appdefined_privilege;
GList *tmp;
pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
continue;
ret = privilege_func(privilege->value, user_data);
if (ret < 0)
+ return PMINFO_R_OK;
+ }
+
+ for (tmp = info->pkg_info->appdefined_privileges; tmp;
+ tmp = tmp->next) {
+ appdefined_privilege = (appdefined_privilege_x *)tmp->data;
+ if (appdefined_privilege == NULL)
+ continue;
+ ret = privilege_func(appdefined_privilege->value, user_data);
+ if (ret < 0)
+ return PMINFO_R_OK;
+ }
+ return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
+ pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
+{
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
+ retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
+ "Callback function is NULL");
+ int ret;
+ plugin_x *plugin;
+ GList *tmp;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+ if (info->pkg_info == NULL)
+ return PMINFO_R_ERROR;
+
+ for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
+ plugin = (plugin_x *)tmp->data;
+ if (plugin == NULL)
+ continue;
+ ret = plugin_func(plugin->pkgid, plugin->appid,
+ plugin->plugin_type, plugin->plugin_name, user_data);
+ if (ret < 0)
+ return PMINFO_R_OK;
+ }
+
+ 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;
+}
+
+API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
+ pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
+ void *user_data)
+{
+ int ret;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ GList *tmp;
+ dependency_x *dependency;
+
+ if (handle == NULL || dependency_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ if (info->pkg_info == NULL)
+ return PMINFO_R_ERROR;
+
+ for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
+ dependency = (dependency_x *)tmp->data;
+ if (dependency == NULL)
+ continue;
+ ret = dependency_cb(info->pkg_info->package,
+ dependency->depends_on, dependency->type,
+ dependency->required_version, user_data);
+ if (ret < 0)
break;
}
+
+ return PMINFO_R_OK;
+}
+
+static void __free_depends_on(gpointer data)
+{
+ dependency_x *dep = (dependency_x *)data;
+ pkgmgrinfo_basic_free_dependency(dep);
+}
+
+/* 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)
+{
+ int ret;
+ GList *pkg_list = NULL;
+ GList *l;
+ dependency_x *dep;
+
+ if (pkgid == NULL || dependency_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ 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);
+
+ return PMINFO_R_OK;
+}
+
+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;
+
+ if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ return pkgmgrinfo_pkginfo_foreach_depends_on_by_pkgid(
+ info->pkg_info->package, dependency_cb, user_data,
+ info->uid);
+}
+
+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;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ GList *res_pkgs;
+ res_allowed_package_x *res_allowed_package;
+
+ if (handle == NULL || res_allowed_package_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ if (info->pkg_info == NULL)
+ return PMINFO_R_ERROR;
+
+ 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;
+
+ ret = res_allowed_package_cb(
+ res_allowed_package->allowed_package,
+ res_allowed_package->required_privileges,
+ user_data);
+ if (ret < 0)
+ return PMINFO_R_OK;
+ }
+
+ return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_foreach_required_privilege(
+ required_privilege_h handle,
+ pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+ void *user_data)
+{
+ int ret;
+ GList *privs;
+
+ if (privilege_func == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ for (privs = (GList *)handle; privs; privs = privs->next) {
+ ret = privilege_func((char *)privs->data, user_data);
+ if (ret < 0)
+ return PMINFO_R_OK;
+ }
+
return PMINFO_R_OK;
}
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());
+}
+
+API int pkgmgrinfo_pkginfo_get_metadata_value(
+ pkgmgrinfo_pkginfo_h handle, const char *metadata_key,
+ char **metadata_value)
+{
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
+ retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
+ retvm_if(metadata_value == NULL, PMINFO_R_EINVAL,
+ "metadata_value is NULL");
+
+ GList *list_md = NULL;
+ metadata_x *metadata = NULL;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+ list_md = info->pkg_info->metadata;
+
+ for (; list_md; list_md = list_md->next) {
+ metadata = (metadata_x *)list_md->data;
+ if (metadata && metadata->key) {
+ if (strcasecmp(metadata->key, metadata_key) == 0) {
+ if (metadata->value == NULL)
+ *metadata_value = "";
+ else
+ *metadata_value =
+ (char *)metadata->value;
+ return PMINFO_R_OK;
+ }
+ }
+ }
+
+ return PMINFO_R_EINVAL;
+}