4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
30 #include <sys/smack.h>
31 #include <linux/limits.h>
38 #include "pkgmgr_parser.h"
39 #include "pkgmgrinfo_basic.h"
40 #include "pkgmgrinfo_private.h"
41 #include "pkgmgrinfo_debug.h"
42 #include "pkgmgr-info.h"
43 #include "pkgmgr_parser_db.h"
44 #include "pkgmgr_parser_internal.h"
46 static bool _get_bool_value(const char *str)
48 if (str && !strcmp(str, "true"))
54 static gint __compare_func(gconstpointer data1, gconstpointer data2)
56 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
57 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
58 if (node1->prop == node2->prop)
60 else if (node1->prop > node2->prop)
66 static void __destroy_each_node(gpointer data, gpointer user_data)
69 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
82 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
86 free((void *)data->locale);
90 pkgmgrinfo_basic_free_package(data->pkg_info);
96 long long _pkgmgr_calculate_dir_size(char *dirname)
100 int q = 0; /*quotient*/
101 int r = 0; /*remainder*/
103 struct dirent ep, *result;
104 struct stat fileinfo;
105 char abs_filename[FILENAME_MAX] = { 0, };
106 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
108 dp = opendir(dirname);
110 _LOGE("Couldn't open the directory\n");
114 for (ret = readdir_r(dp, &ep, &result);
115 ret == 0 && result != NULL;
116 ret = readdir_r(dp, &ep, &result)) {
117 if (!strcmp(ep.d_name, ".") ||
118 !strcmp(ep.d_name, "..")) {
121 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
123 if (lstat(abs_filename, &fileinfo) < 0)
124 perror(abs_filename);
126 if (S_ISDIR(fileinfo.st_mode)) {
127 total += fileinfo.st_size;
128 if (strcmp(ep.d_name, ".")
129 && strcmp(ep.d_name, "..")) {
130 ret = _pkgmgr_calculate_dir_size
134 } else if (S_ISLNK(fileinfo.st_mode)) {
137 /*It is a file. Calculate the actual
138 size occupied (in terms of 4096 blocks)*/
139 q = (fileinfo.st_size / BLOCK_SIZE);
140 r = (fileinfo.st_size % BLOCK_SIZE);
143 total += q * BLOCK_SIZE;
152 static int _pkginfo_add_description_info_into_list(const char *locale,
153 char *record, GList **description)
157 info = calloc(1, sizeof(description_x));
159 LOGE("out of memory");
160 return PMINFO_R_ERROR;
162 info->lang = strdup(locale);
164 *description = g_list_append(*description, info);
169 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
172 static const char query_raw[] =
173 "SELECT privilege FROM package_privilege_info WHERE package=%Q";
179 query = sqlite3_mprintf(query_raw, pkgid);
181 LOGE("out of memory");
182 return PMINFO_R_ERROR;
185 ret = sqlite3_prepare_v2(db, query, strlen(query),
188 if (ret != SQLITE_OK) {
189 LOGE("prepare failed: %s", sqlite3_errmsg(db));
190 return PMINFO_R_ERROR;
193 while (sqlite3_step(stmt) == SQLITE_ROW) {
195 _save_column_str(stmt, 0, &privilege);
197 *privileges = g_list_append(*privileges,
198 (gpointer)privilege);
201 sqlite3_finalize(stmt);
206 static const char join_localized_info[] =
207 " LEFT OUTER JOIN package_localized_info"
208 " ON pi.package=package_localized_info.package"
209 " AND package_localized_info.package_locale=?";
210 static const char join_privilege_info[] =
211 " LEFT OUTER JOIN package_privilege_info"
212 " ON pi.package=package_privilege_info.package";
214 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
215 const char *locale, char **query, GList **bind_params)
218 char buf[MAX_QUERY_LEN] = { '\0' };
219 char buf2[MAX_QUERY_LEN] = { '\0' };
220 char *condition = NULL;
227 len += strlen(" WHERE 1=1 ");
228 strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
229 for (list = filter->list; list; list = list->next) {
230 joined |= __get_filter_condition(list->data, &condition,
232 if (condition == NULL)
235 len += strlen(" AND ");
236 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
238 len += strlen(condition);
239 strncat(buf, condition, sizeof(buf) - len - 1);
244 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
245 strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1);
246 len += strlen(join_localized_info);
247 *bind_params = g_list_append(*bind_params, strdup(locale));
249 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) {
250 strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1);
251 len += strlen(join_privilege_info);
253 strncat(buf2, buf, MAX_QUERY_LEN - len - 1);
255 *query = strdup(buf2);
257 return PMINFO_R_ERROR;
262 static void __free_packages(gpointer data)
264 pkgmgrinfo_basic_free_package((package_x *)data);
267 static int __bind_params(sqlite3_stmt *stmt, GList *params)
269 GList *tmp_list = NULL;
273 if (stmt == NULL || params == NULL)
274 return PMINFO_R_EINVAL;
278 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
279 if (ret != SQLITE_OK)
280 return PMINFO_R_ERROR;
281 tmp_list = tmp_list->next;
287 static int _pkginfo_get_packages(uid_t uid, const char *locale,
288 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
290 static const char query_raw[] =
291 "SELECT DISTINCT pi.package, pi.package_version, "
292 "pi.install_location, pi.package_removable, "
293 "pi.package_preload, pi.package_readonly, pi.package_update, "
294 "pi.package_appsetting, pi.package_system, pi.package_type, "
295 "pi.package_size, pi.installed_time, pi.installed_storage, "
296 "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
297 "pi.root_path, pi.csc_path, pi.package_nodisplay, "
298 "pi.package_api_version, pi.package_support_disable, "
299 "pi.package_tep_name, pi.package_zip_mount_file";
300 static const char query_author[] =
301 ", pi.author_name, pi.author_email, pi.author_href";
302 static const char query_label[] =
304 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
305 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
306 static const char query_icon[] =
308 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
309 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
310 static const char query_description[] =
312 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
313 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
314 static const char query_from_clause[] = " FROM package_info as pi";
315 int ret = PMINFO_R_ERROR;
319 char *tmp_record = NULL;
320 char *constraints = NULL;
321 char query[MAX_QUERY_LEN] = { '\0' };
322 package_x *info = NULL;
323 author_x *author = NULL;
324 GList *bind_params = NULL;
327 pkgmgrinfo_filter_x *tmp_filter = NULL;
329 dbpath = getUserPkgParserDBPathUID(uid);
331 return PMINFO_R_ERROR;
333 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
334 if (ret != SQLITE_OK) {
335 _LOGD("failed to open db: %d", ret);
337 return PMINFO_R_ERROR;
341 if (filter != NULL) {
344 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
345 if (ret != PMINFO_R_OK) {
346 _LOGE("Failed to create filter");
347 return PMINFO_R_ERROR;
351 /* add package_disable='false' clause by default */
352 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
354 query_len = strlen(query_raw);
355 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
356 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
357 strncat(query, query_author, MAX_QUERY_LEN - query_len - 1);
358 query_len += strlen(query_author);
360 if (flag & PMINFO_PKGINFO_GET_LABEL) {
361 strncat(query, query_label, MAX_QUERY_LEN - query_len - 1);
362 query_len += strlen(query_label);
363 bind_params = g_list_append(bind_params, strdup(locale));
365 if (flag & PMINFO_PKGINFO_GET_ICON) {
366 strncat(query, query_icon, MAX_QUERY_LEN - query_len - 1);
367 query_len += strlen(query_icon);
368 bind_params = g_list_append(bind_params, strdup(locale));
370 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
371 strncat(query, query_description, MAX_QUERY_LEN - query_len - 1);
372 query_len += strlen(query_description);
373 bind_params = g_list_append(bind_params, strdup(locale));
376 strncat(query, query_from_clause, MAX_QUERY_LEN - query_len - 1);
377 query_len += strlen(query_from_clause);
379 ret = _get_filtered_query(tmp_filter, locale, &constraints, &bind_params);
380 if (ret != PMINFO_R_OK) {
381 LOGE("Failed to get WHERE clause");
386 strncat(query, constraints, MAX_QUERY_LEN - query_len - 1);
388 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
389 if (ret != SQLITE_OK) {
390 LOGE("prepare failed: %s", sqlite3_errmsg(db));
391 ret = PMINFO_R_ERROR;
395 ret = __bind_params(stmt, bind_params);
396 if (ret != SQLITE_OK) {
397 LOGE("Failed to bind parameters");
401 while (sqlite3_step(stmt) == SQLITE_ROW) {
402 info = calloc(1, sizeof(package_x));
404 LOGE("out of memory");
405 sqlite3_finalize(stmt);
406 sqlite3_close_v2(db);
407 return PMINFO_R_ERROR;
410 _save_column_str(stmt, idx++, &info->package);
411 if (g_hash_table_contains(packages,
412 (gconstpointer)info->package)) {
417 _save_column_str(stmt, idx++, &info->version);
418 _save_column_str(stmt, idx++, &info->installlocation);
419 _save_column_str(stmt, idx++, &info->removable);
420 _save_column_str(stmt, idx++, &info->preload);
421 _save_column_str(stmt, idx++, &info->readonly);
422 _save_column_str(stmt, idx++, &info->update);
423 _save_column_str(stmt, idx++, &info->appsetting);
424 _save_column_str(stmt, idx++, &info->system);
425 _save_column_str(stmt, idx++, &info->type);
426 _save_column_str(stmt, idx++, &info->package_size);
427 _save_column_str(stmt, idx++, &info->installed_time);
428 _save_column_str(stmt, idx++, &info->installed_storage);
429 _save_column_str(stmt, idx++, &info->storeclient_id);
430 _save_column_str(stmt, idx++, &info->mainapp_id);
431 _save_column_str(stmt, idx++, &info->package_url);
432 _save_column_str(stmt, idx++, &info->root_path);
433 _save_column_str(stmt, idx++, &info->csc_path);
434 _save_column_str(stmt, idx++, &info->nodisplay_setting);
435 _save_column_str(stmt, idx++, &info->api_version);
436 _save_column_str(stmt, idx++, &info->support_disable);
437 _save_column_str(stmt, idx++, &info->tep_name);
438 _save_column_str(stmt, idx++, &info->zip_mount_file);
439 info->for_all_users =
440 strdup((uid != GLOBAL_USER) ? "false" : "true");
442 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
443 /* TODO : author should be retrieved at package_localized_info */
444 author = calloc(1, sizeof(author_x));
445 if (author == NULL) {
446 pkgmgrinfo_basic_free_package(info);
447 sqlite3_finalize(stmt);
448 sqlite3_close_v2(db);
449 return PMINFO_R_ERROR;
451 _save_column_str(stmt, idx++, &author->text);
452 _save_column_str(stmt, idx++, &author->email);
453 _save_column_str(stmt, idx++, &author->href);
454 info->author = g_list_append(info->author, author);
457 if (flag & PMINFO_PKGINFO_GET_LABEL) {
459 _save_column_str(stmt, idx++, &tmp_record);
461 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
462 pkgmgrinfo_basic_free_package(info);
463 sqlite3_finalize(stmt);
464 sqlite3_close_v2(db);
465 return PMINFO_R_ERROR;
469 if (flag & PMINFO_PKGINFO_GET_ICON) {
471 _save_column_str(stmt, idx++, &tmp_record);
472 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
473 pkgmgrinfo_basic_free_package(info);
474 sqlite3_finalize(stmt);
475 sqlite3_close_v2(db);
476 return PMINFO_R_ERROR;
480 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
482 _save_column_str(stmt, idx++, &tmp_record);
483 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
484 &info->description)) {
485 pkgmgrinfo_basic_free_package(info);
486 sqlite3_finalize(stmt);
487 sqlite3_close_v2(db);
488 return PMINFO_R_ERROR;
492 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
493 if (_pkginfo_get_privilege(db, info->package,
494 &info->privileges)) {
495 pkgmgrinfo_basic_free_package(info);
496 sqlite3_finalize(stmt);
497 sqlite3_close_v2(db);
498 return PMINFO_R_ERROR;
502 g_hash_table_insert(packages, (gpointer)info->package,
512 if (ret != PMINFO_R_OK && info != NULL)
513 pkgmgrinfo_basic_free_package(info);
516 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
518 g_list_free_full(bind_params, free);
519 sqlite3_close_v2(db);
520 sqlite3_finalize(stmt);
525 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
526 pkgmgrinfo_filter_x *filter, int flag,
527 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
532 pkgmgr_pkginfo_x info;
537 locale = _get_system_locale();
539 return PMINFO_R_ERROR;
541 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
545 return PMINFO_R_ERROR;
548 ret = _pkginfo_get_packages(uid, locale, filter, flag, list);
549 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
550 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
553 if (ret != PMINFO_R_OK) {
554 g_hash_table_destroy(list);
556 return PMINFO_R_ERROR;
559 g_hash_table_iter_init(&iter, list);
560 while (g_hash_table_iter_next(&iter, NULL, &value)) {
561 pkg = (package_x *)value;
564 info.locale = locale;
565 if (pkg_list_cb(&info, user_data) < 0)
569 g_hash_table_destroy(list);
575 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
576 pkgmgrinfo_pkginfo_h *handle)
581 pkgmgrinfo_pkginfo_filter_h filter;
582 pkgmgr_pkginfo_x *info;
584 if (pkgid == NULL || handle == NULL) {
585 LOGE("invalid parameter");
586 return PMINFO_R_EINVAL;
589 locale = _get_system_locale();
591 return PMINFO_R_ERROR;
593 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
594 if (ret != PMINFO_R_OK) {
599 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
600 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
601 if (ret != PMINFO_R_OK) {
602 pkgmgrinfo_pkginfo_filter_destroy(filter);
604 return PMINFO_R_ERROR;
607 list = g_hash_table_new(g_str_hash, g_str_equal);
609 pkgmgrinfo_pkginfo_filter_destroy(filter);
611 return PMINFO_R_ERROR;
614 ret = _pkginfo_get_packages(uid, locale, filter,
615 PMINFO_PKGINFO_GET_ALL, list);
616 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
617 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
618 PMINFO_PKGINFO_GET_ALL, list);
620 pkgmgrinfo_pkginfo_filter_destroy(filter);
621 if (ret != PMINFO_R_OK) {
622 g_hash_table_destroy(list);
627 if (!g_hash_table_size(list)) {
628 _LOGI("pkginfo for [%s] is not existed for user [%d]",
630 g_hash_table_destroy(list);
632 return PMINFO_R_ENOENT;
635 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
637 _LOGE("out of memory");
638 g_hash_table_destroy(list);
640 return PMINFO_R_ERROR;
644 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
645 info->locale = locale;
647 /* just free list only */
648 g_hash_table_destroy(list);
655 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
656 pkgmgrinfo_pkginfo_h *handle)
658 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
661 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
662 int flag, void *user_data, uid_t uid)
664 if (pkg_list_cb == NULL) {
665 LOGE("invalid parameter");
666 return PMINFO_R_EINVAL;
669 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL, flag,
670 pkg_list_cb, user_data);
673 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
674 int flag, void *user_data)
676 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
677 user_data, _getuid());
680 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
681 void *user_data, uid_t uid)
683 if (pkg_list_cb == NULL) {
684 LOGE("invalid parameter");
685 return PMINFO_R_EINVAL;
688 return _pkginfo_get_filtered_foreach_pkginfo(uid, NULL,
689 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
692 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
695 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
699 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
701 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
703 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
704 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
706 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
707 return PMINFO_R_ERROR;
709 *pkg_name = (char *)info->pkg_info->package;
714 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
716 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
718 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
719 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
721 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
722 return PMINFO_R_ERROR;
724 *pkgid = (char *)info->pkg_info->package;
729 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
731 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
733 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
734 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
736 if (info->pkg_info == NULL)
737 return PMINFO_R_ERROR;
739 if (info->pkg_info->type == NULL)
742 *type = (char *)info->pkg_info->type;
747 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
749 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
751 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
752 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
754 if (info->pkg_info == NULL)
755 return PMINFO_R_ERROR;
757 if (info->pkg_info->version == NULL)
760 *version = (char *)info->pkg_info->version;
765 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
767 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
769 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
770 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
772 if (info->pkg_info == NULL)
773 return PMINFO_R_ERROR;
775 if (info->pkg_info->api_version == NULL)
778 *api_version = (char *)info->pkg_info->api_version;
783 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
785 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
787 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
788 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
790 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
791 return PMINFO_R_ERROR;
793 *tep_name = (char *)info->pkg_info->tep_name;
798 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
800 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
802 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
803 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
805 if (info->pkg_info == NULL)
806 return PMINFO_R_ERROR;
808 if (info->pkg_info->zip_mount_file == NULL)
809 *zip_mount_file = "";
811 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
816 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
819 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
821 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
822 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
824 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
825 return PMINFO_R_ERROR;
827 val = (char *)info->pkg_info->installlocation;
828 if (strcmp(val, "internal-only") == 0)
829 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
830 else if (strcmp(val, "prefer-external") == 0)
831 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
833 *location = PMINFO_INSTALL_LOCATION_AUTO;
838 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
840 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
843 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
844 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
846 if (info->pkg_info == NULL)
847 return PMINFO_R_ERROR;
849 if (info->pkg_info->package_size == NULL) {
852 _LOGE("out of memory");
853 return PMINFO_R_ERROR;
855 info->pkg_info->package_size = temp;
859 *size = atoi((char *)info->pkg_info->package_size);
864 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
867 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
869 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
870 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
872 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
873 return PMINFO_R_ERROR;
875 ptr = (icon_x *)info->pkg_info->icon->data;
877 return PMINFO_R_ERROR;
879 /* TODO : should we return empty string if there was no icon? */
880 if (ptr->text == NULL)
888 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
891 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
894 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
896 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
897 return PMINFO_R_ERROR;
899 ptr = (label_x *)info->pkg_info->label->data;
901 return PMINFO_R_ERROR;
903 /* TODO : should we return empty string if there was no label? */
904 if (ptr->text == NULL)
912 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
915 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
917 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
918 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
920 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
921 return PMINFO_R_ERROR;
923 ptr = (description_x *)info->pkg_info->description->data;
925 return PMINFO_R_ERROR;
927 if (ptr->text == NULL)
930 *description = (char *)ptr->text;
935 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
937 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
940 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
941 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
943 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
944 return PMINFO_R_ERROR;
946 author = (author_x *)info->pkg_info->author->data;
948 return PMINFO_R_ERROR;
950 if (author->text == NULL)
953 *author_name = (char *)author->text;
958 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
960 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
963 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
964 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
966 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
967 return PMINFO_R_ERROR;
969 author = (author_x *)info->pkg_info->author->data;
971 return PMINFO_R_ERROR;
973 if (author->email == NULL)
976 *author_email = (char *)author->email;
981 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
983 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
986 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
987 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
989 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
990 return PMINFO_R_ERROR;
992 author = (author_x *)info->pkg_info->author->data;
994 return PMINFO_R_ERROR;
996 if (author->href == NULL)
999 *author_href = (char *)author->href;
1004 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1006 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1008 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1009 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1011 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1012 return PMINFO_R_ERROR;
1014 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1015 *storage = PMINFO_INTERNAL_STORAGE;
1016 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1017 *storage = PMINFO_EXTERNAL_STORAGE;
1019 return PMINFO_R_ERROR;
1024 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1026 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1028 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1029 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1031 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1032 return PMINFO_R_ERROR;
1034 *installed_time = atoi(info->pkg_info->installed_time);
1039 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1041 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1043 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1044 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1046 if (info->pkg_info == NULL)
1047 return PMINFO_R_ERROR;
1049 if (info->pkg_info->storeclient_id == NULL)
1050 *storeclientid = "";
1052 *storeclientid = (char *)info->pkg_info->storeclient_id;
1057 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1059 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1061 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1062 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1064 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1065 return PMINFO_R_ERROR;
1067 *mainappid = (char *)info->pkg_info->mainapp_id;
1072 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1074 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1076 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1077 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1079 if (info->pkg_info == NULL)
1080 return PMINFO_R_ERROR;
1082 if (info->pkg_info->package_url == NULL)
1085 *url = (char *)info->pkg_info->package_url;
1090 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1092 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1094 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1095 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1097 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1098 return PMINFO_R_ERROR;
1100 *path = (char *)info->pkg_info->root_path;
1105 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1107 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1109 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1110 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1112 if (info->pkg_info == NULL)
1113 return PMINFO_R_ERROR;
1115 if (info->pkg_info->csc_path == NULL)
1118 *path = (char *)info->pkg_info->csc_path;
1124 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1126 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1127 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1129 #if 0 /* smack issue occured, check later */
1131 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1132 if (pkgid == NULL) {
1133 _LOGD("invalid func parameters\n");
1134 return PMINFO_R_ERROR;
1136 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1139 char app_mmc_path[FILENAME_MAX] = { 0, };
1140 char app_dir_path[FILENAME_MAX] = { 0, };
1141 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1142 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1143 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1144 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1146 /*check whether application is in external memory or not */
1147 fp = fopen(app_mmc_path, "r");
1149 _LOGD(" app path in external memory not accesible\n");
1154 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1158 /*check whether application is in internal or not */
1160 _LOGD(" app path in internal memory not accesible\n");
1162 return PMINFO_R_ERROR;
1165 /*check whether the application is installed in SD card
1166 but SD card is not present*/
1167 fp = fopen(app_mmc_internal_path, "r");
1170 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1174 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1179 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1186 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1188 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1190 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1191 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1193 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1194 return PMINFO_R_ERROR;
1196 *removable = _get_bool_value(info->pkg_info->removable);
1201 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1204 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1206 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1207 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1209 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1210 return PMINFO_R_ERROR;
1212 val = (char *)info->pkg_info->installlocation;
1213 if (strcmp(val, "internal-only") == 0)
1215 else if (strcmp(val, "prefer-external") == 0)
1223 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1225 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1227 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1228 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1230 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1231 return PMINFO_R_ERROR;
1233 *preload = _get_bool_value(info->pkg_info->preload);
1238 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1240 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1242 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1243 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1245 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1246 return PMINFO_R_ERROR;
1248 *system = _get_bool_value(info->pkg_info->system);
1253 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1255 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1257 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1258 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1260 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1261 return PMINFO_R_ERROR;
1263 *readonly = _get_bool_value(info->pkg_info->readonly);
1268 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1270 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1272 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1273 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1275 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1276 return PMINFO_R_ERROR;
1278 *update = _get_bool_value(info->pkg_info->update);
1283 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1285 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1287 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1288 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1290 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1291 return PMINFO_R_ERROR;
1293 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1298 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1300 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1302 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1303 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1305 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1306 return PMINFO_R_ERROR;
1308 *global = _get_bool_value(info->pkg_info->for_all_users);
1313 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1315 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1318 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1320 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1322 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1324 __cleanup_pkginfo(info);
1329 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1331 pkgmgrinfo_filter_x *filter;
1333 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1335 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1336 if (filter == NULL) {
1337 _LOGE("Out of Memory!!!");
1338 return PMINFO_R_ERROR;
1346 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1348 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1350 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1353 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1354 g_slist_free(filter->list);
1362 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1363 const char *property, const int value)
1365 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1369 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1370 pkgmgrinfo_node_x *node;
1372 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1373 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1375 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1376 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1377 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1378 _LOGE("Invalid Integer Property\n");
1379 return PMINFO_R_EINVAL;
1381 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1383 _LOGE("Out of Memory!!!\n");
1384 return PMINFO_R_ERROR;
1386 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1387 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1389 _LOGE("Out of Memory\n");
1391 return PMINFO_R_ERROR;
1395 /*If API is called multiple times for same property, we should override the previous values.
1396 Last value set will be used for filtering.*/
1397 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1399 filter->list = g_slist_delete_link(filter->list, link);
1400 filter->list = g_slist_append(filter->list, (gpointer)node);
1405 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1406 const char *property, const bool value)
1411 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1412 pkgmgrinfo_node_x *node;
1414 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1415 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1417 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1418 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1419 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1420 _LOGE("Invalid Boolean Property\n");
1421 return PMINFO_R_EINVAL;
1423 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1425 _LOGE("Out of Memory!!!\n");
1426 return PMINFO_R_ERROR;
1429 val = strndup("true", 4);
1431 val = strndup("false", 5);
1433 _LOGE("Out of Memory\n");
1435 return PMINFO_R_ERROR;
1439 /*If API is called multiple times for same property, we should override the previous values.
1440 Last value set will be used for filtering.*/
1441 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1443 filter->list = g_slist_delete_link(filter->list, link);
1444 filter->list = g_slist_append(filter->list, (gpointer)node);
1449 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1450 const char *property, const char *value)
1455 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1456 pkgmgrinfo_node_x *node;
1458 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1459 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1460 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1462 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1463 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1464 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1465 _LOGE("Invalid String Property\n");
1466 return PMINFO_R_EINVAL;
1468 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1470 _LOGE("Out of Memory!!!\n");
1471 return PMINFO_R_ERROR;
1473 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1474 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1475 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1476 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1477 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1478 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1479 else if (strcmp(value, "installed_internal") == 0)
1480 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1481 else if (strcmp(value, "installed_external") == 0)
1482 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1484 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1486 _LOGE("Out of Memory\n");
1488 return PMINFO_R_ERROR;
1492 /*If API is called multiple times for same property, we should override the previous values.
1493 Last value set will be used for filtering.*/
1494 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1496 filter->list = g_slist_delete_link(filter->list, link);
1497 filter->list = g_slist_append(filter->list, (gpointer)node);
1502 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1506 GHashTable *list = NULL;
1508 if (handle == NULL || count == NULL) {
1509 _LOGE("invalid parameter");
1510 return PMINFO_R_EINVAL;
1513 locale = _get_system_locale();
1515 return PMINFO_R_ERROR;
1517 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1521 return PMINFO_R_ERROR;
1524 ret = _pkginfo_get_packages(uid, locale,
1525 (pkgmgrinfo_filter_x *)handle, 0, list);
1526 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1527 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1530 if (ret != PMINFO_R_OK) {
1531 g_hash_table_destroy(list);
1533 return PMINFO_R_ERROR;
1536 *count = g_hash_table_size(list);
1538 g_hash_table_destroy(list);
1544 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1546 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1549 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1550 pkgmgrinfo_pkginfo_filter_h handle,
1551 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1553 if (handle == NULL || pkg_cb == NULL) {
1554 LOGE("invalid parameter");
1555 return PMINFO_R_EINVAL;
1558 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1559 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1562 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1563 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1565 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1568 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1569 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1571 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1572 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1574 const char *privilege;
1576 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1578 if (info->pkg_info == NULL)
1579 return PMINFO_R_ERROR;
1581 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1582 privilege = (const char *)tmp->data;
1583 if (privilege == NULL)
1585 ret = privilege_func(privilege, user_data);