if (ret != PMINFO_R_OK) {
_LOGE("Failed to add filter");
g_hash_table_destroy(list);
- if (filter == NULL)
- pkgmgrinfo_pkginfo_filter_destroy(filter);
return PMINFO_R_ERROR;
}
}
- // TODO: use pkginfo-client APIs.
+ ret = _pkginfo_get_packages(uid, filter, flag, list);
+ pkgmgrinfo_pkginfo_filter_destroy(filter);
+ if (ret != PMINFO_R_OK) {
+ g_hash_table_destroy(list);
+ return PMINFO_R_ERROR;
+ }
+
g_hash_table_iter_init(&iter, list);
while (g_hash_table_iter_next(&iter, NULL, &value)) {
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;
}
return PMINFO_R_OK;
}
+static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
+ pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
+{
+ int ret;
+ GHashTable *list;
+ pkgmgr_pkginfo_x *info;
+
+ if (pkgid == NULL || filter == NULL || handle == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ __free_packages);
+ if (list == NULL)
+ 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;
+ }
+
+ if (!g_hash_table_size(list)) {
+ _LOGD("pkginfo for [%s] is not existed for user [%d]",
+ pkgid, uid);
+ g_hash_table_destroy(list);
+ return PMINFO_R_ENOENT;
+ }
+
+ info = calloc(1, sizeof(pkgmgr_pkginfo_x));
+ if (info == NULL) {
+ _LOGE("out of memory");
+ g_hash_table_destroy(list);
+ return PMINFO_R_ERROR;
+ }
+
+ info->uid = uid;
+ info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
+ 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;
+
+ return ret;
+}
+
API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
pkgmgrinfo_pkginfo_h *handle)
{
int ret;
pkgmgrinfo_pkginfo_filter_h filter;
GHashTable *list;
- pkgmgr_pkginfo_x *info;
if (pkgid == NULL || handle == NULL) {
LOGE("invalid parameter");
pkgmgrinfo_pkginfo_filter_destroy(filter);
return PMINFO_R_ERROR;
}
-
- /* TODO: use pkginfo-client APIs to get pkginfo using filter. */
-
-
-
-
+ ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
pkgmgrinfo_pkginfo_filter_destroy(filter);
- info = calloc(1, sizeof(pkgmgr_pkginfo_x));
- if (info == NULL) {
- _LOGE("out of memory");
- g_hash_table_destroy(list);
- return PMINFO_R_ERROR;
- }
-
- info->uid = uid;
- info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
-
- // TODO: Each parcel will have locale. Use pkginfo-client APIs to get it.
- //info->locale = locale;
-
- /* just free list only */
- g_hash_table_steal(list, (gconstpointer)pkgid);
- g_hash_table_destroy(list);
-
- *handle = info;
-
return ret;
}
uid_t uid, pkgmgrinfo_pkginfo_h *handle)
{
int ret;
- GHashTable *list;
pkgmgrinfo_pkginfo_filter_h filter;
- pkgmgr_pkginfo_x *info;
if (pkgid == NULL || handle == NULL) {
LOGE("invalid parameter");
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);
- return PMINFO_R_ERROR;
- }
-
- // TODO: use pkginfo-client APIs.
-
- pkgmgrinfo_pkginfo_filter_destroy(filter);
- 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);
- return PMINFO_R_ENOENT;
- }
-
- info = calloc(1, sizeof(pkgmgr_pkginfo_x));
- if (info == NULL) {
- _LOGE("out of memory");
- g_hash_table_destroy(list);
- 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;
}
return PMINFO_R_ERROR;
}
- // TODO: use pkginfo-client APIs.
+ ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
pkgmgrinfo_pkginfo_filter_destroy(filter);
return ret;
}
}
- // TODO: use pkginfo-client APIs to get pkginfo list
+ ret = _pkginfo_get_packages(uid, handle, PMINFO_PKGINFO_GET_BASICINFO, list);
+ if (ret != PMINFO_R_OK) {
+ g_hash_table_destroy(list);
+ return PMINFO_R_ERROR;
+ }
*count = g_hash_table_size(list);
g_hash_table_destroy(list);